Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix REST /eth/v1/node/identity should return proper MultiAddresses which is not AnyAddress4/6. #6154

Open
wants to merge 7 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions beacon_chain/networking/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ type
peerId*: PeerId
stamp*: chronos.Moment

ExternalAddressInfo* = object
address*: Opt[IpAddress]
tcp*: Opt[Port]
udp*: Opt[Port]

Eth2Node* = ref object of RootObj
switch*: Switch
pubsub*: GossipSub
Expand Down Expand Up @@ -86,8 +91,9 @@ type
peerTrimmerHeartbeatFut: Future[void].Raising([CancelledError])
cfg: RuntimeConfig
getBeaconTime: GetBeaconTimeFn

quota: TokenBucket ## Global quota mainly for high-bandwidth stuff
externalAddresses*: seq[ExternalAddressInfo]
peerIdent*: PeerId

AverageThroughput* = object
count*: uint64
Expand Down Expand Up @@ -357,6 +363,14 @@ proc openStream(node: Eth2Node,

proc init(T: type Peer, network: Eth2Node, peerId: PeerId): Peer {.gcsafe.}

proc init(T: type ExternalAddressInfo, ip: Option[IpAddress],
tcpPort: Option[Port], udpPort: Option[Port]): ExternalAddressInfo =
ExternalAddressInfo(
address: if ip.isSome(): Opt.some(ip.get()) else: Opt.none(IpAddress),
tcp: if tcpPort.isSome(): Opt.some(tcpPort.get()) else: Opt.none(Port),
udp: if udpPort.isSome(): Opt.some(udpPort.get()) else: Opt.none(Port)
)

proc getState*(peer: Peer, proto: ProtocolInfo): RootRef =
doAssert peer.protocolStates[proto.index] != nil, $proto.index
peer.protocolStates[proto.index]
Expand Down Expand Up @@ -1766,7 +1780,7 @@ proc new(T: type Eth2Node,
switch: Switch, pubsub: GossipSub,
ip: Option[IpAddress], tcpPort, udpPort: Option[Port],
privKey: keys.PrivateKey, discovery: bool,
directPeers: DirectPeers,
directPeers: DirectPeers, peerId: PeerId,
rng: ref HmacDrbgContext): T {.raises: [CatchableError].} =
when not defined(local_testnet):
let
Expand Down Expand Up @@ -1810,7 +1824,9 @@ proc new(T: type Eth2Node,
connectTimeout: connectTimeout,
seenThreshold: seenThreshold,
directPeers: directPeers,
quota: TokenBucket.new(maxGlobalQuota, fullReplenishTime)
quota: TokenBucket.new(maxGlobalQuota, fullReplenishTime),
externalAddresses: @[ExternalAddressInfo.init(ip, tcpPort, udpPort)],
peerIdent: peerId
)

proc peerHook(peerId: PeerId, event: ConnEvent): Future[void] {.gcsafe.} =
Expand Down Expand Up @@ -2357,7 +2373,9 @@ proc createEth2Node*(rng: ref HmacDrbgContext,
let node = Eth2Node.new(
config, cfg, enrForkId, discoveryForkId, forkDigests, getBeaconTime, switch, pubsub, extIp,
extTcpPort, extUdpPort, netKeys.seckey.asEthKey,
discovery = config.discv5Enabled, directPeers, rng = rng)
discovery = config.discv5Enabled, directPeers,
PeerId.init(netKeys.pubkey).get(),
rng = rng)

node.pubsub.subscriptionValidator =
proc(topic: string): bool {.gcsafe, raises: [].} =
Expand Down