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

Commit

Permalink
fix: Removing IgnoreList from Lane Interface (#245)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
davidterpay authored and mergify[bot] committed Nov 29, 2023
1 parent 8570a2e commit 50c5615
Show file tree
Hide file tree
Showing 17 changed files with 708 additions and 131 deletions.
136 changes: 136 additions & 0 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,38 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

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

chainLanes := []blocksdkmoduletypes.Lane{
{
Id: panicLane.Name(),
MaxBlockSpace: panicLane.GetMaxBlockSpace(),
Order: 0,
},
{
Id: defaultLane.Name(),
MaxBlockSpace: defaultLane.GetMaxBlockSpace(),
Order: 1,
},
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
}, func() []blocksdkmoduletypes.Lane {
return chainLanes
}),
)
s.Require().NoError(err)
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand Down Expand Up @@ -540,7 +571,38 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

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

chainLanes := []blocksdkmoduletypes.Lane{
{
Id: panicLane.Name(),
MaxBlockSpace: panicLane.GetMaxBlockSpace(),
Order: 1,
},
{
Id: defaultLane.Name(),
MaxBlockSpace: defaultLane.GetMaxBlockSpace(),
Order: 0,
},
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
}, func() []blocksdkmoduletypes.Lane {
return chainLanes
}),
)
s.Require().NoError(err)
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand Down Expand Up @@ -577,7 +639,44 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

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

chainLanes := []blocksdkmoduletypes.Lane{
{
Id: panicLane.Name(),
MaxBlockSpace: panicLane.GetMaxBlockSpace(),
Order: 0,
},
{
Id: panicLane2.Name(),
MaxBlockSpace: panicLane2.GetMaxBlockSpace(),
Order: 1,
},
{
Id: defaultLane.Name(),
MaxBlockSpace: defaultLane.GetMaxBlockSpace(),
Order: 2,
},
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
}, func() []blocksdkmoduletypes.Lane {
return chainLanes
}),
)
s.Require().NoError(err)
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand Down Expand Up @@ -614,7 +713,44 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
})
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

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

chainLanes := []blocksdkmoduletypes.Lane{
{
Id: panicLane.Name(),
MaxBlockSpace: panicLane.GetMaxBlockSpace(),
Order: 1,
},
{
Id: panicLane2.Name(),
MaxBlockSpace: panicLane2.GetMaxBlockSpace(),
Order: 2,
},
{
Id: defaultLane.Name(),
MaxBlockSpace: defaultLane.GetMaxBlockSpace(),
Order: 0,
},
}

mempool, err := block.NewLanedMempool(
log.NewNopLogger(),
lanes,
mocks.NewMockLaneFetcher(func() (blocksdkmoduletypes.Lane, error) {
return blocksdkmoduletypes.Lane{}, nil
}, func() []blocksdkmoduletypes.Lane {
return chainLanes
}),
)
s.Require().NoError(err)
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

proposalHandler := abci.NewProposalHandler(
log.NewTMLogger(os.Stdout),
Expand Down
5 changes: 3 additions & 2 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 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 @@ -171,3 +171,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)
}
}
7 changes: 7 additions & 0 deletions block/base/lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +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 {
<<<<<<< HEAD

Check failure on line 124 in block/base/lane.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected statement, found '<<' (typecheck)
return l.matchHandler(ctx, tx) && !l.CheckIgnoreList(ctx, tx)
}

Expand All @@ -135,19 +136,25 @@ func (l *BaseLane) CheckIgnoreList(ctx sdk.Context, tx sdk.Tx) bool {
}

return false
=======

Check failure on line 139 in block/base/lane.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected statement, found '==' (typecheck)
return l.matchHandler(ctx, tx)
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

Check failure on line 141 in block/base/lane.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected statement, found '>>' (typecheck)
}

// Name returns the name of the lane.
func (l *BaseLane) Name() string {
return l.laneName
}

<<<<<<< HEAD
// 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
}

=======
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))
// SetAnteHandler sets the ante handler for the lane.
func (l *BaseLane) SetAnteHandler(anteHandler sdk.AnteHandler) {
l.cfg.AnteHandler = anteHandler
Expand Down
3 changes: 3 additions & 0 deletions block/lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ type Lane interface {
// SetAnteHandler sets the lane's antehandler.
SetAnteHandler(antehander sdk.AnteHandler)

<<<<<<< HEAD

Check failure on line 66 in block/lane.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected '}', found '<<' (typecheck)
// SetIgnoreList sets the lanes that should be ignored by this lane.
SetIgnoreList(ignoreList []Lane)

=======
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

Check failure on line 71 in block/lane.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)
// Match determines if a transaction belongs to this lane.
Match(ctx sdk.Context, tx sdk.Tx) bool
}
18 changes: 18 additions & 0 deletions block/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/cometbft/cometbft/libs/log"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
<<<<<<< HEAD

Check failure on line 12 in block/mempool.go

View workflow job for this annotation

GitHub Actions / golangci-lint

missing import path (typecheck)

Check failure on line 12 in block/mempool.go

View workflow job for this annotation

GitHub Actions / test

missing import path

Check failure on line 12 in block/mempool.go

View workflow job for this annotation

GitHub Actions / test-integration

missing import path

Check failure on line 12 in block/mempool.go

View workflow job for this annotation

GitHub Actions / test-integration

missing import path
=======

Check failure on line 13 in block/mempool.go

View workflow job for this annotation

GitHub Actions / golangci-lint

missing import path (typecheck)

blocksdkmoduletypes "github.com/skip-mev/block-sdk/x/blocksdk/types"
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

Check failure on line 16 in block/mempool.go

View workflow job for this annotation

GitHub Actions / golangci-lint

missing import path (typecheck)
)

var _ Mempool = (*LanedMempool)(nil)
Expand Down Expand Up @@ -40,6 +45,7 @@ type (
}
)

<<<<<<< HEAD

Check failure on line 48 in block/mempool.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected declaration, found '<<' (typecheck)
// NewLanedMempool returns a new Block SDK LanedMempool. The laned mempool is
// comprised of a registry of lanes. Each lane is responsible for selecting
// transactions according to its own selection logic. The lanes are ordered
Expand All @@ -52,6 +58,18 @@ type (
// 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, lanes ...Lane) Mempool {
=======
// 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.
func NewLanedMempool(
logger log.Logger,
lanes []Lane,
laneFetcher LaneFetcher,
) (*LanedMempool, error) {
>>>>>>> b91cfb6 (fix: Removing IgnoreList from Lane Interface (#245))

Check failure on line 72 in block/mempool.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)
mempool := &LanedMempool{
logger: logger,
registry: lanes,
Expand Down
Loading

0 comments on commit 50c5615

Please sign in to comment.