Skip to content

Commit

Permalink
chore: Update Lane Specific Readmes (backport #254) (#256)
Browse files Browse the repository at this point in the history
* chore: Update Lane Specific Readmes (#254)

* nits

* e2e shorter testing time

(cherry picked from commit 4bfb7ce)

# Conflicts:
#	abci/abci.go
#	lanes/base/abci_test.go
#	lanes/build-your-own/README.md
#	lanes/mev/abci_test.go
#	lanes/terminator/lane.go

* lint fix

* read me fix

---------

Co-authored-by: David Terpay <[email protected]>
Co-authored-by: David Terpay <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2023
1 parent 9a5e972 commit 9ec6c91
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 150 deletions.
4 changes: 2 additions & 2 deletions abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
)

// Fill the proposal with transactions from each lane.
finalProposal, err := h.prepareLanesHandler(ctx, proposals.NewProposalWithContext(h.logger, ctx, h.txEncoder))
finalProposal, err := h.prepareLanesHandler(ctx, proposals.NewProposalWithContext(ctx, h.logger))
if err != nil {
h.logger.Error("failed to prepare proposal", "err", err)
return &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err
Expand Down Expand Up @@ -130,7 +130,7 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {

// Build handler that will verify the partial proposals according to each lane's verification logic.
processLanesHandler := ChainProcessLanes(h.mempool.Registry())
finalProposal, err := processLanesHandler(ctx, proposals.NewProposalWithContext(h.logger, ctx, h.txEncoder), decodedTxs)
finalProposal, err := processLanesHandler(ctx, proposals.NewProposalWithContext(ctx, h.logger), decodedTxs)
if err != nil {
h.logger.Error("failed to validate the proposal", "err", err)
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
Expand Down
15 changes: 6 additions & 9 deletions block/proposals/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@ type (
Txs [][]byte
// Cache is a cache of the selected transactions in the proposal.
Cache map[string]struct{}
// TxEncoder is the transaction encoder.
TxEncoder sdk.TxEncoder
// Info contains information about the state of the proposal.
Info types.ProposalInfo
}
)

// NewProposalWithContext returns a new empty proposal.
func NewProposalWithContext(logger log.Logger, ctx sdk.Context, txEncoder sdk.TxEncoder) Proposal {
func NewProposalWithContext(ctx sdk.Context, logger log.Logger) Proposal {
maxBlockSize, maxGasLimit := GetBlockLimits(ctx)
return NewProposal(logger, txEncoder, maxBlockSize, maxGasLimit)
return NewProposal(logger, maxBlockSize, maxGasLimit)
}

// NewProposal returns a new empty proposal. Any transactions added to the proposal
// will be subject to the given max block size and max gas limit.
func NewProposal(logger log.Logger, txEncoder sdk.TxEncoder, maxBlockSize int64, maxGasLimit uint64) Proposal {
func NewProposal(logger log.Logger, maxBlockSize int64, maxGasLimit uint64) Proposal {
return Proposal{
Logger: logger,
TxEncoder: txEncoder,
Txs: make([][]byte, 0),
Cache: make(map[string]struct{}),
Logger: logger,
Txs: make([][]byte, 0),
Cache: make(map[string]struct{}),
Info: types.ProposalInfo{
TxsByLane: make(map[string]uint64),
MaxBlockSize: maxBlockSize,
Expand Down
20 changes: 10 additions & 10 deletions block/proposals/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestUpdateProposal(t *testing.T) {
lane.On("GetMaxBlockSpace").Return(math.LegacyNewDec(1)).Maybe()

t.Run("can update with no transactions", func(t *testing.T) {
proposal := proposals.NewProposal(log.NewTestLogger(t), nil, 100, 100)
proposal := proposals.NewProposal(log.NewTestLogger(t), 100, 100)

err := proposal.UpdateProposal(lane, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestUpdateProposal(t *testing.T) {

size := len(txBzs[0])
gasLimit := 100
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
proposal := proposals.NewProposal(log.NewTestLogger(t), int64(size), uint64(gasLimit))

txsWithInfo, err := getTxsWithInfo([]sdk.Tx{tx})
require.NoError(t, err)
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestUpdateProposal(t *testing.T) {
gasLimit += 100
}

proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), gasLimit)
proposal := proposals.NewProposal(log.NewTestLogger(t), int64(size), gasLimit)

txsWithInfo, err := getTxsWithInfo(txs)
require.NoError(t, err)
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestUpdateProposal(t *testing.T) {

size := int64(len(txBzs[0]))
gasLimit := uint64(100)
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), size, gasLimit)
proposal := proposals.NewProposal(log.NewTestLogger(t), size, gasLimit)

txsWithInfo, err := getTxsWithInfo([]sdk.Tx{tx})
require.NoError(t, err)
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestUpdateProposal(t *testing.T) {

size := len(txBzs[0]) + len(txBzs[1])
gasLimit := 200
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
proposal := proposals.NewProposal(log.NewTestLogger(t), int64(size), uint64(gasLimit))

txsWithInfo, err := getTxsWithInfo([]sdk.Tx{tx})
require.NoError(t, err)
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestUpdateProposal(t *testing.T) {

size := len(txBzs[0])
gasLimit := 100
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
proposal := proposals.NewProposal(log.NewTestLogger(t), int64(size), uint64(gasLimit))

lane := mocks.NewLane(t)

Expand Down Expand Up @@ -304,7 +304,7 @@ func TestUpdateProposal(t *testing.T) {

size := len(txBzs[0])
gasLimit := 100
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit))
proposal := proposals.NewProposal(log.NewTestLogger(t), int64(size), uint64(gasLimit))

lane := mocks.NewLane(t)

Expand Down Expand Up @@ -345,7 +345,7 @@ func TestUpdateProposal(t *testing.T) {

size := len(txBzs[0])
gasLimit := 100
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size)-1, uint64(gasLimit))
proposal := proposals.NewProposal(log.NewTestLogger(t), int64(size)-1, uint64(gasLimit))

txsWithInfo, err := getTxsWithInfo([]sdk.Tx{tx})
require.NoError(t, err)
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestUpdateProposal(t *testing.T) {

size := len(txBzs[0])
gasLimit := 100
proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), int64(size), uint64(gasLimit)-1)
proposal := proposals.NewProposal(log.NewTestLogger(t), int64(size), uint64(gasLimit)-1)

txsWithInfo, err := getTxsWithInfo([]sdk.Tx{tx})
require.NoError(t, err)
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestUpdateProposal(t *testing.T) {
txBzs, err := utils.GetEncodedTxs(encodingConfig.TxConfig.TxEncoder(), []sdk.Tx{tx, tx2})
require.NoError(t, err)

proposal := proposals.NewProposal(log.NewTestLogger(t), encodingConfig.TxConfig.TxEncoder(), 10000, 10000)
proposal := proposals.NewProposal(log.NewTestLogger(t), 10000, 10000)

txsWithInfo, err := getTxsWithInfo([]sdk.Tx{tx})
require.NoError(t, err)
Expand Down
11 changes: 6 additions & 5 deletions lanes/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ $ go install github.com/skip-mev/block-sdk

## 📚 Usage

> Note: Please visit [app.go](../../tests/app/lanes.go) to see a sample base app set up.
1. First determine the set of lanes that you want to use in your application. The
available lanes can be found in our
[Lane App Store](https://docs.skip.money/chains/lanes/existing-lanes/default).
Expand Down Expand Up @@ -45,8 +47,7 @@ func NewApp() {
// 1. Create the lanes.
//
// NOTE: The lanes are ordered by priority. The first lane is the highest priority
// lane and the last lane is the lowest priority lane. Top of block lane allows
// transactions to bid for inclusion at the top of the next block.
// lane and the last lane is the lowest priority lane.
//
// For more information on how to utilize the LaneConfig please
// visit the README in docs.skip.money/chains/lanes/build-your-own-lane#-lane-config.
Expand All @@ -57,15 +58,15 @@ func NewApp() {
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyZeroDec(),
MaxTxs: 0,
MaxTxs: 5000,
}
defaultLane := defaultlane.NewDefaultLane(defaultConfig)
defaultLane := defaultlane.NewDefaultLane(defaultConfig, base.DefaultMatchHandler())

// 2. Set up the relative priority of lanes
lanes := []block.Lane{
defaultLane,
}
mempool := block.NewLanedMempool(app.Logger(), true, lanes...)
mempool := block.NewLanedMempool(app.Logger(), lanes)
app.App.SetMempool(mempool)

...
Expand Down
Loading

0 comments on commit 9ec6c91

Please sign in to comment.