Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
removing ignore list from convo, ur done
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay committed Nov 28, 2023
1 parent d59616c commit b05e316
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 367 deletions.
1 change: 1 addition & 0 deletions abci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
28 changes: 8 additions & 20 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
Expand All @@ -532,10 +532,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

defaultLane.SetIgnoreList(nil)

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
Expand Down Expand Up @@ -588,7 +586,7 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
Expand All @@ -598,10 +596,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

defaultLane.SetIgnoreList(nil)

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
Expand Down Expand Up @@ -661,7 +657,7 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
Expand All @@ -671,12 +667,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

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

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
Expand Down Expand Up @@ -736,7 +728,7 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
Expand All @@ -746,12 +738,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

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

proposalHandler := abci.NewProposalHandler(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
Expand Down
19 changes: 10 additions & 9 deletions abci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *ProposalsTestSuite) setUpAnteHandler(expectedExecution map[sdk.Tx]bool)

func (s *ProposalsTestSuite) setUpCustomMatchHandlerLane(maxBlockSpace math.LegacyDec, expectedExecution map[sdk.Tx]bool, mh base.MatchHandler, name string) block.Lane {
cfg := base.LaneConfig{
Logger: log.NewNopLogger(),
Logger: log.NewTestLogger(s.T()),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: s.setUpAnteHandler(expectedExecution),
Expand All @@ -80,7 +80,7 @@ func (s *ProposalsTestSuite) setUpCustomMatchHandlerLane(maxBlockSpace math.Lega

func (s *ProposalsTestSuite) setUpStandardLane(maxBlockSpace math.LegacyDec, expectedExecution map[sdk.Tx]bool) *defaultlane.DefaultLane {
cfg := base.LaneConfig{
Logger: log.NewNopLogger(),
Logger: log.NewTestLogger(s.T()),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: s.setUpAnteHandler(expectedExecution),
Expand All @@ -89,25 +89,26 @@ 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 {
cfg := base.LaneConfig{
Logger: log.NewNopLogger(),
Logger: log.NewTestLogger(s.T()),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: s.setUpAnteHandler(expectedExecution),
MaxBlockSpace: maxBlockSpace,
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 {
cfg := base.LaneConfig{
Logger: log.NewNopLogger(),
Logger: log.NewTestLogger(s.T()),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: s.setUpAnteHandler(expectedExecution),
Expand All @@ -120,7 +121,7 @@ func (s *ProposalsTestSuite) setUpFreeLane(maxBlockSpace math.LegacyDec, expecte

func (s *ProposalsTestSuite) setUpPanicLane(name string, maxBlockSpace math.LegacyDec) *base.BaseLane {
cfg := base.LaneConfig{
Logger: log.NewNopLogger(),
Logger: log.NewTestLogger(s.T()),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
MaxBlockSpace: maxBlockSpace,
Expand Down Expand Up @@ -159,14 +160,14 @@ func (s *ProposalsTestSuite) setUpProposalHandlers(lanes []block.Lane) *abci.Pro
})

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
lanes,
laneFetcher,
)
s.Require().NoError(err)

return abci.NewProposalHandler(
log.NewNopLogger(),
log.NewTestLogger(s.T()),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
Expand Down
14 changes: 14 additions & 0 deletions block/base/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,17 @@ 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.
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)
}
}
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
47 changes: 0 additions & 47 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 @@ -76,47 +70,6 @@ func NewLanedMempool(
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
Loading

0 comments on commit b05e316

Please sign in to comment.