Skip to content

Commit 2dbea7f

Browse files
Merge next
2 parents 429b63e + 292a47e commit 2dbea7f

9 files changed

Lines changed: 83 additions & 83 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/src/inner_forest/mod.rs renamed to crates/store/src/account_state_forest/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ mod tests;
4141
// ================================================================================================
4242

4343
#[derive(Debug, Error)]
44-
pub enum InnerForestError {
44+
pub enum AccountStateForestError {
4545
#[error(transparent)]
4646
Asset(#[from] AssetError),
4747
#[error(transparent)]
@@ -60,17 +60,17 @@ pub enum WitnessError {
6060
AssetError(#[from] AssetError),
6161
}
6262

63-
// INNER FOREST
63+
// ACCOUNT STATE FOREST
6464
// ================================================================================================
6565

6666
/// Container for forest-related state that needs to be updated atomically.
67-
pub(crate) struct InnerForest {
67+
pub(crate) struct AccountStateForest {
6868
/// `LargeSmtForest` for efficient account storage reconstruction.
6969
/// Populated during block import with storage and vault SMTs.
7070
forest: LargeSmtForest<ForestInMemoryBackend>,
7171
}
7272

73-
impl InnerForest {
73+
impl AccountStateForest {
7474
pub(crate) fn new() -> Self {
7575
Self { forest: Self::create_forest() }
7676
}
@@ -311,7 +311,7 @@ impl InnerForest {
311311
&mut self,
312312
block_num: BlockNumber,
313313
account_updates: impl IntoIterator<Item = AccountDelta>,
314-
) -> Result<(), InnerForestError> {
314+
) -> Result<(), AccountStateForestError> {
315315
for delta in account_updates {
316316
self.update_account(block_num, &delta)?;
317317

@@ -345,7 +345,7 @@ impl InnerForest {
345345
&mut self,
346346
block_num: BlockNumber,
347347
delta: &AccountDelta,
348-
) -> Result<(), InnerForestError> {
348+
) -> Result<(), AccountStateForestError> {
349349
let account_id = delta.id();
350350
let is_full_state = delta.is_full_state();
351351

@@ -383,7 +383,7 @@ impl InnerForest {
383383
block_num: BlockNumber,
384384
account_id: AccountId,
385385
vault_delta: &AccountVaultDelta,
386-
) -> Result<(), InnerForestError> {
386+
) -> Result<(), AccountStateForestError> {
387387
let prev_root = self.get_latest_vault_root(account_id);
388388
let lineage = Self::vault_lineage_id(account_id);
389389
assert_eq!(prev_root, Self::empty_smt_root(), "account should not be in the forest");
@@ -523,7 +523,7 @@ impl InnerForest {
523523
block_num: BlockNumber,
524524
account_id: AccountId,
525525
vault_delta: &AccountVaultDelta,
526-
) -> Result<(), InnerForestError> {
526+
) -> Result<(), AccountStateForestError> {
527527
assert!(!vault_delta.is_empty(), "expected the delta not to be empty");
528528

529529
// get the previous vault root; the root could be for an empty or non-empty SMT

crates/store/src/inner_forest/tests.rs renamed to crates/store/src/account_state_forest/tests.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,21 @@ fn dummy_full_state_delta(account_id: AccountId, assets: &[Asset]) -> AccountDel
5858
fn empty_smt_root_is_recognized() {
5959
use miden_crypto::merkle::smt::Smt;
6060

61-
let empty_root = InnerForest::empty_smt_root();
61+
let empty_root = AccountStateForest::empty_smt_root();
6262

6363
assert_eq!(Smt::default().root(), empty_root);
6464
}
6565

6666
#[test]
67-
fn inner_forest_basic_initialization() {
68-
let forest = InnerForest::new();
67+
fn account_state_forest_basic_initialization() {
68+
let forest = AccountStateForest::new();
6969
assert_eq!(forest.forest.lineage_count(), 0);
7070
assert_eq!(forest.forest.tree_count(), 0);
7171
}
7272

7373
#[test]
7474
fn update_account_with_empty_deltas() {
75-
let mut forest = InnerForest::new();
75+
let mut forest = AccountStateForest::new();
7676
let account_id = dummy_account();
7777
let block_num = BlockNumber::GENESIS.child();
7878

@@ -99,15 +99,15 @@ fn vault_partial_vs_full_state_produces_same_root() {
9999
let asset = dummy_fungible_asset(faucet_id, 100);
100100

101101
// Partial delta (block application)
102-
let mut forest_partial = InnerForest::new();
102+
let mut forest_partial = AccountStateForest::new();
103103
let mut vault_delta = AccountVaultDelta::default();
104104
vault_delta.add_asset(asset).unwrap();
105105
let partial_delta =
106106
dummy_partial_delta(account_id, vault_delta, AccountStorageDelta::default());
107107
forest_partial.update_account(block_num, &partial_delta).unwrap();
108108

109109
// Full-state delta (DB reconstruction)
110-
let mut forest_full = InnerForest::new();
110+
let mut forest_full = AccountStateForest::new();
111111
let full_delta = dummy_full_state_delta(account_id, &[asset]);
112112
forest_full.update_account(block_num, &full_delta).unwrap();
113113

@@ -120,7 +120,7 @@ fn vault_partial_vs_full_state_produces_same_root() {
120120

121121
#[test]
122122
fn vault_incremental_updates_with_add_and_remove() {
123-
let mut forest = InnerForest::new();
123+
let mut forest = AccountStateForest::new();
124124
let account_id = dummy_account();
125125
let faucet_id = dummy_faucet();
126126

@@ -153,7 +153,7 @@ fn vault_incremental_updates_with_add_and_remove() {
153153
assert_ne!(root_after_150, root_after_120);
154154

155155
// Verify by comparing to full-state delta
156-
let mut fresh_forest = InnerForest::new();
156+
let mut fresh_forest = AccountStateForest::new();
157157
let full_delta = dummy_full_state_delta(account_id, &[dummy_fungible_asset(faucet_id, 120)]);
158158
fresh_forest.update_account(block_3, &full_delta).unwrap();
159159
let root_full_state_120 = fresh_forest.get_vault_root(account_id, block_3).unwrap();
@@ -168,7 +168,7 @@ fn forest_versions_are_continuous_for_sequential_updates() {
168168
use assert_matches::assert_matches;
169169
use miden_protocol::account::delta::{StorageMapDelta, StorageSlotDelta};
170170

171-
let mut forest = InnerForest::new();
171+
let mut forest = AccountStateForest::new();
172172
let account_id = dummy_account();
173173
let faucet_id = dummy_faucet();
174174
let slot_name = StorageSlotName::mock(9);
@@ -201,7 +201,7 @@ fn forest_versions_are_continuous_for_sequential_updates() {
201201

202202
#[test]
203203
fn vault_state_is_not_available_for_block_gaps() {
204-
let mut forest = InnerForest::new();
204+
let mut forest = AccountStateForest::new();
205205
let account_id = dummy_account();
206206
let faucet_id = dummy_faucet();
207207

@@ -229,7 +229,7 @@ fn witness_queries_work_with_sparse_lineage_updates() {
229229
use assert_matches::assert_matches;
230230
use miden_protocol::account::delta::{StorageMapDelta, StorageSlotDelta};
231231

232-
let mut forest = InnerForest::new();
232+
let mut forest = AccountStateForest::new();
233233
let account_id = dummy_account();
234234
let faucet_id = dummy_faucet();
235235
let slot_name = StorageSlotName::mock(6);
@@ -282,14 +282,14 @@ fn witness_queries_work_with_sparse_lineage_updates() {
282282
.open(forest.tree_id_for_vault_root(account_id, block_3), asset_key.into()),
283283
Ok(_)
284284
);
285-
assert_ne!(vault_root_at_3, InnerForest::empty_smt_root());
285+
assert_ne!(vault_root_at_3, AccountStateForest::empty_smt_root());
286286
}
287287

288288
#[test]
289289
fn vault_full_state_with_empty_vault_records_root() {
290290
use miden_protocol::account::{Account, AccountStorage};
291291

292-
let mut forest = InnerForest::new();
292+
let mut forest = AccountStateForest::new();
293293
let account_id = dummy_account();
294294
let block_num = BlockNumber::GENESIS.child();
295295

@@ -306,7 +306,7 @@ fn vault_full_state_with_empty_vault_records_root() {
306306
forest.update_account(block_num, &full_delta).unwrap();
307307

308308
let recorded_root = forest.get_vault_root(account_id, block_num);
309-
assert_eq!(recorded_root, Some(InnerForest::empty_smt_root()));
309+
assert_eq!(recorded_root, Some(AccountStateForest::empty_smt_root()));
310310

311311
let witnesses = forest
312312
.get_vault_asset_witnesses(account_id, block_num, std::collections::BTreeSet::new())
@@ -316,7 +316,7 @@ fn vault_full_state_with_empty_vault_records_root() {
316316

317317
#[test]
318318
fn vault_shared_root_retained_when_one_entry_pruned() {
319-
let mut forest = InnerForest::new();
319+
let mut forest = AccountStateForest::new();
320320
let account1 = AccountId::try_from(ACCOUNT_ID_REGULAR_PUBLIC_ACCOUNT_IMMUTABLE_CODE).unwrap();
321321
let account2 = AccountId::try_from(ACCOUNT_ID_REGULAR_PUBLIC_ACCOUNT_IMMUTABLE_CODE_2).unwrap();
322322
let faucet_id = dummy_faucet();
@@ -376,7 +376,7 @@ fn storage_map_incremental_updates() {
376376

377377
use miden_protocol::account::delta::{StorageMapDelta, StorageSlotDelta};
378378

379-
let mut forest = InnerForest::new();
379+
let mut forest = AccountStateForest::new();
380380
let account_id = dummy_account();
381381

382382
let slot_name = StorageSlotName::mock(3);
@@ -431,7 +431,7 @@ fn test_storage_map_removals() {
431431
const VALUE_1: [u32; 4] = [10, 0, 0, 0];
432432
const VALUE_2: [u32; 4] = [20, 0, 0, 0];
433433

434-
let mut forest = InnerForest::new();
434+
let mut forest = AccountStateForest::new();
435435
let account_id = dummy_account();
436436
let slot_name = StorageSlotName::mock(SLOT_INDEX);
437437
let key_1 = StorageMapKey::from_index(1);
@@ -481,7 +481,7 @@ fn storage_map_state_is_not_available_for_block_gaps() {
481481
const VALUE_FIRST: u32 = 10;
482482
const VALUE_SECOND: u32 = 20;
483483

484-
let mut forest = InnerForest::new();
484+
let mut forest = AccountStateForest::new();
485485
let account_id = dummy_account();
486486
let slot_name = StorageSlotName::mock(4);
487487
let raw_key = StorageMapKey::from_index(KEY_VALUE);
@@ -532,7 +532,7 @@ fn storage_map_empty_entries_query() {
532532
use miden_standards::account::auth::AuthSingleSig;
533533
use miden_standards::code_builder::CodeBuilder;
534534

535-
let mut forest = InnerForest::new();
535+
let mut forest = AccountStateForest::new();
536536
let block_num = BlockNumber::GENESIS.child();
537537
let slot_name = StorageSlotName::mock(0);
538538

@@ -567,7 +567,7 @@ fn storage_map_empty_entries_query() {
567567
forest.update_account(block_num, &full_delta).unwrap();
568568

569569
let root = forest.get_storage_map_root(account_id, &slot_name, block_num);
570-
assert_eq!(root, Some(InnerForest::empty_smt_root()));
570+
assert_eq!(root, Some(AccountStateForest::empty_smt_root()));
571571
}
572572

573573
#[test]
@@ -577,7 +577,7 @@ fn storage_map_open_returns_proofs() {
577577
use assert_matches::assert_matches;
578578
use miden_protocol::account::delta::{StorageMapDelta, StorageSlotDelta};
579579

580-
let mut forest = InnerForest::new();
580+
let mut forest = AccountStateForest::new();
581581
let account_id = dummy_account();
582582
let slot_name = StorageSlotName::mock(3);
583583
let block_num = BlockNumber::GENESIS.child();
@@ -613,7 +613,7 @@ fn storage_map_key_hashing_and_raw_entries_are_consistent() {
613613
const KEY_VALUE: u32 = 11;
614614
const VALUE_VALUE: u32 = 22;
615615

616-
let mut forest = InnerForest::new();
616+
let mut forest = AccountStateForest::new();
617617
let account_id = dummy_account();
618618
let slot_name = StorageSlotName::mock(SLOT_INDEX);
619619
let block_num = BlockNumber::GENESIS.child();
@@ -650,7 +650,7 @@ const TEST_PRUNE_CHAIN_TIP: u32 = HISTORICAL_BLOCK_RETENTION + 5;
650650

651651
#[test]
652652
fn prune_handles_empty_forest() {
653-
let mut forest = InnerForest::new();
653+
let mut forest = AccountStateForest::new();
654654

655655
let total_roots_removed = forest.prune(BlockNumber::GENESIS);
656656

@@ -661,7 +661,7 @@ fn prune_handles_empty_forest() {
661661
fn prune_removes_smt_roots_from_forest() {
662662
use miden_protocol::account::delta::StorageMapDelta;
663663

664-
let mut forest = InnerForest::new();
664+
let mut forest = AccountStateForest::new();
665665
let account_id = dummy_account();
666666
let faucet_id = dummy_faucet();
667667
let slot_name = StorageSlotName::mock(7);
@@ -712,7 +712,7 @@ fn prune_removes_smt_roots_from_forest() {
712712

713713
#[test]
714714
fn prune_respects_retention_boundary() {
715-
let mut forest = InnerForest::new();
715+
let mut forest = AccountStateForest::new();
716716
let account_id = dummy_account();
717717
let faucet_id = dummy_faucet();
718718

@@ -736,7 +736,7 @@ fn prune_respects_retention_boundary() {
736736
fn prune_roots_removes_old_entries() {
737737
use miden_protocol::account::delta::StorageMapDelta;
738738

739-
let mut forest = InnerForest::new();
739+
let mut forest = AccountStateForest::new();
740740
let account_id = dummy_account();
741741

742742
let faucet_id = dummy_faucet();
@@ -770,7 +770,7 @@ fn prune_roots_removes_old_entries() {
770770

771771
#[test]
772772
fn prune_handles_multiple_accounts() {
773-
let mut forest = InnerForest::new();
773+
let mut forest = AccountStateForest::new();
774774
let account1 = dummy_account();
775775
let account2 = AccountId::try_from(ACCOUNT_ID_PUBLIC_FUNGIBLE_FAUCET).unwrap();
776776
let faucet_id = dummy_faucet();
@@ -807,7 +807,7 @@ fn prune_handles_multiple_slots() {
807807

808808
use miden_protocol::account::delta::{StorageMapDelta, StorageSlotDelta};
809809

810-
let mut forest = InnerForest::new();
810+
let mut forest = AccountStateForest::new();
811811
let account_id = dummy_account();
812812
let slot_a = StorageSlotName::mock(1);
813813
let slot_b = StorageSlotName::mock(2);
@@ -843,7 +843,7 @@ fn prune_preserves_most_recent_state_per_entity() {
843843

844844
use miden_protocol::account::delta::{StorageMapDelta, StorageSlotDelta};
845845

846-
let mut forest = InnerForest::new();
846+
let mut forest = AccountStateForest::new();
847847
let account_id = dummy_account();
848848
let faucet_id = dummy_faucet();
849849
let slot_map_a = StorageSlotName::mock(1);
@@ -900,7 +900,7 @@ fn prune_preserves_entries_within_retention_window() {
900900

901901
use miden_protocol::account::delta::{StorageMapDelta, StorageSlotDelta};
902902

903-
let mut forest = InnerForest::new();
903+
let mut forest = AccountStateForest::new();
904904
let account_id = dummy_account();
905905
let faucet_id = dummy_faucet();
906906
let slot_map = StorageSlotName::mock(1);
@@ -944,7 +944,7 @@ fn prune_preserves_entries_within_retention_window() {
944944
/// witness generation.
945945
#[test]
946946
fn shared_vault_root_retained_when_one_account_changes() {
947-
let mut forest = InnerForest::new();
947+
let mut forest = AccountStateForest::new();
948948
let account1 = AccountId::try_from(ACCOUNT_ID_REGULAR_PUBLIC_ACCOUNT_IMMUTABLE_CODE).unwrap();
949949
let account2 = AccountId::try_from(ACCOUNT_ID_REGULAR_PUBLIC_ACCOUNT_IMMUTABLE_CODE_2).unwrap();
950950
let faucet_id = dummy_faucet();

crates/store/src/db/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl Db {
616616

617617
/// Reconstructs storage map details from the database for a specific slot at a block.
618618
///
619-
/// Used as fallback when `InnerForest` cache misses (historical or evicted queries).
619+
/// Used as fallback when `AccountStateForest` cache misses (historical or evicted queries).
620620
/// Rebuilds all entries by querying the DB and filtering to the specific slot.
621621
///
622622
/// Returns:

0 commit comments

Comments
 (0)