mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-02 14:22:55 +00:00
eth/gasprice: reduce allocations (#33698)
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:
parent
1e9dfd5bb0
commit
424bc22ab8
1 changed files with 6 additions and 5 deletions
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
const sampleNumber = 3 // Number of transactions sampled in a block
|
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))
|
sortedTxs := make([]*types.Transaction, len(txs))
|
||||||
copy(sortedTxs, txs)
|
copy(sortedTxs, txs)
|
||||||
baseFee := block.BaseFee()
|
baseFee := block.BaseFee()
|
||||||
|
baseFee256 := new(uint256.Int)
|
||||||
|
if baseFee != nil {
|
||||||
|
baseFee256.SetFromBig(baseFee)
|
||||||
|
}
|
||||||
slices.SortFunc(sortedTxs, func(a, b *types.Transaction) int {
|
slices.SortFunc(sortedTxs, func(a, b *types.Transaction) int {
|
||||||
// It's okay to discard the error because a tx would never be
|
return a.EffectiveGasTipCmp(b, baseFee256)
|
||||||
// accepted into a block with an invalid effective tip.
|
|
||||||
tip1, _ := a.EffectiveGasTip(baseFee)
|
|
||||||
tip2, _ := b.EffectiveGasTip(baseFee)
|
|
||||||
return tip1.Cmp(tip2)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
var prices []*big.Int
|
var prices []*big.Int
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue