Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txpool: fix initial blockGasLimit and setBlobFee() #9301

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading