From 7ea6b2c5e66a19565141f4105b2d42eb12b25fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 24 Sep 2020 08:53:30 +0200 Subject: [PATCH] Update QueryTendermint to take in tendermint height (#7337) * Update QueryTendermint to take in tendermint height Update QueryTendermint to subtract the provided height by one to query at the IAVL height. * Update x/ibc/client/query.go Co-authored-by: Christopher Goes * update height check to > 2 Update height check to ensure that the client context height is greater than two before decrementing. Queries at height 0 and 1 are not expected to succeed. Documentation was updated to reflect this reasoning * update query to return error for height <= 2 Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Christopher Goes Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- x/ibc/client/query.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/x/ibc/client/query.go b/x/ibc/client/query.go index c55d1e287e..961f8fac88 100644 --- a/x/ibc/client/query.go +++ b/x/ibc/client/query.go @@ -12,16 +12,32 @@ import ( host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) -// QueryTendermintProof performs an ABCI query with the given key and returns the value -// of the query, the proto encoded merkle proof for the query and the height -// at which the proof will succeed on a tendermint verifier (one above the -// returned IAVL version height). +// QueryTendermintProof performs an ABCI query with the given key and returns +// the value of the query, the proto encoded merkle proof, and the height of +// the Tendermint block containing the state root. The desired tendermint height +// to perform the query should be set in the client context. The query will be +// performed at one below this height (at the IAVL version) in order to obtain +// the correct merkle proof. Proof queries at height less than or equal to 2 are +// not supported. // Issue: https://github.com/cosmos/cosmos-sdk/issues/6567 func QueryTendermintProof(clientCtx client.Context, key []byte) ([]byte, []byte, clienttypes.Height, error) { + height := clientCtx.Height + + // ABCI queries at height less than or equal to 2 are not supported. + // Base app does not support queries for height less than or equal to 1. + // Therefore, a query at height 2 would be equivalent to a query at height 3 + if clientCtx.Height <= 2 { + return nil, nil, clienttypes.Height{}, fmt.Errorf("proof queries at height <= 2 are not supported") + } + + // Use the IAVL height if a valid tendermint height is passed in. + height-- + req := abci.RequestQuery{ - Path: fmt.Sprintf("store/%s/key", host.StoreKey), - Data: key, - Prove: true, + Path: fmt.Sprintf("store/%s/key", host.StoreKey), + Height: height, + Data: key, + Prove: true, } res, err := clientCtx.QueryABCI(req)