Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions bin/network-monitor/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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(),
Expand Down
10 changes: 10 additions & 0 deletions bin/network-monitor/src/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading