Skip to content

Commit

Permalink
core/txpool/blobpool: calculate log1.125 faster (ethereum#29300)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronChen0 authored and jorgemmsilva committed Jun 17, 2024
1 parent bd0b4f9 commit f28d761
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/txpool/blobpool/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f28d761

Please sign in to comment.