diff --git a/crates/telos/bin/src/main.rs b/crates/telos/bin/src/main.rs index 617ad27eadc8..7f660ee0ee31 100644 --- a/crates/telos/bin/src/main.rs +++ b/crates/telos/bin/src/main.rs @@ -4,7 +4,7 @@ static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator(); use clap::Parser; -use tracing::{info, warn}; +use tracing::{error, info, warn}; use reth::args::utils::EthereumChainSpecParser; use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher}; use reth::cli::Cli; @@ -20,6 +20,8 @@ use reth_db::{PlainAccountState, PlainStorageState}; #[cfg(feature = "telos")] fn main() { + use reth_provider::BlockNumReader; + reth_cli_util::sigsegv_handler::install(); // Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided. @@ -79,16 +81,20 @@ fn main() { 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); + if block_number.as_u64().unwrap() <= handle.node.provider.best_block_number().unwrap() { + 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::().unwrap(); - let plain_storage_state = handle.node.provider.database_provider_ro().unwrap().table::().unwrap(); + 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::().unwrap(); + let plain_storage_state = handle.node.provider.database_provider_ro().unwrap().table::().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(); + 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"); + info!("Comparing done"); + } else { + error!("Nodeos is ahead of reth, failed to compare state"); + } } } _ => {} diff --git a/crates/telos/node/src/two_way_storage_compare.rs b/crates/telos/node/src/two_way_storage_compare.rs index a88f1cadf784..e39c03d63f6d 100644 --- a/crates/telos/node/src/two_way_storage_compare.rs +++ b/crates/telos/node/src/two_way_storage_compare.rs @@ -288,14 +288,14 @@ pub async fn two_side_state_compare( pub async fn get_telos_tables(telos_rpc: &str, block_delta: u32) -> (HashMap, HashMap<(Address, B256), U256>, BlockId) { let api_client = APIClient::::default_provider(telos_rpc.into(), Some(5)).unwrap(); - let info = api_client.v1_chain.get_info().await.unwrap(); + let info_start = api_client.v1_chain.get_info().await.unwrap(); - let evm_block_num = info.head_block_num - block_delta; + let evm_block_num_start = info_start.head_block_num - block_delta; let mut has_more_account = true; let mut lower_bound_account = Some(TableIndexType::UINT64(0)); - let evm_block_id = BlockId::from(evm_block_num as u64); + let evm_block_id = BlockId::from(evm_block_num_start as u64); let mut account_table = HashMap::default(); let mut accountstate_table = HashMap::default(); @@ -356,5 +356,12 @@ pub async fn get_telos_tables(telos_rpc: &str, block_delta: u32) -> (HashMap