diff --git a/substrate/client/network/src/behaviour.rs b/substrate/client/network/src/behaviour.rs index 5a5dd83803..656743ef7f 100644 --- a/substrate/client/network/src/behaviour.rs +++ b/substrate/client/network/src/behaviour.rs @@ -329,7 +329,7 @@ impl NetworkBehaviourEventProcess Protocol { } } + /// 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. @@ -1874,10 +1883,11 @@ pub enum CustomMessageOutcome { /// 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 }, /// A new finality proof request must be emitted. /// Once you have the response, you must call `Protocol::on_finality_proof_response`.