Skip to content

Commit 712f9e8

Browse files
authored
Merge pull request #968 from opentensor/fix/remove-generics-in-node
Fix compilation
2 parents 64adce1 + 8163679 commit 712f9e8

File tree

1 file changed

+85
-99
lines changed

1 file changed

+85
-99
lines changed

node/src/service.rs

+85-99
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
22
33
use crate::cli::Sealing;
4-
use crate::client::{FullBackend, FullClient, RuntimeApiCollection};
4+
use crate::client::{FullBackend, FullClient};
55
use crate::ethereum::{
66
db_config_dir, new_frontier_partial, spawn_frontier_tasks, BackendType, EthConfiguration,
77
FrontierBackend, FrontierBlockImport, FrontierPartialComponents, StorageOverride,
@@ -12,24 +12,20 @@ use sc_client_api::{Backend as BackendT, BlockBackend};
1212
use sc_consensus::{BasicQueue, BoxBlockImport};
1313
use sc_consensus_grandpa::BlockNumberOps;
1414
use sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging;
15-
use sc_executor::HostFunctions as HostFunctionsT;
1615
use sc_network_sync::strategy::warp::{WarpSyncConfig, WarpSyncProvider};
1716
use sc_service::{error::Error as ServiceError, Configuration, PartialComponents, TaskManager};
1817
use sc_telemetry::{log, Telemetry, TelemetryHandle, TelemetryWorker};
1918
use sc_transaction_pool::FullPool;
2019
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
21-
use sp_api::ConstructRuntimeApi;
22-
use sp_consensus_aura::sr25519::{AuthorityId as AuraId, AuthorityPair as AuraPair};
23-
use sp_core::{H256, U256};
20+
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
21+
use sp_core::U256;
2422
use sp_runtime::traits::{Block as BlockT, NumberFor};
2523
use std::{cell::RefCell, path::Path};
2624
use std::{sync::Arc, time::Duration};
2725
use substrate_prometheus_endpoint::Registry;
2826

2927
// Runtime
30-
use node_subtensor_runtime::{
31-
opaque::Block, AccountId, Balance, Nonce, RuntimeApi, TransactionConverter,
32-
};
28+
use node_subtensor_runtime::{opaque::Block, RuntimeApi, TransactionConverter};
3329

3430
/// The minimum period of blocks on which justifications will be
3531
/// imported and generated.
@@ -53,41 +49,41 @@ type GrandpaBlockImport<B, C> =
5349
sc_consensus_grandpa::GrandpaBlockImport<FullBackend<B>, B, C, FullSelectChain<B>>;
5450
type GrandpaLinkHalf<B, C> = sc_consensus_grandpa::LinkHalf<B, C, FullSelectChain<B>>;
5551

56-
pub fn new_partial<B, RA, HF, BIQ>(
52+
pub fn new_partial<BIQ>(
5753
config: &Configuration,
5854
eth_config: &EthConfiguration,
5955
build_import_queue: BIQ,
6056
) -> Result<
6157
PartialComponents<
62-
FullClient<B, RA, HF>,
63-
FullBackend<B>,
64-
FullSelectChain<B>,
65-
BasicQueue<B>,
66-
FullPool<B, FullClient<B, RA, HF>>,
58+
Client,
59+
FullBackend<Block>,
60+
FullSelectChain<Block>,
61+
BasicQueue<Block>,
62+
FullPool<Block, Client>,
6763
(
6864
Option<Telemetry>,
69-
BoxBlockImport<B>,
70-
GrandpaLinkHalf<B, FullClient<B, RA, HF>>,
71-
FrontierBackend<B, FullClient<B, RA, HF>>,
72-
Arc<dyn StorageOverride<B>>,
65+
BoxBlockImport<Block>,
66+
GrandpaLinkHalf<Block, Client>,
67+
FrontierBackend<Block, Client>,
68+
Arc<dyn StorageOverride<Block>>,
7369
),
7470
>,
7571
ServiceError,
7672
>
7773
where
78-
B: BlockT<Hash = H256>,
79-
RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
80-
RA: Send + Sync + 'static,
81-
RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
82-
HF: HostFunctionsT + 'static,
74+
// B: BlockT<Hash = H256>,
75+
// RA: ConstructRuntimeApi<Block, Client>,
76+
// RA: Send + Sync + 'static,
77+
// RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
78+
// HF: HostFunctionsT + 'static,
8379
BIQ: FnOnce(
84-
Arc<FullClient<B, RA, HF>>,
80+
Arc<Client>,
8581
&Configuration,
8682
&EthConfiguration,
8783
&TaskManager,
8884
Option<TelemetryHandle>,
89-
GrandpaBlockImport<B, FullClient<B, RA, HF>>,
90-
) -> Result<(BasicQueue<B>, BoxBlockImport<B>), ServiceError>,
85+
GrandpaBlockImport<Block, Client>,
86+
) -> Result<(BasicQueue<Block>, BoxBlockImport<Block>), ServiceError>,
9187
{
9288
let telemetry = config
9389
.telemetry_endpoints
@@ -100,12 +96,13 @@ where
10096
})
10197
.transpose()?;
10298

