Skip to content
Snippets Groups Projects

Fix #255 distance reading discarded state

Merged Benjamin Gallois requested to merge fix-255 into master
Files
2
+ 24
17
@@ -40,17 +40,22 @@ where
@@ -40,17 +40,22 @@ where
Backend: sc_client_api::Backend<B>,
Backend: sc_client_api::Backend<B>,
IdtyIndex: Decode + Encode + PartialEq + TypeInfo,
IdtyIndex: Decode + Encode + PartialEq + TypeInfo,
{
{
let pool_index = client
let pool_index = if let Some(index) = client
.storage(
.storage(
parent,
parent,
&StorageKey(
&StorageKey(
frame_support::storage::storage_prefix(b"Distance", b"CurrentPoolIndex").to_vec(),
frame_support::storage::storage_prefix(b"Distance", b"CurrentPoolIndex").to_vec(),
),
),
)
)
.expect("CurrentIndex is Err")
.ok()
.map_or(0, |raw| {
.flatten()
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 cannot be decoded");
 
return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None));
 
};
let published_results = client
let published_results = client
.storage(
.storage(
@@ -67,22 +72,24 @@ where
@@ -67,22 +72,24 @@ where
)
)
.to_vec(),
.to_vec(),
),
),
)?
)
.map_or_else(Default::default, |raw| {
.ok()
pallet_distance::EvaluationPool::<AccountId32, IdtyIndex>::decode(&mut &raw.0[..])
.flatten()
.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?
// Have we already published a result for this period?
// The block author is guaranteed to be in the owner_keys.
// The block author is guaranteed to be in the owner_keys.
let owner_keys = owner_keys
if let Some(results) = published_results {
.iter()
if owner_keys
.map(|&key| sp_runtime::AccountId32::new(key.0))
.iter()
.any(|key| published_results.evaluators.contains(&key));
.map(|&key| sp_runtime::AccountId32::new(key.0))
.any(|key| results.evaluators.contains(&key))
if owner_keys {
{
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
Loading