More proper fix replacing hotfix 052a6ac3bc
nim-eth was bumped to take advantage of a fixed `==` for public eth keys
This commit is contained in:
parent
3b9e9fefa8
commit
55886ff0ac
|
@ -128,6 +128,7 @@ proc getStateFromSnapshot(conf: BeaconNodeConf, state: var BeaconState): bool =
|
||||||
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
|
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
|
||||||
let
|
let
|
||||||
netKeys = getPersistentNetKeys(conf)
|
netKeys = getPersistentNetKeys(conf)
|
||||||
|
ourPubKey = netKeys.pubkey.skkey
|
||||||
nickname = if conf.nodeName == "auto": shortForm(netKeys)
|
nickname = if conf.nodeName == "auto": shortForm(netKeys)
|
||||||
else: conf.nodeName
|
else: conf.nodeName
|
||||||
db = BeaconChainDB.init(kvStore LmdbStoreRef.init(conf.databaseDir))
|
db = BeaconChainDB.init(kvStore LmdbStoreRef.init(conf.databaseDir))
|
||||||
|
@ -183,14 +184,18 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async
|
||||||
|
|
||||||
var bootNodes: seq[ENode]
|
var bootNodes: seq[ENode]
|
||||||
var bootEnrs: seq[enr.Record]
|
var bootEnrs: seq[enr.Record]
|
||||||
for node in conf.bootstrapNodes: addBootstrapNode(node, bootNodes, bootEnrs)
|
for node in conf.bootstrapNodes: addBootstrapNode(node, bootNodes, bootEnrs, ourPubKey)
|
||||||
loadBootstrapFile(string conf.bootstrapNodesFile, bootNodes, bootEnrs)
|
loadBootstrapFile(string conf.bootstrapNodesFile, bootNodes, bootEnrs, ourPubKey)
|
||||||
|
|
||||||
|
when networkBackend == libp2pDaemon:
|
||||||
|
for enr in bootEnrs:
|
||||||
|
let enode = toENode(enr)
|
||||||
|
if enode.isOk:
|
||||||
|
bootNodes.add enode.value
|
||||||
|
|
||||||
let persistentBootstrapFile = conf.dataDir / "bootstrap_nodes.txt"
|
let persistentBootstrapFile = conf.dataDir / "bootstrap_nodes.txt"
|
||||||
if fileExists(persistentBootstrapFile):
|
if fileExists(persistentBootstrapFile):
|
||||||
loadBootstrapFile(persistentBootstrapFile, bootNodes, bootEnrs)
|
loadBootstrapFile(persistentBootstrapFile, bootNodes, bootEnrs, ourPubKey)
|
||||||
|
|
||||||
bootNodes = filterIt(bootNodes, it.pubkey != netKeys.pubkey.skkey)
|
|
||||||
|
|
||||||
let
|
let
|
||||||
network = await createEth2Node(conf, bootNodes)
|
network = await createEth2Node(conf, bootNodes)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import
|
||||||
type
|
type
|
||||||
Eth2DiscoveryProtocol* = protocol.Protocol
|
Eth2DiscoveryProtocol* = protocol.Protocol
|
||||||
Eth2DiscoveryId* = NodeId
|
Eth2DiscoveryId* = NodeId
|
||||||
|
PublicKey = keys.PublicKey
|
||||||
|
|
||||||
export
|
export
|
||||||
Eth2DiscoveryProtocol, open, start, close, result
|
Eth2DiscoveryProtocol, open, start, close, result
|
||||||
|
@ -82,15 +83,22 @@ proc toENode*(enrRec: enr.Record): Result[ENode, cstring] =
|
||||||
let
|
let
|
||||||
ip = IpAddress(family: IpAddressFamily.IPv4,
|
ip = IpAddress(family: IpAddressFamily.IPv4,
|
||||||
address_v4: toArray(4, ipBytes))
|
address_v4: toArray(4, ipBytes))
|
||||||
|
tcpPort = Port enrRec.get("tcp", uint16)
|
||||||
udpPort = Port enrRec.get("udp", uint16)
|
udpPort = Port enrRec.get("udp", uint16)
|
||||||
var pubKey: keys.PublicKey
|
var pubKey: keys.PublicKey
|
||||||
if not enrRec.get(pubKey):
|
if not enrRec.get(pubKey):
|
||||||
return err "Failed to read public key from ENR record"
|
return err "Failed to read public key from ENR record"
|
||||||
return ok ENode(pubkey: pubkey,
|
return ok ENode(pubkey: pubkey,
|
||||||
address: Address(ip: ip, udpPort: udpPort))
|
address: Address(ip: ip,
|
||||||
|
tcpPort: tcpPort,
|
||||||
|
udpPort: udpPort))
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
return err "Invalid ENR record"
|
return err "Invalid ENR record"
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
# This will be resoted to its more generalized form (returning ENode)
|
||||||
|
# once we refactor the discv5 code to be more easily bootstrapped with
|
||||||
|
# trusted, but non-signed bootstrap addresses.
|
||||||
proc parseBootstrapAddress*(address: TaintedString): Result[enr.Record, cstring] =
|
proc parseBootstrapAddress*(address: TaintedString): Result[enr.Record, cstring] =
|
||||||
if address.len == 0:
|
if address.len == 0:
|
||||||
return err "an empty string is not a valid bootstrap node"
|
return err "an empty string is not a valid bootstrap node"
|
||||||
|
@ -127,27 +135,32 @@ proc parseBootstrapAddress*(address: TaintedString): Result[enr.Record, cstring]
|
||||||
|
|
||||||
proc addBootstrapNode*(bootstrapAddr: string,
|
proc addBootstrapNode*(bootstrapAddr: string,
|
||||||
bootNodes: var seq[ENode],
|
bootNodes: var seq[ENode],
|
||||||
bootEnrs: var seq[enr.Record]) =
|
bootEnrs: var seq[enr.Record],
|
||||||
let enodeRes = parseBootstrapAddress(bootstrapAddr)
|
localPubKey: PublicKey) =
|
||||||
if enodeRes.isOk:
|
let enrRes = parseBootstrapAddress(bootstrapAddr)
|
||||||
bootEnrs.add enodeRes.value
|
if enrRes.isOk:
|
||||||
|
let enodeRes = enrRes.value.toENode
|
||||||
|
if enodeRes.isOk:
|
||||||
|
if enodeRes.value.pubKey != localPubKey:
|
||||||
|
bootEnrs.add enrRes.value
|
||||||
else:
|
else:
|
||||||
warn "Ignoring invalid bootstrap address",
|
warn "Ignoring invalid bootstrap address",
|
||||||
bootstrapAddr, reason = enodeRes.error
|
bootstrapAddr, reason = enrRes.error
|
||||||
|
|
||||||
proc loadBootstrapFile*(bootstrapFile: string,
|
proc loadBootstrapFile*(bootstrapFile: string,
|
||||||
bootNodes: var seq[ENode],
|
bootNodes: var seq[ENode],
|
||||||
bootEnrs: var seq[enr.Record]) =
|
bootEnrs: var seq[enr.Record],
|
||||||
|
localPubKey: PublicKey) =
|
||||||
if bootstrapFile.len == 0: return
|
if bootstrapFile.len == 0: return
|
||||||
let ext = splitFile(bootstrapFile).ext
|
let ext = splitFile(bootstrapFile).ext
|
||||||
if cmpIgnoreCase(ext, ".txt") == 0:
|
if cmpIgnoreCase(ext, ".txt") == 0:
|
||||||
for ln in lines(bootstrapFile):
|
for ln in lines(bootstrapFile):
|
||||||
addBootstrapNode(ln, bootNodes, bootEnrs)
|
addBootstrapNode(ln, bootNodes, bootEnrs, localPubKey)
|
||||||
elif cmpIgnoreCase(ext, ".yaml") == 0:
|
elif cmpIgnoreCase(ext, ".yaml") == 0:
|
||||||
# TODO. This is very ugly, but let's try to negotiate the
|
# TODO. This is very ugly, but let's try to negotiate the
|
||||||
# removal of YAML metadata.
|
# removal of YAML metadata.
|
||||||
for ln in lines(bootstrapFile):
|
for ln in lines(bootstrapFile):
|
||||||
addBootstrapNode(string(ln[3..^2]), bootNodes, bootEnrs)
|
addBootstrapNode(string(ln[3..^2]), bootNodes, bootEnrs, localPubKey)
|
||||||
else:
|
else:
|
||||||
error "Unknown bootstrap file format", ext
|
error "Unknown bootstrap file format", ext
|
||||||
quit 1
|
quit 1
|
||||||
|
|
|
@ -203,12 +203,6 @@ when networkBackend in [libp2p, libp2pDaemon]:
|
||||||
bootstrapEnrs: seq[enr.Record]) {.async.} =
|
bootstrapEnrs: seq[enr.Record]) {.async.} =
|
||||||
when networkBackend == libp2pDaemon:
|
when networkBackend == libp2pDaemon:
|
||||||
var connected = false
|
var connected = false
|
||||||
var bootstrapNodes = bootstrapNodes
|
|
||||||
for enr in bootstrapEnrs:
|
|
||||||
let enode = toENode(enr)
|
|
||||||
if enode.isOk:
|
|
||||||
bootstrapNodes.add enode.value
|
|
||||||
|
|
||||||
for bootstrapNode in bootstrapNodes:
|
for bootstrapNode in bootstrapNodes:
|
||||||
try:
|
try:
|
||||||
let peerInfo = toPeerInfo(bootstrapNode)
|
let peerInfo = toPeerInfo(bootstrapNode)
|
||||||
|
@ -233,11 +227,10 @@ when networkBackend in [libp2p, libp2pDaemon]:
|
||||||
node.addKnownPeer bootstrapNode
|
node.addKnownPeer bootstrapNode
|
||||||
await node.start()
|
await node.start()
|
||||||
|
|
||||||
when false:
|
await sleepAsync(10.seconds)
|
||||||
await sleepAsync(10.seconds)
|
if bootstrapEnrs.len > 0 and libp2p_successful_dials.value == 0:
|
||||||
if libp2p_successful_dials.value == 0:
|
fatal "Failed to connect to any bootstrap node. Quitting", bootstrapEnrs
|
||||||
fatal "Failed to connect to any bootstrap node. Quitting", bootstrapEnrs
|
quit 1
|
||||||
quit 1
|
|
||||||
|
|
||||||
proc saveConnectionAddressFile*(node: Eth2Node, filename: string) =
|
proc saveConnectionAddressFile*(node: Eth2Node, filename: string) =
|
||||||
when networkBackend == libp2p:
|
when networkBackend == libp2p:
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9d7fc76c7a7b713dd509e88ba075b928749e51b2
|
Subproject commit 5ca1a21ecdcb63de71c40f30f5b5d22eb7e344f5
|
Loading…
Reference in New Issue