Skip to content

Commit

Permalink
(release) txpool: fix initial blockGasLimit and setBlobFee() (#9303)
Browse files Browse the repository at this point in the history
Cherry pick PR #9301
  • Loading branch information
yperbasis authored Jan 24, 2024
1 parent 2099940 commit 9f1cd65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
20 changes: 15 additions & 5 deletions erigon-lib/txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9f1cd65

Please sign in to comment.