From 03b858a7c6906c48aa97c57a006035e52e3d9156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Eng=C3=A9libert?= <tuxmain@zettascript.org> Date: Mon, 11 Sep 2023 21:54:57 +0200 Subject: [PATCH] Fix distance-oracle EvaluationPool type --- distance-oracle/src/api.rs | 15 ++------------- distance-oracle/src/lib.rs | 4 ++-- distance-oracle/src/mock.rs | 15 +++++++++------ end2end-tests/tests/cucumber_tests.rs | 2 +- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/distance-oracle/src/api.rs b/distance-oracle/src/api.rs index 3af39b736..ee5ce2587 100644 --- a/distance-oracle/src/api.rs +++ b/distance-oracle/src/api.rs @@ -14,14 +14,7 @@ // 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/>. -use crate::{ - runtime, - runtime::runtime_types::{ - pallet_distance::median::MedianAcc, - sp_arithmetic::per_things::Perbill, - sp_core::bounded::{bounded_btree_set::BoundedBTreeSet, bounded_vec::BoundedVec}, - }, -}; +use crate::runtime; use sp_core::H256; use subxt::storage::StorageKey; @@ -29,10 +22,6 @@ use subxt::storage::StorageKey; pub type Client = subxt::OnlineClient<crate::RuntimeConfig>; pub type AccountId = subxt::ext::sp_runtime::AccountId32; pub type IdtyIndex = u32; -pub type EvaluationPool<AccountId, IdtyIndex> = ( - BoundedVec<(IdtyIndex, MedianAcc<Perbill>)>, - BoundedBTreeSet<AccountId>, -); pub async fn client(rpc_url: String) -> Client { Client::from_url(rpc_url) @@ -65,7 +54,7 @@ pub async fn current_pool( client: &Client, parent_hash: H256, current_session: u32, -) -> Option<EvaluationPool<AccountId, IdtyIndex>> { +) -> Option<runtime::runtime_types::pallet_distance::types::EvaluationPool<AccountId, IdtyIndex>> { client .storage() .fetch( diff --git a/distance-oracle/src/lib.rs b/distance-oracle/src/lib.rs index d169c4f7a..be8b8432e 100644 --- a/distance-oracle/src/lib.rs +++ b/distance-oracle/src/lib.rs @@ -158,7 +158,7 @@ pub async fn run( }; // 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"); return None; } @@ -228,8 +228,8 @@ pub async fn run( let referees = members; let evaluation = evaluation_pool + .evaluations .0 - .0 .as_slice() .par_iter() .map(|(idty, _)| distance_rule(&received_certs, &referees, settings.max_depth, *idty)) diff --git a/distance-oracle/src/mock.rs b/distance-oracle/src/mock.rs index 54798d976..1ecc7a74c 100644 --- a/distance-oracle/src/mock.rs +++ b/distance-oracle/src/mock.rs @@ -28,8 +28,11 @@ pub struct Client { } pub type AccountId = subxt::ext::sp_runtime::AccountId32; 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 { unimplemented!() @@ -52,8 +55,8 @@ pub async fn current_pool( _parent_hash: H256, _current_session: u32, ) -> Option<EvaluationPool<AccountId, IdtyIndex>> { - Some(( - (client + Some(EvaluationPool { + evaluations: (client .wot .get_enabled() .into_iter() @@ -65,8 +68,8 @@ pub async fn current_pool( }) }) .collect(),), - std::collections::BTreeSet::new(), - )) + evaluators: BTreeSet::new(), + }) } pub async fn evaluation_block(_client: &Client, _parent_hash: H256) -> H256 { diff --git a/end2end-tests/tests/cucumber_tests.rs b/end2end-tests/tests/cucumber_tests.rs index 47206990a..49177f72c 100644 --- a/end2end-tests/tests/cucumber_tests.rs +++ b/end2end-tests/tests/cucumber_tests.rs @@ -494,7 +494,7 @@ async fn should_have_distance_result_in_sessions( .unwrap() .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 { return Ok(()); } -- GitLab