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
423408proc 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-
444428proc parseGenesis * (data: string ): Genesis
445429 {.gcsafe .} =
446430 try :
0 commit comments