diff --git a/distance-oracle/src/api.rs b/distance-oracle/src/api.rs index 0c08c72658988bb0982eb77d4b1722f10d9868b6..b8d3e9fe07f9b890b04913f1ebc566322e34bdf7 100644 --- a/distance-oracle/src/api.rs +++ b/distance-oracle/src/api.rs @@ -14,23 +14,14 @@ // 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, - }, -}; -use sp_core::bounded::{bounded_btree_set::BoundedBTreeSet, bounded_vec::BoundedVec}; +use crate::runtime; + use sp_core::H256; 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>), u32>, // FIXME is u32 still the good type? - BoundedBTreeSet<AccountId, u32>, // FIXME idem -); pub async fn client(rpc_url: String) -> Client { Client::from_url(rpc_url) @@ -63,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 eb76d9a3657688e1e06b79c3976a25097f59c4f8..738e43bbcb06c92a87508ea7a1372401e7b406dd 100644 --- a/distance-oracle/src/lib.rs +++ b/distance-oracle/src/lib.rs @@ -160,7 +160,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; } @@ -230,8 +230,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 54798d9761965ce4648a0961dcecc0cdbc3fec4b..1ecc7a74c2d91fc36d3b0887c5e47081ffe2e881 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 3eafeb2f4f0ecc86f3bb819360d6593af843fb93..dc30d816a1afde0f0002a85dc34be80ee1f2c5b8 100644 --- a/end2end-tests/tests/cucumber_tests.rs +++ b/end2end-tests/tests/cucumber_tests.rs @@ -508,7 +508,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(()); }