From 3ab4b54c4cda4147205bb490742c984ae7b4d090 Mon Sep 17 00:00:00 2001 From: yito88 Date: Thu, 2 May 2024 17:16:33 +0200 Subject: [PATCH 1/3] set height for abci_query --- crates/apps/src/lib/node/ledger/shell/queries.rs | 8 +++++++- crates/namada/src/ledger/mod.rs | 1 + crates/sdk/src/queries/mod.rs | 1 + crates/sdk/src/queries/router.rs | 8 ++++++-- crates/sdk/src/queries/shell.rs | 7 ++++--- crates/sdk/src/queries/shell/eth_bridge.rs | 9 +++++---- crates/sdk/src/queries/types.rs | 2 ++ 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/apps/src/lib/node/ledger/shell/queries.rs b/crates/apps/src/lib/node/ledger/shell/queries.rs index dd7ddce5e3..7dab7cb27e 100644 --- a/crates/apps/src/lib/node/ledger/shell/queries.rs +++ b/crates/apps/src/lib/node/ledger/shell/queries.rs @@ -30,10 +30,16 @@ where namada::ledger::queries::handle_path(ctx, &query) }; match result { - Ok(ResponseQuery { data, info, proof }) => response::Query { + Ok(ResponseQuery { + data, + info, + proof, + height, + }) => response::Query { value: data.into(), info, proof: proof.map(Into::into), + height: height.0.try_into().expect("Height should be parsable"), ..Default::default() }, Err(err) => response::Query { diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index d450470023..ba16e3ad65 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -124,6 +124,7 @@ mod dry_run_tx { data, proof: None, info: Default::default(), + height: ctx.state.in_mem().get_last_block_height(), }) } } diff --git a/crates/sdk/src/queries/mod.rs b/crates/sdk/src/queries/mod.rs index 8d612a68eb..ee8869c019 100644 --- a/crates/sdk/src/queries/mod.rs +++ b/crates/sdk/src/queries/mod.rs @@ -459,6 +459,7 @@ impl Client for C { data: response.value, info: response.info, proof: response.proof, + height: response.height.value().into(), }), Code::Err(code) => Err(Error::Query(response.info, code.into())), } diff --git a/crates/sdk/src/queries/router.rs b/crates/sdk/src/queries/router.rs index 5befe67f3b..5270a859f6 100644 --- a/crates/sdk/src/queries/router.rs +++ b/crates/sdk/src/queries/router.rs @@ -86,6 +86,7 @@ macro_rules! handle_match { $crate::queries::require_no_proof($request)?; $crate::queries::require_no_data($request)?; + let last_committed_height = $ctx.state.in_mem().get_last_block_height(); // If you get a compile error from here with `expected function, found // queries::Storage`, you're probably missing the marker `(sub _)` let data = $handle($ctx, $( $matched_args ),* )?; @@ -95,6 +96,7 @@ macro_rules! handle_match { data, info: Default::default(), proof: None, + height: last_committed_height, }); }; } @@ -417,13 +419,14 @@ macro_rules! pattern_and_handler_to_method { let path = self.storage_value_path( $( $param ),* ); let $crate::queries::ResponseQuery { - data, info, proof + data, info, proof, height, } = client.request(path, data, height, prove).await?; Ok($crate::queries::ResponseQuery { data, info, proof, + height, }) } } @@ -469,7 +472,7 @@ macro_rules! pattern_and_handler_to_method { let path = self.[<$handle _path>]( $( $param ),* ); let $crate::queries::ResponseQuery { - data, info, proof + data, info, proof, height } = client.request(path, data, height, prove).await?; let decoded: $return_type = @@ -479,6 +482,7 @@ macro_rules! pattern_and_handler_to_method { data: decoded, info, proof, + height, }) } } diff --git a/crates/sdk/src/queries/shell.rs b/crates/sdk/src/queries/shell.rs index d6cb69ad88..08fb6036a3 100644 --- a/crates/sdk/src/queries/shell.rs +++ b/crates/sdk/src/queries/shell.rs @@ -420,6 +420,7 @@ where data: value, proof, info: Default::default(), + height: ctx.state.in_mem().get_last_block_height(), }) } (None, _gas) => { @@ -436,6 +437,7 @@ where data: vec![], proof, info: format!("No value found for key: {}", storage_key), + height: ctx.state.in_mem().get_last_block_height(), }) } } @@ -460,11 +462,9 @@ where }) .collect(); let data = data?; + let last_committed_height = ctx.state.in_mem().get_last_block_height(); let proof = if request.prove { let queried_height = { - let last_committed_height = - ctx.state.in_mem().get_last_block_height(); - let height: BlockHeight = request.height.into(); let is_last_height_query = height.0 == 0; @@ -492,6 +492,7 @@ where Ok(EncodedResponseQuery { data, proof, + height: last_committed_height, ..Default::default() }) } diff --git a/crates/sdk/src/queries/shell/eth_bridge.rs b/crates/sdk/src/queries/shell/eth_bridge.rs index 28f112c37e..3fcc57dd21 100644 --- a/crates/sdk/src/queries/shell/eth_bridge.rs +++ b/crates/sdk/src/queries/shell/eth_bridge.rs @@ -254,12 +254,10 @@ where }; // check which transfers in the Bridge pool match the requested hashes + let last_committed_height = ctx.state.in_mem().get_last_block_height(); let merkle_tree = ctx .state - .get_merkle_tree( - ctx.state.in_mem().get_last_block_height(), - Some(StoreType::BridgePool), - ) + .get_merkle_tree(last_committed_height, Some(StoreType::BridgePool)) .expect("We should always be able to read the database"); let stores = merkle_tree.stores(); let store = match stores.store(&StoreType::BridgePool) { @@ -289,6 +287,7 @@ where let data = status.serialize_to_vec(); return Ok(EncodedResponseQuery { data, + height: last_committed_height, ..Default::default() }); } @@ -342,6 +341,7 @@ where }; Ok(EncodedResponseQuery { data: status.serialize_to_vec(), + height: last_committed_height, ..Default::default() }) } @@ -606,6 +606,7 @@ where let data = rsp.serialize_to_vec(); Ok(EncodedResponseQuery { data, + height: ctx.state.in_mem().get_last_block_height(), ..Default::default() }) } diff --git a/crates/sdk/src/queries/types.rs b/crates/sdk/src/queries/types.rs index b191cb59b5..c96aa73bcd 100644 --- a/crates/sdk/src/queries/types.rs +++ b/crates/sdk/src/queries/types.rs @@ -90,6 +90,8 @@ pub struct ResponseQuery { pub info: String, /// Optional proof - used for storage value reads which request `prove` pub proof: Option, + /// Height of the latest committed block + pub height: BlockHeight, } /// [`ResponseQuery`] with borsh-encoded `data` field From b9476ca86cc91d0b222fe501b24eaba32f378fd2 Mon Sep 17 00:00:00 2001 From: yito88 Date: Thu, 2 May 2024 17:42:38 +0200 Subject: [PATCH 2/3] add changelog --- .changelog/unreleased/bug-fixes/3065-abci-query-height.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/3065-abci-query-height.md diff --git a/.changelog/unreleased/bug-fixes/3065-abci-query-height.md b/.changelog/unreleased/bug-fixes/3065-abci-query-height.md new file mode 100644 index 0000000000..59167620f7 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/3065-abci-query-height.md @@ -0,0 +1,2 @@ +- Set the height for abci_query response + ([\#3065](https://github.com/anoma/namada/issues/3065)) \ No newline at end of file From 801a115c388b2b9b514702914ba5db965996644a Mon Sep 17 00:00:00 2001 From: yito88 Date: Thu, 2 May 2024 20:56:00 +0200 Subject: [PATCH 3/3] fix queried height --- crates/sdk/src/queries/shell.rs | 27 +++++++++++----------- crates/sdk/src/queries/shell/eth_bridge.rs | 6 ++--- crates/sdk/src/queries/types.rs | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/crates/sdk/src/queries/shell.rs b/crates/sdk/src/queries/shell.rs index 08fb6036a3..b35cdc7ab0 100644 --- a/crates/sdk/src/queries/shell.rs +++ b/crates/sdk/src/queries/shell.rs @@ -420,7 +420,7 @@ where data: value, proof, info: Default::default(), - height: ctx.state.in_mem().get_last_block_height(), + height: queried_height, }) } (None, _gas) => { @@ -437,7 +437,7 @@ where data: vec![], proof, info: format!("No value found for key: {}", storage_key), - height: ctx.state.in_mem().get_last_block_height(), + height: queried_height, }) } } @@ -462,18 +462,17 @@ where }) .collect(); let data = data?; - let last_committed_height = ctx.state.in_mem().get_last_block_height(); - let proof = if request.prove { - let queried_height = { - let height: BlockHeight = request.height.into(); - let is_last_height_query = height.0 == 0; + let queried_height = { + let height: BlockHeight = request.height.into(); + let is_last_height_query = height.0 == 0; - if hints::likely(is_last_height_query) { - last_committed_height - } else { - height - } - }; + if hints::likely(is_last_height_query) { + ctx.state.in_mem().get_last_block_height() + } else { + height + } + }; + let proof = if request.prove { let mut ops = vec![]; for PrefixValue { key, value } in &data { let mut proof = ctx @@ -492,7 +491,7 @@ where Ok(EncodedResponseQuery { data, proof, - height: last_committed_height, + height: queried_height, ..Default::default() }) } diff --git a/crates/sdk/src/queries/shell/eth_bridge.rs b/crates/sdk/src/queries/shell/eth_bridge.rs index 3fcc57dd21..beefb21ec7 100644 --- a/crates/sdk/src/queries/shell/eth_bridge.rs +++ b/crates/sdk/src/queries/shell/eth_bridge.rs @@ -248,13 +248,13 @@ where return Ok(Default::default()); } + let last_committed_height = ctx.state.in_mem().get_last_block_height(); let mut status = TransferToEthereumStatus { - queried_height: ctx.state.in_mem().get_last_block_height(), + queried_height: last_committed_height, ..Default::default() }; // check which transfers in the Bridge pool match the requested hashes - let last_committed_height = ctx.state.in_mem().get_last_block_height(); let merkle_tree = ctx .state .get_merkle_tree(last_committed_height, Some(StoreType::BridgePool)) @@ -606,7 +606,7 @@ where let data = rsp.serialize_to_vec(); Ok(EncodedResponseQuery { data, - height: ctx.state.in_mem().get_last_block_height(), + height, ..Default::default() }) } diff --git a/crates/sdk/src/queries/types.rs b/crates/sdk/src/queries/types.rs index c96aa73bcd..8764a130ce 100644 --- a/crates/sdk/src/queries/types.rs +++ b/crates/sdk/src/queries/types.rs @@ -90,7 +90,7 @@ pub struct ResponseQuery { pub info: String, /// Optional proof - used for storage value reads which request `prove` pub proof: Option, - /// Height of the latest committed block + /// Block height from which data was derived pub height: BlockHeight, }