diff --git a/Cargo.lock b/Cargo.lock index a6078230..5f061214 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4892,7 +4892,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite 0.2.16", - "socket2 0.5.10", + "socket2 0.4.10", "tokio", "tower-service", "tracing", @@ -8598,7 +8598,7 @@ checksum = "4e69bf016dc406eff7d53a7d3f7cf1c2e72c82b9088aac1118591e36dd2cd3e9" dependencies = [ "bitcoin_hashes 0.13.0", "rand 0.8.5", - "rand_core 0.6.4", + "rand_core 0.5.1", "serde", "unicode-normalization", ] @@ -8921,6 +8921,7 @@ dependencies = [ "sc-client-api 28.0.0", "sc-consensus 0.33.0", "sc-consensus-babe", + "sc-consensus-babe-rpc", "sc-consensus-grandpa", "sc-consensus-grandpa-rpc", "sc-executor 0.32.0", @@ -8934,12 +8935,14 @@ dependencies = [ "sp-api 26.0.0", "sp-block-builder 26.0.0", "sp-blockchain 28.0.0", + "sp-consensus 0.32.0", "sp-consensus-babe 0.32.0", "sp-core 28.0.0", "sp-genesis-builder 0.8.0", "sp-inherents 26.0.0", "sp-io 30.0.0", "sp-keyring 31.0.0", + "sp-keystore 0.34.0", "sp-runtime 31.0.1", "sp-timestamp 26.0.0", "sp-transaction-storage-proof 26.0.0", @@ -11356,6 +11359,28 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "sc-consensus-babe-rpc" +version = "0.34.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?rev=a64eb1fb02d4012948cba024fca2f27d94732e52#a64eb1fb02d4012948cba024fca2f27d94732e52" +dependencies = [ + "futures", + "jsonrpsee 0.24.7", + "sc-consensus-babe", + "sc-consensus-epochs", + "sc-rpc-api 0.33.0", + "serde", + "sp-api 26.0.0", + "sp-application-crypto 30.0.0", + "sp-blockchain 28.0.0", + "sp-consensus 0.32.0", + "sp-consensus-babe 0.32.0", + "sp-core 28.0.0", + "sp-keystore 0.34.0", + "sp-runtime 31.0.1", + "thiserror 1.0.69", +] + [[package]] name = "sc-consensus-epochs" version = "0.33.0" diff --git a/Cargo.toml b/Cargo.toml index 5940f433..606063b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ sc-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1 sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52" } sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52" } sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52" } +sc-consensus-babe-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52" } sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52" } sc-consensus-grandpa-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52" } sc-executor = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52" } @@ -58,6 +59,7 @@ sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk.gi sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } +sp-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } @@ -65,6 +67,7 @@ sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", r sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } +sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-offchain = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } sp-session = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "a64eb1fb02d4012948cba024fca2f27d94732e52", default-features = false } @@ -136,4 +139,4 @@ panic = "unwind" [profile.production] inherits = "release" lto = true -codegen-units = 1 \ No newline at end of file +codegen-units = 1 diff --git a/node/Cargo.toml b/node/Cargo.toml index 7079f31b..b7682a00 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -25,6 +25,7 @@ sc-cli = { workspace = true } sc-client-api = { workspace = true } sc-consensus = { workspace = true } sc-consensus-babe = { workspace = true } +sc-consensus-babe-rpc = { workspace = true } sc-consensus-grandpa = { workspace = true } sc-consensus-grandpa-rpc = { workspace = true } sc-executor = { workspace = true } @@ -35,11 +36,13 @@ sc-service = { workspace = true } sc-telemetry = { workspace = true } sc-transaction-pool = { workspace = true } sc-transaction-pool-api = { workspace = true } +sp-consensus = { workspace = true } sp-consensus-babe = { workspace = true } sp-core = { workspace = true } sp-inherents = { workspace = true } sp-io = { workspace = true } sp-keyring = { workspace = true } +sp-keystore = { workspace = true } sp-runtime = { workspace = true } sp-timestamp = { workspace = true } sp-transaction-storage-proof = { workspace = true } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index b2d30722..cef00ea8 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -9,6 +9,7 @@ use std::sync::Arc; use jsonrpsee::RpcModule; use polkadot_bulletin_chain_runtime::{opaque::Block, AccountId, BlockNumber, Hash, Nonce}; +use sc_consensus_babe::{BabeApi, BabeWorkerHandle}; use sc_consensus_grandpa::{ FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState, }; @@ -18,17 +19,31 @@ use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; +use sp_consensus::SelectChain; +use sp_keystore::KeystorePtr; /// Full client dependencies. -pub struct FullDeps { +pub struct FullDeps { /// The client instance to use. pub client: Arc, /// Transaction pool instance. pub pool: Arc

