@@ -1662,27 +1662,7 @@ impl Worker {
16621662 }
16631663 }
16641664
1665- let mut last_term_end = None ;
1666- for block_hash in & enacted {
1667- let header = c. block_header ( & BlockId :: Hash ( * block_hash) ) . expect ( "Block is enacted" ) . decode ( ) ;
1668- let parent_header = match c. block_header ( & BlockId :: Hash ( * header. parent_hash ( ) ) ) {
1669- Some ( h) => h. decode ( ) ,
1670- // NOTE: Only the genesis block and the snapshot target don't have the parent in the blockchain
1671- None => continue ,
1672- } ;
1673- let term_seconds = if let Some ( p) = c. term_common_params ( parent_header. hash ( ) . into ( ) ) {
1674- p. term_seconds ( )
1675- } else {
1676- continue
1677- } ;
1678- if super :: engine:: is_term_changed ( & header, & parent_header, term_seconds) {
1679- last_term_end = Some ( * block_hash) ;
1680- }
1681- }
1682- if let Some ( last_term_end) = last_term_end {
1683- // TODO: Reduce the snapshot frequency.
1684- self . snapshot_notify_sender . notify ( last_term_end) ;
1685- }
1665+ self . send_snapshot_notify ( c. as_ref ( ) , enacted. as_slice ( ) ) ;
16861666
16871667 if let Some ( ( last, rest) ) = imported. split_last ( ) {
16881668 let ( imported, last_proposal_header) = {
@@ -1718,6 +1698,31 @@ impl Worker {
17181698 }
17191699 }
17201700
1701+ // Notify once for the latest block even if multiple blocks have been enacted.
1702+ fn send_snapshot_notify ( & mut self , c : & dyn ConsensusClient , enacted : & [ BlockHash ] ) {
1703+ let mut last_term_end = None ;
1704+ for block_hash in enacted {
1705+ let header = c. block_header ( & BlockId :: Hash ( * block_hash) ) . expect ( "Block is enacted" ) . decode ( ) ;
1706+ let parent_header = match c. block_header ( & BlockId :: Hash ( * header. parent_hash ( ) ) ) {
1707+ Some ( h) => h. decode ( ) ,
1708+ // NOTE: Only the genesis block and the snapshot target don't have the parent in the blockchain
1709+ None => continue ,
1710+ } ;
1711+ let term_seconds = if let Some ( p) = c. term_common_params ( parent_header. hash ( ) . into ( ) ) {
1712+ p. term_seconds ( )
1713+ } else {
1714+ continue
1715+ } ;
1716+ if super :: engine:: is_term_changed ( & header, & parent_header, term_seconds) {
1717+ last_term_end = Some ( * block_hash) ;
1718+ }
1719+ }
1720+ if let Some ( last_term_end) = last_term_end {
1721+ // TODO: Reduce the snapshot frequency.
1722+ self . snapshot_notify_sender . notify ( last_term_end) ;
1723+ }
1724+ }
1725+
17211726 fn send_proposal_block (
17221727 & self ,
17231728 signature : SchnorrSignature ,
0 commit comments