Skip to content

Commit 7d81ee1

Browse files
authored
Support reading bootstrap_nodes.yaml (#6751)
* Support reading `bootstrap_nodes.yaml` `bootstrap_nodes.txt` is retired in lieu of `bootstrap_nodes.yaml`, start reading `.yaml` format (similar to `.enr`). * Support Gnosis Chiado format (duplicates of entries in other file)
1 parent 47c1d30 commit 7d81ee1

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

beacon_chain/networking/network_metadata.nim

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import
1818

1919
from std/sequtils import deduplicate, filterIt, mapIt
2020
from std/strutils import
21-
escape, parseBiggestUInt, replace, splitLines, startsWith, strip,
21+
endsWith, escape, parseBiggestUInt, replace, splitLines, startsWith, strip,
2222
toLowerAscii
2323

2424
# TODO(zah):
@@ -91,23 +91,41 @@ type
9191
func 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

112130
proc 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

Comments
 (0)