Skip to content
Snippets Groups Projects
Commit ea629187 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

distance-oracle: sheduler

parent bcc0a50b
No related branches found
No related tags found
1 merge request!285distance oracle scheduler
...@@ -2100,9 +2100,7 @@ dependencies = [ ...@@ -2100,9 +2100,7 @@ dependencies = [
"dubp-wot", "dubp-wot",
"flate2", "flate2",
"fnv", "fnv",
"hex",
"log", "log",
"num-traits 0.2.19",
"parity-scale-codec", "parity-scale-codec",
"rayon", "rayon",
"simple_logger", "simple_logger",
...@@ -2254,6 +2252,7 @@ dependencies = [ ...@@ -2254,6 +2252,7 @@ dependencies = [
"sp-trie", "sp-trie",
"substrate-build-script-utils", "substrate-build-script-utils",
"substrate-frame-rpc-system", "substrate-frame-rpc-system",
"tokio",
] ]
[[package]] [[package]]
......
...@@ -12,13 +12,12 @@ required-features = ["standalone"] ...@@ -12,13 +12,12 @@ required-features = ["standalone"]
[features] [features]
default = ["standalone", "std"] default = ["standalone", "std"]
# Feature standalone is for CLI executable
standalone = ["clap", "tokio"] standalone = ["clap", "tokio"]
# Feature std is needed
std = [ std = [
"codec/std", "codec/std",
"fnv/std", "fnv/std",
"hex/std",
"log/std",
"num-traits/std",
"sp-core/std", "sp-core/std",
"sp-distance/std", "sp-distance/std",
"sp-runtime/std", "sp-runtime/std",
...@@ -30,9 +29,7 @@ runtime-benchmarks = [] ...@@ -30,9 +29,7 @@ runtime-benchmarks = []
clap = { workspace = true, features = ["derive"], optional = true } clap = { workspace = true, features = ["derive"], optional = true }
codec = { workspace = true } codec = { workspace = true }
fnv = { workspace = true } fnv = { workspace = true }
hex = { workspace = true }
log = { workspace = true } log = { workspace = true }
num-traits = { workspace = true }
rayon = { workspace = true } rayon = { workspace = true }
simple_logger = { workspace = true } simple_logger = { workspace = true }
sp-core = { workspace = true } sp-core = { workspace = true }
......
...@@ -25,7 +25,7 @@ pub type Client = subxt::OnlineClient<crate::RuntimeConfig>; ...@@ -25,7 +25,7 @@ pub type Client = subxt::OnlineClient<crate::RuntimeConfig>;
pub type AccountId = subxt::utils::AccountId32; pub type AccountId = subxt::utils::AccountId32;
pub type IdtyIndex = u32; pub type IdtyIndex = u32;
pub async fn client(rpc_url: String) -> Client { pub async fn client(rpc_url: impl AsRef<str>) -> Client {
Client::from_insecure_url(rpc_url) Client::from_insecure_url(rpc_url)
.await .await
.expect("Cannot create RPC client") .expect("Cannot create RPC client")
......
...@@ -84,9 +84,9 @@ impl Default for Settings { ...@@ -84,9 +84,9 @@ impl Default for Settings {
} }
/// Asynchronously runs a computation using the provided client and saves the result to a file. /// Asynchronously runs a computation using the provided client and saves the result to a file.
pub async fn run_and_save(client: &api::Client, settings: Settings) { pub async fn run_and_save(client: &api::Client, settings: &Settings) {
let Some((evaluation, current_pool_index, evaluation_result_path)) = let Some((evaluation, current_pool_index, evaluation_result_path)) =
run(client, &settings, true).await run(client, settings, true).await
else { else {
return; return;
}; };
......
// Copyright 2023 Axiom-Team // Copyright 2023-2024 Axiom-Team
// //
// This file is part of Duniter-v2S. // This file is part of Duniter-v2S.
// //
...@@ -20,6 +20,8 @@ use clap::Parser; ...@@ -20,6 +20,8 @@ use clap::Parser;
struct Cli { struct Cli {
#[clap(short = 'd', long, default_value = "/tmp/duniter/chains/gdev/distance")] #[clap(short = 'd', long, default_value = "/tmp/duniter/chains/gdev/distance")]
evaluation_result_dir: String, evaluation_result_dir: String,
#[clap(short = 'i', long, default_value = "None")]
interval: Option<u64>,
#[clap(short = 'u', long, default_value = "ws://127.0.0.1:9944")] #[clap(short = 'u', long, default_value = "ws://127.0.0.1:9944")]
rpc_url: String, rpc_url: String,
/// Log level (off, error, warn, info, debug, trace) /// Log level (off, error, warn, info, debug, trace)
...@@ -36,12 +38,21 @@ async fn main() { ...@@ -36,12 +38,21 @@ async fn main() {
.init() .init()
.unwrap(); .unwrap();
distance_oracle::run_and_save( let client = distance_oracle::api::client(&cli.rpc_url).await;
&distance_oracle::api::client(cli.rpc_url.clone()).await,
distance_oracle::Settings { let settings = distance_oracle::Settings {
evaluation_result_dir: cli.evaluation_result_dir.into(), evaluation_result_dir: cli.evaluation_result_dir.into(),
rpc_url: cli.rpc_url, rpc_url: cli.rpc_url,
}, };
)
.await; if let Some(duration) = cli.interval {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(duration));
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
loop {
distance_oracle::run_and_save(&client, &settings).await;
interval.tick().await;
}
} else {
distance_oracle::run_and_save(&client, &settings).await;
}
} }
...@@ -34,7 +34,7 @@ pub struct EvaluationPool<AccountId: Ord, IdtyIndex> { ...@@ -34,7 +34,7 @@ pub struct EvaluationPool<AccountId: Ord, IdtyIndex> {
pub evaluators: BTreeSet<AccountId>, pub evaluators: BTreeSet<AccountId>,
} }
pub async fn client(_rpc_url: String) -> Client { pub async fn client(_rpc_url: impl AsRef<str>) -> Client {
unimplemented!() unimplemented!()
} }
......
...@@ -106,7 +106,7 @@ std = [ ...@@ -106,7 +106,7 @@ std = [
"sp-transaction-storage-proof/std", "sp-transaction-storage-proof/std",
"sp-trie/std", "sp-trie/std",
] ]
standalone = ["distance-oracle?/standalone"] distance-oracle = ["dep:distance-oracle"]
[dependencies] [dependencies]
async-io = { workspace = true } async-io = { workspace = true }
...@@ -125,6 +125,7 @@ num-format = { workspace = true } ...@@ -125,6 +125,7 @@ num-format = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
serde_yaml = { workspace = true } serde_yaml = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread"] }
# Local # Local
common-runtime = { workspace = true } common-runtime = { workspace = true }
...@@ -194,9 +195,20 @@ sp-trie = { workspace = true, default-features = true } ...@@ -194,9 +195,20 @@ sp-trie = { workspace = true, default-features = true }
[package.metadata.deb] [package.metadata.deb]
maintainer-scripts = "../resources/debian" maintainer-scripts = "../resources/debian"
systemd-units = [ { unit-name = "duniter-mirror", enable = false }, systemd-units = [
{ unit-name = "duniter-mirror", enable = false },
{ unit-name = "duniter-smith", enable = false }, { unit-name = "duniter-smith", enable = false },
{ unit-name = "distance-oracle", enable = false }, { unit-name = "distance-oracle", enable = false },
] ]
assets = [ ["../resources/debian/env_file", "/etc/duniter/env_file", "0640"], assets = [
["../target/release/duniter", "/usr/bin/duniter2", "755"]] [
"../resources/debian/env_file",
"/etc/duniter/env_file",
"0640",
],
[
"../target/release/duniter",
"/usr/bin/duniter2",
"755",
],
]
...@@ -133,6 +133,8 @@ pub struct Completion { ...@@ -133,6 +133,8 @@ pub struct Completion {
pub struct DistanceOracle { pub struct DistanceOracle {
#[clap(short = 'd', long, default_value = "/tmp/duniter/chains/gdev/distance")] #[clap(short = 'd', long, default_value = "/tmp/duniter/chains/gdev/distance")]
pub evaluation_result_dir: String, pub evaluation_result_dir: String,
#[clap(short = 'i', long, default_value = "None")]
pub interval: Option<u64>,
#[clap(short = 'u', long, default_value = "ws://127.0.0.1:9944")] #[clap(short = 'u', long, default_value = "ws://127.0.0.1:9944")]
pub rpc_url: String, pub rpc_url: String,
} }
...@@ -285,14 +285,23 @@ pub fn run() -> sc_cli::Result<()> { ...@@ -285,14 +285,23 @@ pub fn run() -> sc_cli::Result<()> {
} }
#[cfg(feature = "distance-oracle")] #[cfg(feature = "distance-oracle")]
Some(Subcommand::DistanceOracle(cmd)) => sc_cli::build_runtime()?.block_on(async move { Some(Subcommand::DistanceOracle(cmd)) => sc_cli::build_runtime()?.block_on(async move {
distance_oracle::run_and_save( let client = distance_oracle::api::client(&cmd.rpc_url).await;
&distance_oracle::api::client(cmd.rpc_url.clone()).await,
distance_oracle::Settings { let settings = distance_oracle::Settings {
evaluation_result_dir: cmd.evaluation_result_dir.clone().into(), evaluation_result_dir: cmd.evaluation_result_dir.clone().into(),
rpc_url: cmd.rpc_url.clone(), rpc_url: cmd.rpc_url.clone(),
}, };
)
.await; if let Some(duration) = cmd.interval {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(duration));
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
loop {
distance_oracle::run_and_save(&client, &settings).await;
interval.tick().await;
}
} else {
distance_oracle::run_and_save(&client, &settings).await;
}
Ok(()) Ok(())
}), }),
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment