@@ -3,14 +3,16 @@ use alloc::{collections::BTreeSet, sync::Arc, vec::Vec};
33use miden_lib:: transaction:: TransactionKernel ;
44use miden_objects:: {
55 account:: { AccountCode , AccountId } ,
6- assembly:: Library ,
76 block:: BlockNumber ,
8- note:: NoteId ,
9- transaction:: { ExecutedTransaction , TransactionArgs , TransactionInputs , TransactionScript } ,
7+ note:: NoteLocation ,
8+ transaction:: {
9+ ExecutedTransaction , InputNote , InputNotes , TransactionArgs , TransactionInputs ,
10+ TransactionScript ,
11+ } ,
1012 vm:: StackOutputs ,
1113 Felt , MAX_TX_EXECUTION_CYCLES , MIN_TX_EXECUTION_CYCLES , ZERO ,
1214} ;
13- use vm_processor:: { AdviceInputs , ExecutionOptions , Process , RecAdviceProvider } ;
15+ use vm_processor:: { AdviceInputs , ExecutionOptions , MastForestStore , Process , RecAdviceProvider } ;
1416use winter_maybe_async:: { maybe_async, maybe_await} ;
1517
1618use super :: { TransactionExecutorError , TransactionHost } ;
@@ -36,7 +38,7 @@ pub use mast_store::TransactionMastStore;
3638/// [TransactionAuthenticator], allowing it to be used with different backend implementations.
3739pub struct TransactionExecutor {
3840 data_store : Arc < dyn DataStore > ,
39- mast_store : Arc < TransactionMastStore > ,
41+ mast_forest_store : Arc < dyn MastForestStore > ,
4042 authenticator : Option < Arc < dyn TransactionAuthenticator > > ,
4143 /// Holds the code of all accounts loaded into this transaction executor via the
4244 /// [Self::load_account_code()] method.
@@ -52,13 +54,14 @@ impl TransactionExecutor {
5254 /// [TransactionAuthenticator].
5355 pub fn new (
5456 data_store : Arc < dyn DataStore > ,
57+ mast_forest_store : Arc < dyn MastForestStore > ,
5558 authenticator : Option < Arc < dyn TransactionAuthenticator > > ,
5659 ) -> Self {
5760 const _: ( ) = assert ! ( MIN_TX_EXECUTION_CYCLES <= MAX_TX_EXECUTION_CYCLES ) ;
5861
5962 Self {
6063 data_store,
61- mast_store : Arc :: new ( TransactionMastStore :: new ( ) ) ,
64+ mast_forest_store ,
6265 authenticator,
6366 exec_options : ExecutionOptions :: new (
6467 Some ( MAX_TX_EXECUTION_CYCLES ) ,
@@ -91,27 +94,6 @@ impl TransactionExecutor {
9194 self
9295 }
9396
94- // STATE MUTATORS
95- // --------------------------------------------------------------------------------------------
96-
97- /// Loads the provided account code into the internal MAST forest store and adds the commitment
98- /// of the provided code to the commitments set.
99- pub fn load_account_code ( & mut self , code : & AccountCode ) {
100- // load the code mast forest to the mast store
101- self . mast_store . load_account_code ( code) ;
102-
103- // store the commitment of the foreign account code in the set
104- self . account_codes . insert ( code. clone ( ) ) ;
105- }
106-
107- /// Loads the provided library code into the internal MAST forest store.
108- ///
109- /// TODO: this is a work-around to support accounts which were complied with user-defined
110- /// libraries. Once Miden Assembler supports library vendoring, this should go away.
111- pub fn load_library ( & mut self , library : & Library ) {
112- self . mast_store . insert ( library. mast_forest ( ) . clone ( ) ) ;
113- }
114-
11597 // TRANSACTION EXECUTION
11698 // --------------------------------------------------------------------------------------------
11799
@@ -130,24 +112,36 @@ impl TransactionExecutor {
130112 & self ,
131113 account_id : AccountId ,
132114 block_ref : BlockNumber ,
133- notes : & [ NoteId ] ,
115+ notes : InputNotes < InputNote > ,
134116 tx_args : TransactionArgs ,
135117 ) -> Result < ExecutedTransaction , TransactionExecutorError > {
136- let tx_inputs =
137- maybe_await ! ( self . data_store. get_transaction_inputs( account_id, block_ref, notes) )
138- . map_err ( TransactionExecutorError :: FetchTransactionInputsFailed ) ?;
118+ // TODO: Check that the reference block is not listed here, or otherwise
119+ // change the DataStore/executor API so that returning a ChainMmr with the reference
120+ // block works anyway.
121+ let ref_blocks: BTreeSet < BlockNumber > = notes
122+ . iter ( )
123+ . filter_map ( InputNote :: location)
124+ . map ( NoteLocation :: block_num)
125+ . collect ( ) ;
126+
127+ let ( account, seed) = maybe_await ! ( self . data_store. get_account_inputs( account_id) )
128+ . map_err ( TransactionExecutorError :: FetchTransactionInputsFailed ) ?;
129+
130+ let ( mmr, header) = maybe_await ! ( self . data_store. get_chain_inputs( ref_blocks, block_ref) )
131+ . map_err ( TransactionExecutorError :: FetchTransactionInputsFailed ) ?;
132+
133+ let tx_inputs = TransactionInputs :: new ( account, seed, header, mmr, notes)
134+ . map_err ( TransactionExecutorError :: InvalidTransactionInputs ) ?;
139135
140136 let ( stack_inputs, advice_inputs) =
141137 TransactionKernel :: prepare_inputs ( & tx_inputs, & tx_args, None ) ;
142- let advice_recorder: RecAdviceProvider = advice_inputs. into ( ) ;
143138
144- // load note script MAST into the MAST store
145- self . mast_store . load_transaction_code ( & tx_inputs, & tx_args) ;
139+ let advice_recorder: RecAdviceProvider = advice_inputs. into ( ) ;
146140
147141 let mut host = TransactionHost :: new (
148142 tx_inputs. account ( ) . into ( ) ,
149143 advice_recorder,
150- self . mast_store . clone ( ) ,
144+ self . mast_forest_store . clone ( ) ,
151145 self . authenticator . clone ( ) ,
152146 self . account_codes . iter ( ) . map ( |code| code. commitment ( ) ) . collect ( ) ,
153147 )
@@ -202,23 +196,26 @@ impl TransactionExecutor {
202196 tx_script : TransactionScript ,
203197 advice_inputs : AdviceInputs ,
204198 ) -> Result < [ Felt ; 16 ] , TransactionExecutorError > {
205- let tx_inputs =
206- maybe_await ! ( self . data_store. get_transaction_inputs( account_id, block_ref, & [ ] ) )
199+ let ( account, seed) = maybe_await ! ( self . data_store. get_account_inputs( account_id) )
200+ . map_err ( TransactionExecutorError :: FetchTransactionInputsFailed ) ?;
201+
202+ let ( mmr, header) =
203+ maybe_await ! ( self . data_store. get_chain_inputs( Default :: default ( ) , block_ref) )
207204 . map_err ( TransactionExecutorError :: FetchTransactionInputsFailed ) ?;
208205
206+ let tx_inputs = TransactionInputs :: new ( account, seed, header, mmr, Default :: default ( ) )
207+ . map_err ( TransactionExecutorError :: InvalidTransactionInputs ) ?;
208+
209209 let tx_args = TransactionArgs :: new ( Some ( tx_script. clone ( ) ) , None , Default :: default ( ) ) ;
210210
211211 let ( stack_inputs, advice_inputs) =
212212 TransactionKernel :: prepare_inputs ( & tx_inputs, & tx_args, Some ( advice_inputs) ) ;
213213 let advice_recorder: RecAdviceProvider = advice_inputs. into ( ) ;
214214
215- // load transaction script MAST into the MAST store
216- self . mast_store . load_transaction_code ( & tx_inputs, & tx_args) ;
217-
218215 let mut host = TransactionHost :: new (
219216 tx_inputs. account ( ) . into ( ) ,
220217 advice_recorder,
221- self . mast_store . clone ( ) ,
218+ self . mast_forest_store . clone ( ) ,
222219 self . authenticator . clone ( ) ,
223220 self . account_codes . iter ( ) . map ( |code| code. commitment ( ) ) . collect ( ) ,
224221 )
0 commit comments