core/txpool/blobpool: calculate log1.125 faster (#29300)

pull/29304/head
Aaron Chen 8 months ago committed by GitHub
parent 78c102dec5
commit 0444388c74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      core/txpool/blobpool/priority.go

@ -23,8 +23,8 @@ import (
"github.com/holiman/uint256"
)
// log2_1_125 is used in the eviction priority calculation.
var log2_1_125 = math.Log2(1.125)
// log1_125 is used in the eviction priority calculation.
var log1_125 = math.Log(1.125)
// evictionPriority calculates the eviction priority based on the algorithm
// described in the BlobPool docs for both fee components.
@ -57,8 +57,8 @@ func evictionPriority1D(basefeeJumps float64, txfeeJumps float64) int {
// dynamicFeeJumps calculates the log1.125(fee), namely the number of fee jumps
// needed to reach the requested one. We only use it when calculating the jumps
// between 2 fees, so it doesn't matter from what exact number with returns.
// it returns the result from (0, 1, 1.125).
// between 2 fees, so it doesn't matter from what exact number it returns.
// It returns the result from (0, 1, 1.125).
//
// This method is very expensive, taking about 75ns on a very recent laptop CPU,
// but the result does not change with the lifetime of a transaction, so it can
@ -67,7 +67,7 @@ func dynamicFeeJumps(fee *uint256.Int) float64 {
if fee.IsZero() {
return 0 // can't log2 zero, should never happen outside tests, but don't choke
}
return math.Log2(fee.Float64()) / log2_1_125
return math.Log(fee.Float64()) / log1_125
}
// intLog2 is a helper to calculate the integral part of a log2 of an unsigned

Loading…
Cancel
Save