Skip to content

Commit

Permalink
chore: add client status check to verify membership rpc (cosmos#5870)
Browse files Browse the repository at this point in the history
* chore: add client status check to verify membership rpc

* Update modules/core/02-client/keeper/grpc_query.go

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>

---------

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
  • Loading branch information
damiannolan and DimitrisJim committed Feb 20, 2024
1 parent 72e2b6b commit 94a4597
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ func (k Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMember
return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrClientNotFound, req.ClientId).Error())
}

if clientStatus := k.GetClientStatus(ctx, clientState, req.ClientId); clientStatus != exported.Active {
return nil, status.Error(codes.FailedPrecondition, errorsmod.Wrapf(types.ErrClientNotActive, "cannot verify membership using client (%s) with status %s", req.ClientId, clientStatus).Error())
}

if err := clientState.VerifyMembership(cachedCtx, k.ClientStore(cachedCtx, req.ClientId), k.cdc, req.ProofHeight, req.TimeDelay, req.BlockDelay, req.Proof, req.MerklePath, req.Value); err != nil {
k.Logger(ctx).Debug("proof verification failed", "key", req.MerklePath, "error", err)
return &types.QueryVerifyMembershipResponse{
Expand Down
16 changes: 16 additions & 0 deletions modules/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,22 @@ func (suite *KeeperTestSuite) TestQueryVerifyMembershipProof() {
},
types.ErrClientNotFound,
},
{
"client not active",
func() {
params := types.NewParams("") // disable all clients
suite.chainA.GetSimApp().GetIBCKeeper().ClientKeeper.SetParams(suite.chainA.GetContext(), params)

req = &types.QueryVerifyMembershipRequest{
ClientId: path.EndpointA.ClientID,
Proof: []byte{0x01},
ProofHeight: types.NewHeight(1, 100),
MerklePath: commitmenttypes.NewMerklePath("/ibc", host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)),
Value: []byte{0x01},
}
},
types.ErrClientNotActive,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 94a4597

Please sign in to comment.