mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
try better way
This commit is contained in:
parent
deb5c087c4
commit
d3a754e735
2 changed files with 61 additions and 47 deletions
|
|
@ -1013,6 +1013,56 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *BlobPool) flushTransactionsBelowTip(tip *uint256.Int) {
|
||||
for addr, txs := range p.index {
|
||||
for i, tx := range txs {
|
||||
if tx.execTipCap.Cmp(tip) < 0 {
|
||||
// Drop the offending transaction
|
||||
var (
|
||||
ids = []uint64{tx.id}
|
||||
nonces = []uint64{tx.nonce}
|
||||
)
|
||||
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], txs[i].costCap)
|
||||
p.stored -= uint64(tx.size)
|
||||
delete(p.lookup, tx.hash)
|
||||
txs[i] = nil
|
||||
|
||||
// Drop everything afterwards, no gaps allowed
|
||||
for j, tx := range txs[i+1:] {
|
||||
ids = append(ids, tx.id)
|
||||
nonces = append(nonces, tx.nonce)
|
||||
|
||||
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], tx.costCap)
|
||||
p.stored -= uint64(tx.size)
|
||||
delete(p.lookup, tx.hash)
|
||||
txs[i+1+j] = nil
|
||||
}
|
||||
// Clear out the dropped transactions from the index
|
||||
if i > 0 {
|
||||
p.index[addr] = txs[:i]
|
||||
heap.Fix(p.evict, p.evict.index[addr])
|
||||
} else {
|
||||
delete(p.index, addr)
|
||||
delete(p.spent, addr)
|
||||
|
||||
heap.Remove(p.evict, p.evict.index[addr])
|
||||
p.reserve(addr, false)
|
||||
}
|
||||
// Clear out the transactions from the data store
|
||||
log.Warn("Dropping underpriced blob transaction", "from", addr, "rejected", tx.nonce, "tip", tx.execTipCap, "want", tip, "drop", nonces, "ids", ids)
|
||||
dropUnderpricedMeter.Mark(int64(len(ids)))
|
||||
|
||||
for _, id := range ids {
|
||||
if err := p.store.Delete(id); err != nil {
|
||||
log.Error("Failed to delete dropped transaction", "id", id, "err", err)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetGasTip implements txpool.SubPool, allowing the blob pool's gas requirements
|
||||
// to be kept in sync with the main transaction pool's gas requirements.
|
||||
func (p *BlobPool) SetGasTip(tip *big.Int) {
|
||||
|
|
@ -1025,59 +1075,20 @@ func (p *BlobPool) SetGasTip(tip *big.Int) {
|
|||
|
||||
// If the min miner fee increased, remove transactions below the new threshold
|
||||
if old == nil || p.gasTip.Cmp(old) > 0 {
|
||||
for addr, txs := range p.index {
|
||||
for i, tx := range txs {
|
||||
if tx.execTipCap.Cmp(p.gasTip) < 0 {
|
||||
// Drop the offending transaction
|
||||
var (
|
||||
ids = []uint64{tx.id}
|
||||
nonces = []uint64{tx.nonce}
|
||||
)
|
||||
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], txs[i].costCap)
|
||||
p.stored -= uint64(tx.size)
|
||||
delete(p.lookup, tx.hash)
|
||||
txs[i] = nil
|
||||
|
||||
// Drop everything afterwards, no gaps allowed
|
||||
for j, tx := range txs[i+1:] {
|
||||
ids = append(ids, tx.id)
|
||||
nonces = append(nonces, tx.nonce)
|
||||
|
||||
p.spent[addr] = new(uint256.Int).Sub(p.spent[addr], tx.costCap)
|
||||
p.stored -= uint64(tx.size)
|
||||
delete(p.lookup, tx.hash)
|
||||
txs[i+1+j] = nil
|
||||
}
|
||||
// Clear out the dropped transactions from the index
|
||||
if i > 0 {
|
||||
p.index[addr] = txs[:i]
|
||||
heap.Fix(p.evict, p.evict.index[addr])
|
||||
} else {
|
||||
delete(p.index, addr)
|
||||
delete(p.spent, addr)
|
||||
|
||||
heap.Remove(p.evict, p.evict.index[addr])
|
||||
p.reserve(addr, false)
|
||||
}
|
||||
// Clear out the transactions from the data store
|
||||
log.Warn("Dropping underpriced blob transaction", "from", addr, "rejected", tx.nonce, "tip", tx.execTipCap, "want", tip, "drop", nonces, "ids", ids)
|
||||
dropUnderpricedMeter.Mark(int64(len(ids)))
|
||||
|
||||
for _, id := range ids {
|
||||
if err := p.store.Delete(id); err != nil {
|
||||
log.Error("Failed to delete dropped transaction", "id", id, "err", err)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
p.flushTransactionsBelowTip(p.gasTip)
|
||||
}
|
||||
log.Debug("Blobpool tip threshold updated", "tip", tip)
|
||||
pooltipGauge.Update(tip.Int64())
|
||||
p.updateStorageMetrics()
|
||||
}
|
||||
|
||||
func (p *BlobPool) FlushAllTransactions() {
|
||||
maxUint256 := new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1)
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.flushTransactionsBelowTip(maxUint256)
|
||||
}
|
||||
|
||||
// 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).
|
||||
func (p *BlobPool) validateTx(tx *types.Transaction) error {
|
||||
|
|
|
|||
|
|
@ -116,6 +116,9 @@ type SubPool interface {
|
|||
// transaction, and drops all transactions below this threshold.
|
||||
SetGasTip(tip *big.Int)
|
||||
|
||||
// FlushAllTransactions drops all transactions in the pool.
|
||||
FlushAllTransactions()
|
||||
|
||||
// Has returns an indicator whether subpool has a transaction cached with the
|
||||
// given hash.
|
||||
Has(hash common.Hash) bool
|
||||
|
|
|
|||
Loading…
Reference in a new issue