From 7346894cd23bff80fa0910ed300beefc0abc4f6d Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Tue, 19 Nov 2024 16:36:57 +0000 Subject: [PATCH 01/12] feat(rpc): v0.8.0 getMessagesStatus method --- CHANGELOG.md | 1 + Cargo.lock | 2 + crates/client/db/Cargo.toml | 1 + crates/client/db/src/l1_db.rs | 35 ++- crates/client/db/src/lib.rs | 8 + crates/client/eth/src/l1_messaging.rs | 212 +++++++++--------- crates/client/mempool/src/inner.rs | 14 +- crates/client/mempool/src/lib.rs | 5 +- crates/client/rpc/Cargo.toml | 1 + crates/client/rpc/src/RPC.md | 2 +- crates/client/rpc/src/versions/v0_8_0/api.rs | 8 + .../methods/read/get_messages_status.rs | 43 ++++ .../src/versions/v0_8_0/methods/read/lib.rs | 11 +- .../src/versions/v0_8_0/methods/read/mod.rs | 1 + crates/node/src/cli/analytics.rs | 2 +- 15 files changed, 218 insertions(+), 128 deletions(-) create mode 100644 crates/client/rpc/src/versions/v0_8_0/methods/read/get_messages_status.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 800fa137e..18140441e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- feat(rpc): added `getMessagesStatus` method - fix: FeePayment conversion - fix(block_production): get l2-to-l1 messages recursively from the call tree - refactor: replace starknet-rs BlockId with types-rs BlockId and remove redundant mp_block::BlockId diff --git a/Cargo.lock b/Cargo.lock index 19fefba59..94fa1267c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5521,6 +5521,7 @@ dependencies = [ name = "mc-db" version = "0.7.0" dependencies = [ + "alloy", "anyhow", "bincode 1.3.3", "bonsai-trie", @@ -5789,6 +5790,7 @@ dependencies = [ name = "mc-rpc" version = "0.7.0" dependencies = [ + "alloy", "anyhow", "blockifier", "jsonrpsee", diff --git a/crates/client/db/Cargo.toml b/crates/client/db/Cargo.toml index 85ab46bc1..2d5f4a7c8 100644 --- a/crates/client/db/Cargo.toml +++ b/crates/client/db/Cargo.toml @@ -33,6 +33,7 @@ starknet-types-core = { workspace = true } starknet_api = { workspace = true } # Other +alloy = { workspace = true } anyhow.workspace = true bincode = { workspace = true } rayon = { workspace = true } diff --git a/crates/client/db/src/l1_db.rs b/crates/client/db/src/l1_db.rs index 10c235091..ffe45c57d 100644 --- a/crates/client/db/src/l1_db.rs +++ b/crates/client/db/src/l1_db.rs @@ -1,9 +1,10 @@ +use crate::error::DbError; +use crate::{Column, DatabaseExt, MadaraBackend, MadaraStorageError}; +use alloy::primitives::TxHash; use rocksdb::WriteOptions; use serde::{Deserialize, Serialize}; use starknet_api::core::Nonce; - -use crate::error::DbError; -use crate::{Column, DatabaseExt, MadaraBackend, MadaraStorageError}; +use starknet_types_core::felt::Felt; type Result = std::result::Result; @@ -128,4 +129,32 @@ impl MadaraBackend { self.db.put_cf_opt(&nonce_column, bincode::serialize(&nonce)?, /* empty value */ [], &writeopts)?; Ok(()) } + + pub fn get_l1_handler_tx_hashes(&self, l1_tx_hash: TxHash) -> Result, DbError> { + let l1_l2_mappings_column = self.db.get_column(Column::L1MessagingHandlerTxHashes); + let mut l1_handler_tx_hashes = vec![]; + for kv_bytes in self.db.prefix_iterator_cf(&l1_l2_mappings_column, l1_tx_hash.as_slice()) { + let l1_handler_tx_hash = Felt::from_bytes_be_slice(&kv_bytes?.1); + l1_handler_tx_hashes.push(l1_handler_tx_hash); + } + Ok(l1_handler_tx_hashes) + } + + /// Store mapping from L1 transaction to L1 handler transaction (on the L2). A unique order + /// value is required to ensure the handler transactions are retreived in the correct order. + pub fn add_l1_handler_tx_hash_mapping( + &self, + l1_tx_hash: TxHash, + l1_handler_tx_hash: Felt, + order: u64, + ) -> Result<(), DbError> { + let l1_l2_mappings_column = self.db.get_column(Column::L1MessagingHandlerTxHashes); + let mut key = [0u8; 40]; + key[..32].copy_from_slice(l1_tx_hash.as_slice()); + key[32..].copy_from_slice(&order.to_be_bytes()); // BE is important for the lexographic sorting + let mut writeopts = WriteOptions::default(); + writeopts.disable_wal(true); + self.db.put_cf_opt(&l1_l2_mappings_column, key, l1_handler_tx_hash.to_bytes_be(), &writeopts)?; + Ok(()) + } } diff --git a/crates/client/db/src/lib.rs b/crates/client/db/src/lib.rs index 1a592ddf7..1735c7473 100644 --- a/crates/client/db/src/lib.rs +++ b/crates/client/db/src/lib.rs @@ -1,5 +1,7 @@ //! Madara database +use alloy::primitives::private::alloy_rlp::MaxEncodedLenAssoc; +use alloy::primitives::TxHash; use anyhow::{Context, Result}; use bonsai_db::{BonsaiDb, DatabaseKeyMapping}; use bonsai_trie::id::BasicId; @@ -175,6 +177,7 @@ pub enum Column { L1Messaging, L1MessagingNonce, + L1MessagingHandlerTxHashes, /// Devnet: stores the private keys for the devnet predeployed contracts Devnet, @@ -222,6 +225,7 @@ impl Column { BonsaiClassesLog, L1Messaging, L1MessagingNonce, + L1MessagingHandlerTxHashes, PendingContractToClassHashes, PendingContractToNonces, PendingContractStorage, @@ -259,6 +263,7 @@ impl Column { ContractStorage => "contract_storage", L1Messaging => "l1_messaging", L1MessagingNonce => "l1_messaging_nonce", + L1MessagingHandlerTxHashes => "l1_messaging_handler_tx_hashes", PendingContractToClassHashes => "pending_contract_to_class_hashes", PendingContractToNonces => "pending_contract_to_nonces", PendingContractStorage => "pending_contract_storage", @@ -286,6 +291,9 @@ impl Column { contract_db::CONTRACT_NONCES_PREFIX_EXTRACTOR, )); } + Column::L1MessagingHandlerTxHashes => { + opts.set_prefix_extractor(SliceTransform::create_fixed_prefix(TxHash::LEN)); + } _ => {} } opts diff --git a/crates/client/eth/src/l1_messaging.rs b/crates/client/eth/src/l1_messaging.rs index a9e33c664..5cbb65ac8 100644 --- a/crates/client/eth/src/l1_messaging.rs +++ b/crates/client/eth/src/l1_messaging.rs @@ -1,10 +1,11 @@ +use crate::client::EthereumClient; use crate::client::StarknetCoreContract::LogMessageToL2; -use crate::client::{EthereumClient, StarknetCoreContract}; use crate::utils::u256_to_felt; use alloy::eips::BlockNumberOrTag; use alloy::primitives::{keccak256, FixedBytes, U256}; +use alloy::rpc::types::Log; use alloy::sol_types::SolValue; -use anyhow::Context; +use anyhow::{anyhow, Context}; use blockifier::transaction::transaction_execution::Transaction as BlockifierTransation; use futures::StreamExt; use mc_db::{l1_db::LastSyncedEventBlock, MadaraBackend}; @@ -55,9 +56,10 @@ pub async fn sync( return Err(e.into()); } }; - let event_filter = client.l1_core_contract.event_filter::(); - let mut event_stream = event_filter + let mut event_stream = client + .l1_core_contract + .event_filter::() .from_block(last_synced_event_block.block_number) .to_block(BlockNumberOrTag::Finalized) .watch() @@ -66,114 +68,83 @@ pub async fn sync( "Failed to watch event filter - Ensure you are using an L1 RPC endpoint that points to an archive node", )? .into_stream(); + while let Some(event_result) = channel_wait_or_graceful_shutdown(event_stream.next()).await { - if let Ok((event, meta)) = event_result { - tracing::info!( - "⟠ Processing L1 Message from block: {:?}, transaction_hash: {:?}, log_index: {:?}, fromAddress: {:?}", - meta.block_number, - meta.transaction_hash, - meta.log_index, - event.fromAddress - ); - - // Check if cancellation was initiated - let event_hash = get_l1_to_l2_msg_hash(&event)?; - tracing::info!("⟠ Checking for cancelation, event hash : {:?}", event_hash); - let cancellation_timestamp = client.get_l1_to_l2_message_cancellations(event_hash).await?; - if cancellation_timestamp != Felt::ZERO { - tracing::info!("⟠ L1 Message was cancelled in block at timestamp : {:?}", cancellation_timestamp); - let tx_nonce = Nonce(u256_to_felt(event.nonce)?); - // cancelled message nonce should be inserted to avoid reprocessing - match backend.has_l1_messaging_nonce(tx_nonce) { - Ok(false) => { - backend.set_l1_messaging_nonce(tx_nonce)?; - } - Ok(true) => {} - Err(e) => { - tracing::error!("⟠ Unexpected DB error: {:?}", e); - return Err(e.into()); - } + match event_result { + Ok((event, log)) => { + if let Err(e) = process_l1_to_l2_msg(backend, client, chain_id, &mempool, event, log).await { + tracing::error!("⟠ Unable to process L1 -> L2 messsage event: {e:?}"); }; - continue; - } - - match process_l1_message(backend, &event, &meta.block_number, &meta.log_index, chain_id, mempool.clone()) - .await - { - Ok(Some(tx_hash)) => { - tracing::info!( - "⟠ L1 Message from block: {:?}, transaction_hash: {:?}, log_index: {:?} submitted, \ - transaction hash on L2: {:?}", - meta.block_number, - meta.transaction_hash, - meta.log_index, - tx_hash - ); - } - Ok(None) => {} - Err(e) => { - tracing::error!( - "⟠ Unexpected error while processing L1 Message from block: {:?}, transaction_hash: {:?}, \ - log_index: {:?}, error: {:?}", - meta.block_number, - meta.transaction_hash, - meta.log_index, - e - ) - } } + Err(e) => tracing::error!("⟠ Unable to receive L1 -> L2 message event: {e}"), } } Ok(()) } -async fn process_l1_message( +async fn process_l1_to_l2_msg( backend: &MadaraBackend, - event: &LogMessageToL2, - l1_block_number: &Option, - event_index: &Option, + client: &EthereumClient, chain_id: &ChainId, - mempool: Arc, -) -> anyhow::Result> { - let transaction = parse_handle_l1_message_transaction(event)?; - let tx_nonce = transaction.nonce; + mempool: &Arc, + event: LogMessageToL2, + log: Log, +) -> anyhow::Result<()> { + tracing::debug!("⟠ Processing L1 -> L2 message event {event:#?}, contract address: {}, block number: {:?}, transaction index: {:?}, transaction hash: {:?}, log index: {:?}", + log.address(), log.block_number, log.transaction_index, log.transaction_hash, log.log_index + ); + let tx_nonce = Nonce(u256_to_felt(event.nonce)?); // Ensure that L1 message has not been executed - match backend.has_l1_messaging_nonce(tx_nonce) { - Ok(false) => { - backend.set_l1_messaging_nonce(tx_nonce)?; - } - Ok(true) => { - tracing::debug!("⟠ Event already processed: {:?}", transaction); - return Ok(None); - } - Err(e) => { - tracing::error!("⟠ Unexpected DB error: {:?}", e); - return Err(e.into()); - } - }; + if backend.has_l1_messaging_nonce(tx_nonce)? { + tracing::debug!("⟠ L1 -> L2 event already processed: {tx_nonce:?}"); + return Ok(()); + } else { + backend.set_l1_messaging_nonce(tx_nonce)?; + } + + // Check if cancellation was initiated + let event_hash = get_l1_to_l2_msg_hash(&event); + let cancellation_timestamp = client.get_l1_to_l2_message_cancellations(event_hash).await?; + if cancellation_timestamp != Felt::ZERO { + tracing::info!("⟠ L1 message was cancelled at timestamp {:?}", cancellation_timestamp.to_biguint()); + return Ok(()); + } + + let l1_handler_transaction = parse_handle_l1_message_transaction(&event)?; - let tx_hash = get_transaction_hash(&Transaction::L1Handler(transaction.clone()), chain_id, &transaction.version)?; + let tx_hash = get_transaction_hash( + &Transaction::L1Handler(l1_handler_transaction.clone()), + chain_id, + &l1_handler_transaction.version, + )?; let blockifier_transaction = BlockifierTransation::from_api( - Transaction::L1Handler(transaction), + Transaction::L1Handler(l1_handler_transaction.clone()), tx_hash, None, Some(Fee(event.fee.try_into()?)), None, false, )?; - let res = mempool.accept_l1_handler_tx(blockifier_transaction)?; + mempool.accept_l1_handler_tx(blockifier_transaction)?; + + let l1_tx_hash = log.transaction_hash.ok_or_else(|| anyhow!("Missing transaction hash"))?; + let block_number = log.block_number.ok_or_else(|| anyhow!("Event missing block number"))?; + let log_index = log.log_index.ok_or_else(|| anyhow!("Event missing log index"))?; + + // We use the log index for the order to ensure any L1 txs which have multiple messages are + // retrieved in the order they occured. + backend.add_l1_handler_tx_hash_mapping(l1_tx_hash, tx_hash.0, log_index)?; - // TODO: remove unwraps - // Ques: shall it panic if no block number of event_index? - let block_sent = LastSyncedEventBlock::new(l1_block_number.unwrap(), event_index.unwrap()); - backend.messaging_update_last_synced_l1_block_with_event(block_sent)?; + let last_synced_event_block = LastSyncedEventBlock::new(block_number, log_index); + backend.messaging_update_last_synced_l1_block_with_event(last_synced_event_block)?; - Ok(Some(res.transaction_hash)) + tracing::info!("⟠ L1 message processed: {:?}, transaction hash: {:?}", l1_handler_transaction, tx_hash); + Ok(()) } -pub fn parse_handle_l1_message_transaction(event: &LogMessageToL2) -> anyhow::Result { +fn parse_handle_l1_message_transaction(event: &LogMessageToL2) -> anyhow::Result { // L1 from address. let from_address = u256_to_felt(event.fromAddress.into_word().into())?; @@ -206,7 +177,7 @@ pub fn parse_handle_l1_message_transaction(event: &LogMessageToL2) -> anyhow::Re } /// Computes the message hashed with the given event data -fn get_l1_to_l2_msg_hash(event: &LogMessageToL2) -> anyhow::Result> { +fn get_l1_to_l2_msg_hash(event: &LogMessageToL2) -> FixedBytes<32> { let data = ( [0u8; 12], event.fromAddress.0 .0, @@ -216,14 +187,11 @@ fn get_l1_to_l2_msg_hash(event: &LogMessageToL2) -> anyhow::Result (handler_tx.tx, handler_tx.tx_hash.0), + Transaction::AccountTransaction(_) => panic!("Expecting L1 handler transaction"), + }; + assert_eq!(handler_tx.nonce, nonce); + assert_eq!( + handler_tx.contract_address, + ContractAddress::try_from( + Felt::from_dec_str("3256441166037631918262930812410838598500200462657642943867372734773841898370") + .unwrap() + ) + .unwrap() + ); + assert_eq!( + handler_tx.entry_point_selector, + EntryPointSelector( + Felt::from_dec_str("774397379524139446221206168840917193112228400237242521560346153613428128537") + .unwrap() + ) + ); + assert_eq!( + handler_tx.calldata.0[0], + Felt::from_dec_str("993696174272377493693496825928908586134624850969").unwrap() + ); - // TODO : Assert that the tx has been included in the mempool + // Assert the L1 -> L2 mapping is stored + let l1_handler_tx_hashes = db + .backend() + .get_l1_handler_tx_hashes( + TxHash::from_hex("4961b0fef9f7d7c46fb9095b2b97ea3dc8157fca04e4f2562d1461ac3bb03867").unwrap(), + ) + .expect("Unable to get L1 -> L2 tx hashes mapping from DB"); + assert_eq!(l1_handler_tx_hashes, vec![handler_tx_hash]); // Assert that the event is well stored in db let last_block = db.backend().messaging_last_synced_l1_block_with_event().expect("failed to retrieve block").unwrap(); assert_ne!(last_block.block_number, 0); - let nonce = Nonce(Felt::from_dec_str("10000000000000000").expect("failed to parse nonce string")); assert!(db.backend().has_l1_messaging_nonce(nonce).unwrap()); // TODO : Assert that the tx was correctly executed @@ -485,7 +480,7 @@ mod l1_messaging_tests { .unwrap() .block_number ); - assert!(logs_contain("Event already processed")); + assert!(logs_contain("L1 -> L2 event already processed")); worker_handle.abort(); } @@ -521,7 +516,7 @@ mod l1_messaging_tests { let nonce = Nonce(Felt::from_dec_str("10000000000000000").expect("failed to parse nonce string")); // cancelled message nonce should be inserted to avoid reprocessing assert!(db.backend().has_l1_messaging_nonce(nonce).unwrap()); - assert!(logs_contain("L1 Message was cancelled in block at timestamp : 0x66b4f105")); + assert!(logs_contain("L1 message was cancelled at timestamp 1723134213")); worker_handle.abort(); } @@ -547,8 +542,7 @@ mod l1_messaging_tests { ], nonce: U256::from(775628), fee: U256::ZERO, - }) - .expect("Failed to compute l1 to l2 msg hash"); + }); let expected_hash = <[u8; 32]>::from_hex("c51a543ef9563ad2545342b390b67edfcddf9886aa36846cf70382362fc5fab3").unwrap(); diff --git a/crates/client/mempool/src/inner.rs b/crates/client/mempool/src/inner.rs index 837263ec2..5ab052583 100644 --- a/crates/client/mempool/src/inner.rs +++ b/crates/client/mempool/src/inner.rs @@ -156,11 +156,11 @@ impl NonceChain { match self.transactions.entry(OrderMempoolTransactionByNonce(mempool_tx)) { btree_map::Entry::Occupied(entry) => { // duplicate nonce, either it's because the hash is duplicated or nonce conflict with another tx. - if entry.key().0.tx_hash() == mempool_tx_hash { - return Err(TxInsersionError::DuplicateTxn); + return if entry.key().0.tx_hash() == mempool_tx_hash { + Err(TxInsersionError::DuplicateTxn) } else { - return Err(TxInsersionError::NonceConflict); - } + Err(TxInsersionError::NonceConflict) + }; } btree_map::Entry::Vacant(entry) => *entry.insert(()), } @@ -169,7 +169,7 @@ impl NonceChain { }; let position = if self.front_nonce >= mempool_tx_nonce { - // We insrted at the front here + // We inserted at the front here let former_head_arrived_at = core::mem::replace(&mut self.front_arrived_at, mempool_tx_arrived_at); self.front_nonce = mempool_tx_nonce; self.front_tx_hash = mempool_tx_hash; @@ -307,7 +307,7 @@ impl MempoolInner { None }; - let is_replaced = match self.nonce_chains.entry(contract_addr) { + let replaced_state = match self.nonce_chains.entry(contract_addr) { hash_map::Entry::Occupied(mut entry) => { // Handle nonce collision. let (position, is_replaced) = match entry.get_mut().insert(mempool_tx, force) { @@ -350,7 +350,7 @@ impl MempoolInner { } }; - if is_replaced != ReplacedState::Replaced { + if replaced_state != ReplacedState::Replaced { if let Some(contract_address) = &deployed_contract_address { self.deployed_contracts.increment(*contract_address) } diff --git a/crates/client/mempool/src/lib.rs b/crates/client/mempool/src/lib.rs index 28445193e..703866132 100644 --- a/crates/client/mempool/src/lib.rs +++ b/crates/client/mempool/src/lib.rs @@ -101,10 +101,7 @@ impl Mempool { block } else { // No current pending block, we'll make an unsaved empty one for the sake of validating this tx. - let parent_block_hash = self - .backend - .get_block_hash(&BlockId::Tag(BlockTag::Latest))? - .unwrap_or(/* genesis block's parent hash */ Felt::ZERO); + let parent_block_hash = self.backend.get_block_hash(&BlockId::Tag(BlockTag::Latest))?.unwrap_or(Felt::ZERO); // Genesis block's parent hash MadaraPendingBlockInfo::new( make_pending_header(parent_block_hash, self.backend.chain_config(), self.l1_data_provider.as_ref()), vec![], diff --git a/crates/client/rpc/Cargo.toml b/crates/client/rpc/Cargo.toml index 531a7dae2..d2f0fd546 100644 --- a/crates/client/rpc/Cargo.toml +++ b/crates/client/rpc/Cargo.toml @@ -44,6 +44,7 @@ starknet-types-rpc = { workspace = true } starknet_api = { workspace = true, default-features = true } # Others +alloy = { workspace = true } anyhow = { workspace = true } jsonrpsee = { workspace = true, default-features = true, features = [ "macros", diff --git a/crates/client/rpc/src/RPC.md b/crates/client/rpc/src/RPC.md index f10d9504f..126480716 100644 --- a/crates/client/rpc/src/RPC.md +++ b/crates/client/rpc/src/RPC.md @@ -14,7 +14,7 @@ methods exist in isolation from `read` methods for example. _different versions_ of the same RPC method. This is mostly present for ease of development of new RPC versions, but also serves to assure a level of backwards compatibility. To select a specific version of an rpc method, you will need to -append `/rcp/v{version}` to the rpc url you are connecting to. +append `/rpc/v{version}` to the rpc url you are connecting to. **RPC versions are grouped under the `Starknet` struct**. This serves as a common point of implementation for all RPC methods across all versions, and is diff --git a/crates/client/rpc/src/versions/v0_8_0/api.rs b/crates/client/rpc/src/versions/v0_8_0/api.rs index 40f87b90a..c424cab96 100644 --- a/crates/client/rpc/src/versions/v0_8_0/api.rs +++ b/crates/client/rpc/src/versions/v0_8_0/api.rs @@ -1,3 +1,5 @@ +use crate::versions::v0_8_0::methods::read::get_messages_status::MessageStatus; +use alloy::primitives::TxHash; use jsonrpsee::core::RpcResult; use m_proc_macros::versioned_rpc; use mp_block::BlockId; @@ -18,4 +20,10 @@ pub trait StarknetReadRpcApi { #[method(name = "getCompiledCasm")] fn get_compiled_casm(&self, class_hash: Felt) -> RpcResult; + + /// For the given L1 transaction hash, return the associated L1 handler transaction hashes and + /// statuses for all L1 -> L2 messsages sent by the L1 transaction, ordered by the L1 + /// transaction sending order. + #[method(name = "getMessagesStatus")] + fn get_messages_status(&self, transaction_hash: TxHash) -> RpcResult>; } diff --git a/crates/client/rpc/src/versions/v0_8_0/methods/read/get_messages_status.rs b/crates/client/rpc/src/versions/v0_8_0/methods/read/get_messages_status.rs new file mode 100644 index 000000000..8be63cca4 --- /dev/null +++ b/crates/client/rpc/src/versions/v0_8_0/methods/read/get_messages_status.rs @@ -0,0 +1,43 @@ +use crate::utils::ResultExt; +use crate::versions::v0_7_1::methods::read::get_transaction_status::get_transaction_status; +use crate::{Starknet, StarknetRpcApiError, StarknetRpcResult}; +use alloy::primitives::TxHash; +use jsonrpsee::core::Serialize; +use serde::Deserialize; +use starknet_core::types::SequencerTransactionStatus; +use starknet_types_core::felt::Felt; + +pub fn get_messages_status(starknet: &Starknet, transaction_hash: TxHash) -> StarknetRpcResult> { + let l1_handler_tx_hashes = starknet + .backend + .get_l1_handler_tx_hashes(transaction_hash) + .or_internal_server_error("Retrieving L1 handler transactions from database")?; + if l1_handler_tx_hashes.is_empty() { + return Err(StarknetRpcApiError::TxnHashNotFound); + } + let mut message_statuses = vec![]; + for l1_handler_tx_hash in l1_handler_tx_hashes { + let finality_status = match get_transaction_status(starknet, l1_handler_tx_hash) { + Ok(tx_status) => tx_status.finality_status(), + Err(StarknetRpcApiError::TxnHashNotFound) => { + tracing::error!("L1 handler tx {l1_handler_tx_hash:?} for L1 tx {transaction_hash:?} not found"); + return Err(StarknetRpcApiError::InternalServerError); + } + Err(e) => return Err(e), + }; + message_statuses.push(MessageStatus { + transaction_hash: l1_handler_tx_hash, + finality_status, + // TODO Update this once get_transaction_status supports rejections + failure_reason: None, + }) + } + Ok(message_statuses) +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct MessageStatus { + pub transaction_hash: Felt, + pub finality_status: SequencerTransactionStatus, + pub failure_reason: Option, +} diff --git a/crates/client/rpc/src/versions/v0_8_0/methods/read/lib.rs b/crates/client/rpc/src/versions/v0_8_0/methods/read/lib.rs index dc3ca5966..d7c043517 100644 --- a/crates/client/rpc/src/versions/v0_8_0/methods/read/lib.rs +++ b/crates/client/rpc/src/versions/v0_8_0/methods/read/lib.rs @@ -1,12 +1,13 @@ +use crate::versions::v0_8_0::methods::read::get_messages_status::{get_messages_status, MessageStatus}; +use crate::versions::v0_8_0::StarknetReadRpcApiV0_8_0Server; +use crate::Starknet; +use alloy::primitives::TxHash; use jsonrpsee::core::{async_trait, RpcResult}; use mp_chain_config::RpcVersion; use starknet_types_core::felt::Felt; use super::get_compiled_casm::*; -use crate::versions::v0_8_0::StarknetReadRpcApiV0_8_0Server; -use crate::Starknet; - #[async_trait] impl StarknetReadRpcApiV0_8_0Server for Starknet { fn spec_version(&self) -> RpcResult { @@ -16,4 +17,8 @@ impl StarknetReadRpcApiV0_8_0Server for Starknet { fn get_compiled_casm(&self, class_hash: Felt) -> RpcResult { Ok(get_compiled_casm(self, class_hash)?) } + + fn get_messages_status(&self, transaction_hash: TxHash) -> RpcResult> { + Ok(get_messages_status(self, transaction_hash)?) + } } diff --git a/crates/client/rpc/src/versions/v0_8_0/methods/read/mod.rs b/crates/client/rpc/src/versions/v0_8_0/methods/read/mod.rs index ca920b2ba..4c94236c6 100644 --- a/crates/client/rpc/src/versions/v0_8_0/methods/read/mod.rs +++ b/crates/client/rpc/src/versions/v0_8_0/methods/read/mod.rs @@ -1,2 +1,3 @@ pub mod get_compiled_casm; +pub mod get_messages_status; pub mod lib; diff --git a/crates/node/src/cli/analytics.rs b/crates/node/src/cli/analytics.rs index 1f3ee7220..73be9e431 100644 --- a/crates/node/src/cli/analytics.rs +++ b/crates/node/src/cli/analytics.rs @@ -15,6 +15,6 @@ pub struct AnalyticsParams { pub analytics_log_level: Level, /// Endpoint of the analytics server. - #[arg(env = "OTEL_EXPORTER_OTLP_ENDPOINT", long, value_parser = parse_url, default_value = None)] + #[arg(env = "MADARA_ANALYTICS_COLLECTION_ENDPOINT", long, value_parser = parse_url, default_value = None)] pub analytics_collection_endpoint: Option, } From bbed31d4b4c6af1b793529fa6f4d03c4e3f4a0c5 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Wed, 20 Nov 2024 13:45:02 +0000 Subject: [PATCH 02/12] Merge fix --- crates/client/db/src/lib.rs | 2 -- crates/client/db/src/rocksdb_options.rs | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/client/db/src/lib.rs b/crates/client/db/src/lib.rs index 64eda0160..c1b67015b 100644 --- a/crates/client/db/src/lib.rs +++ b/crates/client/db/src/lib.rs @@ -1,7 +1,5 @@ //! Madara database -use alloy::primitives::private::alloy_rlp::MaxEncodedLenAssoc; -use alloy::primitives::TxHash; use anyhow::{Context, Result}; use bonsai_db::{BonsaiDb, DatabaseKeyMapping}; use bonsai_trie::id::BasicId; diff --git a/crates/client/db/src/rocksdb_options.rs b/crates/client/db/src/rocksdb_options.rs index 37aebb516..2fdd7248d 100644 --- a/crates/client/db/src/rocksdb_options.rs +++ b/crates/client/db/src/rocksdb_options.rs @@ -2,6 +2,8 @@ #![allow(non_upper_case_globals)] // allow KiB/MiB/GiB names use crate::{contract_db, Column}; +use alloy::primitives::private::alloy_rlp::MaxEncodedLenAssoc; +use alloy::primitives::TxHash; use anyhow::{Context, Result}; use rocksdb::{DBCompressionType, Env, Options, SliceTransform}; @@ -56,6 +58,9 @@ impl Column { contract_db::CONTRACT_NONCES_PREFIX_EXTRACTOR, )); } + Column::L1MessagingHandlerTxHashes => { + options.set_prefix_extractor(SliceTransform::create_fixed_prefix(TxHash::LEN)); + } _ => {} } From 09a5a54d4ea4e40eda4d6e27e55b44d772f179d9 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Thu, 21 Nov 2024 10:49:01 +0000 Subject: [PATCH 03/12] Merge fix --- crates/client/rpc/src/versions/user/v0_8_0/api.rs | 2 +- .../user/v0_8_0/methods/read/get_messages_status.rs | 2 +- .../rpc/src/versions/user/v0_8_0/methods/read/lib.rs | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/client/rpc/src/versions/user/v0_8_0/api.rs b/crates/client/rpc/src/versions/user/v0_8_0/api.rs index c424cab96..579d08d9f 100644 --- a/crates/client/rpc/src/versions/user/v0_8_0/api.rs +++ b/crates/client/rpc/src/versions/user/v0_8_0/api.rs @@ -1,4 +1,4 @@ -use crate::versions::v0_8_0::methods::read::get_messages_status::MessageStatus; +use crate::versions::user::v0_8_0::methods::read::get_messages_status::MessageStatus; use alloy::primitives::TxHash; use jsonrpsee::core::RpcResult; use m_proc_macros::versioned_rpc; diff --git a/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs b/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs index 8be63cca4..5e44a8a74 100644 --- a/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs +++ b/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs @@ -1,5 +1,5 @@ use crate::utils::ResultExt; -use crate::versions::v0_7_1::methods::read::get_transaction_status::get_transaction_status; +use crate::versions::user::v0_7_1::methods::read::get_transaction_status::get_transaction_status; use crate::{Starknet, StarknetRpcApiError, StarknetRpcResult}; use alloy::primitives::TxHash; use jsonrpsee::core::Serialize; diff --git a/crates/client/rpc/src/versions/user/v0_8_0/methods/read/lib.rs b/crates/client/rpc/src/versions/user/v0_8_0/methods/read/lib.rs index 08bc93d0f..a272ce7e3 100644 --- a/crates/client/rpc/src/versions/user/v0_8_0/methods/read/lib.rs +++ b/crates/client/rpc/src/versions/user/v0_8_0/methods/read/lib.rs @@ -1,5 +1,5 @@ -use crate::versions::v0_8_0::methods::read::get_messages_status::{get_messages_status, MessageStatus}; -use crate::versions::v0_8_0::StarknetReadRpcApiV0_8_0Server; +use crate::versions::user::v0_8_0::methods::read::get_messages_status::{get_messages_status, MessageStatus}; +use crate::versions::user::v0_8_0::StarknetReadRpcApiV0_8_0Server; use crate::Starknet; use alloy::primitives::TxHash; use jsonrpsee::core::{async_trait, RpcResult}; @@ -8,9 +8,6 @@ use starknet_types_core::felt::Felt; use super::get_compiled_casm::*; -use crate::versions::user::v0_8_0::StarknetReadRpcApiV0_8_0Server; -use crate::Starknet; - #[async_trait] impl StarknetReadRpcApiV0_8_0Server for Starknet { fn spec_version(&self) -> RpcResult { From 492218865dec7118e481134135b7a05205549978 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Mon, 25 Nov 2024 11:16:07 +0000 Subject: [PATCH 04/12] Address review comments --- crates/client/db/src/l1_db.rs | 10 ++--- crates/client/eth/src/l1_messaging.rs | 8 ++-- .../methods/read/get_messages_status.rs | 38 ++++++++++--------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/crates/client/db/src/l1_db.rs b/crates/client/db/src/l1_db.rs index ffe45c57d..73efca0f6 100644 --- a/crates/client/db/src/l1_db.rs +++ b/crates/client/db/src/l1_db.rs @@ -132,11 +132,11 @@ impl MadaraBackend { pub fn get_l1_handler_tx_hashes(&self, l1_tx_hash: TxHash) -> Result, DbError> { let l1_l2_mappings_column = self.db.get_column(Column::L1MessagingHandlerTxHashes); - let mut l1_handler_tx_hashes = vec![]; - for kv_bytes in self.db.prefix_iterator_cf(&l1_l2_mappings_column, l1_tx_hash.as_slice()) { - let l1_handler_tx_hash = Felt::from_bytes_be_slice(&kv_bytes?.1); - l1_handler_tx_hashes.push(l1_handler_tx_hash); - } + let l1_handler_tx_hashes = self + .db + .prefix_iterator_cf(&l1_l2_mappings_column, l1_tx_hash.as_slice()) + .map(|kv_bytes| Ok(Felt::from_bytes_be_slice(&kv_bytes?.1))) + .collect::>()?; Ok(l1_handler_tx_hashes) } diff --git a/crates/client/eth/src/l1_messaging.rs b/crates/client/eth/src/l1_messaging.rs index a47a07038..3d487c414 100644 --- a/crates/client/eth/src/l1_messaging.rs +++ b/crates/client/eth/src/l1_messaging.rs @@ -5,7 +5,7 @@ use alloy::eips::BlockNumberOrTag; use alloy::primitives::{keccak256, FixedBytes, U256}; use alloy::rpc::types::Log; use alloy::sol_types::SolValue; -use anyhow::{anyhow, Context}; +use anyhow::Context; use blockifier::transaction::transaction_execution::Transaction as BlockifierTransation; use futures::StreamExt; use mc_db::{l1_db::LastSyncedEventBlock, MadaraBackend}; @@ -130,9 +130,9 @@ async fn process_l1_to_l2_msg( )?; mempool.accept_l1_handler_tx(blockifier_transaction)?; - let l1_tx_hash = log.transaction_hash.ok_or_else(|| anyhow!("Missing transaction hash"))?; - let block_number = log.block_number.ok_or_else(|| anyhow!("Event missing block number"))?; - let log_index = log.log_index.ok_or_else(|| anyhow!("Event missing log index"))?; + let l1_tx_hash = log.transaction_hash.context("Missing transaction hash")?; + let block_number = log.block_number.context("Event missing block number")?; + let log_index = log.log_index.context("Event missing log index")?; // We use the log index for the order to ensure any L1 txs which have multiple messages are // retrieved in the order they occured. diff --git a/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs b/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs index 5e44a8a74..e4a8ec273 100644 --- a/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs +++ b/crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs @@ -15,24 +15,26 @@ pub fn get_messages_status(starknet: &Starknet, transaction_hash: TxHash) -> Sta if l1_handler_tx_hashes.is_empty() { return Err(StarknetRpcApiError::TxnHashNotFound); } - let mut message_statuses = vec![]; - for l1_handler_tx_hash in l1_handler_tx_hashes { - let finality_status = match get_transaction_status(starknet, l1_handler_tx_hash) { - Ok(tx_status) => tx_status.finality_status(), - Err(StarknetRpcApiError::TxnHashNotFound) => { - tracing::error!("L1 handler tx {l1_handler_tx_hash:?} for L1 tx {transaction_hash:?} not found"); - return Err(StarknetRpcApiError::InternalServerError); - } - Err(e) => return Err(e), - }; - message_statuses.push(MessageStatus { - transaction_hash: l1_handler_tx_hash, - finality_status, - // TODO Update this once get_transaction_status supports rejections - failure_reason: None, - }) - } - Ok(message_statuses) + l1_handler_tx_hashes.iter().try_fold( + Vec::with_capacity(l1_handler_tx_hashes.len()), + |mut acc, l1_handler_tx_hash| { + let finality_status = match get_transaction_status(starknet, *l1_handler_tx_hash) { + Ok(tx_status) => tx_status.finality_status(), + Err(StarknetRpcApiError::TxnHashNotFound) => { + tracing::error!("L1 handler tx {l1_handler_tx_hash:?} for L1 tx {transaction_hash:?} not found"); + return Err(StarknetRpcApiError::InternalServerError); + } + Err(e) => return Err(e), + }; + acc.push(MessageStatus { + transaction_hash: *l1_handler_tx_hash, + finality_status, + // TODO Update this once get_transaction_status supports rejections + failure_reason: None, + }); + Ok(acc) + }, + ) } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] From f5dc8158cd01606b6646e35040ad0bd3568957b0 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Fri, 17 Jan 2025 11:53:44 -0300 Subject: [PATCH 05/12] apply fmt --- crates/madara/client/eth/src/l1_messaging.rs | 2 +- crates/madara/client/rpc/src/versions/user/v0_8_0/api.rs | 4 ++-- .../user/v0_8_0/methods/read/get_messages_status.rs | 6 +++--- .../client/rpc/src/versions/user/v0_8_0/methods/read/mod.rs | 6 ++++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/madara/client/eth/src/l1_messaging.rs b/crates/madara/client/eth/src/l1_messaging.rs index a29b83290..26c433f75 100644 --- a/crates/madara/client/eth/src/l1_messaging.rs +++ b/crates/madara/client/eth/src/l1_messaging.rs @@ -11,7 +11,7 @@ use mc_db::{l1_db::LastSyncedEventBlock, MadaraBackend}; use mc_mempool::{Mempool, MempoolProvider}; use mp_utils::service::ServiceContext; use starknet_api::core::{ChainId, ContractAddress, EntryPointSelector, Nonce}; -use starknet_api::transaction::{Calldata, L1HandlerTransaction, TransactionVersion, Transaction}; +use starknet_api::transaction::{Calldata, L1HandlerTransaction, Transaction, TransactionVersion}; use starknet_api::transaction_hash::get_transaction_hash; use starknet_types_core::felt::Felt; use std::sync::Arc; diff --git a/crates/madara/client/rpc/src/versions/user/v0_8_0/api.rs b/crates/madara/client/rpc/src/versions/user/v0_8_0/api.rs index 737418b69..e0f1a2902 100644 --- a/crates/madara/client/rpc/src/versions/user/v0_8_0/api.rs +++ b/crates/madara/client/rpc/src/versions/user/v0_8_0/api.rs @@ -1,10 +1,10 @@ +use alloy::primitives::TxHash; use jsonrpsee::core::RpcResult; -use starknet_types_rpc::TxnStatus; use m_proc_macros::versioned_rpc; -use alloy::primitives::TxHash; use mp_block::BlockId; use serde::{Deserialize, Serialize}; use starknet_types_core::felt::Felt; +use starknet_types_rpc::TxnStatus; pub(crate) type NewHead = starknet_types_rpc::BlockHeader; diff --git a/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs b/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs index 5bde3c968..1efa5c791 100644 --- a/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs +++ b/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs @@ -1,5 +1,7 @@ use crate::utils::ResultExt; -use crate::versions::user::{v0_7_1::methods::read::get_transaction_status::get_transaction_status, v0_8_0::MessageStatus}; +use crate::versions::user::{ + v0_7_1::methods::read::get_transaction_status::get_transaction_status, v0_8_0::MessageStatus, +}; use crate::{Starknet, StarknetRpcApiError, StarknetRpcResult}; use alloy::primitives::TxHash; @@ -32,5 +34,3 @@ pub fn get_messages_status(starknet: &Starknet, transaction_hash: TxHash) -> Sta }, ) } - - diff --git a/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/mod.rs b/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/mod.rs index 45eb90d5e..d4f6fc5d7 100644 --- a/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/mod.rs +++ b/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/mod.rs @@ -1,4 +1,6 @@ -use crate::versions::user::v0_8_0::{ContractStorageKeysItem, GetStorageProofResult, StarknetReadRpcApiV0_8_0Server, MessageStatus}; +use crate::versions::user::v0_8_0::{ + ContractStorageKeysItem, GetStorageProofResult, MessageStatus, StarknetReadRpcApiV0_8_0Server, +}; use crate::Starknet; use alloy::primitives::TxHash; use jsonrpsee::core::{async_trait, RpcResult}; @@ -7,8 +9,8 @@ use mp_chain_config::RpcVersion; use starknet_types_core::felt::Felt; pub mod get_compiled_casm; -pub mod get_storage_proof; pub mod get_messages_status; +pub mod get_storage_proof; #[async_trait] impl StarknetReadRpcApiV0_8_0Server for Starknet { From 708a6c4dc607f752ffa0cee52c286e841f548c66 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Fri, 17 Jan 2025 17:09:51 -0300 Subject: [PATCH 06/12] wip: debugging e2e test --- crates/madara/client/eth/src/l1_messaging.rs | 2 +- crates/madara/client/mempool/src/inner/mod.rs | 2 ++ crates/madara/client/mempool/src/lib.rs | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/madara/client/eth/src/l1_messaging.rs b/crates/madara/client/eth/src/l1_messaging.rs index 7cb538b73..6d5df3a07 100644 --- a/crates/madara/client/eth/src/l1_messaging.rs +++ b/crates/madara/client/eth/src/l1_messaging.rs @@ -396,7 +396,7 @@ mod l1_messaging_tests { let _ = contract.setIsCanceled(false).send().await; // Send a Event and wait for processing, Panic if fail let _ = contract.fireEvent().send().await.expect("Failed to fire event"); - tokio::time::sleep(Duration::from_secs(10)).await; + tokio::time::sleep(Duration::from_secs(5)).await; let nonce = Nonce(Felt::from_dec_str("10000000000000000").expect("failed to parse nonce string")); diff --git a/crates/madara/client/mempool/src/inner/mod.rs b/crates/madara/client/mempool/src/inner/mod.rs index d37ab3478..007976388 100644 --- a/crates/madara/client/mempool/src/inner/mod.rs +++ b/crates/madara/client/mempool/src/inner/mod.rs @@ -670,7 +670,9 @@ impl MempoolInner { // Pop tx queue. let (tx_mempool, contract_address, nonce_next) = loop { // Bubble up None if the mempool is empty. + println!("DEBUG: Before pop"); let tx_intent = self.tx_intent_queue_ready.pop_first()?; + println!("DEBUG: tx_intent: {:?}", tx_intent); let tx_mempool = self.pop_tx_from_intent(&tx_intent); let limits = TransactionCheckedLimits::limits_for(&tx_mempool); diff --git a/crates/madara/client/mempool/src/lib.rs b/crates/madara/client/mempool/src/lib.rs index 00bb71e7d..7cf77a741 100644 --- a/crates/madara/client/mempool/src/lib.rs +++ b/crates/madara/client/mempool/src/lib.rs @@ -93,7 +93,7 @@ pub trait MempoolProvider: Send + Sync { paid_fees_on_l1: u128, ) -> Result; fn txs_take_chunk(&self, dest: &mut VecDeque, n: usize); - fn tx_take(&mut self) -> Option; + fn tx_take(&self) -> Option; fn tx_mark_included(&self, contract_address: &Felt); fn txs_re_add( &self, @@ -429,7 +429,8 @@ impl MempoolProvider for Mempool { } #[tracing::instrument(skip(self), fields(module = "Mempool"))] - fn tx_take(&mut self) -> Option { + fn tx_take(&self) -> Option { + print!("PASSING HERE?"); if let Some(mempool_tx) = self.inner.write().expect("Poisoned lock").pop_next() { let contract_address = mempool_tx.contract_address().to_felt(); let nonce_next = mempool_tx.nonce_next; @@ -759,7 +760,7 @@ mod test { l1_data_provider: Arc, tx_account_v0_valid: blockifier::transaction::transaction_execution::Transaction, ) { - let mut mempool = Mempool::new(backend, l1_data_provider, MempoolLimits::for_testing()); + let mempool = Mempool::new(backend, l1_data_provider, MempoolLimits::for_testing()); let timestamp = ArrivedAtTimestamp::now(); let result = mempool.accept_tx(tx_account_v0_valid, None, timestamp, NonceInfo::default()); assert_matches::assert_matches!(result, Ok(())); @@ -1437,7 +1438,7 @@ mod test { #[from(tx_account_v0_valid)] tx_ready: blockifier::transaction::transaction_execution::Transaction, #[from(tx_account_v0_valid)] tx_pending: blockifier::transaction::transaction_execution::Transaction, ) { - let mut mempool = Mempool::new(backend, l1_data_provider, MempoolLimits::for_testing()); + let mempool = Mempool::new(backend, l1_data_provider, MempoolLimits::for_testing()); // Insert pending transaction From bb06caa841c852ef89abe2b704dd9411687abf34 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Mon, 20 Jan 2025 18:09:21 -0300 Subject: [PATCH 07/12] wip: debugging e2e test --- crates/madara/client/eth/src/l1_messaging.rs | 33 ++++++++++++++++++- .../madara/client/mempool/src/inner/intent.rs | 20 +++++------ crates/madara/client/mempool/src/inner/mod.rs | 8 ++--- .../client/mempool/src/inner/nonce_mapping.rs | 2 +- crates/madara/client/mempool/src/lib.rs | 2 +- 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/crates/madara/client/eth/src/l1_messaging.rs b/crates/madara/client/eth/src/l1_messaging.rs index 6d5df3a07..3e7004dbd 100644 --- a/crates/madara/client/eth/src/l1_messaging.rs +++ b/crates/madara/client/eth/src/l1_messaging.rs @@ -212,7 +212,6 @@ mod l1_messaging_tests { use rstest::*; use starknet_api::core::{ContractAddress, EntryPointSelector, Nonce}; use starknet_types_core::felt::Felt; - use std::mem; use std::{sync::Arc, time::Duration}; use tempfile::TempDir; use tracing_test::traced_test; @@ -232,6 +231,7 @@ mod l1_messaging_tests { // LogMessageToL2 from https://etherscan.io/tx/0x21980d6674d33e50deee43c6c30ef3b439bd148249b4539ce37b7856ac46b843 // bytecode is compiled DummyContractBasicTestCase + // toAddress = 0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82 sol!( #[derive(Debug)] #[sol(rpc, bytecode="6080604052348015600e575f80fd5b506108258061001c5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c80634185df151461004e57806390985ef9146100585780639be446bf14610076578063af56443a146100a6575b5f80fd5b6100566100c2565b005b61006061013b565b60405161006d9190610488565b60405180910390f35b610090600480360381019061008b91906104cf565b6101ac565b60405161009d9190610512565b60405180910390f35b6100c060048036038101906100bb9190610560565b6101d8565b005b5f6100cb6101f3565b905080604001518160200151825f015173ffffffffffffffffffffffffffffffffffffffff167fdb80dd488acf86d17c747445b0eabb5d57c541d3bd7b6b87af987858e5066b2b846060015185608001518660a0015160405161013093929190610642565b60405180910390a450565b5f806101456101f3565b9050805f015173ffffffffffffffffffffffffffffffffffffffff1681602001518260800151836040015184606001515185606001516040516020016101909695949392919061072a565b6040516020818303038152906040528051906020012091505090565b5f805f9054906101000a900460ff166101c5575f6101cb565b6366b4f1055b63ffffffff169050919050565b805f806101000a81548160ff02191690831515021790555050565b6101fb610429565b5f73ae0ee0a63a2ce6baeeffe56e7714fb4efe48d41990505f7f073314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b8290505f7f01b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb1990505f600767ffffffffffffffff81111561027757610276610795565b5b6040519080825280602002602001820160405280156102a55781602001602082028036833780820191505090505b5090506060815f815181106102bd576102bc6107c2565b5b60200260200101818152505062195091816001815181106102e1576102e06107c2565b5b60200260200101818152505065231594f0c7ea81600281518110610308576103076107c2565b5b60200260200101818152505060058160038151811061032a576103296107c2565b5b602002602001018181525050624554488160048151811061034e5761034d6107c2565b5b60200260200101818152505073bdb193c166cfb7be2e51711c5648ebeef94063bb81600581518110610383576103826107c2565b5b6020026020010181815250507e7d79cd86ba27a2508a9ca55c8b3474ca082bc5173d0467824f07a32e9db888816006815181106103c3576103c26107c2565b5b6020026020010181815250505f662386f26fc1000090505f6040518060c001604052808773ffffffffffffffffffffffffffffffffffffffff16815260200186815260200185815260200184815260200183815260200182815250965050505050505090565b6040518060c001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81526020015f8152602001606081526020015f81526020015f81525090565b5f819050919050565b61048281610470565b82525050565b5f60208201905061049b5f830184610479565b92915050565b5f80fd5b6104ae81610470565b81146104b8575f80fd5b50565b5f813590506104c9816104a5565b92915050565b5f602082840312156104e4576104e36104a1565b5b5f6104f1848285016104bb565b91505092915050565b5f819050919050565b61050c816104fa565b82525050565b5f6020820190506105255f830184610503565b92915050565b5f8115159050919050565b61053f8161052b565b8114610549575f80fd5b50565b5f8135905061055a81610536565b92915050565b5f60208284031215610575576105746104a1565b5b5f6105828482850161054c565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6105bd816104fa565b82525050565b5f6105ce83836105b4565b60208301905092915050565b5f602082019050919050565b5f6105f08261058b565b6105fa8185610595565b9350610605836105a5565b805f5b8381101561063557815161061c88826105c3565b9750610627836105da565b925050600181019050610608565b5085935050505092915050565b5f6060820190508181035f83015261065a81866105e6565b90506106696020830185610503565b6106766040830184610503565b949350505050565b5f819050919050565b610698610693826104fa565b61067e565b82525050565b5f81905092915050565b6106b1816104fa565b82525050565b5f6106c283836106a8565b60208301905092915050565b5f6106d88261058b565b6106e2818561069e565b93506106ed836105a5565b805f5b8381101561071d57815161070488826106b7565b975061070f836105da565b9250506001810190506106f0565b5085935050505092915050565b5f6107358289610687565b6020820191506107458288610687565b6020820191506107558287610687565b6020820191506107658286610687565b6020820191506107758285610687565b60208201915061078582846106ce565b9150819050979650505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea2646970667358221220ddc41ccc2cc8b33e1f608fb6cabf9ead1150daa8798e94e03ce9cd61e0d9389164736f6c634300081a0033")] @@ -393,11 +393,42 @@ mod l1_messaging_tests { }) }; + if let Ok(mempool_inner_read) = mempool.inner.try_read() { + let queue_ready = mempool_inner_read.tx_intent_queue_ready.clone(); + let queue_waiting = mempool_inner_read.tx_intent_queue_pending_by_nonce.clone(); + let len = mempool_inner_read.tx_intent_queue_pending_by_nonce.len(); + println!("ready is empty1?: {:?}", queue_ready.is_empty()); + println!("waiting is empty1?: {:?}", queue_waiting.is_empty()); + println!("waiting queue len1: {:?}", len); + } else { + println!("The worker is holding the lock on mempool.inner"); + } + let _ = contract.setIsCanceled(false).send().await; // Send a Event and wait for processing, Panic if fail let _ = contract.fireEvent().send().await.expect("Failed to fire event"); tokio::time::sleep(Duration::from_secs(5)).await; + println!("Startin checking queue"); + if let Ok(mempool_inner_read) = mempool.inner.try_read() { + let queue_ready = mempool_inner_read.tx_intent_queue_ready.clone(); + let queue_waiting = mempool_inner_read.tx_intent_queue_pending_by_nonce.clone(); + println!("ready is empty?: {:?}", queue_ready.is_empty()); + println!("waiting is empty?: {:?}", queue_waiting.is_empty()); + println!("waiting queue len: {:?}", queue_waiting.len()); + let contract_address = queue_waiting.keys().next().cloned().unwrap(); + // 0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82 + println!("Contract address: {:?}", contract_address.to_hex_string()); + + let nonce_mapping = mempool_inner_read.nonce_mapping.get(&contract_address).unwrap(); + let nonce = nonce_mapping.transactions.keys().next().unwrap(); + let tx = nonce_mapping.transactions.get(nonce).unwrap(); + println!("Contract address has nonce: {:?}", nonce); + println!("Contract address has tx: {:?}", tx); + } else { + println!("The worker is holding the lock on mempool.inner"); + } + let nonce = Nonce(Felt::from_dec_str("10000000000000000").expect("failed to parse nonce string")); let (handler_tx, handler_tx_hash) = match mempool.tx_take().unwrap().tx { diff --git a/crates/madara/client/mempool/src/inner/intent.rs b/crates/madara/client/mempool/src/inner/intent.rs index 49ad9ed12..afe4b6c8a 100644 --- a/crates/madara/client/mempool/src/inner/intent.rs +++ b/crates/madara/client/mempool/src/inner/intent.rs @@ -50,20 +50,20 @@ use super::ArrivedAtTimestamp; #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub(crate) struct MarkerReady; +pub struct MarkerReady; #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub(crate) struct MarkerPendingByNonce; +pub struct MarkerPendingByNonce; #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub(crate) struct MarkerPendingByTimestamp; +pub struct MarkerPendingByTimestamp; /// A [transaction intent] which is ready to be consumed. /// /// [transaction intent]: TransactionIntent -pub(crate) type TransactionIntentReady = TransactionIntent; +pub type TransactionIntentReady = TransactionIntent; impl Ord for TransactionIntentReady { fn cmp(&self, other: &Self) -> cmp::Ordering { @@ -200,19 +200,19 @@ impl PartialOrd for TransactionIntentPendingByTimestamp { /// [Invariants]: CheckInvariants #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub(crate) struct TransactionIntent { +pub struct TransactionIntent { /// The contract responsible for sending the transaction. - pub(crate) contract_address: Felt, + pub contract_address: Felt, /// Time at which the transaction was received by the mempool. - pub(crate) timestamp: ArrivedAtTimestamp, + pub timestamp: ArrivedAtTimestamp, /// The [Nonce] of the transaction associated to this intent. We use this /// for retrieval purposes later on. - pub(crate) nonce: Nonce, + pub nonce: Nonce, /// This is the [Nonce] of the transaction right after this one. We /// precompute this to avoid making calculations on a [Felt] in the hot /// loop, as this can be expensive. - pub(crate) nonce_next: Nonce, - pub(crate) phantom: PhantomData, + pub nonce_next: Nonce, + pub phantom: PhantomData, } #[cfg(any(test, feature = "testing"))] diff --git a/crates/madara/client/mempool/src/inner/mod.rs b/crates/madara/client/mempool/src/inner/mod.rs index 007976388..c087aeb8a 100644 --- a/crates/madara/client/mempool/src/inner/mod.rs +++ b/crates/madara/client/mempool/src/inner/mod.rs @@ -156,12 +156,12 @@ pub struct MempoolInner { /// FIFO queue of all [ready] intents. /// /// [ready]: TransactionIntentReady - pub(crate) tx_intent_queue_ready: BTreeSet, + pub tx_intent_queue_ready: BTreeSet, /// FIFO queue of all [pending] intents, sorted by their [Nonce]. /// /// [pending]: TransactionIntentPendingByNonce // TODO: can remove contract_address from TransactionIntentPendingByNonce - pub(crate) tx_intent_queue_pending_by_nonce: HashMap>, + pub tx_intent_queue_pending_by_nonce: HashMap>, /// FIFO queue of all [pending] intents, sorted by their time of arrival. /// /// This is required for the rapid removal of age-exceeded txs in @@ -172,9 +172,9 @@ pub struct MempoolInner { /// [remove_age_exceeded_txs]: Self::remove_age_exceeded_txs /// [tx_intent_queue_pending_by_nonce]: Self::tx_intent_queue_pending_by_nonce // TODO: can remove nonce_next from TransactionIntentPendingByTimestamp - pub(crate) tx_intent_queue_pending_by_timestamp: BTreeSet, + pub tx_intent_queue_pending_by_timestamp: BTreeSet, /// List of all new deployed contracts currently in the mempool. - pub(crate) deployed_contracts: DeployedContracts, + pub deployed_contracts: DeployedContracts, /// Constraints on the number of transactions allowed in the [Mempool] /// /// [Mempool]: super::Mempool diff --git a/crates/madara/client/mempool/src/inner/nonce_mapping.rs b/crates/madara/client/mempool/src/inner/nonce_mapping.rs index 74ea81e3c..00f1eff09 100644 --- a/crates/madara/client/mempool/src/inner/nonce_mapping.rs +++ b/crates/madara/client/mempool/src/inner/nonce_mapping.rs @@ -11,7 +11,7 @@ use std::iter; pub struct NonceTxMapping { /// An ordered mapping of the transactions to come from an account, accessed /// by [Nonce]. - pub(crate) transactions: BTreeMap, + pub transactions: BTreeMap, } #[derive(Debug)] diff --git a/crates/madara/client/mempool/src/lib.rs b/crates/madara/client/mempool/src/lib.rs index 7cf77a741..9246a8bcd 100644 --- a/crates/madara/client/mempool/src/lib.rs +++ b/crates/madara/client/mempool/src/lib.rs @@ -109,7 +109,7 @@ pub trait MempoolProvider: Send + Sync { pub struct Mempool { backend: Arc, l1_data_provider: Arc, - inner: RwLock, + pub inner: RwLock, metrics: MempoolMetrics, nonce_cache: RwLock>, } From b3d489b4133c89741e955448797c9ff4370febba Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 21 Jan 2025 11:56:07 -0300 Subject: [PATCH 08/12] format and clippy --- crates/madara/client/db/src/l1_db.rs | 1 - crates/madara/client/eth/src/l1_messaging.rs | 34 +------------------ crates/madara/client/mempool/src/inner/mod.rs | 2 -- crates/madara/client/mempool/src/lib.rs | 6 ++-- 4 files changed, 5 insertions(+), 38 deletions(-) diff --git a/crates/madara/client/db/src/l1_db.rs b/crates/madara/client/db/src/l1_db.rs index f103696fd..5f78bc621 100644 --- a/crates/madara/client/db/src/l1_db.rs +++ b/crates/madara/client/db/src/l1_db.rs @@ -148,7 +148,6 @@ impl MadaraBackend { l1_handler_tx_hash: Felt, order: u64, ) -> Result<(), DbError> { - println!("Adding L1-L2 mapping: {}, {}", l1_tx_hash, l1_handler_tx_hash); let l1_l2_mappings_column = self.db.get_column(Column::L1MessagingHandlerTxHashes); let mut key = [0u8; 40]; key[..32].copy_from_slice(l1_tx_hash.as_slice()); diff --git a/crates/madara/client/eth/src/l1_messaging.rs b/crates/madara/client/eth/src/l1_messaging.rs index 3e7004dbd..6ab4697dd 100644 --- a/crates/madara/client/eth/src/l1_messaging.rs +++ b/crates/madara/client/eth/src/l1_messaging.rs @@ -96,12 +96,11 @@ async fn process_l1_to_l2_msg( ); let tx_nonce = Nonce(u256_to_felt(event.nonce)?); + // Ensure that L1 message has not been executed if backend.has_l1_messaging_nonce(tx_nonce)? { tracing::debug!("⟠ L1 -> L2 event already processed: {tx_nonce:?}"); return Ok(()); - } else { - backend.set_l1_messaging_nonce(tx_nonce)?; } // Check if cancellation was initiated @@ -393,42 +392,11 @@ mod l1_messaging_tests { }) }; - if let Ok(mempool_inner_read) = mempool.inner.try_read() { - let queue_ready = mempool_inner_read.tx_intent_queue_ready.clone(); - let queue_waiting = mempool_inner_read.tx_intent_queue_pending_by_nonce.clone(); - let len = mempool_inner_read.tx_intent_queue_pending_by_nonce.len(); - println!("ready is empty1?: {:?}", queue_ready.is_empty()); - println!("waiting is empty1?: {:?}", queue_waiting.is_empty()); - println!("waiting queue len1: {:?}", len); - } else { - println!("The worker is holding the lock on mempool.inner"); - } - let _ = contract.setIsCanceled(false).send().await; // Send a Event and wait for processing, Panic if fail let _ = contract.fireEvent().send().await.expect("Failed to fire event"); tokio::time::sleep(Duration::from_secs(5)).await; - println!("Startin checking queue"); - if let Ok(mempool_inner_read) = mempool.inner.try_read() { - let queue_ready = mempool_inner_read.tx_intent_queue_ready.clone(); - let queue_waiting = mempool_inner_read.tx_intent_queue_pending_by_nonce.clone(); - println!("ready is empty?: {:?}", queue_ready.is_empty()); - println!("waiting is empty?: {:?}", queue_waiting.is_empty()); - println!("waiting queue len: {:?}", queue_waiting.len()); - let contract_address = queue_waiting.keys().next().cloned().unwrap(); - // 0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82 - println!("Contract address: {:?}", contract_address.to_hex_string()); - - let nonce_mapping = mempool_inner_read.nonce_mapping.get(&contract_address).unwrap(); - let nonce = nonce_mapping.transactions.keys().next().unwrap(); - let tx = nonce_mapping.transactions.get(nonce).unwrap(); - println!("Contract address has nonce: {:?}", nonce); - println!("Contract address has tx: {:?}", tx); - } else { - println!("The worker is holding the lock on mempool.inner"); - } - let nonce = Nonce(Felt::from_dec_str("10000000000000000").expect("failed to parse nonce string")); let (handler_tx, handler_tx_hash) = match mempool.tx_take().unwrap().tx { diff --git a/crates/madara/client/mempool/src/inner/mod.rs b/crates/madara/client/mempool/src/inner/mod.rs index c087aeb8a..2d8914e6d 100644 --- a/crates/madara/client/mempool/src/inner/mod.rs +++ b/crates/madara/client/mempool/src/inner/mod.rs @@ -670,9 +670,7 @@ impl MempoolInner { // Pop tx queue. let (tx_mempool, contract_address, nonce_next) = loop { // Bubble up None if the mempool is empty. - println!("DEBUG: Before pop"); let tx_intent = self.tx_intent_queue_ready.pop_first()?; - println!("DEBUG: tx_intent: {:?}", tx_intent); let tx_mempool = self.pop_tx_from_intent(&tx_intent); let limits = TransactionCheckedLimits::limits_for(&tx_mempool); diff --git a/crates/madara/client/mempool/src/lib.rs b/crates/madara/client/mempool/src/lib.rs index 9246a8bcd..7d2213403 100644 --- a/crates/madara/client/mempool/src/lib.rs +++ b/crates/madara/client/mempool/src/lib.rs @@ -350,7 +350,6 @@ impl MempoolProvider for Mempool { let nonce = Nonce(Felt::from(tx.nonce)); let (btx, class) = tx.into_blockifier(self.chain_id(), self.backend.chain_config().latest_protocol_version, paid_fees_on_l1)?; - // L1 Handler nonces represent the ordering of L1 transactions sent by // the core L1 contract. In principle this is a bit strange, as there // currently is only 1 core L1 contract, so all transactions should be @@ -366,6 +365,10 @@ impl MempoolProvider for Mempool { let nonce_info = if nonce != nonce_target { NonceInfo::pending(nonce, nonce_next) } else { + let _ = self + .backend + .set_l1_messaging_nonce(nonce) + .map_err(|_err| MempoolError::StorageError(MadaraStorageError::InvalidNonce)); NonceInfo::ready(nonce, nonce_next) }; @@ -430,7 +433,6 @@ impl MempoolProvider for Mempool { #[tracing::instrument(skip(self), fields(module = "Mempool"))] fn tx_take(&self) -> Option { - print!("PASSING HERE?"); if let Some(mempool_tx) = self.inner.write().expect("Poisoned lock").pop_next() { let contract_address = mempool_tx.contract_address().to_felt(); let nonce_next = mempool_tx.nonce_next; From 0ec57ceb3566455f61030953e759f1088f0ef886 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 21 Jan 2025 12:04:34 -0300 Subject: [PATCH 09/12] revert pub for pub(create) changed for debugging --- .../madara/client/mempool/src/inner/intent.rs | 20 +++++++++---------- crates/madara/client/mempool/src/inner/mod.rs | 8 ++++---- .../client/mempool/src/inner/nonce_mapping.rs | 2 +- crates/madara/client/mempool/src/lib.rs | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/madara/client/mempool/src/inner/intent.rs b/crates/madara/client/mempool/src/inner/intent.rs index afe4b6c8a..49ad9ed12 100644 --- a/crates/madara/client/mempool/src/inner/intent.rs +++ b/crates/madara/client/mempool/src/inner/intent.rs @@ -50,20 +50,20 @@ use super::ArrivedAtTimestamp; #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub struct MarkerReady; +pub(crate) struct MarkerReady; #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub struct MarkerPendingByNonce; +pub(crate) struct MarkerPendingByNonce; #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub struct MarkerPendingByTimestamp; +pub(crate) struct MarkerPendingByTimestamp; /// A [transaction intent] which is ready to be consumed. /// /// [transaction intent]: TransactionIntent -pub type TransactionIntentReady = TransactionIntent; +pub(crate) type TransactionIntentReady = TransactionIntent; impl Ord for TransactionIntentReady { fn cmp(&self, other: &Self) -> cmp::Ordering { @@ -200,19 +200,19 @@ impl PartialOrd for TransactionIntentPendingByTimestamp { /// [Invariants]: CheckInvariants #[derive(Debug)] #[cfg_attr(any(test, feature = "testing"), derive(Clone))] -pub struct TransactionIntent { +pub(crate) struct TransactionIntent { /// The contract responsible for sending the transaction. - pub contract_address: Felt, + pub(crate) contract_address: Felt, /// Time at which the transaction was received by the mempool. - pub timestamp: ArrivedAtTimestamp, + pub(crate) timestamp: ArrivedAtTimestamp, /// The [Nonce] of the transaction associated to this intent. We use this /// for retrieval purposes later on. - pub nonce: Nonce, + pub(crate) nonce: Nonce, /// This is the [Nonce] of the transaction right after this one. We /// precompute this to avoid making calculations on a [Felt] in the hot /// loop, as this can be expensive. - pub nonce_next: Nonce, - pub phantom: PhantomData, + pub(crate) nonce_next: Nonce, + pub(crate) phantom: PhantomData, } #[cfg(any(test, feature = "testing"))] diff --git a/crates/madara/client/mempool/src/inner/mod.rs b/crates/madara/client/mempool/src/inner/mod.rs index 2d8914e6d..d37ab3478 100644 --- a/crates/madara/client/mempool/src/inner/mod.rs +++ b/crates/madara/client/mempool/src/inner/mod.rs @@ -156,12 +156,12 @@ pub struct MempoolInner { /// FIFO queue of all [ready] intents. /// /// [ready]: TransactionIntentReady - pub tx_intent_queue_ready: BTreeSet, + pub(crate) tx_intent_queue_ready: BTreeSet, /// FIFO queue of all [pending] intents, sorted by their [Nonce]. /// /// [pending]: TransactionIntentPendingByNonce // TODO: can remove contract_address from TransactionIntentPendingByNonce - pub tx_intent_queue_pending_by_nonce: HashMap>, + pub(crate) tx_intent_queue_pending_by_nonce: HashMap>, /// FIFO queue of all [pending] intents, sorted by their time of arrival. /// /// This is required for the rapid removal of age-exceeded txs in @@ -172,9 +172,9 @@ pub struct MempoolInner { /// [remove_age_exceeded_txs]: Self::remove_age_exceeded_txs /// [tx_intent_queue_pending_by_nonce]: Self::tx_intent_queue_pending_by_nonce // TODO: can remove nonce_next from TransactionIntentPendingByTimestamp - pub tx_intent_queue_pending_by_timestamp: BTreeSet, + pub(crate) tx_intent_queue_pending_by_timestamp: BTreeSet, /// List of all new deployed contracts currently in the mempool. - pub deployed_contracts: DeployedContracts, + pub(crate) deployed_contracts: DeployedContracts, /// Constraints on the number of transactions allowed in the [Mempool] /// /// [Mempool]: super::Mempool diff --git a/crates/madara/client/mempool/src/inner/nonce_mapping.rs b/crates/madara/client/mempool/src/inner/nonce_mapping.rs index 00f1eff09..74ea81e3c 100644 --- a/crates/madara/client/mempool/src/inner/nonce_mapping.rs +++ b/crates/madara/client/mempool/src/inner/nonce_mapping.rs @@ -11,7 +11,7 @@ use std::iter; pub struct NonceTxMapping { /// An ordered mapping of the transactions to come from an account, accessed /// by [Nonce]. - pub transactions: BTreeMap, + pub(crate) transactions: BTreeMap, } #[derive(Debug)] diff --git a/crates/madara/client/mempool/src/lib.rs b/crates/madara/client/mempool/src/lib.rs index 7d2213403..3574a82ab 100644 --- a/crates/madara/client/mempool/src/lib.rs +++ b/crates/madara/client/mempool/src/lib.rs @@ -109,7 +109,7 @@ pub trait MempoolProvider: Send + Sync { pub struct Mempool { backend: Arc, l1_data_provider: Arc, - pub inner: RwLock, + inner: RwLock, metrics: MempoolMetrics, nonce_cache: RwLock>, } From 9b01a3b2dbf7a8ec8bec12db2540270dc11e2b92 Mon Sep 17 00:00:00 2001 From: trantorian <114066155+Trantorian1@users.noreply.github.com> Date: Tue, 21 Jan 2025 17:31:14 +0100 Subject: [PATCH 10/12] fix(nonce): l1_handler mempool nonce --- crates/madara/client/mempool/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/madara/client/mempool/src/lib.rs b/crates/madara/client/mempool/src/lib.rs index 3574a82ab..ff4be8c82 100644 --- a/crates/madara/client/mempool/src/lib.rs +++ b/crates/madara/client/mempool/src/lib.rs @@ -360,8 +360,7 @@ impl MempoolProvider for Mempool { // INFO: L1 nonce are stored differently in the db because of this, which is // why we do not use `retrieve_nonce_readiness`. let nonce_next = nonce.try_increment()?; - let nonce_target = - self.backend.get_l1_messaging_nonce_latest()?.map(|nonce| nonce.try_increment()).unwrap_or(Ok(nonce))?; + let nonce_target = self.backend.get_l1_messaging_nonce_latest()?.unwrap_or(nonce); let nonce_info = if nonce != nonce_target { NonceInfo::pending(nonce, nonce_next) } else { From 0519656f17d31ed28a89588074400facae6bee2c Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 21 Jan 2025 15:42:59 -0300 Subject: [PATCH 11/12] update db in sync func. update db version. log error if rpc fail --- .db-versions.yml | 4 +++- crates/madara/client/eth/src/l1_messaging.rs | 2 ++ crates/madara/client/mempool/src/lib.rs | 4 ---- .../user/v0_8_0/methods/read/get_messages_status.rs | 8 +++++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.db-versions.yml b/.db-versions.yml index 9a9dea695..73983d32d 100644 --- a/.db-versions.yml +++ b/.db-versions.yml @@ -1,5 +1,7 @@ -current_version: 1 +current_version: 2 versions: + - version: 2 + pr: 388 - version: 1 pr: 450 - version: 0 diff --git a/crates/madara/client/eth/src/l1_messaging.rs b/crates/madara/client/eth/src/l1_messaging.rs index 6ab4697dd..00018a5f7 100644 --- a/crates/madara/client/eth/src/l1_messaging.rs +++ b/crates/madara/client/eth/src/l1_messaging.rs @@ -101,6 +101,8 @@ async fn process_l1_to_l2_msg( if backend.has_l1_messaging_nonce(tx_nonce)? { tracing::debug!("⟠ L1 -> L2 event already processed: {tx_nonce:?}"); return Ok(()); + } else { + backend.set_l1_messaging_nonce(tx_nonce)?; } // Check if cancellation was initiated diff --git a/crates/madara/client/mempool/src/lib.rs b/crates/madara/client/mempool/src/lib.rs index ff4be8c82..90fe50489 100644 --- a/crates/madara/client/mempool/src/lib.rs +++ b/crates/madara/client/mempool/src/lib.rs @@ -364,10 +364,6 @@ impl MempoolProvider for Mempool { let nonce_info = if nonce != nonce_target { NonceInfo::pending(nonce, nonce_next) } else { - let _ = self - .backend - .set_l1_messaging_nonce(nonce) - .map_err(|_err| MempoolError::StorageError(MadaraStorageError::InvalidNonce)); NonceInfo::ready(nonce, nonce_next) }; diff --git a/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs b/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs index 1efa5c791..c4b147705 100644 --- a/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs +++ b/crates/madara/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs @@ -22,7 +22,13 @@ pub fn get_messages_status(starknet: &Starknet, transaction_hash: TxHash) -> Sta tracing::error!("L1 handler tx {l1_handler_tx_hash:?} for L1 tx {transaction_hash:?} not found"); return Err(StarknetRpcApiError::InternalServerError); } - Err(e) => return Err(e), + Err(e) => { + tracing::error!( + "Failed to retrieve transaction status for L1 handler transaction {l1_handler_tx_hash:?} \ + related to L1 transaction {transaction_hash:?}: {e:?}" + ); + return Err(StarknetRpcApiError::InternalServerError); + } }; acc.push(MessageStatus { transaction_hash: *l1_handler_tx_hash, From 1c24712d4345dd43801c06ba59a03458910b43dd Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Wed, 22 Jan 2025 10:34:19 -0300 Subject: [PATCH 12/12] format toml files --- crates/madara/client/eth/Cargo.toml | 2 +- crates/madara/client/gateway/client/Cargo.toml | 2 +- crates/madara/client/gateway/server/Cargo.toml | 2 +- crates/madara/client/mempool/Cargo.toml | 2 +- crates/madara/node/Cargo.toml | 2 +- crates/madara/primitives/utils/Cargo.toml | 2 +- crates/madara/tests/Cargo.toml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/madara/client/eth/Cargo.toml b/crates/madara/client/eth/Cargo.toml index 6bb419fe7..fa4766c88 100644 --- a/crates/madara/client/eth/Cargo.toml +++ b/crates/madara/client/eth/Cargo.toml @@ -28,9 +28,9 @@ mp-transactions.workspace = true mp-utils.workspace = true # Starknet +blockifier.workspace = true starknet-types-core.workspace = true starknet_api.workspace = true -blockifier.workspace = true # Other diff --git a/crates/madara/client/gateway/client/Cargo.toml b/crates/madara/client/gateway/client/Cargo.toml index 4576fc86a..f6c636e35 100644 --- a/crates/madara/client/gateway/client/Cargo.toml +++ b/crates/madara/client/gateway/client/Cargo.toml @@ -30,8 +30,8 @@ starknet-types-rpc.workspace = true anyhow.workspace = true bytes.workspace = true futures.workspace = true -http-body-util.workspace = true http.workspace = true +http-body-util.workspace = true hyper = { workspace = true, features = ["full"] } hyper-tls.workspace = true hyper-util.workspace = true diff --git a/crates/madara/client/gateway/server/Cargo.toml b/crates/madara/client/gateway/server/Cargo.toml index e520a99f0..83a2492e4 100644 --- a/crates/madara/client/gateway/server/Cargo.toml +++ b/crates/madara/client/gateway/server/Cargo.toml @@ -37,8 +37,8 @@ hyper-util.workspace = true serde = { workspace = true, features = ["derive"] } serde_json.workspace = true thiserror.workspace = true -tokio-util.workspace = true tokio.workspace = true +tokio-util.workspace = true tracing.workspace = true [dev-dependencies] diff --git a/crates/madara/client/mempool/Cargo.toml b/crates/madara/client/mempool/Cargo.toml index 79e4ac2e1..6e937af8c 100644 --- a/crates/madara/client/mempool/Cargo.toml +++ b/crates/madara/client/mempool/Cargo.toml @@ -64,8 +64,8 @@ mockall = { workspace = true, optional = true } reqwest.workspace = true serde.workspace = true thiserror.workspace = true -tokio-util.workspace = true tokio.workspace = true +tokio-util.workspace = true #Instrumentation opentelemetry = { workspace = true, features = ["metrics", "logs"] } diff --git a/crates/madara/node/Cargo.toml b/crates/madara/node/Cargo.toml index 05240ceea..4b1e7c4bf 100644 --- a/crates/madara/node/Cargo.toml +++ b/crates/madara/node/Cargo.toml @@ -60,8 +60,8 @@ serde_json.workspace = true serde_yaml.workspace = true thiserror.workspace = true tokio.workspace = true -tower-http.workspace = true tower.workspace = true +tower-http.workspace = true url.workspace = true #Instrumentation diff --git a/crates/madara/primitives/utils/Cargo.toml b/crates/madara/primitives/utils/Cargo.toml index aab8d40c2..183e8aa0e 100644 --- a/crates/madara/primitives/utils/Cargo.toml +++ b/crates/madara/primitives/utils/Cargo.toml @@ -32,8 +32,8 @@ rand.workspace = true rayon.workspace = true serde.workspace = true serde_yaml.workspace = true -tokio-util.workspace = true tokio.workspace = true +tokio-util.workspace = true url.workspace = true #Instrumentation diff --git a/crates/madara/tests/Cargo.toml b/crates/madara/tests/Cargo.toml index 1254ffd7b..8e1b4d1f1 100644 --- a/crates/madara/tests/Cargo.toml +++ b/crates/madara/tests/Cargo.toml @@ -26,5 +26,5 @@ starknet-providers.workspace = true starknet-types-core.workspace = true tempfile.workspace = true tokio = { workspace = true, features = ["rt", "macros"] } -tracing-subscriber.workspace = true tracing.workspace = true +tracing-subscriber.workspace = true