Skip to content

Commit

Permalink
Merge pull request #1941 from subspace/refactor-service-configuration
Browse files Browse the repository at this point in the history
Refactor service configuration to not require cloning
  • Loading branch information
nazar-pc authored Sep 8, 2023
2 parents d57f0bb + 61318ac commit 3a2f870
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ fn main() -> Result<(), Error> {
};
let partial_components =
subspace_service::new_partial::<PosTable, RuntimeApi, ExecutorDispatch>(
&consensus_chain_config,
&consensus_chain_config.base,
Some(&construct_domain_genesis_block_builder),
#[cfg(feature = "pot")]
&pot_external_entropy,
Expand Down
1 change: 0 additions & 1 deletion crates/subspace-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ targets = ["x86_64-unknown-linux-gnu"]
async-trait = "0.1.68"
atomic = "0.5.3"
cross-domain-message-gossip = { version = "0.1.0", path = "../../domains/client/cross-domain-message-gossip" }
derive_more = "0.99.17"
domain-block-preprocessor = { version = "0.1.0", path = "../../domains/client/block-preprocessor" }
domain-runtime-primitives = { version = "0.1.0", path = "../../domains/primitives/runtime" }
either = "1.8.1"
Expand Down
44 changes: 19 additions & 25 deletions crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::dsn::{create_dsn_instance, DsnConfigurationError};
use crate::metrics::NodeMetrics;
use crate::tx_pre_validator::ConsensusChainTxPreValidator;
use cross_domain_message_gossip::cdm_gossip_peers_set_config;
use derive_more::{Deref, DerefMut, Into};
use domain_runtime_primitives::{BlockNumber as DomainNumber, Hash as DomainHash};
pub use dsn::DsnConfig;
use frame_system_rpc_runtime_api::AccountNonceApi;
Expand Down Expand Up @@ -177,7 +176,7 @@ pub type FraudProofVerifier<RuntimeApi, ExecutorDispatch> = subspace_fraud_proof
>;

/// Subspace networking instantiation variant
#[derive(Debug, Clone)]
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub enum SubspaceNetworking {
/// Use existing networking instance
Expand All @@ -195,12 +194,9 @@ pub enum SubspaceNetworking {
}

/// Subspace-specific service configuration.
#[derive(Debug, Deref, DerefMut, Into)]
#[derive(Debug)]
pub struct SubspaceConfiguration {
/// Base configuration.
#[deref]
#[deref_mut]
#[into]
pub base: Configuration,
/// Whether slot notifications need to be present even if node is not responsible for block
/// authoring.
Expand Down Expand Up @@ -587,7 +583,7 @@ where
mut telemetry,
} = other;

let (node, bootstrap_nodes) = match config.subspace_networking.clone() {
let (node, bootstrap_nodes) = match config.subspace_networking {
SubspaceNetworking::Reuse {
node,
bootstrap_nodes,
Expand All @@ -596,7 +592,7 @@ where
let dsn_protocol_version = hex::encode(client.chain_info().genesis_hash);

debug!(
chain_type=?config.chain_spec.chain_type(),
chain_type=?config.base.chain_spec.chain_type(),
genesis_hash=%hex::encode(client.chain_info().genesis_hash),
"Setting DSN protocol version..."
);
Expand Down Expand Up @@ -677,7 +673,7 @@ where

node_listeners
} else {
bootstrap_nodes.clone()
bootstrap_nodes
}
};

Expand All @@ -692,14 +688,14 @@ where
} else {
None
};
let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.base.network);
net_config.add_notification_protocol(cdm_gossip_peers_set_config());
#[cfg(feature = "pot")]
net_config.add_notification_protocol(pot_gossip_peers_set_config());
let sync_mode = Arc::clone(&net_config.network_config.sync_mode);
let (network_service, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
config: &config.base,
net_config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
Expand All @@ -710,14 +706,13 @@ where
block_relay,
})?;

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

let subspace_archiver = create_subspace_archiver(
segment_headers_store.clone(),
&subspace_link,
client.clone(),
subspace_sync_oracle.clone(),
sync_oracle.clone(),
telemetry.as_ref().map(|telemetry| telemetry.handle()),
);

Expand Down Expand Up @@ -754,7 +749,7 @@ where
);
}

if let Some(registry) = config.prometheus_registry().as_ref() {
if let Some(registry) = config.base.prometheus_registry() {
match NodeMetrics::new(
client.clone(),
client.import_notification_stream(),
Expand All @@ -775,17 +770,16 @@ where
}
}

if config.offchain_worker.enabled {
if config.base.offchain_worker.enabled {
sc_service::build_offchain_workers(
&config,
&config.base,
task_manager.spawn_handle(),
client.clone(),
network_service.clone(),
);
}

let backoff_authoring_blocks: Option<()> = None;
let prometheus_registry = config.prometheus_registry().cloned();

let new_slot_notification_stream = subspace_link.new_slot_notification_stream();
let reward_signing_notification_stream = subspace_link.reward_signing_notification_stream();
Expand All @@ -810,12 +804,12 @@ where
pot_slot_info_stream
};

if config.role.is_authority() || config.force_new_slot_notifications {
if config.base.role.is_authority() || config.force_new_slot_notifications {
let proposer_factory = ProposerFactory::new(
task_manager.spawn_handle(),
client.clone(),
transaction_pool.clone(),
prometheus_registry.as_ref(),
config.base.prometheus_registry(),
telemetry.as_ref().map(|x| x.handle()),
);

Expand All @@ -824,7 +818,7 @@ where
select_chain: select_chain.clone(),
env: proposer_factory,
block_import,
sync_oracle: subspace_sync_oracle.clone(),
sync_oracle: sync_oracle.clone(),
justification_sync_link: sync_service.clone(),
create_inherent_data_providers: {
let client = client.clone();
Expand Down Expand Up @@ -854,7 +848,7 @@ where
}
}
},
force_authoring: config.force_authoring,
force_authoring: config.base.force_authoring,
backoff_authoring_blocks,
subspace_link: subspace_link.clone(),
segment_headers_store: segment_headers_store.clone(),
Expand Down Expand Up @@ -891,7 +885,7 @@ where
let reward_signing_notification_stream = reward_signing_notification_stream.clone();
let archived_segment_notification_stream = archived_segment_notification_stream.clone();
let transaction_pool = transaction_pool.clone();
let chain_spec = config.chain_spec.cloned_box();
let chain_spec = config.base.chain_spec.cloned_box();

Box::new(move |deny_unsafe, subscription_executor| {
let deps = rpc::FullDeps {
Expand All @@ -906,7 +900,7 @@ where
.clone(),
dsn_bootstrap_nodes: dsn_bootstrap_nodes.clone(),
segment_headers_store: segment_headers_store.clone(),
sync_oracle: subspace_sync_oracle.clone(),
sync_oracle: sync_oracle.clone(),
kzg: subspace_link.kzg().clone(),
};

Expand All @@ -917,7 +911,7 @@ where
},
backend: backend.clone(),
system_rpc_tx,
config: config.into(),
config: config.base,
telemetry: telemetry.as_mut(),
tx_handler_controller,
sync_service: sync_service.clone(),
Expand Down

0 comments on commit 3a2f870

Please sign in to comment.