Skip to content
Snippets Groups Projects
Commit 0f611028 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist: Committed by Hugo Trentesaux
Browse files

Fix distance-oracle EvaluationPool type

(cherry picked from commit 03b858a7)
parent e926cfd1
No related branches found
No related tags found
No related merge requests found
...@@ -14,23 +14,14 @@ ...@@ -14,23 +14,14 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. // along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use crate::{ use crate::runtime;
runtime,
runtime::runtime_types::{
pallet_distance::median::MedianAcc, sp_arithmetic::per_things::Perbill,
},
};
use sp_core::bounded::{bounded_btree_set::BoundedBTreeSet, bounded_vec::BoundedVec};
use sp_core::H256; use sp_core::H256;
use subxt::storage::StorageKey; use subxt::storage::StorageKey;
pub type Client = subxt::OnlineClient<crate::RuntimeConfig>; pub type Client = subxt::OnlineClient<crate::RuntimeConfig>;
pub type AccountId = subxt::ext::sp_runtime::AccountId32; pub type AccountId = subxt::ext::sp_runtime::AccountId32;
pub type IdtyIndex = u32; pub type IdtyIndex = u32;
pub type EvaluationPool<AccountId, IdtyIndex> = (
BoundedVec<(IdtyIndex, MedianAcc<Perbill>), u32>, // FIXME is u32 still the good type?
BoundedBTreeSet<AccountId, u32>, // FIXME idem
);
pub async fn client(rpc_url: String) -> Client { pub async fn client(rpc_url: String) -> Client {
Client::from_url(rpc_url) Client::from_url(rpc_url)
...@@ -63,7 +54,7 @@ pub async fn current_pool( ...@@ -63,7 +54,7 @@ pub async fn current_pool(
client: &Client, client: &Client,
parent_hash: H256, parent_hash: H256,
current_session: u32, current_session: u32,
) -> Option<EvaluationPool<AccountId, IdtyIndex>> { ) -> Option<runtime::runtime_types::pallet_distance::types::EvaluationPool<AccountId, IdtyIndex>> {
client client
.storage() .storage()
.fetch( .fetch(
......
...@@ -160,7 +160,7 @@ pub async fn run( ...@@ -160,7 +160,7 @@ pub async fn run(
}; };
// Stop if nothing to evaluate // Stop if nothing to evaluate
if evaluation_pool.0 .0.is_empty() { if evaluation_pool.evaluations.0.is_empty() {
debug!("Nothing to do: Pool is empty"); debug!("Nothing to do: Pool is empty");
return None; return None;
} }
...@@ -230,8 +230,8 @@ pub async fn run( ...@@ -230,8 +230,8 @@ pub async fn run(
let referees = members; let referees = members;
let evaluation = evaluation_pool let evaluation = evaluation_pool
.evaluations
.0 .0
.0
.as_slice() .as_slice()
.par_iter() .par_iter()
.map(|(idty, _)| distance_rule(&received_certs, &referees, settings.max_depth, *idty)) .map(|(idty, _)| distance_rule(&received_certs, &referees, settings.max_depth, *idty))
......
...@@ -28,8 +28,11 @@ pub struct Client { ...@@ -28,8 +28,11 @@ pub struct Client {
} }
pub type AccountId = subxt::ext::sp_runtime::AccountId32; pub type AccountId = subxt::ext::sp_runtime::AccountId32;
pub type IdtyIndex = u32; pub type IdtyIndex = u32;
pub type EvaluationPool<AccountId, IdtyIndex> =
((Vec<(IdtyIndex, MedianAcc<Perbill>)>,), BTreeSet<AccountId>); pub struct EvaluationPool<AccountId: Ord, IdtyIndex> {
pub evaluations: (Vec<(IdtyIndex, MedianAcc<Perbill>)>,),
pub evaluators: BTreeSet<AccountId>,
}
pub async fn client(_rpc_url: String) -> Client { pub async fn client(_rpc_url: String) -> Client {
unimplemented!() unimplemented!()
...@@ -52,8 +55,8 @@ pub async fn current_pool( ...@@ -52,8 +55,8 @@ pub async fn current_pool(
_parent_hash: H256, _parent_hash: H256,
_current_session: u32, _current_session: u32,
) -> Option<EvaluationPool<AccountId, IdtyIndex>> { ) -> Option<EvaluationPool<AccountId, IdtyIndex>> {
Some(( Some(EvaluationPool {
(client evaluations: (client
.wot .wot
.get_enabled() .get_enabled()
.into_iter() .into_iter()
...@@ -65,8 +68,8 @@ pub async fn current_pool( ...@@ -65,8 +68,8 @@ pub async fn current_pool(
}) })
}) })
.collect(),), .collect(),),
std::collections::BTreeSet::new(), evaluators: BTreeSet::new(),
)) })
} }
pub async fn evaluation_block(_client: &Client, _parent_hash: H256) -> H256 { pub async fn evaluation_block(_client: &Client, _parent_hash: H256) -> H256 {
......
...@@ -508,7 +508,7 @@ async fn should_have_distance_result_in_sessions( ...@@ -508,7 +508,7 @@ async fn should_have_distance_result_in_sessions(
.unwrap() .unwrap()
.ok_or_else(|| anyhow::anyhow!("given pool is empty"))?; .ok_or_else(|| anyhow::anyhow!("given pool is empty"))?;
for (sample_idty, _) in pool.0 .0 { for (sample_idty, _) in pool.evaluations.0 {
if sample_idty == idty_id { if sample_idty == idty_id {
return Ok(()); return Ok(());
} }
......
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