diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index 8ec54e6ea..ae3394879 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -1269,8 +1269,11 @@ func completeCmdArg*(T: type WalletName, input: string): seq[string] = return @[] proc parseCmdArg*(T: type enr.Record, p: string): T {.raises: [ValueError].} = - if not fromURI(result, p): - raise newException(ValueError, "Invalid ENR") + let res = enr.Record.fromURI(p) + if res.isErr: + raise newException(ValueError, "Invalid ENR:" & $res.error) + + res.value func completeCmdArg*(T: type enr.Record, val: string): seq[string] = return @[] diff --git a/beacon_chain/networking/eth2_discovery.nim b/beacon_chain/networking/eth2_discovery.nim index 7ead407f7..8bb648dba 100644 --- a/beacon_chain/networking/eth2_discovery.nim +++ b/beacon_chain/networking/eth2_discovery.nim @@ -25,13 +25,13 @@ type Eth2DiscoveryId* = NodeId func parseBootstrapAddress*(address: string): - Result[enr.Record, cstring] = + Result[enr.Record, string] = let lowerCaseAddress = toLowerAscii(address) if lowerCaseAddress.startsWith("enr:"): - var enrRec: enr.Record - if enrRec.fromURI(address): - return ok enrRec - return err "Invalid ENR bootstrap record" + let res = enr.Record.fromURI(address) + if res.isOk(): + return ok res.value + return err "Invalid bootstrap ENR: " & $res.error elif lowerCaseAddress.startsWith("enode:"): return err "ENode bootstrap addresses are not supported" else: diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 654548b03..da37cd324 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -1391,7 +1391,7 @@ proc connectWorker(node: Eth2Node, index: int) {.async: (raises: [CancelledError node.connTable.excl(remotePeerAddr.peerId) proc toPeerAddr(node: Node): Result[PeerAddr, cstring] = - let nodeRecord = ? node.record.toTypedRecord() + let nodeRecord = TypedRecord.fromRecord(node.record) let peerAddr = ? nodeRecord.toPeerAddr(tcpProtocol) ok(peerAddr) @@ -1883,11 +1883,9 @@ proc start*(node: Eth2Node) {.async: (raises: [CancelledError]).} = notice "Discovery disabled; trying bootstrap nodes", nodes = node.discovery.bootstrapRecords.len for enr in node.discovery.bootstrapRecords: - let tr = enr.toTypedRecord() - if tr.isOk(): - let pa = tr.get().toPeerAddr(tcpProtocol) - if pa.isOk(): - await node.connQueue.addLast(pa.get()) + let pa = TypedRecord.fromRecord(enr).toPeerAddr(tcpProtocol) + if pa.isOk(): + await node.connQueue.addLast(pa.get()) node.peerPingerHeartbeatFut = node.peerPingerHeartbeat() node.peerTrimmerHeartbeatFut = node.peerTrimmerHeartbeat() @@ -2279,7 +2277,10 @@ proc createEth2Node*(rng: ref HmacDrbgContext, let (peerId, address) = if s.startsWith("enr:"): let - typedEnr = parseBootstrapAddress(s).get().toTypedRecord().get() + enr = parseBootstrapAddress(s).valueOr: + fatal "Failed to parse bootstrap address", enr=s + quit 1 + typedEnr = TypedRecord.fromRecord(enr) peerAddress = toPeerAddr(typedEnr, tcpProtocol).get() (peerAddress.peerId, peerAddress.addrs[0]) elif s.startsWith("/"): diff --git a/beacon_chain/rpc/rest_node_api.nim b/beacon_chain/rpc/rest_node_api.nim index b6465b11f..a9a5a114e 100644 --- a/beacon_chain/rpc/rest_node_api.nim +++ b/beacon_chain/rpc/rest_node_api.nim @@ -108,8 +108,7 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string = "" proc getDiscoveryAddresses(node: BeaconNode): seq[string] = let - typedRec = node.network.enrRecord().toTypedRecord().valueOr: - return default(seq[string]) + typedRec = TypedRecord.fromRecord(node.network.enrRecord()) peerAddr = typedRec.toPeerAddr(udpProtocol).valueOr: return default(seq[string]) maddress = MultiAddress.init(multiCodec("p2p"), peerAddr.peerId).valueOr: