Skip to content

Commit bd9eb5c

Browse files
authored
Fix blobSchedule fallback (#3977)
* Fix blobSchedule fallback Failing hive tests for bal-devnet-2 indicate that blobSchedule should not fallback to forks without time activation field. * Lint
1 parent 76b99ac commit bd9eb5c

File tree

7 files changed

+39
-44
lines changed

7 files changed

+39
-44
lines changed

execution_chain/common/chain_config.nim

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2021-2025 Status Research & Development GmbH
2+
# Copyright (c) 2021-2026 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -394,31 +394,16 @@ proc validateChainConfig(conf: ChainConfig): bool =
394394
if cur.time.isSome:
395395
lastTimeBasedFork = cur
396396

397-
func numBPOForks(): int {.compileTime.} =
398-
for x in Prague..HardFork.high:
399-
if toLowerAscii($x).startsWith("bpo"):
400-
inc result
401-
402-
func getBPOForks(N: static[int]): array[N, HardFork] {.compileTime.} =
403-
var i = 0
404-
for x in Prague..HardFork.high:
405-
if toLowerAscii($x).startsWith("bpo"):
406-
result[i] = x
407-
inc i
408-
409-
func getRegularForks(N: static[int]): array[N, HardFork] {.compileTime.} =
410-
var i = 0
411-
for x in Prague..HardFork.high:
412-
if not toLowerAscii($x).startsWith("bpo"):
413-
result[i] = x
414-
inc i
397+
macro blobScheduleActivation(conf: typed): untyped =
398+
# Automated blob schedule parser generator
399+
var res = nnkBracket.newTree
400+
for fork in Cancun..HardFork.high:
401+
let activationName = BlobScheduleTable[fork] & "Time"
402+
let fieldIdent = newIdentNode(activationName)
403+
res.add quote do:
404+
`conf`.`fieldIdent`
415405

416-
const
417-
NumForksWithBlobSchedule = HardFork.high.int - Prague.int + 1 # minus Cancun, but cardinal + 1
418-
NumBPOForks = numBPOForks()
419-
NumRegularForks = NumForksWithBlobSchedule - NumBPOForks
420-
BPOForks = getBPOForks(NumBPOForks)
421-
RegularForks = getRegularForks(NumRegularForks)
406+
res
422407

423408
proc configureBlobSchedule(conf: ChainConfig) =
424409
if conf.blobSchedule[Cancun].isNone:
@@ -427,20 +412,19 @@ proc configureBlobSchedule(conf: ChainConfig) =
427412
if conf.blobSchedule[Cancun].value.baseFeeUpdateFraction == 0:
428413
conf.blobSchedule[Cancun].value.baseFeeUpdateFraction = 3_338_477'u64
429414

430-
template setBlobScheduleWithFallback(forks) =
431-
var prevFork = Cancun
432-
for fork in forks:
433-
if conf.blobSchedule[fork].isNone:
434-
conf.blobSchedule[fork] = conf.blobSchedule[prevFork]
435-
if conf.blobSchedule[fork].value.baseFeeUpdateFraction == 0:
436-
# Set fallback to Cancun's baseFeeUpdateFraction and prevent division by zero
437-
warn "baseFeeUpdateFraction not set, fallback to Cancun's", fork=fork
438-
conf.blobSchedule[fork].value.baseFeeUpdateFraction = 3_338_477'u64
415+
let blobScheduleTime: array[Cancun..HardFork.high, Opt[EthTime]] = blobScheduleActivation(conf)
416+
417+
var prevFork = Cancun
418+
for fork in Prague..HardFork.high:
419+
if conf.blobSchedule[fork].isNone:
420+
conf.blobSchedule[fork] = conf.blobSchedule[prevFork]
421+
if conf.blobSchedule[fork].value.baseFeeUpdateFraction == 0:
422+
# Set fallback to Cancun's baseFeeUpdateFraction and prevent division by zero
423+
warn "baseFeeUpdateFraction not set, fallback to Cancun's", fork=fork
424+
conf.blobSchedule[fork].value.baseFeeUpdateFraction = 3_338_477'u64
425+
if blobScheduleTime[fork].isSome:
439426
prevFork = fork
440427

441-
setBlobScheduleWithFallback(RegularForks)
442-
setBlobScheduleWithFallback(BPOForks)
443-
444428
proc parseGenesis*(data: string): Genesis
445429
{.gcsafe.} =
446430
try:

tests/customgenesis/blobschedule_amsterdam_fallback.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131
"target": 9,
3232
"max": 12,
3333
"baseFeeUpdateFraction": 5008888
34-
},
34+
},
35+
"bpo2": {
36+
"target": 10,
37+
"max": 13,
38+
"baseFeeUpdateFraction": 5009999
39+
},
3540
},
3641
"depositContractAddress": "0x00000000219ab540356cBB839Cbe05303d7705Fa",
3742
"pragueTime": 0,
3843
"osakaTime": 1748362704,
3944
"bpo1Time": 1748461008,
40-
"bpo2Time": 1748559312,
41-
"bpo3Time": 1748657616,
42-
"bpo4Time": 1748755920,
43-
"bpo5Time": 1748872656
4445
}
4546
}

tests/customgenesis/blobschedule_cancun_osaka.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"muirGlacierBlock": 0,
1414
"berlinBlock": 0,
1515
"londonBlock": 0,
16+
"cancunTime": 0,
17+
"pragueTime": 0,
18+
"osakaTime": 0,
1619
"blobSchedule": {
1720
"cancun": {
1821
"target": 3,

tests/customgenesis/blobschedule_cancun_prague.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"muirGlacierBlock": 0,
1414
"berlinBlock": 0,
1515
"londonBlock": 0,
16+
"cancunTime": 0,
17+
"pragueTime": 0,
18+
"osakaTime": 0,
1619
"blobSchedule": {
1720
"cancun": {
1821
"target": 3,

tests/customgenesis/blobschedule_nobasefee.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"muirGlacierBlock": 0,
1414
"berlinBlock": 0,
1515
"londonBlock": 0,
16+
"cancunTime": 0,
17+
"pragueTime": 0,
1618
"blobSchedule": {
1719
"cancun": {
1820
"target": 3,

tests/customgenesis/blobschedule_prague.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"muirGlacierBlock": 0,
1414
"berlinBlock": 0,
1515
"londonBlock": 0,
16+
"cancunTime": 0,
17+
"pragueTime": 0,
1618
"blobSchedule": {
1719
"prague": {
1820
"target": 6,

tests/test_genesis.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2019-2025 Status Research & Development GmbH
2+
# Copyright (c) 2019-2026 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
55
# http://www.apache.org/licenses/LICENSE-2.0)
@@ -174,7 +174,7 @@ proc customGenesisTest() =
174174
validateBlobSchedule(cg, Prague, 6, 9, 5007716)
175175
validateBlobSchedule(cg, Osaka, 6, 9, 5007716) # fallback to Prague
176176
validateBlobSchedule(cg, Bpo1, 9, 12, 5008888)
177-
validateBlobSchedule(cg, Amsterdam, 6, 9, 5007716) # fallback to Osaka, not Bpo1
177+
validateBlobSchedule(cg, Amsterdam, 9, 12, 5008888) # fallback to bpo1, not Bpo2
178178

179179

180180
proc genesisMain() =

0 commit comments

Comments
 (0)