From d8b7fd2220d79ea4264d29a7d084ef50992410c1 Mon Sep 17 00:00:00 2001 From: YaelD <70628564+Yael-Starkware@users.noreply.github.com> Date: Wed, 1 Jan 2025 16:29:00 +0200 Subject: [PATCH] feat(sequencing): add central l1 handler transaction (#2988) --- .../resources/central_l1_handler_tx.json | 15 ++++++++ .../src/cende/central_objects.rs | 37 ++++++++++++++++++- .../src/cende/central_objects_test.rs | 31 +++++++++++++++- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 crates/sequencing/papyrus_consensus_orchestrator/resources/central_l1_handler_tx.json diff --git a/crates/sequencing/papyrus_consensus_orchestrator/resources/central_l1_handler_tx.json b/crates/sequencing/papyrus_consensus_orchestrator/resources/central_l1_handler_tx.json new file mode 100644 index 0000000000..01c13e116a --- /dev/null +++ b/crates/sequencing/papyrus_consensus_orchestrator/resources/central_l1_handler_tx.json @@ -0,0 +1,15 @@ +{ + "tx": { + "hash_value": "0xc947753befd252ca08042000cd6d783162ee2f5df87b519ddf3081b9b4b997", + "contract_address": "0x14abfd58671a1a9b30de2fcd2a42e8bff2ce1096a7c70bc7995904965f277e", + "entry_point_selector": "0x2a", + "calldata": [ + "0x0", + "0x1" + ], + "nonce": "0x0", + "paid_fee_on_l1": "0x1", + "type": "L1_HANDLER" + }, + "time_created": 1734601657 +} diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects.rs index 69f9a3ae0b..ef24b25a2e 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects.rs @@ -9,13 +9,20 @@ use starknet_api::block::{ StarknetVersion, }; use starknet_api::contract_class::SierraVersion; -use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; +use starknet_api::core::{ + ClassHash, + CompiledClassHash, + ContractAddress, + EntryPointSelector, + Nonce, +}; use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::executable_transaction::{ AccountTransaction, DeclareTransaction, DeployAccountTransaction, InvokeTransaction, + L1HandlerTransaction, Transaction, }; use starknet_api::state::{StorageKey, ThinStateDiff}; @@ -23,6 +30,7 @@ use starknet_api::transaction::fields::{ AccountDeploymentData, Calldata, ContractAddressSalt, + Fee, PaymasterData, Tip, TransactionSignature, @@ -242,6 +250,29 @@ pub enum CentralDeclareTransaction { V3(CentralDeclareTransactionV3), } +#[derive(Debug, PartialEq, Serialize)] +pub struct CentralL1HandlerTransaction { + pub contract_address: ContractAddress, + pub entry_point_selector: EntryPointSelector, + pub calldata: Calldata, + pub nonce: Nonce, + pub paid_fee_on_l1: Fee, + pub hash_value: TransactionHash, +} + +impl From for CentralL1HandlerTransaction { + fn from(tx: L1HandlerTransaction) -> CentralL1HandlerTransaction { + CentralL1HandlerTransaction { + hash_value: tx.tx_hash, + contract_address: tx.tx.contract_address, + entry_point_selector: tx.tx.entry_point_selector, + calldata: tx.tx.calldata, + nonce: tx.tx.nonce, + paid_fee_on_l1: tx.paid_fee_on_l1, + } + } +} + #[derive(Debug, PartialEq, Serialize)] #[serde(tag = "type")] pub enum CentralTransaction { @@ -251,6 +282,8 @@ pub enum CentralTransaction { DeployAccount(CentralDeployAccountTransaction), #[serde(rename = "DECLARE")] Declare(CentralDeclareTransaction), + #[serde(rename = "L1_HANDLER")] + L1Handler(CentralL1HandlerTransaction), } impl From for CentralTransaction { @@ -267,7 +300,7 @@ impl From for CentralTransaction { Transaction::Account(AccountTransaction::Declare(declare_tx)) => { CentralTransaction::Declare(CentralDeclareTransaction::V3(declare_tx.into())) } - Transaction::L1Handler(_) => unimplemented!(), + Transaction::L1Handler(l1_handler) => CentralTransaction::L1Handler(l1_handler.into()), } } } diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects_test.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects_test.rs index 449c2d805d..f25aabbbb0 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects_test.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/cende/central_objects_test.rs @@ -14,12 +14,13 @@ use starknet_api::block::{ StarknetVersion, }; use starknet_api::contract_class::{ClassInfo, ContractClass, SierraVersion}; -use starknet_api::core::{ClassHash, CompiledClassHash, Nonce}; +use starknet_api::core::{ClassHash, CompiledClassHash, EntryPointSelector, Nonce}; use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::executable_transaction::{ DeclareTransaction, DeployAccountTransaction, InvokeTransaction, + L1HandlerTransaction, }; use starknet_api::execution_resources::GasAmount; use starknet_api::state::ThinStateDiff; @@ -28,6 +29,7 @@ use starknet_api::transaction::fields::{ AllResourceBounds, Calldata, ContractAddressSalt, + Fee, ResourceBounds, ValidResourceBounds, }; @@ -36,6 +38,7 @@ use starknet_api::transaction::{ DeployAccountTransactionV3, InvokeTransactionV3, TransactionHash, + TransactionVersion, }; use starknet_api::{contract_address, felt, storage_key}; @@ -52,6 +55,7 @@ pub const CENTRAL_STATE_DIFF_JSON_PATH: &str = "central_state_diff.json"; pub const CENTRAL_INVOKE_TX_JSON_PATH: &str = "central_invoke_tx.json"; pub const CENTRAL_DEPLOY_ACCOUNT_TX_JSON_PATH: &str = "central_deploy_account_tx.json"; pub const CENTRAL_DECLARE_TX_JSON_PATH: &str = "central_declare_tx.json"; +pub const CENTRAL_L1_HANDLER_TX_JSON_PATH: &str = "central_l1_handler_tx.json"; fn central_state_diff_json() -> Value { let state_diff = ThinStateDiff { @@ -212,11 +216,36 @@ fn central_declare_tx_json() -> Value { serde_json::to_value(central_transaction_written).unwrap() } +fn central_l1_handler_tx_json() -> Value { + let l1_handler_tx = L1HandlerTransaction { + tx: starknet_api::transaction::L1HandlerTransaction { + version: TransactionVersion::ZERO, + nonce: Default::default(), + contract_address: contract_address!( + "0x14abfd58671a1a9b30de2fcd2a42e8bff2ce1096a7c70bc7995904965f277e" + ), + entry_point_selector: EntryPointSelector(felt!("0x2a")), + calldata: Calldata(Arc::new(vec![felt!(0_u8), felt!(1_u8)])), + }, + tx_hash: TransactionHash(felt!( + "0xc947753befd252ca08042000cd6d783162ee2f5df87b519ddf3081b9b4b997" + )), + paid_fee_on_l1: Fee(1), + }; + let central_transaction_written = CentralTransactionWritten { + tx: CentralTransaction::L1Handler(l1_handler_tx.into()), + time_created: 1734601657, + }; + + serde_json::to_value(central_transaction_written).unwrap() +} + #[rstest] #[case::state_diff(central_state_diff_json(), CENTRAL_STATE_DIFF_JSON_PATH)] #[case::invoke_tx(central_invoke_tx_json(), CENTRAL_INVOKE_TX_JSON_PATH)] #[case::deploy_account_tx(central_deploy_account_tx_json(), CENTRAL_DEPLOY_ACCOUNT_TX_JSON_PATH)] #[case::declare_tx(central_declare_tx_json(), CENTRAL_DECLARE_TX_JSON_PATH)] +#[case::l1_handler_tx(central_l1_handler_tx_json(), CENTRAL_L1_HANDLER_TX_JSON_PATH)] fn serialize_central_objects(#[case] rust_json: Value, #[case] python_json_path: &str) { let python_json = read_json_file(python_json_path);