diff --git a/chain/src/txhashset/desegmenter.rs b/chain/src/txhashset/desegmenter.rs index 0de446bc1..66f6df6b2 100644 --- a/chain/src/txhashset/desegmenter.rs +++ b/chain/src/txhashset/desegmenter.rs @@ -68,6 +68,8 @@ pub struct Desegmenter { /// Flag indicating there are no more segments to request all_segments_complete: bool, + + latest_block_height: u64, } impl Desegmenter { @@ -104,6 +106,8 @@ impl Desegmenter { bitmap_cache: None, all_segments_complete: false, + + latest_block_height: 0, }; retval.calc_bitmap_mmr_sizes(); retval @@ -120,6 +124,7 @@ impl Desegmenter { self.bitmap_mmr_size = 0; self.bitmap_cache = None; self.bitmap_accumulator = BitmapAccumulator::new(); + self.latest_block_height = 0; self.calc_bitmap_mmr_sizes(); } @@ -140,9 +145,7 @@ impl Desegmenter { /// Check progress, update status if needed, returns true if all required /// segments are in place - pub fn check_progress(&self, status: Arc) -> Result { - let mut latest_block_height = 0; - + pub fn check_progress(&mut self, status: Arc) -> Result { let local_output_mmr_size; let local_kernel_mmr_size; let local_rangeproof_mmr_size; @@ -174,13 +177,13 @@ impl Desegmenter { header_pmmr.get_first_header_with( latest_output_size, local_kernel_mmr_size, - latest_block_height, + self.latest_block_height, self.store.clone(), ) }; if let Some(h) = res { - latest_block_height = h.height; + self.latest_block_height = h.height; // TODO: Unwraps let tip = Tip::from_header(&h); @@ -192,7 +195,7 @@ impl Desegmenter { false, false, completed_leaves, - latest_block_height, + self.latest_block_height, &self.archive_header, ); if local_kernel_mmr_size == self.archive_header.kernel_mmr_size diff --git a/servers/src/grin/sync/state_sync.rs b/servers/src/grin/sync/state_sync.rs index 7220f87b8..9c135538d 100644 --- a/servers/src/grin/sync/state_sync.rs +++ b/servers/src/grin/sync/state_sync.rs @@ -171,7 +171,7 @@ impl StateSync { if self.continue_pibd() { let desegmenter = self.chain.desegmenter(&archive_header).unwrap(); // All segments in, validate - if let Some(d) = desegmenter.read().as_ref() { + if let Some(d) = desegmenter.write().as_mut() { if let Ok(true) = d.check_progress(self.sync_state.clone()) { if let Err(e) = d.check_update_leaf_set_state() { error!("error updating PIBD leaf set: {}", e);