Skip to content

Commit

Permalink
Add more checks to two-way storage compare
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirpashaa committed Nov 13, 2024
1 parent ca62b6a commit 2e91fe1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
22 changes: 14 additions & 8 deletions crates/telos/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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::<PlainAccountState>().unwrap();
let plain_storage_state = handle.node.provider.database_provider_ro().unwrap().table::<PlainStorageState>().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::<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();
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");
}
}
}
_ => {}
Expand Down
13 changes: 10 additions & 3 deletions crates/telos/node/src/two_way_storage_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,14 @@ pub async fn two_side_state_compare(
pub async fn get_telos_tables(telos_rpc: &str, block_delta: u32) -> (HashMap<Address, Account>, HashMap<(Address, B256), U256>, BlockId) {

let api_client = APIClient::<DefaultProvider>::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();
Expand Down Expand Up @@ -356,5 +356,12 @@ pub async fn get_telos_tables(telos_rpc: &str, block_delta: u32) -> (HashMap<Add
}
}

let info_end = api_client.v1_chain.get_info().await.unwrap();
let evm_block_num_end = info_end.head_block_num - block_delta;

if evm_block_num_start != evm_block_num_end {
panic!("Nodeos is syncing, it is impossible to get an accurate state from a syncing native RPC");
}

(account_table, accountstate_table, evm_block_id)
}

0 comments on commit 2e91fe1

Please sign in to comment.