Skip to content

Commit

Permalink
feat(MEV): Updating MEV Lane with Testing + Cleaner Implementation (#134
Browse files Browse the repository at this point in the history
)

* updating mev lane with cleaner impl

* nit

* lint

(cherry picked from commit d495b38)

# Conflicts:
#	block/mocks/lane.go
#	lanes/mev/mev_test.go
#	tests/integration/block_sdk_suite.go
  • Loading branch information
davidterpay authored and mergify[bot] committed Oct 4, 2023
1 parent 9f477a0 commit ffd638a
Show file tree
Hide file tree
Showing 10 changed files with 973 additions and 321 deletions.
7 changes: 0 additions & 7 deletions abci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func ChainPrepareLanes(chain []block.Lane) block.PrepareLanesHandler {

return func(ctx sdk.Context, partialProposal proposals.Proposal) (finalProposal proposals.Proposal, err error) {
lane := chain[0]
lane.Logger().Info("preparing lane", "lane", lane.Name())

// Cache the context in the case where any of the lanes fail to prepare the proposal.
cacheCtx, write := ctx.CacheContext()
Expand All @@ -35,9 +34,6 @@ func ChainPrepareLanes(chain []block.Lane) block.PrepareLanesHandler {
// and call the next lane in the chain to the prepare the proposal.
defer func() {
if rec := recover(); rec != nil || err != nil {
lane.Logger().Error("failed to prepare lane", "lane", lane.Name(), "err", err, "recover_error", rec)
lane.Logger().Info("skipping lane", "lane", lane.Name())

if len(chain) <= 2 {
// If there are only two lanes remaining, then the first lane in the chain
// is the lane that failed to prepare the partial proposal and the second lane in the
Expand Down Expand Up @@ -85,9 +81,6 @@ func ChainProcessLanes(partialProposals [][][]byte, chain []block.Lane) block.Pr
return func(ctx sdk.Context, proposal proposals.Proposal) (proposals.Proposal, error) {
lane := chain[0]
partialProposal := partialProposals[0]

lane.Logger().Info("processing lane", "lane", chain[0].Name())

return lane.ProcessLane(ctx, proposal, partialProposal, ChainProcessLanes(partialProposals[1:], chain[1:]))
}
}
18 changes: 17 additions & 1 deletion block/base/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ func (l *BaseLane) PrepareLane(
proposal proposals.Proposal,
next block.PrepareLanesHandler,
) (proposals.Proposal, error) {
limit := proposal.GetLaneLimits(l.cfg.MaxBlockSpace)
l.Logger().Info("preparing lane", "lane", l.Name())

// Select transactions from the lane respecting the selection logic of the lane and the
// max block space for the lane.
limit := proposal.GetLaneLimits(l.cfg.MaxBlockSpace)
txsToInclude, txsToRemove, err := l.prepareLaneHandler(ctx, proposal, limit)
if err != nil {
l.Logger().Error(
"failed to prepare lane",
"lane", l.Name(),
"err", err,
)

return proposal, err
}

Expand Down Expand Up @@ -67,6 +74,8 @@ func (l *BaseLane) ProcessLane(
txs [][]byte,
next block.ProcessLanesHandler,
) (proposals.Proposal, error) {
l.Logger().Info("processing lane", "lane", l.Name(), "num_txs_to_verify", len(txs))

// Assume that this lane is processing sdk.Tx's and decode the transactions.
decodedTxs, err := utils.GetDecodedTxs(l.TxDecoder(), txs)
if err != nil {
Expand All @@ -81,6 +90,13 @@ func (l *BaseLane) ProcessLane(

// Verify the transactions that belong to this lane according to the verification logic of the lane.
if err := l.processLaneHandler(ctx, decodedTxs); err != nil {
l.Logger().Error(
"failed to process lane",
"lane", l.Name(),
"err", err,
"num_txs_to_verify", len(decodedTxs),
)

return proposal, err
}

Expand Down
3 changes: 0 additions & 3 deletions block/lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ type Lane interface {
// GetMaxBlockSpace returns the max block space for the lane as a relative percentage.
GetMaxBlockSpace() math.LegacyDec

// Logger returns the lane's logger.
Logger() log.Logger

// Name returns the name of the lane.
Name() string

Expand Down
19 changes: 3 additions & 16 deletions block/mocks/lane.go

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

Loading

0 comments on commit ffd638a

Please sign in to comment.