miden_tx/executor/data_store.rs
1use alloc::collections::BTreeSet;
2use alloc::vec::Vec;
3
4use miden_processor::{FutureMaybeSend, MastForestStore, Word};
5use miden_protocol::account::{AccountId, PartialAccount, StorageMapKey, StorageMapWitness};
6use miden_protocol::asset::{AssetId, AssetWitness};
7use miden_protocol::block::{BlockHeader, BlockNumber};
8use miden_protocol::note::{NoteScript, NoteScriptRoot};
9use miden_protocol::transaction::{AccountInputs, PartialBlockchain};
10
11use crate::DataStoreError;
12
13// DATA STORE TRAIT
14// ================================================================================================
15
16/// The [DataStore] trait defines the interface that transaction objects use to fetch data
17/// required for transaction execution.
18pub trait DataStore: MastForestStore {
19 /// Returns all the data required to execute a transaction against the account with the
20 /// specified ID and consuming input notes created in blocks in the input `ref_blocks` set.
21 ///
22 /// The highest block number in `ref_blocks` will be the transaction reference block. In
23 /// general, it is recommended that the reference corresponds to the latest block available
24 /// in the data store.
25 ///
26 /// # Errors
27 /// Returns an error if:
28 /// - The account with the specified ID could not be found in the data store.
29 /// - The block with the specified number could not be found in the data store.
30 /// - The combination of specified inputs resulted in a transaction input error.
31 /// - The data store encountered some internal error
32 fn get_transaction_inputs(
33 &self,
34 account_id: AccountId,
35 ref_blocks: BTreeSet<BlockNumber>,
36 ) -> impl FutureMaybeSend<Result<(PartialAccount, BlockHeader, PartialBlockchain), DataStoreError>>;
37
38 /// Returns a partial foreign account state together with a witness, proving its validity in the
39 /// specified transaction reference block.
40 fn get_foreign_account_inputs(
41 &self,
42 foreign_account_id: AccountId,
43 ref_block: BlockNumber,
44 ) -> impl FutureMaybeSend<Result<AccountInputs, DataStoreError>>;
45
46 /// Returns witnesses for the asset IDs in the requested account's vault with the
47 /// requested vault root.
48 ///
49 /// These are the witnesses that need to be added to the advice provider's merkle store and
50 /// advice map to make access to the corresponding assets possible.
51 fn get_vault_asset_witnesses(
52 &self,
53 account_id: AccountId,
54 vault_root: Word,
55 asset_ids: BTreeSet<AssetId>,
56 ) -> impl FutureMaybeSend<Result<Vec<AssetWitness>, DataStoreError>>;
57
58 /// Returns a witness for a storage map item identified by `map_key` in the requested account's
59 /// storage with the requested storage `map_root`.
60 ///
61 /// Note that the `map_key` needs to be hashed in order to get the actual key into the storage
62 /// map.
63 ///
64 /// This is the witness that needs to be added to the advice provider's merkle store and advice
65 /// map to make access to the specified storage map item possible.
66 fn get_storage_map_witness(
67 &self,
68 account_id: AccountId,
69 map_root: Word,
70 map_key: StorageMapKey,
71 ) -> impl FutureMaybeSend<Result<StorageMapWitness, DataStoreError>>;
72
73 /// Returns a note script with the specified root, or `None` if not found.
74 ///
75 /// This method will try to find a note script with the specified root in the data store.
76 /// If the script is not found, it returns `Ok(None)` rather than an error, as "not found"
77 /// is a valid, expected outcome.
78 ///
79 /// **Note:** Data store implementers do not need to handle standard note scripts (e.g. P2ID).
80 /// These are resolved directly by the transaction executor and will not trigger this method.
81 ///
82 /// # Errors
83 /// Returns an error if the data store encountered an internal error while attempting to
84 /// retrieve the script.
85 fn get_note_script(
86 &self,
87 script_root: NoteScriptRoot,
88 ) -> impl FutureMaybeSend<Result<Option<NoteScript>, DataStoreError>>;
89}