Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Added support for caching mempool statistics in the block producer server ([#1388](https://github.com/0xMiden/miden-node/pull/1388)).
- Added mempool statistics to the block producer status in the `miden-network-monitor` binary ([#1392](https://github.com/0xMiden/miden-node/pull/1392)).
- Add `S` generic to `NullifierTree` to allow usage with `LargeSmt`s ([#1353](https://github.com/0xMiden/miden-node/issues/1353)).
- Modify `AccountProofRequest` to retrieve the latest known state in case specified block number (or chain tip) does not contain account updates ([#1422](https://github.com/0xMiden/miden-node/issues/1422)).

### Fixes

Expand Down
2 changes: 2 additions & 0 deletions crates/proto/src/generated/rpc_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct AccountProofRequest {
pub account_id: ::core::option::Option<super::account::AccountId>,
/// Block at which we'd like to get this data. If present, must be close to the chain tip.
/// If not present, data from the latest block will be returned.
/// If the specified block does not contain an update for the specified account,
/// the latest available data will be returned.
#[prost(message, optional, tag = "2")]
pub block_num: ::core::option::Option<super::blockchain::BlockNumber>,
/// Request for additional account details; valid only for public accounts.
Expand Down
2 changes: 1 addition & 1 deletion crates/store/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl Db {
.await
}

/// Loads account details at a specific block number from the DB.
/// Loads account details up to a specific block number from the DB.
#[instrument(level = "debug", target = COMPONENT, skip_all, ret(level = "debug"), err)]
pub async fn select_historical_account_at(
&self,
Expand Down
13 changes: 9 additions & 4 deletions crates/store/src/db/models/queries/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ pub(crate) fn select_account(
Ok(info)
}

/// Select account details at a specific block number from the DB using the given
/// [`SqliteConnection`].
/// Select account details as they are at the given block height.
///
/// # Returns
///
Expand All @@ -118,7 +117,11 @@ pub(crate) fn select_account(
/// account_codes ON accounts.code_commitment = account_codes.code_commitment
/// WHERE
/// account_id = ?1
/// AND block_num = ?2
/// AND block_num <= ?2
/// ORDER BY
/// block_num DESC
/// LIMIT
/// 1
/// ```
pub(crate) fn select_historical_account_at(
conn: &mut SqliteConnection,
Expand All @@ -134,8 +137,10 @@ pub(crate) fn select_historical_account_at(
.filter(
schema::accounts::account_id
.eq(account_id.to_bytes())
.and(schema::accounts::block_num.eq(block_num.to_raw_sql())),
.and(schema::accounts::block_num.le(block_num.to_raw_sql())),
)
.order_by(schema::accounts::block_num.desc())
.limit(1)
.get_result::<(AccountRaw, Option<Vec<u8>>)>(conn)
.optional()?
.ok_or(DatabaseError::AccountNotFoundInDb(account_id))?;
Expand Down
4 changes: 2 additions & 2 deletions crates/store/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ impl State {
/// Returns the respective account proof with optional details, such as asset and storage
/// entries.
///
/// When `block_num` is provided, this method will return the account state at that specific
/// When `block_num` is provided, this method will return the account state up to that specific
/// block using both the historical account tree witness and historical database state.
pub async fn get_account_proof(
&self,
Expand Down Expand Up @@ -977,7 +977,7 @@ impl State {
Ok((block_num, witness))
}

/// Fetches the account details (code, vault, storage) for a public account at the specified
/// Fetches the account details (code, vault, storage) for a public account up to the specified
/// block.
///
/// This method queries the database to fetch the account state and processes the detail
Expand Down
2 changes: 2 additions & 0 deletions proto/proto/store/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ message AccountProofRequest {

// Block at which we'd like to get this data. If present, must be close to the chain tip.
// If not present, data from the latest block will be returned.
// If the specified block does not contain an update for the specified account,
// the latest available data will be returned.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit ambiguous and could mean that asking for block N could return data after N aka latest > N.

I think phrasing the entire comment as something like

// Optional block height at which to return the proof.
//
// Defaults to current chain tip if unspecified.

optional blockchain.BlockNumber block_num = 2;

// Request for additional account details; valid only for public accounts.
Expand Down
Loading