Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Oct 2, 2024
1 parent 2e07d93 commit 333b02c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions x/finality/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"time"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

storetypes "cosmossdk.io/store/types"
bbn "github.com/babylonlabs-io/babylon/types"
bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
"github.com/babylonlabs-io/babylon/x/finality/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

type msgServer struct {
Expand Down Expand Up @@ -51,6 +51,23 @@ func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinal

ctx := sdk.UnwrapSDKContext(goCtx)

refundable := false

gasMeter := ctx.GasMeter()
cacheGasMeter := storetypes.NewInfiniteGasMeter()
ctx = ctx.WithGasMeter(cacheGasMeter)

defer func() {
// reset gas meter
ctx = ctx.WithGasMeter(gasMeter)
// consume gas if not refundable
// NOTE: the gas only includes the cost during the message handler,
// but not the cost during the AnteHandlers
if !refundable {
gasMeter.ConsumeGas(cacheGasMeter.GasConsumed(), "consume gas for non-refundable finality signature")
}
}()

if req.FpBtcPk == nil {
return nil, types.ErrInvalidFinalitySig.Wrap("empty finality provider BTC PK")
}
Expand Down Expand Up @@ -177,8 +194,7 @@ func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinal
ms.slashFinalityProvider(ctx, req.FpBtcPk, evidence)
}

gasMeter := ctx.GasMeter()
gasMeter.RefundGas(gasMeter.GasConsumed(), "refund gas for submitting finality signatures successfully")
refundable = true

return &types.MsgAddFinalitySigResponse{}, nil
}
Expand Down

0 comments on commit 333b02c

Please sign in to comment.