diff --git a/CHANGELOG.md b/CHANGELOG.md index fd6f20c20..e04239a90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - RPC client now correctly sets `genesis` value in `ACCEPT` header if `version` is unspecified ([#1370](https://github.com/0xMiden/miden-node/pull/1370)). - Pin protobuf (`protox`) dependencies to avoid breaking changes in transitive dependency ([#1403](https://github.com/0xMiden/miden-node/pull/1403)). - Fixed no-std compatibility for remote prover clients ([#1407](https://github.com/0xMiden/miden-node/pull/1407)). +- Fixed `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)). ## v0.12.6 diff --git a/crates/proto/src/generated/rpc_store.rs b/crates/proto/src/generated/rpc_store.rs index 9feea358c..c96247504 100644 --- a/crates/proto/src/generated/rpc_store.rs +++ b/crates/proto/src/generated/rpc_store.rs @@ -18,8 +18,9 @@ pub struct AccountProofRequest { /// ID of the account for which we want to get data #[prost(message, optional, tag = "1")] pub account_id: ::core::option::Option, - /// 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. + /// Optional block height at which to return the proof. + /// + /// Defaults to current chain tip if unspecified. #[prost(message, optional, tag = "2")] pub block_num: ::core::option::Option, /// Request for additional account details; valid only for public accounts. diff --git a/crates/store/src/db/models/queries/accounts.rs b/crates/store/src/db/models/queries/accounts.rs index 52be3ee84..8189403bc 100644 --- a/crates/store/src/db/models/queries/accounts.rs +++ b/crates/store/src/db/models/queries/accounts.rs @@ -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 /// @@ -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, @@ -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>)>(conn) .optional()? .ok_or(DatabaseError::AccountNotFoundInDb(account_id))?; diff --git a/proto/proto/store/rpc.proto b/proto/proto/store/rpc.proto index 6f78444c7..6ac935225 100644 --- a/proto/proto/store/rpc.proto +++ b/proto/proto/store/rpc.proto @@ -147,8 +147,9 @@ message AccountProofRequest { // ID of the account for which we want to get data account.AccountId account_id = 1; - // 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. + // 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.