Skip to content
Snippets Groups Projects
Commit b27ee1da authored by bgallois's avatar bgallois Committed by Hugo Trentesaux
Browse files

add grandpa rpc

parent 7fe42a23
No related branches found
No related tags found
1 merge request!279Fix #250
Pipeline #38062 passed
...@@ -429,13 +429,13 @@ dependencies = [ ...@@ -429,13 +429,13 @@ dependencies = [
[[package]] [[package]]
name = "ark-secret-scalar" name = "ark-secret-scalar"
version = "0.0.2" version = "0.0.2"
source = "git+https://github.com/duniter/ring-vrf#06b60fdb7308c127448ef5799414c45516f6c42b" source = "git+https://github.com/duniter/ring-vrf#27a6b9f6aa0c576bc481947dd5e4f3beff0fe327"
dependencies = [ dependencies = [
"ark-ec", "ark-ec",
"ark-ff", "ark-ff",
"ark-serialize", "ark-serialize",
"ark-std", "ark-std",
"ark-transcript", "ark-transcript 0.0.2 (git+https://github.com/duniter/ring-vrf)",
"digest 0.10.7", "digest 0.10.7",
"getrandom_or_panic", "getrandom_or_panic",
"zeroize", "zeroize",
...@@ -478,7 +478,20 @@ dependencies = [ ...@@ -478,7 +478,20 @@ dependencies = [
[[package]] [[package]]
name = "ark-transcript" name = "ark-transcript"
version = "0.0.2" version = "0.0.2"
source = "git+https://github.com/duniter/ring-vrf#06b60fdb7308c127448ef5799414c45516f6c42b" source = "git+https://github.com/duniter/ring-vrf#27a6b9f6aa0c576bc481947dd5e4f3beff0fe327"
dependencies = [
"ark-ff",
"ark-serialize",
"ark-std",
"digest 0.10.7",
"rand_core",
"sha3",
]
[[package]]
name = "ark-transcript"
version = "0.0.2"
source = "git+https://github.com/w3f/ring-vrf#0fef8266d851932ad25d6b41bc4b34d834d1e11d"
dependencies = [ dependencies = [
"ark-ff", "ark-ff",
"ark-serialize", "ark-serialize",
...@@ -808,7 +821,7 @@ dependencies = [ ...@@ -808,7 +821,7 @@ dependencies = [
[[package]] [[package]]
name = "bandersnatch_vrfs" name = "bandersnatch_vrfs"
version = "0.0.4" version = "0.0.4"
source = "git+https://github.com/duniter/ring-vrf#06b60fdb7308c127448ef5799414c45516f6c42b" source = "git+https://github.com/duniter/ring-vrf#27a6b9f6aa0c576bc481947dd5e4f3beff0fe327"
dependencies = [ dependencies = [
"ark-bls12-381", "ark-bls12-381",
"ark-ec", "ark-ec",
...@@ -1487,7 +1500,7 @@ dependencies = [ ...@@ -1487,7 +1500,7 @@ dependencies = [
[[package]] [[package]]
name = "common" name = "common"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/w3f/ring-proof#b273d33f9981e2bb3375ab45faeb537f7ee35224" source = "git+https://github.com/w3f/ring-proof#1472ce9cd87cee49c56ce7869a0aba872d837c51"
dependencies = [ dependencies = [
"ark-ec", "ark-ec",
"ark-ff", "ark-ff",
...@@ -1496,8 +1509,7 @@ dependencies = [ ...@@ -1496,8 +1509,7 @@ dependencies = [
"ark-std", "ark-std",
"fflonk", "fflonk",
"getrandom_or_panic", "getrandom_or_panic",
"merlin", "rand_core",
"rand_chacha",
] ]
[[package]] [[package]]
...@@ -2401,7 +2413,7 @@ dependencies = [ ...@@ -2401,7 +2413,7 @@ dependencies = [
[[package]] [[package]]
name = "dleq_vrf" name = "dleq_vrf"
version = "0.0.2" version = "0.0.2"
source = "git+https://github.com/duniter/ring-vrf#06b60fdb7308c127448ef5799414c45516f6c42b" source = "git+https://github.com/duniter/ring-vrf#27a6b9f6aa0c576bc481947dd5e4f3beff0fe327"
dependencies = [ dependencies = [
"ark-ec", "ark-ec",
"ark-ff", "ark-ff",
...@@ -2409,7 +2421,7 @@ dependencies = [ ...@@ -2409,7 +2421,7 @@ dependencies = [
"ark-secret-scalar", "ark-secret-scalar",
"ark-serialize", "ark-serialize",
"ark-std", "ark-std",
"ark-transcript", "ark-transcript 0.0.2 (git+https://github.com/duniter/ring-vrf)",
"arrayvec 0.7.4", "arrayvec 0.7.4",
"zeroize", "zeroize",
] ]
...@@ -2516,11 +2528,13 @@ dependencies = [ ...@@ -2516,11 +2528,13 @@ dependencies = [
"sc-consensus-babe", "sc-consensus-babe",
"sc-consensus-babe-rpc", "sc-consensus-babe-rpc",
"sc-consensus-grandpa", "sc-consensus-grandpa",
"sc-consensus-grandpa-rpc",
"sc-consensus-manual-seal", "sc-consensus-manual-seal",
"sc-executor", "sc-executor",
"sc-keystore", "sc-keystore",
"sc-network", "sc-network",
"sc-offchain", "sc-offchain",
"sc-rpc",
"sc-rpc-api", "sc-rpc-api",
"sc-service", "sc-service",
"sc-telemetry", "sc-telemetry",
...@@ -4334,14 +4348,14 @@ checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" ...@@ -4334,14 +4348,14 @@ checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"http 1.1.0", "http 1.1.0",
"hyper 1.4.0", "hyper 1.3.1",
"hyper-util", "hyper-util",
"rustls 0.23.10", "rustls 0.23.10",
"rustls-pki-types", "rustls-pki-types",
"tokio", "tokio",
"tokio-rustls 0.26.0", "tokio-rustls 0.26.0",
"tower-service", "tower-service",
"webpki-roots 0.26.3", "webpki-roots 0.26.5",
] ]
[[package]] [[package]]
...@@ -8175,7 +8189,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -8175,7 +8189,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684"
dependencies = [ dependencies = [
"bytes", "bytes",
"pin-project-lite 0.2.14", "pin-project-lite",
"quinn-proto 0.11.8", "quinn-proto 0.11.8",
"quinn-udp 0.5.4", "quinn-udp 0.5.4",
"rustc-hash 2.0.0", "rustc-hash 2.0.0",
...@@ -8550,7 +8564,7 @@ dependencies = [ ...@@ -8550,7 +8564,7 @@ dependencies = [
"http 1.1.0", "http 1.1.0",
"http-body 1.0.0", "http-body 1.0.0",
"http-body-util", "http-body-util",
"hyper 1.4.0", "hyper 1.3.1",
"hyper-rustls 0.27.3", "hyper-rustls 0.27.3",
"hyper-util", "hyper-util",
"ipnet", "ipnet",
...@@ -8559,7 +8573,7 @@ dependencies = [ ...@@ -8559,7 +8573,7 @@ dependencies = [
"mime", "mime",
"once_cell", "once_cell",
"percent-encoding", "percent-encoding",
"pin-project-lite 0.2.14", "pin-project-lite",
"quinn 0.11.5", "quinn 0.11.5",
"rustls 0.23.10", "rustls 0.23.10",
"rustls-pemfile 2.1.2", "rustls-pemfile 2.1.2",
...@@ -8575,7 +8589,7 @@ dependencies = [ ...@@ -8575,7 +8589,7 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"web-sys", "web-sys",
"webpki-roots 0.26.3", "webpki-roots 0.26.5",
"winreg 0.52.0", "winreg 0.52.0",
] ]
...@@ -8602,17 +8616,18 @@ dependencies = [ ...@@ -8602,17 +8616,18 @@ dependencies = [
[[package]] [[package]]
name = "ring" name = "ring"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/w3f/ring-proof#b273d33f9981e2bb3375ab45faeb537f7ee35224" source = "git+https://github.com/w3f/ring-proof#1472ce9cd87cee49c56ce7869a0aba872d837c51"
dependencies = [ dependencies = [
"ark-ec", "ark-ec",
"ark-ff", "ark-ff",
"ark-poly", "ark-poly",
"ark-serialize", "ark-serialize",
"ark-std", "ark-std",
"ark-transcript 0.0.2 (git+https://github.com/w3f/ring-vrf)",
"arrayvec 0.7.4",
"blake2 0.10.6", "blake2 0.10.6",
"common", "common",
"fflonk", "fflonk",
"merlin",
] ]
[[package]] [[package]]
...@@ -9316,6 +9331,26 @@ dependencies = [ ...@@ -9316,6 +9331,26 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "sc-consensus-grandpa-rpc"
version = "0.19.0"
source = "git+https://github.com/duniter/duniter-polkadot-sdk?branch=duniter-substrate-v1.14.0#bcc60f3e4170c3908689252242f40761270c9a51"
dependencies = [
"finality-grandpa",
"futures 0.3.30",
"jsonrpsee 0.23.2",
"log",
"parity-scale-codec",
"sc-client-api",
"sc-consensus-grandpa",
"sc-rpc",
"serde",
"sp-blockchain",
"sp-core",
"sp-runtime",
"thiserror",
]
[[package]] [[package]]
name = "sc-consensus-manual-seal" name = "sc-consensus-manual-seal"
version = "0.35.0" version = "0.35.0"
......
...@@ -169,6 +169,8 @@ sp-block-builder = { git = 'https://github.com/duniter/duniter-polkadot-sdk', br ...@@ -169,6 +169,8 @@ sp-block-builder = { git = 'https://github.com/duniter/duniter-polkadot-sdk', br
sc-client-db = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false } sc-client-db = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
sc-client-api = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false } sc-client-api = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
sc-consensus-grandpa = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false } sc-consensus-grandpa = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
sc-rpc = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
sc-consensus-grandpa-rpc = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
sc-consensus-babe = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false } sc-consensus-babe = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
sc-consensus-babe-rpc = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false } sc-consensus-babe-rpc = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
sp-blockchain = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false } sp-blockchain = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.14.0', default-features = false }
......
...@@ -139,9 +139,11 @@ sc-chain-spec = { workspace = true, default-features = true } ...@@ -139,9 +139,11 @@ sc-chain-spec = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true } sc-client-api = { workspace = true, default-features = true }
sc-client-db = { workspace = true, default-features = true } sc-client-db = { workspace = true, default-features = true }
sc-consensus = { workspace = true, default-features = true } sc-consensus = { workspace = true, default-features = true }
sc-rpc = { workspace = true, default-features = true }
sc-consensus-babe = { workspace = true, default-features = true } sc-consensus-babe = { workspace = true, default-features = true }
sc-consensus-babe-rpc = { workspace = true, default-features = true } sc-consensus-babe-rpc = { workspace = true, default-features = true }
sc-consensus-grandpa = { workspace = true, default-features = true } sc-consensus-grandpa = { workspace = true, default-features = true }
sc-consensus-grandpa-rpc = { workspace = true, default-features = true }
sc-consensus-manual-seal = { workspace = true, default-features = true } sc-consensus-manual-seal = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true } sc-executor = { workspace = true, default-features = true }
sc-keystore = { workspace = true, default-features = true } sc-keystore = { workspace = true, default-features = true }
......
...@@ -23,9 +23,13 @@ ...@@ -23,9 +23,13 @@
pub use sc_rpc_api::DenyUnsafe; pub use sc_rpc_api::DenyUnsafe;
use common_runtime::{AccountId, Balance, Block, Index}; use common_runtime::{AccountId, Balance, Block, BlockNumber, Hash, Index};
use jsonrpsee::RpcModule; use jsonrpsee::RpcModule;
use sc_consensus_babe::{BabeApi, BabeWorkerHandle}; use sc_consensus_babe::{BabeApi, BabeWorkerHandle};
use sc_consensus_grandpa::{
self, FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
};
use sc_rpc::SubscriptionTaskExecutor;
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;
...@@ -43,8 +47,23 @@ pub struct BabeDeps { ...@@ -43,8 +47,23 @@ pub struct BabeDeps {
pub keystore: KeystorePtr, pub keystore: KeystorePtr,
} }
/// Dependencies for GRANDPA
#[derive(Clone)]
pub struct GrandpaDeps<B> {
/// Voting round info.
pub shared_voter_state: SharedVoterState,
/// Authority set info.
pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,
/// Receives notifications about justification events from Grandpa.
pub justification_stream: GrandpaJustificationStream<Block>,
/// Executor to drive the subscription manager in the Grandpa RPC handler.
pub subscription_executor: SubscriptionTaskExecutor,
/// Finality proof provider.
pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
}
/// Full client dependencies. /// Full client dependencies.
pub struct FullDeps<C, P, SC> { pub struct FullDeps<C, P, SC, B> {
/// The client instance to use. /// The client instance to use.
pub client: Arc<C>, pub client: Arc<C>,
/// Transaction pool instance. /// Transaction pool instance.
...@@ -59,11 +78,13 @@ pub struct FullDeps<C, P, SC> { ...@@ -59,11 +78,13 @@ pub struct FullDeps<C, P, SC> {
>, >,
/// BABE specific dependencies. /// BABE specific dependencies.
pub babe: Option<BabeDeps>, pub babe: Option<BabeDeps>,
/// GRANDPA specific dependencies.
pub grandpa: GrandpaDeps<B>,
} }
/// Instantiate all full RPC extensions. /// Instantiate all full RPC extensions.
pub fn create_full<C, P, SC>( pub fn create_full<C, P, SC, B>(
deps: FullDeps<C, P, SC>, deps: FullDeps<C, P, SC, B>,
) -> 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>,
...@@ -75,9 +96,11 @@ where ...@@ -75,9 +96,11 @@ where
C::Api: BlockBuilder<Block>, C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static, P: TransactionPool + 'static,
SC: SelectChain<Block> + 'static, SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<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_babe_rpc::{Babe, BabeApiServer};
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};
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};
...@@ -89,6 +112,7 @@ where ...@@ -89,6 +112,7 @@ where
deny_unsafe, deny_unsafe,
command_sink_opt, command_sink_opt,
babe, babe,
grandpa,
} = deps; } = deps;
if let Some(babe) = babe { if let Some(babe) = babe {
...@@ -107,6 +131,25 @@ where ...@@ -107,6 +131,25 @@ where
.into_rpc(), .into_rpc(),
)?; )?;
} }
let GrandpaDeps {
shared_voter_state,
shared_authority_set,
justification_stream,
subscription_executor,
finality_provider,
} = grandpa;
module.merge(
Grandpa::new(
subscription_executor,
shared_authority_set,
shared_voter_state,
justification_stream,
finality_provider,
)
.into_rpc(),
)?;
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client).into_rpc())?; module.merge(TransactionPayment::new(client).into_rpc())?;
if let Some(command_sink) = command_sink_opt { if let Some(command_sink) = command_sink_opt {
......
...@@ -23,8 +23,9 @@ use async_io::Timer; ...@@ -23,8 +23,9 @@ use async_io::Timer;
use common_runtime::Block; use common_runtime::Block;
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
use sc_client_api::{client::BlockBackend, Backend}; use sc_client_api::{client::BlockBackend, Backend};
use sc_consensus_grandpa::SharedVoterState; use sc_consensus_grandpa::{FinalityProofProvider, SharedVoterState};
use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams}; use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};
use sc_rpc::SubscriptionTaskExecutor;
use sc_service::{ use sc_service::{
error::Error as ServiceError, Configuration, PartialComponents, TaskManager, WarpSyncParams, error::Error as ServiceError, Configuration, PartialComponents, TaskManager, WarpSyncParams,
}; };
...@@ -572,6 +573,12 @@ where ...@@ -572,6 +573,12 @@ where
} }
} }
let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
let shared_voter_state = SharedVoterState::empty();
let finality_proof_provider =
FinalityProofProvider::new_for_service(backend.clone(), Some(shared_authority_set.clone()));
let rpc_extensions_builder = { let rpc_extensions_builder = {
let client = client.clone(); let client = client.clone();
let pool = transaction_pool.clone(); let pool = transaction_pool.clone();
...@@ -581,19 +588,31 @@ where ...@@ -581,19 +588,31 @@ where
babe_worker_handle, babe_worker_handle,
keystore: keystore.clone(), keystore: keystore.clone(),
}); });
let rpc_setup = shared_voter_state.clone();
Box::new(
move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {
let grandpa_deps = crate::rpc::GrandpaDeps {
shared_voter_state: rpc_setup.clone(),
shared_authority_set: shared_authority_set.clone(),
justification_stream: justification_stream.clone(),
subscription_executor: subscription_task_executor.clone(),
finality_provider: finality_proof_provider.clone(),
};
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(), deny_unsafe,
deny_unsafe, babe: babe_deps.clone(),
babe: babe_deps.clone(), grandpa: grandpa_deps,
command_sink_opt: command_sink_opt.clone(), command_sink_opt: command_sink_opt.clone(),
}; };
crate::rpc::create_full(deps).map_err(Into::into) crate::rpc::create_full(deps).map_err(Into::into)
}) },
)
}; };
let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
...@@ -644,7 +663,7 @@ where ...@@ -644,7 +663,7 @@ where
network, network,
voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(), voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry, prometheus_registry,
shared_voter_state: SharedVoterState::empty(), shared_voter_state,
telemetry: telemetry.as_ref().map(|x| x.handle()), telemetry: telemetry.as_ref().map(|x| x.handle()),
notification_service: grandpa_notification_service, notification_service: grandpa_notification_service,
offchain_tx_pool_factory: sc_transaction_pool_api::OffchainTransactionPoolFactory::new( offchain_tx_pool_factory: sc_transaction_pool_api::OffchainTransactionPoolFactory::new(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment