diff --git a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs index d8269b3f42..7a94dd59cc 100644 --- a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs +++ b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs @@ -208,6 +208,7 @@ fn main() -> Result<(), Error> { // Domain node needs slots notifications for bundle production. force_new_slot_notifications: true, subspace_networking: SubspaceNetworking::Create { config: dsn_config }, + dsn_piece_getter: None, sync_from_dsn: true, is_timekeeper: false, timekeeper_cpu_cores: Default::default(), diff --git a/crates/subspace-networking/src/utils/piece_provider.rs b/crates/subspace-networking/src/utils/piece_provider.rs index c3e0e6901c..9563e9a43c 100644 --- a/crates/subspace-networking/src/utils/piece_provider.rs +++ b/crates/subspace-networking/src/utils/piece_provider.rs @@ -9,6 +9,7 @@ use futures::StreamExt; use libp2p::PeerId; use std::collections::HashSet; use std::error::Error; +use std::fmt; use std::sync::atomic::{AtomicU64, Ordering}; use std::time::Duration; use subspace_core_primitives::{Piece, PieceIndex}; @@ -63,6 +64,12 @@ pub struct PieceProvider { piece_validator: Option, } +impl fmt::Debug for PieceProvider { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("PieceProvider").finish_non_exhaustive() + } +} + impl PieceProvider where PV: PieceValidator, diff --git a/crates/subspace-node/src/commands/run/consensus.rs b/crates/subspace-node/src/commands/run/consensus.rs index 023d862c46..2035c0c279 100644 --- a/crates/subspace-node/src/commands/run/consensus.rs +++ b/crates/subspace-node/src/commands/run/consensus.rs @@ -530,6 +530,7 @@ pub(super) fn create_consensus_chain_configuration( // Domain node needs slots notifications for bundle production. force_new_slot_notifications: domains_enabled, subspace_networking: SubspaceNetworking::Create { config: dsn_config }, + dsn_piece_getter: None, sync_from_dsn, is_timekeeper: timekeeper_options.timekeeper, timekeeper_cpu_cores: timekeeper_options.timekeeper_cpu_cores, diff --git a/crates/subspace-service/src/config.rs b/crates/subspace-service/src/config.rs index 7da9a432ba..74e5e554cb 100644 --- a/crates/subspace-service/src/config.rs +++ b/crates/subspace-service/src/config.rs @@ -1,4 +1,5 @@ use crate::dsn::DsnConfig; +use crate::sync_from_dsn::DsnSyncPieceGetter; use prometheus_client::registry::Registry; use sc_chain_spec::ChainSpec; use sc_network::config::{ @@ -242,6 +243,8 @@ pub struct SubspaceConfiguration { pub force_new_slot_notifications: bool, /// Subspace networking (DSN). pub subspace_networking: SubspaceNetworking, + /// DSN piece getter + pub dsn_piece_getter: Option>, /// Enables DSN-sync on startup. pub sync_from_dsn: bool, /// Is this node a Timekeeper diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index e692427e9c..a829b0809c 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -846,14 +846,16 @@ where network_wrapper.set(network_service.clone()); if config.sync_from_dsn { - let piece_provider = PieceProvider::new( - node.clone(), - Some(SegmentCommitmentPieceValidator::new( + let dsn_sync_piece_getter = config.dsn_piece_getter.unwrap_or_else(|| { + Arc::new(PieceProvider::new( node.clone(), - subspace_link.kzg().clone(), - segment_headers_store.clone(), - )), - ); + Some(SegmentCommitmentPieceValidator::new( + node.clone(), + subspace_link.kzg().clone(), + segment_headers_store.clone(), + )), + )) + }); let (observer, worker) = sync_from_dsn::create_observer_and_worker( segment_headers_store.clone(), @@ -863,7 +865,7 @@ where import_queue_service, sync_target_block_number, pause_sync, - piece_provider, + dsn_sync_piece_getter, ); task_manager .spawn_handle() diff --git a/crates/subspace-service/src/sync_from_dsn/import_blocks.rs b/crates/subspace-service/src/sync_from_dsn/import_blocks.rs index 4bba0cfaae..b24c3ad6eb 100644 --- a/crates/subspace-service/src/sync_from_dsn/import_blocks.rs +++ b/crates/subspace-service/src/sync_from_dsn/import_blocks.rs @@ -28,6 +28,7 @@ use sp_runtime::generic::SignedBlock; use sp_runtime::traits::{Block as BlockT, Header, NumberFor, One}; use sp_runtime::Saturating; use std::error::Error; +use std::fmt; use std::num::NonZeroU16; use std::sync::Arc; use std::time::Duration; @@ -41,7 +42,7 @@ use tracing::warn; /// Trait representing a way to get pieces for DSN sync purposes #[async_trait] -pub trait DsnSyncPieceGetter { +pub trait DsnSyncPieceGetter: fmt::Debug { async fn get_piece( &self, piece_index: PieceIndex, @@ -51,7 +52,7 @@ pub trait DsnSyncPieceGetter { #[async_trait] impl DsnSyncPieceGetter for Arc where - T: DsnSyncPieceGetter + Send + Sync, + T: DsnSyncPieceGetter + Send + Sync + ?Sized, { async fn get_piece( &self,