Skip to content

Commit

Permalink
Add two-way storage compare
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirpashaa committed Nov 7, 2024
1 parent ced4d2d commit ae4a3b7
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/telos/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ reth-chainspec.workspace = true
reth-provider.workspace = true
reth-node-telos.workspace = true
reth-telos-rpc.workspace = true
reth-db.workspace = true
alloy-primitives.workspace = true


clap = { workspace = true, features = ["derive", "env"] }
Expand Down
35 changes: 35 additions & 0 deletions crates/telos/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();

use clap::Parser;
use tracing::{info, warn};
use reth::args::utils::EthereumChainSpecParser;
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
use reth::cli::Cli;
use reth_node_telos::{TelosArgs, TelosNode};
use reth_node_telos::node::TelosAddOns;
use reth_provider::providers::BlockchainProvider2;
use reth_telos_rpc::TelosClient;
use reth::primitives::BlockId;
use reth::rpc::types::BlockNumberOrTag;
use reth_provider::{DatabaseProviderFactory, StateProviderFactory};
use reth_db::{PlainAccountState, PlainStorageState};


#[cfg(feature = "telos")]
Expand Down Expand Up @@ -45,6 +50,10 @@ fn main() {
handle.node_exit_future.await
},
false => {
let two_way_storage_compare = telos_args.two_way_storage_compare.clone();
let telos_rpc = telos_args.telos_endpoint.clone();
let block_delta = telos_args.block_delta.clone();

let handle = builder
.node(TelosNode::new(telos_args.clone()))
.extend_rpc_modules(move |ctx| {
Expand All @@ -59,6 +68,32 @@ fn main() {
.launch()
.await?;

match two_way_storage_compare {
true => {
if telos_rpc.is_none() {
warn!("Telos RPC Endpoint is not specified, skipping two-way storage compare");
} else if block_delta.is_none() {
warn!("Block delta is not specified, skipping two-way storage compare");
} else {
info!("Fetching account and accountstate from Telos native RPC (Can take a long time)...");

let (account_table, accountstate_table, block_number) = reth_node_telos::two_way_storage_compare::get_telos_tables(telos_rpc.unwrap().as_str(), block_delta.unwrap()).await;

info!("Two-way comparing state (Reth vs. Telos) at height: {:?}", block_number);

let state_at_specific_height = handle.node.provider.state_by_block_id(BlockId::Number(BlockNumberOrTag::Number(block_number.as_u64().unwrap()))).unwrap();
let plain_account_state = handle.node.provider.database_provider_ro().unwrap().table::<PlainAccountState>().unwrap();
let plain_storage_state = handle.node.provider.database_provider_ro().unwrap().table::<PlainStorageState>().unwrap();

let match_counter = reth_node_telos::two_way_storage_compare::two_side_state_compare(account_table, accountstate_table, state_at_specific_height, plain_account_state, plain_storage_state).await;
match_counter.print();

info!("Comparing done");
}
}
_ => {}
}

handle.node_exit_future.await
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/telos/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ reth-telos-rpc.workspace = true
reth-tracing.workspace = true
reth-transaction-pool.workspace = true
reth-telos-rpc-engine-api.workspace = true
alloy-primitives.workspace = true
reth-db.workspace = true

clap.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand Down
8 changes: 8 additions & 0 deletions crates/telos/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ pub struct TelosArgs {
/// a batch of downloaded blocks.
#[arg(long = "engine.max-execute-block-batch-size", requires = "experimental", default_value_t = DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE)]
pub max_execute_block_batch_size: usize,

/// Enable Two-way storage compare between reth and telos
#[arg(long = "telos.two_way_storage_compare", default_value = "false")]
pub two_way_storage_compare: bool,

/// Block delta between native and EVM
#[arg(long = "telos.block_delta")]
pub block_delta: Option<u32>,
}

impl From<TelosArgs> for TelosClientArgs {
Expand Down
1 change: 1 addition & 0 deletions crates/telos/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

pub mod args;
pub mod node;
pub mod two_way_storage_compare;

pub use crate::args::TelosArgs;
pub use crate::node::TelosNode;
Expand Down
Loading

0 comments on commit ae4a3b7

Please sign in to comment.