rename of constructor to base

This commit is contained in:
David Terpay
2023-08-15 18:01:49 -04:00
parent bf4e3b8af2
commit af2b5226f3
22 changed files with 147 additions and 147 deletions
@@ -1,10 +1,10 @@
# 🎨 Lane Constructor
# 🎨 Base Lane
> 🏗️ Build your own lane in less than 10 minutes using the Lane Constructor
> 🏗️ Build your own lane in less than 10 minutes using the Base Lane
## 💡 Overview
The Lane Constructor is a generic implementation of a lane. It comes out of the
The Base Lane is a generic implementation of a lane. It comes out of the
box with default implementations for all the required interfaces. It is meant to
be used as a starting point for building your own lane.
@@ -13,7 +13,7 @@ be used as a starting point for building your own lane.
> **Default Implementations**
>
> There are default implementations for all of the below which can be found in
> the `block/constructor` package. It is highly recommended that developers overview
> the `block/base` package. It is highly recommended that developers overview
> the default implementations before building their own lane.
There are **three** critical components to building a custom lane using the lane
@@ -128,7 +128,7 @@ transactions by default).
### 2. 🗄️ LaneMempool
This is the data structure that is responsible for storing transactions
as they are being verified and are waiting to be included in proposals. `block/constructor/mempool.go`
as they are being verified and are waiting to be included in proposals. `block/base/mempool.go`
provides an out-of-the-box implementation that should be used as a starting
point for building out the mempool and should cover most use cases. To
utilize the mempool, you must implement a `TxPriority[C]` struct that does the
@@ -143,7 +143,7 @@ should return 1, otherwise the method should return 0.
* Implements a `MinValue` method that returns the minimum priority value
that a transaction can have.
The default implementation can be found in `block/constructor/mempool.go`. What
The default implementation can be found in `block/base/mempool.go`. What
if we wanted to prioritize transactions by the amount they have staked on a chain?
Well we could do something like the following:
@@ -228,7 +228,7 @@ mempool := constructor.NewMempool[string](
)
// Initialize your lane with the mempool
lane := constructor.NewLaneConstructor(
lane := constructor.NewBaseLane(
laneCfg,
LaneName,
mempool,
@@ -240,7 +240,7 @@ lane := constructor.NewLaneConstructor(
`MatchHandler` is utilized to determine if a transaction should be included in
the lane. This function can be a stateless or stateful check on the transaction.
The default implementation can be found in `block/constructor/handlers.go`.
The default implementation can be found in `block/base/handlers.go`.
The match handler can be as custom as desired. Following the example above, if
we wanted to make a lane that only accepts transactions if they have a large
@@ -298,7 +298,7 @@ mempool := constructor.NewMempool[string](
)
// Initialize your lane with the mempool
lane := constructor.NewLaneConstructor(
lane := constructor.NewBaseLane(
cfg,
LaneName,
mempool,
@@ -319,7 +319,7 @@ have a custom lane that only accepts transactions that match a custom criteria.
### [OPTIONAL] Steps 4-6
The remaining steps walk through the process of creating custom block
building/verification logic. The default implementation found in `block/constructor/handlers.go`
building/verification logic. The default implementation found in `block/base/handlers.go`
should fit most use cases. Please reference that file for more details on
the default implementation and whether it fits your use case.
@@ -1,4 +1,4 @@
package constructor
package base
import (
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -10,7 +10,7 @@ import (
// lane respecting the selection logic of the prepareLaneHandler. It will then update the partial
// proposal with the selected transactions. If the proposal is unable to be updated, we return an
// error. The proposal will only be modified if it passes all of the invarient checks.
func (l *LaneConstructor) PrepareLane(
func (l *BaseLane) PrepareLane(
ctx sdk.Context,
proposal block.BlockProposal,
maxTxBytes int64,
@@ -40,7 +40,7 @@ func (l *LaneConstructor) PrepareLane(
// CheckOrder checks that the ordering logic of the lane is respected given the set of transactions
// in the block proposal. If the ordering logic is not respected, we return an error.
func (l *LaneConstructor) CheckOrder(ctx sdk.Context, txs []sdk.Tx) error {
func (l *BaseLane) CheckOrder(ctx sdk.Context, txs []sdk.Tx) error {
return l.checkOrderHandler(ctx, txs)
}
@@ -48,7 +48,7 @@ func (l *LaneConstructor) CheckOrder(ctx sdk.Context, txs []sdk.Tx) error {
// the verification logic of the lane (processLaneHandler). If the transactions are valid, we
// return the transactions that do not belong to this lane to the next lane. If the transactions
// are invalid, we return an error.
func (l *LaneConstructor) ProcessLane(ctx sdk.Context, txs []sdk.Tx, next block.ProcessLanesHandler) (sdk.Context, error) {
func (l *BaseLane) ProcessLane(ctx sdk.Context, txs []sdk.Tx, next block.ProcessLanesHandler) (sdk.Context, error) {
remainingTxs, err := l.processLaneHandler(ctx, txs)
if err != nil {
return ctx, err
@@ -59,7 +59,7 @@ func (l *LaneConstructor) ProcessLane(ctx sdk.Context, txs []sdk.Tx, next block.
// AnteVerifyTx verifies that the transaction is valid respecting the ante verification logic of
// of the antehandler chain.
func (l *LaneConstructor) AnteVerifyTx(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
func (l *BaseLane) AnteVerifyTx(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
if l.cfg.AnteHandler != nil {
return l.cfg.AnteHandler(ctx, tx, simulate)
}
@@ -1,4 +1,4 @@
package constructor
package base
import (
"fmt"
@@ -1,4 +1,4 @@
package constructor
package base
import (
"fmt"
@@ -12,7 +12,7 @@ import (
// selects all transactions in the mempool that are valid and not already in the partial
// proposal. It will continue to reap transactions until the maximum block space for this
// lane has been reached. Additionally, any transactions that are invalid will be returned.
func (l *LaneConstructor) DefaultPrepareLaneHandler() block.PrepareLaneHandler {
func (l *BaseLane) DefaultPrepareLaneHandler() block.PrepareLaneHandler {
return func(ctx sdk.Context, proposal block.BlockProposal, maxTxBytes int64) ([][]byte, []sdk.Tx, error) {
var (
totalSize int64
@@ -96,7 +96,7 @@ func (l *LaneConstructor) DefaultPrepareLaneHandler() block.PrepareLaneHandler {
// fails to verify, the entire proposal is rejected. If the handler comes across a transaction
// that does not match the lane's matcher, it will return the remaining transactions in the
// proposal.
func (l *LaneConstructor) DefaultProcessLaneHandler() block.ProcessLaneHandler {
func (l *BaseLane) DefaultProcessLaneHandler() block.ProcessLaneHandler {
return func(ctx sdk.Context, txs []sdk.Tx) ([]sdk.Tx, error) {
var err error
@@ -123,7 +123,7 @@ func (l *LaneConstructor) DefaultProcessLaneHandler() block.ProcessLaneHandler {
// lane.
// 2. Transactions that belong to other lanes cannot be interleaved with transactions that
// belong to this lane.
func (l *LaneConstructor) DefaultCheckOrderHandler() block.CheckOrderHandler {
func (l *BaseLane) DefaultCheckOrderHandler() block.CheckOrderHandler {
return func(ctx sdk.Context, txs []sdk.Tx) error {
seenOtherLaneTx := false
@@ -1,4 +1,4 @@
package constructor
package base
import (
"fmt"
@@ -9,14 +9,14 @@ import (
"github.com/skip-mev/pob/block"
)
var _ block.Lane = (*LaneConstructor)(nil)
var _ block.Lane = (*BaseLane)(nil)
// LaneConstructor is a generic implementation of a lane. It is meant to be used
// BaseLane is a generic implementation of a lane. It is meant to be used
// as a base for other lanes to be built on top of. It provides a default
// implementation of the MatchHandler, PrepareLaneHandler, ProcessLaneHandler,
// and CheckOrderHandler. To extend this lane, you must either utilize the default
// handlers or construct your own that you pass into the constructor/setters.
type LaneConstructor struct {
// handlers or construct your own that you pass into the base/setters.
type BaseLane struct {
// cfg stores functionality required to encode/decode transactions, maintains how
// many transactions are allowed in this lane's mempool, and the amount of block
// space this lane is allowed to consume.
@@ -48,16 +48,16 @@ type LaneConstructor struct {
processLaneHandler block.ProcessLaneHandler
}
// NewLaneConstructor returns a new lane constructor. When creating this lane, the type
// NewBaseLane returns a new lane base. When creating this lane, the type
// of the lane must be specified. The type of the lane is directly associated with the
// type of the mempool that is used to store transactions that are waiting to be processed.
func NewLaneConstructor(
func NewBaseLane(
cfg LaneConfig,
laneName string,
laneMempool block.LaneMempool,
matchHandlerFn block.MatchHandler,
) *LaneConstructor {
lane := &LaneConstructor{
) *BaseLane {
lane := &BaseLane{
cfg: cfg,
laneName: laneName,
LaneMempool: laneMempool,
@@ -73,7 +73,7 @@ func NewLaneConstructor(
// ValidateBasic ensures that the lane was constructed properly. In the case that
// the lane was not constructed with proper handlers, default handlers are set.
func (l *LaneConstructor) ValidateBasic() error {
func (l *BaseLane) ValidateBasic() error {
if err := l.cfg.ValidateBasic(); err != nil {
return err
}
@@ -108,7 +108,7 @@ func (l *LaneConstructor) ValidateBasic() error {
// SetPrepareLaneHandler sets the prepare lane handler for the lane. This handler
// is called when a new proposal is being requested and the lane needs to submit
// transactions it wants included in the block.
func (l *LaneConstructor) SetPrepareLaneHandler(prepareLaneHandler block.PrepareLaneHandler) {
func (l *BaseLane) SetPrepareLaneHandler(prepareLaneHandler block.PrepareLaneHandler) {
if prepareLaneHandler == nil {
panic("prepare lane handler cannot be nil")
}
@@ -120,7 +120,7 @@ func (l *LaneConstructor) SetPrepareLaneHandler(prepareLaneHandler block.Prepare
// is called when a new proposal is being verified and the lane needs to verify
// that the transactions included in the proposal are valid respecting the verification
// logic of the lane.
func (l *LaneConstructor) SetProcessLaneHandler(processLaneHandler block.ProcessLaneHandler) {
func (l *BaseLane) SetProcessLaneHandler(processLaneHandler block.ProcessLaneHandler) {
if processLaneHandler == nil {
panic("process lane handler cannot be nil")
}
@@ -132,7 +132,7 @@ func (l *LaneConstructor) SetProcessLaneHandler(processLaneHandler block.Process
// is called when a new proposal is being verified and the lane needs to verify
// that the transactions included in the proposal respect the ordering rules of
// the lane and does not include transactions from other lanes.
func (l *LaneConstructor) SetCheckOrderHandler(checkOrderHandler block.CheckOrderHandler) {
func (l *BaseLane) SetCheckOrderHandler(checkOrderHandler block.CheckOrderHandler) {
if checkOrderHandler == nil {
panic("check order handler cannot be nil")
}
@@ -144,14 +144,14 @@ func (l *LaneConstructor) SetCheckOrderHandler(checkOrderHandler block.CheckOrde
// function first determines if the transaction matches the lane and then checks
// if the transaction is on the ignore list. If the transaction is on the ignore
// list, it returns false.
func (l *LaneConstructor) Match(ctx sdk.Context, tx sdk.Tx) bool {
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 *LaneConstructor) CheckIgnoreList(ctx sdk.Context, tx sdk.Tx) bool {
func (l *BaseLane) CheckIgnoreList(ctx sdk.Context, tx sdk.Tx) bool {
for _, lane := range l.cfg.IgnoreList {
if lane.Match(ctx, tx) {
return true
@@ -162,38 +162,38 @@ func (l *LaneConstructor) CheckIgnoreList(ctx sdk.Context, tx sdk.Tx) bool {
}
// Name returns the name of the lane.
func (l *LaneConstructor) Name() string {
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 *LaneConstructor) SetIgnoreList(lanes []block.Lane) {
func (l *BaseLane) SetIgnoreList(lanes []block.Lane) {
l.cfg.IgnoreList = lanes
}
// SetAnteHandler sets the ante handler for the lane.
func (l *LaneConstructor) SetAnteHandler(anteHandler sdk.AnteHandler) {
func (l *BaseLane) SetAnteHandler(anteHandler sdk.AnteHandler) {
l.cfg.AnteHandler = anteHandler
}
// Logger returns the logger for the lane.
func (l *LaneConstructor) Logger() log.Logger {
func (l *BaseLane) Logger() log.Logger {
return l.cfg.Logger
}
// TxDecoder returns the tx decoder for the lane.
func (l *LaneConstructor) TxDecoder() sdk.TxDecoder {
func (l *BaseLane) TxDecoder() sdk.TxDecoder {
return l.cfg.TxDecoder
}
// TxEncoder returns the tx encoder for the lane.
func (l *LaneConstructor) TxEncoder() sdk.TxEncoder {
func (l *BaseLane) TxEncoder() sdk.TxEncoder {
return l.cfg.TxEncoder
}
// GetMaxBlockSpace returns the maximum amount of block space that the lane is
// allowed to consume as a percentage of the total block space.
func (l *LaneConstructor) GetMaxBlockSpace() math.LegacyDec {
func (l *BaseLane) GetMaxBlockSpace() math.LegacyDec {
return l.cfg.MaxBlockSpace
}
@@ -1,4 +1,4 @@
package constructor
package base
import (
"context"
@@ -1,4 +1,4 @@
package constructor
package base
// ------------------------------------------------------------------------------ //
// ------------------------------------------------------------------------------ //
+8 -8
View File
@@ -11,10 +11,10 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/skip-mev/pob/block"
"github.com/skip-mev/pob/block/constructor"
"github.com/skip-mev/pob/lanes/base"
"github.com/skip-mev/pob/block/base"
"github.com/skip-mev/pob/lanes/free"
"github.com/skip-mev/pob/lanes/mev"
"github.com/skip-mev/pob/lanes/standard"
testutils "github.com/skip-mev/pob/testutils"
buildertypes "github.com/skip-mev/pob/x/builder/types"
"github.com/stretchr/testify/suite"
@@ -29,7 +29,7 @@ type BlockBusterTestSuite struct {
// Define all of the lanes utilized in the test suite
mevLane *mev.MEVLane
baseLane *base.DefaultLane
baseLane *standard.StandardLane
freeLane *free.FreeLane
gasTokenDenom string
@@ -58,7 +58,7 @@ func (suite *BlockBusterTestSuite) SetupTest() {
//
// TOB lane set up
suite.gasTokenDenom = "stake"
mevConfig := constructor.LaneConfig{
mevConfig := base.LaneConfig{
Logger: log.NewNopLogger(),
TxEncoder: suite.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: suite.encodingConfig.TxConfig.TxDecoder(),
@@ -71,7 +71,7 @@ func (suite *BlockBusterTestSuite) SetupTest() {
)
// Free lane set up
freeConfig := constructor.LaneConfig{
freeConfig := base.LaneConfig{
Logger: log.NewNopLogger(),
TxEncoder: suite.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: suite.encodingConfig.TxConfig.TxDecoder(),
@@ -80,19 +80,19 @@ func (suite *BlockBusterTestSuite) SetupTest() {
}
suite.freeLane = free.NewFreeLane(
freeConfig,
constructor.DefaultTxPriority(),
base.DefaultTxPriority(),
free.DefaultMatchHandler(),
)
// Base lane set up
baseConfig := constructor.LaneConfig{
baseConfig := base.LaneConfig{
Logger: log.NewNopLogger(),
TxEncoder: suite.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: suite.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: nil,
MaxBlockSpace: math.LegacyZeroDec(),
}
suite.baseLane = base.NewDefaultLane(
suite.baseLane = standard.NewStandardLane(
baseConfig,
)