Skip to content

Commit

Permalink
chore: Default Process Proposal (#543)
Browse files Browse the repository at this point in the history
* init

* nits

(cherry picked from commit 79d7ef7)

# Conflicts:
#	abci/abci.go
  • Loading branch information
davidterpay authored and mergify[bot] committed Jun 25, 2024
1 parent e56839b commit 176b162
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
48 changes: 45 additions & 3 deletions abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/skip-mev/block-sdk/v2/block"
"github.com/skip-mev/block-sdk/v2/block/proposals"
"github.com/skip-mev/block-sdk/v2/block/utils"
Expand All @@ -16,28 +17,65 @@ type (
// ProposalHandler is a wrapper around the ABCI++ PrepareProposal and ProcessProposal
// handlers.
ProposalHandler struct {
<<<<<<< HEAD

Check failure on line 20 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expected field name or embedded type

Check failure on line 20 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-integration

expected '}', found '<<'

Check failure on line 20 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected '}', found '<<'

Check failure on line 20 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected ';', found '<<'

Check failure on line 20 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: unexpected <<, expected field name or embedded type

Check failure on line 20 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: unexpected <<, expected field name or embedded type

Check failure on line 20 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: unexpected <<, expected field name or embedded type
logger log.Logger
txDecoder sdk.TxDecoder
txEncoder sdk.TxEncoder
prepareLanesHandler block.PrepareLanesHandler
mempool block.Mempool
=======

Check failure on line 26 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ==, expected field name or embedded type

Check failure on line 26 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: unexpected ==, expected field name or embedded type

Check failure on line 26 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: unexpected ==, expected field name or embedded type

Check failure on line 26 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: unexpected ==, expected field name or embedded type
logger log.Logger
txDecoder sdk.TxDecoder
txEncoder sdk.TxEncoder
mempool block.Mempool
useCustomProcessProposal bool
>>>>>>> 79d7ef7 (chore: Default Process Proposal (#543))

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#'

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-integration

illegal character U+0023 '#'

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

illegal character U+0023 '#'

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

invalid character U+0023 '#'

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

invalid character U+0023 '#'

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: unexpected >>, expected field name or embedded type

Check failure on line 32 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

invalid character U+0023 '#'
}
)

// NewProposalHandler returns a new ABCI++ proposal handler. This proposal handler will
// iteratively call each of the lanes in the chain to prepare and process the proposal.
func NewProposalHandler(
// NewDefaultProposalHandler returns a new ABCI++ proposal handler. This proposal handler will
// iteratively call each of the lanes in the chain to prepare and process the proposal. This
// will not use custom process proposal logic.
func NewDefaultProposalHandler(
logger log.Logger,
txDecoder sdk.TxDecoder,
txEncoder sdk.TxEncoder,
mempool block.Mempool,
) *ProposalHandler {
return &ProposalHandler{

Check failure on line 45 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-integration

expected 'IDENT', found 'return'

Check failure on line 45 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected 'IDENT', found 'return'

Check failure on line 45 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected type, found '&'
<<<<<<< HEAD

Check failure on line 46 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expected expression

Check failure on line 46 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: unexpected <<, expected expression

Check failure on line 46 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: unexpected <<, expected expression

Check failure on line 46 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: unexpected <<, expected expression
logger: logger,

Check failure on line 47 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-integration

expected type, found ':'

Check failure on line 47 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected ';', found ':'

Check failure on line 47 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected type, found ':'
txDecoder: txDecoder,
txEncoder: txEncoder,
prepareLanesHandler: ChainPrepareLanes(mempool.Registry()),

Check failure on line 50 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 50 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 50 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: unexpected ) in composite literal; possibly missing comma or }

Check failure on line 50 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: unexpected ) in composite literal; possibly missing comma or }
mempool: mempool,
=======
logger: logger,
txDecoder: txDecoder,
txEncoder: txEncoder,
mempool: mempool,
useCustomProcessProposal: false,
}
}

Check failure on line 59 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: non-declaration statement outside function body

Check failure on line 59 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: non-declaration statement outside function body

Check failure on line 59 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: non-declaration statement outside function body

Check failure on line 59 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: non-declaration statement outside function body

