Skip to content

Commit 00d5003

Browse files
committed
unify spawn_essential_handles params into SpawnEssentialHandlesParams
1 parent a234096 commit 00d5003

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

node/src/consensus/aura_consensus.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::consensus::consensus_mechanism::SpawnEssentialHandlesParams;
12
use crate::consensus::hybrid_import_queue::HybridBlockImport;
23
use crate::consensus::{ConsensusMechanism, StartAuthoringParams};
34
use crate::{
@@ -11,7 +12,6 @@ use sc_client_api::{AuxStore, BlockOf, UsageProvider};
1112
use sc_consensus::{BlockImport, BoxBlockImport};
1213
use sc_consensus_grandpa::BlockNumberOps;
1314
use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, InherentDataProviderExt};
14-
use sc_network_sync::SyncingService;
1515
use sc_service::{Configuration, TaskManager};
1616
use sc_telemetry::TelemetryHandle;
1717
use sc_transaction_pool::TransactionPoolHandle;
@@ -193,15 +193,12 @@ impl ConsensusMechanism for AuraConsensus {
193193

194194
fn spawn_essential_handles(
195195
&self,
196-
task_manager: &mut TaskManager,
197-
client: Arc<FullClient>,
198-
triggered: Option<Arc<std::sync::atomic::AtomicBool>>,
199-
sync_service: Arc<SyncingService<Block>>,
196+
p: SpawnEssentialHandlesParams,
200197
) -> Result<(), sc_service::Error> {
201-
let client_clone = client.clone();
202-
let triggered_clone = triggered.clone();
203-
let slot_duration = self.slot_duration(&client)?;
204-
task_manager.spawn_essential_handle().spawn(
198+
let client_clone = p.client.clone();
199+
let triggered_clone = p.triggered.clone();
200+
let slot_duration = self.slot_duration(&p.client)?;
201+
p.task_manager.spawn_essential_handle().spawn(
205202
"babe-switch",
206203
None,
207204
Box::pin(async move {
@@ -219,7 +216,7 @@ impl ConsensusMechanism for AuraConsensus {
219216
// Babe service. If we only wait for the "warp sync" to finish while state
220217
// sync is still in progress prior to switching, the warp sync will not
221218
// complete successfully.
222-
let syncing = sync_service.status().await.is_ok_and(|status| status.warp_sync.is_some() || status.state_sync.is_some());
219+
let syncing = p.sync_service.status().await.is_ok_and(|status| status.warp_sync.is_some() || status.state_sync.is_some());
223220
if !c.authorities.is_empty() && !syncing {
224221
log::info!("Babe runtime detected! Intentionally failing the essential handle `babe-switch` to trigger switch to Babe service.");
225222
if let Some(triggered) = triggered {

node/src/consensus/babe_consensus.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::consensus::ConsensusMechanism;
22
use crate::consensus::StartAuthoringParams;
3+
use crate::consensus::consensus_mechanism::SpawnEssentialHandlesParams;
34
use crate::{
45
client::{FullBackend, FullClient},
56
conditional_evm_block_import::ConditionalEVMBlockImport,
@@ -16,7 +17,6 @@ use sc_consensus_babe::{BabeLink, BabeWorkerHandle};
1617
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
1718
use sc_consensus_grandpa::BlockNumberOps;
1819
use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, InherentDataProviderExt};
19-
use sc_network_sync::SyncingService;
2020
use sc_service::{Configuration, TaskManager};
2121
use sc_telemetry::TelemetryHandle;
2222
use sc_transaction_pool::TransactionPoolHandle;
@@ -216,10 +216,7 @@ impl ConsensusMechanism for BabeConsensus {
216216

217217
fn spawn_essential_handles(
218218
&self,
219-
_task_manager: &mut TaskManager,
220-
_client: Arc<FullClient>,
221-
_triggered: Option<Arc<std::sync::atomic::AtomicBool>>,
222-
_sync_service: Arc<SyncingService<Block>>,
219+
_params: SpawnEssentialHandlesParams,
223220
) -> Result<(), sc_service::Error> {
224221
// No additional Babe handles required.
225222
Ok(())

node/src/consensus/consensus_mechanism.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ pub trait ConsensusMechanism {
122122
/// Spawns any consensus mechanism specific essential handles.
123123
fn spawn_essential_handles(
124124
&self,
125-
task_manager: &mut TaskManager,
126-
client: Arc<FullClient>,
127-
triggered: Option<Arc<AtomicBool>>,
128-
sync_service: Arc<SyncingService<Block>>,
125+
params: SpawnEssentialHandlesParams,
129126
) -> Result<(), ServiceError>;
130127

131128
/// Returns any consensus mechanism specific rpc methods to register.
@@ -136,3 +133,26 @@ pub trait ConsensusMechanism {
136133
select_chain: FullSelectChain,
137134
) -> Result<Vec<Methods>, sc_service::Error>;
138135
}
136+
137+
pub struct SpawnEssentialHandlesParams<'a> {
138+
pub task_manager: &'a mut TaskManager,
139+
pub client: Arc<FullClient>,
140+
pub triggered: Option<Arc<AtomicBool>>,
141+
pub sync_service: Arc<SyncingService<Block>>,
142+
}
143+
144+
impl<'a> SpawnEssentialHandlesParams<'a> {
145+
pub fn new(
146+
task_manager: &'a mut TaskManager,
147+
client: Arc<FullClient>,
148+
triggered: Option<Arc<AtomicBool>>,
149+
sync_service: Arc<SyncingService<Block>>,
150+
) -> Self {
151+
Self {
152+
task_manager,
153+
client,
154+
triggered,
155+
sync_service,
156+
}
157+
}
158+
}

node/src/consensus/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ mod hybrid_import_queue;
66
pub use aura_consensus::AuraConsensus;
77
pub use babe_consensus::BabeConsensus;
88
pub use consensus_mechanism::ConsensusMechanism;
9+
pub use consensus_mechanism::SpawnEssentialHandlesParams;
910
pub use consensus_mechanism::StartAuthoringParams;

node/src/service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
22
33
use crate::consensus::ConsensusMechanism;
4+
use crate::consensus::SpawnEssentialHandlesParams;
45
use futures::{FutureExt, channel::mpsc, future};
56
use node_subtensor_runtime::{RuntimeApi, TransactionConverter, opaque::Block};
67
use sc_chain_spec::ChainType;
@@ -350,12 +351,12 @@ where
350351
metrics,
351352
})?;
352353

353-
consensus_mechanism.spawn_essential_handles(
354+
consensus_mechanism.spawn_essential_handles(SpawnEssentialHandlesParams::new(
354355
&mut task_manager,
355356
client.clone(),
356357
custom_service_signal,
357358
sync_service.clone(),
358-
)?;
359+
))?;
359360

360361
if config.offchain_worker.enabled && config.role.is_authority() {
361362
let public_keys = keystore_container

0 commit comments

Comments
 (0)