From 7aa514df927f542313a43f2fd26f15af5d4a072f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 17 Jun 2021 17:39:05 +0200 Subject: [PATCH] Backport: IBC query header/node-state fixes (#9385) * fix ibc query header/node-state cmds * changelog Co-authored-by: Amaury M <1293565+amaurym@users.noreply.github.com> --- CHANGELOG.md | 1 + x/ibc/core/02-client/client/utils/utils.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8c6769244f4..8748a73fe883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* [\#9385](https://github.com/cosmos/cosmos-sdk/pull/9385) Fix IBC `query ibc client header` cli command. Support historical queries for query header/node-state commands. * [\#9401](https://github.com/cosmos/cosmos-sdk/pull/9401) Fixes incorrect export of IBC identifier sequences. Previously, the next identifier sequence for clients/connections/channels was not set during genesis export. This resulted in the next identifiers being generated on the new chain to reuse old identifiers (the sequences began again from 0). * [\#9408](https://github.com/cosmos/cosmos-sdk/pull/9408) Update simapp to use correct default broadcast mode. diff --git a/x/ibc/core/02-client/client/utils/utils.go b/x/ibc/core/02-client/client/utils/utils.go index 1a7bc003bc51..847abb00d250 100644 --- a/x/ibc/core/02-client/client/utils/utils.go +++ b/x/ibc/core/02-client/client/utils/utils.go @@ -131,14 +131,19 @@ func QueryTendermintHeader(clientCtx client.Context) (ibctmtypes.Header, int64, return ibctmtypes.Header{}, 0, err } - height := info.Response.LastBlockHeight + var height int64 + if clientCtx.Height != 0 { + height = clientCtx.Height + } else { + height = info.Response.LastBlockHeight + } commit, err := node.Commit(context.Background(), &height) if err != nil { return ibctmtypes.Header{}, 0, err } - page := 0 + page := 1 count := 10_000 validators, err := node.Validators(context.Background(), &height, &page, &count) @@ -173,7 +178,12 @@ func QueryNodeConsensusState(clientCtx client.Context) (*ibctmtypes.ConsensusSta return &ibctmtypes.ConsensusState{}, 0, err } - height := info.Response.LastBlockHeight + var height int64 + if clientCtx.Height != 0 { + height = clientCtx.Height + } else { + height = info.Response.LastBlockHeight + } commit, err := node.Commit(context.Background(), &height) if err != nil {