Skip to content

Commit

Permalink
Add prometheus params to run cmd and make substrate full sync work (#30)
Browse files Browse the repository at this point in the history
* Add prometheus config to run cmd and start substrate network

* Sync seednode list from Bitcoin Core

* Update openssl dep

* Make Substrate full sync work

* Restore the default --blocks-pruning

* Fix clippy
  • Loading branch information
liuchengxu authored Aug 3, 2024
1 parent e6379c5 commit 1758327
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 160 deletions.
203 changes: 105 additions & 98 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ sc-informant = { git = "https://github.com/subcoin-project/polkadot-sdk", branch
sc-network = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }
sc-network-sync = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }
sc-rpc = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }
sc-rpc-api = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }
# Disable the default `rocksdb` feature
sc-service = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1", default-features = false }
sc-storage-monitor = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }
Expand Down Expand Up @@ -102,6 +103,7 @@ sp-trie = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "s
sp-version = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1", default-features = false }
substrate-build-script-utils = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }
substrate-frame-rpc-system = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }
substrate-prometheus-endpoint = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1", default-features = false }
substrate-wasm-builder = { git = "https://github.com/subcoin-project/polkadot-sdk", branch = "subcoin-v1" }

pallet-bitcoin = { path = "crates/pallet-bitcoin", default-features = false }
Expand Down
26 changes: 13 additions & 13 deletions crates/subcoin-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,25 @@ fn seednodes(network: BitcoinNetwork) -> Vec<&'static str> {
match network {
BitcoinNetwork::Bitcoin => {
vec![
"seed.bitcoin.sipa.be:8333", // Pieter Wuille
"dnsseed.bluematt.me:8333", // Matt Corallo
"dnsseed.bitcoin.dashjr.org:8333", // Luke Dashjr
"seed.bitcoinstats.com:8333", // Christian Decker
"seed.bitcoin.jonasschnelli.ch:8333", // Jonas Schnelli
"seed.btc.petertodd.org:8333", // Peter Todd
"seed.bitcoin.sprovoost.nl:8333", // Sjors Provoost
"dnsseed.emzy.de:8333", // Stephan Oeste
"seed.bitcoin.wiz.biz:8333", // Jason Maurice
"seed.cloudhead.io:8333", // Alexis Sellier
"seed.bitcoin.sipa.be:8333", // Pieter Wuille
"dnsseed.bluematt.me:8333", // Matt Corallo
"dnsseed.bitcoin.dashjr-list-of-p2p-nodes.us:8333", // Luke Dashjr
"seed.bitcoinstats.com:8333", // Christian Decker
"seed.bitcoin.jonasschnelli.ch:8333", // Jonas Schnelli
"seed.btc.petertodd.net:8333", // Peter Todd
"seed.bitcoin.sprovoost.nl:8333", // Sjors Provoost
"dnsseed.emzy.de:8333", // Stephan Oeste
"seed.bitcoin.wiz.biz:8333", // Jason Maurice
"seed.mainnet.achownodes.xyz:8333", // Ava Chow
]
}
BitcoinNetwork::Testnet => {
vec![
"testnet-seed.bitcoin.jonasschnelli.ch:18333",
"seed.tbtc.petertodd.org:18333",
"seed.tbtc.petertodd.net:18333",
"seed.testnet.bitcoin.sprovoost.nl:18333",
"testnet-seed.bluematt.me:18333",
"testnet-seed.bitcoin.schildbach.de:18333",
"testnet-seed.voskuil.org:18333",
"testnet-seed.achownodes.xyz:18333",
]
}
_ => Vec::new(),
Expand Down
4 changes: 2 additions & 2 deletions crates/subcoin-node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use subcoin_primitives::CONFIRMATION_DEPTH;
#[derive(Debug, clap::Subcommand)]
pub enum Command {
/// Run subcoin node.
Run(Run),
Run(Box<Run>),

/// Import blocks from bitcoind database.
ImportBlocks(ImportBlocks),
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn run() -> sc_cli::Result<()> {
let runner = SubstrateCli.create_runner(&run_cmd)?;
runner.run_node_until_exit(|config| async move {
run_cmd
.start(config, run, no_hardware_benchmarks, storage_monitor)
.start(config, *run, no_hardware_benchmarks, storage_monitor)
.await
})
}
Expand Down
95 changes: 79 additions & 16 deletions crates/subcoin-node/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::cli::params::{CommonParams, NetworkParams};
use clap::Parser;
use sc_cli::{DatabasePruningMode, ImportParams, NodeKeyParams, PruningParams, Role, SharedParams};
use sc_cli::{
DatabasePruningMode, ImportParams, NetworkParams as SubstrateNetworkParams, NodeKeyParams,
PrometheusParams, PruningParams, Role, SharedParams,
};
use sc_client_api::UsageProvider;
use sc_consensus_nakamoto::{BitcoinBlockImporter, BlockVerification, ImportConfig};
use sc_service::{BlocksPruning, Configuration, TaskManager};
use sc_service::{Configuration, TaskManager};
use std::sync::Arc;
use subcoin_network::SyncStrategy;
use subcoin_primitives::CONFIRMATION_DEPTH;
Expand All @@ -30,6 +33,14 @@ pub struct Run {
#[clap(long)]
pub no_finalizer: bool,

/// Disable the Bitcoin networking.
#[clap(long)]
pub disable_subcoin_networking: bool,

#[allow(missing_docs)]
#[clap(flatten)]
pub prometheus_params: PrometheusParams,

#[allow(missing_docs)]
#[clap(flatten)]
pub common_params: CommonParams,
Expand All @@ -38,6 +49,10 @@ pub struct Run {
#[clap(flatten)]
pub network_params: NetworkParams,

#[allow(missing_docs)]
#[clap(flatten)]
pub substrate_network_params: SubstrateNetworkParams,

#[allow(missing_docs)]
#[clap(flatten)]
pub import_params: ImportParams,
Expand All @@ -63,6 +78,8 @@ pub struct RunCmd {
shared_params: SharedParams,
pruning_params: PruningParams,
import_params: ImportParams,
prometheus_params: PrometheusParams,
substrate_network_params: SubstrateNetworkParams,
}

impl RunCmd {
Expand All @@ -75,7 +92,9 @@ impl RunCmd {
Self {
shared_params,
pruning_params,
prometheus_params: run.prometheus_params.clone(),
import_params: run.import_params.clone(),
substrate_network_params: run.substrate_network_params.clone(),
}
}

Expand All @@ -95,9 +114,12 @@ impl RunCmd {

let subcoin_service::NodeComponents {
client,
backend,
mut task_manager,
block_executor,
system_rpc_tx,
keystore_container,
telemetry,
..
} = subcoin_service::new_node(subcoin_service::SubcoinConfiguration {
network,
Expand Down Expand Up @@ -140,15 +162,19 @@ impl RunCmd {
);

// TODO: handle Substrate networking and Bitcoin networking properly.
task_manager.spawn_essential_handle().spawn_blocking(
"subcoin-networking",
None,
async move {
if let Err(err) = bitcoin_network.run().await {
tracing::error!(?err, "Subcoin network worker exited");
}
},
);
if !run.disable_subcoin_networking {
task_manager.spawn_essential_handle().spawn_blocking(
"subcoin-networking",
None,
async move {
if let Err(err) = bitcoin_network.run().await {
tracing::error!(?err, "Subcoin network worker exited");
}
},
);
} else {
task_manager.keep_alive(bitcoin_network);
}

// TODO: Bitcoin-compatible RPC
// Start JSON-RPC server.
Expand All @@ -173,7 +199,35 @@ impl RunCmd {
};

let rpc = sc_service::start_rpc_servers(&config, gen_rpc_module, None)?;
task_manager.keep_alive((config.base_path, rpc));
task_manager.keep_alive((config.base_path.clone(), rpc));

match config.network.network_backend {
sc_network::config::NetworkBackendType::Libp2p => {
subcoin_service::start_substrate_network::<
sc_network::NetworkWorker<
subcoin_runtime::interface::OpaqueBlock,
<subcoin_runtime::interface::OpaqueBlock as sp_runtime::traits::Block>::Hash,
>,
>(
config,
client.clone(),
backend,
&mut task_manager,
keystore_container.keystore(),
telemetry,
)?;
}
sc_network::config::NetworkBackendType::Litep2p => {
subcoin_service::start_substrate_network::<sc_network::Litep2pNetworkBackend>(
config,
client.clone(),
backend,
&mut task_manager,
keystore_container.keystore(),
telemetry,
)?;
}
}

if !no_finalizer {
spawn_handle.spawn("finalizer", None, {
Expand Down Expand Up @@ -212,15 +266,24 @@ impl sc_cli::CliConfiguration for RunCmd {
}

fn node_key_params(&self) -> Option<&NodeKeyParams> {
None
Some(&self.substrate_network_params.node_key_params)
}

fn role(&self, _is_dev: bool) -> sc_cli::Result<Role> {
Ok(Role::Full)
}

fn blocks_pruning(&self) -> sc_cli::Result<BlocksPruning> {
// TODO: configurable blocks pruning
Ok(BlocksPruning::KeepAll)
fn network_params(&self) -> Option<&SubstrateNetworkParams> {
Some(&self.substrate_network_params)
}

fn prometheus_config(
&self,
default_listen_port: u16,
chain_spec: &Box<dyn sc_service::ChainSpec>,
) -> sc_cli::Result<Option<sc_service::config::PrometheusConfig>> {
Ok(self
.prometheus_params
.prometheus_config(default_listen_port, chain_spec.id().to_string()))
}
}
7 changes: 7 additions & 0 deletions crates/subcoin-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ sc-consensus = { workspace = true }
sc-consensus-nakamoto = { workspace = true }
sc-executor = { workspace = true }
sc-fast-sync-backend = { workspace = true }
sc-informant = { workspace = true }
sc-network = { workspace = true }
sc-rpc = { workspace = true }
sc-rpc-api = { workspace = true }
# `test-helpers` for the exposed Client type.
sc-service = { workspace = true, features = ["test-helpers"], default-features = false }
sc-storage-monitor = { workspace = true }
sc-sysinfo = { workspace = true }
sc-telemetry = { workspace = true }
sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sc-utils = { workspace = true }
serde_json = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-block-builder = { workspace = true }
sp-core = { workspace = true }
sp-keystore = { workspace = true }
sp-runtime = { workspace = true }
Expand All @@ -38,6 +43,8 @@ sp-storage = { workspace = true }
sp-trie = { workspace = true }
subcoin-primitives = { workspace = true }
subcoin-runtime = { workspace = true }
substrate-frame-rpc-system = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
Expand Down
Loading

0 comments on commit 1758327

Please sign in to comment.