Skip to content
Snippets Groups Projects

Fix distance evaluation client

Merged Pascal Engélibert requested to merge tuxmain/distance-fix-evaluator into master

Files

+ 33
8
@@ -85,24 +85,46 @@ where
@@ -85,24 +85,46 @@ where
});
});
// Have we already published a result for this period?
// Have we already published a result for this period?
// The block author is guaranteed to be in the owner_keys.
if let Some(results) = published_results {
if let Some(results) = published_results {
if owner_keys
// Find the account associated with the BABE key that is in our owner keys.
.iter()
let Some((_key, local_account)) = client
.map(|&key| sp_runtime::AccountId32::new(key.0))
.storage_pairs(
.any(|key| results.evaluators.contains(&key))
parent,
{
Some(&StorageKey(
 
frame_support::storage::storage_prefix(b"Session", b"KeyOwner").to_vec(),
 
)),
 
None,
 
)?
 
.filter_map(|(raw_key, raw_data)| {
 
if &raw_key.0[40..44] == b"babe" {
 
Some((
 
sp_core::sr25519::Public::from_raw(
 
raw_key.0[45..45 + 32].try_into().unwrap(),
 
),
 
AccountId32::decode(&mut &raw_data.0[..]).ok()?,
 
))
 
} else {
 
None
 
}
 
})
 
.find(|(key, _data)| owner_keys.contains(key))
 
else {
 
log::error!("🧙 [distance oracle] Cannot find our BABE owner key");
 
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
 
};
 
if results.evaluators.contains(&local_account) {
log::debug!("🧙 [distance oracle] Already published a result for this period");
log::debug!("🧙 [distance oracle] Already published a result for this period");
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
}
}
}
}
// Read evaluation result from file, if it exists
// Read evaluation result from file, if it exists, then remove it
log::debug!(
log::debug!(
"🧙 [distance oracle] Reading evaluation result from file {:?}",
"🧙 [distance oracle] Reading evaluation result from file {:?}",
distance_dir.clone().join(pool_index.to_string())
distance_dir.clone().join(pool_index.to_string())
);
);
let evaluation_result = match std::fs::read(distance_dir.join(pool_index.to_string())) {
let evaluation_result_file_path = distance_dir.join(pool_index.to_string());
 
let evaluation_result = match std::fs::read(&evaluation_result_file_path) {
Ok(data) => data,
Ok(data) => data,
Err(e) => {
Err(e) => {
match e.kind() {
match e.kind() {
@@ -118,6 +140,9 @@ where
@@ -118,6 +140,9 @@ where
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
}
}
};
};
 
std::fs::remove_file(&evaluation_result_file_path).unwrap_or_else(move |e| {
 
log::warn!("🧙 [distance oracle] Cannot remove old result file `{evaluation_result_file_path:?}`: {e:?}")
 
});
log::info!("🧙 [distance oracle] Providing evaluation result");
log::info!("🧙 [distance oracle] Providing evaluation result");
Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(Some(
Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(Some(
Loading