fix: fixes after rebase & address comments

This commit is contained in:
Daniil Polyakov 2026-03-18 21:58:36 +03:00
parent 325960d696
commit 7b20a83379
11 changed files with 36 additions and 74 deletions

View File

@ -4,7 +4,6 @@ use nssa::{
program::Program, program::Program,
public_transaction::{Message, WitnessSet}, public_transaction::{Message, WitnessSet},
}; };
use nssa_core::account::Nonce;
use sequencer_service_rpc::RpcClient as _; use sequencer_service_rpc::RpcClient as _;
use wallet::WalletCore; use wallet::WalletCore;
@ -65,13 +64,7 @@ async fn main() {
.await .await
.expect("Node should be reachable to query account data"); .expect("Node should be reachable to query account data");
let signing_keys = [signing_key]; let signing_keys = [signing_key];
let message = Message::try_new( let message = Message::try_new(program.id(), vec![account_id], nonces, greeting).unwrap();
program.id(),
vec![account_id],
nonces.iter().map(|x| Nonce(*x)).collect(),
greeting,
)
.unwrap();
// Pass the signing key to sign the message. This will be used by the node // Pass the signing key to sign the message. This will be used by the node
// to flag the pre_state as `is_authorized` when executing the program // to flag the pre_state as `is_authorized` when executing the program
let witness_set = WitnessSet::for_message(&message, &signing_keys); let witness_set = WitnessSet::for_message(&message, &signing_keys);

View File

@ -176,7 +176,7 @@ mod tests {
) )
.unwrap(); .unwrap();
let block = storage.get_block_at_id(1).unwrap(); let block = storage.get_block_at_id(1).unwrap().unwrap();
let final_id = storage.get_last_block_id().unwrap(); let final_id = storage.get_last_block_id().unwrap();
assert_eq!(block.header.hash, genesis_block().header.hash); assert_eq!(block.header.hash, genesis_block().header.hash);

View File

@ -40,10 +40,10 @@ impl IndexerHandle {
} }
#[must_use] #[must_use]
pub fn is_stopped(&self) -> bool { pub fn is_healthy(&self) -> bool {
self.server_handle self.server_handle
.as_ref() .as_ref()
.is_none_or(ServerHandle::is_stopped) .is_some_and(|handle| !handle.is_stopped())
} }
} }

View File

@ -338,17 +338,17 @@ impl Drop for TestContext {
let sequencer_handle = sequencer_handle let sequencer_handle = sequencer_handle
.take() .take()
.expect("Sequencer handle should be present in TestContext drop"); .expect("Sequencer handle should be present in TestContext drop");
if sequencer_handle.is_stopped() { if !sequencer_handle.is_healthy() {
let Err(err) = sequencer_handle let Err(err) = sequencer_handle
.stopped() .failed()
.now_or_never() .now_or_never()
.expect("Sequencer handle should be stopped"); .expect("Sequencer handle should not be running");
error!( error!(
"Sequencer handle has unexpectedly stopped before TestContext drop with error: {err:#}" "Sequencer handle has unexpectedly stopped before TestContext drop with error: {err:#}"
); );
} }
if indexer_handle.is_stopped() { if !indexer_handle.is_healthy() {
error!("Indexer handle has unexpectedly stopped before TestContext drop"); error!("Indexer handle has unexpectedly stopped before TestContext drop");
} }

View File

@ -66,13 +66,13 @@ impl NSSAUserData {
) -> Result<Self> { ) -> Result<Self> {
if !Self::valid_public_key_transaction_pairing_check(&default_accounts_keys) { if !Self::valid_public_key_transaction_pairing_check(&default_accounts_keys) {
anyhow::bail!( anyhow::bail!(
"Key transaction pairing check not satisfied, there are public account_ids, which is not derived from keys" "Key transaction pairing check not satisfied, there are public account_ids, which are not derived from keys"
); );
} }
if !Self::valid_private_key_transaction_pairing_check(&default_accounts_key_chains) { if !Self::valid_private_key_transaction_pairing_check(&default_accounts_key_chains) {
anyhow::bail!( anyhow::bail!(
"Key transaction pairing check not satisfied, there are private account_ids, which is not derived from keys" "Key transaction pairing check not satisfied, there are private account_ids, which are not derived from keys"
); );
} }

View File

@ -50,12 +50,12 @@ impl SequencerHandle {
} }
} }
/// Wait for all Sequencer tasks to stop. /// Wait for any of the sequencer tasks to fail and return the error.
#[expect( #[expect(
clippy::integer_division_remainder_used, clippy::integer_division_remainder_used,
reason = "Generated by select! macro, can't be easily rewritten to avoid this lint" reason = "Generated by select! macro, can't be easily rewritten to avoid this lint"
)] )]
pub async fn stopped(mut self) -> Result<Never> { pub async fn failed(mut self) -> Result<Never> {
let Self { let Self {
addr: _, addr: _,
server_handle, server_handle,
@ -88,8 +88,12 @@ impl SequencerHandle {
} }
} }
/// Check if all Sequencer tasks are still running.
///
/// Return `false` if any of the tasks has failed and `true` otherwise.
/// Error of the failed task can be retrieved by awaiting on [`Self::failed()`].
#[must_use] #[must_use]
pub fn is_stopped(&self) -> bool { pub fn is_healthy(&self) -> bool {
let Self { let Self {
addr: _, addr: _,
server_handle, server_handle,
@ -98,10 +102,11 @@ impl SequencerHandle {
listen_for_bedrock_blocks_loop_handle, listen_for_bedrock_blocks_loop_handle,
} = self; } = self;
server_handle.as_ref().is_none_or(ServerHandle::is_stopped) let stopped = server_handle.as_ref().is_none_or(ServerHandle::is_stopped)
|| main_loop_handle.is_finished() || main_loop_handle.is_finished()
|| retry_pending_blocks_loop_handle.is_finished() || retry_pending_blocks_loop_handle.is_finished()
|| listen_for_bedrock_blocks_loop_handle.is_finished() || listen_for_bedrock_blocks_loop_handle.is_finished();
!stopped
} }
#[must_use] #[must_use]

View File

@ -33,8 +33,8 @@ async fn main() -> Result<()> {
() = cancellation_token.cancelled() => { () = cancellation_token.cancelled() => {
info!("Shutting down sequencer..."); info!("Shutting down sequencer...");
} }
Err(err) = sequencer_handle.stopped() => { Err(err) = sequencer_handle.failed() => {
error!("Sequencer stopped unexpectedly: {err}"); error!("Sequencer failed unexpectedly: {err}");
} }
} }

View File

@ -22,7 +22,9 @@ use nssa::{
circuit::ProgramWithDependencies, message::EncryptedAccountData, circuit::ProgramWithDependencies, message::EncryptedAccountData,
}, },
}; };
use nssa_core::{Commitment, MembershipProof, SharedSecretKey, program::InstructionData}; use nssa_core::{
Commitment, MembershipProof, SharedSecretKey, account::Nonce, program::InstructionData,
};
pub use privacy_preserving_tx::PrivacyPreservingAccount; pub use privacy_preserving_tx::PrivacyPreservingAccount;
use sequencer_service_rpc::{RpcClient as _, SequencerClient, SequencerClientBuilder}; use sequencer_service_rpc::{RpcClient as _, SequencerClient, SequencerClientBuilder};
use tokio::io::AsyncWriteExt as _; use tokio::io::AsyncWriteExt as _;
@ -253,7 +255,7 @@ impl WalletCore {
} }
/// Get accounts nonces. /// Get accounts nonces.
pub async fn get_accounts_nonces(&self, accs: Vec<AccountId>) -> Result<Vec<u128>> { pub async fn get_accounts_nonces(&self, accs: Vec<AccountId>) -> Result<Vec<Nonce>> {
Ok(self.sequencer_client.get_accounts_nonces(accs).await?) Ok(self.sequencer_client.get_accounts_nonces(accs).await?)
} }

