Struct miden_tx::TransactionExecutor
source · pub struct TransactionExecutor<D, A> { /* private fields */ }Expand description
The transaction executor is responsible for executing Miden rollup transactions.
Transaction execution consists of the following steps:
- Fetch the data required to execute a transaction from the DataStore.
- Compile the transaction into a program using the TransactionCompiler.
- Execute the transaction program and create an ExecutedTransaction.
The transaction executor is generic over the DataStore which allows it to be used with different data backend implementations.
The TransactionExecutor::execute_transaction() method is the main entry point for the executor and produces an ExecutedTransaction for the transaction. The executed transaction can then be used to by the prover to generate a proof transaction execution.
Implementations§
source§impl<D: DataStore, A: TransactionAuthenticator> TransactionExecutor<D, A>
impl<D: DataStore, A: TransactionAuthenticator> TransactionExecutor<D, A>
sourcepub fn new(data_store: D, authenticator: Option<Rc<A>>) -> Self
pub fn new(data_store: D, authenticator: Option<Rc<A>>) -> Self
Creates a new TransactionExecutor instance with the specified DataStore and TransactionAuthenticator.
sourcepub fn with_debug_mode(self, in_debug_mode: bool) -> Self
pub fn with_debug_mode(self, in_debug_mode: bool) -> Self
Puts the TransactionExecutor into debug mode.
When transaction executor is in debug mode, all transaction-related code (note scripts, account code) will be compiled and executed in debug mode. This will ensure that all debug instructions present in the original source code are executed.
sourcepub fn with_tracing(self) -> Self
pub fn with_tracing(self) -> Self
Enables tracing for the created instance of TransactionExecutor.
When tracing is enabled, the executor will receive tracing events as various stages of the transaction kernel complete. This enables collecting basic stats about how long different stages of transaction execution take.
sourcepub fn load_account(
&mut self,
account_id: AccountId,
) -> Result<AccountCode, TransactionExecutorError>
pub fn load_account( &mut self, account_id: AccountId, ) -> Result<AccountCode, TransactionExecutorError>
Fetches the account code from the DataStore, compiles it, and loads the compiled code into the internal cache.
This also returns the AccountCode object built from the loaded account code.
§Errors:
Returns an error if:
- If the account code cannot be fetched from the DataStore.
- If the account code fails to be loaded into the compiler.
sourcepub fn load_account_interface(
&mut self,
account_id: AccountId,
procedures: Vec<Digest>,
) -> Option<Vec<Digest>>
pub fn load_account_interface( &mut self, account_id: AccountId, procedures: Vec<Digest>, ) -> Option<Vec<Digest>>
Loads the provided account interface (vector of procedure digests) into the compiler.
Returns the old interface for the specified account ID if it previously existed.
sourcepub fn compile_note_script(
&self,
note_script_ast: ProgramAst,
target_account_procs: Vec<ScriptTarget>,
) -> Result<NoteScript, TransactionExecutorError>
pub fn compile_note_script( &self, note_script_ast: ProgramAst, target_account_procs: Vec<ScriptTarget>, ) -> Result<NoteScript, TransactionExecutorError>
Compiles the provided program into a NoteScript and checks (to the extent possible) if the specified note program could be executed against all accounts with the specified interfaces.
sourcepub fn compile_tx_script<T>(
&self,
tx_script_ast: ProgramAst,
inputs: T,
target_account_procs: Vec<ScriptTarget>,
) -> Result<TransactionScript, TransactionExecutorError>
pub fn compile_tx_script<T>( &self, tx_script_ast: ProgramAst, inputs: T, target_account_procs: Vec<ScriptTarget>, ) -> Result<TransactionScript, TransactionExecutorError>
Compiles the provided transaction script source and inputs into a TransactionScript and checks (to the extent possible) that the transaction script can be executed against all accounts with the specified interfaces.
sourcepub fn execute_transaction(
&self,
account_id: AccountId,
block_ref: u32,
notes: &[NoteId],
tx_args: TransactionArgs,
) -> Result<ExecutedTransaction, TransactionExecutorError>
pub fn execute_transaction( &self, account_id: AccountId, block_ref: u32, notes: &[NoteId], tx_args: TransactionArgs, ) -> Result<ExecutedTransaction, TransactionExecutorError>
Prepares and executes a transaction specified by the provided arguments and returns an ExecutedTransaction.
The method first fetches the data required to execute the transaction from the DataStore and compile the transaction into an executable program. Then, it executes the transaction program and creates an ExecutedTransaction object.
§Errors:
Returns an error if:
- If required data can not be fetched from the DataStore.
- If the transaction program can not be compiled.
- If the transaction program can not be executed.
sourcepub fn prepare_transaction(
&self,
account_id: AccountId,
block_ref: u32,
notes: &[NoteId],
tx_args: TransactionArgs,
) -> Result<PreparedTransaction, TransactionExecutorError>
pub fn prepare_transaction( &self, account_id: AccountId, block_ref: u32, notes: &[NoteId], tx_args: TransactionArgs, ) -> Result<PreparedTransaction, TransactionExecutorError>
Fetches the data required to execute the transaction from the DataStore, compiles the transaction into an executable program using the TransactionCompiler, and returns a PreparedTransaction.
§Errors:
Returns an error if:
- If required data can not be fetched from the DataStore.
- If the transaction can not be compiled.