Skip to content

Commit

Permalink
Enabling live comparison for account table only
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirpashaa committed Nov 14, 2024
1 parent 200948c commit 228fbc5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
36 changes: 18 additions & 18 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,24 @@ where
new_addresses_using_create_iter.next();
}

// #[cfg(feature = "telos")]
// {
// // Perform state diff comparision
// let revm_state_diffs = evm.db_mut().transition_state.clone().unwrap_or_default().transitions;
// let block_num = block.block.header.number;
// println!(
// "Compare: block {block_num} {}",
// compare_state_diffs(
// &mut evm,
// revm_state_diffs,
// unwrapped_telos_extra_fields.statediffs_account.clone().unwrap_or_default(),
// unwrapped_telos_extra_fields.statediffs_accountstate.clone().unwrap_or_default(),
// unwrapped_telos_extra_fields.new_addresses_using_create.clone().unwrap_or_default(),
// unwrapped_telos_extra_fields.new_addresses_using_openwallet.clone().unwrap_or_default(),
// false
// )
// );
// }
#[cfg(feature = "telos")]
{
// Perform state diff comparision
let revm_state_diffs = evm.db_mut().transition_state.clone().unwrap_or_default().transitions;
let block_num = block.block.header.number;
println!(
"Compare: block {block_num} {}",
compare_state_diffs(
&mut evm,
revm_state_diffs,
unwrapped_telos_extra_fields.statediffs_account.clone().unwrap_or_default(),
unwrapped_telos_extra_fields.statediffs_accountstate.clone().unwrap_or_default(),
unwrapped_telos_extra_fields.new_addresses_using_create.clone().unwrap_or_default(),
unwrapped_telos_extra_fields.new_addresses_using_openwallet.clone().unwrap_or_default(),
true
)
);
}

#[cfg(feature = "telos")]
let receipts = if unwrapped_telos_extra_fields.receipts.is_some() {
Expand Down
80 changes: 40 additions & 40 deletions crates/telos/rpc-engine-api/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ where
for row in &statediffs_account {
statediffs_account_hashmap.insert(row.address);
}
let mut statediffs_accountstate_hashmap = HashSet::new();
for row in &statediffs_accountstate {
statediffs_accountstate_hashmap.insert((row.address,row.key));
}
// let mut statediffs_accountstate_hashmap = HashSet::new();
// for row in &statediffs_accountstate {
// statediffs_accountstate_hashmap.insert((row.address,row.key));
// }

for row in &statediffs_account {
// Skip if address is created using openwallet and is empty
Expand Down Expand Up @@ -239,37 +239,37 @@ where
}
}
}
for row in &statediffs_accountstate {
if let None = revm_db.cache.accounts.get_mut(&row.address) {
let cached_account = revm_db.load_cache_account(row.address);
match cached_account {
Ok(cached_account) => {
if cached_account.account.is_none() {
panic!("An account state modification was made for an account that is not in revm storage, address: {:?}", row.address);
}
},
Err(_) => {
panic!("An account state modification was made for an account that returned Err from load_cache_account, address: {:?}", row.address);
}
}
}
if let Ok(revm_row) = revm_db.storage(row.address, row.key) {
// The values should match, but if it is removed, then the revm value should be zero
if revm_row != row.value {
if revm_row != U256::ZERO && row.removed == true {
maybe_panic!(panic_mode, "Difference in value on revm storage, removed on Telos, non-ZERO on revm, address: {:?}, key: {:?}, revm-value: {:?}, tevm-row: {:?}", row.address, row.key, revm_row, row);
state_override.override_storage(revm_db, row.address, row.key, U256::ZERO, revm_row);
}
if row.removed == false {
maybe_panic!(panic_mode, "Difference in value on revm storage, address: {:?}, key: {:?}, revm-value: {:?}, tevm-row: {:?}", row.address, row.key, revm_row, row);
state_override.override_storage(revm_db, row.address, row.key, row.value, revm_row);
}
}
} else {
maybe_panic!(panic_mode, "Key was not found on revm storage, address: {:?}, key: {:?}",row.address,row.key);
state_override.override_storage(revm_db, row.address, row.key, row.value, U256::ZERO);
}
}
// for row in &statediffs_accountstate {
// if let None = revm_db.cache.accounts.get_mut(&row.address) {
// let cached_account = revm_db.load_cache_account(row.address);
// match cached_account {
// Ok(cached_account) => {
// if cached_account.account.is_none() {
// panic!("An account state modification was made for an account that is not in revm storage, address: {:?}", row.address);
// }
// },
// Err(_) => {
// panic!("An account state modification was made for an account that returned Err from load_cache_account, address: {:?}", row.address);
// }
// }
// }
// if let Ok(revm_row) = revm_db.storage(row.address, row.key) {
// // The values should match, but if it is removed, then the revm value should be zero
// if revm_row != row.value {
// if revm_row != U256::ZERO && row.removed == true {
// maybe_panic!(panic_mode, "Difference in value on revm storage, removed on Telos, non-ZERO on revm, address: {:?}, key: {:?}, revm-value: {:?}, tevm-row: {:?}", row.address, row.key, revm_row, row);
// state_override.override_storage(revm_db, row.address, row.key, U256::ZERO, revm_row);
// }
// if row.removed == false {
// maybe_panic!(panic_mode, "Difference in value on revm storage, address: {:?}, key: {:?}, revm-value: {:?}, tevm-row: {:?}", row.address, row.key, revm_row, row);
// state_override.override_storage(revm_db, row.address, row.key, row.value, revm_row);
// }
// }
// } else {
// maybe_panic!(panic_mode, "Key was not found on revm storage, address: {:?}, key: {:?}",row.address,row.key);
// state_override.override_storage(revm_db, row.address, row.key, row.value, U256::ZERO);
// }
// }

for (address, account) in &revm_state_diffs {
if let (Some(info),Some(previous_info)) = (account.info.clone(),account.previous_info.clone()) {
Expand All @@ -283,11 +283,11 @@ where
panic!("A modified address was not found on tevm state diffs, info/previous_info were not Some, address: {:?}",address);
}
}
for (key,_) in account.storage.clone() {
if statediffs_accountstate_hashmap.get(&(*address,key)).is_none() {
panic!("A modified storage slot was not found on tevm state diffs, address: {:?}",address);
}
}
// for (key,_) in account.storage.clone() {
// if statediffs_accountstate_hashmap.get(&(*address,key)).is_none() {
// panic!("A modified storage slot was not found on tevm state diffs, address: {:?}",address);
// }
// }
}

state_override.apply(revm_db);
Expand Down

0 comments on commit 228fbc5

Please sign in to comment.