(release) txpool: fix initial blockGasLimit and setBlobFee() (#9303)

Cherry pick PR #9301
This commit is contained in:
Andrew Ashikhmin 2024-01-24 13:33:28 +01:00 committed by GitHub
parent 20999401b2
commit 9f1cd651f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 9 deletions

View File

@ -63,17 +63,17 @@ var Eip1559FeeCalculator eip1559Calculator
type eip1559Calculator struct{}
func (f eip1559Calculator) CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee uint64, blobFee uint64, minBlobGasPrice uint64, err error) {
func (f eip1559Calculator) CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee, blobFee, minBlobGasPrice, blockGasLimit uint64, err error) {
hash := rawdb.ReadHeadHeaderHash(db)
if hash == (libcommon.Hash{}) {
return 0, 0, 0, fmt.Errorf("can't get head header hash")
return 0, 0, 0, 0, fmt.Errorf("can't get head header hash")
}
currentHeader, err := rawdb.ReadHeaderByHash(db, hash)
if err != nil {
return 0, 0, 0, err
return 0, 0, 0, 0, err
}
if chainConfig != nil {
@ -92,7 +92,7 @@ func (f eip1559Calculator) CurrentFees(chainConfig *chain.Config, db kv.Getter)
minBlobGasPrice = chainConfig.GetMinBlobGasPrice()
return baseFee, blobFee, minBlobGasPrice, nil
return baseFee, blobFee, minBlobGasPrice, currentHeader.GasLimit, nil
}
// CalcBaseFee calculates the basefee of the header.

View File

@ -61,6 +61,8 @@ import (
"github.com/ledgerwatch/erigon-lib/types"
)
const DefaultBlockGasLimit = uint64(30000000)
var (
processBatchTxsTimer = metrics.NewSummary(`pool_process_remote_txs`)
addRemoteTxsTimer = metrics.NewSummary(`pool_add_remote_txs`)
@ -229,7 +231,7 @@ type TxPool struct {
}
type FeeCalculator interface {
CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee uint64, blobFee uint64, minBlobGasPrice uint64, err error)
CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee uint64, blobFee uint64, minBlobGasPrice, blockGasLimit uint64, err error)
}
func New(newTxs chan types.Announcements, coreDB kv.RoDB, cfg txpoolcfg.Config, cache kvcache.Cache,
@ -1317,7 +1319,7 @@ func (p *TxPool) setBaseFee(baseFee uint64) (uint64, bool) {
func (p *TxPool) setBlobFee(blobFee uint64) {
if blobFee > 0 {
p.pendingBaseFee.Store(blobFee)
p.pendingBlobFee.Store(blobFee)
}
}
@ -2086,11 +2088,14 @@ func (p *TxPool) fromDB(ctx context.Context, tx kv.Tx, coreTx kv.Tx) error {
i++
}
var pendingBaseFee, pendingBlobFee, minBlobGasPrice uint64
var pendingBaseFee, pendingBlobFee, minBlobGasPrice, blockGasLimit uint64
if p.feeCalculator != nil {
if chainConfig, _ := ChainConfig(tx); chainConfig != nil {
pendingBaseFee, pendingBlobFee, minBlobGasPrice, _ = p.feeCalculator.CurrentFees(chainConfig, coreTx)
pendingBaseFee, pendingBlobFee, minBlobGasPrice, blockGasLimit, err = p.feeCalculator.CurrentFees(chainConfig, coreTx)
if err != nil {
return err
}
}
}
@ -2118,16 +2123,21 @@ func (p *TxPool) fromDB(ctx context.Context, tx kv.Tx, coreTx kv.Tx) error {
pendingBlobFee = minBlobGasPrice
}
if blockGasLimit == 0 {
blockGasLimit = DefaultBlockGasLimit
}
err = p.senders.registerNewSenders(&txs, p.logger)
if err != nil {
return err
}
if _, _, err := p.addTxs(p.lastSeenBlock.Load(), cacheView, p.senders, txs,
pendingBaseFee, pendingBlobFee, math.MaxUint64 /* blockGasLimit */, false, p.logger); err != nil {
pendingBaseFee, pendingBlobFee, blockGasLimit, false, p.logger); err != nil {
return err
}
p.pendingBaseFee.Store(pendingBaseFee)
p.pendingBlobFee.Store(pendingBlobFee)
p.blockGasLimit.Store(blockGasLimit)
return nil
}