Skip to content

Commit

Permalink
feat: add test for transaction benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Apr 8, 2024
1 parent acfb528 commit cd6f639
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
12 changes: 12 additions & 0 deletions miden-lib/asm/kernels/transaction/main.masm
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ proc.main.1
# Prologue
# ---------------------------------------------------------------------------------------------

push.0 drop
emit.131077

# execute the transaction prologue
exec.prologue::prepare_transaction
# => []

# Note Processing
# ---------------------------------------------------------------------------------------------

push.0 drop
emit.131077

# get the total number of consumed notes
exec.memory::get_total_num_consumed_notes
# => [num_consumed_notes]
Expand Down Expand Up @@ -112,6 +118,9 @@ proc.main.1
# Transaction Script Processing
# ---------------------------------------------------------------------------------------------

push.0 drop
emit.131077

# execute the transaction script
exec.memory::get_tx_script_root
# => [TX_SCRIPT_ROOT]
Expand All @@ -136,6 +145,9 @@ proc.main.1
# Epilogue
# ---------------------------------------------------------------------------------------------

push.0 drop
emit.131077

# execute the transaction epilogue
exec.epilogue::finalize_transaction
# => [TX_SCRIPT_ROOT, CREATED_NOTES_COMMITMENT, FINAL_ACCOUNT_HASH]
Expand Down
2 changes: 2 additions & 0 deletions miden-lib/src/transaction/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum TransactionEvent {
AccountStorageSetItem = 0x2_0002, // 131074
AccountIncrementNonce = 0x2_0003, // 131075
AccountPushProcedureIndex = 0x2_0004, // 131076
AccountBenchData = 0x2_0005, // 131077
}

impl TransactionEvent {
Expand Down Expand Up @@ -47,6 +48,7 @@ impl TryFrom<u32> for TransactionEvent {
0x2_0002 => Ok(TransactionEvent::AccountStorageSetItem),
0x2_0003 => Ok(TransactionEvent::AccountIncrementNonce),
0x2_0004 => Ok(TransactionEvent::AccountPushProcedureIndex),
0x2_0005 => Ok(TransactionEvent::AccountBenchData),
_ => Err(TransactionEventParsingError::InvalidTransactionEvent(value)),
}
}
Expand Down
10 changes: 10 additions & 0 deletions miden-tx/src/host/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::{collections::BTreeMap, string::ToString};
use std::println;

use miden_lib::transaction::{TransactionEvent, TransactionKernelError};
use miden_objects::{
Expand Down Expand Up @@ -61,6 +62,14 @@ impl<A: AdviceProvider> TransactionHost<A> {
.expect("failed to push value onto advice stack");
Ok(())
}

fn on_account_print_cycle_data<S: ProcessState>(
&self,
process: &S,
) -> Result<(), TransactionKernelError> {
println!("Event emitted at step {} in context {}", process.clk(), process.ctx(),);
Ok(())
}
}

impl<A: AdviceProvider> Host for TransactionHost<A> {
Expand Down Expand Up @@ -101,6 +110,7 @@ impl<A: AdviceProvider> Host for TransactionHost<A> {
AccountStorageSetItem => self.on_account_storage_set_item(process),
AccountIncrementNonce => self.on_account_increment_nonce(process),
AccountPushProcedureIndex => self.on_account_push_procedure_index(process),
AccountBenchData => self.on_account_print_cycle_data(process),
}
.map_err(|err| ExecutionError::EventError(err.to_string()))?;

Expand Down
2 changes: 1 addition & 1 deletion miden-tx/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ fn test_tx_script() {
// ================================================================================================

#[derive(Clone)]
struct MockDataStore {
pub struct MockDataStore {
pub account: Account,
pub block_header: BlockHeader,
pub block_chain: ChainMmr,
Expand Down
1 change: 1 addition & 0 deletions miden-tx/tests/integration/bench/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod tx_benchmark;
16 changes: 16 additions & 0 deletions miden-tx/tests/integration/bench/tx_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::MockDataStore;
use miden_tx::TransactionExecutor;

#[test]
fn benchmark_default_tx() {
let data_store = MockDataStore::default();
let mut executor = TransactionExecutor::new(data_store.clone());

let account_id = data_store.account.id();
executor.load_account(account_id).unwrap();

let block_ref = data_store.block_header.block_num();
let note_ids = data_store.notes.iter().map(|note| note.id()).collect::<Vec<_>>();

executor.execute_transaction(account_id, block_ref, &note_ids, None).unwrap();
}
1 change: 1 addition & 0 deletions miden-tx/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod bench;
mod scripts;
mod wallet;

Expand Down

0 comments on commit cd6f639

Please sign in to comment.