Skip to content
Snippets Groups Projects
Unverified Commit da8259c8 authored by bgallois's avatar bgallois
Browse files

fix babe-worker

parent abd16b23
No related branches found
No related tags found
No related merge requests found
...@@ -1905,6 +1905,7 @@ dependencies = [ ...@@ -1905,6 +1905,7 @@ dependencies = [
"sc-client-db", "sc-client-db",
"sc-consensus", "sc-consensus",
"sc-consensus-babe", "sc-consensus-babe",
"sc-consensus-babe-rpc",
"sc-consensus-grandpa", "sc-consensus-grandpa",
"sc-consensus-manual-seal", "sc-consensus-manual-seal",
"sc-executor", "sc-executor",
...@@ -7633,6 +7634,28 @@ dependencies = [ ...@@ -7633,6 +7634,28 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "sc-consensus-babe-rpc"
version = "0.10.0-dev"
source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.42#87ef489034ca2b15c4f30da387e06b1f6716d9a2"
dependencies = [
"futures 0.3.28",
"jsonrpsee",
"sc-consensus-babe",
"sc-consensus-epochs",
"sc-rpc-api",
"serde",
"sp-api",
"sp-application-crypto",
"sp-blockchain",
"sp-consensus",
"sp-consensus-babe",
"sp-core",
"sp-keystore",
"sp-runtime",
"thiserror",
]
[[package]] [[package]]
name = "sc-consensus-epochs" name = "sc-consensus-epochs"
version = "0.10.0-dev" version = "0.10.0-dev"
...@@ -10629,7 +10652,7 @@ version = "1.6.3" ...@@ -10629,7 +10652,7 @@ version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 0.1.10",
"digest 0.10.7", "digest 0.10.7",
"rand 0.8.5", "rand 0.8.5",
"static_assertions", "static_assertions",
......
...@@ -93,6 +93,7 @@ sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-subst ...@@ -93,6 +93,7 @@ sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-subst
sc-client-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false } sc-client-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
sc-consensus = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false } sc-consensus = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
sc-consensus-babe = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false } sc-consensus-babe = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
sc-consensus-babe-rpc = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
sc-consensus-manual-seal = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false } sc-consensus-manual-seal = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
sc-client-db = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false } sc-client-db = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
sc-executor = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false } sc-executor = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.42", default-features = false }
......
...@@ -26,29 +26,47 @@ pub use sc_rpc_api::DenyUnsafe; ...@@ -26,29 +26,47 @@ pub use sc_rpc_api::DenyUnsafe;
use common_runtime::Block; use common_runtime::Block;
use common_runtime::{AccountId, Balance, Index}; use common_runtime::{AccountId, Balance, Index};
use jsonrpsee::RpcModule; use jsonrpsee::RpcModule;
use sc_consensus_babe::BabeApi;
use sc_consensus_babe::BabeWorkerHandle;
use sc_transaction_pool_api::TransactionPool; use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi; use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder; use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::SelectChain;
use sp_keystore::KeystorePtr;
use std::sync::Arc; use std::sync::Arc;
/// Extra dependencies for BABE.
pub struct BabeDeps {
/// A handle to the BABE worker for issuing requests.
pub babe_worker_handle: BabeWorkerHandle<Block>,
/// The keystore that manages the keys of the node.
pub keystore: KeystorePtr,
}
/// Full client dependencies. /// Full client dependencies.
pub struct FullDeps<C, P> { pub struct FullDeps<C, P, SC> {
/// The client instance to use. /// The client instance to use.
pub client: Arc<C>, pub client: Arc<C>,
/// Transaction pool instance. /// Transaction pool instance.
pub pool: Arc<P>, pub pool: Arc<P>,
/// The SelectChain Strategy
pub select_chain: SC,
/// A copy of the chain spec.
pub chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
/// Whether to deny unsafe calls /// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe, pub deny_unsafe: DenyUnsafe,
/// Manual seal command sink /// Manual seal command sink
pub command_sink_opt: Option< pub command_sink_opt: Option<
futures::channel::mpsc::Sender<sc_consensus_manual_seal::EngineCommand<sp_core::H256>>, futures::channel::mpsc::Sender<sc_consensus_manual_seal::EngineCommand<sp_core::H256>>,
>, >,
/// BABE specific dependencies.
pub babe: BabeDeps,
} }
/// Instantiate all full RPC extensions. /// Instantiate all full RPC extensions.
pub fn create_full<C, P>( pub fn create_full<C, P, SC>(
deps: FullDeps<C, P>, deps: FullDeps<C, P, SC>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>> ) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where where
C: ProvideRuntimeApi<Block>, C: ProvideRuntimeApi<Block>,
...@@ -56,10 +74,13 @@ where ...@@ -56,10 +74,13 @@ where
C: Send + Sync + 'static, C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>, C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>, C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static, P: TransactionPool + 'static,
SC: SelectChain<Block> + 'static,
{ {
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer}; use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer};
...@@ -67,13 +88,30 @@ where ...@@ -67,13 +88,30 @@ where
let FullDeps { let FullDeps {
client, client,
pool, pool,
select_chain,
chain_spec: _,
deny_unsafe, deny_unsafe,
command_sink_opt, command_sink_opt,
babe,
} = deps; } = deps;
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; let BabeDeps {
module.merge(TransactionPayment::new(client).into_rpc())?; babe_worker_handle,
keystore,
} = babe;
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(
Babe::new(
client.clone(),
babe_worker_handle.clone(),
keystore,
select_chain,
deny_unsafe,
)
.into_rpc(),
)?;
if let Some(command_sink) = command_sink_opt { if let Some(command_sink) = command_sink_opt {
// We provide the rpc handler with the sending end of the channel to allow the rpc // We provide the rpc handler with the sending end of the channel to allow the rpc
// send EngineCommands to the background block authorship task. // send EngineCommands to the background block authorship task.
......
...@@ -218,6 +218,7 @@ pub fn new_partial<RuntimeApi, Executor>( ...@@ -218,6 +218,7 @@ pub fn new_partial<RuntimeApi, Executor>(
FullGrandpaBlockImport<RuntimeApi, Executor>, FullGrandpaBlockImport<RuntimeApi, Executor>,
>, >,
sc_consensus_babe::BabeLink<Block>, sc_consensus_babe::BabeLink<Block>,
sc_consensus_babe::BabeWorkerHandle<Block>,
sc_consensus_grandpa::LinkHalf< sc_consensus_grandpa::LinkHalf<
Block, Block,
FullClient<RuntimeApi, Executor>, FullClient<RuntimeApi, Executor>,
...@@ -237,13 +238,6 @@ where ...@@ -237,13 +238,6 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>, RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Executor: sc_executor::NativeExecutionDispatch + 'static, Executor: sc_executor::NativeExecutionDispatch + 'static,
{ {
/*if config.keystore_remote.is_some() {
return Err(ServiceError::Other(
"Remote Keystores are not supported.".to_owned(),
));
}*/
// TODO deprecated ?
let telemetry = config let telemetry = config
.telemetry_endpoints .telemetry_endpoints
.clone() .clone()
...@@ -297,15 +291,8 @@ where ...@@ -297,15 +291,8 @@ where
client.clone(), client.clone(),
)?; )?;
let import_queue = if consensus_manual {
sc_consensus_manual_seal::import_queue(
Box::new(babe_block_import.clone()),
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
)
} else {
let slot_duration = babe_link.config().slot_duration(); let slot_duration = babe_link.config().slot_duration();
let (import_queue, _) = sc_consensus_babe::import_queue( let (mut import_queue, babe_worker_handle) = sc_consensus_babe::import_queue(
babe_link.clone(), babe_link.clone(),
babe_block_import.clone(), babe_block_import.clone(),
Some(Box::new(justification_import)), Some(Box::new(justification_import)),
...@@ -319,15 +306,20 @@ where ...@@ -319,15 +306,20 @@ where
*timestamp, *timestamp,
slot_duration, slot_duration,
); );
Ok((slot, timestamp)) Ok((slot, timestamp))
}, },
&task_manager.spawn_essential_handle(), &task_manager.spawn_essential_handle(),
config.prometheus_registry(), config.prometheus_registry(),
telemetry.as_ref().map(|x| x.handle()), telemetry.as_ref().map(|x| x.handle()),
)?; )?;
import_queue
}; if consensus_manual {
import_queue = sc_consensus_manual_seal::import_queue(
Box::new(babe_block_import.clone()),
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
);
}
Ok(sc_service::PartialComponents { Ok(sc_service::PartialComponents {
client, client,
...@@ -337,7 +329,13 @@ where ...@@ -337,7 +329,13 @@ where
keystore_container, keystore_container,
select_chain, select_chain,
transaction_pool, transaction_pool,
other: (babe_block_import, babe_link, grandpa_link, telemetry), other: (
babe_block_import,
babe_link,
babe_worker_handle,
grandpa_link,
telemetry,
),
}) })
} }
...@@ -363,21 +361,9 @@ where ...@@ -363,21 +361,9 @@ where
keystore_container, keystore_container,
select_chain, select_chain,
transaction_pool, transaction_pool,
other: (block_import, babe_link, grandpa_link, mut telemetry), other: (block_import, babe_link, babe_worker_handle, grandpa_link, mut telemetry),
} = new_partial::<RuntimeApi, Executor>(&config, sealing.is_manual_consensus())?; } = new_partial::<RuntimeApi, Executor>(&config, sealing.is_manual_consensus())?;
/*if let Some(url) = &config.keystore_remote {
match remote_keystore(url) {
Ok(k) => keystore_container.set_remote_keystore(k),
Err(e) => {
return Err(ServiceError::Other(format!(
"Error hooking up remote keystore for {}: {}",
url, e
)))
}
};
}*/// TODO deprecated ?
let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name( let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name(
&client &client
.block_hash(0) .block_hash(0)
...@@ -398,11 +384,9 @@ where ...@@ -398,11 +384,9 @@ where
Vec::default(), Vec::default(),
)); ));
//let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) = let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams { sc_service::build_network(sc_service::BuildNetworkParams {
config: &config, config: &config,
//net_config: net_config,
client: client.clone(), client: client.clone(),
transaction_pool: transaction_pool.clone(), transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(), spawn_handle: task_manager.spawn_handle(),
...@@ -497,7 +481,7 @@ where ...@@ -497,7 +481,7 @@ where
client: client.clone(), client: client.clone(),
pool: transaction_pool.clone(), pool: transaction_pool.clone(),
commands_stream, commands_stream,
select_chain, select_chain: select_chain.clone(),
consensus_data_provider: Some(Box::new(babe_consensus_data_provider)), consensus_data_provider: Some(Box::new(babe_consensus_data_provider)),
create_inherent_data_providers: move |_, _| { create_inherent_data_providers: move |_, _| {
let client = client_clone.clone(); let client = client_clone.clone();
...@@ -521,7 +505,7 @@ where ...@@ -521,7 +505,7 @@ where
let babe_config = sc_consensus_babe::BabeParams { let babe_config = sc_consensus_babe::BabeParams {
keystore: keystore_container.keystore(), keystore: keystore_container.keystore(),
client: client.clone(), client: client.clone(),
select_chain, select_chain: select_chain.clone(),
block_import, block_import,
env: proposer_factory, env: proposer_factory,
sync_oracle: sync_service.clone(), sync_oracle: sync_service.clone(),
...@@ -568,23 +552,22 @@ where ...@@ -568,23 +552,22 @@ where
let rpc_extensions_builder = { let rpc_extensions_builder = {
let client = client.clone(); let client = client.clone();
//let keystore = keystore_container.sync_keystore();
let pool = transaction_pool.clone(); let pool = transaction_pool.clone();
//let select_chain = select_chain.clone(); let select_chain = select_chain.clone();
//let chain_spec = config.chain_spec.cloned_box(); let chain_spec = config.chain_spec.cloned_box();
let keystore = keystore_container.keystore().clone();
Box::new(move |deny_unsafe, _| { Box::new(move |deny_unsafe, _| {
let deps = crate::rpc::FullDeps { let deps = crate::rpc::FullDeps {
client: client.clone(), client: client.clone(),
pool: pool.clone(), pool: pool.clone(),
//select_chain: select_chain.clone(), select_chain: select_chain.clone(),
//chain_spec: chain_spec.cloned_box(), chain_spec: chain_spec.cloned_box(),
deny_unsafe, deny_unsafe,
/*babe: crate::rpc::BabeDeps { babe: crate::rpc::BabeDeps {
babe_config: babe_config.clone(), babe_worker_handle: babe_worker_handle.clone(),
shared_epoch_changes: shared_epoch_changes.clone(),
keystore: keystore.clone(), keystore: keystore.clone(),
},*/ },
command_sink_opt: command_sink_opt.clone(), command_sink_opt: command_sink_opt.clone(),
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment