Skip to content

Commit

Permalink
build(blockifier_reexecution): add support for l1 handler tx
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware committed Nov 6, 2024
1 parent fb69950 commit 2efb4d5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,21 @@
"account_deployment_data": [],
"nonce_data_availability_mode": "L1",
"fee_data_availability_mode": "L1"
},
"l1_handler": {
"transaction_hash": "0x2315145ae0290b7d49ea3f509b1084b5fcd70d0fea8bed04b83aa8af33e4d7e",
"type": "L1_HANDLER",
"version": "0x0",
"nonce": "0x1961fb",
"contract_address": "0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82",
"calldata": [
"0xae0ee0a63a2ce6baeeffe56e7714fb4efe48d419",
"0x455448",
"0xc2da4fdceac12352751fb90eca6821107563d743",
"0x622dc4bd4723f8b058196db0be5e7b89bbe01f0e55730a51c45480ba229a373",
"0xe35fa931a0000",
"0x0"
],
"entry_point_selector": "0x1b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ fn deserialize_declare_txs(
}
}

#[test]
fn deserialize_l1_handler_tx() {
let l1_handler_tx = deserialize_transaction_json_to_starknet_api_tx(
read_json_file("raw_rpc_json_objects/transactions.json")["l1_handler"].clone(),
)
.expect("Failed to deserialize l1 handler tx");

assert_matches!(l1_handler_tx, Transaction::L1Handler(..));
}

#[rstest]
fn serialize_state_maps() {
let nonces = HashMap::from([(contract_address!(1_u8), nonce!(1_u8))]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use blockifier::execution::contract_class::ClassInfo;
use blockifier::state::state_api::StateResult;
use blockifier::test_utils::MAX_FEE;
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
use papyrus_execution::DEPRECATED_CONTRACT_SIERRA_SIZE;
use starknet_api::core::ClassHash;
Expand Down Expand Up @@ -41,28 +42,34 @@ pub(crate) trait ReexecutionStateReader {
.into_iter()
.map(|(tx, tx_hash)| match tx {
Transaction::Invoke(_) | Transaction::DeployAccount(_) => {
BlockifierTransaction::from_api(tx, tx_hash, None, None, None, false)
.map_err(ReexecutionError::from)
Ok(BlockifierTransaction::from_api(tx, tx_hash, None, None, None, false)?)
}
Transaction::Declare(ref declare_tx) => {
let class_info = self
.get_class_info(declare_tx.class_hash())
.map_err(ReexecutionError::from)?;
BlockifierTransaction::from_api(
Ok(BlockifierTransaction::from_api(
tx,
tx_hash,
Some(class_info),
None,
None,
false,
)
.map_err(ReexecutionError::from)
)?)
}
Transaction::L1Handler(_) => todo!("Implement L1Handler transaction converter"),
Transaction::L1Handler(_) => Ok(BlockifierTransaction::from_api(
tx,
tx_hash,
None,
Some(MAX_FEE),
None,
false,
)?),

Transaction::Deploy(_) => {
panic!("Reexecution not supported for Deploy transactions.")
}
})
.collect::<Result<Vec<_>, _>>()
.collect()
}
}
13 changes: 13 additions & 0 deletions crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const EXAMPLE_DECLARE_V3_BLOCK_NUMBER: u64 = 825013;
const EXAMPLE_DECLARE_V3_TX_HASH: &str =
"0x03ab43c0913f95b901b49ed1aa6009b31ebe0ad7ba62da49fc6de7f3854b496f";

const EXAMPLE_L1_HANDLER_BLOCK_NUMBER: u64 = 868429;
const EXAMPLE_L1_HANDLER_TX_HASH: &str =
"0x02315145ae0290b7d49ea3f509b1084b5fcd70d0fea8bed04b83aa8af33e4d7e";

#[fixture]
pub fn test_block_number() -> BlockNumber {
BlockNumber(EXAMPLE_BLOCK_NUMBER)
Expand Down Expand Up @@ -176,6 +180,15 @@ pub fn test_get_declare_tx_by_hash(
}
}

#[test]
pub fn test_get_l1_handler_tx_by_hash() {
// Create StateReader with block number that contain the l1 handler tx.
let state_reader =
TestStateReader::new_for_testing(BlockNumber(EXAMPLE_L1_HANDLER_BLOCK_NUMBER));
let actual_tx = state_reader.get_tx_by_hash(EXAMPLE_L1_HANDLER_TX_HASH).unwrap();
assert_matches!(actual_tx, Transaction::L1Handler(..))
}

#[rstest]
pub fn test_get_statediff_rpc(test_state_reader: TestStateReader) {
assert!(test_state_reader.get_state_diff().is_ok());
Expand Down

0 comments on commit 2efb4d5

Please sign in to comment.