Skip to content

Commit af45e2e

Browse files
consensus/misc/4844: fix blob price computation, add test
1 parent 1478f6a commit af45e2e

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

consensus/misc/eip4844/eip4844.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func calcExcessBlobGas(isOsaka bool, bcfg *BlobConfig, parent *types.Header) uin
155155
var (
156156
baseCost = big.NewInt(params.BlobBaseCost)
157157
reservePrice = baseCost.Mul(baseCost, parent.BaseFee)
158-
blobPrice = bcfg.blobPrice(excessBlobGas)
158+
blobPrice = bcfg.blobPrice(parentExcessBlobGas)
159159
)
160160
if reservePrice.Cmp(blobPrice) > 0 {
161161
scaledExcess := parentBlobGasUsed * uint64(bcfg.Max-bcfg.Target) / uint64(bcfg.Max)

consensus/misc/eip4844/eip4844_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,65 @@ func TestCalcBlobFee(t *testing.T) {
9191
}
9292
}
9393

94+
func TestCalcBlobFeePostOsaka(t *testing.T) {
95+
zero := uint64(0)
96+
bpo1 := uint64(1754836608)
97+
bpo2 := uint64(1754934912)
98+
bpo3 := uint64(1755033216)
99+
100+
tests := []struct {
101+
excessBlobGas uint64
102+
blobGasUsed uint64
103+
blobfee uint64
104+
basefee uint64
105+
parenttime uint64
106+
headertime uint64
107+
}{
108+
{5149252, 1310720, 5617366, 30, 1754904516, 1754904528},
109+
{19251039, 2490368, 20107103, 50, 1755033204, 1755033216},
110+
}
111+
for i, tt := range tests {
112+
config := &params.ChainConfig{
113+
LondonBlock: big.NewInt(0),
114+
CancunTime: &zero,
115+
PragueTime: &zero,
116+
OsakaTime: &zero,
117+
BPO1Time: &bpo1,
118+
BPO2Time: &bpo2,
119+
BPO3Time: &bpo3,
120+
BlobScheduleConfig: &params.BlobScheduleConfig{
121+
Cancun: params.DefaultCancunBlobConfig,
122+
Prague: params.DefaultPragueBlobConfig,
123+
Osaka: params.DefaultOsakaBlobConfig,
124+
BPO1: &params.BlobConfig{
125+
Target: 9,
126+
Max: 14,
127+
UpdateFraction: 8832827,
128+
},
129+
BPO2: &params.BlobConfig{
130+
Target: 14,
131+
Max: 21,
132+
UpdateFraction: 13739630,
133+
},
134+
BPO3: &params.BlobConfig{
135+
Target: 21,
136+
Max: 32,
137+
UpdateFraction: 20609697,
138+
},
139+
}}
140+
parent := &types.Header{
141+
ExcessBlobGas: &tt.excessBlobGas,
142+
BlobGasUsed: &tt.blobGasUsed,
143+
BaseFee: big.NewInt(int64(tt.basefee)),
144+
Time: tt.parenttime,
145+
}
146+
have := CalcExcessBlobGas(config, parent, tt.headertime)
147+
if have != tt.blobfee {
148+
t.Errorf("test %d: blobfee mismatch: have %v want %v", i, have, tt.blobfee)
149+
}
150+
}
151+
}
152+
94153
func TestFakeExponential(t *testing.T) {
95154
tests := []struct {
96155
factor int64

0 commit comments

Comments
 (0)