@@ -57,17 +57,19 @@ func config() *params.ChainConfig {
5757 return config
5858}
5959
60- var TestCanyonTime = uint64 (10 )
61- var TestHoloceneTime = uint64 (12 )
62- var TestJovianTime = uint64 (14 )
60+ var (
61+ testCanyonTime = uint64 (10 )
62+ testHoloceneTime = uint64 (12 )
63+ testJovianTime = uint64 (14 )
64+ )
6365
6466func opConfig () * params.ChainConfig {
6567 config := copyConfig (params .TestChainConfig )
6668 config .LondonBlock = big .NewInt (5 )
6769 eip1559DenominatorCanyon := uint64 (250 )
68- config .CanyonTime = & TestCanyonTime
69- config .HoloceneTime = & TestHoloceneTime
70- config .JovianTime = & TestJovianTime
70+ config .CanyonTime = & testCanyonTime
71+ config .HoloceneTime = & testHoloceneTime
72+ config .JovianTime = & testJovianTime
7173 config .Optimism = & params.OptimismConfig {
7274 EIP1559Elasticity : 6 ,
7375 EIP1559Denominator : 50 ,
@@ -227,59 +229,74 @@ func TestCalcBaseFeeOptimismHolocene(t *testing.T) {
227229// TestCalcBaseFeeJovian tests that the minimum base fee is enforced
228230// when the computed base fee is less than the minimum base fee,
229231// if the feature is active and not enforced otherwise.
232+ // It also tests that the base fee udpate will take the DA footprint as stored
233+ // in the blob gas used field into account if it is larger than the gas used
234+ // field.
230235func TestCalcBaseFeeJovian (t * testing.T ) {
231236 parentGasLimit := uint64 (30_000_000 )
232237 denom := uint64 (50 )
233238 elasticity := uint64 (3 )
239+ parentGasTarget := parentGasLimit / elasticity
240+ const zeroParentBlobGasUsed = 0
234241
235- preJovian := TestJovianTime - 1
236- postJovian := TestJovianTime
242+ preJovian := testJovianTime - 1
243+ postJovian := testJovianTime
237244
238245 tests := []struct {
239- parentBaseFee int64
240- parentGasUsed uint64
241- parentTime uint64
242- minBaseFee uint64
243- expectedBaseFee uint64
246+ parentBaseFee int64
247+ parentGasUsed uint64
248+ parentBlobGasUsed uint64
249+ parentTime uint64
250+ minBaseFee uint64
251+ expectedBaseFee uint64
244252 }{
245253 // Test 0: gas used is below target, and the new calculated base fee is very low.
246254 // But since we are pre Jovian, we don't enforce the minBaseFee.
247- {1 , parentGasLimit / elasticity - 1_000_000 , preJovian , 1e9 , 1 },
255+ {1 , parentGasTarget - 1_000_000 , zeroParentBlobGasUsed , preJovian , 1e9 , 1 },
248256 // Test 1: gas used is exactly the target gas, but the base fee is set too low so
249257 // the base fee is expected to be the minBaseFee
250- {1 , parentGasLimit / elasticity , postJovian , 1e9 , 1e9 },
258+ {1 , parentGasTarget , zeroParentBlobGasUsed , postJovian , 1e9 , 1e9 },
251259 // Test 2: gas used exceeds gas target, but the new calculated base fee is still
252260 // too low so the base fee is expected to be the minBaseFee
253- {1 , parentGasLimit / elasticity + 1_000_000 , postJovian , 1e9 , 1e9 },
261+ {1 , parentGasTarget + 1_000_000 , zeroParentBlobGasUsed , postJovian , 1e9 , 1e9 },
254262 // Test 3: gas used exceeds gas target, but the new calculated base fee is higher
255263 // than the minBaseFee, so don't enforce minBaseFee. See the calculation below:
256264 // gasUsedDelta = gasUsed - parentGasTarget = 20_000_000 - 30_000_000 / 3 = 10_000_000
257265 // 2e9 * 10_000_000 / 10_000_000 / 50 = 40_000_000
258266 // 2e9 + 40_000_000 = 2_040_000_000, which is greater than minBaseFee
259- {2e9 , parentGasLimit / elasticity + 10_000_000 , postJovian , 1e9 , 2_040_000_000 },
267+ {2e9 , parentGasTarget + 10_000_000 , zeroParentBlobGasUsed , postJovian , 1e9 , 2_040_000_000 },
260268 // Test 4: gas used is below target, but the new calculated base fee is still
261269 // too low so the base fee is expected to be the minBaseFee
262- {1 , parentGasLimit / elasticity - 1_000_000 , postJovian , 1e9 , 1e9 },
270+ {1 , parentGasTarget - 1_000_000 , zeroParentBlobGasUsed , postJovian , 1e9 , 1e9 },
263271 // Test 5: gas used is below target, and the new calculated base fee is higher
264272 // than the minBaseFee, so don't enforce minBaseFee. See the calculation below:
265273 // gasUsedDelta = gasUsed - parentGasTarget = 9_000_000 - 30_000_000 / 3 = -1_000_000
266274 // 2_097_152 * -1_000_000 / 10_000_000 / 50 = -4194.304
267275 // 2_097_152 - 4194.304 = 2_092_957.696, which is greater than minBaseFee
268- {2_097_152 , parentGasLimit / elasticity - 1_000_000 , postJovian , 2e6 , 2_092_958 },
276+ {2_097_152 , parentGasTarget - 1_000_000 , zeroParentBlobGasUsed , postJovian , 2e6 , 2_092_958 },
269277 // Test 6: parent base fee already at minimum, below target => no change
270- {1e4 , parentGasLimit / elasticity - 1 , postJovian , 1e4 , 1e4 },
278+ {1e4 , parentGasTarget - 1 , zeroParentBlobGasUsed , postJovian , 1e4 , 1e4 },
271279 // Test 7: parent base fee already at minimum, above target => small increase as usual
272- {1e4 , parentGasLimit / elasticity + 1 , postJovian , 1e4 , 1e4 + 1 },
280+ {1e4 , parentGasTarget + 1 , zeroParentBlobGasUsed , postJovian , 1e4 , 1e4 + 1 },
281+
282+ // Test 8: Pre-Jovian: parent base fee already at minimum, gas used at target, blob gas used at limit
283+ // => no increase, minBaseFee ignored, high blob gas used ignored
284+ {1e4 , parentGasTarget , parentGasLimit , preJovian , 1e6 , 1e4 },
285+ // Test 9: parent base fee already at minimum, gas used at target, da footprint above target => small increase
286+ {1e4 , parentGasTarget , parentGasTarget + 1 , postJovian , 1e4 , 1e4 + 1 },
287+ // Test 10: Test 3, but with high blob gas used instead of gas used
288+ {2e9 , parentGasTarget , parentGasTarget + 10_000_000 , postJovian , 1e9 , 2_040_000_000 },
273289 }
274290 for i , test := range tests {
275291 testName := fmt .Sprintf ("test %d" , i )
276292 t .Run (testName , func (t * testing.T ) {
277293 parent := & types.Header {
278- Number : common .Big32 ,
279- GasLimit : parentGasLimit ,
280- GasUsed : test .parentGasUsed ,
281- BaseFee : big .NewInt (test .parentBaseFee ),
282- Time : test .parentTime ,
294+ Number : common .Big32 ,
295+ GasLimit : parentGasLimit ,
296+ GasUsed : test .parentGasUsed ,
297+ BlobGasUsed : & test .parentBlobGasUsed ,
298+ BaseFee : big .NewInt (test .parentBaseFee ),
299+ Time : test .parentTime ,
283300 }
284301 parent .Extra = EncodeOptimismExtraData (opConfig (), test .parentTime , denom , elasticity , & test .minBaseFee )
285302 have , want := CalcBaseFee (opConfig (), parent , parent .Time + 2 ), big .NewInt (int64 (test .expectedBaseFee ))
0 commit comments