From b698bc193be8fe0440f4ba4c6fa2fa22657f9415 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Fri, 16 Jun 2023 13:36:59 +0100 Subject: [PATCH 1/2] revert earlier pibd_aborted flag in sync logic --- chain/src/txhashset/desegmenter.rs | 14 ++++++++------ servers/src/grin/sync/state_sync.rs | 13 +++++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/chain/src/txhashset/desegmenter.rs b/chain/src/txhashset/desegmenter.rs index 0de446bc1..74632c65f 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,7 @@ impl Desegmenter { bitmap_cache: None, all_segments_complete: false, + latest_block_height: 0, }; retval.calc_bitmap_mmr_sizes(); retval @@ -120,6 +123,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 +144,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 +176,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 +194,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..60f733550 100644 --- a/servers/src/grin/sync/state_sync.rs +++ b/servers/src/grin/sync/state_sync.rs @@ -37,6 +37,7 @@ pub struct StateSync { prev_state_sync: Option>, state_sync_peer: Option>, + pibd_aborted: bool, earliest_zero_pibd_peer_time: Option>, } @@ -52,6 +53,7 @@ impl StateSync { chain, prev_state_sync: None, state_sync_peer: None, + pibd_aborted: false, earliest_zero_pibd_peer_time: None, } } @@ -62,6 +64,12 @@ impl StateSync { self.earliest_zero_pibd_peer_time = t; } + /// Flag to abort PIBD process within StateSync, intentionally separate from `sync_state`, + /// which can be reset between calls + pub fn set_pibd_aborted(&mut self) { + self.pibd_aborted = true; + } + /// Check whether state sync should run and triggers a state download when /// it's time (we have all headers). Returns true as long as state sync /// needs monitoring, false when it's either done or turned off. @@ -90,7 +98,7 @@ impl StateSync { let using_pibd = !matches!( self.sync_state.status(), SyncStatus::TxHashsetPibd { aborted: true, .. }, - ); + ) && !self.pibd_aborted; // Check whether we've errored and should restart pibd if using_pibd { @@ -171,7 +179,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); @@ -315,6 +323,7 @@ impl StateSync { .update_pibd_progress(true, true, 0, 1, &archive_header); self.sync_state .set_sync_error(chain::Error::AbortingPIBDError); + self.set_pibd_aborted(); return false; } } else { From 2c5f642788fe14c6b6178bee33e13764371f8b8c Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Tue, 20 Jun 2023 12:19:31 +0100 Subject: [PATCH 2/2] formatting --- chain/src/txhashset/desegmenter.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/chain/src/txhashset/desegmenter.rs b/chain/src/txhashset/desegmenter.rs index 74632c65f..66f6df6b2 100644 --- a/chain/src/txhashset/desegmenter.rs +++ b/chain/src/txhashset/desegmenter.rs @@ -106,6 +106,7 @@ impl Desegmenter { bitmap_cache: None, all_segments_complete: false, + latest_block_height: 0, }; retval.calc_bitmap_mmr_sizes();