`getMetaData_v3` (#6739)

* add getMetaDataV3

* simpler fix, to review

* drop returns
This commit is contained in:
Agnish Ghosh 2024-11-30 21:23:02 +05:30 committed by GitHub
parent 18f492d929
commit c13b0c94b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 5 deletions

View File

@ -69,7 +69,7 @@ type
protocols: seq[ProtocolInfo] protocols: seq[ProtocolInfo]
## Protocols managed by the DSL and mounted on the switch ## Protocols managed by the DSL and mounted on the switch
protocolStates*: seq[RootRef] protocolStates*: seq[RootRef]
metadata*: altair.MetaData metadata*: fulu.MetaData
connectTimeout*: chronos.Duration connectTimeout*: chronos.Duration
seenThreshold*: chronos.Duration seenThreshold*: chronos.Duration
connQueue: AsyncQueue[PeerAddr] connQueue: AsyncQueue[PeerAddr]
@ -108,7 +108,7 @@ type
lastReqTime*: Moment lastReqTime*: Moment
connections*: int connections*: int
enr*: Opt[enr.Record] enr*: Opt[enr.Record]
metadata*: Opt[altair.MetaData] metadata*: Opt[fulu.MetaData]
failedMetadataRequests: int failedMetadataRequests: int
lastMetadataTime*: Moment lastMetadataTime*: Moment
direction*: PeerType direction*: PeerType
@ -1803,7 +1803,7 @@ proc new(T: type Eth2Node,
let let
connectTimeout = chronos.seconds(10) connectTimeout = chronos.seconds(10)
seenThreshold = 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 # 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 #`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 import ./peer_protocol
export 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]).} = proc updatePeerMetadata(node: Eth2Node, peerId: PeerId) {.async: (raises: [CancelledError]).} =
trace "updating peer metadata", peerId trace "updating peer metadata", peerId
let let
peer = node.getPeer(peerId) peer = node.getPeer(peerId)
newMetadataRes = await peer.getMetadata_v2() newMetadataRes = await node.getMetadata_vx(peer)
newMetadata = newMetadataRes.valueOr: newMetadata = newMetadataRes.valueOr:
debug "Failed to retrieve metadata from peer!", peerId, error = newMetadataRes.error debug "Failed to retrieve metadata from peer!", peerId, error = newMetadataRes.error
peer.failedMetadataRequests.inc() peer.failedMetadataRequests.inc()

View File

@ -169,6 +169,14 @@ p2pProtocol PeerSync(version = 1,
proc getMetadata_v2(peer: Peer): altair.MetaData proc getMetadata_v2(peer: Peer): altair.MetaData
{.libp2pProtocol("metadata", 2).} = {.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 peer.network.metadata
proc goodbye(peer: Peer, reason: uint64) {. proc goodbye(peer: Peer, reason: uint64) {.