From 0efd5d4e996abdd5b251fce6583e913a9a2c27c8 Mon Sep 17 00:00:00 2001 From: Ollie202 Date: Tue, 26 May 2026 05:56:22 +0100 Subject: [PATCH 1/2] fix(network-monitor): move local proving off async runtime --- bin/network-monitor/src/counter.rs | 49 ++++++++++++++++----------- bin/network-monitor/src/deploy/mod.rs | 10 ++++++ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/bin/network-monitor/src/counter.rs b/bin/network-monitor/src/counter.rs index 80e42ec15..ea28c1254 100644 --- a/bin/network-monitor/src/counter.rs +++ b/bin/network-monitor/src/counter.rs @@ -11,6 +11,7 @@ use anyhow::{Context, Result}; use miden_node_proto::clients::RpcClient; use miden_node_proto::generated::rpc::BlockHeaderByNumberRequest; use miden_node_proto::generated::transaction::ProvenTransaction; +use miden_node_utils::spawn::spawn_blocking_in_current_span; use miden_protocol::account::auth::AuthSecretKey; use miden_protocol::account::{Account, AccountCode, AccountHeader, AccountId}; use miden_protocol::asset::AssetVault; @@ -271,10 +272,6 @@ impl IncrementService { err )] async fn submit_increment(&mut self) -> Result<(String, AccountHeader, BlockNumber)> { - let authenticator = BasicAuthenticator::new(&[AuthSecretKey::Falcon512Poseidon2( - self.tx.secret_key.clone(), - )]); - let account_interface = AccountInterface::from_account(&self.tx.wallet_account); let (network_note, note_recipient) = create_network_note( @@ -285,26 +282,38 @@ impl IncrementService { )?; let script = account_interface.build_send_notes_script(&[network_note.into()], None)?; - let executor = - TransactionExecutor::new(&self.tx.data_store).with_authenticator(&authenticator); - let mut tx_args = TransactionArgs::default().with_tx_script(script); tx_args.add_output_note_recipient(Box::new(note_recipient)); - let executed_tx = Box::pin(executor.execute_transaction( - self.tx.wallet_account.id(), - self.tx.block_header.block_num(), - InputNotes::default(), - tx_args, - )) + let data_store = self.tx.data_store.clone(); + let secret_key = self.tx.secret_key.clone(); + let account_id = self.tx.wallet_account.id(); + let block_num = self.tx.block_header.block_num(); + let handle = tokio::runtime::Handle::current(); + let (proven_tx, tx_inputs, final_account) = spawn_blocking_in_current_span(move || { + let authenticator = + BasicAuthenticator::new(&[AuthSecretKey::Falcon512Poseidon2(secret_key)]); + let executor = TransactionExecutor::new(&data_store).with_authenticator(&authenticator); + + let executed_tx = handle + .block_on(executor.execute_transaction( + account_id, + block_num, + InputNotes::default(), + tx_args, + )) + .context("Failed to execute transaction")?; + + let tx_inputs = executed_tx.tx_inputs().to_bytes(); + let final_account = executed_tx.final_account().clone(); + let proven_tx = handle + .block_on(LocalTransactionProver::default().prove(executed_tx)) + .context("Failed to prove transaction")?; + + Ok::<_, anyhow::Error>((proven_tx, tx_inputs, final_account)) + }) .await - .context("Failed to execute transaction")?; - - let tx_inputs = executed_tx.tx_inputs().to_bytes(); - let final_account = executed_tx.final_account().clone(); - - let prover = LocalTransactionProver::default(); - let proven_tx = prover.prove(executed_tx).await.context("Failed to prove transaction")?; + .context("counter increment task failed")??; let request = ProvenTransaction { transaction: proven_tx.to_bytes(), diff --git a/bin/network-monitor/src/deploy/mod.rs b/bin/network-monitor/src/deploy/mod.rs index e4c8c60a8..eb95cb73e 100644 --- a/bin/network-monitor/src/deploy/mod.rs +++ b/bin/network-monitor/src/deploy/mod.rs @@ -186,6 +186,16 @@ pub struct MonitorDataStore { mast_store: TransactionMastStore, } +impl Clone for MonitorDataStore { + fn clone(&self) -> Self { + let mut cloned = Self::new(self.block_header.clone(), self.partial_block_chain.clone()); + for account in self.accounts.values() { + cloned.add_account(account.clone()); + } + cloned + } +} + impl MonitorDataStore { pub fn new(block_header: BlockHeader, partial_block_chain: PartialBlockchain) -> Self { Self { From 75e131369c6fab7c26b84e7a27fe7d9495d6174f Mon Sep 17 00:00:00 2001 From: Ollie202 Date: Thu, 11 Jun 2026 08:18:31 +0100 Subject: [PATCH 2/2] refactor(network-monitor): build counter store in task --- bin/network-monitor/src/counter.rs | 20 +++++++++----------- bin/network-monitor/src/deploy/mod.rs | 15 --------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/bin/network-monitor/src/counter.rs b/bin/network-monitor/src/counter.rs index 9cfd4b86e..44919f80e 100644 --- a/bin/network-monitor/src/counter.rs +++ b/bin/network-monitor/src/counter.rs @@ -93,7 +93,6 @@ struct TxBuilder { counter_account: Account, secret_key: SecretKey, increment_script: NoteScript, - data_store: MonitorDataStore, block_header: BlockHeader, rng: ChaCha20Rng, } @@ -189,7 +188,6 @@ impl IncrementService { ) .expect("nonce-only update of an already-valid account cannot fail"); self.tx.wallet_account = updated_wallet; - self.tx.data_store.update_account(self.tx.wallet_account.clone()); self.details.success_count += 1; self.details.last_tx_id = Some(tx_id); @@ -220,7 +218,6 @@ impl IncrementService { info!(account.id = %self.tx.wallet_account.id(), "wallet account re-synced from RPC"); self.tx.wallet_account = fresh_account; - self.tx.data_store.update_account(self.tx.wallet_account.clone()); Ok(()) } @@ -285,12 +282,18 @@ impl IncrementService { let mut tx_args = TransactionArgs::default().with_tx_script(script); tx_args.add_output_note_recipient(Box::new(note_recipient)); - let data_store = self.tx.data_store.clone(); + let wallet_account = self.tx.wallet_account.clone(); + let counter_account = self.tx.counter_account.clone(); + let block_header = self.tx.block_header.clone(); let secret_key = self.tx.secret_key.clone(); - let account_id = self.tx.wallet_account.id(); - let block_num = self.tx.block_header.block_num(); let handle = tokio::runtime::Handle::current(); let (proven_tx, tx_inputs, final_account) = spawn_blocking_in_current_span(move || { + let account_id = wallet_account.id(); + let block_num = block_header.block_num(); + let mut data_store = MonitorDataStore::new(block_header, PartialBlockchain::default()); + data_store.add_account(wallet_account); + data_store.add_account(counter_account); + let authenticator = BasicAuthenticator::new(&[AuthSecretKey::Falcon512Poseidon2(secret_key)]); let executor = TransactionExecutor::new(&data_store).with_authenticator(&authenticator); @@ -622,16 +625,11 @@ async fn setup_increment_task( let increment_script = create_increment_script()?; - let mut data_store = MonitorDataStore::new(block_header.clone(), PartialBlockchain::default()); - data_store.add_account(wallet_account.clone()); - data_store.add_account(counter_account.clone()); - let tx = TxBuilder { wallet_account, counter_account, secret_key, increment_script, - data_store, block_header, rng: ChaCha20Rng::from_os_rng(), }; diff --git a/bin/network-monitor/src/deploy/mod.rs b/bin/network-monitor/src/deploy/mod.rs index 673f49d9e..818d04eb0 100644 --- a/bin/network-monitor/src/deploy/mod.rs +++ b/bin/network-monitor/src/deploy/mod.rs @@ -260,16 +260,6 @@ pub struct MonitorDataStore { mast_store: TransactionMastStore, } -impl Clone for MonitorDataStore { - fn clone(&self) -> Self { - let mut cloned = Self::new(self.block_header.clone(), self.partial_block_chain.clone()); - for account in self.accounts.values() { - cloned.add_account(account.clone()); - } - cloned - } -} - impl MonitorDataStore { pub fn new(block_header: BlockHeader, partial_block_chain: PartialBlockchain) -> Self { Self { @@ -286,11 +276,6 @@ impl MonitorDataStore { self.accounts.insert(account.id(), account); } - /// Update an account after a transaction (loads latest code too). - pub fn update_account(&mut self, account: Account) { - self.add_account(account); - } - /// Returns a reference to the account or a standardized "unknown account" error. fn get_account(&self, account_id: AccountId) -> Result<&Account, DataStoreError> { self.accounts.get(&account_id).ok_or_else(|| DataStoreError::Other {