103-
let executor = sc_service::new_wasm_executor::<HostFunctions>(&config.executor);
104-
let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::<B, RA, _>(
105-
config,
106-
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
107-
executor,
108-
)?;
99+
let executor = sc_service::new_wasm_executor(&config.executor);
100+
let (client, backend, keystore_container, task_manager) =
101+
sc_service::new_full_parts::<Block, RuntimeApi, _>(
102+
config,
103+
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
104+
executor,
105+
)?;
109106
let client = Arc::new(client);
110107

111108
let telemetry = telemetry.map(|(worker, telemetry)| {
@@ -124,7 +121,7 @@ where
124121
telemetry.as_ref().map(|x| x.handle()),
125122
)?;
126123

127-
let storage_override = Arc::new(StorageOverrideHandler::<B, _, _>::new(client.clone()));
124+
let storage_override = Arc::new(StorageOverrideHandler::<_, _, _>::new(client.clone()));
128125
let frontier_backend = match eth_config.frontier_backend_type {
129126
BackendType::KeyValue => FrontierBackend::KeyValue(Arc::new(fc_db::kv::Backend::open(
130127
Arc::clone(&client),
@@ -190,21 +187,21 @@ where
190187
}
191188

192189
/// Build the import queue for the template runtime (aura + grandpa).
193-
pub fn build_aura_grandpa_import_queue<B, RA, HF>(
194-
client: Arc<FullClient<B, RA, HF>>,
190+
pub fn build_aura_grandpa_import_queue(
191+
client: Arc<Client>,
195192
config: &Configuration,
196193
eth_config: &EthConfiguration,
197194
task_manager: &TaskManager,
198195
telemetry: Option<TelemetryHandle>,
199-
grandpa_block_import: GrandpaBlockImport<B, FullClient<B, RA, HF>>,
200-
) -> Result<(BasicQueue<B>, BoxBlockImport<B>), ServiceError>
196+
grandpa_block_import: GrandpaBlockImport<Block, Client>,
197+
) -> Result<(BasicQueue<Block>, BoxBlockImport<Block>), ServiceError>
201198
where
202-
B: BlockT,
203-
NumberFor<B>: BlockNumberOps,
204-
RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
205-
RA: Send + Sync + 'static,
206-
RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
207-
HF: HostFunctionsT + 'static,
199+
// B: BlockT,
200+
NumberFor<Block>: BlockNumberOps,
201+
// RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
202+
// RA: Send + Sync + 'static,
203+
// RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
204+
// HF: HostFunctionsT + 'static,
208205
{
209206
let frontier_block_import =
210207
FrontierBlockImport::new(grandpa_block_import.clone(), client.clone());
@@ -241,20 +238,20 @@ where
241238
}
242239

243240
/// Build the import queue for the template runtime (manual seal).
244-
pub fn build_manual_seal_import_queue<B, RA, HF>(
245-
client: Arc<FullClient<B, RA, HF>>,
241+
pub fn build_manual_seal_import_queue(
242+
client: Arc<Client>,
246243
config: &Configuration,
247244
_eth_config: &EthConfiguration,
248245
task_manager: &TaskManager,
249246
_telemetry: Option<TelemetryHandle>,
250-
_grandpa_block_import: GrandpaBlockImport<B, FullClient<B, RA, HF>>,
251-
) -> Result<(BasicQueue<B>, BoxBlockImport<B>), ServiceError>
252-
where
253-
B: BlockT,
254-
RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
255-
RA: Send + Sync + 'static,
256-
RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
257-
HF: HostFunctionsT + 'static,
247+
_grandpa_block_import: GrandpaBlockImport<Block, Client>,
248+
) -> Result<(BasicQueue<Block>, BoxBlockImport<Block>), ServiceError>
249+
// where
250+
// B: BlockT,
251+
// RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
252+
// RA: Send + Sync + 'static,
253+
// RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
254+
// HF: HostFunctionsT + 'static,
258255
{
259256
let frontier_block_import = FrontierBlockImport::new(client.clone(), client);
260257
Ok((
@@ -268,25 +265,25 @@ where
268265
}
269266

270267
/// Builds a new service for a full client.
271-
pub async fn new_full<B, RA, HF, NB>(
268+
pub async fn new_full<NB>(
272269
mut config: Configuration,
273270
eth_config: EthConfiguration,
274271
sealing: Option<Sealing>,
275272
) -> Result<TaskManager, ServiceError>
276273
where
277-
B: BlockT<Hash = H256>,
278-
NumberFor<B>: BlockNumberOps,
279-
<B as BlockT>::Header: Unpin,
280-
RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
281-
RA: Send + Sync + 'static,
282-
RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
283-
HF: HostFunctionsT + 'static,
284-
NB: sc_network::NetworkBackend<B, <B as sp_runtime::traits::Block>::Hash>,
274+
// B: BlockT<Hash = H256>,
275+
NumberFor<Block>: BlockNumberOps,
276+
// <B as BlockT>::Header: Unpin,
277+
// RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
278+
// RA: Send + Sync + 'static,
279+
// RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
280+
// HF: HostFunctionsT + 'static,
281+
NB: sc_network::NetworkBackend<Block, <Block as BlockT>::Hash>,
285282
{
286283
let build_import_queue = if sealing.is_some() {
287-
build_manual_seal_import_queue::<B, RA, HF>
284+
build_manual_seal_import_queue
288285
} else {
289-
build_aura_grandpa_import_queue::<B, RA, HF>
286+
build_aura_grandpa_import_queue
290287
};
291288

292289
let PartialComponents {
@@ -315,9 +312,7 @@ where
315312
let metrics = NB::register_notification_metrics(maybe_registry);
316313

317314
let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name(
318-
&client
319-
.block_hash(0u32.into())?
320-
.expect("Genesis block exists; qed"),
315+
&client.block_hash(0u32)?.expect("Genesis block exists; qed"),
321316
&config.chain_spec,
322317
);
323318

@@ -332,7 +327,7 @@ where
332327
None
333328
} else {
334329
net_config.add_notification_protocol(grandpa_protocol_config);
335-
let warp_sync: Arc<dyn WarpSyncProvider<B>> =
330+
let warp_sync: Arc<dyn WarpSyncProvider<Block>> =
336331
Arc::new(sc_consensus_grandpa::warp_proof::NetworkProvider::new(
337332
backend.clone(),
338333
grandpa_link.shared_authority_set().clone(),
@@ -378,10 +373,11 @@ where
378373

379374
let role = config.role;
380375
let force_authoring = config.force_authoring;
381-
let backoff_authoring_blocks = Some(BackoffAuthoringOnFinalizedHeadLagging::<NumberFor<B>> {
382-
unfinalized_slack: 6u32.into(),
383-
..Default::default()
384-
});
376+
let backoff_authoring_blocks =
377+
Some(BackoffAuthoringOnFinalizedHeadLagging::<NumberFor<Block>> {
378+
unfinalized_slack: 6u32,
379+
..Default::default()
380+
});
385381
let name = config.network.node_name.clone();
386382
let frontier_backend = Arc::new(frontier_backend);
387383
let enable_grandpa = !config.disable_grandpa && sealing.is_none();
@@ -395,7 +391,7 @@ where
395391
// The MappingSyncWorker sends through the channel on block import and the subscription emits a notification to the subscriber on receiving a message through this channel.
396392
// This way we avoid race conditions when using native substrate block import notification stream.
397393
let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
398-
fc_mapping_sync::EthereumBlockNotification<B>,
394+
fc_mapping_sync::EthereumBlockNotification<Block>,
399395
> = Default::default();
400396
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);
401397

@@ -447,7 +443,7 @@ where
447443
client: client.clone(),
448444
pool: pool.clone(),
449445
graph: pool.pool().clone(),
450-
converter: Some(TransactionConverter::<B>::default()),
446+
converter: Some(TransactionConverter::<Block>::default()),
451447
is_authority,
452448
enable_dev_signer,
453449
network: network.clone(),
@@ -640,16 +636,10 @@ pub async fn build_full(
640636
) -> Result<TaskManager, ServiceError> {
641637
match config.network.network_backend {
642638
sc_network::config::NetworkBackendType::Libp2p => {
643-
new_full::<Block, RuntimeApi, HostFunctions, sc_network::NetworkWorker<_, _>>(
644-
config, eth_config, sealing,
645-
)
646-
.await
639+
new_full::<sc_network::NetworkWorker<_, _>>(config, eth_config, sealing).await
647640
}
648641
sc_network::config::NetworkBackendType::Litep2p => {
649-
new_full::<Block, RuntimeApi, HostFunctions, sc_network::Litep2pNetworkBackend>(
650-
config, eth_config, sealing,
651-
)
652-
.await
642+
new_full::<sc_network::NetworkWorker<_, _>>(config, eth_config, sealing).await
653643
}
654644
}
655645
}
@@ -675,35 +665,31 @@ pub fn new_chain_ops(
675665
task_manager,
676666
other,
677667
..
678-
} = new_partial::<Block, RuntimeApi, HostFunctions, _>(
679-
config,
680-
eth_config,
681-
build_aura_grandpa_import_queue,
682-
)?;
668+
} = new_partial(config, eth_config, build_aura_grandpa_import_queue)?;
683669
Ok((client, backend, import_queue, task_manager, other.3))
684670
}
685671

686672
#[allow(clippy::too_many_arguments)]
687-
fn run_manual_seal_authorship<B, RA, HF>(
673+
fn run_manual_seal_authorship(
688674
eth_config: &EthConfiguration,
689675
sealing: Sealing,
690-
client: Arc<FullClient<B, RA, HF>>,
691-
transaction_pool: Arc<FullPool<B, FullClient<B, RA, HF>>>,
692-
select_chain: FullSelectChain<B>,
693-
block_import: BoxBlockImport<B>,
676+
client: Arc<Client>,
677+
transaction_pool: Arc<FullPool<Block, Client>>,
678+
select_chain: FullSelectChain<Block>,
679+
block_import: BoxBlockImport<Block>,
694680
task_manager: &TaskManager,
695681
prometheus_registry: Option<&Registry>,
696682
telemetry: Option<&Telemetry>,
697683
commands_stream: mpsc::Receiver<
698-
sc_consensus_manual_seal::rpc::EngineCommand<<B as BlockT>::Hash>,
684+
sc_consensus_manual_seal::rpc::EngineCommand<<Block as BlockT>::Hash>,
699685
>,
700686
) -> Result<(), ServiceError>
701-
where
702-
B: BlockT,
703-
RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
704-
RA: Send + Sync + 'static,
705-
RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
706-
HF: HostFunctionsT + 'static,
687+
// where
688+
// B: BlockT,
689+
// RA: ConstructRuntimeApi<B, FullClient<B, RA, HF>>,
690+
// RA: Send + Sync + 'static,
691+
// RA::RuntimeApi: RuntimeApiCollection<B, AuraId, AccountId, Nonce, Balance>,
692+
// HF: HostFunctionsT + 'static,
707693
{
708694
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
709695
task_manager.spawn_handle(),

0 commit comments

Comments
 (0)