From 476dc50482392a39b9bb4e1678b524a65f5bd102 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Thu, 29 Jan 2026 13:47:39 -0300 Subject: [PATCH] handle comments --- bedrock_client/src/lib.rs | 1 + indexer_service/protocol/src/lib.rs | 8 +++++++- integration_tests/src/lib.rs | 8 ++++++-- nssa/src/state.rs | 3 +-- sequencer_core/src/lib.rs | 26 +++++++++++++------------- sequencer_runner/src/lib.rs | 2 +- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/bedrock_client/src/lib.rs b/bedrock_client/src/lib.rs index 631216bd..b34687c3 100644 --- a/bedrock_client/src/lib.rs +++ b/bedrock_client/src/lib.rs @@ -17,6 +17,7 @@ pub struct BackoffConfig { // Simple wrapper // maybe extend in the future for our purposes +// `Clone` is cheap because `CommonHttpClient` is internally reference counted (`Arc`). #[derive(Clone)] pub struct BedrockClient { http_client: CommonHttpClient, diff --git a/indexer_service/protocol/src/lib.rs b/indexer_service/protocol/src/lib.rs index 096fbc2f..627d8513 100644 --- a/indexer_service/protocol/src/lib.rs +++ b/indexer_service/protocol/src/lib.rs @@ -30,7 +30,6 @@ pub struct Account { pub type BlockId = u64; pub type TimeStamp = u64; -pub type MsgId = [u8; 32]; #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)] pub struct Block { @@ -190,6 +189,13 @@ pub struct Hash( pub [u8; 32], ); +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)] +pub struct MsgId( + #[serde(with = "base64::arr")] + #[schemars(with = "String", description = "base64-encoded Bedrock message id")] + pub [u8; 32], +); + #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)] pub enum BedrockStatus { Pending, diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index 524621ad..5d810166 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -163,8 +163,12 @@ impl TestContext { // Setting port to 0 lets the OS choose a free port for us config.port = 0; - let (sequencer_server_handle, sequencer_addr, sequencer_loop_handle, _) = - sequencer_runner::startup_sequencer(config).await?; + let ( + sequencer_server_handle, + sequencer_addr, + sequencer_loop_handle, + _retry_pending_blocks_handle, + ) = sequencer_runner::startup_sequencer(config).await?; Ok(( sequencer_server_handle, diff --git a/nssa/src/state.rs b/nssa/src/state.rs index da86103b..d6bf8d60 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -1,5 +1,6 @@ use std::collections::{BTreeSet, HashMap, HashSet}; +use borsh::{BorshDeserialize, BorshSerialize}; use nssa_core::{ Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, MembershipProof, Nullifier, account::{Account, AccountId}, @@ -103,8 +104,6 @@ impl BorshDeserialize for NullifierSet { } } -use borsh::{BorshDeserialize, BorshSerialize}; - #[derive(BorshSerialize, BorshDeserialize)] #[cfg_attr(test, derive(Debug, PartialEq, Eq))] pub struct V02State { diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 5e14c26f..119d5d73 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -80,20 +80,20 @@ impl SequencerCore { info!( "No database found when starting the sequencer. Creating a fresh new with the initial data in config" ); - let mut initial_commitments = vec![]; + let initial_commitments: Vec = config + .initial_commitments + .iter() + .map(|init_comm_data| { + let npk = &init_comm_data.npk; - for init_comm_data in config.initial_commitments.clone() { - let npk = init_comm_data.npk; + let mut acc = init_comm_data.account.clone(); - let mut acc = init_comm_data.account; + acc.program_owner = + nssa::program::Program::authenticated_transfer_program().id(); - acc.program_owner = - nssa::program::Program::authenticated_transfer_program().id(); - - let comm = nssa_core::Commitment::new(&npk, &acc); - - initial_commitments.push(comm); - } + nssa_core::Commitment::new(&npk, &acc) + }) + .collect(); let init_accs: Vec<(nssa::AccountId, u128)> = config .initial_accounts @@ -239,7 +239,7 @@ impl SequencerCore { /// This method must be called when new blocks are finalized on Bedrock. /// All pending blocks with an ID less than or equal to `last_finalized_block_id` /// are removed from the database. - pub fn delete_finalized_blocks_from_db(&mut self, last_finalized_block_id: u64) -> Result<()> { + pub fn clean_finalized_blocks_from_db(&mut self, last_finalized_block_id: u64) -> Result<()> { if let Some(first_pending_block_id) = self .get_pending_blocks()? .iter() @@ -845,7 +845,7 @@ mod tests { let last_finalized_block = 3; sequencer - .delete_finalized_blocks_from_db(last_finalized_block) + .clean_finalized_blocks_from_db(last_finalized_block) .unwrap(); assert_eq!(sequencer.get_pending_blocks().unwrap().len(), 1); diff --git a/sequencer_runner/src/lib.rs b/sequencer_runner/src/lib.rs index 8540c2c2..8dbea525 100644 --- a/sequencer_runner/src/lib.rs +++ b/sequencer_runner/src/lib.rs @@ -68,7 +68,7 @@ pub async fn startup_sequencer( }; info!("Resubmitting {} pending blocks", pending_blocks.len()); - for block in pending_blocks.iter() { + for block in &pending_blocks { if let Err(e) = client.submit_block_to_bedrock(block).await { warn!( "Failed to resubmit block with id {} with error {}",