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
......@@ -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"),
......
......@@ -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(
......
......@@ -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
}
......
......@@ -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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment