`getMetaData_v3` (#6739)
* add getMetaDataV3 * simpler fix, to review * drop returns
This commit is contained in:
parent
18f492d929
commit
c13b0c94b9
|
@ -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()
|
||||
|
|
|
@ -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) {.
|
||||
|
|
Loading…
Reference in New Issue