@@ -381,13 +381,53 @@ func TestSuggestGasPricePreAP3(t *testing.T) {
381381 require .NoError (t , err )
382382}
383383
384+ // NOTE: [Oracle.SuggestTipCap] does NOT simply return the "required" (minimum) tip.
385+ // The oracle computes a percentile of recent required tips (not observed on-chain tips)
386+ // within a time/blocks lookback window and applies a small floor (e.g., 1 wei in tests):
387+ //
388+ // suggested = max(floor, recent-required-percentile)
389+ //
390+ // After Granite, BlockGasCost is 0 and per-block required tips are 0, so the oracle
391+ // suggestion equals the floor (1 wei) in steady state, regardless of high on-chain tips.
392+ // The cases below exercise behavior across forks using the same percentile logic and floor.
384393func TestSuggestTipCapMaxBlocksLookback (t * testing.T ) {
394+ cases := []struct {
395+ chainConfig * params.ChainConfig
396+ expectedTip * big.Int
397+ }{
398+ // TODO: remove Fortuna case when we activate Granite
399+ {
400+ chainConfig : params .TestFortunaChainConfig ,
401+ expectedTip : big .NewInt (3 ),
402+ },
403+ {
404+ chainConfig : params .TestChainConfig ,
405+ expectedTip : big .NewInt (1 ),
406+ },
407+ }
408+ for _ , c := range cases {
409+ applyGasPriceTest (t , suggestTipCapTest {
410+ chainConfig : c .chainConfig ,
411+ numBlocks : 200 ,
412+ extDataGasUsage : common .Big0 ,
413+ genBlock : testGenBlock (t , 550 , 80 ),
414+ expectedTip : c .expectedTip ,
415+ }, defaultOracleConfig ())
416+ }
417+ }
418+
419+ // Post-Granite, even very high observed tx tips should not affect SuggestTipCap, which
420+ // is computed from required tips. Since required tips are 0 in Granite, the returned
421+ // suggestion should be the floor (1 wei).
422+ func TestSuggestTipCapIgnoresObservedTipsPostGranite (t * testing.T ) {
385423 applyGasPriceTest (t , suggestTipCapTest {
386- chainConfig : params .TestChainConfig ,
387- numBlocks : 200 ,
424+ chainConfig : params .TestChainConfig , // Granite active in TestChainConfig
425+ numBlocks : 20 ,
388426 extDataGasUsage : common .Big0 ,
389- genBlock : testGenBlock (t , 550 , 80 ),
390- expectedTip : big .NewInt (3 ),
427+ // Generate blocks with very high on-chain tips to ensure they wouldn't bias the result
428+ // if the oracle looked at observed tips. Expectation remains 1 wei.
429+ genBlock : testGenBlock (t , 100_000 , 80 ),
430+ expectedTip : big .NewInt (1 ),
391431 }, defaultOracleConfig ())
392432}
393433
@@ -402,14 +442,30 @@ func TestSuggestTipCapMaxBlocksSecondsLookback(t *testing.T) {
402442}
403443
404444func TestSuggestTipCapIncludesExtraDataGas (t * testing.T ) {
405- applyGasPriceTest (t , suggestTipCapTest {
406- chainConfig : params .TestChainConfig ,
407- numBlocks : 1000 ,
408- extDataGasUsage : big .NewInt (acp176 .MinMaxPerSecond - int64 (ethparams .TxGas )),
409- // The tip on the transaction is very large to pay the block gas cost.
410- genBlock : testGenBlock (t , 100_000 , 1 ),
411- // The actual tip doesn't matter, we just want to ensure that the tip is
412- // non-zero when almost all the gas is coming from the extDataGasUsage.
413- expectedTip : big .NewInt (44_252 ),
414- }, defaultOracleConfig ())
445+ cases := []struct {
446+ chainConfig * params.ChainConfig
447+ expectedTip * big.Int
448+ }{
449+ // TODO: remove Fortuna case when we activate Granite
450+ {
451+ chainConfig : params .TestFortunaChainConfig ,
452+ expectedTip : big .NewInt (44_252 ),
453+ },
454+ {
455+ chainConfig : params .TestChainConfig ,
456+ expectedTip : big .NewInt (1 ),
457+ },
458+ }
459+ for _ , c := range cases {
460+ applyGasPriceTest (t , suggestTipCapTest {
461+ chainConfig : c .chainConfig ,
462+ numBlocks : 1000 ,
463+ extDataGasUsage : big .NewInt (acp176 .MinMaxPerSecond - int64 (ethparams .TxGas )),
464+ // The tip on the transaction is very large to pay the block gas cost.
465+ genBlock : testGenBlock (t , 100_000 , 1 ),
466+ // The actual tip doesn't matter, we just want to ensure that the tip is
467+ // non-zero when almost all the gas is coming from the extDataGasUsage.
468+ expectedTip : c .expectedTip ,
469+ }, defaultOracleConfig ())
470+ }
415471}
0 commit comments