mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-07-20 14:35:44 +00:00
Separate stdout and stderr and use more consts.
This commit is contained in:
+31
-14
@@ -28,6 +28,7 @@ use revive_dt_node_interaction::{
|
|||||||
transaction::execute_transaction,
|
transaction::execute_transaction,
|
||||||
};
|
};
|
||||||
use subprocess::{Exec, Popen};
|
use subprocess::{Exec, Popen};
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
use crate::Node;
|
use crate::Node;
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ pub struct Instance {
|
|||||||
connection_string: String,
|
connection_string: String,
|
||||||
base_directory: PathBuf,
|
base_directory: PathBuf,
|
||||||
data_directory: PathBuf,
|
data_directory: PathBuf,
|
||||||
|
logs_directory: PathBuf,
|
||||||
geth: PathBuf,
|
geth: PathBuf,
|
||||||
id: u32,
|
id: u32,
|
||||||
handle: Option<Popen>,
|
handle: Option<Popen>,
|
||||||
@@ -57,6 +59,7 @@ pub struct Instance {
|
|||||||
impl Instance {
|
impl Instance {
|
||||||
const BASE_DIRECTORY: &str = "geth";
|
const BASE_DIRECTORY: &str = "geth";
|
||||||
const DATA_DIRECTORY: &str = "data";
|
const DATA_DIRECTORY: &str = "data";
|
||||||
|
const LOGS_DIRECTORY: &str = "logs";
|
||||||
|
|
||||||
const IPC_FILE: &str = "geth.ipc";
|
const IPC_FILE: &str = "geth.ipc";
|
||||||
const GENESIS_JSON_FILE: &str = "genesis.json";
|
const GENESIS_JSON_FILE: &str = "genesis.json";
|
||||||
@@ -64,11 +67,14 @@ impl Instance {
|
|||||||
const READY_MARKER: &str = "IPC endpoint opened";
|
const READY_MARKER: &str = "IPC endpoint opened";
|
||||||
const ERROR_MARKER: &str = "Fatal:";
|
const ERROR_MARKER: &str = "Fatal:";
|
||||||
|
|
||||||
|
const GETH_STDOUT_LOG_FILE_NAME: &str = "node_stdout.log";
|
||||||
|
const GETH_STDERR_LOG_FILE_NAME: &str = "node_stderr.log";
|
||||||
|
|
||||||
/// Create the node directory and call `geth init` to configure the genesis.
|
/// Create the node directory and call `geth init` to configure the genesis.
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn init(&mut self, genesis: String) -> anyhow::Result<&mut Self> {
|
fn init(&mut self, genesis: String) -> anyhow::Result<&mut Self> {
|
||||||
create_dir_all(&self.base_directory)?;
|
create_dir_all(&self.base_directory)?;
|
||||||
create_dir_all(self.base_directory.join("logs"))?;
|
create_dir_all(&self.logs_directory)?;
|
||||||
|
|
||||||
let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE);
|
let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE);
|
||||||
File::create(&genesis_path)?.write_all(genesis.as_bytes())?;
|
File::create(&genesis_path)?.write_all(genesis.as_bytes())?;
|
||||||
@@ -101,15 +107,19 @@ impl Instance {
|
|||||||
/// [Instance::init] must be called prior.
|
/// [Instance::init] must be called prior.
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn spawn_process(&mut self) -> anyhow::Result<&mut Self> {
|
fn spawn_process(&mut self) -> anyhow::Result<&mut Self> {
|
||||||
let node_logs_file_path = self.base_directory.join("logs").join("node.log");
|
// Options to re-create and re-write to the file starting at offset zero. We do not want to
|
||||||
let node_logs_file = OpenOptions::new()
|
// re-use log files between runs. Users that want to keep their log files should pass in a
|
||||||
// Options to re-create and re-write to the file starting at offset zero. We do not want
|
// different working directory between runs.
|
||||||
// to re-use log files between runs. Users that want to keep their log files should pass
|
let stdout_logs_file = OpenOptions::new()
|
||||||
// in a different working directory between runs.
|
|
||||||
.create(true)
|
.create(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.open(&node_logs_file_path)?;
|
.open(self.geth_stdout_log_file_path())?;
|
||||||
|
let stderr_logs_file = OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.write(true)
|
||||||
|
.open(self.geth_stderr_log_file_path())?;
|
||||||
self.handle = Exec::cmd(&self.geth)
|
self.handle = Exec::cmd(&self.geth)
|
||||||
.arg("--dev")
|
.arg("--dev")
|
||||||
.arg("--datadir")
|
.arg("--datadir")
|
||||||
@@ -121,12 +131,8 @@ impl Instance {
|
|||||||
.arg("--nodiscover")
|
.arg("--nodiscover")
|
||||||
.arg("--maxpeers")
|
.arg("--maxpeers")
|
||||||
.arg("0")
|
.arg("0")
|
||||||
// We pipe both stdout and stderr to the same log file and therefore we're persisting
|
.stderr(stderr_logs_file)
|
||||||
// both. In the implementation of [`std::fs::File`] the `try_clone` method will ensure
|
.stdout(stdout_logs_file)
|
||||||
// that both [`std::fs::File`] objects have the same seeks and offsets and therefore we
|
|
||||||
// don't have to worry about either streams overriding each other.
|
|
||||||
.stderr(node_logs_file.try_clone()?)
|
|
||||||
.stdout(node_logs_file)
|
|
||||||
.popen()?
|
.popen()?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
@@ -151,7 +157,7 @@ impl Instance {
|
|||||||
.write(false)
|
.write(false)
|
||||||
.append(false)
|
.append(false)
|
||||||
.truncate(false)
|
.truncate(false)
|
||||||
.open(self.base_directory.join("logs").join("node.log"))?;
|
.open(self.geth_stderr_log_file_path())?;
|
||||||
|
|
||||||
let maximum_wait_time = Duration::from_millis(self.start_timeout);
|
let maximum_wait_time = Duration::from_millis(self.start_timeout);
|
||||||
let mut stderr = BufReader::new(logs_file).lines();
|
let mut stderr = BufReader::new(logs_file).lines();
|
||||||
@@ -169,6 +175,16 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id), level = Level::TRACE)]
|
||||||
|
fn geth_stdout_log_file_path(&self) -> PathBuf {
|
||||||
|
self.logs_directory.join(Self::GETH_STDOUT_LOG_FILE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id), level = Level::TRACE)]
|
||||||
|
fn geth_stderr_log_file_path(&self) -> PathBuf {
|
||||||
|
self.logs_directory.join(Self::GETH_STDERR_LOG_FILE_NAME)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthereumNode for Instance {
|
impl EthereumNode for Instance {
|
||||||
@@ -323,6 +339,7 @@ impl Node for Instance {
|
|||||||
Self {
|
Self {
|
||||||
connection_string: base_directory.join(Self::IPC_FILE).display().to_string(),
|
connection_string: base_directory.join(Self::IPC_FILE).display().to_string(),
|
||||||
data_directory: base_directory.join(Self::DATA_DIRECTORY),
|
data_directory: base_directory.join(Self::DATA_DIRECTORY),
|
||||||
|
logs_directory: base_directory.join(Self::LOGS_DIRECTORY),
|
||||||
base_directory,
|
base_directory,
|
||||||
geth: config.geth.clone(),
|
geth: config.geth.clone(),
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -30,13 +30,14 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json::{Value as JsonValue, json};
|
use serde_json::{Value as JsonValue, json};
|
||||||
use sp_core::crypto::Ss58Codec;
|
use sp_core::crypto::Ss58Codec;
|
||||||
use sp_runtime::AccountId32;
|
use sp_runtime::AccountId32;
|
||||||
|
use subprocess::{Exec, Popen};
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
use revive_dt_node_interaction::{
|
use revive_dt_node_interaction::{
|
||||||
EthereumNode, nonce::fetch_onchain_nonce, trace::trace_transaction,
|
EthereumNode, nonce::fetch_onchain_nonce, trace::trace_transaction,
|
||||||
transaction::execute_transaction,
|
transaction::execute_transaction,
|
||||||
};
|
};
|
||||||
use subprocess::{Exec, Popen};
|
|
||||||
|
|
||||||
use crate::Node;
|
use crate::Node;
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ pub struct KitchensinkNode {
|
|||||||
rpc_url: String,
|
rpc_url: String,
|
||||||
wallet: EthereumWallet,
|
wallet: EthereumWallet,
|
||||||
base_directory: PathBuf,
|
base_directory: PathBuf,
|
||||||
|
logs_directory: PathBuf,
|
||||||
process_substrate: Option<Popen>,
|
process_substrate: Option<Popen>,
|
||||||
process_proxy: Option<Popen>,
|
process_proxy: Option<Popen>,
|
||||||
nonces: Mutex<HashMap<Address, u64>>,
|
nonces: Mutex<HashMap<Address, u64>>,
|
||||||
@@ -57,6 +59,8 @@ pub struct KitchensinkNode {
|
|||||||
|
|
||||||
impl KitchensinkNode {
|
impl KitchensinkNode {
|
||||||
const BASE_DIRECTORY: &str = "kitchensink";
|
const BASE_DIRECTORY: &str = "kitchensink";
|
||||||
|
const LOGS_DIRECTORY: &str = "logs";
|
||||||
|
|
||||||
const SUBSTRATE_READY_MARKER: &str = "Running JSON-RPC server";
|
const SUBSTRATE_READY_MARKER: &str = "Running JSON-RPC server";
|
||||||
const ETH_PROXY_READY_MARKER: &str = "Running JSON-RPC server";
|
const ETH_PROXY_READY_MARKER: &str = "Running JSON-RPC server";
|
||||||
const CHAIN_SPEC_JSON_FILE: &str = "template_chainspec.json";
|
const CHAIN_SPEC_JSON_FILE: &str = "template_chainspec.json";
|
||||||
@@ -66,10 +70,16 @@ impl KitchensinkNode {
|
|||||||
const SUBSTRATE_LOG_ENV: &str = "error,evm=debug,sc_rpc_server=info,runtime::revive=debug";
|
const SUBSTRATE_LOG_ENV: &str = "error,evm=debug,sc_rpc_server=info,runtime::revive=debug";
|
||||||
const PROXY_LOG_ENV: &str = "info,eth-rpc=debug";
|
const PROXY_LOG_ENV: &str = "info,eth-rpc=debug";
|
||||||
|
|
||||||
|
const KITCHENSINK_STDOUT_LOG_FILE_NAME: &str = "node_stdout.log";
|
||||||
|
const KITCHENSINK_STDERR_LOG_FILE_NAME: &str = "node_stderr.log";
|
||||||
|
|
||||||
|
const PROXY_STDOUT_LOG_FILE_NAME: &str = "proxy_stdout.log";
|
||||||
|
const PROXY_STDERR_LOG_FILE_NAME: &str = "proxy_stderr.log";
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
||||||
fn init(&mut self, genesis: &str) -> anyhow::Result<&mut Self> {
|
fn init(&mut self, genesis: &str) -> anyhow::Result<&mut Self> {
|
||||||
create_dir_all(&self.base_directory)?;
|
create_dir_all(&self.base_directory)?;
|
||||||
create_dir_all(self.base_directory.join("logs"))?;
|
create_dir_all(&self.logs_directory)?;
|
||||||
|
|
||||||
let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
|
let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
|
||||||
|
|
||||||
@@ -132,18 +142,24 @@ impl KitchensinkNode {
|
|||||||
|
|
||||||
let chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
|
let chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
|
||||||
|
|
||||||
let logs_directory_path = self.base_directory.join("logs");
|
// This is the `OpenOptions` that we wish to use for all of the log files that we will be
|
||||||
|
// opening in this method. We need to construct it in this way to:
|
||||||
|
// 1. Be consistent
|
||||||
|
// 2. Less verbose and more dry
|
||||||
|
// 3. Because the builder pattern uses mutable references so we need to get around that.
|
||||||
|
let open_options = {
|
||||||
|
let mut options = OpenOptions::new();
|
||||||
|
options.create(true).truncate(true).write(true);
|
||||||
|
options
|
||||||
|
};
|
||||||
|
|
||||||
// Start Substrate node
|
// Start Substrate node
|
||||||
let substrate_logs_file_path = logs_directory_path.join("node.log");
|
let stdout_logs_file = open_options
|
||||||
let substrate_logs_file = OpenOptions::new()
|
.clone()
|
||||||
// Options to re-create and re-write to the file starting at offset zero. We do not want
|
.open(self.kitchensink_stdout_log_file_path())?;
|
||||||
// to re-use log files between runs. Users that want to keep their log files should pass
|
let stderr_logs_file = open_options
|
||||||
// in a different working directory between runs.
|
.clone()
|
||||||
.create(true)
|
.open(self.kitchensink_stderr_log_file_path())?;
|
||||||
.truncate(true)
|
|
||||||
.write(true)
|
|
||||||
.open(&substrate_logs_file_path)?;
|
|
||||||
self.process_substrate = Exec::cmd(&self.substrate_binary)
|
self.process_substrate = Exec::cmd(&self.substrate_binary)
|
||||||
.arg("--chain")
|
.arg("--chain")
|
||||||
.arg(chainspec_path)
|
.arg(chainspec_path)
|
||||||
@@ -159,18 +175,14 @@ impl KitchensinkNode {
|
|||||||
.arg("--rpc-cors")
|
.arg("--rpc-cors")
|
||||||
.arg("all")
|
.arg("all")
|
||||||
.env("RUST_LOG", Self::SUBSTRATE_LOG_ENV)
|
.env("RUST_LOG", Self::SUBSTRATE_LOG_ENV)
|
||||||
// We pipe both stdout and stderr to the same log file and therefore we're persisting
|
.stdout(stdout_logs_file)
|
||||||
// both. In the implementation of [`std::fs::File`] the `try_clone` method will ensure
|
.stderr(stderr_logs_file)
|
||||||
// that both [`std::fs::File`] objects have the same seeks and offsets and therefore we
|
|
||||||
// don't have to worry about either streams overriding each other.
|
|
||||||
.stdout(substrate_logs_file.try_clone()?)
|
|
||||||
.stderr(substrate_logs_file)
|
|
||||||
.popen()?
|
.popen()?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
// Give the node a moment to boot
|
// Give the node a moment to boot
|
||||||
if let Err(error) = Self::wait_ready(
|
if let Err(error) = Self::wait_ready(
|
||||||
substrate_logs_file_path.as_path(),
|
self.kitchensink_stderr_log_file_path().as_path(),
|
||||||
Self::SUBSTRATE_READY_MARKER,
|
Self::SUBSTRATE_READY_MARKER,
|
||||||
Duration::from_secs(30),
|
Duration::from_secs(30),
|
||||||
) {
|
) {
|
||||||
@@ -182,15 +194,10 @@ impl KitchensinkNode {
|
|||||||
return Err(error);
|
return Err(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
let proxy_logs_file_path = logs_directory_path.join("proxy.log");
|
let stdout_logs_file = open_options
|
||||||
let proxy_logs_file = OpenOptions::new()
|
.clone()
|
||||||
// Options to re-create and re-write to the file starting at offset zero. We do not want
|
.open(self.proxy_stdout_log_file_path())?;
|
||||||
// to re-use log files between runs. Users that want to keep their log files should pass
|
let stderr_logs_file = open_options.open(self.proxy_stderr_log_file_path())?;
|
||||||
// in a different working directory between runs.
|
|
||||||
.create(true)
|
|
||||||
.truncate(true)
|
|
||||||
.write(true)
|
|
||||||
.open(&proxy_logs_file_path)?;
|
|
||||||
self.process_proxy = Exec::cmd(&self.eth_proxy_binary)
|
self.process_proxy = Exec::cmd(&self.eth_proxy_binary)
|
||||||
.arg("--dev")
|
.arg("--dev")
|
||||||
.arg("--rpc-port")
|
.arg("--rpc-port")
|
||||||
@@ -202,13 +209,13 @@ impl KitchensinkNode {
|
|||||||
// both. In the implementation of [`std::fs::File`] the `try_clone` method will ensure
|
// both. In the implementation of [`std::fs::File`] the `try_clone` method will ensure
|
||||||
// that both [`std::fs::File`] objects have the same seeks and offsets and therefore we
|
// that both [`std::fs::File`] objects have the same seeks and offsets and therefore we
|
||||||
// don't have to worry about either streams overriding each other.
|
// don't have to worry about either streams overriding each other.
|
||||||
.stdout(proxy_logs_file.try_clone()?)
|
.stdout(stdout_logs_file)
|
||||||
.stderr(proxy_logs_file)
|
.stderr(stderr_logs_file)
|
||||||
.popen()?
|
.popen()?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
if let Err(error) = Self::wait_ready(
|
if let Err(error) = Self::wait_ready(
|
||||||
proxy_logs_file_path.as_path(),
|
self.proxy_stderr_log_file_path().as_path(),
|
||||||
Self::ETH_PROXY_READY_MARKER,
|
Self::ETH_PROXY_READY_MARKER,
|
||||||
Duration::from_secs(30),
|
Duration::from_secs(30),
|
||||||
) {
|
) {
|
||||||
@@ -295,6 +302,28 @@ impl KitchensinkNode {
|
|||||||
.stdout;
|
.stdout;
|
||||||
Ok(String::from_utf8_lossy(&output).trim().to_string())
|
Ok(String::from_utf8_lossy(&output).trim().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
||||||
|
fn kitchensink_stdout_log_file_path(&self) -> PathBuf {
|
||||||
|
self.logs_directory
|
||||||
|
.join(Self::KITCHENSINK_STDOUT_LOG_FILE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
||||||
|
fn kitchensink_stderr_log_file_path(&self) -> PathBuf {
|
||||||
|
self.logs_directory
|
||||||
|
.join(Self::KITCHENSINK_STDERR_LOG_FILE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
||||||
|
fn proxy_stdout_log_file_path(&self) -> PathBuf {
|
||||||
|
self.logs_directory.join(Self::PROXY_STDOUT_LOG_FILE_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
||||||
|
fn proxy_stderr_log_file_path(&self) -> PathBuf {
|
||||||
|
self.logs_directory.join(Self::PROXY_STDERR_LOG_FILE_NAME)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthereumNode for KitchensinkNode {
|
impl EthereumNode for KitchensinkNode {
|
||||||
@@ -380,6 +409,7 @@ impl Node for KitchensinkNode {
|
|||||||
let kitchensink_directory = config.directory().join(Self::BASE_DIRECTORY);
|
let kitchensink_directory = config.directory().join(Self::BASE_DIRECTORY);
|
||||||
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
|
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
|
||||||
let base_directory = kitchensink_directory.join(id.to_string());
|
let base_directory = kitchensink_directory.join(id.to_string());
|
||||||
|
let logs_directory = base_directory.join(Self::LOGS_DIRECTORY);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
@@ -388,6 +418,7 @@ impl Node for KitchensinkNode {
|
|||||||
rpc_url: String::new(),
|
rpc_url: String::new(),
|
||||||
wallet: config.wallet(),
|
wallet: config.wallet(),
|
||||||
base_directory,
|
base_directory,
|
||||||
|
logs_directory,
|
||||||
process_substrate: None,
|
process_substrate: None,
|
||||||
process_proxy: None,
|
process_proxy: None,
|
||||||
nonces: Mutex::new(HashMap::new()),
|
nonces: Mutex::new(HashMap::new()),
|
||||||
|
|||||||
Reference in New Issue
Block a user