Skip to content

Commit

Permalink
Merge branch 'main' into aljo242-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Johnson authored Nov 27, 2023
2 parents 58caa5d + 736b2d3 commit 1cf0ebf
Show file tree
Hide file tree
Showing 26 changed files with 1,310 additions and 948 deletions.
1 change: 1 addition & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"MD033": false,
"MD034": false,
"MD014": false,
"MD013": false,
"no-hard-tabs": false,
"whitespace": false
}
49 changes: 18 additions & 31 deletions abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import (

"github.com/skip-mev/block-sdk/block"
"github.com/skip-mev/block-sdk/block/proposals"
)

const (
// ProposalInfoIndex is the index of the proposal metadata in the proposal.
ProposalInfoIndex = 0
"github.com/skip-mev/block-sdk/block/utils"
)

type (
Expand Down Expand Up @@ -78,25 +74,17 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
return &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err
}

prepareLanesHandler := ChainPrepareLanes(registry)

// Fill the proposal with transactions from each lane.
prepareLanesHandler := ChainPrepareLanes(registry)
finalProposal, err := prepareLanesHandler(ctx, proposals.NewProposalWithContext(h.logger, ctx, h.txEncoder))
if err != nil {
h.logger.Error("failed to prepare proposal", "err", err)
return &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err
}

// Retrieve the proposal with metadata and transactions.
txs, err := finalProposal.GetProposalWithInfo()
if err != nil {
h.logger.Error("failed to get proposal with metadata", "err", err)
return &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err
}

h.logger.Info(
"prepared proposal",
"num_txs", len(txs),
"num_txs", len(finalProposal.Txs),
"total_tx_bytes", finalProposal.Info.BlockSize,
"max_tx_bytes", finalProposal.Info.MaxBlockSize,
"total_gas_limit", finalProposal.Info.GasLimit,
Expand All @@ -111,17 +99,17 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
)

return &abci.ResponsePrepareProposal{
Txs: txs,
Txs: finalProposal.Txs,
}, nil
}
}

// ProcessProposalHandler processes the proposal by verifying all transactions in the proposal
// according to each lane's verification logic. Proposals are verified similar to how they are
// constructed. After a proposal is processed, it should amount to the same proposal that was prepared.
// Each proposal will first be broken down by the lanes that prepared each partial proposal. Then, each
// lane will iteratively verify the transactions that it belong to it. If any lane fails to verify the
// transactions, then the proposal is rejected.
// The proposal is verified in a greedy fashion, respecting the ordering of lanes. A lane will
// verify all transactions in the proposal that belong to the lane and pass any remaining transactions
// to the next lane in the chain.
func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
return func(ctx sdk.Context, req *abci.RequestProcessProposal) (resp *abci.ResponseProcessProposal, err error) {
if req.Height <= 1 {
Expand All @@ -138,10 +126,10 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
}
}()

// Extract all of the lanes and their corresponding transactions from the proposal.
proposalInfo, partialProposals, err := h.ExtractLanes(ctx, req.Txs)
// Decode the transactions in the proposal. These will be verified by each lane in a greedy fashion.
decodedTxs, err := utils.GetDecodedTxs(h.txDecoder, req.Txs)
if err != nil {
h.logger.Error("failed to validate proposal", "err", err)
h.logger.Error("failed to decode txs", "err", err)
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
}

Expand All @@ -152,22 +140,21 @@ func (h *ProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHandler {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
}

processLanesHandler := ChainProcessLanes(partialProposals, registry)
finalProposal, err := processLanesHandler(ctx, proposals.NewProposalWithContext(h.logger, ctx, h.txEncoder))
// Verify the proposal.
processLanesHandler := ChainProcessLanes(registry)
finalProposal, err := processLanesHandler(
ctx,
proposals.NewProposalWithContext(h.logger, ctx, h.txEncoder),
decodedTxs,
)
if err != nil {
h.logger.Error("failed to validate the proposal", "err", err)
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
}

// Ensure block size and gas limit are correct.
if err := h.ValidateBlockLimits(finalProposal, proposalInfo); err != nil {
h.logger.Error("failed to validate the proposal", "err", err)
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err
}

h.logger.Info(
"processed proposal",
"num_txs", len(req.Txs),
"num_txs", len(finalProposal.Txs),
"total_tx_bytes", finalProposal.Info.BlockSize,
"max_tx_bytes", finalProposal.Info.MaxBlockSize,
"total_gas_limit", finalProposal.Info.GasLimit,
Expand Down
Loading

0 comments on commit 1cf0ebf

Please sign in to comment.