Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ type HandlerOptions struct {
TracingInfo *tracing.Info
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk.AnteDepGenerator, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if options.WasmConfig == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}
if options.TXCounterStoreKey == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}
if options.OracleKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder")
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder")
}
if options.TracingInfo == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tracing info is required for ante builder")
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tracing info is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
Expand All @@ -66,29 +66,31 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
// sigVerifyDecorator = ante.NewBatchSigVerificationDecorator(options.BatchVerifier, sequentialVerifyDecorator)
// }

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
anteDecorators := []sdk.AnteFullDecorator{
sdk.DefaultWrappedAnteDecorator(ante.NewSetUpContextDecorator()), // outermost AnteDecorator. SetUpContext must be called first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - could probably create a function for this i.e. wrapDecorator(decs []Decorator) ([]WrappedDecorator, err)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to explicitly wrap each ante handler, because otherwise future changes may change order of the antehandlers without properly changing the order of dependency generators, and that could potentially result in unintended behavior

// TODO: have dex antehandler separate, and then call the individual antehandlers FROM the gasless antehandler decorator wrapper
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
ante.NewRejectExtensionOptionsDecorator(),
oracle.NewSpammingPreventionDecorator(*options.OracleKeeper),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit)), // after setup context to enforce limits early
sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey)),
sdk.DefaultWrappedAnteDecorator(ante.NewRejectExtensionOptionsDecorator()),
sdk.DefaultWrappedAnteDecorator(oracle.NewSpammingPreventionDecorator(*options.OracleKeeper)),
sdk.DefaultWrappedAnteDecorator(ante.NewValidateBasicDecorator()),
sdk.DefaultWrappedAnteDecorator(ante.NewTxTimeoutHeightDecorator()),
sdk.DefaultWrappedAnteDecorator(ante.NewValidateMemoDecorator(options.AccountKeeper)),
sdk.DefaultWrappedAnteDecorator(ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper)),
sdk.DefaultWrappedAnteDecorator(ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker)),
// PriorityDecorator must be called after DeductFeeDecorator which sets tx priority based on tx fees
antedecorators.NewPriorityDecorator(),
sdk.DefaultWrappedAnteDecorator(antedecorators.NewPriorityDecorator()),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
sequentialVerifyDecorator,
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
dex.NewTickSizeMultipleDecorator(*options.DexKeeper),
sdk.DefaultWrappedAnteDecorator(ante.NewSetPubKeyDecorator(options.AccountKeeper)),
sdk.DefaultWrappedAnteDecorator(ante.NewValidateSigCountDecorator(options.AccountKeeper)),
sdk.DefaultWrappedAnteDecorator(ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer)),
sdk.DefaultWrappedAnteDecorator(sequentialVerifyDecorator),
sdk.DefaultWrappedAnteDecorator(ante.NewIncrementSequenceDecorator(options.AccountKeeper)),
sdk.DefaultWrappedAnteDecorator(ibcante.NewAnteDecorator(options.IBCKeeper)),
sdk.DefaultWrappedAnteDecorator(dex.NewTickSizeMultipleDecorator(*options.DexKeeper)),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
anteHandler, anteDepGenerator := sdk.ChainAnteDecorators(anteDecorators...)

return anteHandler, anteDepGenerator, nil
}
10 changes: 5 additions & 5 deletions app/antedecorators/gasless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func (tx FakeTx) ValidateBasic() error {

func TestGaslessDecorator(t *testing.T) {
output = ""
anteDecorators := []sdk.AnteDecorator{
FakeAnteDecoratorOne{},
antedecorators.NewGaslessDecorator([]sdk.AnteDecorator{FakeAnteDecoratorTwo{}}, oraclekeeper.Keeper{}),
FakeAnteDecoratorThree{},
anteDecorators := []sdk.AnteFullDecorator{
sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorOne{}),
sdk.DefaultWrappedAnteDecorator(antedecorators.NewGaslessDecorator([]sdk.AnteDecorator{FakeAnteDecoratorTwo{}}, oraclekeeper.Keeper{})),
sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorThree{}),
}
chainedHandler := sdk.ChainAnteDecorators(anteDecorators...)
chainedHandler, _ := sdk.ChainAnteDecorators(anteDecorators...)
chainedHandler(sdk.Context{}, FakeTx{}, false)
require.Equal(t, "onetwothree", output)
}
14 changes: 7 additions & 7 deletions app/antedecorators/traced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (

func TestTracedDecorator(t *testing.T) {
output = ""
anteDecorators := []sdk.AnteDecorator{
FakeAnteDecoratorOne{},
FakeAnteDecoratorTwo{},
FakeAnteDecoratorThree{},
anteDecorators := []sdk.AnteFullDecorator{
sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorOne{}),
sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorTwo{}),
sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorThree{}),
}
tracedDecorators := utils.Map(anteDecorators, func(d sdk.AnteDecorator) sdk.AnteDecorator {
return antedecorators.NewTracedAnteDecorator(d, nil)
tracedDecorators := utils.Map(anteDecorators, func(d sdk.AnteFullDecorator) sdk.AnteFullDecorator {
return sdk.DefaultWrappedAnteDecorator(antedecorators.NewTracedAnteDecorator(d, nil))
})
chainedHandler := sdk.ChainAnteDecorators(tracedDecorators...)
chainedHandler, _ := sdk.ChainAnteDecorators(tracedDecorators...)
chainedHandler(sdk.Context{}, FakeTx{}, false)
require.Equal(t, "onetwothree", output)
}
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func New(
signModeHandler := encodingConfig.TxConfig.SignModeHandler()
// app.batchVerifier = ante.NewSR25519BatchVerifier(app.AccountKeeper, signModeHandler)

anteHandler, err := NewAnteHandler(
anteHandler, anteDepGenerator, err := NewAnteHandlerAndDepGenerator(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
Expand All @@ -755,6 +755,7 @@ func New(
}

app.SetAnteHandler(anteHandler)
app.SetAnteDepGenerator(anteDepGenerator)
app.SetEndBlocker(app.EndBlocker)
app.SetPrepareProposalHandler(app.PrepareProposalHandler)
app.SetProcessProposalHandler(app.ProcessProposalHandler)
Expand Down Expand Up @@ -1077,7 +1078,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
// }
// app.batchVerifier.VerifyTxs(ctx, typedTxs)

dependencyDag, err := app.AccessControlKeeper.BuildDependencyDag(ctx, app.txDecoder, txs)
dependencyDag, err := app.AccessControlKeeper.BuildDependencyDag(ctx, app.txDecoder, app.GetAnteDepGenerator(), txs)
var txResults []*abci.ExecTxResult

switch err {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.105
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.114
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.1.59
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/sei-cosmos v0.1.105 h1:45l/ZNaYrdyU87TNijE1OIciYI4wb3PXd95qr1HPAgE=
github.com/sei-protocol/sei-cosmos v0.1.105/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0=
github.com/sei-protocol/sei-cosmos v0.1.114 h1:Cy5MnBdvql5VJw5pC104DsivQxPg0xkvVOuq6VwDiRk=
github.com/sei-protocol/sei-cosmos v0.1.114/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0=
github.com/sei-protocol/sei-tendermint v0.1.59 h1:POGL60PumMQHF4EzAHzvkGfDnodQJLHpl65LuiwSO/Y=
github.com/sei-protocol/sei-tendermint v0.1.59/go.mod h1:Olwbjyagrpoxj5DAUhHxMTWDVEfQ3FYdpypaJ3+6Hs8=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down