View File

@ -81,10 +81,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
program.id(), program.id(),
account_ids, account_ids,
nonces nonces,
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction, instruction,
) )
.unwrap(); .unwrap();
@ -195,10 +192,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
program.id(), program.id(),
account_ids, account_ids,
nonces nonces,
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction, instruction,
) )
.unwrap(); .unwrap();
@ -289,10 +283,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
program.id(), program.id(),
account_ids, account_ids,
nonces nonces,
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction, instruction,
) )
.unwrap(); .unwrap();
@ -378,10 +369,7 @@ impl Amm<'_> {
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
program.id(), program.id(),
account_ids, account_ids,
nonces nonces,
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction, instruction,
) )
.unwrap(); .unwrap();

View File

@ -31,16 +31,8 @@ impl NativeTokenTransfer<'_> {
let account_ids = vec![from, to]; let account_ids = vec![from, to];
let program_id = Program::authenticated_transfer_program().id(); let program_id = Program::authenticated_transfer_program().id();
let message = Message::try_new( let message =
program_id, Message::try_new(program_id, account_ids, nonces, balance_to_move).unwrap();
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
balance_to_move,
)
.unwrap();
let signing_key = self.0.storage.user_data.get_pub_account_signing_key(from); let signing_key = self.0.storage.user_data.get_pub_account_signing_key(from);
@ -75,16 +67,7 @@ impl NativeTokenTransfer<'_> {
let instruction: u128 = 0; let instruction: u128 = 0;
let account_ids = vec![from]; let account_ids = vec![from];
let program_id = Program::authenticated_transfer_program().id(); let program_id = Program::authenticated_transfer_program().id();
let message = Message::try_new( let message = Message::try_new(program_id, account_ids, nonces, instruction).unwrap();
program_id,
account_ids,
nonces
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction,
)
.unwrap();
let signing_key = self.0.storage.user_data.get_pub_account_signing_key(from); let signing_key = self.0.storage.user_data.get_pub_account_signing_key(from);

View File

@ -146,10 +146,7 @@ impl Token<'_> {
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
program_id, program_id,
account_ids, account_ids,
nonces nonces,
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction, instruction,
) )
.unwrap(); .unwrap();
@ -354,10 +351,7 @@ impl Token<'_> {
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
Program::token().id(), Program::token().id(),
account_ids, account_ids,
nonces nonces,
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction, instruction,
) )
.expect("Instruction should serialize"); .expect("Instruction should serialize");
@ -491,10 +485,7 @@ impl Token<'_> {
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
Program::token().id(), Program::token().id(),
account_ids, account_ids,
nonces nonces,
.iter()
.map(|x| nssa_core::account::Nonce(*x))
.collect(),
instruction, instruction,
) )
.unwrap(); .unwrap();