10000 ABCI 2.0: Double-check that `PreparaProposal` and `ProcessProposal` respect coherence all over our code by sergio-mena · Pull Request #514 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ABCI 2.0: Double-check that PreparaProposal and ProcessProposal respect coherence all over our code #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (app *Application) formatTxs(ctx context.Context, blockData [][]byte) [][]b
func (app *Application) ProcessProposal(ctx context.Context, req *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
for _, tx := range req.Txs {
// As CheckTx is a full validity check we can simply reuse this
if resp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx}); resp.Code != CodeTypeOK || err != nil {
if resp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx}); err != nil || resp.Code != CodeTypeOK {
return &types.ResponseProcessProposal{Status: types.ResponseProcessProposal_REJECT}, nil
}
}
Expand Down
5 changes: 4 additions & 1 deletion state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ func (blockExec *BlockExecutor) VerifyVoteExtension(ctx context.Context, vote *t

// Commit locks the mempool, runs the ABCI Commit message, and updates the
// mempool.
// It returns the result of calling abci.Commit (the AppHash) and the height to retain (if any).
// It returns the result of calling abci.Commit which is the height to retain (if any)).
// The application is expected to have persisted its state (if any) before returning
// from the ABCI Commit call. This is the only place where the application should
// persist its state.
// The Mempool must be locked during commit and update because state is
// typically reset on Commit and old txs must be replayed against committed
// state before new txs are run in the mempool, lest they be invalid.
Expand Down
24 changes: 23 additions & 1 deletion state/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,29 @@ func (app *testApp) Commit(_ context.Context, _ *abci.RequestCommit) (*abci.Resp
return &abci.ResponseCommit{RetainHeight: 1}, nil
}

func (app *testApp) ProcessProposal(_ context.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) {
func (app *testApp) PrepareProposal(
_ context.Context,
req *abci.RequestPrepareProposal,
) (*abci.ResponsePrepareProposal, error) {
txs := make([][]byte, 0, len(req.Txs))
var totalBytes int64
for _, tx := range req.Txs {
if len(tx) == 0 {
continue
}
totalBytes += int64(len(tx))
if totalBytes > req.MaxTxBytes {
break
}
txs = append(txs, tx)
}
return &abci.ResponsePrepareProposal{Txs: txs}, nil
}

func (app *testApp) ProcessProposal(
_ context.Context,
req *abci.RequestProcessProposal,
) (*abci.ResponseProcessProposal, error) {
for _, tx := range req.Txs {
if len(tx) == 0 {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func (app *Application) PrepareProposal(
break
}
totalBytes += int64(len(tx))
// Coherence: No need to call parseTx, as the check is stateless and has been performed by CheckTx
txs = append(txs, tx)
}
if totalBytes+int64(len(extTx)) <= req.MaxTxBytes {
Expand All @@ -376,6 +377,7 @@ func (app *Application) PrepareProposal(
if totalBytes > req.MaxTxBytes {
break
}
// Coherence: No need to call parseTx, as the check is stateless and has been performed by CheckTx
txs = append(txs, tx)
}

Expand Down
0