Skip to content

Commit 30e4f50

Browse files
authored
Only bundle named network metadata when SECONDS_PER_SLOT matches preset (#7534)
* Only bundle named network metadata when SECONDS_PER_SLOT matches preset When customizing `SECONDS_PER_SLOT` to a value that is incompatible with the named networks for the preset (e.g., Hoodi, for `mainnet`), do not bundle support for those named networks as that would fail compilation. * Fix CI additional step
1 parent 5cc18c3 commit 30e4f50

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373

7474
steps:
7575
- name: Fix nim cache conflicts
76-
run: |
76+
run: |
7777
echo "XDG_CACHE_HOME=${{ runner.temp }}/.nim-cache" >> $GITHUB_ENV
7878
echo "CI_CACHE=${{ runner.temp }}/.nbs-cache" >> $GITHUB_ENV
7979
@@ -247,6 +247,11 @@ jobs:
247247
nim c --passC:-fsyntax-only --noLinking:on -d:chronicles_log_level=TRACE "${executable}"
248248
done
249249
250+
- name: Build with custom SECONDS_PER_SLOT
251+
run: |
252+
source env.sh
253+
nim c --passC:-fsyntax-only --noLinking:on -d:chronicles_log_level=TRACE -d:SECONDS_PER_SLOT=1 beacon_chain/nimbus_beacon_node
254+
250255
lint:
251256
name: "Lint"
252257
runs-on: ubuntu-latest

beacon_chain/conf.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,9 @@ proc loadEth2Network*(eth2Network: Option[string]): Eth2NetworkMetadata =
11541154
if eth2Network.isSome:
11551155
getMetadataForNetwork(eth2Network.get)
11561156
else:
1157-
when const_preset == "gnosis":
1157+
when IsGnosisSupported:
11581158
getMetadataForNetwork("gnosis")
1159-
elif const_preset == "mainnet":
1159+
elif IsMainnetSupported:
11601160
getMetadataForNetwork("mainnet")
11611161
else:
11621162
# Presumably other configurations can have other defaults, but for now

beacon_chain/networking/network_metadata.nim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ proc loadCompileTimeNetworkMetadata(
201201
else:
202202
macros.error "config.yaml not found for network '" & path
203203

204-
when const_preset == "gnosis":
204+
when IsGnosisSupported:
205205
when incbinEnabled:
206206
let
207207
gnosisGenesisVar {.importc: "gnosis_mainnet_genesis".}: ptr UncheckedArray[byte]
@@ -247,7 +247,7 @@ when const_preset == "gnosis":
247247
doAssert network.cfg.GLOAS_FORK_EPOCH == FAR_FUTURE_EPOCH
248248
doAssert ConsensusFork.high == ConsensusFork.Gloas
249249

250-
elif const_preset == "mainnet":
250+
elif IsMainnetSupported:
251251
when incbinEnabled:
252252
# Nim is very inefficent at loading large constants from binary files so we
253253
# use this trick instead which saves significant amounts of compile time
@@ -360,7 +360,7 @@ proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata =
360360
warn "https://blog.ethereum.org/2025/09/01/holesky-shutdown-announcement suggests migrating to Hoodi or Sepolia"
361361

362362
let metadata =
363-
when const_preset == "gnosis":
363+
when IsGnosisSupported:
364364
case toLowerAscii(networkName)
365365
of "gnosis":
366366
gnosisMetadata
@@ -373,7 +373,7 @@ proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata =
373373
else:
374374
loadRuntimeMetadata()
375375

376-
elif const_preset == "mainnet":
376+
elif IsMainnetSupported:
377377
case toLowerAscii(networkName)
378378
of "mainnet":
379379
mainnetMetadata
@@ -404,9 +404,9 @@ proc getRuntimeConfig*(eth2Network: Option[string]): RuntimeConfig =
404404
if eth2Network.isSome:
405405
getMetadataForNetwork(eth2Network.get)
406406
else:
407-
when const_preset == "mainnet":
407+
when IsMainnetSupported:
408408
mainnetMetadata
409-
elif const_preset == "gnosis":
409+
elif IsGnosisSupported:
410410
gnosisMetadata
411411
else:
412412
# This is a non-standard build (i.e. minimal), and the function was
@@ -416,7 +416,7 @@ proc getRuntimeConfig*(eth2Network: Option[string]): RuntimeConfig =
416416

417417
metadata.cfg
418418

419-
when const_preset in ["mainnet", "gnosis"]:
419+
when IsMainnetSupported or IsGnosisSupported:
420420
template bakedInGenesisStateAsBytes(networkName: untyped): untyped =
421421
when incbinEnabled:
422422
`networkName Genesis`.toOpenArray(0, `networkName GenesisSize` - 1)
@@ -435,22 +435,22 @@ when const_preset in ["mainnet", "gnosis"]:
435435
template bakedBytes*(metadata: GenesisMetadata): auto =
436436
case metadata.networkName
437437
of "mainnet":
438-
when const_preset == "mainnet":
438+
when IsMainnetSupported:
439439
bakedInGenesisStateAsBytes mainnet
440440
else:
441441
raiseAssert availableOnlyInMainnetBuild
442442
of "sepolia":
443-
when const_preset == "mainnet":
443+
when IsMainnetSupported:
444444
bakedInGenesisStateAsBytes sepolia
445445
else:
446446
raiseAssert availableOnlyInMainnetBuild
447447
of "gnosis":
448-
when const_preset == "gnosis":
448+
when IsGnosisSupported:
449449
bakedInGenesisStateAsBytes gnosis
450450
else:
451451
raiseAssert availableOnlyInGnosisBuild
452452
of "chiado":
453-
when const_preset == "gnosis":
453+
when IsGnosisSupported:
454454
bakedInGenesisStateAsBytes chiado
455455
else:
456456
raiseAssert availableOnlyInGnosisBuild

beacon_chain/spec/presets.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,12 @@ else:
729729

730730
# createConstantsFromPreset const_preset
731731

732+
const IsMainnetSupported*: bool =
733+
const_preset == "mainnet" and SECONDS_PER_SLOT == 12
734+
735+
const IsGnosisSupported*: bool =
736+
const_preset == "gnosis" and SECONDS_PER_SLOT == 5
737+
732738
const
733739
MIN_SECONDS_PER_SLOT* = 1'u64
734740
MAX_SECONDS_PER_SLOT* = int64.high.uint64 div 1_000_000_000'u64

0 commit comments

Comments
 (0)