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

fix #255

parent 6018f90d
No related branches found
No related tags found
No related merge requests found
Pipeline #38229 passed
......@@ -40,18 +40,28 @@ where
Backend: sc_client_api::Backend<B>,
IdtyIndex: Decode + Encode + PartialEq + TypeInfo,
{
let pool_index = client
// Retrieve the pool_index from storage. If storage is inaccessible or the data is corrupted,
// return an the appropriate storage error.
let pool_index = if let Some(index) = client
.storage(
parent,
&StorageKey(
frame_support::storage::storage_prefix(b"Distance", b"CurrentPoolIndex").to_vec(),
),
)
.expect("CurrentIndex is Err")
.map_or(0, |raw| {
u32::decode(&mut &raw.0[..]).expect("cannot decode CurrentIndex")
});
)?
.and_then(|raw| u32::decode(&mut &raw.0[..]).ok())
{
index
} else {
log::error!("🧙 [distance oracle] CurrentPoolIndex storage is corrupted");
return Err(sc_client_api::blockchain::Error::Storage(
"CurrentPoolIndex storage corrupted".to_string(),
));
};
// Retrieve the published_result from storage.
// Return an error if the storage is inaccessible.
// Continue execution if None is returned, meaning there is no published_result at this block.
let published_results = client
.storage(
parent,
......@@ -68,21 +78,21 @@ where
.to_vec(),
),
)?
.map_or_else(Default::default, |raw| {
pallet_distance::EvaluationPool::<AccountId32, IdtyIndex>::decode(&mut &raw.0[..])
.expect("cannot decode EvaluationPool")
.and_then(|raw| {
pallet_distance::EvaluationPool::<AccountId32, IdtyIndex>::decode(&mut &raw.0[..]).ok()
});
// Have we already published a result for this period?
// The block author is guaranteed to be in the owner_keys.
let owner_keys = owner_keys
.iter()
.map(|&key| sp_runtime::AccountId32::new(key.0))
.any(|key| published_results.evaluators.contains(&key));
if owner_keys {
log::debug!("🧙 [distance oracle] Already published a result for this period");
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
if let Some(results) = published_results {
if owner_keys
.iter()
.map(|&key| sp_runtime::AccountId32::new(key.0))
.any(|key| results.evaluators.contains(&key))
{
log::debug!("🧙 [distance oracle] Already published a result for this period");
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
}
}
// Read evaluation result from file, if it exists
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment