Skip to content
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

fix: fix blockchain stop to produce blocks #211

Merged
merged 3 commits into from
May 26, 2023
Merged
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
33 changes: 21 additions & 12 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,13 @@ func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events {
// PrepareProposal state internally will be discarded. <nil, err> will be
// returned if the transaction cannot be encoded. <bz, nil> will be returned if
// the transaction is valid, otherwise <bz, err> will be returned.
func (app *BaseApp) PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error) {
bz, err := app.txEncoder(tx)
if err != nil {
return nil, err
func (app *BaseApp) PrepareProposalVerifyTx(tx sdk.Tx, bz []byte) ([]byte, error) {
var err error
if bz == nil {
bz, err = app.txEncoder(tx)
if err != nil {
return nil, err
}
}

_, _, _, _, err = app.runTx(runTxPrepareProposal, bz) //nolint:dogsled
Expand Down Expand Up @@ -920,7 +923,7 @@ type (
// that any custom ABCI PrepareProposal and ProcessProposal handler can use
// to verify a transaction.
ProposalTxVerifier interface {
PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error)
PrepareProposalVerifyTx(tx sdk.Tx, txBz []byte) ([]byte, error)
ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error)
}

Expand Down Expand Up @@ -961,18 +964,24 @@ func NewDefaultProposalHandler(mp mempool.Mempool, txVerifier ProposalTxVerifier
// FIFO order.
func (h DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
return func(ctx sdk.Context, req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
var (
selectedTxs [][]byte
totalTxBytes int64
)

// If the mempool is nil or a no-op mempool, we simply return the transactions
// requested from CometBFT, which, by default, should be in FIFO order.
_, isNoOp := h.mempool.(mempool.NoOpMempool)
if h.mempool == nil || isNoOp {
return abci.ResponsePrepareProposal{Txs: req.Txs}
for _, txBz := range req.Txs { // req.MaxTxBytes has been ensured
bz, err := h.txVerifier.PrepareProposalVerifyTx(nil, txBz)
if err == nil {
selectedTxs = append(selectedTxs, bz)
}
}
return abci.ResponsePrepareProposal{Txs: selectedTxs}
}

var (
selectedTxs [][]byte
totalTxBytes int64
)

iterator := h.mempool.Select(ctx, req.Txs)

for iterator != nil {
Expand All @@ -982,7 +991,7 @@ func (h DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
// which calls mempool.Insert, in theory everything in the pool should be
// valid. But some mempool implementations may insert invalid txs, so we
// check again.
bz, err := h.txVerifier.PrepareProposalVerifyTx(memTx)
bz, err := h.txVerifier.PrepareProposalVerifyTx(memTx, nil)
if err != nil {
err := h.mempool.Remove(memTx)
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
Expand Down