|
156 | 156 | Success
|
157 | 157 | InvalidRequest
|
158 | 158 | ServerError
|
| 159 | + ResourceUnavailable |
159 | 160 |
|
160 | 161 | PeerStateInitializer* = proc(peer: Peer): RootRef {.gcsafe, raises: [Defect].}
|
161 | 162 | NetworkStateInitializer* = proc(network: EthereumNode): RootRef {.gcsafe, raises: [Defect].}
|
|
204 | 205 |
|
205 | 206 | InvalidInputsError* = object of CatchableError
|
206 | 207 |
|
| 208 | + ResourceUnavailableError* = object of CatchableError |
| 209 | + |
207 | 210 | NetRes*[T] = Result[T, Eth2NetworkingError]
|
208 | 211 | ## This is type returned from all network requests
|
209 | 212 |
|
@@ -707,6 +710,13 @@ proc handleIncomingStream(network: Eth2Node,
|
707 | 710 | template returnInvalidRequest(msg: string) =
|
708 | 711 | returnInvalidRequest(ErrorMsg msg.toBytes)
|
709 | 712 |
|
| 713 | + template returnResourceUnavailable(msg: ErrorMsg) = |
| 714 | + await sendErrorResponse(peer, conn, ResourceUnavailable, msg) |
| 715 | + return |
| 716 | + |
| 717 | + template returnResourceUnavailable(msg: string) = |
| 718 | + returnResourceUnavailable(ErrorMsg msg.toBytes) |
| 719 | + |
710 | 720 | let s = when useNativeSnappy:
|
711 | 721 | let fs = libp2pInput(conn)
|
712 | 722 |
|
@@ -771,8 +781,8 @@ proc handleIncomingStream(network: Eth2Node,
|
771 | 781 | await callUserHandler(MsgType, peer, conn, msg.get)
|
772 | 782 | except InvalidInputsError as err:
|
773 | 783 | returnInvalidRequest err.msg
|
774 |
| - await sendErrorResponse(peer, conn, ServerError, |
775 |
| - ErrorMsg err.msg.toBytes) |
| 784 | + except ResourceUnavailableError as err: |
| 785 | + returnResourceUnavailable err.msg |
776 | 786 | except CatchableError as err:
|
777 | 787 | await sendErrorResponse(peer, conn, ServerError,
|
778 | 788 | ErrorMsg err.msg.toBytes)
|
@@ -2225,3 +2235,17 @@ proc broadcastSignedContributionAndProof*(
|
2225 | 2235 | node: Eth2Node, msg: SignedContributionAndProof) =
|
2226 | 2236 | let topic = getSyncCommitteeContributionAndProofTopic(node.forkDigests.altair)
|
2227 | 2237 | node.broadcast(topic, msg)
|
| 2238 | + |
| 2239 | +proc broadcastOptimisticLightClientUpdate*( |
| 2240 | + node: Eth2Node, msg: OptimisticLightClientUpdate) = |
| 2241 | + let |
| 2242 | + forkDigest = |
| 2243 | + if msg.fork_version == node.cfg.SHARDING_FORK_VERSION: |
| 2244 | + node.forkDigests.sharding |
| 2245 | + elif msg.fork_version == node.cfg.BELLATRIX_FORK_VERSION: |
| 2246 | + node.forkDigests.bellatrix |
| 2247 | + else: |
| 2248 | + doAssert msg.fork_version == node.cfg.ALTAIR_FORK_VERSION |
| 2249 | + node.forkDigests.altair |
| 2250 | + topic = getOptimisticLightClientUpdateTopic(forkDigest) |
| 2251 | + node.broadcast(topic, msg) |
0 commit comments