go-ethereum/core/txpool/blobpool/priority.go
Csaba Kiraly a19f1ff11b
core/txpool/blobpool: remove the log-log grouping for positive priorities
The priority groups for positive fee difference were not used. In these
cases we always used the tip as the basis for comparison. Thus, it
is useless to do an extra log, just to then throw it away.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2026-02-25 21:25:46 +01:00

70 lines
2.7 KiB
Go

// Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package blobpool
import (
"math"
"github.com/holiman/uint256"
)
// 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.
//
// This method takes about 8ns on a very recent laptop CPU, recalculating about
// 125 million transaction priority values per second.
func evictionPriority(basefeeJumps float64, txBasefeeJumps, blobfeeJumps, txBlobfeeJumps float64) int {
var (
basefeePriority = evictionPriority1D(basefeeJumps, txBasefeeJumps)
blobfeePriority = evictionPriority1D(blobfeeJumps, txBlobfeeJumps)
)
return min(0, basefeePriority, blobfeePriority)
}
// evictionPriority1D calculates the eviction priority based on the algorithm
// described in the BlobPool docs for a single fee component.
func evictionPriority1D(basefeeJumps float64, txfeeJumps float64) int {
jumps := txfeeJumps - basefeeJumps
if jumps <= 0 {
return int(math.Floor(jumps))
}
// We only use the negative part for ordering. The positive part is only used
// for threshold comparision (with a negative threshold), so the value is almost
// irrelevant, as long as it's positive.
return int((math.Ceil(jumps)))
}
// 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 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
// be cached.
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.Log(fee.Float64()) / log1_125
}
}
}