Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set height for abci_query #3164

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/3065-abci-query-height.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Set the height for abci_query response
([\#3065](https://github.com/anoma/namada/issues/3065))
8 changes: 7 additions & 1 deletion crates/apps/src/lib/node/ledger/shell/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions crates/namada/src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ mod dry_run_tx {
data,
proof: None,
info: Default::default(),
height: ctx.state.in_mem().get_last_block_height(),
})
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/sdk/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ impl<C: tendermint_rpc::client::Client + std::marker::Sync> 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())),
}
Expand Down
8 changes: 6 additions & 2 deletions crates/sdk/src/queries/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),* )?;
Expand All @@ -95,6 +96,7 @@ macro_rules! handle_match {
data,
info: Default::default(),
proof: None,
height: last_committed_height,
});
};
}
Expand Down Expand Up @@ -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,
})
}
}
Expand Down Expand Up @@ -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 =
Expand All @@ -479,6 +482,7 @@ macro_rules! pattern_and_handler_to_method {
data: decoded,
info,
proof,
height,
})
}
}
Expand Down
26 changes: 13 additions & 13 deletions crates/sdk/src/queries/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ where
data: value,
proof,
info: Default::default(),
height: queried_height,
})
}
(None, _gas) => {
Expand All @@ -436,6 +437,7 @@ where
data: vec![],
proof,
info: format!("No value found for key: {}", storage_key),
height: queried_height,
})
}
}
Expand All @@ -460,20 +462,17 @@ where
})
.collect();
let data = data?;
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;
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
Expand All @@ -492,6 +491,7 @@ where
Ok(EncodedResponseQuery {
data,
proof,
height: queried_height,
..Default::default()
})
}
Expand Down
11 changes: 6 additions & 5 deletions crates/sdk/src/queries/shell/eth_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,16 @@ 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 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) {
Expand Down Expand Up @@ -289,6 +287,7 @@ where
let data = status.serialize_to_vec();
return Ok(EncodedResponseQuery {
data,
height: last_committed_height,
..Default::default()
});
}
Expand Down Expand Up @@ -342,6 +341,7 @@ where
};
Ok(EncodedResponseQuery {
data: status.serialize_to_vec(),
height: last_committed_height,
..Default::default()
})
}
Expand Down Expand Up @@ -606,6 +606,7 @@ where
let data = rsp.serialize_to_vec();
Ok(EncodedResponseQuery {
data,
height,
..Default::default()
})
}
Expand Down
2 changes: 2 additions & 0 deletions crates/sdk/src/queries/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub struct ResponseQuery<T> {
pub info: String,
/// Optional proof - used for storage value reads which request `prove`
pub proof: Option<ProofOps>,
/// Block height from which data was derived
pub height: BlockHeight,
}

/// [`ResponseQuery`] with borsh-encoded `data` field
Expand Down
Loading