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)
This commit is contained in:
Etan Kissling 2024-12-09 14:38:56 +01:00 committed by GitHub
parent 47c1d30560
commit 7d81ee17db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,7 +18,7 @@ import
from std/sequtils import deduplicate, filterIt, mapIt from std/sequtils import deduplicate, filterIt, mapIt
from std/strutils import from std/strutils import
escape, parseBiggestUInt, replace, splitLines, startsWith, strip, endsWith, escape, parseBiggestUInt, replace, splitLines, startsWith, strip,
toLowerAscii toLowerAscii
# TODO(zah): # TODO(zah):
@ -91,23 +91,41 @@ type
func hasGenesis*(metadata: Eth2NetworkMetadata): bool = func hasGenesis*(metadata: Eth2NetworkMetadata): bool =
metadata.genesis.kind != NoGenesis metadata.genesis.kind != NoGenesis
proc readBootstrapNodes*(path: string): seq[string] {.raises: [IOError].} = proc readBootstrapNodes(path: string): seq[string] {.raises: [IOError].} =
# Read a list of ENR values from a YAML file containing a flat list of entries # Read a list of ENR values from a YAML file containing a flat list of entries
var res: seq[string]
if fileExists(path): if fileExists(path):
splitLines(readFile(path)). for line in splitLines(readFile(path)):
filterIt(it.startsWith("enr:")). let line = line.strip()
mapIt(it.strip()) if line.startsWith("enr:"):
else: res.add line
@[] elif line.len == 0 or line.startsWith("#"):
discard
else:
when nimvm:
raiseAssert "Bootstrap node invalid (" & path & "): " & line
else:
warn "Ignoring invalid bootstrap node", path, bootstrapNode = line
res
proc readBootEnr*(path: string): seq[string] {.raises: [IOError].} = proc readBootEnr(path: string): seq[string] {.raises: [IOError].} =
# Read a list of ENR values from a YAML file containing a flat list of entries # Read a list of ENR values from a YAML file containing a flat list of entries
var res: seq[string]
if fileExists(path): if fileExists(path):
splitLines(readFile(path)). for line in splitLines(readFile(path)):
filterIt(it.startsWith("- enr:")). let line = line.strip()
mapIt(it[2..^1].strip()) if line.startsWith("- enr:"):
else: res.add line[2 .. ^1]
@[] elif line.startsWith("- \"enr:") and line.endsWith("\""):
res.add line[3 .. ^2] # Gnosis Chiado `boot_enr.yaml`
elif line.len == 0 or line.startsWith("#"):
discard
else:
when nimvm:
raiseAssert "Bootstrap ENR invalid (" & path & "): " & line
else:
warn "Ignoring invalid bootstrap ENR", path, bootstrapEnr = line
res
proc loadEth2NetworkMetadata*( proc loadEth2NetworkMetadata*(
path: string, path: string,
@ -126,7 +144,8 @@ proc loadEth2NetworkMetadata*(
deployBlockPath = path & "/deploy_block.txt" deployBlockPath = path & "/deploy_block.txt"
depositContractBlockPath = path & "/deposit_contract_block.txt" depositContractBlockPath = path & "/deposit_contract_block.txt"
depositContractBlockHashPath = path & "/deposit_contract_block_hash.txt" depositContractBlockHashPath = path & "/deposit_contract_block_hash.txt"
bootstrapNodesPath = path & "/bootstrap_nodes.txt" bootstrapNodesLegacyPath = path & "/bootstrap_nodes.txt" # <= Dec 2024
bootstrapNodesPath = path & "/bootstrap_nodes.yaml"
bootEnrPath = path & "/boot_enr.yaml" bootEnrPath = path & "/boot_enr.yaml"
runtimeConfig = if fileExists(configPath): runtimeConfig = if fileExists(configPath):
let (cfg, unknowns) = readRuntimeConfig(configPath) let (cfg, unknowns) = readRuntimeConfig(configPath)
@ -178,7 +197,8 @@ proc loadEth2NetworkMetadata*(
default(Eth2Digest) default(Eth2Digest)
bootstrapNodes = deduplicate( bootstrapNodes = deduplicate(
readBootstrapNodes(bootstrapNodesPath) & readBootstrapNodes(bootstrapNodesLegacyPath) &
readBootEnr(bootstrapNodesPath) &
readBootEnr(bootEnrPath)) readBootEnr(bootEnrPath))
ok Eth2NetworkMetadata( ok Eth2NetworkMetadata(