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
) (#139)

* updating mev lane with cleaner impl

* nit

* lint

(cherry picked from commit d495b38)

Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com>
  • Loading branch information
mergify[bot] and davidterpay committed Oct 4, 2023
1 parent 18e8e25 commit 2a697cc
Show file tree
Hide file tree
Showing 10 changed files with 1,022 additions and 404 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 @@ -17,12 +17,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 @@ -68,6 +75,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 @@ -82,6 +91,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
4 changes: 0 additions & 4 deletions block/lane.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package block

import (
"cosmossdk.io/log"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
Expand Down Expand Up @@ -57,9 +56,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
18 changes: 0 additions & 18 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 2a697cc

Please sign in to comment.