Skip to content

Commit

Permalink
chore(blockifier_reexecution): full blockifier reexecution poc (#1346)
Browse files Browse the repository at this point in the history
* chore(blockifier_reexecution): full reexecution poc

* chore(blockifier_reexecution): move more logic to consecutive state readers
  • Loading branch information
aner-starkware authored Oct 27, 2024
1 parent 73a9a7f commit 3dbef1c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use starknet_api::block::{BlockNumber, StarknetVersion};
use starknet_api::class_hash;
use starknet_api::core::ClassHash;
use starknet_api::core::{ClassHash, ContractAddress};
use starknet_api::test_utils::read_json_file;
use starknet_api::transaction::Transaction;
use starknet_core::types::ContractClass::{Legacy, Sierra};
Expand Down Expand Up @@ -104,3 +104,26 @@ pub fn test_get_tx_by_hash(test_state_reader: TestStateReader) {
pub fn test_get_statediff_rpc(test_state_reader: TestStateReader) {
assert!(test_state_reader.get_state_diff().is_ok());
}

// TODO(Aner): replace this test with a CLI command that receives the node URL as input.
#[rstest]
pub fn test_full_blockifier_via_rpc(
test_state_readers_last_and_current_block: ConsecutiveTestStateReaders,
) {
let all_txs_in_next_block =
test_state_readers_last_and_current_block.get_next_block_txs().unwrap();

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

let mut transaction_executor =
test_state_readers_last_and_current_block.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 the 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use blockifier::execution::contract_class::ContractClass as BlockifierContractCl
use blockifier::state::cached_state::{CachedState, CommitmentStateDiff};
use blockifier::state::errors::StateError;
use blockifier::state::state_api::{StateReader, StateResult};
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
use blockifier::versioned_constants::VersionedConstants;
use serde_json::{json, to_value};
use starknet_api::block::{BlockNumber, StarknetVersion};
Expand All @@ -30,6 +31,7 @@ use crate::state_reader::serde_utils::{
};
use crate::state_reader::utils::{
disjoint_hashmap_union,
from_api_txs_to_blockifier_txs,
get_chain_info,
get_rpc_state_reader_config,
};
Expand Down Expand Up @@ -258,4 +260,12 @@ impl ConsecutiveTestStateReaders {
transaction_executor_config,
)
}

pub fn get_next_block_txs(&self) -> ReexecutionResult<Vec<BlockifierTransaction>> {
from_api_txs_to_blockifier_txs(self.next_block_state_reader.get_all_txs_in_block()?)
}

pub fn get_next_block_state_diff(&self) -> ReexecutionResult<CommitmentStateDiff> {
self.next_block_state_reader.get_state_diff()
}
}

0 comments on commit 3dbef1c

Please sign in to comment.