Skip to content

Commit 9f1cd65

Browse files
authored
(release) txpool: fix initial blockGasLimit and setBlobFee() (#9303)
Cherry pick PR #9301
1 parent 2099940 commit 9f1cd65

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

consensus/misc/eip1559.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ var Eip1559FeeCalculator eip1559Calculator
6363

6464
type eip1559Calculator struct{}
6565

66-
func (f eip1559Calculator) CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee uint64, blobFee uint64, minBlobGasPrice uint64, err error) {
66+
func (f eip1559Calculator) CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee, blobFee, minBlobGasPrice, blockGasLimit uint64, err error) {
6767
hash := rawdb.ReadHeadHeaderHash(db)
6868

6969
if hash == (libcommon.Hash{}) {
70-
return 0, 0, 0, fmt.Errorf("can't get head header hash")
70+
return 0, 0, 0, 0, fmt.Errorf("can't get head header hash")
7171
}
7272

7373
currentHeader, err := rawdb.ReadHeaderByHash(db, hash)
7474

7575
if err != nil {
76-
return 0, 0, 0, err
76+
return 0, 0, 0, 0, err
7777
}
7878

7979
if chainConfig != nil {
@@ -92,7 +92,7 @@ func (f eip1559Calculator) CurrentFees(chainConfig *chain.Config, db kv.Getter)
9292

9393
minBlobGasPrice = chainConfig.GetMinBlobGasPrice()
9494

95-
return baseFee, blobFee, minBlobGasPrice, nil
95+
return baseFee, blobFee, minBlobGasPrice, currentHeader.GasLimit, nil
9696
}
9797

9898
// CalcBaseFee calculates the basefee of the header.

erigon-lib/txpool/pool.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ import (
6161
"github.com/ledgerwatch/erigon-lib/types"
6262
)
6363

64+
const DefaultBlockGasLimit = uint64(30000000)
65+
6466
var (
6567
processBatchTxsTimer = metrics.NewSummary(`pool_process_remote_txs`)
6668
addRemoteTxsTimer = metrics.NewSummary(`pool_add_remote_txs`)
@@ -229,7 +231,7 @@ type TxPool struct {
229231
}
230232

231233
type FeeCalculator interface {
232-
CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee uint64, blobFee uint64, minBlobGasPrice uint64, err error)
234+
CurrentFees(chainConfig *chain.Config, db kv.Getter) (baseFee uint64, blobFee uint64, minBlobGasPrice, blockGasLimit uint64, err error)
233235
}
234236

235237
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) {
13171319

13181320
func (p *TxPool) setBlobFee(blobFee uint64) {
13191321
if blobFee > 0 {
1320-
p.pendingBaseFee.Store(blobFee)
1322+
p.pendingBlobFee.Store(blobFee)
13211323
}
13221324
}
13231325

@@ -2086,11 +2088,14 @@ func (p *TxPool) fromDB(ctx context.Context, tx kv.Tx, coreTx kv.Tx) error {
20862088
i++
20872089
}
20882090

2089-
var pendingBaseFee, pendingBlobFee, minBlobGasPrice uint64
2091+
var pendingBaseFee, pendingBlobFee, minBlobGasPrice, blockGasLimit uint64
20902092

20912093
if p.feeCalculator != nil {
20922094
if chainConfig, _ := ChainConfig(tx); chainConfig != nil {
2093-
pendingBaseFee, pendingBlobFee, minBlobGasPrice, _ = p.feeCalculator.CurrentFees(chainConfig, coreTx)
2095+
pendingBaseFee, pendingBlobFee, minBlobGasPrice, blockGasLimit, err = p.feeCalculator.CurrentFees(chainConfig, coreTx)
2096+
if err != nil {
2097+
return err
2098+
}
20942099
}
20952100
}
20962101

@@ -2118,16 +2123,21 @@ func (p *TxPool) fromDB(ctx context.Context, tx kv.Tx, coreTx kv.Tx) error {
21182123
pendingBlobFee = minBlobGasPrice
21192124
}
21202125

2126+
if blockGasLimit == 0 {
2127+
blockGasLimit = DefaultBlockGasLimit
2128+
}
2129+
21212130
err = p.senders.registerNewSenders(&txs, p.logger)
21222131
if err != nil {
21232132
return err
21242133
}
21252134
if _, _, err := p.addTxs(p.lastSeenBlock.Load(), cacheView, p.senders, txs,
2126-
pendingBaseFee, pendingBlobFee, math.MaxUint64 /* blockGasLimit */, false, p.logger); err != nil {
2135+
pendingBaseFee, pendingBlobFee, blockGasLimit, false, p.logger); err != nil {
21272136
return err
21282137
}
21292138
p.pendingBaseFee.Store(pendingBaseFee)
21302139
p.pendingBlobFee.Store(pendingBlobFee)
2140+
p.blockGasLimit.Store(blockGasLimit)
21312141
return nil
21322142
}
21332143

0 commit comments

Comments
 (0)