/
nethermind.rs
111 lines (97 loc) · 3.35 KB
/
nethermind.rs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use crate::build_utils;
use crate::execution_engine::GenericExecutionEngine;
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Child, Command, Output};
use tempfile::TempDir;
use unused_port::unused_tcp_port;
const NETHERMIND_BRANCH: &str = "master";
const NETHERMIND_REPO_URL: &str = "https://github.com/NethermindEth/nethermind";
fn build_result(repo_dir: &Path) -> Output {
Command::new("dotnet")
.arg("build")
.arg("src/Nethermind/Nethermind.sln")
.arg("-c")
.arg("Release")
.current_dir(repo_dir)
.output()
.expect("failed to make nethermind")
}
pub fn build(execution_clients_dir: &Path) {
let repo_dir = execution_clients_dir.join("nethermind");
if !repo_dir.exists() {
// Clone the repo
assert!(build_utils::clone_repo(
execution_clients_dir,
NETHERMIND_REPO_URL
));
}
// Checkout the correct branch
assert!(build_utils::checkout_branch(&repo_dir, NETHERMIND_BRANCH));
// Update the branch
assert!(build_utils::update_branch(&repo_dir, NETHERMIND_BRANCH));
// Build nethermind
build_utils::check_command_output(build_result(&repo_dir), "dotnet build failed");
// Build nethermind a second time to enable Merge-related features.
// Not sure why this is necessary.
build_utils::check_command_output(build_result(&repo_dir), "dotnet build failed");
}
/*
* Nethermind-specific Implementation for GenericExecutionEngine
*/
#[derive(Clone)]
pub struct NethermindEngine;
impl NethermindEngine {
fn binary_path() -> PathBuf {
let manifest_dir: PathBuf = env::var("CARGO_MANIFEST_DIR").unwrap().into();
manifest_dir
.join("execution_clients")
.join("nethermind")
.join("src")
.join("Nethermind")
.join("Nethermind.Runner")
.join("bin")
.join("Release")
.join("net6.0")
.join("Nethermind.Runner")
}
}
impl GenericExecutionEngine for NethermindEngine {
fn init_datadir() -> TempDir {
TempDir::new().unwrap()
}
fn start_client(
datadir: &TempDir,
_http_port: u16,
http_auth_port: u16,
jwt_secret_path: PathBuf,
) -> Child {
let network_port = unused_tcp_port().unwrap();
Command::new(Self::binary_path())
.arg("--datadir")
.arg(datadir.path().to_str().unwrap())
.arg("--config")
.arg("kiln")
.arg("--Merge.TerminalTotalDifficulty")
.arg("0")
.arg("--JsonRpc.AdditionalRpcUrls")
.arg(format!(
"http://localhost:{}|http;ws|net;eth;subscribe;engine;web3;client",
http_auth_port
))
.arg("--JsonRpc.EnabledModules")
.arg("net,eth,subscribe,web3,admin,engine")
.arg("--JsonRpc.Port")
.arg(http_auth_port.to_string())
.arg("--Network.DiscoveryPort")
.arg(network_port.to_string())
.arg("--Network.P2PPort")
.arg(network_port.to_string())
.arg("--JsonRpc.JwtSecretFile")
.arg(jwt_secret_path.as_path().to_str().unwrap())
.stdout(build_utils::build_stdio())
.stderr(build_utils::build_stdio())
.spawn()
.expect("failed to start nethermind")
}
}