Skip to content

Commit 406115a

Browse files
authored
Add BPO fallback test case and fix fallback logic (#3781)
1 parent f3253f4 commit 406115a

File tree

3 files changed

+92
-9
lines changed

3 files changed

+92
-9
lines changed

execution_chain/common/chain_config.nim

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,52 @@ proc validateChainConfig(conf: ChainConfig): bool =
395395
if cur.time.isSome:
396396
lastTimeBasedFork = cur
397397

398+
func numBPOForks(): int {.compileTime.} =
399+
for x in Prague..HardFork.high:
400+
if toLowerAscii($x).startsWith("bpo"):
401+
inc result
402+
403+
func getBPOForks(N: static[int]): array[N, HardFork] {.compileTime.} =
404+
var i = 0
405+
for x in Prague..HardFork.high:
406+
if toLowerAscii($x).startsWith("bpo"):
407+
result[i] = x
408+
inc i
409+
410+
func getRegularForks(N: static[int]): array[N, HardFork] {.compileTime.} =
411+
var i = 0
412+
for x in Prague..HardFork.high:
413+
if not toLowerAscii($x).startsWith("bpo"):
414+
result[i] = x
415+
inc i
416+
417+
const
418+
NumForksWithBlobSchedule = HardFork.high.int - Prague.int + 1 # minus Cancun, but cardinal + 1
419+
NumBPOForks = numBPOForks()
420+
NumRegularForks = NumForksWithBlobSchedule - NumBPOForks
421+
BPOForks = getBPOForks(NumBPOForks)
422+
RegularForks = getRegularForks(NumRegularForks)
423+
398424
proc configureBlobSchedule(conf: ChainConfig) =
399-
var prevFork = Cancun
400425
if conf.blobSchedule[Cancun].isNone:
401426
conf.blobSchedule[Cancun] = Opt.some(BlobSchedule(target: 3'u64, max: 6'u64, baseFeeUpdateFraction: 3_338_477'u64))
402427
else:
403428
if conf.blobSchedule[Cancun].value.baseFeeUpdateFraction == 0:
404429
conf.blobSchedule[Cancun].value.baseFeeUpdateFraction = 3_338_477'u64
405430

406-
for fork in Prague..HardFork.high:
407-
if conf.blobSchedule[fork].isNone:
408-
conf.blobSchedule[fork] = conf.blobSchedule[prevFork]
409-
if conf.blobSchedule[fork].value.baseFeeUpdateFraction == 0:
410-
# Set fallback to Cancun's baseFeeUpdateFraction and prevent division by zero
411-
warn "baseFeeUpdateFraction not set, fallback to Cancun's", fork=fork
412-
conf.blobSchedule[fork].value.baseFeeUpdateFraction = 3_338_477'u64
413-
prevFork = fork
431+
template setBlobScheduleWithFallback(forks) =
432+
var prevFork = Cancun
433+
for fork in forks:
434+
if conf.blobSchedule[fork].isNone:
435+
conf.blobSchedule[fork] = conf.blobSchedule[prevFork]
436+
if conf.blobSchedule[fork].value.baseFeeUpdateFraction == 0:
437+
# Set fallback to Cancun's baseFeeUpdateFraction and prevent division by zero
438+
warn "baseFeeUpdateFraction not set, fallback to Cancun's", fork=fork
439+
conf.blobSchedule[fork].value.baseFeeUpdateFraction = 3_338_477'u64
440+
prevFork = fork
441+
442+
setBlobScheduleWithFallback(RegularForks)
443+
setBlobScheduleWithFallback(BPOForks)
414444

415445
proc parseGenesis*(data: string): Genesis
416446
{.gcsafe.} =
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"config": {
3+
"chainId": 7042643276,
4+
"homesteadBlock": 0,
5+
"eip150Block": 0,
6+
"eip155Block": 0,
7+
"eip158Block": 0,
8+
"byzantiumBlock": 0,
9+
"constantinopleBlock": 0,
10+
"petersburgBlock": 0,
11+
"istanbulBlock": 0,
12+
"berlinBlock": 0,
13+
"londonBlock": 0,
14+
"mergeNetsplitBlock": 0,
15+
"terminalTotalDifficulty": 0,
16+
"terminalTotalDifficultyPassed": true,
17+
"shanghaiTime": 0,
18+
"cancunTime": 0,
19+
"blobSchedule": {
20+
"cancun": {
21+
"target": 3,
22+
"max": 6,
23+
"baseFeeUpdateFraction": 3338477
24+
},
25+
"prague": {
26+
"target": 6,
27+
"max": 9,
28+
"baseFeeUpdateFraction": 5007716
29+
},
30+
"bpo1": {
31+
"target": 9,
32+
"max": 12,
33+
"baseFeeUpdateFraction": 5008888
34+
},
35+
},
36+
"depositContractAddress": "0x00000000219ab540356cBB839Cbe05303d7705Fa",
37+
"pragueTime": 0,
38+
"osakaTime": 1748362704,
39+
"bpo1Time": 1748461008,
40+
"bpo2Time": 1748559312,
41+
"bpo3Time": 1748657616,
42+
"bpo4Time": 1748755920,
43+
"bpo5Time": 1748872656
44+
}
45+
}

tests/test_genesis.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ proc customGenesisTest() =
195195
validateBlobSchedule(cg, Bpo4, 6, 9, 5007716)
196196
validateBlobSchedule(cg, Bpo5, 15, 20, 5007716)
197197

198+
check loadNetworkParams("blobschedule_amsterdam_fallback.json".findFilePath, cg)
199+
validateBlobSchedule(cg, Cancun, 3, 6, 3338477)
200+
validateBlobSchedule(cg, Prague, 6, 9, 5007716)
201+
validateBlobSchedule(cg, Osaka, 6, 9, 5007716) # fallback to Prague
202+
validateBlobSchedule(cg, Bpo1, 9, 12, 5008888)
203+
validateBlobSchedule(cg, Amsterdam, 6, 9, 5007716) # fallback to Osaka, not Bpo1
204+
205+
198206
proc genesisMain() =
199207
genesisTest()
200208
customGenesisTest()

0 commit comments

Comments
 (0)