Skip to content

Commit 6408ea9

Browse files
authored
Merge pull request #2472 from subspace/account-for-sync-pause
Account for DSN sync in `SubspaceSyncOracle`
2 parents b5a7e3c + 0d54b63 commit 6408ea9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

crates/sc-consensus-subspace/src/slot_worker.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use std::collections::BTreeMap;
6666
use std::future::Future;
6767
use std::marker::PhantomData;
6868
use std::pin::Pin;
69+
use std::sync::atomic::{AtomicBool, Ordering};
6970
use std::sync::Arc;
7071
use subspace_core_primitives::{
7172
BlockNumber, PotCheckpoints, PotOutput, PublicKey, Randomness, RewardSignature, SectorId,
@@ -82,13 +83,16 @@ const PENDING_SOLUTIONS_CHANNEL_CAPACITY: usize = 10;
8283

8384
/// Subspace sync oracle that takes into account force authoring flag, allowing to bootstrap
8485
/// Subspace network from scratch due to our fork of Substrate where sync state of nodes depends on
85-
/// connected nodes (none of which will be synced initially).
86+
/// connected nodes (none of which will be synced initially). It also accounts for DSN sync, when
87+
/// normal Substrate sync is paused, which might happen before Substrate's internals decide there is
88+
/// a sync happening, but DSN sync is already in progress.
8689
#[derive(Debug, Clone)]
8790
pub struct SubspaceSyncOracle<SO>
8891
where
8992
SO: SyncOracle + Send + Sync,
9093
{
9194
force_authoring: bool,
95+
pause_sync: Arc<AtomicBool>,
9296
inner: SO,
9397
}
9498

@@ -99,8 +103,9 @@ where
99103
fn is_major_syncing(&self) -> bool {
100104
// This allows slot worker to produce blocks even when it is offline, which according to
101105
// modified Substrate fork will happen when node is offline or connected to non-synced peers
102-
// (default state)
103-
!self.force_authoring && self.inner.is_major_syncing()
106+
// (default state), it also accounts for DSN sync
107+
(!self.force_authoring && self.inner.is_major_syncing())
108+
|| self.pause_sync.load(Ordering::Acquire)
104109
}
105110

106111
fn is_offline(&self) -> bool {
@@ -113,9 +118,14 @@ where
113118
SO: SyncOracle + Send + Sync,
114119
{
115120
/// Create new instance
116-
pub fn new(force_authoring: bool, substrate_sync_oracle: SO) -> Self {
121+
pub fn new(
122+
force_authoring: bool,
123+
pause_sync: Arc<AtomicBool>,
124+
substrate_sync_oracle: SO,
125+
) -> Self {
117126
Self {
118127
force_authoring,
128+
pause_sync,
119129
inner: substrate_sync_oracle,
120130
}
121131
}

crates/subspace-service/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,11 @@ where
813813
}),
814814
);
815815

816-
let sync_oracle = SubspaceSyncOracle::new(config.base.force_authoring, sync_service.clone());
816+
let sync_oracle = SubspaceSyncOracle::new(
817+
config.base.force_authoring,
818+
Arc::clone(&pause_sync),
819+
sync_service.clone(),
820+
);
817821

818822
let subspace_archiver = tokio::task::block_in_place(|| {
819823
create_subspace_archiver(

0 commit comments

Comments
 (0)