try better way

This commit is contained in:
Jared Wasinger 2024-09-23 20:41:31 +07:00
parent deb5c087c4
commit d3a754e735
2 changed files with 61 additions and 47 deletions

View file

@ -1013,21 +1013,10 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error {
return nil
}
// 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) {
p.lock.Lock()
defer p.lock.Unlock()
// Store the new minimum gas tip
old := p.gasTip
p.gasTip = uint256.MustFromBig(tip)
// If the min miner fee increased, remove transactions below the new threshold
if old == nil || p.gasTip.Cmp(old) > 0 {
func (p *BlobPool) flushTransactionsBelowTip(tip *uint256.Int) {
for addr, txs := range p.index {
for i, tx := range txs {
if tx.execTipCap.Cmp(p.gasTip) < 0 {
if tx.execTipCap.Cmp(tip) < 0 {
// Drop the offending transaction
var (
ids = []uint64{tx.id}
@ -1072,12 +1061,34 @@ func (p *BlobPool) SetGasTip(tip *big.Int) {
}
}
}
}
// 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) {
p.lock.Lock()
defer p.lock.Unlock()
// Store the new minimum gas tip
old := p.gasTip
p.gasTip = uint256.MustFromBig(tip)
// If the min miner fee increased, remove transactions below the new threshold
if old == nil || p.gasTip.Cmp(old) > 0 {
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 {

View file

@ -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