-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: main
Are you sure you want to change the base?
Changes from all commits
7346894
97329f9
bbed31d
e5356f7
09a5a54
a3fd0a7
425b4ee
4922188
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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>; | ||
|
||
|
@@ -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, | ||
) -> 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Storing the mapping is guarded behind |
||
self.db.put_cf_opt(&l1_l2_mappings_column, key, l1_handler_tx_hash.to_bytes_be(), &writeopts)?; | ||
Ok(()) | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.