-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom priority mempool (#2152)
- fork custom priority mempool from cosmos-sdk 0.47 - adapt to support ethermint txs
- Loading branch information
Showing
11 changed files
with
922 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.