Skip to content
Snippets Groups Projects
Unverified Commit ade2e5cf authored by bgallois's avatar bgallois
Browse files

update distance-oracle

parent 3e25de1b
No related branches found
No related tags found
1 merge request!252Change distance evaluation period from Sessions to Blocks
This commit is part of merge request !252. Comments created here will be created in the context of that merge request.
...@@ -40,35 +40,35 @@ pub async fn parent_hash(client: &Client) -> H256 { ...@@ -40,35 +40,35 @@ pub async fn parent_hash(client: &Client) -> H256 {
.hash() .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 client
.storage() .storage()
.at(parent_hash) .at(parent_hash)
.fetch(&runtime::storage().session().current_index()) .fetch(&runtime::storage().distance().current_pool_index())
.await .await
.expect("Cannot fetch current session") .expect("Cannot fetch current pool index")
.unwrap_or_default() .unwrap_or_default()
} }
pub async fn current_pool( pub async fn current_pool(
client: &Client, client: &Client,
parent_hash: H256, parent_hash: H256,
current_session: u32, current_pool_index: u32,
) -> Option<runtime::runtime_types::pallet_distance::types::EvaluationPool<AccountId, IdtyIndex>> { ) -> Option<runtime::runtime_types::pallet_distance::types::EvaluationPool<AccountId, IdtyIndex>> {
client client
.storage() .storage()
.at(parent_hash) .at(parent_hash)
.fetch(&match current_session % 3 { .fetch(&match current_pool_index {
0 => { 0 => {
debug!("Looking at Pool1 for session {}", current_session); debug!("Looking at Pool1 for pool index {}", current_pool_index);
runtime::storage().distance().evaluation_pool1() runtime::storage().distance().evaluation_pool1()
} }
1 => { 1 => {
debug!("Looking at Pool2 for session {}", current_session); debug!("Looking at Pool2 for pool index {}", current_pool_index);
runtime::storage().distance().evaluation_pool2() runtime::storage().distance().evaluation_pool2()
} }
2 => { 2 => {
debug!("Looking at Pool0 for session {}", current_session); debug!("Looking at Pool0 for pool index {}", current_pool_index);
runtime::storage().distance().evaluation_pool0() runtime::storage().distance().evaluation_pool0()
} }
_ => unreachable!("n%3<3"), _ => unreachable!("n%3<3"),
......
...@@ -84,7 +84,7 @@ impl Default for Settings { ...@@ -84,7 +84,7 @@ impl Default for Settings {
} }
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_session, 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;
...@@ -128,7 +128,7 @@ pub async fn run_and_save(client: &api::Client, settings: Settings) { ...@@ -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_name) = entry.file_name().into_string() {
if let Ok(entry_session) = entry_name.parse::<isize>() { 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()); files_to_remove.push(entry.path());
} }
} }
...@@ -140,7 +140,7 @@ pub async fn run_and_save(client: &api::Client, settings: Settings) { ...@@ -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( pub async fn run(
client: &api::Client, client: &api::Client,
settings: &Settings, settings: &Settings,
...@@ -150,10 +150,10 @@ pub async fn run( ...@@ -150,10 +150,10 @@ pub async fn run(
let max_depth = api::max_referee_distance(client).await; 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 // 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 { else {
info!("Nothing to do: Pool does not exist"); info!("Nothing to do: Pool does not exist");
return None; return None;
...@@ -167,7 +167,7 @@ pub async fn run( ...@@ -167,7 +167,7 @@ pub async fn run(
let evaluation_result_path = settings let evaluation_result_path = settings
.evaluation_result_dir .evaluation_result_dir
.join((current_session + 1).to_string()); .join((current_pool_index + 1).to_string());
if handle_fs { if handle_fs {
// Stop if already evaluated // Stop if already evaluated
...@@ -187,7 +187,7 @@ pub async fn run( ...@@ -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; let evaluation_block = api::evaluation_block(client, parent_hash).await;
// member idty -> issued certs // member idty -> issued certs
...@@ -243,7 +243,7 @@ pub async fn run( ...@@ -243,7 +243,7 @@ pub async fn run(
.map(|(idty, _)| distance_rule(&received_certs, &referees, max_depth, *idty)) .map(|(idty, _)| distance_rule(&received_certs, &referees, max_depth, *idty))
.collect(); .collect();
Some((evaluation, current_session, evaluation_result_path)) Some((evaluation, current_pool_index, evaluation_result_path))
} }
fn distance_rule_recursive( fn distance_rule_recursive(
......
...@@ -46,7 +46,7 @@ pub async fn parent_hash(_client: &Client) -> H256 { ...@@ -46,7 +46,7 @@ pub async fn parent_hash(_client: &Client) -> H256 {
Default::default() 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 0
} }
......
...@@ -160,6 +160,7 @@ pub mod pallet { ...@@ -160,6 +160,7 @@ pub mod pallet {
/// Current evaluation pool. /// Current evaluation pool.
#[pallet::storage] #[pallet::storage]
#[pallet::getter(fn current_pool_index)]
pub(super) type CurrentPoolIndex<T: Config> = StorageValue<_, u32, ValueQuery>; pub(super) type CurrentPoolIndex<T: Config> = StorageValue<_, u32, ValueQuery>;
#[pallet::event] #[pallet::event]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment