Revert the use of subprocess

This commit is contained in:
Omar Abdulla
2025-07-14 16:31:54 +03:00
parent 4d2759dc9a
commit e2795cd5cd
5 changed files with 19 additions and 47 deletions
Generated
-11
View File
@@ -4002,7 +4002,6 @@ dependencies = [
"serde_json",
"sp-core",
"sp-runtime",
"subprocess",
"temp-dir",
"tokio",
"tracing",
@@ -5044,16 +5043,6 @@ dependencies = [
"syn 2.0.101",
]
[[package]]
name = "subprocess"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "substrate-bip39"
version = "0.6.0"
-1
View File
@@ -50,7 +50,6 @@ tracing-subscriber = { version = "0.3.19", default-features = false, features =
"json",
"env-filter",
] }
subprocess = { version = "0.2.9" }
# revive compiler
revive-solc-json-interface = { git = "https://github.com/paritytech/revive", rev = "3389865af7c3ff6f29a586d82157e8bc573c1a8e" }
-1
View File
@@ -12,7 +12,6 @@ rust-version.workspace = true
anyhow = { workspace = true }
alloy = { workspace = true }
tracing = { workspace = true }
subprocess = { workspace = true }
tokio = { workspace = true }
revive-dt-node-interaction = { workspace = true }
+7 -11
View File
@@ -5,7 +5,7 @@ use std::{
fs::{File, OpenOptions, create_dir_all, remove_dir_all},
io::{BufRead, BufReader, Read, Write},
path::PathBuf,
process::{Command, Stdio},
process::{Child, Command, Stdio},
sync::{
Mutex,
atomic::{AtomicU32, Ordering},
@@ -27,7 +27,6 @@ use revive_dt_node_interaction::{
EthereumNode, nonce::fetch_onchain_nonce, trace::trace_transaction,
transaction::execute_transaction,
};
use subprocess::{Exec, Popen};
use tracing::Level;
use crate::Node;
@@ -49,7 +48,7 @@ pub struct Instance {
logs_directory: PathBuf,
geth: PathBuf,
id: u32,
handle: Option<Popen>,
handle: Option<Child>,
network_id: u64,
start_timeout: u64,
wallet: EthereumWallet,
@@ -122,7 +121,7 @@ impl Instance {
.clone()
.open(self.geth_stdout_log_file_path())?;
let stderr_logs_file = open_options.open(self.geth_stderr_log_file_path())?;
self.handle = Exec::cmd(&self.geth)
self.handle = Command::new(&self.geth)
.arg("--dev")
.arg("--datadir")
.arg(&self.data_directory)
@@ -135,7 +134,7 @@ impl Instance {
.arg("0")
.stderr(stderr_logs_file)
.stdout(stdout_logs_file)
.popen()?
.spawn()?
.into();
if let Err(error) = self.wait_ready() {
@@ -362,12 +361,9 @@ impl Node for Instance {
fn shutdown(&mut self) -> anyhow::Result<()> {
// Terminate the processes in a graceful manner to allow for the output to be flushed.
if let Some(mut child) = self.handle.take() {
child.terminate().map_err(|error| {
anyhow::anyhow!("Failed to terminate the geth process: {error:?}")
})?;
child.wait().map_err(|error| {
anyhow::anyhow!("Failed to wait for the termination of the geth process: {error:?}")
})?;
child
.kill()
.map_err(|error| anyhow::anyhow!("Failed to kill the geth process: {error:?}"))?;
}
// Remove the node's database so that subsequent runs do not run on the same database. We
+12 -23
View File
@@ -3,7 +3,7 @@ use std::{
fs::{OpenOptions, create_dir_all, remove_dir_all},
io::BufRead,
path::{Path, PathBuf},
process::{Command, Stdio},
process::{Child, Command, Stdio},
sync::{
Mutex,
atomic::{AtomicU32, Ordering},
@@ -30,7 +30,6 @@ use serde::{Deserialize, Serialize};
use serde_json::{Value as JsonValue, json};
use sp_core::crypto::Ss58Codec;
use sp_runtime::AccountId32;
use subprocess::{Exec, Popen};
use tracing::Level;
use revive_dt_config::Arguments;
@@ -52,8 +51,8 @@ pub struct KitchensinkNode {
wallet: EthereumWallet,
base_directory: PathBuf,
logs_directory: PathBuf,
process_substrate: Option<Popen>,
process_proxy: Option<Popen>,
process_substrate: Option<Child>,
process_proxy: Option<Child>,
nonces: Mutex<HashMap<Address, u64>>,
}
@@ -160,7 +159,7 @@ impl KitchensinkNode {
let stderr_logs_file = open_options
.clone()
.open(self.kitchensink_stderr_log_file_path())?;
self.process_substrate = Exec::cmd(&self.substrate_binary)
self.process_substrate = Command::new(&self.substrate_binary)
.arg("--chain")
.arg(chainspec_path)
.arg("--base-path")
@@ -177,7 +176,7 @@ impl KitchensinkNode {
.env("RUST_LOG", Self::SUBSTRATE_LOG_ENV)
.stdout(stdout_logs_file)
.stderr(stderr_logs_file)
.popen()?
.spawn()?
.into();
// Give the node a moment to boot
@@ -198,7 +197,7 @@ impl KitchensinkNode {
.clone()
.open(self.proxy_stdout_log_file_path())?;
let stderr_logs_file = open_options.open(self.proxy_stderr_log_file_path())?;
self.process_proxy = Exec::cmd(&self.eth_proxy_binary)
self.process_proxy = Command::new(&self.eth_proxy_binary)
.arg("--dev")
.arg("--rpc-port")
.arg(proxy_rpc_port.to_string())
@@ -211,7 +210,7 @@ impl KitchensinkNode {
// don't have to worry about either streams overriding each other.
.stdout(stdout_logs_file)
.stderr(stderr_logs_file)
.popen()?
.spawn()?
.into();
if let Err(error) = Self::wait_ready(
@@ -434,23 +433,13 @@ impl Node for KitchensinkNode {
fn shutdown(&mut self) -> anyhow::Result<()> {
// Terminate the processes in a graceful manner to allow for the output to be flushed.
if let Some(mut child) = self.process_proxy.take() {
child.terminate().map_err(|error| {
anyhow::anyhow!("Failed to terminate the proxy process: {error:?}")
})?;
child.wait().map_err(|error| {
anyhow::anyhow!(
"Failed to wait for the termination of the proxy process: {error:?}"
)
})?;
child
.kill()
.map_err(|error| anyhow::anyhow!("Failed to kill the proxy process: {error:?}"))?;
}
if let Some(mut child) = self.process_substrate.take() {
child.terminate().map_err(|error| {
anyhow::anyhow!("Failed to terminate the substrate process: {error:?}")
})?;
child.wait().map_err(|error| {
anyhow::anyhow!(
"Failed to wait for the termination of the substrate process: {error:?}"
)
child.kill().map_err(|error| {
anyhow::anyhow!("Failed to kill the substrate process: {error:?}")
})?;
}