, + /// The chain selection strategy. + pub select_chain: SC, + /// BABE RPC dependencies. + pub babe: BabeDeps, /// GRANDPA RPC dependencies. pub grandpa: GrandpaDeps, } +/// BABE RPC dependencies. +pub struct BabeDeps { + /// A handle to the BABE worker for issuing requests. + pub babe_worker_handle: BabeWorkerHandle, + /// The keystore that manages the keys of the node. + pub keystore: KeystorePtr, +} + /// GRANDPA RPC dependncies. pub struct GrandpaDeps { /// Subscription task executor. @@ -44,8 +59,8 @@ pub struct GrandpaDeps { } /// Instantiate all full RPC extensions. -pub fn create_full( - deps: FullDeps, +pub fn create_full( + deps: FullDeps, ) -> Result, Box> where C: ProvideRuntimeApi, @@ -53,15 +68,21 @@ where C: Send + Sync + 'static, C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: BlockBuilder, + C::Api: BabeApi, P: TransactionPool + 'static, + SC: SelectChain + 'static, B: sc_client_api::Backend + Send + Sync + 'static, { + use sc_consensus_babe_rpc::{Babe, BabeApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer}; let mut module = RpcModule::new(()); - let FullDeps { client, pool, grandpa } = deps; + let FullDeps { client, pool, select_chain, babe, grandpa } = deps; + let BabeDeps { babe_worker_handle, keystore } = babe; - module.merge(System::new(client, pool).into_rpc())?; + module.merge(System::new(client.clone(), pool).into_rpc())?; + module + .merge(Babe::new(client, babe_worker_handle.clone(), keystore, select_chain).into_rpc())?; module.merge( Grandpa::new( grandpa.subscription_executor, diff --git a/node/src/service.rs b/node/src/service.rs index f2328de8..0406414e 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -45,6 +45,7 @@ pub fn new_partial( >, sc_consensus_grandpa::LinkHalf, sc_consensus_babe::BabeLink, + sc_consensus_babe::BabeWorkerHandle, Option, ), >, @@ -128,9 +129,6 @@ pub fn new_partial( telemetry: telemetry.as_ref().map(|x| x.handle()), })?; - // TODO Wire up to RPC - std::mem::forget(babe_worker_handle); - Ok(sc_service::PartialComponents { client, backend, @@ -139,7 +137,7 @@ pub fn new_partial( keystore_container, select_chain, transaction_pool, - other: (block_import, grandpa_link, babe_link, telemetry), + other: (block_import, grandpa_link, babe_link, babe_worker_handle, telemetry), }) } @@ -157,7 +155,7 @@ pub fn new_full< keystore_container, select_chain, transaction_pool, - other: (block_import, grandpa_link, babe_link, mut telemetry), + other: (block_import, grandpa_link, babe_link, babe_worker_handle, mut telemetry), } = new_partial(&config)?; let mut net_config = sc_network::config::FullNetworkConfiguration::<_, _, N>::new( @@ -226,6 +224,8 @@ pub fn new_full< let rpc_extensions_builder = { let client = client.clone(); let pool = transaction_pool.clone(); + let keystore = keystore_container.keystore(); + let select_chain = select_chain.clone(); let justification_stream = grandpa_link.justification_stream(); let shared_authority_set = grandpa_link.shared_authority_set().clone(); @@ -240,6 +240,11 @@ pub fn new_full< let deps = crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), + select_chain: select_chain.clone(), + babe: crate::rpc::BabeDeps { + babe_worker_handle: babe_worker_handle.clone(), + keystore: keystore.clone(), + }, grandpa: crate::rpc::GrandpaDeps { subscription_executor, shared_authority_set: shared_authority_set.clone(),