Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for DSN sync in SubspaceSyncOracle #2472

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions crates/sc-consensus-subspace/src/slot_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use std::collections::BTreeMap;
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use subspace_core_primitives::{
BlockNumber, PotCheckpoints, PotOutput, PublicKey, Randomness, RewardSignature, SectorId,
Expand All @@ -82,13 +83,16 @@ const PENDING_SOLUTIONS_CHANNEL_CAPACITY: usize = 10;

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

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

fn is_offline(&self) -> bool {
Expand All @@ -113,9 +118,14 @@ where
SO: SyncOracle + Send + Sync,
{
/// Create new instance
pub fn new(force_authoring: bool, substrate_sync_oracle: SO) -> Self {
pub fn new(
force_authoring: bool,
pause_sync: Arc<AtomicBool>,
substrate_sync_oracle: SO,
) -> Self {
Self {
force_authoring,
pause_sync,
inner: substrate_sync_oracle,
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,11 @@ where
}),
);

let sync_oracle = SubspaceSyncOracle::new(config.base.force_authoring, sync_service.clone());
let sync_oracle = SubspaceSyncOracle::new(
config.base.force_authoring,
Arc::clone(&pause_sync),
sync_service.clone(),
);

let subspace_archiver = tokio::task::block_in_place(|| {
create_subspace_archiver(
Expand Down
Loading