mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-04-03 23:36:05 +00:00
update priority nonce mempool using
This commit is contained in:
parent
0b027e10ed
commit
248db0f47c
@ -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,47 +158,49 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !shouldAdd {
|
if shouldAdd {
|
||||||
iterator = iterator.Next()
|
// NOTE: Since transaction verification was already executed in CheckTx,
|
||||||
continue
|
// 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.
|
||||||
// NOTE: Since transaction verification was already executed in CheckTx,
|
txBz, err := h.txVerifier.PrepareProposalVerifyTx(memTx)
|
||||||
// which calls mempool.Insert, in theory everything in the pool should be
|
if err != nil {
|
||||||
// valid. But some mempool implementations may insert invalid txs, so we
|
waitRemoveTxs = append(waitRemoveTxs, memTx)
|
||||||
// check again.
|
} else {
|
||||||
txBz, err := h.txVerifier.PrepareProposalVerifyTx(memTx)
|
stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz)
|
||||||
if err != nil {
|
if stop {
|
||||||
err := h.mempool.Remove(memTx)
|
return false
|
||||||
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz)
|
|
||||||
if stop {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
txsLen := len(h.txSelector.SelectedTxs())
|
|
||||||
for sender, seq := range txSignersSeqs {
|
|
||||||
// If txsLen != selectedTxsNums is true, it means that we've
|
|
||||||
// added a new tx to the selected txs, so we need to update
|
|
||||||
// the sequence of the sender.
|
|
||||||
if txsLen != selectedTxsNums {
|
|
||||||
selectedTxsSignersSeqs[sender] = seq
|
|
||||||
} else if _, ok := selectedTxsSignersSeqs[sender]; !ok {
|
|
||||||
// The transaction hasn't been added but it passed the
|
|
||||||
// verification, so we know that the sequence is correct.
|
|
||||||
// So we set this sender's sequence to seq-1, in order
|
|
||||||
// to avoid unnecessary calls to PrepareProposalVerifyTx.
|
|
||||||
selectedTxsSignersSeqs[sender] = seq - 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txsLen := len(h.txSelector.SelectedTxs())
|
||||||
|
for sender, seq := range txSignersSeqs {
|
||||||
|
// If txsLen != selectedTxsNums is true, it means that we've
|
||||||
|
// added a new tx to the selected txs, so we need to update
|
||||||
|
// the sequence of the sender.
|
||||||
|
if txsLen != selectedTxsNums {
|
||||||
|
selectedTxsSignersSeqs[sender] = seq
|
||||||
|
} else if _, ok := selectedTxsSignersSeqs[sender]; !ok {
|
||||||
|
// The transaction hasn't been added but it passed the
|
||||||
|
// verification, so we know that the sequence is correct.
|
||||||
|
// So we set this sender's sequence to seq-1, in order
|
||||||
|
// to avoid unnecessary calls to PrepareProposalVerifyTx.
|
||||||
|
selectedTxsSignersSeqs[sender] = seq - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user