1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::{
    execution_correctness_manager,
    remote_service::{self, RemoteService},
};
use diem_config::config::{ExecutionCorrectnessService, NodeConfig};
use diem_crypto::ed25519::Ed25519PrivateKey;
use std::net::SocketAddr;

pub struct Process {
    // TODO:  Restrict this to hold only the execution config.
    config: NodeConfig,
    prikey: Option<Ed25519PrivateKey>,
    // Timeout in milliseconds
    network_timeout_ms: u64,
}

impl Process {
    pub fn new(config: NodeConfig) -> Self {
        let prikey = execution_correctness_manager::extract_execution_prikey(&config);
        let network_timeout = config.execution.network_timeout_ms;
        Self {
            config,
            prikey,
            network_timeout_ms: network_timeout,
        }
    }

    pub fn start(self) {
        let service = &self.config.execution.service;
        let server_addr = match &service {
            ExecutionCorrectnessService::Process(remote_service) => remote_service.server_address,
            _ => panic!("Unexpected ExecutionCorrectness service: {:?}", service),
        };
        remote_service::execute(
            self.config.storage.address,
            server_addr,
            self.prikey,
            self.network_timeout_ms,
        );
    }
}

pub struct ProcessService {
    server_addr: SocketAddr,
    network_timeout: u64,
}

impl ProcessService {
    pub fn new(server_addr: SocketAddr, network_timeout: u64) -> Self {
        Self {
            server_addr,
            network_timeout,
        }
    }
}

impl RemoteService for ProcessService {
    fn server_address(&self) -> SocketAddr {
        self.server_addr
    }
    fn network_timeout(&self) -> u64 {
        self.network_timeout
    }
}