@@ -279,7 +279,7 @@ impl<D> Peer<D> {
279279 where F : FnMut ( BlockBuilder < Block , PeersFullClient , substrate_test_runtime_client:: Backend > ) -> Block
280280 {
281281 let best_hash = self . client . info ( ) . best_hash ;
282- self . generate_blocks_at ( BlockId :: Hash ( best_hash) , count, origin, edit_block, false )
282+ self . generate_blocks_at ( BlockId :: Hash ( best_hash) , count, origin, edit_block, false , true )
283283 }
284284
285285 /// Add blocks to the peer -- edit the block before adding. The chain will
@@ -291,6 +291,7 @@ impl<D> Peer<D> {
291291 origin : BlockOrigin ,
292292 mut edit_block : F ,
293293 headers_only : bool ,
294+ inform_sync_about_new_best_block : bool ,
294295 ) -> H256 where F : FnMut ( BlockBuilder < Block , PeersFullClient , substrate_test_runtime_client:: Backend > ) -> Block {
295296 let full_client = self . client . as_full ( )
296297 . expect ( "blocks could only be generated by full clients" ) ;
@@ -328,7 +329,12 @@ impl<D> Peer<D> {
328329 at = hash;
329330 }
330331
331- self . network . update_chain ( ) ;
332+ if inform_sync_about_new_best_block {
333+ self . network . new_best_block_imported (
334+ at,
335+ full_client. header ( & BlockId :: Hash ( at) ) . ok ( ) . flatten ( ) . unwrap ( ) . number ( ) . clone ( ) ,
336+ ) ;
337+ }
332338 self . network . service ( ) . announce_block ( at. clone ( ) , Vec :: new ( ) ) ;
333339 at
334340 }
@@ -342,18 +348,36 @@ impl<D> Peer<D> {
342348 /// Push blocks to the peer (simplified: with or without a TX)
343349 pub fn push_headers ( & mut self , count : usize ) -> H256 {
344350 let best_hash = self . client . info ( ) . best_hash ;
345- self . generate_tx_blocks_at ( BlockId :: Hash ( best_hash) , count, false , true )
351+ self . generate_tx_blocks_at ( BlockId :: Hash ( best_hash) , count, false , true , true )
346352 }
347353
348354 /// Push blocks to the peer (simplified: with or without a TX) starting from
349355 /// given hash.
350356 pub fn push_blocks_at ( & mut self , at : BlockId < Block > , count : usize , with_tx : bool ) -> H256 {
351- self . generate_tx_blocks_at ( at, count, with_tx, false )
357+ self . generate_tx_blocks_at ( at, count, with_tx, false , true )
358+ }
359+
360+ /// Push blocks to the peer (simplified: with or without a TX) starting from
361+ /// given hash without informing the sync protocol about the new best block.
362+ pub fn push_blocks_at_without_informing_sync (
363+ & mut self ,
364+ at : BlockId < Block > ,
365+ count : usize ,
366+ with_tx : bool ,
367+ ) -> H256 {
368+ self . generate_tx_blocks_at ( at, count, with_tx, false , false )
352369 }
353370
354371 /// Push blocks/headers to the peer (simplified: with or without a TX) starting from
355372 /// given hash.
356- fn generate_tx_blocks_at ( & mut self , at : BlockId < Block > , count : usize , with_tx : bool , headers_only : bool ) -> H256 {
373+ fn generate_tx_blocks_at (
374+ & mut self ,
375+ at : BlockId < Block > ,
376+ count : usize ,
377+ with_tx : bool ,
378+ headers_only : bool ,
379+ inform_sync_about_new_best_block : bool ,
380+ ) -> H256 {
357381 let mut nonce = 0 ;
358382 if with_tx {
359383 self . generate_blocks_at (
@@ -370,7 +394,8 @@ impl<D> Peer<D> {
370394 nonce = nonce + 1 ;
371395 builder. build ( ) . unwrap ( ) . block
372396 } ,
373- headers_only
397+ headers_only,
398+ inform_sync_about_new_best_block,
374399 )
375400 } else {
376401 self . generate_blocks_at (
@@ -379,6 +404,7 @@ impl<D> Peer<D> {
379404 BlockOrigin :: File ,
380405 |builder| builder. build ( ) . unwrap ( ) . block ,
381406 headers_only,
407+ inform_sync_about_new_best_block,
382408 )
383409 }
384410 }
0 commit comments