Skip to content
Snippets Groups Projects
Commit 424a9db1 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist: Committed by Hugo Trentesaux
Browse files

distance: move max-depth to runtime constant (!226)

* resolve metadata conflicts

* feat(distance): move max-depth to runtime constant
parent 874d1c93
No related branches found
No related tags found
1 merge request!226distance: move max-depth to runtime constant
Pipeline #35242 passed
......@@ -81,6 +81,13 @@ pub async fn evaluation_block(client: &Client, parent_hash: H256) -> H256 {
.expect("No evaluation block")
}
pub async fn max_referee_distance(client: &Client) -> u32 {
client
.constants()
.at(&runtime::constants().distance().max_referee_distance())
.expect("Cannot fetch referee distance")
}
pub async fn member_iter(client: &Client, evaluation_block: H256) -> MemberIter {
MemberIter(
client
......
......@@ -72,7 +72,6 @@ impl From<u64> for Tip {
pub struct Settings {
pub evaluation_result_dir: PathBuf,
pub max_depth: u32,
pub rpc_url: String,
}
......@@ -80,7 +79,6 @@ impl Default for Settings {
fn default() -> Self {
Self {
evaluation_result_dir: PathBuf::from("/tmp/duniter/chains/gdev/distance"),
max_depth: 5,
rpc_url: String::from("ws://127.0.0.1:9944"),
}
}
......@@ -151,6 +149,8 @@ pub async fn run(
) -> Option<(Vec<sp_runtime::Perbill>, u32, PathBuf)> {
let parent_hash = api::parent_hash(client).await;
let max_depth = api::max_referee_distance(client).await;
let current_session = api::current_session(client, parent_hash).await;
// Fetch the pending identities
......@@ -196,9 +196,7 @@ pub async fn run(
members.insert(member_idty, 0);
}
let min_certs_for_referee = (members.len() as f32)
.powf(1. / (settings.max_depth as f32))
.ceil() as u32;
let min_certs_for_referee = (members.len() as f32).powf(1. / (max_depth as f32)).ceil() as u32;
// idty -> received certs
let mut received_certs = FnvHashMap::<IdtyIndex, Vec<IdtyIndex>>::default();
......@@ -236,7 +234,7 @@ pub async fn run(
.0
.as_slice()
.par_iter()
.map(|(idty, _)| distance_rule(&received_certs, &referees, settings.max_depth, *idty))
.map(|(idty, _)| distance_rule(&received_certs, &referees, max_depth, *idty))
.collect();
Some((evaluation, current_session, evaluation_result_path))
......
......@@ -20,9 +20,6 @@ use clap::Parser;
struct Cli {
#[clap(short = 'd', long, default_value = "/tmp/duniter/chains/gdev/distance")]
evaluation_result_dir: String,
/// Maximum depth to explore the WoT graph for referees
#[clap(short = 'D', long, default_value = "5")]
max_depth: u32,
#[clap(short = 'u', long, default_value = "ws://127.0.0.1:9944")]
rpc_url: String,
/// Log level (off, error, warn, info, debug, trace)
......@@ -43,7 +40,6 @@ async fn main() {
&distance_oracle::api::client(cli.rpc_url.clone()).await,
distance_oracle::Settings {
evaluation_result_dir: cli.evaluation_result_dir.into(),
max_depth: cli.max_depth,
rpc_url: cli.rpc_url,
},
)
......
......@@ -76,6 +76,10 @@ pub async fn evaluation_block(_client: &Client, _parent_hash: H256) -> H256 {
Default::default()
}
pub async fn max_referee_distance(_client: &Client) -> u32 {
5
}
pub async fn member_iter(client: &Client, _evaluation_block: H256) -> MemberIter {
MemberIter(client.wot.get_enabled().into_iter())
}
......
......@@ -26,7 +26,6 @@ use std::{fs::File, io::Read};
async fn test_distance_against_v1() {
let wot = wot_from_v1_file();
let n = wot.size();
let max_depth = 5;
let min_certs_for_referee = (wot.get_enabled().len() as f32).powf(1. / 5.).ceil() as u32;
// Reference implementation
......@@ -44,7 +43,7 @@ async fn test_distance_against_v1() {
dubp_wot::operations::distance::WotDistanceParameters {
node: i,
sentry_requirement: min_certs_for_referee,
step_max: max_depth,
step_max: 5,
x_percent: 0.8,
},
)
......@@ -59,14 +58,7 @@ async fn test_distance_against_v1() {
client.pool_len = n;
let t_a = std::time::Instant::now();
let results = crate::run(
&client,
&crate::Settings {
max_depth,
..Default::default()
},
false,
)
let results = crate::run(&client, &Default::default(), false)
.await
.unwrap();
println!("new time: {}", t_a.elapsed().as_millis());
......
......@@ -10,15 +10,9 @@ Any smith member authoring blocks can run a distance evaluation oracle. It is be
The simplest way is to run the oracle on the same machine as Duniter.
Build the oracle:
cargo build --release -p distance-oracle
It will be available at `./target/release/distance-oracle`. Move it to somewhere appropriate.
Add this line to your cron with the command `crontab -e`: (add option `-u <user>` to edit another user's cron)
4,24,44 * * * * nice -n 2 /absolute/path/to/distance-oracle
4,24,44 * * * * nice -n 2 /absolute/path/to/duniter distance-oracle
The precise hours don't matter so you can pick random values, but it should run at least one time per hour, and running it more often decreases the risk of problem in case of missing blocks or temporary network failure.
......@@ -28,4 +22,4 @@ The `nice -n 2` lowers the oracle's priority, so that Duniter has the priority e
### Additional Duniter configuration
Duniter should keep states at least one session old, that it 600 blocks (while 256 is the default). Use the option `--state-pruning 600` if your node is not already an archive (`--state-pruning archive`).
Duniter should keep states at least one session old, that is 600 blocks (while 256 is the default). Use the option `--state-pruning 600` if your node is not already an archive (`--state-pruning archive`).
......@@ -49,7 +49,6 @@ pub async fn run_oracle(client: &Client, origin: AccountKeyring, rpc_url: String
&distance_oracle::api::client(rpc_url.clone()).await,
&distance_oracle::Settings {
evaluation_result_dir: PathBuf::default(),
max_depth: 5,
rpc_url,
},
false,
......
......@@ -141,9 +141,6 @@ pub struct Completion {
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,
}
......@@ -310,7 +310,6 @@ pub fn run() -> sc_cli::Result<()> {
&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(),
},
)
......
......@@ -72,6 +72,10 @@ pub mod pallet {
type EvaluationPrice: Get<
<Self::Currency as frame_support::traits::Currency<Self::AccountId>>::Balance,
>;
/// Maximum distance used to define referee's accessibility
/// Unused by runtime but needed by client distance oracle
#[pallet::constant]
type MaxRefereeDistance: Get<u32>;
/// Minimum ratio of accessible referees
#[pallet::constant]
type MinAccessibleReferees: Get<Perbill>;
......
......@@ -253,6 +253,7 @@ parameter_types! {
impl pallet_distance::Config for Test {
type Currency = Balances;
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MaxRefereeDistance = frame_support::traits::ConstU32<5>;
type MinAccessibleReferees = MinAccessibleReferees;
type ResultExpiration = frame_support::traits::ConstU32<720>;
type RuntimeEvent = RuntimeEvent;
......
No preview for this file type
......@@ -518,6 +518,7 @@ macro_rules! pallets_config {
impl pallet_distance::Config for Runtime {
type Currency = Balances;
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MaxRefereeDistance = frame_support::traits::ConstU32<5>;
type MinAccessibleReferees = MinAccessibleReferees;
type ResultExpiration = frame_support::traits::ConstU32<720>;
type RuntimeEvent = RuntimeEvent;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment