From 1b152a87d4bfca023e3ca0a0eb8fd2466ef2c221 Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Wed, 3 Dec 2025 14:17:15 -0300 Subject: [PATCH 1/7] feat: make get account proof retrieve latest known state --- crates/proto/src/generated/rpc_store.rs | 2 ++ crates/store/src/db/mod.rs | 2 +- crates/store/src/db/models/queries/accounts.rs | 14 ++++++++++---- crates/store/src/state.rs | 4 ++-- proto/proto/store/rpc.proto | 2 ++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/proto/src/generated/rpc_store.rs b/crates/proto/src/generated/rpc_store.rs index 9feea358c..3f8ec7298 100644 --- a/crates/proto/src/generated/rpc_store.rs +++ b/crates/proto/src/generated/rpc_store.rs @@ -20,6 +20,8 @@ pub struct AccountProofRequest { 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. + /// 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, /// Request for additional account details; valid only for public accounts. diff --git a/crates/store/src/db/mod.rs b/crates/store/src/db/mod.rs index 6339c0660..3f65d30c8 100644 --- a/crates/store/src/db/mod.rs +++ b/crates/store/src/db/mod.rs @@ -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, diff --git a/crates/store/src/db/models/queries/accounts.rs b/crates/store/src/db/models/queries/accounts.rs index 52be3ee84..a9613dfa2 100644 --- a/crates/store/src/db/models/queries/accounts.rs +++ b/crates/store/src/db/models/queries/accounts.rs @@ -93,8 +93,8 @@ 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 at a block number lower or equal than specified from the DB using the +/// given [`SqliteConnection`]. /// /// # Returns /// @@ -118,7 +118,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 +138,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/crates/store/src/state.rs b/crates/store/src/state.rs index e91a11477..23d79a627 100644 --- a/crates/store/src/state.rs +++ b/crates/store/src/state.rs @@ -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, @@ -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 diff --git a/proto/proto/store/rpc.proto b/proto/proto/store/rpc.proto index 6f78444c7..007af5ce3 100644 --- a/proto/proto/store/rpc.proto +++ b/proto/proto/store/rpc.proto @@ -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. optional blockchain.BlockNumber block_num = 2; // Request for additional account details; valid only for public accounts. From 72a9755b00a1e27da809d17b908b18890057110b Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Wed, 3 Dec 2025 14:19:44 -0300 Subject: [PATCH 2/7] docs: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd6f20c20..2fbc1e478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 containt account updates ([#1422](https://github.com/0xMiden/miden-node/issues/1422)). ### Fixes From 83c609f208c55dc4c5459ba0cb95fe4f4b43fa84 Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Wed, 3 Dec 2025 14:25:59 -0300 Subject: [PATCH 3/7] docs: fix typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fbc1e478..09f51cab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +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 containt account updates ([#1422](https://github.com/0xMiden/miden-node/issues/1422)). +- 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 From e8f74dd41e94dc42a3ad0f3906f0d9a2564e0a0f Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Wed, 3 Dec 2025 14:38:08 -0300 Subject: [PATCH 4/7] ci: try fix msrv script --- scripts/check-msrv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check-msrv.sh b/scripts/check-msrv.sh index 0bde2955f..f88ab8480 100755 --- a/scripts/check-msrv.sh +++ b/scripts/check-msrv.sh @@ -92,7 +92,7 @@ while IFS=$'\t' read -r pkg_id package_name manifest_path rust_version; do # Determine the currently-installed stable toolchain version (e.g., "1.81.0") latest_stable="$(rustup run stable rustc --version 2>/dev/null | awk '{print $2}')" - if [[ -z "$latest_stable" ]]; then latest_stable="1.81.0"; fi + if [[ -z "$latest_stable" ]]; then latest_stable="1.91.1"; fi # Search for the actual MSRV starting from the current one if actual_msrv=$(cargo msrv find \ @@ -150,4 +150,4 @@ if [[ -n "$failed_packages" ]]; then else echo "ALL WORKSPACE MEMBERS PASSED MSRV CHECKS!" exit 0 -fi \ No newline at end of file +fi From 33f3a1600545e9af1e6b1b0b866df7d4451ba35c Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Wed, 3 Dec 2025 14:50:34 -0300 Subject: [PATCH 5/7] Revert "ci: try fix msrv script" This reverts commit e8f74dd41e94dc42a3ad0f3906f0d9a2564e0a0f. --- scripts/check-msrv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check-msrv.sh b/scripts/check-msrv.sh index f88ab8480..0bde2955f 100755 --- a/scripts/check-msrv.sh +++ b/scripts/check-msrv.sh @@ -92,7 +92,7 @@ while IFS=$'\t' read -r pkg_id package_name manifest_path rust_version; do # Determine the currently-installed stable toolchain version (e.g., "1.81.0") latest_stable="$(rustup run stable rustc --version 2>/dev/null | awk '{print $2}')" - if [[ -z "$latest_stable" ]]; then latest_stable="1.91.1"; fi + if [[ -z "$latest_stable" ]]; then latest_stable="1.81.0"; fi # Search for the actual MSRV starting from the current one if actual_msrv=$(cargo msrv find \ @@ -150,4 +150,4 @@ if [[ -n "$failed_packages" ]]; then else echo "ALL WORKSPACE MEMBERS PASSED MSRV CHECKS!" exit 0 -fi +fi \ No newline at end of file From 295e5199df16b7d8b0d5f0277cf4ab086241a313 Mon Sep 17 00:00:00 2001 From: juan518munoz <62400508+juan518munoz@users.noreply.github.com> Date: Wed, 3 Dec 2025 16:01:40 -0300 Subject: [PATCH 6/7] Apply suggestion from @Mirko-von-Leipzig Co-authored-by: Mirko <48352201+Mirko-von-Leipzig@users.noreply.github.com> --- crates/store/src/db/models/queries/accounts.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/store/src/db/models/queries/accounts.rs b/crates/store/src/db/models/queries/accounts.rs index a9613dfa2..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 block number lower or equal than specified from the DB using the -/// given [`SqliteConnection`]. +/// Select account details as they are at the given block height. /// /// # Returns /// From 04725803b830d6169ad58a0f98ef2c627eea2653 Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Wed, 3 Dec 2025 16:11:56 -0300 Subject: [PATCH 7/7] chore: address PR comments --- CHANGELOG.md | 2 +- crates/proto/src/generated/rpc_store.rs | 7 +++---- crates/store/src/db/mod.rs | 2 +- crates/store/src/state.rs | 4 ++-- proto/proto/store/rpc.proto | 7 +++---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09f51cab3..e04239a90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,13 +15,13 @@ - 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 - 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 3f8ec7298..c96247504 100644 --- a/crates/proto/src/generated/rpc_store.rs +++ b/crates/proto/src/generated/rpc_store.rs @@ -18,10 +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. - /// If the specified block does not contain an update for the specified account, - /// the latest available data 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/mod.rs b/crates/store/src/db/mod.rs index 3f65d30c8..6339c0660 100644 --- a/crates/store/src/db/mod.rs +++ b/crates/store/src/db/mod.rs @@ -408,7 +408,7 @@ impl Db { .await } - /// Loads account details up to a specific block number from the DB. + /// Loads account details at 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, diff --git a/crates/store/src/state.rs b/crates/store/src/state.rs index 23d79a627..e91a11477 100644 --- a/crates/store/src/state.rs +++ b/crates/store/src/state.rs @@ -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 up to that specific + /// When `block_num` is provided, this method will return the account state at that specific /// block using both the historical account tree witness and historical database state. pub async fn get_account_proof( &self, @@ -977,7 +977,7 @@ impl State { Ok((block_num, witness)) } - /// Fetches the account details (code, vault, storage) for a public account up to the specified + /// Fetches the account details (code, vault, storage) for a public account at the specified /// block. /// /// This method queries the database to fetch the account state and processes the detail diff --git a/proto/proto/store/rpc.proto b/proto/proto/store/rpc.proto index 007af5ce3..6ac935225 100644 --- a/proto/proto/store/rpc.proto +++ b/proto/proto/store/rpc.proto @@ -147,10 +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. - // If the specified block does not contain an update for the specified account, - // the latest available data 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.