diff --git a/servers/src/grin/sync/state_sync.rs b/servers/src/grin/sync/state_sync.rs index 9c135538d..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 { @@ -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 {