Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): v0.8.0 getMessagesStatus method #388

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .db-versions.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
current_version: 1
current_version: 2
versions:
- version: 2
pr: 388
- version: 1
pr: 450
- version: 0
Expand Down
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(primitives): limit legacy class sizes
- fix(block_production): dynamic block closing now adds special address with prev block hash
- fix(rpc): call, simulate, estimate rpcs executed on top of the block, not at the start of it
Expand Down
3 changes: 3 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/madara/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ starknet-types-rpc = { workspace = true }
starknet_api = { workspace = true }

# Other
alloy = { workspace = true }
anyhow.workspace = true
bincode = { workspace = true }
librocksdb-sys = { workspace = true }
Expand Down
35 changes: 32 additions & 3 deletions crates/madara/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::{IteratorMode, 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 @@ -129,6 +130,34 @@ impl MadaraBackend {
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 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::<Result<_, rocksdb::Error>>()?;
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(())
}

/// Retrieve the latest L1 messaging [Nonce] if one is available, otherwise
/// returns [None].
pub fn get_l1_messaging_nonce_latest(&self) -> Result<Option<Nonce>, MadaraStorageError> {
Expand Down
3 changes: 3 additions & 0 deletions crates/madara/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub enum Column {

L1Messaging,
L1MessagingNonce,
L1MessagingHandlerTxHashes,

/// Devnet: stores the private keys for the devnet predeployed contracts
Devnet,
Expand Down Expand Up @@ -196,6 +197,7 @@ impl Column {
BonsaiClassesLog,
L1Messaging,
L1MessagingNonce,
L1MessagingHandlerTxHashes,
PendingContractToClassHashes,
PendingContractToNonces,
PendingContractStorage,
Expand Down Expand Up @@ -232,6 +234,7 @@ impl Column {
ContractStorage => "contract_storage",
L1Messaging => "l1_messaging",
L1MessagingNonce => "l1_messaging_nonce",
L1MessagingHandlerTxHashes => "l1_messaging_handler_tx_hashes",
Trantorian1 marked this conversation as resolved.
Show resolved Hide resolved
PendingContractToClassHashes => "pending_contract_to_class_hashes",
PendingContractToNonces => "pending_contract_to_nonces",
PendingContractStorage => "pending_contract_storage",
Expand Down
5 changes: 5 additions & 0 deletions crates/madara/client/db/src/rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -56,6 +58,9 @@ impl Column {
contract_db::CONTRACT_NONCES_PREFIX_EXTRACTOR,
));
}
Column::L1MessagingHandlerTxHashes => {
options.set_prefix_extractor(SliceTransform::create_fixed_prefix(TxHash::LEN));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given we are adding support for l2<>l3 as well in the madara, do you think it make sense to make it generic?

}
_ => {}
}

Expand Down
1 change: 1 addition & 0 deletions crates/madara/client/eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mp-transactions.workspace = true
mp-utils.workspace = true

# Starknet
blockifier.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true

Expand Down
Loading
Loading