Replace deprecated ENR functions (#6419)
This commit is contained in:
parent
738bc0e98f
commit
ca15c4e433
|
@ -1269,8 +1269,11 @@ func completeCmdArg*(T: type WalletName, input: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
proc parseCmdArg*(T: type enr.Record, p: string): T {.raises: [ValueError].} =
|
proc parseCmdArg*(T: type enr.Record, p: string): T {.raises: [ValueError].} =
|
||||||
if not fromURI(result, p):
|
let res = enr.Record.fromURI(p)
|
||||||
raise newException(ValueError, "Invalid ENR")
|
if res.isErr:
|
||||||
|
raise newException(ValueError, "Invalid ENR:" & $res.error)
|
||||||
|
|
||||||
|
res.value
|
||||||
|
|
||||||
func completeCmdArg*(T: type enr.Record, val: string): seq[string] =
|
func completeCmdArg*(T: type enr.Record, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
|
@ -25,13 +25,13 @@ type
|
||||||
Eth2DiscoveryId* = NodeId
|
Eth2DiscoveryId* = NodeId
|
||||||
|
|
||||||
func parseBootstrapAddress*(address: string):
|
func parseBootstrapAddress*(address: string):
|
||||||
Result[enr.Record, cstring] =
|
Result[enr.Record, string] =
|
||||||
let lowerCaseAddress = toLowerAscii(address)
|
let lowerCaseAddress = toLowerAscii(address)
|
||||||
if lowerCaseAddress.startsWith("enr:"):
|
if lowerCaseAddress.startsWith("enr:"):
|
||||||
var enrRec: enr.Record
|
let res = enr.Record.fromURI(address)
|
||||||
if enrRec.fromURI(address):
|
if res.isOk():
|
||||||
return ok enrRec
|
return ok res.value
|
||||||
return err "Invalid ENR bootstrap record"
|
return err "Invalid bootstrap ENR: " & $res.error
|
||||||
elif lowerCaseAddress.startsWith("enode:"):
|
elif lowerCaseAddress.startsWith("enode:"):
|
||||||
return err "ENode bootstrap addresses are not supported"
|
return err "ENode bootstrap addresses are not supported"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1391,7 +1391,7 @@ proc connectWorker(node: Eth2Node, index: int) {.async: (raises: [CancelledError
|
||||||
node.connTable.excl(remotePeerAddr.peerId)
|
node.connTable.excl(remotePeerAddr.peerId)
|
||||||
|
|
||||||
proc toPeerAddr(node: Node): Result[PeerAddr, cstring] =
|
proc toPeerAddr(node: Node): Result[PeerAddr, cstring] =
|
||||||
let nodeRecord = ? node.record.toTypedRecord()
|
let nodeRecord = TypedRecord.fromRecord(node.record)
|
||||||
let peerAddr = ? nodeRecord.toPeerAddr(tcpProtocol)
|
let peerAddr = ? nodeRecord.toPeerAddr(tcpProtocol)
|
||||||
ok(peerAddr)
|
ok(peerAddr)
|
||||||
|
|
||||||
|
@ -1883,9 +1883,7 @@ proc start*(node: Eth2Node) {.async: (raises: [CancelledError]).} =
|
||||||
notice "Discovery disabled; trying bootstrap nodes",
|
notice "Discovery disabled; trying bootstrap nodes",
|
||||||
nodes = node.discovery.bootstrapRecords.len
|
nodes = node.discovery.bootstrapRecords.len
|
||||||
for enr in node.discovery.bootstrapRecords:
|
for enr in node.discovery.bootstrapRecords:
|
||||||
let tr = enr.toTypedRecord()
|
let pa = TypedRecord.fromRecord(enr).toPeerAddr(tcpProtocol)
|
||||||
if tr.isOk():
|
|
||||||
let pa = tr.get().toPeerAddr(tcpProtocol)
|
|
||||||
if pa.isOk():
|
if pa.isOk():
|
||||||
await node.connQueue.addLast(pa.get())
|
await node.connQueue.addLast(pa.get())
|
||||||
node.peerPingerHeartbeatFut = node.peerPingerHeartbeat()
|
node.peerPingerHeartbeatFut = node.peerPingerHeartbeat()
|
||||||
|
@ -2279,7 +2277,10 @@ proc createEth2Node*(rng: ref HmacDrbgContext,
|
||||||
let (peerId, address) =
|
let (peerId, address) =
|
||||||
if s.startsWith("enr:"):
|
if s.startsWith("enr:"):
|
||||||
let
|
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 = toPeerAddr(typedEnr, tcpProtocol).get()
|
||||||
(peerAddress.peerId, peerAddress.addrs[0])
|
(peerAddress.peerId, peerAddress.addrs[0])
|
||||||
elif s.startsWith("/"):
|
elif s.startsWith("/"):
|
||||||
|
|
|
@ -108,8 +108,7 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
|
||||||
""
|
""
|
||||||
proc getDiscoveryAddresses(node: BeaconNode): seq[string] =
|
proc getDiscoveryAddresses(node: BeaconNode): seq[string] =
|
||||||
let
|
let
|
||||||
typedRec = node.network.enrRecord().toTypedRecord().valueOr:
|
typedRec = TypedRecord.fromRecord(node.network.enrRecord())
|
||||||
return default(seq[string])
|
|
||||||
peerAddr = typedRec.toPeerAddr(udpProtocol).valueOr:
|
peerAddr = typedRec.toPeerAddr(udpProtocol).valueOr:
|
||||||
return default(seq[string])
|
return default(seq[string])
|
||||||
maddress = MultiAddress.init(multiCodec("p2p"), peerAddr.peerId).valueOr:
|
maddress = MultiAddress.init(multiCodec("p2p"), peerAddr.peerId).valueOr:
|
||||||
|
|
Loading…
Reference in New Issue