@@ -11,6 +11,7 @@ use anyhow::{Context, Result};
1111use miden_node_proto:: clients:: RpcClient ;
1212use miden_node_proto:: generated:: rpc:: BlockHeaderByNumberRequest ;
1313use miden_node_proto:: generated:: transaction:: ProvenTransaction ;
14+ use miden_node_utils:: spawn:: spawn_blocking_in_current_span;
1415use miden_protocol:: account:: auth:: AuthSecretKey ;
1516use miden_protocol:: account:: { Account , AccountCode , AccountHeader , AccountId } ;
1617use miden_protocol:: asset:: AssetVault ;
@@ -92,7 +93,6 @@ struct TxBuilder {
9293 counter_account : Account ,
9394 secret_key : SecretKey ,
9495 increment_script : NoteScript ,
95- data_store : MonitorDataStore ,
9696 block_header : BlockHeader ,
9797 rng : ChaCha20Rng ,
9898}
@@ -192,7 +192,6 @@ impl IncrementService {
192192 )
193193 . expect ( "nonce-only update of an already-valid account cannot fail" ) ;
194194 self . tx . wallet_account = updated_wallet;
195- self . tx . data_store . update_account ( self . tx . wallet_account . clone ( ) ) ;
196195
197196 self . details . success_count += 1 ;
198197 self . details . last_tx_id = Some ( tx_id) ;
@@ -223,7 +222,6 @@ impl IncrementService {
223222
224223 info ! ( account. id = %self . tx. wallet_account. id( ) , "wallet account re-synced from RPC" ) ;
225224 self . tx . wallet_account = fresh_account;
226- self . tx . data_store . update_account ( self . tx . wallet_account . clone ( ) ) ;
227225 Ok ( ( ) )
228226 }
229227
@@ -275,10 +273,6 @@ impl IncrementService {
275273 err
276274 ) ]
277275 async fn submit_increment ( & mut self ) -> Result < ( String , AccountHeader , BlockNumber ) > {
278- let authenticator = BasicAuthenticator :: new ( & [ AuthSecretKey :: Falcon512Poseidon2 (
279- self . tx . secret_key . clone ( ) ,
280- ) ] ) ;
281-
282276 let account_interface = AccountInterface :: from_account ( & self . tx . wallet_account ) ;
283277
284278 let ( network_note, note_recipient) = create_network_note (
@@ -289,26 +283,44 @@ impl IncrementService {
289283 ) ?;
290284 let script = account_interface. build_send_notes_script ( & [ network_note. into ( ) ] , None ) ?;
291285
292- let executor =
293- TransactionExecutor :: new ( & self . tx . data_store ) . with_authenticator ( & authenticator) ;
294-
295286 let mut tx_args = TransactionArgs :: default ( ) . with_tx_script ( script) ;
296287 tx_args. add_output_note_recipient ( Box :: new ( note_recipient) ) ;
297288
298- let executed_tx = Box :: pin ( executor. execute_transaction (
299- self . tx . wallet_account . id ( ) ,
300- self . tx . block_header . block_num ( ) ,
301- InputNotes :: default ( ) ,
302- tx_args,
303- ) )
289+ let wallet_account = self . tx . wallet_account . clone ( ) ;
290+ let counter_account = self . tx . counter_account . clone ( ) ;
291+ let block_header = self . tx . block_header . clone ( ) ;
292+ let secret_key = self . tx . secret_key . clone ( ) ;
293+ let handle = tokio:: runtime:: Handle :: current ( ) ;
294+ let ( proven_tx, tx_inputs, final_account) = spawn_blocking_in_current_span ( move || {
295+ let account_id = wallet_account. id ( ) ;
296+ let block_num = block_header. block_num ( ) ;
297+ let mut data_store = MonitorDataStore :: new ( block_header, PartialBlockchain :: default ( ) ) ;
298+ data_store. add_account ( wallet_account) ;
299+ data_store. add_account ( counter_account) ;
300+
301+ let authenticator =
302+ BasicAuthenticator :: new ( & [ AuthSecretKey :: Falcon512Poseidon2 ( secret_key) ] ) ;
303+ let executor = TransactionExecutor :: new ( & data_store) . with_authenticator ( & authenticator) ;
304+
305+ let executed_tx = handle
306+ . block_on ( executor. execute_transaction (
307+ account_id,
308+ block_num,
309+ InputNotes :: default ( ) ,
310+ tx_args,
311+ ) )
312+ . context ( "Failed to execute transaction" ) ?;
313+
314+ let tx_inputs = executed_tx. tx_inputs ( ) . to_bytes ( ) ;
315+ let final_account = executed_tx. final_account ( ) . clone ( ) ;
316+ let proven_tx = handle
317+ . block_on ( LocalTransactionProver :: default ( ) . prove ( executed_tx) )
318+ . context ( "Failed to prove transaction" ) ?;
319+
320+ Ok :: < _ , anyhow:: Error > ( ( proven_tx, tx_inputs, final_account) )
321+ } )
304322 . await
305- . context ( "Failed to execute transaction" ) ?;
306-
307- let tx_inputs = executed_tx. tx_inputs ( ) . to_bytes ( ) ;
308- let final_account = executed_tx. final_account ( ) . clone ( ) ;
309-
310- let prover = LocalTransactionProver :: default ( ) ;
311- let proven_tx = prover. prove ( executed_tx) . await . context ( "Failed to prove transaction" ) ?;
323+ . context ( "counter increment task failed" ) ??;
312324
313325 let request = ProvenTransaction {
314326 transaction : proven_tx. to_bytes ( ) ,
@@ -621,16 +633,11 @@ async fn setup_increment_task(
621633
622634 let increment_script = create_increment_script ( ) ?;
623635
624- let mut data_store = MonitorDataStore :: new ( block_header. clone ( ) , PartialBlockchain :: default ( ) ) ;
625- data_store. add_account ( wallet_account. clone ( ) ) ;
626- data_store. add_account ( counter_account. clone ( ) ) ;
627-
628636 let tx = TxBuilder {
629637 wallet_account,
630638 counter_account,
631639 secret_key,
632640 increment_script,
633- data_store,
634641 block_header,
635642 rng : ChaCha20Rng :: from_os_rng ( ) ,
636643 } ;
0 commit comments