@@ -23,7 +23,11 @@ use cuprate_consensus::{
2323use cuprate_consensus_context:: { BlockchainContext , NewBlockData } ;
2424use cuprate_fast_sync:: { block_to_verified_block_information, fast_sync_stop_height} ;
2525use cuprate_helper:: cast:: usize_to_u64;
26- use cuprate_p2p:: { block_downloader:: BlockBatch , constants:: LONG_BAN , BroadcastRequest } ;
26+ use cuprate_p2p:: {
27+ block_downloader:: BlockBatch ,
28+ constants:: { LONG_BAN , MEDIUM_BAN } ,
29+ BroadcastRequest ,
30+ } ;
2731use cuprate_txpool:: service:: interface:: TxpoolWriteRequest ;
2832use cuprate_types:: {
2933 blockchain:: { BlockchainReadRequest , BlockchainResponse , BlockchainWriteRequest } ,
@@ -246,15 +250,20 @@ impl super::BlockchainManager {
246250 {
247251 Ok ( v) => v,
248252 Err ( BlockManagerError :: Internal ( e) ) => return Err ( e) ,
249- Err ( BlockManagerError :: Validation ( _) ) => {
250- batch. peer_handle . ban_peer ( LONG_BAN ) ;
253+ Err ( BlockManagerError :: Validation ( e) ) => {
254+ let duration = match e {
255+ BlockValidationError :: HardFork ( _) => MEDIUM_BAN ,
256+ BlockValidationError :: Other ( _) => LONG_BAN ,
257+ } ;
258+ batch. peer_handle . ban_peer ( duration) ;
251259 self . stop_current_block_downloader . notify_waiters ( ) ;
252260 return Ok ( ( ) ) ;
253261 }
254262 } ;
255263
256264 for ( block, txs) in prepped_blocks {
257265 let hash = block. block_hash ;
266+ let block_version = block. hf_version . as_u8 ( ) ;
258267 let verified_block = match verify_prepped_main_chain_block (
259268 block,
260269 txs,
@@ -268,12 +277,27 @@ impl super::BlockchainManager {
268277 Ok ( block) => block,
269278 Err ( BlockManagerError :: Internal ( e) ) => return Err ( e) ,
270279 Err ( BlockManagerError :: Validation ( e) ) => {
271- warn ! (
272- "Failed to verify block: {}, error {}, banning peer." ,
273- hex:: encode( hash) ,
274- e
275- ) ;
276- batch. peer_handle . ban_peer ( LONG_BAN ) ;
280+ let duration = match e {
281+ BlockValidationError :: HardFork ( e) => {
282+ warn ! (
283+ "Failed to verify block: {}, error {} (block v{}, current v{}), banning peer." ,
284+ hex:: encode( hash) ,
285+ e,
286+ block_version,
287+ self . blockchain_context_service. blockchain_context( ) . current_hf. as_u8( )
288+ ) ;
289+ MEDIUM_BAN
290+ }
291+ BlockValidationError :: Other ( e) => {
292+ warn ! (
293+ "Failed to verify block: {}, error {}, banning peer." ,
294+ hex:: encode( hash) ,
295+ e
296+ ) ;
297+ LONG_BAN
298+ }
299+ } ;
300+ batch. peer_handle . ban_peer ( duration) ;
277301 self . stop_current_block_downloader . notify_waiters ( ) ;
278302 return Ok ( ( ) ) ;
279303 }
@@ -335,6 +359,7 @@ impl super::BlockchainManager {
335359
336360 while let Some ( ( block, txs) ) = blocks. next ( ) {
337361 let hash = block. hash ( ) ;
362+ let block_version = block. header . hardfork_version ;
338363
339364 // async blocks work as try blocks.
340365 let res = async {
@@ -355,12 +380,27 @@ impl super::BlockchainManager {
355380 match res {
356381 Err ( BlockManagerError :: Internal ( e) ) => return Err ( e) ,
357382 Err ( BlockManagerError :: Validation ( e) ) => {
358- warn ! (
359- "Failed to verify block: {}, error {}, banning peer." ,
360- hex:: encode( hash) ,
361- e
362- ) ;
363- batch. peer_handle . ban_peer ( LONG_BAN ) ;
383+ let duration = match e {
384+ BlockValidationError :: HardFork ( e) => {
385+ warn ! (
386+ "Failed to verify block: {}, error {} (block v{}, current v{}), banning peer." ,
387+ hex:: encode( hash) ,
388+ e,
389+ block_version,
390+ self . blockchain_context_service. blockchain_context( ) . current_hf. as_u8( )
391+ ) ;
392+ MEDIUM_BAN
393+ }
394+ BlockValidationError :: Other ( e) => {
395+ warn ! (
396+ "Failed to verify block: {}, error {}, banning peer." ,
397+ hex:: encode( hash) ,
398+ e
399+ ) ;
400+ LONG_BAN
401+ }
402+ } ;
403+ batch. peer_handle . ban_peer ( duration) ;
364404 self . stop_current_block_downloader . notify_waiters ( ) ;
365405 return Ok ( ( ) ) ;
366406 }
0 commit comments