Skip to content

Commit

Permalink
feat(rpc): v0.8.0 getMessagesStatus method
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsasari committed Nov 20, 2024
1 parent e140ab3 commit 7346894
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 128 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
35 changes: 32 additions & 3 deletions crates/client/db/src/l1_db.rs
Original file line number Diff line number Diff line change
@@ -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<T, E = MadaraStorageError> = std::result::Result<T, E>;

Expand Down Expand Up @@ -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<Vec<Felt>, 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(())
}
}
8 changes: 8 additions & 0 deletions crates/client/db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -175,6 +177,7 @@ pub enum Column {

L1Messaging,
L1MessagingNonce,
L1MessagingHandlerTxHashes,

/// Devnet: stores the private keys for the devnet predeployed contracts
Devnet,
Expand Down Expand Up @@ -222,6 +225,7 @@ impl Column {
BonsaiClassesLog,
L1Messaging,
L1MessagingNonce,
L1MessagingHandlerTxHashes,
PendingContractToClassHashes,
PendingContractToNonces,
PendingContractStorage,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7346894

Please sign in to comment.