update priority nonce mempool using

This commit is contained in:
Solovyov1796 2025-03-12 21:07:14 +08:00
parent 0b027e10ed
commit 248db0f47c

View File

@ -1,9 +1,9 @@
package app package app
import ( import (
"errors"
"fmt" "fmt"
"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types" abci "github.com/cometbft/cometbft/abci/types"
gethtypes "github.com/ethereum/go-ethereum/core/types" gethtypes "github.com/ethereum/go-ethereum/core/types"
evmtypes "github.com/evmos/ethermint/x/evm/types" evmtypes "github.com/evmos/ethermint/x/evm/types"
@ -97,11 +97,12 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()} return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()}
} }
iterator := h.mempool.Select(ctx, req.Txs)
selectedTxsSignersSeqs := make(map[string]uint64) selectedTxsSignersSeqs := make(map[string]uint64)
var selectedTxsNums int var selectedTxsNums int
for iterator != nil {
memTx := iterator.Tx() var waitRemoveTxs []sdk.Tx
mempool.SelectBy(ctx, h.mempool, req.Txs, func(memTx sdk.Tx) bool {
sigs, err := memTx.(signing.SigVerifiableTx).GetSignaturesV2() sigs, err := memTx.(signing.SigVerifiableTx).GetSignaturesV2()
if err != nil { if err != nil {
panic(fmt.Errorf("failed to get signatures: %w", err)) panic(fmt.Errorf("failed to get signatures: %w", err))
@ -157,25 +158,18 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
} }
} }
if !shouldAdd { if shouldAdd {
iterator = iterator.Next()
continue
}
// NOTE: Since transaction verification was already executed in CheckTx, // NOTE: Since transaction verification was already executed in CheckTx,
// which calls mempool.Insert, in theory everything in the pool should be // which calls mempool.Insert, in theory everything in the pool should be
// valid. But some mempool implementations may insert invalid txs, so we // valid. But some mempool implementations may insert invalid txs, so we
// check again. // check again.
txBz, err := h.txVerifier.PrepareProposalVerifyTx(memTx) txBz, err := h.txVerifier.PrepareProposalVerifyTx(memTx)
if err != nil { if err != nil {
err := h.mempool.Remove(memTx) waitRemoveTxs = append(waitRemoveTxs, memTx)
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
panic(err)
}
} else { } else {
stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz) stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz)
if stop { if stop {
break return false
} }
txsLen := len(h.txSelector.SelectedTxs()) txsLen := len(h.txSelector.SelectedTxs())
@ -195,9 +189,18 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
} }
selectedTxsNums = txsLen selectedTxsNums = txsLen
} }
iterator = iterator.Next()
} }
return true
})
for i := range waitRemoveTxs {
err := h.mempool.Remove(waitRemoveTxs[i])
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
panic(err)
}
}
return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()} return abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs()}
} }
} }