From 4d0c7fd5cf093988f91aab315eda938d2eef7406 Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sat, 28 May 2022 10:56:35 +0200 Subject: [PATCH] ref(wot): remove WotDiffs --- pallets/duniter-wot/src/lib.rs | 52 ++------------------------------ pallets/duniter-wot/src/tests.rs | 21 +------------ 2 files changed, 4 insertions(+), 69 deletions(-) diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 6a716b715..ee23ecf9b 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -33,7 +33,6 @@ pub use pallet::*; pub use types::*; use frame_support::pallet_prelude::*; -use frame_system::pallet_prelude::BlockNumberFor; use frame_system::RawOrigin; use pallet_certification::traits::SetNextIssuableOn; use pallet_identity::{IdtyEvent, IdtyStatus}; @@ -47,7 +46,6 @@ pub mod pallet { use super::*; use frame_support::dispatch::UnfilteredDispatchable; use frame_support::traits::StorageVersion; - use sp_std::vec::Vec; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); @@ -73,34 +71,6 @@ pub mod pallet { type MinCertForCreateIdtyRight: Get<u32>; } - // STORAGE // - - #[pallet::storage] - #[pallet::getter(fn wot_diffs)] - pub(super) type WotDiffs<T: Config<I>, I: 'static = ()> = - StorageValue<_, Vec<WotDiff>, ValueQuery>; - - // HOOKS // - - #[pallet::hooks] - impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> { - fn on_initialize(_: T::BlockNumber) -> Weight { - 0 - } - fn on_finalize(block_number: T::BlockNumber) { - const OFFCHAIN_WOT_DIFFS_KEY: &[u8] = b"ocw/wot-diffs/"; - let diffs = WotDiffs::<T, I>::take(); - let key = block_number.using_encoded(|encoded_block_number| { - OFFCHAIN_WOT_DIFFS_KEY - .iter() - .chain(encoded_block_number) - .copied() - .collect::<Vec<u8>>() - }); - sp_io::offchain_index::set(&key, &diffs.encode()); - } - } - // INTERNAL FUNCTIONS // impl<T: Config<I>, I: 'static> Pallet<T, I> { @@ -215,20 +185,13 @@ where { fn on_event(membership_event: &sp_membership::Event<IdtyIndex, MetaData>) -> Weight { match membership_event { - sp_membership::Event::<IdtyIndex, MetaData>::MembershipAcquired(idty_index, _) => { - if !T::IsSubWot::get() { - WotDiffs::<T, I>::append(WotDiff::AddNode(*idty_index)); - } - } + sp_membership::Event::<IdtyIndex, MetaData>::MembershipAcquired(_, _) => {} sp_membership::Event::<IdtyIndex, MetaData>::MembershipExpired(idty_index) | sp_membership::Event::<IdtyIndex, MetaData>::MembershipRevoked(idty_index) => { Self::dispath_idty_call(pallet_identity::Call::remove_identity { idty_index: *idty_index, idty_name: None, }); - if !T::IsSubWot::get() { - WotDiffs::<T, I>::append(WotDiff::DisableNode(*idty_index)); - } } sp_membership::Event::<IdtyIndex, MetaData>::MembershipRenewed(_) => {} sp_membership::Event::<IdtyIndex, MetaData>::MembershipRequested(idty_index) => { @@ -283,7 +246,7 @@ impl<T: Config<I>, I: 'static> pallet_identity::traits::OnIdtyChange<T> for Pall impl<T: Config<I>, I: 'static> pallet_certification::traits::OnNewcert<IdtyIndex> for Pallet<T, I> { fn on_new_cert( - issuer: IdtyIndex, + _issuer: IdtyIndex, _issuer_issued_count: u32, receiver: IdtyIndex, receiver_received_count: u32, @@ -292,9 +255,6 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnNewcert<IdtyIndex if receiver_received_count == T::MinReceivedCertToBeAbleToIssueCert::get() { Self::do_apply_first_issuable_on(receiver); } - if T::IsSubWot::get() { - WotDiffs::<T, I>::append(WotDiff::AddLink(issuer, receiver)); - } } else if pallet_membership::Pallet::<T, I>::is_in_pending_memberships(receiver) && receiver_received_count >= T::MinCertForMembership::get() { @@ -312,9 +272,6 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnNewcert<IdtyIndex Self::dispath_idty_call(pallet_identity::Call::validate_identity { idty_index: receiver, }); - for issuer in pallet_certification::Pallet::<T, I>::certs_by_receiver(receiver) { - WotDiffs::<T, I>::append(WotDiff::AddLink(issuer, receiver)); - } } if receiver_received_count == T::MinReceivedCertToBeAbleToIssueCert::get() { @@ -329,7 +286,7 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnRemovedCert<IdtyI for Pallet<T, I> { fn on_removed_cert( - issuer: IdtyIndex, + _issuer: IdtyIndex, _issuer_issued_count: u32, receiver: IdtyIndex, receiver_received_count: u32, @@ -348,9 +305,6 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnRemovedCert<IdtyI } } } - if !T::IsSubWot::get() { - WotDiffs::<T, I>::append(WotDiff::DelLink(issuer, receiver)); - } 0 } } diff --git a/pallets/duniter-wot/src/tests.rs b/pallets/duniter-wot/src/tests.rs index 42f255fa8..ab9dca2de 100644 --- a/pallets/duniter-wot/src/tests.rs +++ b/pallets/duniter-wot/src/tests.rs @@ -16,7 +16,6 @@ use crate::mock::Identity; use crate::mock::*; -use crate::WotDiff; use frame_support::assert_err; use frame_support::assert_ok; use frame_support::instances::Instance1; @@ -87,7 +86,6 @@ fn test_create_idty_ok() { ); assert_eq!(Identity::identity(6).unwrap().status, IdtyStatus::Created); assert_eq!(Identity::identity(6).unwrap().removable_on, 4); - assert!(DuniterWot::wot_diffs().is_empty()); }); } @@ -105,9 +103,6 @@ fn test_new_idty_validation() { IdtyName::from("Ferdie"), )); - // Ferdie is not yet validated, so there should be no wot diff - assert!(DuniterWot::wot_diffs().is_empty()); - // Bob should be able to certify Ferdie run_to_block(4); assert_ok!(Cert::add_cert(Origin::signed(2), 6)); @@ -144,17 +139,6 @@ fn test_new_idty_validation() { topics: vec![], } ); - - // Ferdie has just been validated, so the wot diff should contain her entry and all her - // certifications - assert_eq!( - DuniterWot::wot_diffs(), - vec![ - WotDiff::AddNode(6), - WotDiff::AddLink(1, 6), - WotDiff::AddLink(2, 6) - ] - ); }); } @@ -231,7 +215,6 @@ fn test_idty_membership_expire_them_requested() { topics: vec![], } ); - assert_eq!(DuniterWot::wot_diffs(), vec![WotDiff::DisableNode(3),]); // Charlie's identity should be removed at block #5 assert!(Identity::identity(3).is_none()); @@ -275,8 +258,6 @@ fn test_idty_membership_expire_them_requested() { event: Event::Identity(pallet_identity::Event::IdtyValidated(3)), topics: vec![], } - ); - - assert_eq!(DuniterWot::wot_diffs(), vec![WotDiff::AddNode(3),]);*/ + );*/ }); } -- GitLab