miden_tx/prover/
mast_store.rs1use alloc::collections::BTreeMap;
2use alloc::sync::Arc;
3
4use miden_processor::MastForestStore;
5use miden_protocol::account::AccountCode;
6use miden_protocol::assembly::mast::MastForest;
7use miden_protocol::transaction::TransactionKernel;
8use miden_protocol::utils::sync::RwLock;
9use miden_protocol::{CoreLibrary, ProtocolLib, Word};
10use miden_standards::StandardsLib;
11
12pub struct TransactionMastStore {
23 mast_forests: RwLock<BTreeMap<Word, Arc<MastForest>>>,
24}
25
26#[allow(clippy::new_without_default)]
27impl TransactionMastStore {
28 pub fn new() -> Self {
36 let mast_forests = RwLock::new(BTreeMap::new());
37 let store = Self { mast_forests };
38
39 let kernels_forest = TransactionKernel::kernel().mast_forest().clone();
41 store.insert(kernels_forest);
42
43 let miden_core_lib_forest = CoreLibrary::default().mast_forest().clone();
45 store.insert(miden_core_lib_forest);
46
47 let protocol_lib_forest = ProtocolLib::default().mast_forest().clone();
49 store.insert(protocol_lib_forest);
50
51 let standards_lib_forest = StandardsLib::default().mast_forest().clone();
53 store.insert(standards_lib_forest);
54
55 store
56 }
57
58 pub fn insert(&self, mast_forest: Arc<MastForest>) {
60 let mut mast_forests = self.mast_forests.write();
61
62 for proc_digest in mast_forest.local_procedure_digests() {
64 mast_forests.insert(proc_digest, mast_forest.clone());
65 }
66 }
67
68 pub fn load_account_code(&self, code: &AccountCode) {
70 self.insert(code.mast().clone());
71 }
72}
73
74impl MastForestStore for TransactionMastStore {
78 fn get(&self, procedure_root: &Word) -> Option<Arc<MastForest>> {
79 self.mast_forests.read().get(procedure_root).cloned()
80 }
81}