Skip to content

Commit 2964a93

Browse files
committed
y
1 parent 9d5806e commit 2964a93

4 files changed

Lines changed: 64 additions & 35 deletions

File tree

crates/proto/src/domain/account.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use std::fmt::{Debug, Display, Formatter};
33
use miden_node_utils::formatting::format_opt;
44
use miden_objects::Word;
55
use miden_objects::account::{
6-
Account, AccountHeader, AccountId, AccountStorageHeader, StorageMap, StorageSlotType,
6+
Account,
7+
AccountHeader,
8+
AccountId,
9+
AccountStorageHeader,
10+
StorageMap,
11+
StorageSlotType,
712
};
813
use miden_objects::asset::{Asset, AssetVault};
914
use miden_objects::block::{AccountWitness, BlockNumber};
@@ -375,7 +380,7 @@ impl AccountVaultDetails {
375380
/// Creates `AccountVaultDetails` from vault entries (key-value pairs).
376381
///
377382
/// This is useful when entries have been fetched directly from the database
378-
/// rather than extracted from an AssetVault.
383+
/// rather than extracted from an `AssetVault`.
379384
///
380385
/// The entries are `(vault_key, asset)` pairs where `asset` is a Word representation.
381386
pub fn from_entries(entries: Vec<(Word, Word)>) -> Result<Self, miden_objects::AssetError> {
@@ -449,7 +454,7 @@ impl AccountStorageMapDetails {
449454
pub fn new(slot_index: u8, slot_data: SlotData, storage_map: &StorageMap) -> Self {
450455
match slot_data {
451456
SlotData::All => Self::from_all_entries(slot_index, storage_map),
452-
SlotData::MapKeys(keys) => Self::from_all_entries(slot_index, storage_map), // TODO use from_specific_keys
457+
SlotData::MapKeys(_keys) => Self::from_all_entries(slot_index, storage_map), /* TODO use from_specific_keys */
453458
}
454459
}
455460

@@ -468,17 +473,17 @@ impl AccountStorageMapDetails {
468473

469474
// TODO this is
470475
#[allow(dead_code)]
471-
fn from_specific_keys(slot_index: u8, keys: &[Word], storage_map: &StorageMap) -> Self {
476+
fn from_specific_keys(slot_index: u8, keys: &[Word], _storage_map: &StorageMap) -> Self {
472477
if keys.len() > Self::MAX_RETURN_ENTRIES {
473478
Self::too_many_entries(slot_index)
474479
} else {
475480
todo!("construct a partial SMT / set of key values")
476481
}
477482
}
478483

479-
/// Creates an AccountStorageMapDetails from already-queried entries (e.g., from database).
484+
/// Creates an `AccountStorageMapDetails` from already-queried entries (e.g., from database).
480485
/// This is useful when entries have been fetched directly rather than extracted from a
481-
/// StorageMap.
486+
/// `StorageMap`.
482487
pub fn from_entries(slot_index: u8, map_entries: Vec<(Word, Word)>) -> Self {
483488
let too_many_entries = map_entries.len() > Self::MAX_RETURN_ENTRIES;
484489
let map_entries = if too_many_entries { Vec::new() } else { map_entries };

crates/store/src/db/models/queries/accounts.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use miden_lib::utils::{Deserializable, Serializable};
1919
use miden_node_proto as proto;
2020
use miden_node_proto::domain::account::{AccountInfo, AccountSummary};
2121
use miden_node_utils::limiter::{QueryParamAccountIdLimit, QueryParamLimiter};
22-
use miden_objects::Word;
23-
use miden_objects::{Felt, FieldElement};
2422
use miden_objects::account::delta::AccountUpdateDetails;
2523
use miden_objects::account::{
2624
Account,
@@ -35,6 +33,7 @@ use miden_objects::account::{
3533
};
3634
use miden_objects::asset::{Asset, AssetVault, AssetVaultKey, FungibleAsset};
3735
use miden_objects::block::{BlockAccountUpdate, BlockNumber};
36+
use miden_objects::{Felt, FieldElement, Word};
3837

3938
use crate::constants::MAX_PAYLOAD_BYTES;
4039
use crate::db::models::conv::{
@@ -1398,13 +1397,9 @@ pub(crate) fn select_account_vault_at_block(
13981397
/// The storage commitment as a `Word`
13991398
fn compute_storage_commitment(slot_commitments: &[Word]) -> Word {
14001399
use miden_objects::crypto::hash::rpo::Rpo256;
1401-
1402-
let elements: Vec<Felt> = slot_commitments
1403-
.iter()
1404-
.flat_map(|w| w.iter())
1405-
.copied()
1406-
.collect();
1407-
1400+
1401+
let elements: Vec<Felt> = slot_commitments.iter().flat_map(|w| w.iter()).copied().collect();
1402+
14081403
Rpo256::hash_elements(&elements).into()
14091404
}
14101405

@@ -1517,9 +1512,7 @@ pub(crate) fn select_account_header_at_block(
15171512

15181513
let slot_commitments: Vec<Word> = storage_slots
15191514
.into_iter()
1520-
.map(|(_slot_index, _slot_type, commitment_bytes)| {
1521-
Word::read_from_bytes(&commitment_bytes)
1522-
})
1515+
.map(|(_slot_index, _slot_type, commitment_bytes)| Word::read_from_bytes(&commitment_bytes))
15231516
.collect::<Result<Vec<_>, _>>()?;
15241517

15251518
let storage_commitment = compute_storage_commitment(&slot_commitments);
@@ -1529,9 +1522,7 @@ pub(crate) fn select_account_header_at_block(
15291522
.transpose()?
15301523
.unwrap_or(Word::default());
15311524

1532-
let nonce = nonce_raw
1533-
.map(raw_sql_to_nonce)
1534-
.unwrap_or(Felt::ZERO);
1525+
let nonce = nonce_raw.map_or(Felt::ZERO, raw_sql_to_nonce);
15351526

15361527
let vault_root = vault_root_bytes
15371528
.map(|bytes| Word::read_from_bytes(&bytes))

crates/store/src/db/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,10 +1912,10 @@ fn test_select_account_code_at_block() {
19121912
[],
19131913
None,
19141914
);
1915-
1915+
19161916
// Use the actual account ID from the created account
19171917
let account_id = account.id();
1918-
1918+
19191919
// Get the code bytes before inserting
19201920
let expected_code = account.code().to_bytes();
19211921

@@ -1938,13 +1938,13 @@ fn test_select_account_code_at_block() {
19381938
assert_eq!(code_at_1, expected_code);
19391939

19401940
// Query code at non-existent block - should return None
1941-
let code_at_2 = queries::select_account_code_at_block(&mut conn, account_id, block_num_2)
1942-
.unwrap();
1941+
let code_at_2 =
1942+
queries::select_account_code_at_block(&mut conn, account_id, block_num_2).unwrap();
19431943
assert!(code_at_2.is_none(), "Code should not exist at block 2");
19441944

19451945
// Query code for non-existent account - should return None
19461946
let other_account_id = AccountId::try_from(ACCOUNT_ID_PRIVATE_SENDER).unwrap();
1947-
let code_other = queries::select_account_code_at_block(&mut conn, other_account_id, block_num_1)
1948-
.unwrap();
1947+
let code_other =
1948+
queries::select_account_code_at_block(&mut conn, other_account_id, block_num_1).unwrap();
19491949
assert!(code_other.is_none(), "Code should not exist for non-existent account");
19501950
}

crates/store/src/state.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ use std::path::Path;
99
use std::sync::Arc;
1010

1111
use miden_node_proto::domain::account::{
12-
AccountDetailRequest, AccountDetails, AccountInfo, AccountProofRequest, AccountProofResponse,
13-
AccountStorageDetails, AccountStorageMapDetails, AccountVaultDetails, NetworkAccountPrefix,
12+
AccountDetailRequest,
13+
AccountDetails,
14+
AccountInfo,
15+
AccountProofRequest,
16+
AccountProofResponse,
17+
AccountStorageDetails,
18+
AccountStorageMapDetails,
19+
AccountVaultDetails,
20+
NetworkAccountPrefix,
1421
StorageMapRequest,
1522
};
1623
use miden_node_proto::domain::batch::BatchInputs;
@@ -20,12 +27,26 @@ use miden_objects::account::{AccountId, StorageSlot};
2027
use miden_objects::block::account_tree::{AccountTree, account_id_to_smt_key};
2128
use miden_objects::block::nullifier_tree::NullifierTree;
2229
use miden_objects::block::{
23-
AccountWitness, BlockHeader, BlockInputs, BlockNumber, Blockchain, NullifierWitness,
30+
AccountWitness,
31+
BlockHeader,
32+
BlockInputs,
33+
BlockNumber,
34+
Blockchain,
35+
NullifierWitness,
2436
ProvenBlock,
2537
};
2638
use miden_objects::crypto::merkle::{
27-
Forest, LargeSmt, MemoryStorage, Mmr, MmrDelta, MmrPeaks, MmrProof, PartialMmr, SmtForest,
28-
SmtProof, SmtStorage,
39+
Forest,
40+
LargeSmt,
41+
MemoryStorage,
42+
Mmr,
43+
MmrDelta,
44+
MmrPeaks,
45+
MmrProof,
46+
PartialMmr,
47+
SmtForest,
48+
SmtProof,
49+
SmtStorage,
2950
};
3051
use miden_objects::note::{NoteDetails, NoteId, NoteScript, Nullifier};
3152
use miden_objects::transaction::{OutputNote, PartialBlockchain};
@@ -38,11 +59,23 @@ use crate::blocks::BlockStore;
3859
use crate::db::models::Page;
3960
use crate::db::models::queries::StorageMapValuesPage;
4061
use crate::db::{
41-
AccountVaultValue, Db, NoteRecord, NoteSyncUpdate, NullifierInfo, StateSyncUpdate,
62+
AccountVaultValue,
63+
Db,
64+
NoteRecord,
65+
NoteSyncUpdate,
66+
NullifierInfo,
67+
StateSyncUpdate,
4268
};
4369
use crate::errors::{
44-
ApplyBlockError, DatabaseError, GetBatchInputsError, GetBlockHeaderError, GetBlockInputsError,
45-
GetCurrentBlockchainDataError, InvalidBlockError, NoteSyncError, StateInitializationError,
70+
ApplyBlockError,
71+
DatabaseError,
72+
GetBatchInputsError,
73+
GetBlockHeaderError,
74+
GetBlockInputsError,
75+
GetCurrentBlockchainDataError,
76+
InvalidBlockError,
77+
NoteSyncError,
78+
StateInitializationError,
4679
StateSyncError,
4780
};
4881
use crate::{AccountTreeWithHistory, COMPONENT, DataDirectory};

0 commit comments

Comments
 (0)