diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 3ffd88c8c3..f585738e5f 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -69,7 +69,7 @@ type protocols: seq[ProtocolInfo] ## Protocols managed by the DSL and mounted on the switch protocolStates*: seq[RootRef] - metadata*: altair.MetaData + metadata*: fulu.MetaData connectTimeout*: chronos.Duration seenThreshold*: chronos.Duration connQueue: AsyncQueue[PeerAddr] @@ -108,7 +108,7 @@ type lastReqTime*: Moment connections*: int enr*: Opt[enr.Record] - metadata*: Opt[altair.MetaData] + metadata*: Opt[fulu.MetaData] failedMetadataRequests: int lastMetadataTime*: Moment direction*: PeerType @@ -1803,7 +1803,7 @@ proc new(T: type Eth2Node, let connectTimeout = chronos.seconds(10) seenThreshold = chronos.seconds(10) - type MetaData = altair.MetaData # Weird bug without this.. + type MetaData = fulu.MetaData # Weird bug without this.. # Versions up to v22.3.0 would write an empty `MetaData` to #`data-dir/node-metadata.json` which would then be reloaded on startup - don't @@ -2082,12 +2082,33 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend = import ./peer_protocol export peer_protocol +proc updateMetadataV2ToV3(metadataRes: NetRes[altair.MetaData]): + NetRes[fulu.MetaData] = + if metadataRes.isOk: + let metadata = metadataRes.get + ok(fulu.MetaData(seq_number: metadata.seq_number, + attnets: metadata.attnets, + syncnets: metadata.syncnets)) + else: + err(metadataRes.error) + +proc getMetadata_vx(node: Eth2Node, peer: Peer): + Future[NetRes[fulu.MetaData]] + {.async: (raises: [CancelledError]).} = + let + res = + if node.cfg.FULU_FORK_EPOCH != FAR_FUTURE_EPOCH: + # Directly fetch fulu metadata if available + await getMetadata_v3(peer) + else: + updateMetadataV2ToV3(await getMetadata_v2(peer)) + return res + proc updatePeerMetadata(node: Eth2Node, peerId: PeerId) {.async: (raises: [CancelledError]).} = trace "updating peer metadata", peerId - let peer = node.getPeer(peerId) - newMetadataRes = await peer.getMetadata_v2() + newMetadataRes = await node.getMetadata_vx(peer) newMetadata = newMetadataRes.valueOr: debug "Failed to retrieve metadata from peer!", peerId, error = newMetadataRes.error peer.failedMetadataRequests.inc() diff --git a/beacon_chain/networking/peer_protocol.nim b/beacon_chain/networking/peer_protocol.nim index 429e6ccdff..9c6d32486d 100644 --- a/beacon_chain/networking/peer_protocol.nim +++ b/beacon_chain/networking/peer_protocol.nim @@ -169,6 +169,14 @@ p2pProtocol PeerSync(version = 1, proc getMetadata_v2(peer: Peer): altair.MetaData {.libp2pProtocol("metadata", 2).} = + let altair_metadata = altair.MetaData( + seq_number: peer.network.metadata.seq_number, + attnets: peer.network.metadata.attnets, + syncnets: peer.network.metadata.syncnets) + altair_metadata + + proc getMetadata_v3(peer: Peer): fulu.MetaData + {. libp2pProtocol("metadata", 3).} = peer.network.metadata proc goodbye(peer: Peer, reason: uint64) {.