Skip to content

Commit

Permalink
imp: add flat fee for queries to VerifyMembership (#5927) (#6108)
Browse files Browse the repository at this point in the history
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
(cherry picked from commit 9aa7151)

# Conflicts:
#	modules/core/02-client/keeper/grpc_query.go

Co-authored-by: Charly <charly@interchain.io>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
  • Loading branch information
4 people committed Apr 8, 2024
1 parent 23ad7a5 commit b7077b3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func (k Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMember
}

ctx := sdk.UnwrapSDKContext(c)

// cache the context to ensure clientState.VerifyMembership does not change state
cachedCtx, _ := ctx.CacheContext()

Expand All @@ -386,6 +387,13 @@ func (k Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMember
return nil, status.Error(codes.FailedPrecondition, errorsmod.Wrapf(types.ErrClientNotActive, "cannot verify membership using client (%s) with status %s", req.ClientId, clientStatus).Error())
}

// consume flat gas fee for proof verification queries.
// NOTE: consuming gas prior to method invocation also provides protection against recursive calls reaching stack overflow
ctx.GasMeter().ConsumeGas(
3*ctx.KVGasConfig().ReadCostPerByte*uint64(len(req.Proof)),
"verify membership query",
)

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

0 comments on commit b7077b3

Please sign in to comment.