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

fix: Removing IgnoreList from Lane Interface #245

Merged
merged 30 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4abf08e
greedy approach to lane verification
davidterpay Nov 21, 2023
b9fc721
docs
davidterpay Nov 22, 2023
580f487
base lane testing
davidterpay Nov 22, 2023
0a44f1f
mev lane testing nits
davidterpay Nov 22, 2023
0399069
abci top level testing done
davidterpay Nov 22, 2023
8b25b03
network spamming in E2E
davidterpay Nov 22, 2023
b1a14cd
string rep of escrow address
davidterpay Nov 22, 2023
6266d60
nit
davidterpay Nov 22, 2023
ad9df3d
nit
davidterpay Nov 27, 2023
2084ddf
nit v1.0.1
davidterpay Nov 27, 2023
b337085
removing logs from testing
davidterpay Nov 27, 2023
f6c723e
Merge branch 'terpay/greedy-process-proposal' into terpay/escrow-addr…
davidterpay Nov 27, 2023
0f8c6f8
query test
davidterpay Nov 27, 2023
a562fcd
logging with tx info
davidterpay Nov 27, 2023
d63bc47
Merge branch 'terpay/escrow-address-string' into terpay/lane-tx-info
Nov 27, 2023
c95343b
nits
davidterpay Nov 27, 2023
a45de07
Merge branch 'main' into terpay/escrow-address-string
davidterpay Nov 27, 2023
91b2fa9
Merge branch 'terpay/escrow-address-string' into terpay/lane-tx-info
davidterpay Nov 27, 2023
3026f7f
Merge branch 'main' into terpay/lane-tx-info
davidterpay Nov 27, 2023
765de40
nit
davidterpay Nov 27, 2023
36ec06a
nit
davidterpay Nov 27, 2023
f20b15b
testing nit
davidterpay Nov 27, 2023
d59616c
adding readmes which i will fill out l8r
davidterpay Nov 28, 2023
b05e316
removing ignore list from convo, ur done
davidterpay Nov 28, 2023
326dd5c
removing logs in testing
davidterpay Nov 28, 2023
8d55050
Merge branch 'main' into terpay/ignorelist-dep
davidterpay Nov 28, 2023
397e6bf
nits
davidterpay Nov 28, 2023
99eb742
eh ig we dont need it rn
davidterpay Nov 28, 2023
196b831
removing ignore list from config
davidterpay Nov 29, 2023
0436c08
nit test
davidterpay Nov 29, 2023
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
12 changes: 0 additions & 12 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

defaultLane.SetIgnoreList(nil)

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
Expand Down Expand Up @@ -598,8 +596,6 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

defaultLane.SetIgnoreList(nil)

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
Expand Down Expand Up @@ -671,10 +667,6 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

panicLane.SetIgnoreList(nil)
panicLane2.SetIgnoreList(nil)
defaultLane.SetIgnoreList(nil)

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
Expand Down Expand Up @@ -746,10 +738,6 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

panicLane.SetIgnoreList(nil)
panicLane2.SetIgnoreList(nil)
defaultLane.SetIgnoreList(nil)

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
Expand Down
5 changes: 3 additions & 2 deletions abci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *ProposalsTestSuite) setUpStandardLane(maxBlockSpace math.LegacyDec, exp
SignerExtractor: signeradaptors.NewDefaultAdapter(),
}

return defaultlane.NewDefaultLane(cfg)
return defaultlane.NewDefaultLane(cfg, base.DefaultMatchHandler())
}

func (s *ProposalsTestSuite) setUpTOBLane(maxBlockSpace math.LegacyDec, expectedExecution map[sdk.Tx]bool) *mev.MEVLane {
Expand All @@ -102,7 +102,8 @@ func (s *ProposalsTestSuite) setUpTOBLane(maxBlockSpace math.LegacyDec, expected
SignerExtractor: signeradaptors.NewDefaultAdapter(),
}

return mev.NewMEVLane(cfg, mev.NewDefaultAuctionFactory(cfg.TxDecoder, signeradaptors.NewDefaultAdapter()))
factory := mev.NewDefaultAuctionFactory(cfg.TxDecoder, signeradaptors.NewDefaultAdapter())
return mev.NewMEVLane(cfg, factory, factory.MatchHandler())
}

func (s *ProposalsTestSuite) setUpFreeLane(maxBlockSpace math.LegacyDec, expectedExecution map[sdk.Tx]bool) *free.FreeLane {
Expand Down
16 changes: 16 additions & 0 deletions block/base/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
davidterpay marked this conversation as resolved.
Show resolved Hide resolved
for _, ignoreMH := range ignoreMHs {
if ignoreMH(ctx, tx) {
return false
}
}

return mh(ctx, tx)
}
}
31 changes: 1 addition & 30 deletions block/base/lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,43 +121,14 @@ 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.
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
Expand Down
6 changes: 0 additions & 6 deletions block/lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 0 additions & 56 deletions block/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
72 changes: 9 additions & 63 deletions block/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -121,6 +123,7 @@ func (suite *BlockBusterTestSuite) SetupTest() {
}
suite.baseLane = defaultlane.NewDefaultLane(
baseConfig,
base.DefaultMatchHandler(),
)

suite.baseSDKLane = blocksdkmoduletypes.Lane{
Expand Down Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -324,7 +270,7 @@ func (suite *BlockBusterTestSuite) TestNewMempool() {
lanes,
fetcher,
)
suite.Require().Error(err)
suite.Require().NoError(err)
aljo242 marked this conversation as resolved.
Show resolved Hide resolved
})

suite.Run("duplicate lanes", func() {
Expand Down
21 changes: 0 additions & 21 deletions block/mocks/lane.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading