consensus/misc/4844: fix blob price computation, add test

This commit is contained in:
MariusVanDerWijden 2025-08-15 11:34:08 +02:00
parent 1478f6a64e
commit af45e2e9ee
2 changed files with 60 additions and 1 deletions

View file

@ -155,7 +155,7 @@ func calcExcessBlobGas(isOsaka bool, bcfg *BlobConfig, parent *types.Header) uin
var ( var (
baseCost = big.NewInt(params.BlobBaseCost) baseCost = big.NewInt(params.BlobBaseCost)
reservePrice = baseCost.Mul(baseCost, parent.BaseFee) reservePrice = baseCost.Mul(baseCost, parent.BaseFee)
blobPrice = bcfg.blobPrice(excessBlobGas) blobPrice = bcfg.blobPrice(parentExcessBlobGas)
) )
if reservePrice.Cmp(blobPrice) > 0 { if reservePrice.Cmp(blobPrice) > 0 {
scaledExcess := parentBlobGasUsed * uint64(bcfg.Max-bcfg.Target) / uint64(bcfg.Max) scaledExcess := parentBlobGasUsed * uint64(bcfg.Max-bcfg.Target) / uint64(bcfg.Max)

View file

@ -91,6 +91,65 @@ func TestCalcBlobFee(t *testing.T) {
} }
} }
func TestCalcBlobFeePostOsaka(t *testing.T) {
zero := uint64(0)
bpo1 := uint64(1754836608)
bpo2 := uint64(1754934912)
bpo3 := uint64(1755033216)
tests := []struct {
excessBlobGas uint64
blobGasUsed uint64
blobfee uint64
basefee uint64
parenttime uint64
headertime uint64
}{
{5149252, 1310720, 5617366, 30, 1754904516, 1754904528},
{19251039, 2490368, 20107103, 50, 1755033204, 1755033216},
}
for i, tt := range tests {
config := &params.ChainConfig{
LondonBlock: big.NewInt(0),
CancunTime: &zero,
PragueTime: &zero,
OsakaTime: &zero,
BPO1Time: &bpo1,
BPO2Time: &bpo2,
BPO3Time: &bpo3,
BlobScheduleConfig: &params.BlobScheduleConfig{
Cancun: params.DefaultCancunBlobConfig,
Prague: params.DefaultPragueBlobConfig,
Osaka: params.DefaultOsakaBlobConfig,
BPO1: &params.BlobConfig{
Target: 9,
Max: 14,
UpdateFraction: 8832827,
},
BPO2: &params.BlobConfig{
Target: 14,
Max: 21,
UpdateFraction: 13739630,
},
BPO3: &params.BlobConfig{
Target: 21,
Max: 32,
UpdateFraction: 20609697,
},
}}
parent := &types.Header{
ExcessBlobGas: &tt.excessBlobGas,
BlobGasUsed: &tt.blobGasUsed,
BaseFee: big.NewInt(int64(tt.basefee)),
Time: tt.parenttime,
}
have := CalcExcessBlobGas(config, parent, tt.headertime)
if have != tt.blobfee {
t.Errorf("test %d: blobfee mismatch: have %v want %v", i, have, tt.blobfee)
}
}
}
func TestFakeExponential(t *testing.T) { func TestFakeExponential(t *testing.T) {
tests := []struct { tests := []struct {
factor int64 factor int64