Skip to content

Commit

Permalink
chore(blockifier_reexecution): offline reexecution from file
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware committed Nov 6, 2024
1 parent 2070e7b commit f8eb0c3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use blockifier_reexecution::state_reader::reexecution_state_reader::ReexecutionS
use blockifier_reexecution::state_reader::test_state_reader::{
ConsecutiveStateReaders,
ConsecutiveTestStateReaders,
OfflineConsecutiveStateReaders,
SerializableOfflineReexecutionData,
};
use blockifier_reexecution::state_reader::utils::JSON_RPC_VERSION;
Expand Down Expand Up @@ -52,6 +53,18 @@ enum Command {
#[clap(long, default_value = None)]
directory_path: Option<String>,
},

// Reexecutes the block from JSON files.
ReexecuteBlock {
/// Block number.
#[clap(long, short = 'b')]
block_number: u64,

/// Directory path to json files.
/// Default: "./crates/blockifier_reexecution/resources/block_{block_number}".
#[clap(long, default_value = None)]
directory_path: Option<String>,
},
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -165,5 +178,36 @@ fn main() {
"RPC replies required for reexecuting block {block_number} written to json file."
);
}

Command::ReexecuteBlock { block_number, directory_path } => {
let full_file_path = directory_path.unwrap_or(format!(
"./crates/blockifier_reexecution/resources/block_{block_number}"
)) + "/reexecution_data.json";

let serializable_offline_reexecution_data =
SerializableOfflineReexecutionData::read_from_file(&full_file_path).unwrap();

let reexecution_state_readers =
OfflineConsecutiveStateReaders::new(serializable_offline_reexecution_data.into());

let mut expected_state_diff =
reexecution_state_readers.get_next_block_state_diff().unwrap();

let all_txs_in_next_block = reexecution_state_readers.get_next_block_txs().unwrap();

let mut transaction_executor =
reexecution_state_readers.get_transaction_executor(None).unwrap();

transaction_executor.execute_txs(&all_txs_in_next_block);
// Finalize block and read actual statediff.
let (actual_state_diff, _, _) =
transaction_executor.finalize().expect("Couldn't finalize block");

// TODO(Aner): compute correct block hash at storage slot 0x1 instead of removing it.
expected_state_diff.storage_updates.shift_remove(&ContractAddress(1_u128.into()));
assert_eq!(expected_state_diff, actual_state_diff);

println!("Reexecution test for block {block_number} passed successfully.");
}
}
}

0 comments on commit f8eb0c3

Please sign in to comment.