mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
core/txpool/legacypool: scope queued replacement costs to the current batch
This commit is contained in:
parent
6336d965df
commit
37492a3142
1 changed files with 34 additions and 0 deletions
|
|
@ -561,13 +561,17 @@ func (pool *LegacyPool) ValidateTxBasics(tx *types.Transaction) error {
|
||||||
|
|
||||||
// batchTxValidationState tracks the queue cost baseline for a batch addition so
|
// batchTxValidationState tracks the queue cost baseline for a batch addition so
|
||||||
// later transactions can account for the net queue growth caused by earlier ones.
|
// later transactions can account for the net queue growth caused by earlier ones.
|
||||||
|
// It also tracks queued nonces introduced by the current batch so replacement
|
||||||
|
// cost lookups only see queue state created within that batch.
|
||||||
type batchTxValidationState struct {
|
type batchTxValidationState struct {
|
||||||
queueCostSnapshot map[common.Address]*big.Int
|
queueCostSnapshot map[common.Address]*big.Int
|
||||||
|
batchQueuedNonces map[common.Address]map[uint64]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBatchTxValidationState() *batchTxValidationState {
|
func newBatchTxValidationState() *batchTxValidationState {
|
||||||
return &batchTxValidationState{
|
return &batchTxValidationState{
|
||||||
queueCostSnapshot: make(map[common.Address]*big.Int),
|
queueCostSnapshot: make(map[common.Address]*big.Int),
|
||||||
|
batchQueuedNonces: make(map[common.Address]map[uint64]struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -603,6 +607,32 @@ func (batch *batchTxValidationState) queueCostDelta(pool *LegacyPool, addr commo
|
||||||
return current.Sub(current, snapshot)
|
return current.Sub(current, snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (batch *batchTxValidationState) trackQueuedNonce(addr common.Address, nonce uint64) {
|
||||||
|
if batch == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if batch.batchQueuedNonces[addr] == nil {
|
||||||
|
batch.batchQueuedNonces[addr] = make(map[uint64]struct{})
|
||||||
|
}
|
||||||
|
batch.batchQueuedNonces[addr][nonce] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (batch *batchTxValidationState) batchQueuedCost(pool *LegacyPool, addr common.Address, nonce uint64) *big.Int {
|
||||||
|
if batch == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
nonces := batch.batchQueuedNonces[addr]
|
||||||
|
if _, ok := nonces[nonce]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if list, ok := pool.queue.get(addr); ok {
|
||||||
|
if tx := list.txs.Get(nonce); tx != nil {
|
||||||
|
return tx.Cost()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// validateTx checks whether a transaction is valid according to the consensus
|
// validateTx checks whether a transaction is valid according to the consensus
|
||||||
// rules and adheres to some heuristic limits of the local node (price and size).
|
// rules and adheres to some heuristic limits of the local node (price and size).
|
||||||
func (pool *LegacyPool) validateTx(tx *types.Transaction) error {
|
func (pool *LegacyPool) validateTx(tx *types.Transaction) error {
|
||||||
|
|
@ -628,6 +658,9 @@ func (pool *LegacyPool) validateTxWithBatch(tx *types.Transaction, batch *batchT
|
||||||
return tx.Cost()
|
return tx.Cost()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if cost := batch.batchQueuedCost(pool, addr, nonce); cost != nil {
|
||||||
|
return cost
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -837,6 +870,7 @@ func (pool *LegacyPool) addWithBatch(tx *types.Transaction, batch *batchTxValida
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
batch.trackQueuedNonce(from, tx.Nonce())
|
||||||
|
|
||||||
log.Trace("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To())
|
log.Trace("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To())
|
||||||
return replaced, nil
|
return replaced, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue