1818
1919from std/ sequtils import deduplicate, filterIt, mapIt
2020from std/ strutils import
21- escape, parseBiggestUInt, replace, splitLines, startsWith, strip,
21+ endsWith, escape, parseBiggestUInt, replace, splitLines, startsWith, strip,
2222 toLowerAscii
2323
2424# TODO (zah):
9191func hasGenesis * (metadata: Eth2NetworkMetadata ): bool =
9292 metadata.genesis.kind != NoGenesis
9393
94- proc readBootstrapNodes * (path: string ): seq [string ] {.raises : [IOError ].} =
94+ proc readBootstrapNodes (path: string ): seq [string ] {.raises : [IOError ].} =
9595 # Read a list of ENR values from a YAML file containing a flat list of entries
96+ var res: seq [string ]
9697 if fileExists (path):
97- splitLines (readFile (path)).
98- filterIt (it.startsWith (" enr:" )).
99- mapIt (it.strip ())
100- else :
101- @ []
98+ for line in splitLines (readFile (path)):
99+ let line = line.strip ()
100+ if line.startsWith (" enr:" ):
101+ res.add line
102+ elif line.len == 0 or line.startsWith (" #" ):
103+ discard
104+ else :
105+ when nimvm :
106+ raiseAssert " Bootstrap node invalid (" & path & " ): " & line
107+ else :
108+ warn " Ignoring invalid bootstrap node" , path, bootstrapNode = line
109+ res
102110
103- proc readBootEnr * (path: string ): seq [string ] {.raises : [IOError ].} =
111+ proc readBootEnr (path: string ): seq [string ] {.raises : [IOError ].} =
104112 # Read a list of ENR values from a YAML file containing a flat list of entries
113+ var res: seq [string ]
105114 if fileExists (path):
106- splitLines (readFile (path)).
107- filterIt (it.startsWith (" - enr:" )).
108- mapIt (it[2 ..^ 1 ].strip ())
109- else :
110- @ []
115+ for line in splitLines (readFile (path)):
116+ let line = line.strip ()
117+ if line.startsWith (" - enr:" ):
118+ res.add line[2 .. ^ 1 ]
119+ elif line.startsWith (" - \" enr:" ) and line.endsWith (" \" " ):
120+ res.add line[3 .. ^ 2 ] # Gnosis Chiado `boot_enr.yaml`
121+ elif line.len == 0 or line.startsWith (" #" ):
122+ discard
123+ else :
124+ when nimvm :
125+ raiseAssert " Bootstrap ENR invalid (" & path & " ): " & line
126+ else :
127+ warn " Ignoring invalid bootstrap ENR" , path, bootstrapEnr = line
128+ res
111129
112130proc loadEth2NetworkMetadata * (
113131 path: string ,
@@ -126,7 +144,8 @@ proc loadEth2NetworkMetadata*(
126144 deployBlockPath = path & " /deploy_block.txt"
127145 depositContractBlockPath = path & " /deposit_contract_block.txt"
128146 depositContractBlockHashPath = path & " /deposit_contract_block_hash.txt"
129- bootstrapNodesPath = path & " /bootstrap_nodes.txt"
147+ bootstrapNodesLegacyPath = path & " /bootstrap_nodes.txt" # <= Dec 2024
148+ bootstrapNodesPath = path & " /bootstrap_nodes.yaml"
130149 bootEnrPath = path & " /boot_enr.yaml"
131150 runtimeConfig = if fileExists (configPath):
132151 let (cfg, unknowns) = readRuntimeConfig (configPath)
@@ -178,7 +197,8 @@ proc loadEth2NetworkMetadata*(
178197 default (Eth2Digest )
179198
180199 bootstrapNodes = deduplicate (
181- readBootstrapNodes (bootstrapNodesPath) &
200+ readBootstrapNodes (bootstrapNodesLegacyPath) &
201+ readBootEnr (bootstrapNodesPath) &
182202 readBootEnr (bootEnrPath))
183203
184204 ok Eth2NetworkMetadata (
@@ -268,7 +288,7 @@ when const_preset == "gnosis":
268288
269289 for network in [gnosisMetadata, chiadoMetadata]:
270290 doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
271- doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
291+ doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
272292 doAssert network.cfg.FULU_FORK_EPOCH == FAR_FUTURE_EPOCH
273293 doAssert ConsensusFork .high == ConsensusFork .Fulu
274294
0 commit comments