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

Fix query client consensus command #287

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add epoch to query client consensus
  • Loading branch information
ancazamfir committed Oct 6, 2020
commit 48e0c2cad16ab3eb2d6d706c47a196b9f2029b16
6 changes: 3 additions & 3 deletions modules/src/ics24_host/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const IBC_QUERY_PATH: &str = "store/ibc/key";
pub enum Path {
ClientType(ClientId),
ClientState(ClientId),
ClientConsensusState(ClientId, u64),
ClientConsensusState(ClientId, u64, u64),
ancazamfir marked this conversation as resolved.
Show resolved Hide resolved
ClientConnections(ClientId),
Connections(ConnectionId),
Ports(PortId),
Expand Down Expand Up @@ -46,8 +46,8 @@ impl Display for Path {
match &self {
Path::ClientType(id) => write!(f, "clients/{}/clientType", id),
Path::ClientState(id) => write!(f, "clients/{}/clientState", id),
Path::ClientConsensusState(id, height) => {
write!(f, "clients/{}/consensusState/{}", id, height)
Path::ClientConsensusState(id, epoch, height) => {
write!(f, "clients/{}/consensusState/{}-{}", id, epoch, height)
}
Path::ClientConnections(id) => write!(f, "clients/{}/connections", id),
Path::Connections(id) => write!(f, "connections/{}", id),
Expand Down
3 changes: 2 additions & 1 deletion modules/src/mock_client/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ impl ClientDef for MockClient {
_expected_consensus_state: &AnyConsensusState,
) -> Result<(), Box<dyn std::error::Error>> {
let client_prefixed_path =
Path::ClientConsensusState(client_id.clone(), height.value()).to_string();
// TODO - will pick epoch from new type Height
Path::ClientConsensusState(client_id.clone(), 0, height.value()).to_string();

let _path = apply_prefix(prefix, client_prefixed_path)?;

Expand Down
15 changes: 11 additions & 4 deletions relayer-cli/src/commands/query/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ pub struct QueryClientConsensusCmd {
#[options(free, help = "identifier of the client to query")]
client_id: Option<String>,

#[options(free, help = "epoch of the client's consensus state to query")]
consensus_epoch: Option<u64>,

#[options(free, help = "height of the client's consensus state to query")]
consensus_height: Option<u64>,

Expand All @@ -116,6 +119,7 @@ pub struct QueryClientConsensusCmd {
#[derive(Debug)]
struct QueryClientConsensusOptions {
client_id: ClientId,
consensus_epoch: u64,
consensus_height: u64,
height: u64,
proof: bool,
Expand All @@ -129,10 +133,11 @@ impl QueryClientConsensusCmd {
let (chain_config, client_id) =
validate_common_options(&self.chain_id, &self.client_id, config)?;

match self.consensus_height {
Some(consensus_height) => {
match (self.consensus_epoch, self.consensus_height) {
(Some(consensus_epoch), Some(consensus_height)) => {
let opts = QueryClientConsensusOptions {
client_id,
consensus_epoch,
consensus_height,
height: match self.height {
Some(h) => h,
Expand All @@ -145,7 +150,9 @@ impl QueryClientConsensusCmd {
};
Ok((chain_config, opts))
}
None => Err("missing client consensus height".to_string()),
(Some(consensus_epoch), None) => Err("missing client consensus height".to_string()),

(None, _) => Err("missing client consensus epoch".to_string()),
}
}
}
Expand All @@ -172,7 +179,7 @@ impl Runnable for QueryClientConsensusCmd {
let chain = CosmosSDKChain::from_config(chain_config).unwrap();
let res: Result<AnyConsensusState, Error> = chain
.query(
ClientConsensusState(opts.client_id, opts.consensus_height),
ClientConsensusState(opts.client_id, opts.consensus_epoch, opts.consensus_height),
opts.height,
opts.proof,
)
Expand Down