@@ -66,6 +66,7 @@ use std::collections::BTreeMap;
6666use std:: future:: Future ;
6767use std:: marker:: PhantomData ;
6868use std:: pin:: Pin ;
69+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
6970use std:: sync:: Arc ;
7071use 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 ) ]
8790pub struct SubspaceSyncOracle < SO >
8891where
8992 SO : SyncOracle + Send + Sync ,
9093{
9194 force_authoring : bool ,
95+ pause_sync : Arc < AtomicBool > ,
9296 inner : SO ,
9397}
9498
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 }
0 commit comments