diff --git a/distance-oracle/src/api.rs b/distance-oracle/src/api.rs index 3af39b736d557280609b320c0fbb44c709d9277f..ee5ce2587325f15a61cc08c09e723b732a68929c 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 d169c4f7a41b92010b967d7f562797fff70f5707..be8b8432eb500d46ac8b30502371c6564e8eba33 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 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 47206990acae821ed80271ffa695a5f18a7a6a1e..49177f72cd32eb2bb5454eed3fe7eccf42ba3cca 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(()); }