diff --git a/Cargo.toml b/Cargo.toml index 9a86c03760535a544e4fd3c9b3c545b0395784e9..5517414ea929bdcb8445fca79f6b8e9b0f7e711d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ name = 'duniter' path = "node/src/main.rs" [features] -default = ["gdev"] +default = ["gdev", "distance-oracle"] gdev = ["gdev-runtime"] # gdev feature enables gdev runtime and gdev command line options g1 = ["g1-runtime"] gtest = ["gtest-runtime"] @@ -58,7 +58,7 @@ sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-subs # local dependencies common-runtime = { path = 'runtime/common' } dc-distance = { path = 'client/distance' } -distance-oracle = { path = 'distance-oracle', optional = true } +distance-oracle = { path = 'distance-oracle', default-features = false, optional = true } g1-runtime = { path = 'runtime/g1', optional = true } gdev-runtime = { path = 'runtime/gdev', optional = true } gtest-runtime = { path = 'runtime/gtest', optional = true } diff --git a/distance-oracle/Cargo.toml b/distance-oracle/Cargo.toml index 12095aacea5c26fd2795e98a1c737ff44920fdd1..4ca93a1a5b5347e7503eb386b487666d036f10e2 100644 --- a/distance-oracle/Cargo.toml +++ b/distance-oracle/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" [dependencies] sp-distance = { path = "../primitives/distance" } -codec = { package = "parity-scale-codec", version = "3.1.5" } +codec = { package = "parity-scale-codec", version = "3.6.5" } fnv = "1.0.7" log = "0.4.17" num-traits = "0.2.15" diff --git a/node/src/cli.rs b/node/src/cli.rs index e1f62481f5ae63ca53e5b5096c29f5e1a6632502..a6f6a25e920082ec70fa50e81cb0cd79f8bf4cf6 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -37,6 +37,10 @@ pub enum Subcommand { /// Validate blocks. CheckBlock(sc_cli::CheckBlockCmd), + /// Run distance oracle. + #[cfg(feature = "distance-oracle")] + DistanceOracle(DistanceOracle), + /// Export blocks. ExportBlocks(sc_cli::ExportBlocksCmd), @@ -132,3 +136,14 @@ pub struct Completion { #[clap(short, long, value_enum)] pub generator: clap_complete::Shell, } + +#[derive(Debug, clap::Args)] +pub struct DistanceOracle { + #[clap(short = 'd', long, default_value = "/tmp/duniter/chains/gdev/distance")] + pub evaluation_result_dir: String, + /// Maximum depth to explore the WoT graph for referees + #[clap(short = 'D', long, default_value = "5")] + pub max_depth: u32, + #[clap(short = 'u', long, default_value = "ws://127.0.0.1:9944")] + pub rpc_url: String, +} diff --git a/node/src/command.rs b/node/src/command.rs index 4008229eefaf488e1887f7e6d63b186b21a2c7f4..60aa193aa645c24c30d74fed474921bab1c5d256 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -304,6 +304,19 @@ pub fn run() -> sc_cli::Result<()> { ); Ok(()) } + #[cfg(feature = "distance-oracle")] + Some(Subcommand::DistanceOracle(cmd)) => sc_cli::build_runtime()?.block_on(async move { + distance_oracle::run_and_save( + &distance_oracle::api::client(cmd.rpc_url.clone()).await, + distance_oracle::Settings { + evaluation_result_dir: cmd.evaluation_result_dir.clone().into(), + max_depth: cmd.max_depth, + rpc_url: cmd.rpc_url.clone(), + }, + ) + .await; + Ok(()) + }), #[cfg(feature = "runtime-benchmarks")] Some(Subcommand::Benchmark(cmd)) => { let runner = cli.create_runner(&**cmd)?;