Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
3e35d61
add block sdk with default lane
colmazia Dec 24, 2024
738dabd
add feeds lanes for MsgSubmitSignalPrices
colmazia Dec 25, 2024
5805491
create band custom mempool
colmazia Feb 4, 2025
cecc2c7
refactor and add enforce one tx per signer option
colmazia Feb 7, 2025
057b778
integrate cosmos mempool to store tx in lane, add unit tests
colmazia Feb 14, 2025
2bd4894
Merge branch 'master' into add-block-lanes
colmazia Feb 17, 2025
ebb0f6e
implement tx verification by msgServer in lane insertion, use ignore …
colmazia Feb 18, 2025
335cbd7
Merge branch 'master' into add-block-lanes
colmazia Feb 20, 2025
70676de
use blockspace in all mempool package
colmazia Feb 20, 2025
6c873b0
cleanup print
colmazia Feb 20, 2025
f81df6c
use signer adapter from cosmos instead of block-sdk, add comments
colmazia Feb 20, 2025
e6e1995
add comment
colmazia Feb 20, 2025
ff957c3
use noop process proposal
colmazia Feb 26, 2025
0b1c9f7
Add separate lane for Oracle requests based on report limit dependency
Mar 18, 2025
3d10cf9
correct variables name and comment
Mar 24, 2025
9ae5286
fix double gas issue
colmazia Apr 2, 2025
3ab0082
add and delete comments
colmazia Apr 2, 2025
6ecd5f3
Merge branch 'master' into add-block-lanes
colmazia Apr 4, 2025
2b58d0d
fix from comments
colmazia Apr 4, 2025
9fc1a7b
make field in lane, proposal private
colmazia Apr 4, 2025
0c83958
fix from comments
colmazia Apr 4, 2025
40a7235
fix from comments
colmazia Apr 4, 2025
d07815f
fix from comments
colmazia Apr 8, 2025
936f975
Merge branch 'add-block-lanes' into fix-double-gas
colmazia Apr 8, 2025
c5f05af
fix test
colmazia Apr 8, 2025
fc693ac
Merge branch 'add-block-lanes' into fix-double-gas
colmazia Apr 8, 2025
4162d42
remove logic in lane match function to reduce gas used
colmazia Apr 8, 2025
82b228a
add context for matchFns option
colmazia Apr 8, 2025
aa598c7
fix matchFn names
colmazia Apr 8, 2025
497622f
Merge pull request #633 from bandprotocol/fix-double-gas
RogerKSI Apr 10, 2025
7c00830
Merge branch 'add-block-lanes' into add-armageddon
Apr 10, 2025
5e66f6a
fix typo
Apr 10, 2025
7f340d4
[Fix][Mempool] Fix invalid block sequence (#614)
Marca23 Apr 16, 2025
2ed34e2
fix comments
colmazia Apr 17, 2025
1c272b5
Merge branch 'add-block-lanes' into add-armageddon
Apr 18, 2025
136286c
add comments for mempool lanes
Apr 18, 2025
b84bf7e
fix comment
Apr 21, 2025
baf082d
add comment and refactor
Apr 22, 2025
0e49a39
refactor return order
Apr 22, 2025
ad929da
fix callbackAfterFillProposal comment
Apr 23, 2025
1424b9e
Merge pull request #613 from bandprotocol/add-armageddon
colmazia Apr 23, 2025
6ddcb3f
[Mempool] Add Readme (#650)
colmazia Apr 23, 2025
08e56e2
refactor lane and matchFn
taobun Apr 24, 2025
4aed982
remove cdc
taobun Apr 24, 2025
aa0f937
fix lanes.go
taobun Apr 24, 2025
fc3c6e6
fix import
taobun Apr 24, 2025
4256a93
rename fn and remove unused ctx
taobun Apr 24, 2025
5788d63
move tx size check logic to lane insert
colmazia Apr 24, 2025
a663941
add test for check in insert, add test for tx bytes
colmazia Apr 24, 2025
ca71a2f
Merge pull request #659 from bandprotocol/refactor-match-fn
colmazia Apr 24, 2025
c4d58f9
Merge branch 'add-block-lanes' into fix-tx-limit
colmazia Apr 24, 2025
402fe34
fix merge bug
colmazia Apr 24, 2025
f13a7b0
remove redundant test
colmazia Apr 24, 2025
3dd7737
fix from comments
colmazia Apr 25, 2025
724ead4
Merge pull request #660 from bandprotocol/fix-tx-limit
taobun Apr 25, 2025
6fcbae1
Merge branch 'master' into add-block-lanes
colmazia Apr 25, 2025
c07158d
Merge branch 'master' into add-block-lanes
colmazia Apr 25, 2025
23cf32d
Merge branch 'master' into add-block-lanes
colmazia Apr 29, 2025
3b0097b
fix from comments
colmazia May 8, 2025
20f84a7
Merge branch 'master' into add-block-lanes
colmazia May 8, 2025
775ed36
use safesub and remove colon
colmazia May 8, 2025
adfd332
change tx cap for tss to 5%
colmazia May 13, 2025
164c6a0
change from 20 to 10 (#687)
RogerKSI May 13, 2025
da5fdd1
fix comment
colmazia May 13, 2025
bae8fef
remove custom checktx
colmazia May 16, 2025
f25ffe7
fix from comments
colmazia May 16, 2025
1edd95f
update readme
colmazia May 16, 2025
037de4e
Merge branch 'master' into add-block-lanes
colmazia May 16, 2025
4eea271
adjust tx limit size for tss and report lanes
RogerKSI May 17, 2025
7570218
Merge branch 'master' of https://github.com/bandprotocol/chain into a…
RogerKSI May 18, 2025
c2f9455
fix from comments
colmazia May 19, 2025
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
77 changes: 57 additions & 20 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

"github.com/bandprotocol/chain/v3/app/mempool"
bandtsskeeper "github.com/bandprotocol/chain/v3/x/bandtss/keeper"
feedskeeper "github.com/bandprotocol/chain/v3/x/feeds/keeper"
"github.com/bandprotocol/chain/v3/x/globalfee/feechecker"
Expand All @@ -23,15 +24,16 @@ import (
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions
Cdc codec.Codec
AuthzKeeper *authzkeeper.Keeper
OracleKeeper *oraclekeeper.Keeper
IBCKeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
GlobalfeeKeeper *globalfeekeeper.Keeper
TSSKeeper *tsskeeper.Keeper
BandtssKeeper *bandtsskeeper.Keeper
FeedsKeeper *feedskeeper.Keeper
Cdc codec.Codec
AuthzKeeper *authzkeeper.Keeper
OracleKeeper *oraclekeeper.Keeper
IBCKeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
GlobalfeeKeeper *globalfeekeeper.Keeper
TSSKeeper *tsskeeper.Keeper
BandtssKeeper *bandtsskeeper.Keeper
FeedsKeeper *feedskeeper.Keeper
IgnoreDecoratorMatchFns []mempool.TxMatchFn
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand Down Expand Up @@ -79,14 +81,8 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

if options.TxFeeChecker == nil {
feeChecker := feechecker.NewFeeChecker(
options.Cdc,
options.AuthzKeeper,
options.OracleKeeper,
options.GlobalfeeKeeper,
options.StakingKeeper,
options.TSSKeeper,
options.BandtssKeeper,
options.FeedsKeeper,
)
options.TxFeeChecker = feeChecker.CheckTxFee
}
Expand All @@ -98,11 +94,14 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BankKeeper,
options.FeegrantKeeper,
options.TxFeeChecker,
NewIgnoreDecorator(
ante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BankKeeper,
options.FeegrantKeeper,
options.TxFeeChecker,
),
options.IgnoreDecoratorMatchFns...,
),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
Expand All @@ -115,3 +114,41 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

return sdk.ChainAnteDecorators(anteDecorators...), nil
}

// IgnoreDecorator is an AnteDecorator that wraps an existing AnteDecorator. It allows
// for the AnteDecorator to be ignored for specified lanes.
type IgnoreDecorator struct {
decorator sdk.AnteDecorator
matchFns []mempool.TxMatchFn
}

// NewIgnoreDecorator returns a new IgnoreDecorator instance.
func NewIgnoreDecorator(decorator sdk.AnteDecorator, matchFns ...mempool.TxMatchFn) *IgnoreDecorator {
return &IgnoreDecorator{
decorator: decorator,
matchFns: matchFns,
}
}

// NewIgnoreDecorator is a wrapper that implements the sdk.AnteDecorator interface,
// providing two execution paths for processing transactions:
// - If a transaction matches one of the designated bypass lanes, it is forwarded
// directly to the next AnteHandler.
// - Otherwise, the transaction is processed using the embedded decorator’s AnteHandler.
func (ig IgnoreDecorator) AnteHandle(
ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler,
) (sdk.Context, error) {
// IgnoreDecorator is only used for check tx and re-check tx.
if !ctx.IsCheckTx() && !ctx.IsReCheckTx() {
return ig.decorator.AnteHandle(ctx, tx, simulate, next)
}

cacheCtx, _ := ctx.CacheContext()
for _, matchFn := range ig.matchFns {
if matchFn(cacheCtx, tx) {
return next(ctx, tx, simulate)
}
}

return ig.decorator.AnteHandle(ctx, tx, simulate, next)
}
26 changes: 26 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/bandprotocol/chain/v3/app/keepers"
"github.com/bandprotocol/chain/v3/app/mempool"
"github.com/bandprotocol/chain/v3/app/upgrades"
v3 "github.com/bandprotocol/chain/v3/app/upgrades/v3"
v3_rc4 "github.com/bandprotocol/chain/v3/app/upgrades/v3_rc4"
nodeservice "github.com/bandprotocol/chain/v3/client/grpc/node"
proofservice "github.com/bandprotocol/chain/v3/client/grpc/oracle/proof"
feedskeeper "github.com/bandprotocol/chain/v3/x/feeds/keeper"
oraclekeeper "github.com/bandprotocol/chain/v3/x/oracle/keeper"
tsskeeper "github.com/bandprotocol/chain/v3/x/tss/keeper"
)

var (
Expand Down Expand Up @@ -254,11 +257,22 @@ func NewBandApp(

app.sm.RegisterStoreDecoders()

lanes := CreateLanes(app)

// create Band mempool
bandMempool := mempool.NewMempool(app.Logger(), lanes)
// set the mempool
app.SetMempool(bandMempool)

// Initialize stores.
app.MountKVStores(app.GetKVStoreKey())
app.MountTransientStores(app.GetTransientStoreKey())
app.MountMemoryStores(app.GetMemoryStoreKey())

feedsMsgServer := feedskeeper.NewMsgServerImpl(app.FeedsKeeper)
tssMsgServer := tsskeeper.NewMsgServerImpl(app.TSSKeeper)
oracleMsgServer := oraclekeeper.NewMsgServerImpl(app.OracleKeeper)

anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand All @@ -277,12 +291,24 @@ func NewBandApp(
IBCKeeper: app.IBCKeeper,
StakingKeeper: app.StakingKeeper,
GlobalfeeKeeper: &app.GlobalFeeKeeper,
IgnoreDecoratorMatchFns: []mempool.TxMatchFn{
feedsSubmitSignalPriceTxMatchHandler(app.appCodec, &app.AuthzKeeper, feedsMsgServer),
tssTxMatchHandler(app.appCodec, &app.AuthzKeeper, &app.BandtssKeeper, tssMsgServer),
oracleReportTxMatchHandler(app.appCodec, &app.AuthzKeeper, oracleMsgServer),
},
},
)
if err != nil {
panic(fmt.Errorf("failed to create ante handler: %s", err))
}

// proposal handler
proposalHandler := mempool.NewProposalHandler(app.Logger(), txConfig.TxDecoder(), bandMempool)

// set the Prepare / ProcessProposal Handlers on the app to be the `LanedMempool`'s
app.SetPrepareProposal(proposalHandler.PrepareProposalHandler())
app.SetProcessProposal(proposalHandler.ProcessProposalHandler())

postHandler, err := NewPostHandler(
PostHandlerOptions{},
)
Expand Down
113 changes: 113 additions & 0 deletions app/lanes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package band

import (
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"

"github.com/bandprotocol/chain/v3/app/mempool"
feedstypes "github.com/bandprotocol/chain/v3/x/feeds/types"
oracletypes "github.com/bandprotocol/chain/v3/x/oracle/types"
tsstypes "github.com/bandprotocol/chain/v3/x/tss/types"
)

// DefaultLaneMatchHandler is a function that returns the match function for the default lane.
func DefaultLaneMatchHandler() mempool.TxMatchFn {
return func(_ sdk.Context, _ sdk.Tx) bool {
return true
}
}

// CreateLanes creates the lanes for the Band mempool.
func CreateLanes(app *BandApp) []*mempool.Lane {
// feedsLane handles feeds submit signal price transactions.
// Each transaction has a gas limit of 2%, and the total gas limit for the lane is 50%.
// It uses SenderNonceMempool to ensure transactions are ordered by sender and nonce, with no per-sender tx limit.
feedsLane := mempool.NewLane(
app.Logger(),
app.txConfig.TxEncoder(),
"feedsLane",
mempool.NewLaneTxMatchFn([]sdk.Msg{&feedstypes.MsgSubmitSignalPrices{}}, true),
math.LegacyMustNewDecFromStr("0.02"),
math.LegacyMustNewDecFromStr("0.5"),
sdkmempool.NewSenderNonceMempool(sdkmempool.SenderNonceMaxTxOpt(0)),
nil,
)

// tssLane handles TSS transactions.
// Each transaction has a gas limit of 10%, and the total gas limit for the lane is 20%.
tssLane := mempool.NewLane(
app.Logger(),
app.txConfig.TxEncoder(),
"tssLane",
mempool.NewLaneTxMatchFn(
[]sdk.Msg{
&tsstypes.MsgSubmitDKGRound1{},
&tsstypes.MsgSubmitDKGRound2{},
&tsstypes.MsgConfirm{},
&tsstypes.MsgComplain{},
&tsstypes.MsgSubmitDEs{},
&tsstypes.MsgSubmitSignature{},
},
true,
),
math.LegacyMustNewDecFromStr("0.1"),
math.LegacyMustNewDecFromStr("0.2"),
sdkmempool.DefaultPriorityMempool(),
nil,
)

// oracleRequestLane handles oracle request data transactions.
// Each transaction has a gas limit of 10%, and the total gas limit for the lane is 10%.
// It is blocked if the oracle report lane exceeds its limit.
oracleRequestLane := mempool.NewLane(
app.Logger(),
app.txConfig.TxEncoder(),
"oracleRequestLane",
mempool.NewLaneTxMatchFn(
[]sdk.Msg{
&oracletypes.MsgRequestData{},
&channeltypes.MsgRecvPacket{}, // TODO: Only match oracle request packet
},
false,
),
math.LegacyMustNewDecFromStr("0.1"),
math.LegacyMustNewDecFromStr("0.1"),
sdkmempool.DefaultPriorityMempool(),
nil,
)

// oracleReportLane handles oracle report data transactions.
// Each transaction has a gas limit of 10%, and the total gas limit for the lane is 20%.
// It block the oracle request lane if it exceeds its limit.
oracleReportLane := mempool.NewLane(
app.Logger(),
app.txConfig.TxEncoder(),
"oracleReportLane",
mempool.NewLaneTxMatchFn([]sdk.Msg{&oracletypes.MsgReportData{}}, true),
math.LegacyMustNewDecFromStr("0.1"),
math.LegacyMustNewDecFromStr("0.2"),
sdkmempool.DefaultPriorityMempool(),
func(isLaneLimitExceeded bool) {
oracleRequestLane.SetBlocked(isLaneLimitExceeded)
},
)

// defaultLane handles all other transactions.
// Each transaction has a gas limit of 10%, and the total gas limit for the lane is 10%.
defaultLane := mempool.NewLane(
app.Logger(),
app.txConfig.TxEncoder(),
"defaultLane",
DefaultLaneMatchHandler(),
math.LegacyMustNewDecFromStr("0.1"),
math.LegacyMustNewDecFromStr("0.1"),
sdkmempool.DefaultPriorityMempool(),
nil,
)

return []*mempool.Lane{feedsLane, tssLane, oracleReportLane, oracleRequestLane, defaultLane}
}
Loading
Loading