fix: Removing IgnoreList from Lane Interface (#245)
* greedy approach to lane verification * docs * base lane testing * mev lane testing nits * abci top level testing done * network spamming in E2E * string rep of escrow address * nit * nit * nit v1.0.1 * removing logs from testing * query test * logging with tx info * nits * nit * nit * testing nit * adding readmes which i will fill out l8r * removing ignore list from convo, ur done * removing logs in testing * nits * eh ig we dont need it rn * removing ignore list from config * nit test --------- Co-authored-by: Alex Johnson <alex@skip.money>
This commit is contained in:
co-authored by
Alex Johnson
parent
be4465ae95
commit
b91cfb617c
@@ -8,7 +8,6 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
signer_extraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter"
|
||||
"github.com/skip-mev/block-sdk/block"
|
||||
)
|
||||
|
||||
// LaneConfig defines the basic configurations needed for a lane.
|
||||
@@ -28,14 +27,6 @@ type LaneConfig struct {
|
||||
// lane (up to maxTxBytes as provided by the request). This is useful for the default lane.
|
||||
MaxBlockSpace math.LegacyDec
|
||||
|
||||
// IgnoreList defines the list of lanes to ignore when processing transactions. This
|
||||
// is useful for when you want lanes to exist after the default lane. For example,
|
||||
// say there are two lanes: default and free. The free lane should be processed after
|
||||
// the default lane. In this case, the free lane should be added to the ignore list
|
||||
// of the default lane. Otherwise, the transactions that belong to the free lane
|
||||
// will be processed by the default lane (which accepts all transactions by default).
|
||||
IgnoreList []block.Lane
|
||||
|
||||
// MaxTxs sets the maximum number of transactions allowed in the mempool with
|
||||
// the semantics:
|
||||
// - if MaxTx == 0, there is no cap on the number of transactions in the mempool
|
||||
|
||||
@@ -170,3 +170,19 @@ func DefaultMatchHandler() MatchHandler {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// NewMatchHandler returns a match handler that matches transactions
|
||||
// that match the lane and do not match with any of the provided match handlers.
|
||||
// In the context of building an application, you would want to use this to
|
||||
// ignore the match handlers of other lanes in the application.
|
||||
func NewMatchHandler(mh MatchHandler, ignoreMHs ...MatchHandler) MatchHandler {
|
||||
return func(ctx sdk.Context, tx sdk.Tx) bool {
|
||||
for _, ignoreMH := range ignoreMHs {
|
||||
if ignoreMH(ctx, tx) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return mh(ctx, tx)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-30
@@ -121,24 +121,7 @@ func (l *BaseLane) SetProcessLaneHandler(processLaneHandler ProcessLaneHandler)
|
||||
// if the transaction is on the ignore list. If the transaction is on the ignore
|
||||
// list, it returns false.
|
||||
func (l *BaseLane) Match(ctx sdk.Context, tx sdk.Tx) bool {
|
||||
return l.matchHandler(ctx, tx) && !l.CheckIgnoreList(ctx, tx)
|
||||
}
|
||||
|
||||
// CheckIgnoreList returns true if the transaction is on the ignore list. The ignore
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return l.matchHandler(ctx, tx)
|
||||
}
|
||||
|
||||
// Name returns the name of the lane.
|
||||
@@ -146,18 +129,6 @@ func (l *BaseLane) Name() string {
|
||||
return l.laneName
|
||||
}
|
||||
|
||||
// SetIgnoreList sets 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) 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
|
||||
|
||||
@@ -70,12 +70,6 @@ type Lane interface {
|
||||
// SetAnteHandler sets the lane's antehandler.
|
||||
SetAnteHandler(antehander sdk.AnteHandler)
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
@@ -12,12 +12,6 @@ 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.
|
||||
@@ -62,61 +56,11 @@ type (
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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,
|
||||
|
||||
+9
-63
@@ -78,9 +78,11 @@ func (suite *BlockBusterTestSuite) SetupTest() {
|
||||
AnteHandler: nil,
|
||||
MaxBlockSpace: math.LegacyZeroDec(),
|
||||
}
|
||||
factory := mev.NewDefaultAuctionFactory(suite.encodingConfig.TxConfig.TxDecoder(), signer_extraction.NewDefaultAdapter())
|
||||
suite.mevLane = mev.NewMEVLane(
|
||||
mevConfig,
|
||||
mev.NewDefaultAuctionFactory(suite.encodingConfig.TxConfig.TxDecoder(), signer_extraction.NewDefaultAdapter()),
|
||||
factory,
|
||||
factory.MatchHandler(),
|
||||
)
|
||||
|
||||
suite.mevSDKLane = blocksdkmoduletypes.Lane{
|
||||
@@ -121,6 +123,7 @@ func (suite *BlockBusterTestSuite) SetupTest() {
|
||||
}
|
||||
suite.baseLane = defaultlane.NewDefaultLane(
|
||||
baseConfig,
|
||||
base.DefaultMatchHandler(),
|
||||
)
|
||||
|
||||
suite.baseSDKLane = blocksdkmoduletypes.Lane{
|
||||
@@ -169,10 +172,12 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
MaxBlockSpace: math.LegacyZeroDec(),
|
||||
}
|
||||
|
||||
defaultLane := defaultlane.NewDefaultLane(baseConfig)
|
||||
defaultLane := defaultlane.NewDefaultLane(baseConfig, base.DefaultMatchHandler())
|
||||
factory := mev.NewDefaultAuctionFactory(suite.encodingConfig.TxConfig.TxDecoder(), signer_extraction.NewDefaultAdapter())
|
||||
mevLane := mev.NewMEVLane(
|
||||
baseConfig,
|
||||
mev.NewDefaultAuctionFactory(suite.encodingConfig.TxConfig.TxDecoder(), signer_extraction.NewDefaultAdapter()),
|
||||
factory,
|
||||
factory.MatchHandler(),
|
||||
)
|
||||
freeLane := free.NewFreeLane(
|
||||
baseConfig,
|
||||
@@ -189,9 +194,6 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
ignoreList := defaultLane.GetIgnoreList()
|
||||
suite.Require().Equal(0, len(ignoreList))
|
||||
})
|
||||
|
||||
suite.Run("works mev and default lane", func() {
|
||||
@@ -203,12 +205,6 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
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() {
|
||||
@@ -220,12 +216,6 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
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() {
|
||||
@@ -237,17 +227,6 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
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() {
|
||||
@@ -259,17 +238,6 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
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() {
|
||||
@@ -281,17 +249,6 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
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() {
|
||||
@@ -303,17 +260,6 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
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() {
|
||||
@@ -324,7 +270,7 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
|
||||
lanes,
|
||||
fetcher,
|
||||
)
|
||||
suite.Require().Error(err)
|
||||
suite.Require().NoError(err)
|
||||
})
|
||||
|
||||
suite.Run("duplicate lanes", func() {
|
||||
|
||||
@@ -77,22 +77,6 @@ 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()
|
||||
@@ -272,11 +256,6 @@ func (_m *Lane) SetAnteHandler(antehander types.AnteHandler) {
|
||||
_m.Called(antehander)
|
||||
}
|
||||
|
||||
// SetIgnoreList provides a mock function with given fields: ignoreList
|
||||
func (_m *Lane) SetIgnoreList(ignoreList []block.Lane) {
|
||||
_m.Called(ignoreList)
|
||||
}
|
||||
|
||||
// SetMaxBlockSpace provides a mock function with given fields: _a0
|
||||
func (_m *Lane) SetMaxBlockSpace(_a0 math.LegacyDec) {
|
||||
_m.Called(_a0)
|
||||
|
||||
@@ -591,7 +591,7 @@ func getTxsWithInfo(txs []sdk.Tx) ([]utils.TxWithInfo, error) {
|
||||
signerextraction.NewDefaultAdapter(),
|
||||
math.LegacyNewDec(1),
|
||||
)
|
||||
lane := defaultlane.NewDefaultLane(cfg)
|
||||
lane := defaultlane.NewDefaultLane(cfg, base.DefaultMatchHandler())
|
||||
|
||||
txsWithInfo := make([]utils.TxWithInfo, len(txs))
|
||||
for i, tx := range txs {
|
||||
|
||||
Reference in New Issue
Block a user