Skip to content

Commit

Permalink
impl Resource Unavailable RPC error (#2072)
Browse files Browse the repository at this point in the history
## Issue Addressed

Related to #1891, The error is not in the spec yet (see ethereum/consensus-specs#2131)

## Proposed Changes

Implement the proposed error, banning peers that send it

## Additional Info

NA
  • Loading branch information
divagant-martian committed Dec 13, 2020
1 parent c1e27f4 commit 906d5d1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions beacon_node/eth2_libp2p/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
}
RPCError::ErrorResponse(code, _) => match code {
RPCResponseErrorCode::Unknown => PeerAction::HighToleranceError,
RPCResponseErrorCode::ResourceUnavailable => {
// NOTE: This error only makes sense for the `BlocksByRange` and `BlocksByRoot`
// protocols. For the time being, there is no reason why a peer should send
// this error.
PeerAction::Fatal
}
RPCResponseErrorCode::ServerError => PeerAction::MidToleranceError,
RPCResponseErrorCode::InvalidRequest => PeerAction::LowToleranceError,
RPCResponseErrorCode::RateLimited => match protocol {
Expand Down
5 changes: 5 additions & 0 deletions beacon_node/eth2_libp2p/src/rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ pub enum RPCResponseErrorCode {
RateLimited,
InvalidRequest,
ServerError,
/// Error spec'd to indicate that a peer does not have blocks on a requested range.
ResourceUnavailable,
Unknown,
}

Expand All @@ -285,6 +287,7 @@ impl<T: EthSpec> RPCCodedResponse<T> {
let code = match response_code {
1 => RPCResponseErrorCode::InvalidRequest,
2 => RPCResponseErrorCode::ServerError,
3 => RPCResponseErrorCode::ResourceUnavailable,
139 => RPCResponseErrorCode::RateLimited,
_ => RPCResponseErrorCode::Unknown,
};
Expand Down Expand Up @@ -318,6 +321,7 @@ impl RPCResponseErrorCode {
match self {
RPCResponseErrorCode::InvalidRequest => 1,
RPCResponseErrorCode::ServerError => 2,
RPCResponseErrorCode::ResourceUnavailable => 3,
RPCResponseErrorCode::Unknown => 255,
RPCResponseErrorCode::RateLimited => 139,
}
Expand All @@ -328,6 +332,7 @@ impl std::fmt::Display for RPCResponseErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let repr = match self {
RPCResponseErrorCode::InvalidRequest => "The request was invalid",
RPCResponseErrorCode::ResourceUnavailable => "Resource unavailable",
RPCResponseErrorCode::ServerError => "Server error occurred",
RPCResponseErrorCode::Unknown => "Unknown error occurred",
RPCResponseErrorCode::RateLimited => "Rate limited",
Expand Down
1 change: 1 addition & 0 deletions beacon_node/eth2_libp2p/src/rpc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ impl RPCError {
RPCResponseErrorCode::RateLimited => "rate_limited",
RPCResponseErrorCode::InvalidRequest => "invalid_request",
RPCResponseErrorCode::ServerError => "server_error",
RPCResponseErrorCode::ResourceUnavailable => "resource_unavailable",
RPCResponseErrorCode::Unknown => "unknown_response_code",
},
RPCError::StreamTimeout => "stream_timeout",
Expand Down

0 comments on commit 906d5d1

Please sign in to comment.