-
Notifications
You must be signed in to change notification settings - Fork 0
/
gas.go
43 lines (37 loc) · 1.61 KB
/
gas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ante
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furyanprotocol/v4-chain/protocol/app/ante/types"
libante "github.com/furyanprotocol/v4-chain/protocol/lib/ante"
clobante "github.com/furyanprotocol/v4-chain/protocol/x/clob/ante"
)
// FreeInfiniteGasDecorator is an AnteHandler that sets `GasMeter` to
// `FreeInfiniteGasMeter` for off-chain single clob msg transactions, and app-injected transactions.
// These transactions should not use any gas, and the sender should not be charged any gas.
// Using this meter means gas will never be consumed for these transactions.
// Also note that not explicitly setting a `gasMeter` means that the `gasMeter` from the previous transaction
// or from `BeginBlock` will be used. Not doing this could result in consensus failure as demonstrated in #869.
// Cosmos SDK expects an explicit call to `WithGasMeter` at the beginning of the AnteHandler chain.
type FreeInfiniteGasDecorator struct {
}
func NewFreeInfiniteGasDecorator() FreeInfiniteGasDecorator {
return FreeInfiniteGasDecorator{}
}
func (dec FreeInfiniteGasDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
isSingleClobMsgTx, err := clobante.IsSingleClobMsgTx(ctx, tx)
if err != nil {
return ctx, err
}
// If this is a single clob msg tx, or a single app-injected msg tx, then set the gas meter to
// FreeInfiniteGasMeter.
if isSingleClobMsgTx || libante.IsSingleAppInjectedMsg(tx.GetMsgs()) {
newCtx = ctx.WithGasMeter(types.NewFreeInfiniteGasMeter())
return next(newCtx, tx, simulate)
}
return next(ctx, tx, simulate)
}