mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 14:26:26 +00:00
add support for ResourceUnavailable
p2p error (#3476)
The `p2p-interface.md` spec defines a `ResourceUnavailable` error to return in situations where data that exists on the network is locally unavailable, e.g., when a block within `MIN_EPOCHS_FOR_BLOCK_REQUESTS` is requested by `BeaconBlocksByRange` but cannot be provided. This patch adds support for that additional error code.
This commit is contained in:
parent
266fd98a13
commit
64242d9c84
@ -158,6 +158,7 @@ type
|
|||||||
Success
|
Success
|
||||||
InvalidRequest
|
InvalidRequest
|
||||||
ServerError
|
ServerError
|
||||||
|
ResourceUnavailable
|
||||||
|
|
||||||
PeerStateInitializer* = proc(peer: Peer): RootRef {.gcsafe, raises: [Defect].}
|
PeerStateInitializer* = proc(peer: Peer): RootRef {.gcsafe, raises: [Defect].}
|
||||||
NetworkStateInitializer* = proc(network: EthereumNode): RootRef {.gcsafe, raises: [Defect].}
|
NetworkStateInitializer* = proc(network: EthereumNode): RootRef {.gcsafe, raises: [Defect].}
|
||||||
@ -206,6 +207,8 @@ type
|
|||||||
|
|
||||||
InvalidInputsError* = object of CatchableError
|
InvalidInputsError* = object of CatchableError
|
||||||
|
|
||||||
|
ResourceUnavailableError* = object of CatchableError
|
||||||
|
|
||||||
NetRes*[T] = Result[T, Eth2NetworkingError]
|
NetRes*[T] = Result[T, Eth2NetworkingError]
|
||||||
## This is type returned from all network requests
|
## This is type returned from all network requests
|
||||||
|
|
||||||
@ -720,6 +723,13 @@ proc handleIncomingStream(network: Eth2Node,
|
|||||||
template returnInvalidRequest(msg: string) =
|
template returnInvalidRequest(msg: string) =
|
||||||
returnInvalidRequest(ErrorMsg msg.toBytes)
|
returnInvalidRequest(ErrorMsg msg.toBytes)
|
||||||
|
|
||||||
|
template returnResourceUnavailable(msg: ErrorMsg) =
|
||||||
|
await sendErrorResponse(peer, conn, ResourceUnavailable, msg)
|
||||||
|
return
|
||||||
|
|
||||||
|
template returnResourceUnavailable(msg: string) =
|
||||||
|
returnResourceUnavailable(ErrorMsg msg.toBytes)
|
||||||
|
|
||||||
let s = when useNativeSnappy:
|
let s = when useNativeSnappy:
|
||||||
let fs = libp2pInput(conn)
|
let fs = libp2pInput(conn)
|
||||||
|
|
||||||
@ -794,8 +804,8 @@ proc handleIncomingStream(network: Eth2Node,
|
|||||||
await callUserHandler(MsgType, peer, conn, msg.get)
|
await callUserHandler(MsgType, peer, conn, msg.get)
|
||||||
except InvalidInputsError as err:
|
except InvalidInputsError as err:
|
||||||
returnInvalidRequest err.msg
|
returnInvalidRequest err.msg
|
||||||
await sendErrorResponse(peer, conn, ServerError,
|
except ResourceUnavailableError as err:
|
||||||
ErrorMsg err.msg.toBytes)
|
returnResourceUnavailable err.msg
|
||||||
except CatchableError as err:
|
except CatchableError as err:
|
||||||
await sendErrorResponse(peer, conn, ServerError,
|
await sendErrorResponse(peer, conn, ServerError,
|
||||||
ErrorMsg err.msg.toBytes)
|
ErrorMsg err.msg.toBytes)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
@ -112,7 +112,7 @@ proc readResponseChunk(s: AsyncInputStream,
|
|||||||
|
|
||||||
let responseCode = ResponseCode responseCodeByte
|
let responseCode = ResponseCode responseCodeByte
|
||||||
case responseCode:
|
case responseCode:
|
||||||
of InvalidRequest, ServerError:
|
of InvalidRequest, ServerError, ResourceUnavailable:
|
||||||
let errorMsgChunk = await readChunkPayload(s, noSnappy, string)
|
let errorMsgChunk = await readChunkPayload(s, noSnappy, string)
|
||||||
let errorMsg = if errorMsgChunk.isOk: errorMsgChunk.value
|
let errorMsg = if errorMsgChunk.isOk: errorMsgChunk.value
|
||||||
else: return err(errorMsgChunk.error)
|
else: return err(errorMsgChunk.error)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
@ -148,7 +148,7 @@ proc readResponseChunk(conn: Connection, peer: Peer,
|
|||||||
|
|
||||||
let responseCode = ResponseCode responseCodeByte
|
let responseCode = ResponseCode responseCodeByte
|
||||||
case responseCode:
|
case responseCode:
|
||||||
of InvalidRequest, ServerError:
|
of InvalidRequest, ServerError, ResourceUnavailable:
|
||||||
let
|
let
|
||||||
errorMsgChunk = await readChunkPayload(conn, peer, ErrorMsg)
|
errorMsgChunk = await readChunkPayload(conn, peer, ErrorMsg)
|
||||||
errorMsg = if errorMsgChunk.isOk: errorMsgChunk.value
|
errorMsg = if errorMsgChunk.isOk: errorMsgChunk.value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user