eth/gasprice: reduce allocations (#33698)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

Recent pprof from our validator shows ~6% of all allocations because of
the gas price oracle. This PR reduces that.
This commit is contained in:
Marius van der Wijden 2026-01-28 20:33:04 +01:00 committed by GitHub
parent 1e9dfd5bb0
commit 424bc22ab8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/holiman/uint256"
)
const sampleNumber = 3 // Number of transactions sampled in a block
@ -257,12 +258,12 @@ func (oracle *Oracle) getBlockValues(ctx context.Context, blockNum uint64, limit
sortedTxs := make([]*types.Transaction, len(txs))
copy(sortedTxs, txs)
baseFee := block.BaseFee()
baseFee256 := new(uint256.Int)
if baseFee != nil {
baseFee256.SetFromBig(baseFee)
}
slices.SortFunc(sortedTxs, func(a, b *types.Transaction) int {
// It's okay to discard the error because a tx would never be
// accepted into a block with an invalid effective tip.
tip1, _ := a.EffectiveGasTip(baseFee)
tip2, _ := b.EffectiveGasTip(baseFee)
return tip1.Cmp(tip2)
return a.EffectiveGasTipCmp(b, baseFee256)
})
var prices []*big.Int