fmt and clippy

This commit is contained in:
Sergio Chouhy 2026-04-02 17:42:33 -03:00
parent 29d66d2c2d
commit 6a467da3b1
8 changed files with 65 additions and 44 deletions

View File

@ -1,11 +1,10 @@
use borsh::{BorshDeserialize, BorshSerialize};
use nssa_core::BlockId;
pub use nssa_core::Timestamp;
use serde::{Deserialize, Serialize};
use sha2::{Digest as _, Sha256, digest::FixedOutput as _};
use crate::{HashType, transaction::NSSATransaction};
pub use nssa_core::Timestamp;
pub type MantleMsgId = [u8; 32];
pub type BlockHash = HashType;

View File

@ -3,7 +3,6 @@
reason = "We prefer to group methods by functionality rather than by type for encoding"
)]
pub use circuit_io::{PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput};
pub use commitment::{
Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, DUMMY_COMMITMENT_HASH, MembershipProof,

View File

@ -1,7 +1,7 @@
use std::collections::HashSet;
use borsh::{BorshDeserialize, BorshSerialize};
use nssa_core::account::{Account, AccountId};
use nssa_core::account::AccountId;
use sha2::{Digest as _, digest::FixedOutput as _};
use super::{message::Message, witness_set::WitnessSet};

View File

@ -9,7 +9,8 @@ use serde::Serialize;
use crate::{
error::NssaError,
program_methods::{
AMM_ELF, ASSOCIATED_TOKEN_ACCOUNT_ELF, AUTHENTICATED_TRANSFER_ELF, CLOCK_ELF, PINATA_ELF, TOKEN_ELF,
AMM_ELF, ASSOCIATED_TOKEN_ACCOUNT_ELF, AUTHENTICATED_TRANSFER_ELF, CLOCK_ELF, PINATA_ELF,
TOKEN_ELF,
},
};

View File

@ -1,6 +1,11 @@
use std::collections::{BTreeSet, HashMap, HashSet};
use borsh::{BorshDeserialize, BorshSerialize};
use clock_core::ClockAccountData;
pub use clock_core::{
CLOCK_01_PROGRAM_ACCOUNT_ID, CLOCK_10_PROGRAM_ACCOUNT_ID, CLOCK_50_PROGRAM_ACCOUNT_ID,
CLOCK_PROGRAM_ACCOUNT_IDS,
};
use nssa_core::{
BlockId, Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, MembershipProof, Nullifier,
Timestamp,
@ -8,18 +13,11 @@ use nssa_core::{
program::ProgramId,
};
pub use clock_core::{
CLOCK_01_PROGRAM_ACCOUNT_ID, CLOCK_10_PROGRAM_ACCOUNT_ID, CLOCK_50_PROGRAM_ACCOUNT_ID,
CLOCK_PROGRAM_ACCOUNT_IDS,
};
use clock_core::ClockAccountData;
use crate::{
error::NssaError, merkle_tree::MerkleTree,
privacy_preserving_transaction::PrivacyPreservingTransaction, program::Program,
program_deployment_transaction::ProgramDeploymentTransaction,
public_transaction::PublicTransaction,
validated_state_diff::ValidatedStateDiff,
public_transaction::PublicTransaction, validated_state_diff::ValidatedStateDiff,
};
pub const MAX_NUMBER_CHAINED_CALLS: usize = 10;
@ -164,7 +162,11 @@ impl V03State {
}
fn insert_clock_accounts(&mut self, genesis_timestamp: nssa_core::Timestamp) {
let data = ClockAccountData { block_id: 0, timestamp: genesis_timestamp }.to_bytes();
let data = ClockAccountData {
block_id: 0,
timestamp: genesis_timestamp,
}
.to_bytes();
let clock_program_id = Program::clock().id();
for account_id in CLOCK_PROGRAM_ACCOUNT_IDS {
self.public_state.insert(
@ -186,7 +188,8 @@ impl V03State {
}
pub fn apply_state_diff(&mut self, diff: ValidatedStateDiff) {
let (signer_account_ids, public_diff, new_commitments, new_nullifiers, program) = diff.into_parts();
let (signer_account_ids, public_diff, new_commitments, new_nullifiers, program) =
diff.into_parts();
#[expect(
clippy::iter_over_hash_type,
reason = "Iteration order doesn't matter here"
@ -195,11 +198,13 @@ impl V03State {
*self.get_account_by_id_mut(account_id) = account;
}
for account_id in signer_account_ids {
self.get_account_by_id_mut(account_id).nonce.public_account_nonce_increment();
self.get_account_by_id_mut(account_id)
.nonce
.public_account_nonce_increment();
}
self.private_state.0.extend(&new_commitments);
self.private_state.1.extend(&new_nullifiers);
if let Some(program) =program {
if let Some(program) = program {
self.insert_program(program);
}
}

View File

@ -7,16 +7,16 @@ use log::debug;
use nssa_core::{
BlockId, Commitment, Nullifier, PrivacyPreservingCircuitOutput, Timestamp,
account::{Account, AccountId, AccountWithMetadata},
program::{ChainedCall, Claim, DEFAULT_PROGRAM_ID, compute_authorized_pdas, validate_execution},
program::{
ChainedCall, Claim, DEFAULT_PROGRAM_ID, compute_authorized_pdas, validate_execution,
},
};
use crate::{
V03State, ensure,
error::NssaError,
privacy_preserving_transaction::{
PrivacyPreservingTransaction,
circuit::Proof,
message::Message,
PrivacyPreservingTransaction, circuit::Proof, message::Message,
},
program::Program,
program_deployment_transaction::ProgramDeploymentTransaction,
@ -349,7 +349,7 @@ impl ValidatedStateDiff {
let new_nullifiers = message
.new_nullifiers
.iter()
.cloned()
.copied()
.map(|(nullifier, _)| nullifier)
.collect();
@ -389,15 +389,23 @@ impl ValidatedStateDiff {
self.public_diff.clone()
}
pub(crate) fn into_parts(self) -> (
Vec<AccountId>,
HashMap<AccountId, Account>,
Vec<Commitment>,
Vec<Nullifier>,
Option<Program>,
) {
(self.signer_account_ids, self.public_diff, self.new_commitments, self.new_nullifiers, self.program)
}
pub(crate) fn into_parts(
self,
) -> (
Vec<AccountId>,
HashMap<AccountId, Account>,
Vec<Commitment>,
Vec<Nullifier>,
Option<Program>,
) {
(
self.signer_account_ids,
self.public_diff,
self.new_commitments,
self.new_nullifiers,
self.program,
)
}
}
fn check_privacy_preserving_circuit_proof_is_valid(

View File

@ -57,7 +57,11 @@ fn main() {
.checked_add(1)
.expect("Next block id should be within u64 boundaries");
let updated_data = ClockAccountData { block_id: current_block_id, timestamp }.to_bytes();
let updated_data = ClockAccountData {
block_id: current_block_id,
timestamp,
}
.to_bytes();
let (pre_01, post_01) = update_if_multiple(pre_01, 1, current_block_id, updated_data);
let (pre_10, post_10) = update_if_multiple(pre_10, 10, current_block_id, updated_data);

View File

@ -259,11 +259,15 @@ impl<BC: BlockSettlementClientTrait, IC: IndexerClientTrait> SequencerCore<BC, I
while let Some(tx) = self.mempool.pop() {
let tx_hash = tx.hash();
let validated_diff = match self.validate_transaction_and_produce_state_diff(&tx, new_block_height, new_block_timestamp) {
let validated_diff = match self.validate_transaction_and_produce_state_diff(
&tx,
new_block_height,
new_block_timestamp,
) {
Ok(diff) => {
let touches_system = clock_accounts_pre
.iter()
.any(|(id, pre)| diff.public_diff().get(id).is_some_and(|post| post != pre));
let touches_system = clock_accounts_pre.iter().any(|(id, pre)| {
diff.public_diff().get(id).is_some_and(|post| post != pre)
});
if touches_system {
warn!(
"Dropping transaction from mempool: user transactions may not modify the system clock account"
@ -321,7 +325,7 @@ impl<BC: BlockSettlementClientTrait, IC: IndexerClientTrait> SequencerCore<BC, I
new_block_height,
new_block_timestamp,
)
.context("Clock transaction failed aborting block production")?;
.context("Clock transaction failed \u{2014} aborting block production")?;
valid_transactions.push(clock_nssa_tx);
let hashable_data = HashableBlockData {
@ -450,8 +454,8 @@ mod tests {
use common::{test_utils::sequencer_sign_key_for_testing, transaction::NSSATransaction};
use logos_blockchain_core::mantle::ops::channel::ChannelId;
use mempool::MemPoolHandle;
use nssa::{execute_and_prove, program::Program};
use nssa_core::account::AccountWithMetadata;
use testnet_initial_state::{initial_accounts, initial_pub_accounts_private_keys};
use crate::{
@ -1035,11 +1039,12 @@ mod tests {
let (mut sequencer, mempool_handle) = common_setup().await;
// Deploy the clock_chain_caller test program.
let deploy_tx = NSSATransaction::ProgramDeployment(nssa::ProgramDeploymentTransaction::new(
nssa::program_deployment_transaction::Message::new(
test_program_methods::CLOCK_CHAIN_CALLER_ELF.to_vec(),
),
));
let deploy_tx =
NSSATransaction::ProgramDeployment(nssa::ProgramDeploymentTransaction::new(
nssa::program_deployment_transaction::Message::new(
test_program_methods::CLOCK_CHAIN_CALLER_ELF.to_vec(),
),
));
mempool_handle.push(deploy_tx).await.unwrap();
sequencer
.produce_new_block_with_mempool_transactions()