From 35eb66d9e5ac60973bc2f0c12d5c675cfc2e43f8 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Wed, 23 Oct 2024 16:31:03 +0200
Subject: [PATCH] wip sketch endpoint gossip service
---
node/src/cli.rs | 17 +++++++++++++++++
node/src/command.rs | 4 +++-
node/src/service.rs | 23 +++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/node/src/cli.rs b/node/src/cli.rs
index a494a8727..647845b5f 100644
--- a/node/src/cli.rs
+++ b/node/src/cli.rs
@@ -19,9 +19,14 @@ pub struct Cli {
#[clap(subcommand)]
pub subcommand: Option<Subcommand>,
+ /// substrate base options
#[clap(flatten)]
pub run: sc_cli::RunCmd,
+ /// duniter specific options
+ #[clap(flatten)]
+ pub duniter_options: DuniterConfigExtension,
+
/// How blocks should be sealed
///
/// Options are "production", "instant", "manual", or timer interval in milliseconds
@@ -29,6 +34,18 @@ pub struct Cli {
pub sealing: crate::cli::Sealing,
}
+/// add options specific to duniter client
+#[derive(Debug, Clone, clap::Parser)]
+pub struct DuniterConfigExtension {
+ /// Public RPC endpoint to gossip on the network and make available in the apps.
+ #[arg(long)]
+ pub public_rpc: Option<String>,
+
+ /// Public Squid graphql endpoint to gossip on the network and make available in the apps.
+ #[arg(long)]
+ pub public_squid: Option<String>,
+}
+
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
/// Build a chain specification.
diff --git a/node/src/command.rs b/node/src/command.rs
index 29af19445..9bac52396 100644
--- a/node/src/command.rs
+++ b/node/src/command.rs
@@ -364,6 +364,8 @@ pub fn run() -> sc_cli::Result<()> {
}
None => {
let runner = cli.create_runner(&cli.run)?;
+ // TODO add endpoint config here
+ let config_extension: DuniterConfigExtension = ();
runner.run_node_until_exit(|mut config| async move {
// Force offchain worker and offchain indexing if we have the role Authority
if config.role.is_authority() {
@@ -376,7 +378,7 @@ pub fn run() -> sc_cli::Result<()> {
service::runtime_executor::runtime::RuntimeApi,
Executor,
sc_network::Litep2pNetworkBackend,
- >(config, cli.sealing)
+ >(config, cli.sealing, config_extension)
.map_err(sc_cli::Error::Service)
}
})
diff --git a/node/src/service.rs b/node/src/service.rs
index 894644308..48b2c255c 100644
--- a/node/src/service.rs
+++ b/node/src/service.rs
@@ -147,6 +147,7 @@ type FullGrandpaBlockImport<RuntimeApi, Executor> = sc_consensus_grandpa::Grandp
pub fn new_partial<RuntimeApi, Executor>(
config: &Configuration,
consensus_manual: bool,
+ config_extension: DuniterConfigExtension,
) -> Result<
sc_service::PartialComponents<
FullClient<RuntimeApi, Executor>,
@@ -348,6 +349,28 @@ where
);
net_config.add_notification_protocol(grandpa_protocol_config);
+ // endpoint gossip
+ // only active for non-authority (to save workload)
+ if !role.is_authority() {
+ // configure protocol
+ let (endpoint_gossip_protocol_config, endpoint_gossip_notification_service) = ((), ());
+ net_config.add_notification_protocol(endpoint_gossip_protocol_config);
+ let endpoint_gossip_config = ();
+ let endpoint_gossip_params = EndpointGossipParams {
+ config: endpoint_gossip_config,
+ network,
+ notification_service: endpoint_gossip_notification_service,
+ // offchain storage
+ offchain_endpoint_tester: (),
+ };
+ // spawn task
+ task_manager.spawn_handle().spawn(
+ "endpoint-gossip",
+ None,
+ run_gossip_worker(endpoint_gossip_params)?,
+ );
+ }
+
let warp_sync = Arc::new(sc_consensus_grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
grandpa_link.shared_authority_set().clone(),
--
GitLab