From e9fabd26341be71a9b630d16ab07804408fa9eee Mon Sep 17 00:00:00 2001 From: Marios Christou Date: Mon, 22 Sep 2025 18:45:27 +0300 Subject: [PATCH] Basic zombie node definition --- Cargo.toml | 2 + crates/node/Cargo.toml | 1 + crates/node/src/lib.rs | 1 + crates/node/src/zombie.rs | 163 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 crates/node/src/zombie.rs diff --git a/Cargo.toml b/Cargo.toml index 32c59f2..bf36b39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,8 @@ revive-solc-json-interface = { git = "https://github.com/paritytech/revive", rev revive-common = { git = "https://github.com/paritytech/revive", rev = "3389865af7c3ff6f29a586d82157e8bc573c1a8e" } revive-differential = { git = "https://github.com/paritytech/revive", rev = "3389865af7c3ff6f29a586d82157e8bc573c1a8e" } +zombienet-sdk = { git = "https://github.com/paritytech/zombienet-sdk.git", rev ="891f6554354ce466abd496366dbf8b4f82141241" } + [workspace.dependencies.alloy] version = "1.0.22" default-features = false diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index d482621..4c8f8ce 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -27,6 +27,7 @@ serde_yaml_ng = { workspace = true } sp-core = { workspace = true } sp-runtime = { workspace = true } +zombienet-sdk = { workspace = true } [dev-dependencies] temp-dir = { workspace = true } diff --git a/crates/node/src/lib.rs b/crates/node/src/lib.rs index 5cbedf8..e5b9022 100644 --- a/crates/node/src/lib.rs +++ b/crates/node/src/lib.rs @@ -9,6 +9,7 @@ pub mod geth; pub mod lighthouse_geth; pub mod process; pub mod substrate; +pub mod zombie; /// An abstract interface for testing nodes. pub trait Node: EthereumNode { diff --git a/crates/node/src/zombie.rs b/crates/node/src/zombie.rs new file mode 100644 index 0000000..cad6dd5 --- /dev/null +++ b/crates/node/src/zombie.rs @@ -0,0 +1,163 @@ +use std::{ + fs::{File, OpenOptions, create_dir_all, remove_dir_all}, + io::{BufRead, Write}, + path::{Path, PathBuf}, + pin::Pin, + process::{Child, Command, Stdio}, + sync::{ + Arc, + atomic::{AtomicU32, Ordering}, + }, + time::Duration, +}; + +use alloy::{ + consensus::{BlockHeader, TxEnvelope}, + eips::BlockNumberOrTag, + genesis::{Genesis, GenesisAccount}, + network::{ + Ethereum, EthereumWallet, Network, NetworkWallet, TransactionBuilder, + TransactionBuilderError, UnbuiltTransactionError, + }, + primitives::{ + Address, B64, B256, BlockHash, BlockNumber, BlockTimestamp, Bloom, Bytes, StorageKey, + TxHash, U256, + }, + providers::{ + Provider, ProviderBuilder, + ext::DebugApi, + fillers::{CachedNonceManager, ChainIdFiller, FillProvider, NonceFiller, TxFiller}, + }, + rpc::types::{ + EIP1186AccountProofResponse, TransactionReceipt, + eth::{Block, Header, Transaction}, + trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, + }, +}; +use anyhow::Context as _; +use revive_common::EVMVersion; +use revive_dt_common::fs::clear_directory; +use revive_dt_format::traits::ResolverApi; +use serde::{Deserialize, Serialize, de}; +use serde_json::{Value as JsonValue, json}; +use sp_core::crypto::Ss58Codec; +use sp_runtime::AccountId32; + +use revive_dt_config::*; +use revive_dt_node_interaction::EthereumNode; +use tracing::instrument; + +use crate::{Node, common::FallbackGasFiller, constants::INITIAL_BALANCE}; + +static NODE_COUNT: AtomicU32 = AtomicU32::new(0); + +#[derive(Debug, Default)] +pub struct ZombieNode { + id: u32, + node_binary: PathBuf, + export_chainspec_command: String, + connection_string: String, + base_directory: PathBuf, + logs_directory: PathBuf, + process_proxy: Option, + wallet: Arc, + nonce_manager: CachedNonceManager, + chain_id_filler: ChainIdFiller, + logs_file_to_flush: Vec, +} + +impl ZombieNode { + const BASE_DIRECTORY: &str = "zombienet"; + const DATA_DIRECTORY: &str = "data"; + const LOGS_DIRECTORY: &str = "logs"; + + const ZOMBIENET_STDOUT_LOG_FILE_NAME: &str = "node_stdout.log"; + const ZOMBIENET_STDERR_LOG_FILE_NAME: &str = "node_stderr.log"; + + pub fn new( + context: impl AsRef + + AsRef + + AsRef, + ) -> Self { + let working_directory_path = AsRef::::as_ref(&context); + let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst); + let base_directory = working_directory_path.as_path().join(Self::BASE_DIRECTORY); + let logs_directory = base_directory.join(Self::LOGS_DIRECTORY); + let wallet = AsRef::::as_ref(&context).wallet(); + + Self { + id, + base_directory, + logs_directory, + wallet, + logs_file_to_flush: Vec::with_capacity(2), + ..Default::default() + } + } + + fn init(&mut self, mut genesis: Genesis) -> anyhow::Result<&mut Self> { + todo!() + } + + fn spawn_process(&mut self) -> anyhow::Result<()> { + todo!() + } +} + +impl EthereumNode for ZombieNode { + fn id(&self) -> usize { + self.id as _ + } + + fn connection_string(&self) -> &str { + &self.connection_string + } + + fn execute_transaction( + &self, + transaction: alloy::rpc::types::TransactionRequest, + ) -> Pin> + '_>> { + todo!() + } + + fn trace_transaction( + &self, + tx_hash: TxHash, + trace_options: GethDebugTracingOptions, + ) -> Pin> + '_>> + { + todo!() + } + + fn state_diff( + &self, + tx_hash: TxHash, + ) -> Pin> + '_>> { + todo!() + } + + fn balance_of( + &self, + address: Address, + ) -> Pin> + '_>> { + todo!() + } + + fn latest_state_proof( + &self, + address: Address, + keys: Vec, + ) -> Pin> + '_>> { + todo!() + } + + fn resolver( + &self, + ) -> Pin>> + '_>> { + todo!() + } + + fn evm_version(&self) -> EVMVersion { + todo!() + } +}