Skip to content

Commit

Permalink
fix: Removing IgnoreList from Lane Interface (backport #245) (#249)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
(cherry picked from commit b91cfb6)

# Conflicts:
#	abci/abci_test.go
#	block/base/lane.go
#	block/lane.go
#	block/mempool.go
#	block/mempool_test.go
#	block/mocks/lane.go
#	block/proposals/proposals_test.go
#	tests/app/app.go

* why are there so many conflicts

* more conflicts

* fixing merge

---------

Co-authored-by: David Terpay <[email protected]>
Co-authored-by: David Terpay <[email protected]>
  • Loading branch information
3 people authored Dec 1, 2023
1 parent 9bdab39 commit fd8a786
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 289 deletions.
60 changes: 49 additions & 11 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {

func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
s.Run("can build a proposal if a lane panics first", func() {
panicLane := s.setUpPanicLane(math.LegacyMustNewDecFromStr("0.25"))
panicLane := s.setUpPanicLane("panik", math.LegacyMustNewDecFromStr("0.25"))

tx, err := testutils.CreateRandomTx(
s.encodingConfig.TxConfig,
Expand All @@ -504,7 +504,16 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

mempool := block.NewLanedMempool(log.NewTMLogger(os.Stdout), false, panicLane, defaultLane)
lanes := []block.Lane{
panicLane,
defaultLane,
}

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

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand All @@ -522,7 +531,7 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})

s.Run("can build a proposal if second lane panics", func() {
panicLane := s.setUpPanicLane(math.LegacyMustNewDecFromStr("0.25"))
panicLane := s.setUpPanicLane("panik", math.LegacyMustNewDecFromStr("0.25"))

tx, err := testutils.CreateRandomTx(
s.encodingConfig.TxConfig,
Expand All @@ -540,7 +549,16 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

mempool := block.NewLanedMempool(log.NewTMLogger(os.Stdout), false, defaultLane, panicLane)
lanes := []block.Lane{
defaultLane,
panicLane,
}

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

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand All @@ -558,8 +576,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})

s.Run("can build a proposal if multiple consecutive lanes panic", func() {
panicLane := s.setUpPanicLane(math.LegacyMustNewDecFromStr("0.25"))
panicLane2 := s.setUpPanicLane(math.LegacyMustNewDecFromStr("0.25"))
panicLane := s.setUpPanicLane("panik1", math.LegacyMustNewDecFromStr("0.25"))
panicLane2 := s.setUpPanicLane("panik sum mo", math.LegacyMustNewDecFromStr("0.25"))

tx, err := testutils.CreateRandomTx(
s.encodingConfig.TxConfig,
Expand All @@ -577,7 +595,17 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

mempool := block.NewLanedMempool(log.NewTMLogger(os.Stdout), false, panicLane, panicLane2, defaultLane)
lanes := []block.Lane{
panicLane,
panicLane2,
defaultLane,
}

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

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand All @@ -595,8 +623,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})

s.Run("can build a proposal if the last few lanes panic", func() {
panicLane := s.setUpPanicLane(math.LegacyMustNewDecFromStr("0.25"))
panicLane2 := s.setUpPanicLane(math.LegacyMustNewDecFromStr("0.25"))
panicLane := s.setUpPanicLane("panik", math.LegacyMustNewDecFromStr("0.25"))
panicLane2 := s.setUpPanicLane("dont trip shawty proposal will be built", math.LegacyMustNewDecFromStr("0.25"))

tx, err := testutils.CreateRandomTx(
s.encodingConfig.TxConfig,
Expand All @@ -614,7 +642,17 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

mempool := block.NewLanedMempool(log.NewTMLogger(os.Stdout), false, defaultLane, panicLane, panicLane2)
lanes := []block.Lane{
defaultLane,
panicLane,
panicLane2,
}

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

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand Down Expand Up @@ -905,7 +943,7 @@ func (s *ProposalsTestSuite) TestProcessProposal() {

s.Run("rejects a proposal when a lane panics", func() {
mevLane := s.setUpTOBLane(math.LegacyMustNewDecFromStr("0.25"), map[sdk.Tx]bool{})
panicLane := s.setUpPanicLane(math.LegacyMustNewDecFromStr("0.0"))
panicLane := s.setUpPanicLane("ahhhhhh", math.LegacyMustNewDecFromStr("0.0"))

txbz, err := testutils.CreateRandomTxBz(
s.encodingConfig.TxConfig,
Expand Down
12 changes: 7 additions & 5 deletions abci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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 @@ -99,7 +99,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 All @@ -115,7 +116,7 @@ func (s *ProposalsTestSuite) setUpFreeLane(maxBlockSpace math.LegacyDec, expecte
return free.NewFreeLane(cfg, base.DefaultTxPriority(), free.DefaultMatchHandler())
}

func (s *ProposalsTestSuite) setUpPanicLane(maxBlockSpace math.LegacyDec) *base.BaseLane {
func (s *ProposalsTestSuite) setUpPanicLane(name string, maxBlockSpace math.LegacyDec) *base.BaseLane {
cfg := base.LaneConfig{
Logger: log.NewNopLogger(),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
Expand All @@ -126,7 +127,7 @@ func (s *ProposalsTestSuite) setUpPanicLane(maxBlockSpace math.LegacyDec) *base.

lane := base.NewBaseLane(
cfg,
"panic",
name,
base.NewMempool[string](base.DefaultTxPriority(), cfg.TxEncoder, cfg.SignerExtractor, 0),
base.DefaultMatchHandler(),
)
Expand All @@ -138,7 +139,8 @@ func (s *ProposalsTestSuite) setUpPanicLane(maxBlockSpace math.LegacyDec) *base.
}

func (s *ProposalsTestSuite) setUpProposalHandlers(lanes []block.Lane) *abci.ProposalHandler {
mempool := block.NewLanedMempool(log.NewNopLogger(), true, lanes...)
mempool, err := block.NewLanedMempool(log.NewNopLogger(), lanes)
s.Require().NoError(err)

return abci.NewProposalHandler(
log.NewNopLogger(),
Expand Down
9 changes: 0 additions & 9 deletions block/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
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 {
for _, ignoreMH := range ignoreMHs {
if ignoreMH(ctx, tx) {
return false
}
}

return mh(ctx, tx)
}
}
21 changes: 1 addition & 20 deletions block/base/lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +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 {
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
}

// SetAnteHandler sets the ante handler for the lane.
func (l *BaseLane) SetAnteHandler(anteHandler sdk.AnteHandler) {
l.cfg.AnteHandler = anteHandler
Expand Down
3 changes: 0 additions & 3 deletions block/lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,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)

// Match determines if a transaction belongs to this lane.
Match(ctx sdk.Context, tx sdk.Tx) bool

Expand Down
Loading

0 comments on commit fd8a786

Please sign in to comment.