@@ -46,7 +46,7 @@ mod rep {
46
46
use super :: ReputationChange as Rep ;
47
47
48
48
/// Reputation change when a peer sent us the same request multiple times.
49
- pub const SAME_REQUEST : Rep = Rep :: new ( i32 :: min_value ( ) , "Same block request multiple times" ) ;
49
+ pub const SAME_REQUEST : Rep = Rep :: new_fatal ( "Same block request multiple times" ) ;
50
50
}
51
51
52
52
/// Generates a [`ProtocolConfig`] for the block request protocol, refusing incoming requests.
@@ -65,11 +65,7 @@ pub fn generate_protocol_config(protocol_id: &ProtocolId) -> ProtocolConfig {
65
65
// Visibility `pub(crate)` to allow `crate::light_client_requests::sender` to generate block request
66
66
// protocol name and send block requests.
67
67
pub ( crate ) fn generate_protocol_name ( protocol_id : & ProtocolId ) -> String {
68
- let mut s = String :: new ( ) ;
69
- s. push_str ( "/" ) ;
70
- s. push_str ( protocol_id. as_ref ( ) ) ;
71
- s. push_str ( "/sync/2" ) ;
72
- s
68
+ format ! ( "/{}/sync/2" , protocol_id. as_ref( ) )
73
69
}
74
70
75
71
/// The key of [`BlockRequestHandler::seen_requests`].
@@ -192,15 +188,15 @@ impl<B: BlockT> BlockRequestHandler<B> {
192
188
support_multiple_justifications,
193
189
} ;
194
190
195
- let mut reputation_changes = Vec :: new ( ) ;
191
+ let mut reputation_change = None ;
196
192
197
193
match self . seen_requests . get_mut ( & key) {
198
194
Some ( SeenRequestsValue :: First ) => { } ,
199
195
Some ( SeenRequestsValue :: Fulfilled ( ref mut requests) ) => {
200
196
* requests = requests. saturating_add ( 1 ) ;
201
197
202
198
if * requests > MAX_NUMBER_OF_SAME_REQUESTS_PER_PEER {
203
- reputation_changes . push ( rep:: SAME_REQUEST ) ;
199
+ reputation_change = Some ( rep:: SAME_REQUEST ) ;
204
200
}
205
201
} ,
206
202
None => {
@@ -219,7 +215,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
219
215
attributes,
220
216
) ;
221
217
222
- let result = if reputation_changes . is_empty ( ) {
218
+ let result = if reputation_change . is_none ( ) {
223
219
let block_response = self . get_block_response (
224
220
attributes,
225
221
from_block_id,
@@ -228,7 +224,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
228
224
support_multiple_justifications,
229
225
) ?;
230
226
231
- // If any of the blocks contains nay data, we can consider it as successful request.
227
+ // If any of the blocks contains any data, we can consider it as successful request.
232
228
if block_response
233
229
. blocks
234
230
. iter ( )
@@ -253,7 +249,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
253
249
254
250
pending_response. send ( OutgoingResponse {
255
251
result,
256
- reputation_changes,
252
+ reputation_changes : reputation_change . into_iter ( ) . collect ( ) ,
257
253
sent_feedback : None ,
258
254
} ) . map_err ( |_| HandleRequestError :: SendResponse )
259
255
}
0 commit comments