Skip to content

Commit 3bd5451

Browse files
committed
Merge branch 'bernhard-db-schema-queries' into bernhard-integrate-smtforest
2 parents dbbc1eb + 69ee5a5 commit 3bd5451

6 files changed

Lines changed: 249 additions & 190 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- Increased retained account tree history from 33 to 100 blocks to account for the reduced block interval ([#1438](https://github.com/0xMiden/miden-node/pull/1438)).
3636
- Increased the maximum query limit for the store ([#1443](https://github.com/0xMiden/miden-node/pull/1443)).
3737
- [BREAKING] Migrated to version `v0.20` of the VM ([#1476](https://github.com/0xMiden/miden-node/pull/1476)).
38+
- [BREAKING] Change account in database representation ([#1481](https://github.com/0xMiden/miden-node/pull/1481)).
3839

3940
### Fixes
4041

crates/proto/src/domain/account.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use miden_protocol::block::account_tree::AccountWitness;
1717
use miden_protocol::crypto::merkle::SparseMerklePath;
1818
use miden_protocol::note::{NoteExecutionMode, NoteTag};
1919
use miden_protocol::utils::{Deserializable, DeserializationError, Serializable};
20-
use miden_protocol::{AssetError, Word};
20+
use miden_protocol::Word;
2121
use thiserror::Error;
2222

2323
use super::try_convert;
@@ -72,7 +72,6 @@ impl From<AccountId> for proto::account::AccountId {
7272
// ACCOUNT UPDATE
7373
// ================================================================================================
7474

75-
// TODO should be called `AccountStateRef` or so
7675
#[derive(Debug, PartialEq)]
7776
pub struct AccountSummary {
7877
pub account_id: AccountId,
@@ -389,24 +388,6 @@ impl AccountVaultDetails {
389388
Self::Assets(assets)
390389
}
391390
}
392-
393-
/// Creates `AccountVaultDetails` from vault entries (key-value pairs).
394-
///
395-
/// This is useful when entries have been fetched directly from the database
396-
/// rather than extracted from an `AssetVault`.
397-
///
398-
/// The entries are `(vault_key, asset)` pairs where `asset` is a Word representation.
399-
pub fn from_entries(entries: Vec<(Word, Word)>) -> Result<Self, AssetError> {
400-
if entries.len() > Self::MAX_RETURN_ENTRIES {
401-
return Ok(Self::LimitExceeded);
402-
}
403-
404-
let assets = Result::<Vec<_>, _>::from_iter(
405-
entries.into_iter().map(|(_key, asset_word)| Asset::try_from(asset_word)),
406-
)?;
407-
408-
Ok(Self::Assets(assets))
409-
}
410391
}
411392

412393
impl TryFrom<proto::rpc::AccountVaultDetails> for AccountVaultDetails {

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub(crate) use at_block::{
5656
select_account_vault_at_block,
5757
};
5858

59+
#[cfg(test)]
60+
mod tests;
61+
5962
type StorageMapValueRow = (i64, String, Vec<u8>, Vec<u8>);
6063

6164
// ACCOUNT RETRIEVAL
@@ -447,14 +450,17 @@ pub(crate) fn select_all_accounts(
447450
.order_by(schema::accounts::block_num.asc())
448451
.load::<AccountSummaryRaw>(conn)?;
449452

450-
let summaries: Vec<AccountSummary> = vec_raw_try_into(raw).unwrap();
453+
let summaries: Vec<AccountSummary> = vec_raw_try_into(raw)?;
451454

452455
// Backfill account details from database
453-
let account_infos = Vec::from_iter(summaries.into_iter().map(|summary| {
454-
let account_id = summary.account_id;
455-
let details = select_full_account(conn, account_id).ok();
456-
AccountInfo { summary, details }
457-
}));
456+
let account_infos = summaries
457+
.into_iter()
458+
.map(|summary| {
459+
let account_id = summary.account_id;
460+
let details = select_full_account(conn, account_id).ok();
461+
AccountInfo { summary, details }
462+
})
463+
.collect();
458464

459465
Ok(account_infos)
460466
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,11 @@ pub(crate) fn select_account_storage_at_block(
279279
DatabaseError::DataCorrupted(format!("Invalid slot name: {slot_name_str}"))
280280
})?;
281281
let key = Word::read_from_bytes(&key_bytes)?;
282+
let value = Word::read_from_bytes(&value_bytes)?;
282283

283284
// Only insert if we haven't seen this (slot_name, key) yet
284285
// (since results are ordered by block_num desc, first one is latest)
285-
latest_map_entries
286-
.entry((slot_name, key))
287-
.or_insert_with(|| Word::read_from_bytes(&value_bytes).unwrap_or_default());
286+
latest_map_entries.entry((slot_name, key)).or_insert(value);
288287
}
289288

290289
// Group entries by slot name

0 commit comments

Comments
 (0)