diff --git a/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs b/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs index 39e1380f..a9750bce 100644 --- a/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs +++ b/examples/program_deployment/src/bin/run_hello_world_with_authorization.rs @@ -4,7 +4,6 @@ use nssa::{ program::Program, public_transaction::{Message, WitnessSet}, }; -use nssa_core::account::Nonce; use sequencer_service_rpc::RpcClient as _; use wallet::WalletCore; @@ -65,13 +64,7 @@ async fn main() { .await .expect("Node should be reachable to query account data"); let signing_keys = [signing_key]; - let message = Message::try_new( - program.id(), - vec![account_id], - nonces.iter().map(|x| Nonce(*x)).collect(), - greeting, - ) - .unwrap(); + let message = Message::try_new(program.id(), vec![account_id], nonces, greeting).unwrap(); // 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 let witness_set = WitnessSet::for_message(&message, &signing_keys); diff --git a/indexer/core/src/block_store.rs b/indexer/core/src/block_store.rs index 384217ff..bf3516e3 100644 --- a/indexer/core/src/block_store.rs +++ b/indexer/core/src/block_store.rs @@ -176,7 +176,7 @@ mod tests { ) .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(); assert_eq!(block.header.hash, genesis_block().header.hash); diff --git a/indexer/service/src/lib.rs b/indexer/service/src/lib.rs index 47f9289e..10f1cade 100644 --- a/indexer/service/src/lib.rs +++ b/indexer/service/src/lib.rs @@ -40,10 +40,10 @@ impl IndexerHandle { } #[must_use] - pub fn is_stopped(&self) -> bool { + pub fn is_healthy(&self) -> bool { self.server_handle .as_ref() - .is_none_or(ServerHandle::is_stopped) + .is_some_and(|handle| !handle.is_stopped()) } } diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index 2128a482..08e7cf9f 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -338,17 +338,17 @@ impl Drop for TestContext { let sequencer_handle = sequencer_handle .take() .expect("Sequencer handle should be present in TestContext drop"); - if sequencer_handle.is_stopped() { + if !sequencer_handle.is_healthy() { let Err(err) = sequencer_handle - .stopped() + .failed() .now_or_never() - .expect("Sequencer handle should be stopped"); + .expect("Sequencer handle should not be running"); error!( "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"); } diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index cb21748c..8232d9f4 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -66,13 +66,13 @@ impl NSSAUserData { ) -> Result { if !Self::valid_public_key_transaction_pairing_check(&default_accounts_keys) { 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) { 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" ); } diff --git a/sequencer/service/src/lib.rs b/sequencer/service/src/lib.rs index bc9a4ef5..5373b31f 100644 --- a/sequencer/service/src/lib.rs +++ b/sequencer/service/src/lib.rs @@ -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( clippy::integer_division_remainder_used, reason = "Generated by select! macro, can't be easily rewritten to avoid this lint" )] - pub async fn stopped(mut self) -> Result { + pub async fn failed(mut self) -> Result { let Self { addr: _, 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] - pub fn is_stopped(&self) -> bool { + pub fn is_healthy(&self) -> bool { let Self { addr: _, server_handle, @@ -98,10 +102,11 @@ impl SequencerHandle { listen_for_bedrock_blocks_loop_handle, } = 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() || 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] diff --git a/sequencer/service/src/main.rs b/sequencer/service/src/main.rs index 326ded70..e78ad502 100644 --- a/sequencer/service/src/main.rs +++ b/sequencer/service/src/main.rs @@ -33,8 +33,8 @@ async fn main() -> Result<()> { () = cancellation_token.cancelled() => { info!("Shutting down sequencer..."); } - Err(err) = sequencer_handle.stopped() => { - error!("Sequencer stopped unexpectedly: {err}"); + Err(err) = sequencer_handle.failed() => { + error!("Sequencer failed unexpectedly: {err}"); } } diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 86e27784..bf82a1bd 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -22,7 +22,9 @@ use nssa::{ 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; use sequencer_service_rpc::{RpcClient as _, SequencerClient, SequencerClientBuilder}; use tokio::io::AsyncWriteExt as _; @@ -253,7 +255,7 @@ impl WalletCore { } /// Get accounts nonces. - pub async fn get_accounts_nonces(&self, accs: Vec) -> Result> { + pub async fn get_accounts_nonces(&self, accs: Vec) -> Result> { Ok(self.sequencer_client.get_accounts_nonces(accs).await?) } diff --git a/wallet/src/program_facades/amm.rs b/wallet/src/program_facades/amm.rs index c430f29d..f1b94621 100644 --- a/wallet/src/program_facades/amm.rs +++ b/wallet/src/program_facades/amm.rs @@ -81,10 +81,7 @@ impl Amm<'_> { let message = nssa::public_transaction::Message::try_new( program.id(), account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), + nonces, instruction, ) .unwrap(); @@ -195,10 +192,7 @@ impl Amm<'_> { let message = nssa::public_transaction::Message::try_new( program.id(), account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), + nonces, instruction, ) .unwrap(); @@ -289,10 +283,7 @@ impl Amm<'_> { let message = nssa::public_transaction::Message::try_new( program.id(), account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), + nonces, instruction, ) .unwrap(); @@ -378,10 +369,7 @@ impl Amm<'_> { let message = nssa::public_transaction::Message::try_new( program.id(), account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), + nonces, instruction, ) .unwrap(); diff --git a/wallet/src/program_facades/native_token_transfer/public.rs b/wallet/src/program_facades/native_token_transfer/public.rs index a54a215f..f91171db 100644 --- a/wallet/src/program_facades/native_token_transfer/public.rs +++ b/wallet/src/program_facades/native_token_transfer/public.rs @@ -31,16 +31,8 @@ impl NativeTokenTransfer<'_> { let account_ids = vec![from, to]; let program_id = Program::authenticated_transfer_program().id(); - let message = Message::try_new( - program_id, - account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), - balance_to_move, - ) - .unwrap(); + let message = + Message::try_new(program_id, account_ids, nonces, balance_to_move).unwrap(); 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 account_ids = vec![from]; let program_id = Program::authenticated_transfer_program().id(); - let message = Message::try_new( - program_id, - account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), - instruction, - ) - .unwrap(); + let message = Message::try_new(program_id, account_ids, nonces, instruction).unwrap(); let signing_key = self.0.storage.user_data.get_pub_account_signing_key(from); diff --git a/wallet/src/program_facades/token.rs b/wallet/src/program_facades/token.rs index ca36e723..3aa6891f 100644 --- a/wallet/src/program_facades/token.rs +++ b/wallet/src/program_facades/token.rs @@ -146,10 +146,7 @@ impl Token<'_> { let message = nssa::public_transaction::Message::try_new( program_id, account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), + nonces, instruction, ) .unwrap(); @@ -354,10 +351,7 @@ impl Token<'_> { let message = nssa::public_transaction::Message::try_new( Program::token().id(), account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), + nonces, instruction, ) .expect("Instruction should serialize"); @@ -491,10 +485,7 @@ impl Token<'_> { let message = nssa::public_transaction::Message::try_new( Program::token().id(), account_ids, - nonces - .iter() - .map(|x| nssa_core::account::Nonce(*x)) - .collect(), + nonces, instruction, ) .unwrap();