mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-23 23:05:18 +00:00
add antehandler to app
This commit is contained in:
parent
2ab6c4669f
commit
54c2e44a2d
31
app/app.go
31
app/app.go
@ -4,11 +4,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/kava-labs/kava/x/auction"
|
||||
"github.com/kava-labs/kava/x/cdp"
|
||||
"github.com/kava-labs/kava/x/pricefeed"
|
||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
@ -32,6 +27,13 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||
|
||||
"github.com/kava-labs/kava/x/auction"
|
||||
"github.com/kava-labs/kava/x/cdp"
|
||||
"github.com/kava-labs/kava/x/pricefeed"
|
||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
||||
shutdownAnte "github.com/kava-labs/kava/x/shutdown/ante"
|
||||
"github.com/kava-labs/kava/x/shutdown"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -319,7 +321,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
|
||||
// initialize the app
|
||||
app.SetInitChainer(app.InitChainer)
|
||||
app.SetBeginBlocker(app.BeginBlocker)
|
||||
app.SetAnteHandler(auth.NewAnteHandler(app.accountKeeper, app.supplyKeeper, auth.DefaultSigVerificationGasConsumer))
|
||||
app.SetAnteHandler(NewAnteHandler(app.accountKeeper, app.supplyKeeper, app.shutdownKeeper, auth.DefaultSigVerificationGasConsumer))
|
||||
app.SetEndBlocker(app.EndBlocker)
|
||||
|
||||
// load store
|
||||
@ -333,6 +335,23 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
|
||||
return app
|
||||
}
|
||||
|
||||
func NewAnteHandler(ak auth.AccountKeeper, supplyKeeper supply.SupplyKeeper, shutdownKeeper shutdown.Keeper, sigGasConsumer SignatureVerificationGasConsumer) sdk.AnteHandler {
|
||||
return sdk.ChainAnteDecorators(
|
||||
auth.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
|
||||
shutdownAnte.NewDisableMsgDecorator(shutdownKeeper)
|
||||
auth.NewMempoolFeeDecorator(),
|
||||
auth.NewValidateBasicDecorator(),
|
||||
auth.NewValidateMemoDecorator(ak),
|
||||
auth.NewConsumeGasForTxSizeDecorator(ak),
|
||||
auth.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
|
||||
auth.NewValidateSigCountDecorator(ak),
|
||||
auth.NewDeductFeeDecorator(ak, supplyKeeper),
|
||||
auth.NewSigGasConsumeDecorator(ak, sigGasConsumer),
|
||||
auth.NewSigVerificationDecorator(ak),
|
||||
auth.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator
|
||||
)
|
||||
}
|
||||
|
||||
// custom tx codec
|
||||
func MakeCodec() *codec.Codec {
|
||||
var cdc = codec.New()
|
||||
|
@ -15,7 +15,7 @@ Members vote on proposals, with just simple one vote per member, no deposits or
|
||||
|
||||
A permission acts as a filter for incoming gov proposals, rejecting them if they do not pass. A permission can be anything with a method `Allows(p Proposal) bool`. They reject all proposals that they don't explicitly allow.
|
||||
|
||||
This allows permissions to be parameterized to allow fine grained control specified at runtime. For example a generic parameter permission type can exist, but then on a live chain a permission can be added to a group to allow them to only change a particular param, even restricting the range of allowed change.
|
||||
This allows permissions to be parameterized to allow fine grained control specified at runtime. For example a generic parameter permission type can allow a group to only change a particular param, or only change params within a certain percentage.
|
||||
|
||||
Design Alternatives
|
||||
|
||||
|
@ -8,30 +8,28 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// CircuitBreakerDecorator needs to be combined with other standard decorators (from auth) to create the app's AnteHandler.
|
||||
|
||||
// CircuitBreakerDecorator errors if a tx contains a disallowed msg type
|
||||
// Call next AnteHandler if all msgs are allowed
|
||||
type CircuitBreakerDecorator struct {
|
||||
cbk keeper.Keeper
|
||||
// DisableMsgDecorator errors if a tx contains a disallowed msg type and calls the next AnteHandler if all msgs are allowed
|
||||
type DisableMsgDecorator struct {
|
||||
shutdownKeeper keeper.Keeper
|
||||
}
|
||||
|
||||
func NewCircuitBreakerDecorator(cbk keeper.Keeper) CircuitBreakerDecorator {
|
||||
return CircuitBreakerDecorator{
|
||||
cbk: cbk,
|
||||
func NewDisableMsgDecorator(shutdownKeeper keeper.Keeper) DisableMsgDecorator {
|
||||
return DisableMsgDecorator{
|
||||
shutdownKeeper: shutdownKeeper,
|
||||
}
|
||||
}
|
||||
|
||||
func (cbd CircuitBreakerDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
||||
func (dmd DisableMsgDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
||||
|
||||
// get msg route, error if not allowed
|
||||
disallowedRoutes := cbd.cbk.GetMsgRoutes(ctx)
|
||||
disallowedRoutes := dmd.shutdownKeeper.GetMsgRoutes(ctx)
|
||||
for _, m := range tx.GetMsgs() {
|
||||
for _, r := range disallowedRoutes {
|
||||
if r.Route == m.Route() && r.Msg == m.Type() {
|
||||
return ctx, fmt.Errorf("route %s has been circuit broken, tx rejected", r)
|
||||
return ctx, fmt.Errorf("route %s has been disabled, tx rejected", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
// otherwise continue to next antehandler decorator
|
||||
return next(ctx, tx, simulate)
|
||||
}
|
||||
|
@ -14,5 +14,5 @@ The list of disallowed msg types is updated via a custom governance proposal and
|
||||
|
||||
Design Alternatives:
|
||||
|
||||
- store list of disallowed msg types in params, then don't need custom gov proposal
|
||||
- store list of disallowed msg types in params, then we don't need the custom gov proposal
|
||||
- replace the app Router with a custom one to avoid using the antehandler - can't be done with current baseapp, but v0.38.x enables this. (https://github.com/cosmos/cosmos-sdk/issues/5455)
|
Loading…
Reference in New Issue
Block a user