diff --git a/common/src/block.rs b/common/src/block.rs index faafbf3a..6decc390 100644 --- a/common/src/block.rs +++ b/common/src/block.rs @@ -1,9 +1,8 @@ use borsh::{BorshDeserialize, BorshSerialize}; +use nssa_core::{BlockId, Timestamp}; use serde::{Deserialize, Serialize}; use sha2::{Digest as _, Sha256, digest::FixedOutput as _}; -use nssa_core::{BlockId, Timestamp}; - use crate::{HashType, transaction::NSSATransaction}; pub type MantleMsgId = [u8; 32]; diff --git a/common/src/transaction.rs b/common/src/transaction.rs index c59bbd18..ea0b9819 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -73,9 +73,7 @@ impl NSSATransaction { timestamp: Timestamp, ) -> Result { match &self { - Self::Public(tx) => { - state.transition_from_public_transaction(tx, block_id, timestamp) - } + Self::Public(tx) => state.transition_from_public_transaction(tx, block_id, timestamp), Self::PrivacyPreserving(tx) => { state.transition_from_privacy_preserving_transaction(tx, block_id, timestamp) } diff --git a/indexer/core/src/block_store.rs b/indexer/core/src/block_store.rs index 866add94..7faf5376 100644 --- a/indexer/core/src/block_store.rs +++ b/indexer/core/src/block_store.rs @@ -6,8 +6,8 @@ use common::{ block::{BedrockStatus, Block}, transaction::NSSATransaction, }; -use nssa_core::BlockId; use nssa::{Account, AccountId, V03State}; +use nssa_core::BlockId; use storage::indexer::RocksDBIO; use tokio::sync::RwLock; diff --git a/nssa/core/src/program.rs b/nssa/core/src/program.rs index 277ae36f..e3953f6a 100644 --- a/nssa/core/src/program.rs +++ b/nssa/core/src/program.rs @@ -183,8 +183,7 @@ impl ValidityWindow { /// Valid for values in the range [from, to), where `from` is included and `to` is excluded. #[must_use] pub fn is_valid_for(&self, value: T) -> bool { - self.from.is_none_or(|start| value >= start) - && self.to.is_none_or(|end| value < end) + self.from.is_none_or(|start| value >= start) && self.to.is_none_or(|end| value < end) } /// Returns `Err(InvalidWindow)` if both bounds are set and `from >= to`. @@ -310,7 +309,9 @@ impl ProgramOutput { /// Sets the block ID validity window from a fallible range conversion (`1..5`). /// Returns `Err` if the range is empty. - pub fn try_with_block_validity_window>( + pub fn try_with_block_validity_window< + W: TryInto, + >( mut self, window: W, ) -> Result { @@ -319,14 +320,19 @@ impl ProgramOutput { } /// Sets the timestamp validity window from an infallible range conversion. - pub fn with_timestamp_validity_window>(mut self, window: W) -> Self { + pub fn with_timestamp_validity_window>( + mut self, + window: W, + ) -> Self { self.timestamp_validity_window = window.into(); self } /// Sets the timestamp validity window from a fallible range conversion. /// Returns `Err` if the range is empty. - pub fn try_with_timestamp_validity_window>( + pub fn try_with_timestamp_validity_window< + W: TryInto, + >( mut self, window: W, ) -> Result { diff --git a/nssa/src/public_transaction/transaction.rs b/nssa/src/public_transaction/transaction.rs index aea05965..d436aaff 100644 --- a/nssa/src/public_transaction/transaction.rs +++ b/nssa/src/public_transaction/transaction.rs @@ -196,7 +196,9 @@ impl PublicTransaction { // Verify validity window ensure!( program_output.block_validity_window.is_valid_for(block_id) - && program_output.timestamp_validity_window.is_valid_for(timestamp), + && program_output + .timestamp_validity_window + .is_valid_for(timestamp), NssaError::OutOfValidityWindow ); diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 9f58bbaa..cae74f2a 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -3032,7 +3032,10 @@ pub mod tests { let account_ids = vec![pre.account_id]; let nonces = vec![]; let program_id = validity_window_program.id(); - let instruction = (block_validity_window, TimestampValidityWindow::new_unbounded()); + let instruction = ( + block_validity_window, + TimestampValidityWindow::new_unbounded(), + ); let message = public_transaction::Message::try_new(program_id, account_ids, nonces, instruction) .unwrap(); @@ -3040,12 +3043,13 @@ pub mod tests { PublicTransaction::new(message, witness_set) }; let result = state.transition_from_public_transaction(&tx, block_id, 0); - let is_inside_validity_window = match (block_validity_window.start(), block_validity_window.end()) { - (Some(s), Some(e)) => s <= block_id && block_id < e, - (Some(s), None) => s <= block_id, - (None, Some(e)) => block_id < e, - (None, None) => true, - }; + let is_inside_validity_window = + match (block_validity_window.start(), block_validity_window.end()) { + (Some(s), Some(e)) => s <= block_id && block_id < e, + (Some(s), None) => s <= block_id, + (None, Some(e)) => block_id < e, + (None, None) => true, + }; if is_inside_validity_window { assert!(result.is_ok()); } else { @@ -3080,8 +3084,10 @@ pub mod tests { let account_ids = vec![pre.account_id]; let nonces = vec![]; let program_id = validity_window_program.id(); - let instruction = - (BlockValidityWindow::new_unbounded(), timestamp_validity_window); + let instruction = ( + BlockValidityWindow::new_unbounded(), + timestamp_validity_window, + ); let message = public_transaction::Message::try_new(program_id, account_ids, nonces, instruction) .unwrap(); @@ -3089,13 +3095,15 @@ pub mod tests { PublicTransaction::new(message, witness_set) }; let result = state.transition_from_public_transaction(&tx, 1, timestamp); - let is_inside_validity_window = - match (timestamp_validity_window.start(), timestamp_validity_window.end()) { - (Some(s), Some(e)) => s <= timestamp && timestamp < e, - (Some(s), None) => s <= timestamp, - (None, Some(e)) => timestamp < e, - (None, None) => true, - }; + let is_inside_validity_window = match ( + timestamp_validity_window.start(), + timestamp_validity_window.end(), + ) { + (Some(s), Some(e)) => s <= timestamp && timestamp < e, + (Some(s), None) => s <= timestamp, + (None, Some(e)) => timestamp < e, + (None, None) => true, + }; if is_inside_validity_window { assert!(result.is_ok()); } else { @@ -3130,7 +3138,10 @@ pub mod tests { let shared_secret = SharedSecretKey::new(&esk, &account_keys.vpk()); let epk = EphemeralPublicKey::from_scalar(esk); - let instruction = (block_validity_window, TimestampValidityWindow::new_unbounded()); + let instruction = ( + block_validity_window, + TimestampValidityWindow::new_unbounded(), + ); let (output, proof) = circuit::execute_and_prove( vec![pre], Program::serialize_instruction(instruction).unwrap(), @@ -3196,8 +3207,10 @@ pub mod tests { let shared_secret = SharedSecretKey::new(&esk, &account_keys.vpk()); let epk = EphemeralPublicKey::from_scalar(esk); - let instruction = - (BlockValidityWindow::new_unbounded(), timestamp_validity_window); + let instruction = ( + BlockValidityWindow::new_unbounded(), + timestamp_validity_window, + ); let (output, proof) = circuit::execute_and_prove( vec![pre], Program::serialize_instruction(instruction).unwrap(), @@ -3221,13 +3234,15 @@ pub mod tests { PrivacyPreservingTransaction::new(message, witness_set) }; let result = state.transition_from_privacy_preserving_transaction(&tx, 1, timestamp); - let is_inside_validity_window = - match (timestamp_validity_window.start(), timestamp_validity_window.end()) { - (Some(s), Some(e)) => s <= timestamp && timestamp < e, - (Some(s), None) => s <= timestamp, - (None, Some(e)) => timestamp < e, - (None, None) => true, - }; + let is_inside_validity_window = match ( + timestamp_validity_window.start(), + timestamp_validity_window.end(), + ) { + (Some(s), Some(e)) => s <= timestamp && timestamp < e, + (Some(s), None) => s <= timestamp, + (None, Some(e)) => timestamp < e, + (None, None) => true, + }; if is_inside_validity_window { assert!(result.is_ok()); } else { diff --git a/sequencer/core/src/lib.rs b/sequencer/core/src/lib.rs index 5415913e..1c6b37e5 100644 --- a/sequencer/core/src/lib.rs +++ b/sequencer/core/src/lib.rs @@ -170,10 +170,9 @@ impl SequencerCore Result { match &tx { - NSSATransaction::Public(tx) => { - self.state - .transition_from_public_transaction(tx, block_id, timestamp) - } + NSSATransaction::Public(tx) => self + .state + .transition_from_public_transaction(tx, block_id, timestamp), NSSATransaction::PrivacyPreserving(tx) => self .state .transition_from_privacy_preserving_transaction(tx, block_id, timestamp), @@ -253,7 +252,8 @@ impl SequencerCore { valid_transactions.push(valid_tx); diff --git a/sequencer/service/protocol/src/lib.rs b/sequencer/service/protocol/src/lib.rs index be4fc6ef..ec0020ac 100644 --- a/sequencer/service/protocol/src/lib.rs +++ b/sequencer/service/protocol/src/lib.rs @@ -1,9 +1,5 @@ //! Reexports of types used by sequencer rpc specification. -pub use common::{ - HashType, - block::Block, - transaction::NSSATransaction, -}; +pub use common::{HashType, block::Block, transaction::NSSATransaction}; pub use nssa::{Account, AccountId, ProgramId}; pub use nssa_core::{BlockId, Commitment, MembershipProof, account::Nonce}; diff --git a/storage/src/indexer/mod.rs b/storage/src/indexer/mod.rs index 23e8aa89..6a9a67b6 100644 --- a/storage/src/indexer/mod.rs +++ b/storage/src/indexer/mod.rs @@ -188,7 +188,11 @@ impl RocksDBIO { "transaction pre check failed with err {err:?}" )) })? - .execute_check_on_state(&mut breakpoint, block.header.block_id, block.header.timestamp) + .execute_check_on_state( + &mut breakpoint, + block.header.block_id, + block.header.timestamp, + ) .map_err(|err| { DbError::db_interaction_error(format!( "transaction execution failed with err {err:?}"