Fix ConsensusStates grpc query (#8246)

* fix consensus states grpc query

* Update x/ibc/core/02-client/keeper/grpc_query.go

* simplify
This commit is contained in:
Aditya 2021-01-04 15:03:11 +00:00 committed by GitHub
parent 6a9b0caa57
commit f67eac6840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -157,19 +157,24 @@ func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStat
consensusStates := []types.ConsensusStateWithHeight{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix))))
pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
// filter any metadata stored under consensus state key
if strings.Contains(string(key), "/") {
return false, nil
}
height, err := types.ParseHeight(string(key))
if err != nil {
return err
return false, err
}
consensusState, err := q.UnmarshalConsensusState(value)
if err != nil {
return err
return false, err
}
consensusStates = append(consensusStates, types.NewConsensusStateWithHeight(height, consensusState))
return nil
return true, nil
})
if err != nil {

View File

@ -315,8 +315,14 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() {
suite.consensusState.Timestamp.Add(time.Second), commitmenttypes.NewMerkleRoot([]byte("hash2")), nil,
)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, cs)
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight.Increment(), cs2)
clientState := ibctmtypes.NewClientState(
testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, testClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false,
)
// Use CreateClient to ensure that processedTime metadata gets stored.
clientId, err := suite.keeper.CreateClient(suite.ctx, clientState, cs)
suite.Require().NoError(err)
suite.keeper.SetClientConsensusState(suite.ctx, clientId, testClientHeight.Increment(), cs2)
// order is swapped because the res is sorted by client id
expConsensusStates = []types.ConsensusStateWithHeight{
@ -324,7 +330,7 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() {
types.NewConsensusStateWithHeight(testClientHeight.Increment().(types.Height), cs2),
}
req = &types.QueryConsensusStatesRequest{
ClientId: testClientID,
ClientId: clientId,
Pagination: &query.PageRequest{
Limit: 3,
CountTotal: true,