Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Restore the reputation penalty for timeouts (#5984)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored May 12, 2020
1 parent ba00ef1 commit 4e8e1b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<block_requests::Event<B
protocol: self.block_requests.protocol_name().to_vec(),
request_duration,
});
self.substrate.disconnect_peer(&peer);
self.substrate.on_block_request_failed(&peer);
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,15 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
}
}

/// Must be called in response to a [`CustomMessageOutcome::BlockRequest`] if it has failed.
pub fn on_block_request_failed(
&mut self,
peer: &PeerId,
) {
self.peerset_handle.report_peer(peer.clone(), rep::TIMEOUT);
self.behaviour.disconnect_peer(peer);
}

/// Perform time based maintenance.
///
/// > **Note**: This method normally doesn't have to be called except for testing purposes.
Expand Down Expand Up @@ -1874,10 +1883,11 @@ pub enum CustomMessageOutcome<B: BlockT> {
/// Messages have been received on one or more notifications protocols.
NotificationsReceived { remote: PeerId, messages: Vec<(ConsensusEngineId, Bytes)> },
/// A new block request must be emitted.
/// Once you have the response, you must call `Protocol::on_block_response`.
/// You must later call either [`Protocol::on_block_response`] or
/// [`Protocol::on_block_request_failed`].
/// Each peer can only have one active request. If a request already exists for this peer, it
/// must be silently discarded.
/// It is the responsibility of the handler to ensure that a timeout exists.
/// If the request times out, or the peer responds in an invalid way, the peer has to be
/// disconnect. This will inform the state machine that the request it has emitted is stale.
BlockRequest { target: PeerId, request: message::BlockRequest<B> },
/// A new finality proof request must be emitted.
/// Once you have the response, you must call `Protocol::on_finality_proof_response`.
Expand Down

0 comments on commit 4e8e1b7

Please sign in to comment.