2020-05-23 22:24:47 +00:00
|
|
|
|
2020-08-05 23:22:12 +00:00
|
|
|
## Generated at line 84
|
2020-05-23 22:24:47 +00:00
|
|
|
type
|
|
|
|
BeaconSync* = object
|
|
|
|
template State*(PROTO: type BeaconSync): type =
|
|
|
|
ref[BeaconSyncPeerState:ObjectType]
|
|
|
|
|
|
|
|
template NetworkState*(PROTO: type BeaconSync): type =
|
|
|
|
ref[BeaconSyncNetworkState:ObjectType]
|
|
|
|
|
|
|
|
type
|
|
|
|
statusObj* = distinct StatusMsg
|
|
|
|
template status*(PROTO: type BeaconSync): type =
|
|
|
|
StatusMsg
|
|
|
|
|
|
|
|
template msgProtocol*(MSG: type statusObj): type =
|
|
|
|
BeaconSync
|
|
|
|
|
|
|
|
template RecType*(MSG: type statusObj): untyped =
|
|
|
|
StatusMsg
|
|
|
|
|
|
|
|
type
|
|
|
|
pingObj* = distinct uint64
|
|
|
|
template ping*(PROTO: type BeaconSync): type =
|
|
|
|
uint64
|
|
|
|
|
|
|
|
template msgProtocol*(MSG: type pingObj): type =
|
|
|
|
BeaconSync
|
|
|
|
|
|
|
|
template RecType*(MSG: type pingObj): untyped =
|
|
|
|
uint64
|
|
|
|
|
|
|
|
type
|
|
|
|
getMetadataObj* = object
|
|
|
|
|
|
|
|
template getMetadata*(PROTO: type BeaconSync): type =
|
|
|
|
getMetadataObj
|
|
|
|
|
|
|
|
template msgProtocol*(MSG: type getMetadataObj): type =
|
|
|
|
BeaconSync
|
|
|
|
|
|
|
|
template RecType*(MSG: type getMetadataObj): untyped =
|
|
|
|
getMetadataObj
|
|
|
|
|
|
|
|
type
|
|
|
|
beaconBlocksByRangeObj* = object
|
|
|
|
startSlot*: Slot
|
2020-08-05 23:22:12 +00:00
|
|
|
reqCount*: uint64
|
|
|
|
reqStep*: uint64
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
template beaconBlocksByRange*(PROTO: type BeaconSync): type =
|
|
|
|
beaconBlocksByRangeObj
|
|
|
|
|
|
|
|
template msgProtocol*(MSG: type beaconBlocksByRangeObj): type =
|
|
|
|
BeaconSync
|
|
|
|
|
|
|
|
template RecType*(MSG: type beaconBlocksByRangeObj): untyped =
|
|
|
|
beaconBlocksByRangeObj
|
|
|
|
|
|
|
|
type
|
|
|
|
beaconBlocksByRootObj* = distinct BlockRootsList
|
|
|
|
template beaconBlocksByRoot*(PROTO: type BeaconSync): type =
|
|
|
|
BlockRootsList
|
|
|
|
|
|
|
|
template msgProtocol*(MSG: type beaconBlocksByRootObj): type =
|
|
|
|
BeaconSync
|
|
|
|
|
|
|
|
template RecType*(MSG: type beaconBlocksByRootObj): untyped =
|
|
|
|
BlockRootsList
|
|
|
|
|
|
|
|
type
|
2020-06-20 07:24:33 +00:00
|
|
|
goodbyeObj* = distinct uint64
|
2020-05-23 22:24:47 +00:00
|
|
|
template goodbye*(PROTO: type BeaconSync): type =
|
2020-06-20 07:24:33 +00:00
|
|
|
uint64
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
template msgProtocol*(MSG: type goodbyeObj): type =
|
|
|
|
BeaconSync
|
|
|
|
|
|
|
|
template RecType*(MSG: type goodbyeObj): untyped =
|
2020-06-20 07:24:33 +00:00
|
|
|
uint64
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
var BeaconSyncProtocolObj = initProtocol("BeaconSync", createPeerState[Peer,
|
|
|
|
ref[BeaconSyncPeerState:ObjectType]], createNetworkState[Eth2Node,
|
|
|
|
ref[BeaconSyncNetworkState:ObjectType]])
|
|
|
|
var BeaconSyncProtocol = addr BeaconSyncProtocolObj
|
2020-05-25 17:33:03 +00:00
|
|
|
template protocolInfo*(PROTO: type BeaconSync): auto =
|
2020-05-23 22:24:47 +00:00
|
|
|
BeaconSyncProtocol
|
|
|
|
|
|
|
|
proc status*(peer: Peer; theirStatus: StatusMsg;
|
|
|
|
timeout: Duration = milliseconds(10000'i64)): Future[NetRes[StatusMsg]] {.
|
|
|
|
gcsafe, libp2pProtocol("status", 1).} =
|
|
|
|
var outputStream = memoryOutput()
|
|
|
|
var writer = init(WriterType(SSZ), outputStream)
|
|
|
|
writeValue(writer, theirStatus)
|
|
|
|
let msgBytes = getOutput(outputStream)
|
|
|
|
makeEth2Request(peer, "/eth2/beacon_chain/req/status/1/", msgBytes, StatusMsg,
|
|
|
|
timeout)
|
|
|
|
|
|
|
|
proc ping*(peer: Peer; value: uint64; timeout: Duration = milliseconds(10000'i64)): Future[
|
|
|
|
NetRes[uint64]] {.gcsafe, libp2pProtocol("ping", 1).} =
|
|
|
|
var outputStream = memoryOutput()
|
|
|
|
var writer = init(WriterType(SSZ), outputStream)
|
|
|
|
writeValue(writer, value)
|
|
|
|
let msgBytes = getOutput(outputStream)
|
|
|
|
makeEth2Request(peer, "/eth2/beacon_chain/req/ping/1/", msgBytes, uint64, timeout)
|
|
|
|
|
|
|
|
proc getMetadata*(peer: Peer; timeout: Duration = milliseconds(10000'i64)): Future[
|
|
|
|
NetRes[Eth2Metadata]] {.gcsafe, libp2pProtocol("metadata", 1).} =
|
|
|
|
var msgBytes: seq[byte]
|
|
|
|
makeEth2Request(peer, "/eth2/beacon_chain/req/metadata/1/", msgBytes,
|
|
|
|
Eth2Metadata, timeout)
|
|
|
|
|
2020-08-05 23:22:12 +00:00
|
|
|
proc beaconBlocksByRange*(peer: Peer; startSlot: Slot; reqCount: uint64;
|
|
|
|
reqStep: uint64;
|
2020-05-23 22:24:47 +00:00
|
|
|
timeout: Duration = milliseconds(10000'i64)): Future[
|
|
|
|
NetRes[seq[SignedBeaconBlock]]] {.gcsafe, libp2pProtocol(
|
|
|
|
"beacon_blocks_by_range", 1).} =
|
|
|
|
var outputStream = memoryOutput()
|
|
|
|
var writer = init(WriterType(SSZ), outputStream)
|
|
|
|
var recordWriterCtx = beginRecord(writer, beaconBlocksByRangeObj)
|
|
|
|
writeField(writer, recordWriterCtx, "startSlot", startSlot)
|
2020-08-05 23:22:12 +00:00
|
|
|
writeField(writer, recordWriterCtx, "reqCount", reqCount)
|
|
|
|
writeField(writer, recordWriterCtx, "reqStep", reqStep)
|
2020-05-23 22:24:47 +00:00
|
|
|
endRecord(writer, recordWriterCtx)
|
|
|
|
let msgBytes = getOutput(outputStream)
|
|
|
|
makeEth2Request(peer, "/eth2/beacon_chain/req/beacon_blocks_by_range/1/",
|
|
|
|
msgBytes, seq[SignedBeaconBlock], timeout)
|
|
|
|
|
|
|
|
proc beaconBlocksByRoot*(peer: Peer; blockRoots: BlockRootsList;
|
|
|
|
timeout: Duration = milliseconds(10000'i64)): Future[
|
|
|
|
NetRes[seq[SignedBeaconBlock]]] {.gcsafe,
|
|
|
|
libp2pProtocol("beacon_blocks_by_root", 1).} =
|
|
|
|
var outputStream = memoryOutput()
|
|
|
|
var writer = init(WriterType(SSZ), outputStream)
|
|
|
|
writeValue(writer, blockRoots)
|
|
|
|
let msgBytes = getOutput(outputStream)
|
|
|
|
makeEth2Request(peer, "/eth2/beacon_chain/req/beacon_blocks_by_root/1/",
|
|
|
|
msgBytes, seq[SignedBeaconBlock], timeout)
|
|
|
|
|
2020-06-20 07:24:33 +00:00
|
|
|
proc goodbye*(peer: Peer; reason: uint64): Future[void] {.gcsafe,
|
2020-05-23 22:24:47 +00:00
|
|
|
libp2pProtocol("goodbye", 1).} =
|
|
|
|
var outputStream = memoryOutput()
|
|
|
|
var writer = init(WriterType(SSZ), outputStream)
|
|
|
|
writeValue(writer, reason)
|
|
|
|
let msgBytes = getOutput(outputStream)
|
|
|
|
sendNotificationMsg(peer, "/eth2/beacon_chain/req/goodbye/1/", msgBytes)
|
|
|
|
|
|
|
|
proc statusUserHandler(peer: Peer; theirStatus: StatusMsg;
|
|
|
|
response: SingleChunkResponse[StatusMsg]) {.async,
|
|
|
|
libp2pProtocol("status", 1), gcsafe.} =
|
|
|
|
type
|
|
|
|
CurrentProtocol = BeaconSync
|
|
|
|
template state(peer: Peer): ref[BeaconSyncPeerState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncPeerState:ObjectType]](getState(peer, BeaconSyncProtocol))
|
|
|
|
|
|
|
|
template networkState(peer: Peer): ref[BeaconSyncNetworkState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
|
|
|
BeaconSyncProtocol))
|
|
|
|
|
|
|
|
let ourStatus = peer.networkState.getCurrentStatus()
|
|
|
|
trace "Sending status message", peer = peer, status = ourStatus
|
|
|
|
await response.send(ourStatus)
|
|
|
|
await peer.handleStatus(peer.networkState, ourStatus, theirStatus)
|
|
|
|
|
|
|
|
proc pingUserHandler(peer: Peer; value: uint64): uint64 {.libp2pProtocol("ping", 1),
|
|
|
|
gcsafe.} =
|
|
|
|
type
|
|
|
|
CurrentProtocol = BeaconSync
|
|
|
|
template state(peer: Peer): ref[BeaconSyncPeerState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncPeerState:ObjectType]](getState(peer, BeaconSyncProtocol))
|
|
|
|
|
|
|
|
template networkState(peer: Peer): ref[BeaconSyncNetworkState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
|
|
|
BeaconSyncProtocol))
|
|
|
|
|
|
|
|
return peer.network.metadata.seq_number
|
|
|
|
|
|
|
|
proc getMetadataUserHandler(peer: Peer): Eth2Metadata {.
|
|
|
|
libp2pProtocol("metadata", 1), gcsafe.} =
|
|
|
|
type
|
|
|
|
CurrentProtocol = BeaconSync
|
|
|
|
template state(peer: Peer): ref[BeaconSyncPeerState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncPeerState:ObjectType]](getState(peer, BeaconSyncProtocol))
|
|
|
|
|
|
|
|
template networkState(peer: Peer): ref[BeaconSyncNetworkState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
|
|
|
BeaconSyncProtocol))
|
|
|
|
|
|
|
|
return peer.network.metadata
|
|
|
|
|
2020-08-05 23:22:12 +00:00
|
|
|
proc beaconBlocksByRangeUserHandler(peer: Peer; startSlot: Slot; reqCount: uint64;
|
|
|
|
reqStep: uint64; response: MultipleChunksResponse[
|
2020-05-23 22:24:47 +00:00
|
|
|
SignedBeaconBlock]) {.async, libp2pProtocol("beacon_blocks_by_range", 1), gcsafe.} =
|
|
|
|
type
|
|
|
|
CurrentProtocol = BeaconSync
|
|
|
|
template state(peer: Peer): ref[BeaconSyncPeerState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncPeerState:ObjectType]](getState(peer, BeaconSyncProtocol))
|
|
|
|
|
|
|
|
template networkState(peer: Peer): ref[BeaconSyncNetworkState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
|
|
|
BeaconSyncProtocol))
|
|
|
|
|
2020-08-05 23:22:12 +00:00
|
|
|
trace "got range request", peer, startSlot, count = reqCount, step = reqStep
|
|
|
|
if reqCount > 0'u64:
|
|
|
|
var blocks: array[MAX_REQUEST_BLOCKS, BlockRef]
|
2020-05-23 22:24:47 +00:00
|
|
|
let
|
2020-07-30 19:18:17 +00:00
|
|
|
chainDag = peer.networkState.chainDag
|
2020-08-05 23:22:12 +00:00
|
|
|
count = int min(reqCount, blocks.lenu64)
|
2020-05-23 22:24:47 +00:00
|
|
|
let
|
|
|
|
endIndex = count - 1
|
2020-08-05 23:22:12 +00:00
|
|
|
startIndex = chainDag.getBlockRange(startSlot, reqStep,
|
2020-07-30 19:18:17 +00:00
|
|
|
blocks.toOpenArray(0, endIndex))
|
2020-05-23 22:24:47 +00:00
|
|
|
for b in blocks[startIndex .. endIndex]:
|
|
|
|
doAssert not b.isNil, "getBlockRange should return non-nil blocks only"
|
|
|
|
trace "wrote response block", slot = b.slot, roor = shortLog(b.root)
|
2020-07-30 19:18:17 +00:00
|
|
|
await response.write(chainDag.get(b).data)
|
2020-08-05 23:22:12 +00:00
|
|
|
debug "Block range request done", peer, startSlot, count, reqStep,
|
2020-05-23 22:24:47 +00:00
|
|
|
found = count - startIndex
|
|
|
|
|
|
|
|
proc beaconBlocksByRootUserHandler(peer: Peer; blockRoots: BlockRootsList; response: MultipleChunksResponse[
|
|
|
|
SignedBeaconBlock]) {.async, libp2pProtocol("beacon_blocks_by_root", 1), gcsafe.} =
|
|
|
|
type
|
|
|
|
CurrentProtocol = BeaconSync
|
|
|
|
template state(peer: Peer): ref[BeaconSyncPeerState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncPeerState:ObjectType]](getState(peer, BeaconSyncProtocol))
|
|
|
|
|
|
|
|
template networkState(peer: Peer): ref[BeaconSyncNetworkState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
|
|
|
BeaconSyncProtocol))
|
|
|
|
|
|
|
|
let
|
2020-07-30 19:18:17 +00:00
|
|
|
chainDag = peer.networkState.chainDag
|
2020-05-23 22:24:47 +00:00
|
|
|
count = blockRoots.len
|
|
|
|
var found = 0
|
|
|
|
for root in blockRoots[0 ..< count]:
|
2020-07-30 19:18:17 +00:00
|
|
|
let blockRef = chainDag.getRef(root)
|
2020-05-23 22:24:47 +00:00
|
|
|
if not isNil(blockRef):
|
2020-07-30 19:18:17 +00:00
|
|
|
await response.write(chainDag.get(blockRef).data)
|
2020-05-23 22:24:47 +00:00
|
|
|
inc found
|
|
|
|
debug "Block root request done", peer, roots = blockRoots.len, count, found
|
|
|
|
|
2020-06-20 07:24:33 +00:00
|
|
|
proc goodbyeUserHandler(peer: Peer; reason: uint64) {.async,
|
2020-05-26 17:07:18 +00:00
|
|
|
libp2pProtocol("goodbye", 1), gcsafe.} =
|
|
|
|
type
|
|
|
|
CurrentProtocol = BeaconSync
|
|
|
|
template state(peer: Peer): ref[BeaconSyncPeerState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncPeerState:ObjectType]](getState(peer, BeaconSyncProtocol))
|
|
|
|
|
|
|
|
template networkState(peer: Peer): ref[BeaconSyncNetworkState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
|
|
|
BeaconSyncProtocol))
|
|
|
|
|
2020-06-20 07:24:33 +00:00
|
|
|
debug "Received Goodbye message", reason = disconnectReasonName(reason), peer
|
2020-05-26 17:07:18 +00:00
|
|
|
|
2020-05-23 22:24:47 +00:00
|
|
|
template callUserHandler(MSG: type statusObj; peer: Peer; stream: Connection;
|
2020-08-10 13:18:17 +00:00
|
|
|
msg: StatusMsg): untyped =
|
|
|
|
var response = init(SingleChunkResponse[StatusMsg], peer, stream)
|
2020-05-23 22:24:47 +00:00
|
|
|
statusUserHandler(peer, msg, response)
|
|
|
|
|
2020-05-26 17:07:18 +00:00
|
|
|
proc statusMounter(network: Eth2Node) =
|
2020-05-23 22:24:47 +00:00
|
|
|
proc snappyThunk(stream: Connection; protocol: string): Future[void] {.gcsafe.} =
|
2020-08-10 13:18:17 +00:00
|
|
|
return handleIncomingStream(network, stream, statusObj)
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
mount network.switch, LPProtocol(codec: "/eth2/beacon_chain/req/status/1/" &
|
|
|
|
"ssz_snappy", handler: snappyThunk)
|
|
|
|
|
2020-08-10 13:18:17 +00:00
|
|
|
template callUserHandler(MSG: type pingObj; peer: Peer; stream: Connection; msg: uint64): untyped =
|
|
|
|
sendUserHandlerResultAsChunkImpl(stream, pingUserHandler(peer, msg))
|
2020-05-23 22:24:47 +00:00
|
|
|
|
2020-05-26 17:07:18 +00:00
|
|
|
proc pingMounter(network: Eth2Node) =
|
2020-05-23 22:24:47 +00:00
|
|
|
proc snappyThunk(stream: Connection; protocol: string): Future[void] {.gcsafe.} =
|
2020-08-10 13:18:17 +00:00
|
|
|
return handleIncomingStream(network, stream, pingObj)
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
mount network.switch, LPProtocol(codec: "/eth2/beacon_chain/req/ping/1/" &
|
|
|
|
"ssz_snappy", handler: snappyThunk)
|
|
|
|
|
|
|
|
template callUserHandler(MSG: type getMetadataObj; peer: Peer; stream: Connection;
|
2020-08-10 13:18:17 +00:00
|
|
|
msg: getMetadataObj): untyped =
|
|
|
|
sendUserHandlerResultAsChunkImpl(stream, getMetadataUserHandler(peer))
|
2020-05-23 22:24:47 +00:00
|
|
|
|
2020-05-26 17:07:18 +00:00
|
|
|
proc getMetadataMounter(network: Eth2Node) =
|
2020-05-23 22:24:47 +00:00
|
|
|
proc snappyThunk(stream: Connection; protocol: string): Future[void] {.gcsafe.} =
|
2020-08-10 13:18:17 +00:00
|
|
|
return handleIncomingStream(network, stream, getMetadataObj)
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
mount network.switch, LPProtocol(codec: "/eth2/beacon_chain/req/metadata/1/" &
|
|
|
|
"ssz_snappy", handler: snappyThunk)
|
|
|
|
|
|
|
|
template callUserHandler(MSG: type beaconBlocksByRangeObj; peer: Peer;
|
2020-08-10 13:18:17 +00:00
|
|
|
stream: Connection; msg: beaconBlocksByRangeObj): untyped =
|
|
|
|
var response = init(MultipleChunksResponse[SignedBeaconBlock], peer, stream)
|
2020-08-05 23:22:12 +00:00
|
|
|
beaconBlocksByRangeUserHandler(peer, msg.startSlot, msg.reqCount, msg.reqStep,
|
|
|
|
response)
|
2020-05-23 22:24:47 +00:00
|
|
|
|
2020-05-26 17:07:18 +00:00
|
|
|
proc beaconBlocksByRangeMounter(network: Eth2Node) =
|
2020-05-23 22:24:47 +00:00
|
|
|
proc snappyThunk(stream: Connection; protocol: string): Future[void] {.gcsafe.} =
|
2020-08-10 13:18:17 +00:00
|
|
|
return handleIncomingStream(network, stream, beaconBlocksByRangeObj)
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
mount network.switch, LPProtocol(codec: "/eth2/beacon_chain/req/beacon_blocks_by_range/1/" &
|
|
|
|
"ssz_snappy", handler: snappyThunk)
|
|
|
|
|
|
|
|
template callUserHandler(MSG: type beaconBlocksByRootObj; peer: Peer;
|
2020-08-10 13:18:17 +00:00
|
|
|
stream: Connection; msg: BlockRootsList): untyped =
|
|
|
|
var response = init(MultipleChunksResponse[SignedBeaconBlock], peer, stream)
|
2020-05-23 22:24:47 +00:00
|
|
|
beaconBlocksByRootUserHandler(peer, msg, response)
|
|
|
|
|
2020-05-26 17:07:18 +00:00
|
|
|
proc beaconBlocksByRootMounter(network: Eth2Node) =
|
2020-05-23 22:24:47 +00:00
|
|
|
proc snappyThunk(stream: Connection; protocol: string): Future[void] {.gcsafe.} =
|
2020-08-10 13:18:17 +00:00
|
|
|
return handleIncomingStream(network, stream, beaconBlocksByRootObj)
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
mount network.switch, LPProtocol(codec: "/eth2/beacon_chain/req/beacon_blocks_by_root/1/" &
|
|
|
|
"ssz_snappy", handler: snappyThunk)
|
|
|
|
|
2020-05-26 17:07:18 +00:00
|
|
|
template callUserHandler(MSG: type goodbyeObj; peer: Peer; stream: Connection;
|
2020-08-10 13:18:17 +00:00
|
|
|
msg: uint64): untyped =
|
2020-05-26 17:07:18 +00:00
|
|
|
goodbyeUserHandler(peer, msg)
|
|
|
|
|
|
|
|
proc goodbyeMounter(network: Eth2Node) =
|
|
|
|
proc snappyThunk(stream: Connection; protocol: string): Future[void] {.gcsafe.} =
|
2020-08-10 13:18:17 +00:00
|
|
|
return handleIncomingStream(network, stream, goodbyeObj)
|
2020-05-26 17:07:18 +00:00
|
|
|
|
|
|
|
mount network.switch, LPProtocol(codec: "/eth2/beacon_chain/req/goodbye/1/" &
|
|
|
|
"ssz_snappy", handler: snappyThunk)
|
|
|
|
|
|
|
|
registerMsg(BeaconSyncProtocol, "status", statusMounter,
|
2020-05-23 22:24:47 +00:00
|
|
|
"/eth2/beacon_chain/req/status/1/")
|
2020-05-26 17:07:18 +00:00
|
|
|
registerMsg(BeaconSyncProtocol, "ping", pingMounter,
|
2020-05-23 22:24:47 +00:00
|
|
|
"/eth2/beacon_chain/req/ping/1/")
|
2020-05-26 17:07:18 +00:00
|
|
|
registerMsg(BeaconSyncProtocol, "getMetadata", getMetadataMounter,
|
2020-05-23 22:24:47 +00:00
|
|
|
"/eth2/beacon_chain/req/metadata/1/")
|
2020-05-26 17:07:18 +00:00
|
|
|
registerMsg(BeaconSyncProtocol, "beaconBlocksByRange", beaconBlocksByRangeMounter,
|
2020-05-23 22:24:47 +00:00
|
|
|
"/eth2/beacon_chain/req/beacon_blocks_by_range/1/")
|
2020-05-26 17:07:18 +00:00
|
|
|
registerMsg(BeaconSyncProtocol, "beaconBlocksByRoot", beaconBlocksByRootMounter,
|
2020-05-23 22:24:47 +00:00
|
|
|
"/eth2/beacon_chain/req/beacon_blocks_by_root/1/")
|
2020-05-26 17:07:18 +00:00
|
|
|
registerMsg(BeaconSyncProtocol, "goodbye", goodbyeMounter,
|
|
|
|
"/eth2/beacon_chain/req/goodbye/1/")
|
2020-08-10 10:58:34 +00:00
|
|
|
proc BeaconSyncPeerConnected(peer: Peer; incoming: bool) {.async, gcsafe.} =
|
2020-05-23 22:24:47 +00:00
|
|
|
type
|
|
|
|
CurrentProtocol = BeaconSync
|
|
|
|
template state(peer: Peer): ref[BeaconSyncPeerState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncPeerState:ObjectType]](getState(peer, BeaconSyncProtocol))
|
|
|
|
|
|
|
|
template networkState(peer: Peer): ref[BeaconSyncNetworkState:ObjectType] =
|
|
|
|
cast[ref[BeaconSyncNetworkState:ObjectType]](getNetworkState(peer.network,
|
|
|
|
BeaconSyncProtocol))
|
|
|
|
|
2020-08-10 10:58:34 +00:00
|
|
|
debug "Peer connected", peer, peerInfo = shortLog(peer.info), incoming
|
|
|
|
let
|
|
|
|
ourStatus = peer.networkState.getCurrentStatus()
|
|
|
|
theirStatus = await peer.status(ourStatus, timeout = 60.seconds)
|
|
|
|
if theirStatus.isOk:
|
|
|
|
await peer.handleStatus(peer.networkState, ourStatus, theirStatus.get())
|
|
|
|
else:
|
|
|
|
warn "Status response not received in time", peer, error = theirStatus.error
|
2020-05-23 22:24:47 +00:00
|
|
|
|
|
|
|
setEventHandlers(BeaconSyncProtocol, BeaconSyncPeerConnected, nil)
|
|
|
|
registerProtocol(BeaconSyncProtocol)
|