Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom priority mempool #2152

Merged
merged 14 commits into from
May 14, 2024
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- name: Run Gosec Security Scanner
if: ${{ github.event.inputs.skip_checks != 'true' }}
uses: securego/gosec@master
uses: securego/gosec@v2.19.0
with:
args: ./...

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sast-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
go-version: '1.20'

- name: Run Gosec Security Scanner
uses: securego/gosec@master
uses: securego/gosec@v2.19.0
with:
args: ./...

Expand Down
1 change: 1 addition & 0 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func newCosmosAnteHandlerForSystemTx(options HandlerOptions) sdk.AnteHandler {
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
NewSystemPriorityDecorator(),
skosito marked this conversation as resolved.
Show resolved Hide resolved
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
29 changes: 29 additions & 0 deletions app/ante/system_tx_priority_decorator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ante

import (
"math"

sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ sdk.AnteDecorator = SystemPriorityDecorator{}

// SystemPriorityDecorator adds bigger priority for system messages
type SystemPriorityDecorator struct {
}

// NewSystemPriorityDecorator creates a decorator to add bigger priority for system messages
func NewSystemPriorityDecorator() SystemPriorityDecorator {
return SystemPriorityDecorator{}
}

// AnteHandle implements AnteDecorator
func (vad SystemPriorityDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (sdk.Context, error) {
newCtx := ctx.WithPriority(math.MaxInt64)
return next(newCtx, tx, simulate)
}
45 changes: 45 additions & 0 deletions app/ante/system_tx_priority_decorator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ante_test

import (
"math"
"math/rand"
"testing"
"time"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/app/ante"
"github.com/zeta-chain/zetacore/testutil/sample"
)

func TestSystemTxPriorityDecorator_AnteHandle(t *testing.T) {
txConfig := app.MakeEncodingConfig().TxConfig

testPrivKey, _ := sample.PrivKeyAddressPair()

decorator := ante.NewSystemPriorityDecorator()
mmd := MockAnteHandler{}
// set priority to 10 before ante handler
ctx := sdk.Context{}.WithIsCheckTx(true).WithPriority(10)

tx, err := simtestutil.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txConfig,
[]sdk.Msg{},
sdk.NewCoins(),
simtestutil.DefaultGenTxGas,
"testing-chain-id",
[]uint64{0},
[]uint64{0},
testPrivKey,
)
require.NoError(t, err)
ctx, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
require.NoError(t, err)

// check that priority is set to max int64
priorityAfter := ctx.Priority()
require.Equal(t, math.MaxInt64, int(priorityAfter))
}
4 changes: 4 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func New(
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(encodingConfig.TxConfig.TxEncoder())
skosito marked this conversation as resolved.
Show resolved Hide resolved

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey,
Expand Down Expand Up @@ -385,6 +386,9 @@ func New(
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authAddr)
bApp.SetParamStore(&app.ConsensusParamsKeeper)

customProposalHandler := NewCustomProposalHandler(bApp.Mempool(), bApp)
skosito marked this conversation as resolved.
Show resolved Hide resolved
app.SetPrepareProposal(customProposalHandler.PrepareProposalHandler())

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(
appCodec,
Expand Down
Loading
Loading