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 8 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
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(fgw): fetch class
- feat: possibility of starting madara & kakarot-rpc in docker
- feat(debug): service cancelling and profiling build
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 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,
Copy link
Member

Choose a reason for hiding this comment

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

Can the index be a type smaller than u64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason it's u64 is because it's using the log index. Not sure why that needs to be that big, even u32 is more than enough to cover logs in a block I would have thought. I can reduce if you think it's safe.

) -> 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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't WAL be enabled so we don't risk loosing this on a node restart?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Storing the mapping is guarded behind messaging_update_last_synced_l1_block_with_event, which also has WAL disabled. The sync will restart from the last stored LastSyncedEventBlock. So I think that should also be enabled? @cchudant

self.db.put_cf_opt(&l1_l2_mappings_column, key, l1_handler_tx_hash.to_bytes_be(), &writeopts)?;
Ok(())
}
}
3 changes: 3 additions & 0 deletions crates/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub enum Column {

L1Messaging,
L1MessagingNonce,
L1MessagingHandlerTxHashes,

/// Devnet: stores the private keys for the devnet predeployed contracts
Devnet,
Expand Down Expand Up @@ -190,6 +191,7 @@ impl Column {
BonsaiClassesLog,
L1Messaging,
L1MessagingNonce,
L1MessagingHandlerTxHashes,
PendingContractToClassHashes,
PendingContractToNonces,
PendingContractStorage,
Expand Down Expand Up @@ -227,6 +229,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
5 changes: 5 additions & 0 deletions crates/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));
}
_ => {}
}

Expand Down
Loading
Loading