// New returns a new ABCI++ proposal handler with the ability to use custom process proposal logic.
//
// NOTE: It is highly recommended to use the default proposal handler unless you have a specific
// use case that requires custom process proposal logic.
func New(
logger log.Logger,
txDecoder sdk.TxDecoder,
txEncoder sdk.TxEncoder,
mempool block.Mempool,
useCustomProcessProposal bool,
) *ProposalHandler {
return &ProposalHandler{

Check failure on line 72 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-integration

expected 'IDENT', found 'return'

Check failure on line 72 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected 'IDENT', found 'return'

Check failure on line 72 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected type, found '&'
logger: logger,

Check failure on line 73 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-integration

expected ';', found ':'

Check failure on line 73 in abci/abci.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected ';', found ':'
txDecoder: txDecoder,
txEncoder: txEncoder,
mempool: mempool,
useCustomProcessProposal: useCustomProcessProposal,
>>>>>>> 79d7ef7 (chore: Default Process Proposal (#543))

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected >>, expected expression

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#'

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-integration

illegal character U+0023 '#'

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: unexpected >>, expected expression

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

invalid character U+0023 '#'

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: unexpected >>, expected expression

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

invalid character U+0023 '#'

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: unexpected >>, expected expression

Check failure on line 78 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

invalid character U+0023 '#'
}
}

Check failure on line 80 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-e2e

syntax error: non-declaration statement outside function body

Check failure on line 80 in abci/abci.go

View workflow job for this annotation

GitHub Actions / test-unit

syntax error: non-declaration statement outside function body

Check failure on line 80 in abci/abci.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

syntax error: non-declaration statement outside function body

Expand Down Expand Up @@ -110,6 +148,10 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
// 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 {
if !h.useCustomProcessProposal {
return baseapp.NoOpProcessProposal()
}

return func(ctx sdk.Context, req *abci.RequestProcessProposal) (resp *abci.ResponseProcessProposal, err error) {
if req.Height <= 1 {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil
Expand Down
12 changes: 8 additions & 4 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,12 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
proposalHandler := abci.New(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
true,
).PrepareProposalHandler()

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
Expand Down Expand Up @@ -545,11 +546,12 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
proposalHandler := abci.New(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
true,
).PrepareProposalHandler()

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
Expand Down Expand Up @@ -594,11 +596,12 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
proposalHandler := abci.New(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
true,
).PrepareProposalHandler()

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
Expand Down Expand Up @@ -643,11 +646,12 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
)
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
proposalHandler := abci.New(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
true,
).PrepareProposalHandler()

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
Expand Down
3 changes: 2 additions & 1 deletion abci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ func (s *ProposalsTestSuite) setUpProposalHandlers(lanes []block.Lane) *abci.Pro
mempool, err := block.NewLanedMempool(log.NewNopLogger(), lanes)
s.Require().NoError(err)

return abci.NewProposalHandler(
return abci.New(
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
true,
)
}

Expand Down
2 changes: 2 additions & 0 deletions tests/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ There are fix critical steps to building a test app that uses the Block SDK:
5. Setting the antehandlers - used for transaction validation - for each lane.
6. Setting the proposal handlers - used for block creation and verification - for the application to utilize the Block SDK's Prepare and Process Proposal handlers.

**IMPORTANT NOTE:** It is recommended that applications use the **`NewDefaultProposalHandler`** when constructing their Prepare and Process Proposal handlers. This is because the priority nonce mempool - the underlying storage device of transactions - has non-deterministic ordering of transactions on chains with multiple fees. The use of the `NewDefaultProposalHandler` ensures that the ordering of transactions on proposal construction follows the ordering logic of the lanes, which is deterministic, and that process proposal optimistically assumes that the ordering of transactions is correct.

### 1. Signer Extractor

The signer extractor is responsible for extracting signers and relevant information about who is signing the transaction. We recommend using the default implementation provided by the Block SDK.
Expand Down
11 changes: 10 additions & 1 deletion tests/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,20 @@ func New(

// Step 6: Create the proposal handler and set it on the app. Now the application
// will build and verify proposals using the Block SDK!
proposalHandler := abci.NewProposalHandler(
//
// NOTE: It is recommended to use the default proposal handler by constructing
// using the NewDefaultProposalHandler function. This will use the correct prepare logic
// for the lanes, but the process logic will be a no-op. To read more about the default
// proposal handler, see the documentation in readme.md in this directory.
//
// If you want to customize the prepare and process logic, you can construct the proposal
// handler using the New function and setting the useProcess flag to true.
proposalHandler := abci.New( // use NewDefaultProposalHandler instead for default behavior (RECOMMENDED)
app.Logger(),
app.TxConfig().TxDecoder(),
app.TxConfig().TxEncoder(),
mempool,
true,
)
app.App.SetPrepareProposal(proposalHandler.PrepareProposalHandler())
app.App.SetProcessProposal(proposalHandler.ProcessProposalHandler())
Expand Down

0 comments on commit 176b162

Please sign in to comment.