fix: Make lanes mutually exclusive by default (#206)
* lanes always mutually exclusive * nit 1.0.0.0 * gg adding back interface --------- Co-authored-by: Alex Johnson <alex@skip.money>
This commit is contained in:
co-authored by
Alex Johnson
parent
f1beb215f7
commit
f607439637
@@ -128,6 +128,10 @@ func (l *BaseLane) Match(ctx sdk.Context, tx sdk.Tx) bool {
|
||||
// list is utilized to prevent transactions that should be considered in other lanes
|
||||
// from being considered from this lane.
|
||||
func (l *BaseLane) CheckIgnoreList(ctx sdk.Context, tx sdk.Tx) bool {
|
||||
if l.cfg.IgnoreList == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, lane := range l.cfg.IgnoreList {
|
||||
if lane.Match(ctx, tx) {
|
||||
return true
|
||||
@@ -148,6 +152,12 @@ func (l *BaseLane) SetIgnoreList(lanes []block.Lane) {
|
||||
l.cfg.IgnoreList = lanes
|
||||
}
|
||||
|
||||
// GetIgnoreList returns the ignore list for the lane. The ignore list is a list
|
||||
// of lanes that the lane should ignore when processing transactions.
|
||||
func (l *BaseLane) GetIgnoreList() []block.Lane {
|
||||
return l.cfg.IgnoreList
|
||||
}
|
||||
|
||||
// SetAnteHandler sets the ante handler for the lane.
|
||||
func (l *BaseLane) SetAnteHandler(anteHandler sdk.AnteHandler) {
|
||||
l.cfg.AnteHandler = anteHandler
|
||||
|
||||
@@ -69,6 +69,9 @@ type Lane interface {
|
||||
// SetIgnoreList sets the lanes that should be ignored by this lane.
|
||||
SetIgnoreList(ignoreList []Lane)
|
||||
|
||||
// GetIgnoreList returns the lanes that should be ignored by this lane.
|
||||
GetIgnoreList() []Lane
|
||||
|
||||
// Match determines if a transaction belongs to this lane.
|
||||
Match(ctx sdk.Context, tx sdk.Tx) bool
|
||||
}
|
||||
|
||||
+118
-98
@@ -3,7 +3,6 @@ package block
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/math"
|
||||
@@ -13,6 +12,12 @@ import (
|
||||
blocksdkmoduletypes "github.com/skip-mev/block-sdk/x/blocksdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultLaneName is the default lane name. We enforce that a lane with the name
|
||||
// "default" is provided when constructing the mempool.
|
||||
DefaultLaneName = "default"
|
||||
)
|
||||
|
||||
var _ Mempool = (*LanedMempool)(nil)
|
||||
|
||||
// LaneFetcher defines the interface to get a lane stored in the x/blocksdk module.
|
||||
@@ -53,19 +58,65 @@ type (
|
||||
)
|
||||
|
||||
// NewLanedMempool returns a new Block SDK LanedMempool. The laned mempool comprises
|
||||
// a registry of lanes. Each lane is responsible for selecting transactions according
|
||||
// to its own selection logic. The lanes are ordered according to their priority. The
|
||||
// first lane in the registry has the highest priority. Proposals are verified according
|
||||
// to the order of the lanes in the registry. Each transaction SHOULD only belong in one lane.
|
||||
// To enforce that transactions only belong to one lane, each lane has an ignore list.
|
||||
//
|
||||
// a registry of lanes. Each lane is responsible for selecting
|
||||
// For example, say we have three lanes, MEV, default, and free. The ignore list of each
|
||||
// lane will look like the following:
|
||||
// - MEV: free
|
||||
// - default: MEV, free
|
||||
// - free: MEV.
|
||||
//
|
||||
// transactions according to its own selection logic. The lanes are ordered
|
||||
// according to their priority. The first lane in the registry has the highest
|
||||
// priority. Proposals are verified according to the order of the lanes in the
|
||||
// registry. Each transaction should only belong in one lane but this is NOT enforced.
|
||||
// To enforce that each transaction belong to a single lane, you must configure the
|
||||
// ignore list of each lane to include all preceding lanes. Basic mempool API will
|
||||
// attempt to insert, remove transactions from all lanes it belongs to. It is recommended,
|
||||
// that mutex is set to true when creating the mempool. This will ensure that each
|
||||
// transaction cannot be inserted into the lanes before it.
|
||||
func NewLanedMempool(logger log.Logger, mutex bool, laneFetcher LaneFetcher, lanes ...Lane) Mempool {
|
||||
// Note that a name with the value "default" MUST be provided.
|
||||
func NewLanedMempool(
|
||||
logger log.Logger,
|
||||
lanes []Lane,
|
||||
laneFetcher LaneFetcher,
|
||||
) (*LanedMempool, error) {
|
||||
laneCache := make(map[Lane]struct{})
|
||||
seenDefault := false
|
||||
|
||||
// Ensure that each of the lanes are mutually exclusive. The default lane should
|
||||
// ignore all other lanes, while all other lanes should ignore every lane except
|
||||
// the default lane.
|
||||
for index, lane := range lanes {
|
||||
if lane.Name() == DefaultLaneName {
|
||||
lowerIgnoreList := make([]Lane, index)
|
||||
copy(lowerIgnoreList, lanes[:index])
|
||||
|
||||
upperIgnoreList := make([]Lane, len(lanes)-index-1)
|
||||
copy(upperIgnoreList, lanes[index+1:])
|
||||
|
||||
lane.SetIgnoreList(append(lowerIgnoreList, upperIgnoreList...))
|
||||
seenDefault = true
|
||||
} else {
|
||||
laneCache[lane] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
if !seenDefault {
|
||||
return nil, fmt.Errorf("default lane not found. a lane with the name %s must be provided", DefaultLaneName)
|
||||
}
|
||||
|
||||
for _, lane := range lanes {
|
||||
if lane.Name() == DefaultLaneName {
|
||||
continue
|
||||
}
|
||||
|
||||
delete(laneCache, lane)
|
||||
|
||||
ignoreList := make([]Lane, 0)
|
||||
for otherLane := range laneCache {
|
||||
ignoreList = append(ignoreList, otherLane)
|
||||
}
|
||||
|
||||
lane.SetIgnoreList(ignoreList)
|
||||
laneCache[lane] = struct{}{}
|
||||
}
|
||||
|
||||
mempool := &LanedMempool{
|
||||
logger: logger,
|
||||
registry: lanes,
|
||||
@@ -73,22 +124,10 @@ func NewLanedMempool(logger log.Logger, mutex bool, laneFetcher LaneFetcher, lan
|
||||
}
|
||||
|
||||
if err := mempool.ValidateBasic(); err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set the ignore list for each lane
|
||||
if mutex {
|
||||
// perform full copy to prevent GC
|
||||
registry := make([]Lane, len(mempool.registry))
|
||||
copy(registry, mempool.registry)
|
||||
for index, lane := range registry {
|
||||
if index > 0 {
|
||||
lane.SetIgnoreList(registry[:index])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mempool
|
||||
return mempool, nil
|
||||
}
|
||||
|
||||
// CountTx returns the total number of transactions in the mempool. This will
|
||||
@@ -123,25 +162,14 @@ func (m *LanedMempool) Insert(ctx context.Context, tx sdk.Tx) (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
var errors []string
|
||||
|
||||
unwrappedCtx := sdk.UnwrapSDKContext(ctx)
|
||||
for _, lane := range m.registry {
|
||||
if !lane.Match(unwrappedCtx, tx) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := lane.Insert(ctx, tx); err != nil {
|
||||
m.logger.Debug("failed to insert tx into lane", "lane", lane.Name(), "err", err)
|
||||
errors = append(errors, fmt.Sprintf("failed to insert tx into lane %s: %s", lane.Name(), err.Error()))
|
||||
if lane.Match(unwrappedCtx, tx) {
|
||||
return lane.Insert(ctx, tx)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errors) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf(strings.Join(errors, ";"))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Insert returns a nil iterator.
|
||||
@@ -154,7 +182,8 @@ func (m *LanedMempool) Select(_ context.Context, _ [][]byte) sdkmempool.Iterator
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove removes a transaction from all of the lanes it is currently in.
|
||||
// Remove removes a transaction from the mempool. This assumes that the transaction
|
||||
// is contained in only one of the lanes.
|
||||
func (m *LanedMempool) Remove(tx sdk.Tx) (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -163,33 +192,13 @@ func (m *LanedMempool) Remove(tx sdk.Tx) (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
var errors []string
|
||||
|
||||
for _, lane := range m.registry {
|
||||
if !lane.Contains(tx) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := lane.Remove(tx); err != nil {
|
||||
m.logger.Debug("failed to remove tx from lane", "lane", lane.Name(), "err", err)
|
||||
|
||||
// We only care about errors that are not "tx not found" errors.
|
||||
//
|
||||
// TODO: Figure out whether we should be erroring in the mempool if
|
||||
// the tx is not found in the lane. Downstream, if the removal fails runTx will
|
||||
// error out and will NOT execute runMsgs (which is where the tx is actually
|
||||
// executed).
|
||||
if err != sdkmempool.ErrTxNotFound {
|
||||
errors = append(errors, fmt.Sprintf("failed to remove tx from lane %s: %s;", lane.Name(), err.Error()))
|
||||
}
|
||||
if lane.Contains(tx) {
|
||||
return lane.Remove(tx)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errors) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf(strings.Join(errors, ";"))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Contains returns true if the transaction is contained in any of the lanes.
|
||||
@@ -210,40 +219,6 @@ func (m *LanedMempool) Contains(tx sdk.Tx) (contains bool) {
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidateBasic validates the mempools configuration. ValidateBasic ensures
|
||||
// the following:
|
||||
// - The sum of the lane max block space percentages is less than or equal to 1.
|
||||
// - There is no unused block space.
|
||||
func (m *LanedMempool) ValidateBasic() error {
|
||||
sum := math.LegacyZeroDec()
|
||||
seenZeroMaxBlockSpace := false
|
||||
|
||||
for _, lane := range m.registry {
|
||||
maxBlockSpace := lane.GetMaxBlockSpace()
|
||||
if maxBlockSpace.IsZero() {
|
||||
seenZeroMaxBlockSpace = true
|
||||
}
|
||||
|
||||
sum = sum.Add(lane.GetMaxBlockSpace())
|
||||
}
|
||||
|
||||
switch {
|
||||
// Ensure that the sum of the lane max block space percentages is less than
|
||||
// or equal to 1.
|
||||
case sum.GT(math.LegacyOneDec()):
|
||||
return fmt.Errorf("sum of lane max block space percentages must be less than or equal to 1, got %s", sum)
|
||||
// Ensure that there is no unused block space.
|
||||
case sum.LT(math.LegacyOneDec()) && !seenZeroMaxBlockSpace:
|
||||
return fmt.Errorf("sum of total block space percentages will be less than 1")
|
||||
}
|
||||
|
||||
if m.moduleLaneFetcher == nil {
|
||||
return fmt.Errorf("moduleLaneFetcher muset be set on mempool")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Registry returns the mempool's lane registry.
|
||||
func (m *LanedMempool) Registry(ctx sdk.Context) (newRegistry []Lane, err error) {
|
||||
if m.moduleLaneFetcher == nil {
|
||||
@@ -284,3 +259,48 @@ func (m *LanedMempool) OrderLanes(chainLanes []blocksdkmoduletypes.Lane) (ordere
|
||||
|
||||
return orderedLanes, nil
|
||||
}
|
||||
|
||||
// ValidateBasic validates the mempools configuration. ValidateBasic ensures
|
||||
// the following:
|
||||
// - The sum of the lane max block space percentages is less than or equal to 1.
|
||||
// - There is no unused block space.
|
||||
func (m *LanedMempool) ValidateBasic() error {
|
||||
if len(m.registry) == 0 {
|
||||
return fmt.Errorf("registry cannot be nil; must configure at least one lane")
|
||||
}
|
||||
|
||||
sum := math.LegacyZeroDec()
|
||||
seenZeroMaxBlockSpace := false
|
||||
seenLanes := make(map[string]struct{})
|
||||
|
||||
for _, lane := range m.registry {
|
||||
name := lane.Name()
|
||||
if _, seen := seenLanes[name]; seen {
|
||||
return fmt.Errorf("duplicate lane name %s", name)
|
||||
}
|
||||
|
||||
maxBlockSpace := lane.GetMaxBlockSpace()
|
||||
if maxBlockSpace.IsZero() {
|
||||
seenZeroMaxBlockSpace = true
|
||||
}
|
||||
|
||||
sum = sum.Add(lane.GetMaxBlockSpace())
|
||||
seenLanes[name] = struct{}{}
|
||||
}
|
||||
|
||||
switch {
|
||||
// Ensure that the sum of the lane max block space percentages is less than
|
||||
// or equal to 1.
|
||||
case sum.GT(math.LegacyOneDec()):
|
||||
return fmt.Errorf("sum of lane max block space percentages must be less than or equal to 1, got %s", sum)
|
||||
// Ensure that there is no unused block space.
|
||||
case sum.LT(math.LegacyOneDec()) && !seenZeroMaxBlockSpace:
|
||||
return fmt.Errorf("sum of total block space percentages will be less than 1")
|
||||
}
|
||||
|
||||
if m.moduleLaneFetcher == nil {
|
||||
return fmt.Errorf("moduleLaneFetcher muset be set on mempool")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
+199
-42
@@ -46,7 +46,7 @@ type BlockBusterTestSuite struct {
|
||||
|
||||
chainLanes []blocksdkmoduletypes.Lane
|
||||
lanes []block.Lane
|
||||
mempool block.Mempool
|
||||
mempool *block.LanedMempool
|
||||
|
||||
// account set up
|
||||
accounts []testutils.Account
|
||||
@@ -132,16 +132,18 @@ func (suite *BlockBusterTestSuite) SetupTest() {
|
||||
// Mempool set up
|
||||
suite.lanes = []block.Lane{suite.mevLane, suite.freeLane, suite.baseLane}
|
||||
suite.chainLanes = []blocksdkmoduletypes.Lane{suite.mevSDKLane, suite.freeSDKLane, suite.baseSDKLane}
|
||||
suite.mempool = block.NewLanedMempool(
|
||||
|
||||
var err error
|
||||
suite.mempool, err = block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
true,
|
||||
suite.lanes,
|
||||
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
|
||||
return suite.baseSDKLane, nil
|
||||
}, func() []blocksdkmoduletypes.Lane {
|
||||
return suite.chainLanes
|
||||
}),
|
||||
suite.lanes...,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// Accounts set up
|
||||
suite.accounts = testutils.RandomAccounts(suite.random, 10)
|
||||
@@ -151,6 +153,192 @@ func (suite *BlockBusterTestSuite) SetupTest() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
fetcher := mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
|
||||
return blocksdkmoduletypes.Lane{}, nil
|
||||
}, func() []blocksdkmoduletypes.Lane {
|
||||
return nil
|
||||
})
|
||||
|
||||
baseConfig := base.LaneConfig{
|
||||
Logger: log.NewNopLogger(),
|
||||
TxEncoder: suite.encodingConfig.TxConfig.TxEncoder(),
|
||||
TxDecoder: suite.encodingConfig.TxConfig.TxDecoder(),
|
||||
SignerExtractor: signer_extraction.NewDefaultAdapter(),
|
||||
AnteHandler: nil,
|
||||
MaxBlockSpace: math.LegacyZeroDec(),
|
||||
}
|
||||
|
||||
defaultLane := defaultlane.NewDefaultLane(baseConfig)
|
||||
mevLane := mev.NewMEVLane(
|
||||
baseConfig,
|
||||
mev.NewDefaultAuctionFactory(suite.encodingConfig.TxConfig.TxDecoder(), signer_extraction.NewDefaultAdapter()),
|
||||
)
|
||||
freeLane := free.NewFreeLane(
|
||||
baseConfig,
|
||||
base.DefaultTxPriority(),
|
||||
free.DefaultMatchHandler(),
|
||||
)
|
||||
|
||||
suite.Run("works with a single lane", func() {
|
||||
lanes := []block.Lane{defaultLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(0, len(ignoreList))
|
||||
})
|
||||
|
||||
suite.Run("works mev and default lane", func() {
|
||||
lanes := []block.Lane{mevLane, defaultLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
|
||||
ignoreList = mevLane.GetIgnoreList()
|
||||
suite.Require().Equal(0, len(ignoreList))
|
||||
})
|
||||
|
||||
suite.Run("works mev and default lane in reverse order", func() {
|
||||
lanes := []block.Lane{mevLane, defaultLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
|
||||
ignoreList = mevLane.GetIgnoreList()
|
||||
suite.Require().Equal(0, len(ignoreList))
|
||||
})
|
||||
|
||||
suite.Run("works with mev, free, and default lane", func() {
|
||||
lanes := []block.Lane{mevLane, freeLane, defaultLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(2, len(ignoreList))
|
||||
|
||||
ignoreList = mevLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(freeLane, ignoreList[0])
|
||||
|
||||
ignoreList = freeLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(mevLane, ignoreList[0])
|
||||
})
|
||||
|
||||
suite.Run("works with mev, default, free lane", func() {
|
||||
lanes := []block.Lane{mevLane, defaultLane, freeLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(2, len(ignoreList))
|
||||
|
||||
ignoreList = mevLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(freeLane, ignoreList[0])
|
||||
|
||||
ignoreList = freeLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(mevLane, ignoreList[0])
|
||||
})
|
||||
|
||||
suite.Run("works with free, mev, and default lane", func() {
|
||||
lanes := []block.Lane{freeLane, mevLane, defaultLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(2, len(ignoreList))
|
||||
|
||||
ignoreList = mevLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(freeLane, ignoreList[0])
|
||||
|
||||
ignoreList = freeLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(mevLane, ignoreList[0])
|
||||
})
|
||||
|
||||
suite.Run("works with default, free, mev lanes", func() {
|
||||
lanes := []block.Lane{defaultLane, freeLane, mevLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(2, len(ignoreList))
|
||||
|
||||
ignoreList = mevLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(freeLane, ignoreList[0])
|
||||
|
||||
ignoreList = freeLane.GetIgnoreList()
|
||||
suite.Require().Equal(1, len(ignoreList))
|
||||
suite.Require().Equal(mevLane, ignoreList[0])
|
||||
})
|
||||
|
||||
suite.Run("default lane not included", func() {
|
||||
lanes := []block.Lane{mevLane, freeLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().Error(err)
|
||||
})
|
||||
|
||||
suite.Run("duplicate lanes", func() {
|
||||
lanes := []block.Lane{mevLane, defaultLane, mevLane}
|
||||
|
||||
_, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().Error(err)
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *BlockBusterTestSuite) TestInsert() {
|
||||
cases := []struct {
|
||||
name string
|
||||
@@ -463,20 +651,6 @@ func (suite *BlockBusterTestSuite) TestLanedMempool_Registry() {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid duplicate lanes in registry",
|
||||
chainLanes: []blocksdkmoduletypes.Lane{
|
||||
suite.mevSDKLane, // order = 0
|
||||
suite.freeSDKLane, // order = 1
|
||||
suite.baseSDKLane, // order = 2
|
||||
},
|
||||
registryLanes: []block.Lane{
|
||||
suite.freeLane,
|
||||
suite.baseLane,
|
||||
suite.baseLane,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid reorder",
|
||||
chainLanes: []blocksdkmoduletypes.Lane{
|
||||
@@ -519,16 +693,16 @@ func (suite *BlockBusterTestSuite) TestLanedMempool_Registry() {
|
||||
for _, tc := range tests {
|
||||
suite.Run(tc.name, func() {
|
||||
// setup mock mempool
|
||||
mempool := block.NewLanedMempool(
|
||||
mempool, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
true,
|
||||
tc.registryLanes,
|
||||
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
|
||||
return blocksdkmoduletypes.Lane{}, nil
|
||||
}, func() []blocksdkmoduletypes.Lane {
|
||||
return tc.chainLanes
|
||||
}),
|
||||
tc.registryLanes...,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
gotOrderedLanes, err := mempool.Registry(suite.ctx)
|
||||
if tc.wantErr {
|
||||
@@ -590,20 +764,6 @@ func (suite *BlockBusterTestSuite) TestLanedMempool_OrderLanes() {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid duplicate lanes in registry",
|
||||
chainLanes: []blocksdkmoduletypes.Lane{
|
||||
suite.mevSDKLane, // order = 0
|
||||
suite.freeSDKLane, // order = 1
|
||||
suite.baseSDKLane, // order = 2
|
||||
},
|
||||
registryLanes: []block.Lane{
|
||||
suite.freeLane,
|
||||
suite.baseLane,
|
||||
suite.baseLane,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid reorder",
|
||||
chainLanes: []blocksdkmoduletypes.Lane{
|
||||
@@ -646,21 +806,18 @@ func (suite *BlockBusterTestSuite) TestLanedMempool_OrderLanes() {
|
||||
for _, tc := range tests {
|
||||
suite.Run(tc.name, func() {
|
||||
// setup mock mempool
|
||||
mempool := block.NewLanedMempool(
|
||||
mempool, err := block.NewLanedMempool(
|
||||
log.NewTestLogger(suite.T()),
|
||||
true,
|
||||
tc.registryLanes,
|
||||
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
|
||||
return blocksdkmoduletypes.Lane{}, nil
|
||||
}, func() []blocksdkmoduletypes.Lane {
|
||||
return []blocksdkmoduletypes.Lane{}
|
||||
}),
|
||||
tc.registryLanes...,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
lanedMempool, ok := mempool.(*block.LanedMempool)
|
||||
suite.Require().True(ok)
|
||||
|
||||
gotOrderedLanes, err := lanedMempool.OrderLanes(tc.chainLanes)
|
||||
gotOrderedLanes, err := mempool.OrderLanes(tc.chainLanes)
|
||||
if tc.wantErr {
|
||||
suite.Require().Error(err)
|
||||
return
|
||||
|
||||
+18
-3
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
// Code generated by mockery v2.30.1. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
@@ -75,6 +75,22 @@ func (_m *Lane) CountTx() int {
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetIgnoreList provides a mock function with given fields:
|
||||
func (_m *Lane) GetIgnoreList() []block.Lane {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 []block.Lane
|
||||
if rf, ok := ret.Get(0).(func() []block.Lane); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]block.Lane)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetMaxBlockSpace provides a mock function with given fields:
|
||||
func (_m *Lane) GetMaxBlockSpace() math.LegacyDec {
|
||||
ret := _m.Called()
|
||||
@@ -229,8 +245,7 @@ func (_m *Lane) SetMaxBlockSpace(_a0 math.LegacyDec) {
|
||||
func NewLane(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
},
|
||||
) *Lane {
|
||||
}) *Lane {
|
||||
mock := &Lane{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
// Code generated by mockery v2.30.1. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
@@ -117,8 +117,7 @@ func (_m *LaneMempool) Select(_a0 context.Context, _a1 [][]byte) mempool.Iterato
|
||||
func NewLaneMempool(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
},
|
||||
) *LaneMempool {
|
||||
}) *LaneMempool {
|
||||
mock := &LaneMempool{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
lane.On("GetMaxBlockSpace").Return(math.LegacyNewDec(1)).Maybe()
|
||||
|
||||
t.Run("can update with no transactions", func(t *testing.T) {
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), nil, 100, 100)
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), nil, 100, 100)
|
||||
|
||||
err := proposal.UpdateProposal(lane, nil)
|
||||
require.NoError(t, err)
|
||||
@@ -61,7 +61,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
|
||||
size := len(txBzs[0])
|
||||
gasLimit := 100
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
|
||||
err = proposal.UpdateProposal(lane, []sdk.Tx{tx})
|
||||
require.NoError(t, err)
|
||||
@@ -107,7 +107,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
gasLimit += 100
|
||||
}
|
||||
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), gasLimit)
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), int64(size), gasLimit)
|
||||
|
||||
err = proposal.UpdateProposal(lane, txs)
|
||||
require.NoError(t, err)
|
||||
@@ -144,7 +144,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
|
||||
size := int64(len(txBzs[0]))
|
||||
gasLimit := uint64(100)
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), size, gasLimit)
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), size, gasLimit)
|
||||
|
||||
err = proposal.UpdateProposal(lane, []sdk.Tx{tx})
|
||||
require.NoError(t, err)
|
||||
@@ -204,7 +204,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
|
||||
size := len(txBzs[0]) + len(txBzs[1])
|
||||
gasLimit := 200
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
|
||||
err = proposal.UpdateProposal(lane, []sdk.Tx{tx})
|
||||
require.NoError(t, err)
|
||||
@@ -242,7 +242,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
|
||||
size := len(txBzs[0])
|
||||
gasLimit := 100
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
|
||||
lane := mocks.NewLane(t)
|
||||
|
||||
@@ -280,7 +280,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
|
||||
size := len(txBzs[0])
|
||||
gasLimit := 100
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
|
||||
|
||||
lane := mocks.NewLane(t)
|
||||
|
||||
@@ -318,7 +318,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
|
||||
size := len(txBzs[0])
|
||||
gasLimit := 100
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size)-1, uint64(gasLimit))
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), int64(size)-1, uint64(gasLimit))
|
||||
|
||||
err = proposal.UpdateProposal(lane, []sdk.Tx{tx})
|
||||
require.Error(t, err)
|
||||
@@ -351,7 +351,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
|
||||
size := len(txBzs[0])
|
||||
gasLimit := 100
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit)-1)
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit)-1)
|
||||
|
||||
err = proposal.UpdateProposal(lane, []sdk.Tx{tx})
|
||||
require.Error(t, err)
|
||||
@@ -392,7 +392,7 @@ func TestUpdateProposal(t *testing.T) {
|
||||
txBzs, err := utils.GetEncodedTxs(encodingConfig.TxConfig.TxEncoder(), []sdk.Tx{tx, tx2})
|
||||
require.NoError(t, err)
|
||||
|
||||
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), 10000, 10000)
|
||||
proposal := proposals.NewProposal(log.NewNopLogger(), encodingConfig.TxConfig.TxEncoder(), 10000, 10000)
|
||||
|
||||
err = proposal.UpdateProposal(lane, []sdk.Tx{tx})
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user