From 8f9f84648e7ce50df1f825de0b0c5ba36aca955d Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Thu, 29 Feb 2024 19:20:53 +0100 Subject: [PATCH] update distance-oracle --- distance-oracle/src/api.rs | 16 ++++++++-------- distance-oracle/src/lib.rs | 16 ++++++++-------- distance-oracle/src/mock.rs | 2 +- pallets/distance/src/lib.rs | 1 + 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/distance-oracle/src/api.rs b/distance-oracle/src/api.rs index fae73cdd7..3aeaa7f8f 100644 --- a/distance-oracle/src/api.rs +++ b/distance-oracle/src/api.rs @@ -40,35 +40,35 @@ pub async fn parent_hash(client: &Client) -> H256 { .hash() } -pub async fn current_session(client: &Client, parent_hash: H256) -> u32 { +pub async fn current_pool_index(client: &Client, parent_hash: H256) -> u32 { client .storage() .at(parent_hash) - .fetch(&runtime::storage().session().current_index()) + .fetch(&runtime::storage().distance().current_pool_index()) .await - .expect("Cannot fetch current session") + .expect("Cannot fetch current pool index") .unwrap_or_default() } pub async fn current_pool( client: &Client, parent_hash: H256, - current_session: u32, + current_pool_index: u32, ) -> Option<runtime::runtime_types::pallet_distance::types::EvaluationPool<AccountId, IdtyIndex>> { client .storage() .at(parent_hash) - .fetch(&match current_session % 3 { + .fetch(&match current_pool_index { 0 => { - debug!("Looking at Pool1 for session {}", current_session); + debug!("Looking at Pool1 for pool index {}", current_pool_index); runtime::storage().distance().evaluation_pool1() } 1 => { - debug!("Looking at Pool2 for session {}", current_session); + debug!("Looking at Pool2 for pool index {}", current_pool_index); runtime::storage().distance().evaluation_pool2() } 2 => { - debug!("Looking at Pool0 for session {}", current_session); + debug!("Looking at Pool0 for pool index {}", current_pool_index); runtime::storage().distance().evaluation_pool0() } _ => unreachable!("n%3<3"), diff --git a/distance-oracle/src/lib.rs b/distance-oracle/src/lib.rs index 955759efd..0fe796fb1 100644 --- a/distance-oracle/src/lib.rs +++ b/distance-oracle/src/lib.rs @@ -84,7 +84,7 @@ impl Default for Settings { } pub async fn run_and_save(client: &api::Client, settings: Settings) { - let Some((evaluation, current_session, evaluation_result_path)) = + let Some((evaluation, current_pool_index, evaluation_result_path)) = run(client, &settings, true).await else { return; @@ -128,7 +128,7 @@ pub async fn run_and_save(client: &api::Client, settings: Settings) { { if let Ok(entry_name) = entry.file_name().into_string() { if let Ok(entry_session) = entry_name.parse::<isize>() { - if current_session as isize - entry_session > 3 { + if current_pool_index as isize - entry_session > 3 { files_to_remove.push(entry.path()); } } @@ -140,7 +140,7 @@ pub async fn run_and_save(client: &api::Client, settings: Settings) { }); } -/// Returns `Option<(evaluation, current_session, evaluation_result_path)>` +/// Returns `Option<(evaluation, current_pool_index, evaluation_result_path)>` pub async fn run( client: &api::Client, settings: &Settings, @@ -150,10 +150,10 @@ pub async fn run( let max_depth = api::max_referee_distance(client).await; - let current_session = api::current_session(client, parent_hash).await; + let current_pool_index = api::current_pool_index(client, parent_hash).await; // Fetch the pending identities - let Some(evaluation_pool) = api::current_pool(client, parent_hash, current_session).await + let Some(evaluation_pool) = api::current_pool(client, parent_hash, current_pool_index).await else { info!("Nothing to do: Pool does not exist"); return None; @@ -167,7 +167,7 @@ pub async fn run( let evaluation_result_path = settings .evaluation_result_dir - .join((current_session + 1).to_string()); + .join((current_pool_index + 1).to_string()); if handle_fs { // Stop if already evaluated @@ -187,7 +187,7 @@ pub async fn run( }); } - info!("Evaluating distance for session {}", current_session); + info!("Evaluating distance for session {}", current_pool_index); let evaluation_block = api::evaluation_block(client, parent_hash).await; // member idty -> issued certs @@ -243,7 +243,7 @@ pub async fn run( .map(|(idty, _)| distance_rule(&received_certs, &referees, max_depth, *idty)) .collect(); - Some((evaluation, current_session, evaluation_result_path)) + Some((evaluation, current_pool_index, evaluation_result_path)) } fn distance_rule_recursive( diff --git a/distance-oracle/src/mock.rs b/distance-oracle/src/mock.rs index 805ac607b..56e5f98bc 100644 --- a/distance-oracle/src/mock.rs +++ b/distance-oracle/src/mock.rs @@ -46,7 +46,7 @@ pub async fn parent_hash(_client: &Client) -> H256 { Default::default() } -pub async fn current_session(_client: &Client, _parent_hash: H256) -> u32 { +pub async fn current_pool_index(_client: &Client, _parent_hash: H256) -> u32 { 0 } diff --git a/pallets/distance/src/lib.rs b/pallets/distance/src/lib.rs index 8ae9a9d6a..03a6c5bb3 100644 --- a/pallets/distance/src/lib.rs +++ b/pallets/distance/src/lib.rs @@ -160,6 +160,7 @@ pub mod pallet { /// Current evaluation pool. #[pallet::storage] + #[pallet::getter(fn current_pool_index)] pub(super) type CurrentPoolIndex<T: Config> = StorageValue<_, u32, ValueQuery>; #[pallet::event] -- GitLab