From d215bea9618ded35df53f2459ea025f5be94e41a Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 11:11:30 +0100 Subject: [PATCH 01/24] Update toolchain versions --- .gitlab-ci.yml | 4 ++-- .maintain/srtool.Dockerfile | 2 +- crates/assets/Cargo.toml | 2 -- nodes/parachain/Cargo.toml | 2 -- nodes/standalone/Cargo.toml | 2 -- pallets/attestation/Cargo.toml | 2 -- pallets/ctype/Cargo.toml | 2 -- pallets/delegation/Cargo.toml | 2 -- pallets/did/Cargo.toml | 2 -- pallets/pallet-did-lookup/Cargo.toml | 2 -- pallets/pallet-inflation/Cargo.toml | 2 -- pallets/pallet-web3-names/Cargo.toml | 2 -- pallets/parachain-staking/Cargo.toml | 2 -- pallets/public-credentials/Cargo.toml | 2 -- runtime-api/did/Cargo.toml | 2 -- runtime-api/public-credentials/Cargo.toml | 2 -- runtime-api/staking/Cargo.toml | 2 -- runtimes/clone/Cargo.toml | 2 -- runtimes/common/Cargo.toml | 2 -- runtimes/peregrine/Cargo.toml | 2 -- runtimes/spiritnet/Cargo.toml | 2 -- runtimes/standalone/Cargo.toml | 2 -- rust-toolchain.toml | 3 ++- support/Cargo.toml | 2 -- 24 files changed, 5 insertions(+), 46 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b66878f7e..089afb7ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ clippy: stage: test timeout: 1 hours script: - - rustup component add clippy --toolchain nightly + - rustup update - cargo +nightly clippy --all-features --all-targets --locked -- -D warnings fmt: @@ -19,7 +19,7 @@ fmt: stage: test timeout: 1 hours script: - - rustup component add rustfmt --toolchain nightly + - rustup update - cargo +nightly fmt -- --check test: diff --git a/.maintain/srtool.Dockerfile b/.maintain/srtool.Dockerfile index 65dda3ce0..717c6fd4c 100644 --- a/.maintain/srtool.Dockerfile +++ b/.maintain/srtool.Dockerfile @@ -3,7 +3,7 @@ FROM docker.io/library/ubuntu:22.04 LABEL maintainer "chevdor@gmail.com" LABEL description="This image contains tools for Substrate blockchains runtimes." -ARG RUSTC_VERSION="1.62.0" +ARG RUSTC_VERSION="1.64.0" ENV RUSTC_VERSION=$RUSTC_VERSION ENV DOCKER_IMAGE="paritytech/srtool" ENV PROFILE=release diff --git a/crates/assets/Cargo.toml b/crates/assets/Cargo.toml index b1646a781..a233d94ee 100644 --- a/crates/assets/Cargo.toml +++ b/crates/assets/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/nodes/parachain/Cargo.toml b/nodes/parachain/Cargo.toml index 2ba531a9f..06cfc79be 100644 --- a/nodes/parachain/Cargo.toml +++ b/nodes/parachain/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/nodes/standalone/Cargo.toml b/nodes/standalone/Cargo.toml index 5328bd189..6efa52a15 100644 --- a/nodes/standalone/Cargo.toml +++ b/nodes/standalone/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/attestation/Cargo.toml b/pallets/attestation/Cargo.toml index 2be22eecc..6c66c902c 100644 --- a/pallets/attestation/Cargo.toml +++ b/pallets/attestation/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/ctype/Cargo.toml b/pallets/ctype/Cargo.toml index 7f074f402..86086fa2f 100644 --- a/pallets/ctype/Cargo.toml +++ b/pallets/ctype/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/delegation/Cargo.toml b/pallets/delegation/Cargo.toml index 23ecef4a6..691e6138d 100644 --- a/pallets/delegation/Cargo.toml +++ b/pallets/delegation/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/did/Cargo.toml b/pallets/did/Cargo.toml index b801840d3..5aaaef86e 100644 --- a/pallets/did/Cargo.toml +++ b/pallets/did/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/pallet-did-lookup/Cargo.toml b/pallets/pallet-did-lookup/Cargo.toml index 37350f458..a44b2cc92 100644 --- a/pallets/pallet-did-lookup/Cargo.toml +++ b/pallets/pallet-did-lookup/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/pallet-inflation/Cargo.toml b/pallets/pallet-inflation/Cargo.toml index fd7075157..dc4f5de4b 100644 --- a/pallets/pallet-inflation/Cargo.toml +++ b/pallets/pallet-inflation/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/pallet-web3-names/Cargo.toml b/pallets/pallet-web3-names/Cargo.toml index 6074fd21d..6cd3f5da4 100644 --- a/pallets/pallet-web3-names/Cargo.toml +++ b/pallets/pallet-web3-names/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index 3e6a8e08e..85933c673 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/pallets/public-credentials/Cargo.toml b/pallets/public-credentials/Cargo.toml index 52899c206..8fc5f7dc7 100644 --- a/pallets/public-credentials/Cargo.toml +++ b/pallets/public-credentials/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtime-api/did/Cargo.toml b/runtime-api/did/Cargo.toml index dd9a182d9..51a5972eb 100644 --- a/runtime-api/did/Cargo.toml +++ b/runtime-api/did/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtime-api/public-credentials/Cargo.toml b/runtime-api/public-credentials/Cargo.toml index 03306deb9..4d983407b 100644 --- a/runtime-api/public-credentials/Cargo.toml +++ b/runtime-api/public-credentials/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtime-api/staking/Cargo.toml b/runtime-api/staking/Cargo.toml index 4e558ad32..aad32cd56 100644 --- a/runtime-api/staking/Cargo.toml +++ b/runtime-api/staking/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtimes/clone/Cargo.toml b/runtimes/clone/Cargo.toml index 0d69ce902..08d04490e 100644 --- a/runtimes/clone/Cargo.toml +++ b/runtimes/clone/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtimes/common/Cargo.toml b/runtimes/common/Cargo.toml index d52a09082..9c3aec069 100644 --- a/runtimes/common/Cargo.toml +++ b/runtimes/common/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtimes/peregrine/Cargo.toml b/runtimes/peregrine/Cargo.toml index 236a78fcd..30302fdb9 100644 --- a/runtimes/peregrine/Cargo.toml +++ b/runtimes/peregrine/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtimes/spiritnet/Cargo.toml b/runtimes/spiritnet/Cargo.toml index 389b1d2bb..b54269083 100644 --- a/runtimes/spiritnet/Cargo.toml +++ b/runtimes/spiritnet/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/runtimes/standalone/Cargo.toml b/runtimes/standalone/Cargo.toml index df39ef582..279a5f8f3 100644 --- a/runtimes/standalone/Cargo.toml +++ b/runtimes/standalone/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 514ced16b..c3889eb24 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,4 @@ [toolchain] -channel = "nightly-2022-07-24" +channel = "nightly" +components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] diff --git a/support/Cargo.toml b/support/Cargo.toml index e0a94fb7d..37210d044 100644 --- a/support/Cargo.toml +++ b/support/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["workspace-inheritance"] - [package] authors.workspace = true documentation.workspace = true From 96eacc99f75213bad4d99f80b5317c492dbcbccc Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 11:40:23 +0100 Subject: [PATCH 02/24] Address new clippy warnings --- .gitlab-ci.yml | 3 +- nodes/parachain/src/command.rs | 2 +- nodes/standalone/src/benchmarking.rs | 2 +- pallets/attestation/src/benchmarking.rs | 12 +++--- pallets/attestation/src/lib.rs | 20 +++++----- pallets/attestation/src/mock.rs | 2 +- pallets/ctype/src/benchmarking.rs | 2 +- pallets/ctype/src/lib.rs | 4 +- pallets/delegation/src/benchmarking.rs | 4 +- pallets/delegation/src/lib.rs | 24 +++++------ pallets/did/src/benchmarking.rs | 4 +- pallets/did/src/lib.rs | 6 +-- pallets/did/src/mock.rs | 6 +-- pallets/pallet-did-lookup/src/account.rs | 4 +- pallets/pallet-did-lookup/src/benchmarking.rs | 2 +- pallets/pallet-did-lookup/src/lib.rs | 6 +-- pallets/pallet-did-lookup/src/tests.rs | 32 +++++++-------- pallets/pallet-web3-names/src/lib.rs | 12 +++--- pallets/parachain-staking/src/benchmarking.rs | 6 +-- pallets/parachain-staking/src/lib.rs | 6 +-- .../public-credentials/src/benchmarking.rs | 14 +++---- pallets/public-credentials/src/lib.rs | 12 +++--- pallets/public-credentials/src/tests.rs | 40 +++++++++---------- runtimes/peregrine/src/lib.rs | 6 +-- runtimes/spiritnet/src/lib.rs | 6 +-- runtimes/standalone/src/lib.rs | 6 +-- rust-toolchain.toml | 2 +- 27 files changed, 122 insertions(+), 123 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 089afb7ba..aa87b020c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ clippy: stage: test timeout: 1 hours script: - - rustup update + - rustup show - cargo +nightly clippy --all-features --all-targets --locked -- -D warnings fmt: @@ -19,7 +19,6 @@ fmt: stage: test timeout: 1 hours script: - - rustup update - cargo +nightly fmt -- --check test: diff --git a/nodes/parachain/src/command.rs b/nodes/parachain/src/command.rs index 9fd2e263e..d012ed6d7 100644 --- a/nodes/parachain/src/command.rs +++ b/nodes/parachain/src/command.rs @@ -406,7 +406,7 @@ pub fn run() -> Result<()> { runner.run_node_until_exit(|config| async move { let hwbench = if !cli.no_hardware_benchmarks { config.database.path().map(|database_path| { - let _ = std::fs::create_dir_all(&database_path); + let _ = std::fs::create_dir_all(database_path); sc_sysinfo::gather_hwbench(Some(database_path)) }) } else { diff --git a/nodes/standalone/src/benchmarking.rs b/nodes/standalone/src/benchmarking.rs index 08a52335e..0206c3d58 100644 --- a/nodes/standalone/src/benchmarking.rs +++ b/nodes/standalone/src/benchmarking.rs @@ -130,7 +130,7 @@ pub fn create_benchmark_extrinsic( let period = runtime::BlockHashCount::get() .checked_next_power_of_two() .map(|c| c / 2) - .unwrap_or(2) as u64; + .unwrap_or(2); let extra: runtime::SignedExtra = ( frame_system::CheckNonZeroSender::::new(), frame_system::CheckSpecVersion::::new(), diff --git a/pallets/attestation/src/benchmarking.rs b/pallets/attestation/src/benchmarking.rs index 59edb493d..479e0a65d 100644 --- a/pallets/attestation/src/benchmarking.rs +++ b/pallets/attestation/src/benchmarking.rs @@ -41,7 +41,7 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester.clone()); @@ -66,7 +66,7 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester.clone()); @@ -92,7 +92,7 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester.clone()); @@ -109,7 +109,7 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester); @@ -127,7 +127,7 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); ::Currency::make_free_balance_be(&deposit_owner_old, ::Deposit::get() + ::Deposit::get()); ::Currency::make_free_balance_be(&deposit_owner_new, ::Deposit::get() + ::Deposit::get()); @@ -154,7 +154,7 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); ::Currency::make_free_balance_be(&deposit_owner, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(deposit_owner.clone(), attester.clone()); diff --git a/pallets/attestation/src/lib.rs b/pallets/attestation/src/lib.rs index 6782a8d68..e01e25f86 100644 --- a/pallets/attestation/src/lib.rs +++ b/pallets/attestation/src/lib.rs @@ -246,11 +246,11 @@ pub mod pallet { let deposit_amount = ::Deposit::get(); ensure!( - ctype::Ctypes::::contains_key(&ctype_hash), + ctype::Ctypes::::contains_key(ctype_hash), ctype::Error::::CTypeNotFound ); ensure!( - !Attestations::::contains_key(&claim_hash), + !Attestations::::contains_key(claim_hash), Error::::AlreadyAttested ); @@ -268,7 +268,7 @@ pub mod pallet { log::debug!("insert Attestation"); Attestations::::insert( - &claim_hash, + claim_hash, AttestationDetails { ctype_hash, attester: who.clone(), @@ -315,7 +315,7 @@ pub mod pallet { let source = ::EnsureOrigin::ensure_origin(origin)?; let who = source.subject(); - let attestation = Attestations::::get(&claim_hash).ok_or(Error::::AttestationNotFound)?; + let attestation = Attestations::::get(claim_hash).ok_or(Error::::AttestationNotFound)?; ensure!(!attestation.revoked, Error::::AlreadyRevoked); @@ -333,7 +333,7 @@ pub mod pallet { log::debug!("revoking Attestation"); Attestations::::insert( - &claim_hash, + claim_hash, AttestationDetails { revoked: true, ..attestation @@ -374,7 +374,7 @@ pub mod pallet { let source = ::EnsureOrigin::ensure_origin(origin)?; let who = source.subject(); - let attestation = Attestations::::get(&claim_hash).ok_or(Error::::AttestationNotFound)?; + let attestation = Attestations::::get(claim_hash).ok_or(Error::::AttestationNotFound)?; if attestation.attester != who { let attestation_auth_id = attestation.authorization_id.as_ref().ok_or(Error::::Unauthorized)?; @@ -408,7 +408,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::reclaim_deposit())] pub fn reclaim_deposit(origin: OriginFor, claim_hash: ClaimHashOf) -> DispatchResult { let who = ensure_signed(origin)?; - let attestation = Attestations::::get(&claim_hash).ok_or(Error::::AttestationNotFound)?; + let attestation = Attestations::::get(claim_hash).ok_or(Error::::AttestationNotFound)?; ensure!(attestation.deposit.owner == who, Error::::Unauthorized); @@ -435,7 +435,7 @@ pub mod pallet { let subject = source.subject(); let sender = source.sender(); - let attestation = Attestations::::get(&claim_hash).ok_or(Error::::AttestationNotFound)?; + let attestation = Attestations::::get(claim_hash).ok_or(Error::::AttestationNotFound)?; ensure!(attestation.attester == subject, Error::::Unauthorized); AttestationStorageDepositCollector::::change_deposit_owner(&claim_hash, sender)?; @@ -450,7 +450,7 @@ pub mod pallet { pub fn update_deposit(origin: OriginFor, claim_hash: ClaimHashOf) -> DispatchResult { let sender = ensure_signed(origin)?; - let attestation = Attestations::::get(&claim_hash).ok_or(Error::::AttestationNotFound)?; + let attestation = Attestations::::get(claim_hash).ok_or(Error::::AttestationNotFound)?; ensure!(attestation.deposit.owner == sender, Error::::Unauthorized); AttestationStorageDepositCollector::::update_deposit(&claim_hash)?; @@ -462,7 +462,7 @@ pub mod pallet { impl Pallet { fn remove_attestation(attestation: AttestationDetails, claim_hash: ClaimHashOf) { kilt_support::free_deposit::, CurrencyOf>(&attestation.deposit); - Attestations::::remove(&claim_hash); + Attestations::::remove(claim_hash); if let Some(authorization_id) = &attestation.authorization_id { ExternalAttestations::::remove(authorization_id, claim_hash); } diff --git a/pallets/attestation/src/mock.rs b/pallets/attestation/src/mock.rs index 98d7099ef..489d7b08a 100644 --- a/pallets/attestation/src/mock.rs +++ b/pallets/attestation/src/mock.rs @@ -159,7 +159,7 @@ pub fn insert_attestation(claim_hash: ClaimHashOf, details: Attest ) .expect("Should have balance"); - crate::Attestations::::insert(&claim_hash, details.clone()); + crate::Attestations::::insert(claim_hash, details.clone()); if let Some(delegation_id) = details.authorization_id.as_ref() { crate::ExternalAttestations::::insert(delegation_id, claim_hash, true) } diff --git a/pallets/ctype/src/benchmarking.rs b/pallets/ctype/src/benchmarking.rs index 1f18daf7b..95726055c 100644 --- a/pallets/ctype/src/benchmarking.rs +++ b/pallets/ctype/src/benchmarking.rs @@ -57,7 +57,7 @@ benchmarks! { }: _(origin, ctype) verify { - let stored_ctype_creator: T::CtypeCreatorId = Ctypes::::get(&ctype_hash).expect("CType hash should be present on chain."); + let stored_ctype_creator: T::CtypeCreatorId = Ctypes::::get(ctype_hash).expect("CType hash should be present on chain."); // Verify the CType has the right owner assert_eq!(stored_ctype_creator, did); diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 787a45f70..73f84d530 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -160,7 +160,7 @@ pub mod pallet { let hash = ::Hashing::hash(&ctype[..]); - ensure!(!Ctypes::::contains_key(&hash), Error::::CTypeAlreadyExists); + ensure!(!Ctypes::::contains_key(hash), Error::::CTypeAlreadyExists); // *** No Fail except during withdraw beyond this point *** @@ -176,7 +176,7 @@ pub mod pallet { T::FeeCollector::on_unbalanced(imbalance); log::debug!("Creating CType with hash {:?} and creator {:?}", hash, creator); - Ctypes::::insert(&hash, creator.clone()); + Ctypes::::insert(hash, creator.clone()); Self::deposit_event(Event::CTypeCreated(creator, hash)); diff --git a/pallets/delegation/src/benchmarking.rs b/pallets/delegation/src/benchmarking.rs index 3b2974355..dcf922b34 100644 --- a/pallets/delegation/src/benchmarking.rs +++ b/pallets/delegation/src/benchmarking.rs @@ -74,7 +74,7 @@ where ::Currency::minimum_balance() + ::Deposit::get() + ::Deposit::get(), ); - ctype::Ctypes::::insert(&ctype_hash, T::CtypeCreatorId::from(root_acc.clone())); + ctype::Ctypes::::insert(ctype_hash, T::CtypeCreatorId::from(root_acc.clone())); Pallet::::create_hierarchy( ::EnsureOrigin::generate_origin(sender, root_acc.clone()), @@ -234,7 +234,7 @@ benchmarks! { let creator: T::DelegationEntityId = account("creator", 0, SEED); let ctype = ::default(); let delegation = generate_delegation_id::(0); - ctype::Ctypes::::insert(&ctype, ::CtypeCreatorId::from(creator.clone())); + ctype::Ctypes::::insert(ctype, ::CtypeCreatorId::from(creator.clone())); ::Currency::make_free_balance_be( &sender, ::Currency::minimum_balance() + ::Deposit::get(), diff --git a/pallets/delegation/src/lib.rs b/pallets/delegation/src/lib.rs index d2bfa7633..c6975ed07 100644 --- a/pallets/delegation/src/lib.rs +++ b/pallets/delegation/src/lib.rs @@ -324,12 +324,12 @@ pub mod pallet { let creator = source.subject(); ensure!( - !>::contains_key(&root_node_id), + !>::contains_key(root_node_id), Error::::HierarchyAlreadyExists ); ensure!( - >::contains_key(&ctype_hash), + >::contains_key(ctype_hash), >::CTypeNotFound ); @@ -397,11 +397,11 @@ pub mod pallet { let delegator = source.subject(); ensure!( - !>::contains_key(&delegation_id), + !>::contains_key(delegation_id), Error::::DelegationAlreadyExists ); - let parent_node = >::get(&parent_id).ok_or(Error::::ParentDelegationNotFound)?; + let parent_node = >::get(parent_id).ok_or(Error::::ParentDelegationNotFound)?; let hierarchy_root_id = parent_node.hierarchy_root_id; // Calculate the hash root @@ -501,7 +501,7 @@ pub mod pallet { let invoker = ::EnsureOrigin::ensure_origin(origin)?.subject(); ensure!( - >::contains_key(&delegation_id), + >::contains_key(delegation_id), Error::::DelegationNotFound ); @@ -525,7 +525,7 @@ pub mod pallet { let (revocation_checks, _) = Self::revoke(&delegation_id, &invoker, max_revocations.saturating_add(1))?; // If the revoked node is a root node, emit also a HierarchyRevoked event. - if DelegationHierarchies::::contains_key(&delegation_id) { + if DelegationHierarchies::::contains_key(delegation_id) { Self::deposit_event(Event::HierarchyRevoked(invoker, delegation_id)); } @@ -574,7 +574,7 @@ pub mod pallet { let source = ::EnsureOrigin::ensure_origin(origin)?; let invoker = source.subject(); - let delegation = DelegationNodes::::get(&delegation_id).ok_or(Error::::DelegationNotFound)?; + let delegation = DelegationNodes::::get(delegation_id).ok_or(Error::::DelegationNotFound)?; // Node can only be removed by owner of the node, not the parent or another // ancestor @@ -589,7 +589,7 @@ pub mod pallet { let (removal_checks, _) = Self::remove(&delegation_id, max_removals.saturating_add(1))?; // If the removed node is a root node, emit also a HierarchyRemoved event. - if DelegationHierarchies::::take(&delegation_id).is_some() { + if DelegationHierarchies::::take(delegation_id).is_some() { Self::deposit_event(Event::HierarchyRemoved(invoker, delegation_id)); } @@ -628,7 +628,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - let delegation = DelegationNodes::::get(&delegation_id).ok_or(Error::::DelegationNotFound)?; + let delegation = DelegationNodes::::get(delegation_id).ok_or(Error::::DelegationNotFound)?; // Deposit can only be removed by the owner of the deposit, not the // parent or another ancestor. @@ -646,7 +646,7 @@ pub mod pallet { // Delete the delegation hierarchy details, if the provided ID was for a root // node. No event generated as we don't have information about the owner DID // here. - DelegationHierarchies::::remove(&delegation_id); + DelegationHierarchies::::remove(delegation_id); Ok(Some(::WeightInfo::remove_delegation(removal_checks)).into()) } @@ -662,7 +662,7 @@ pub mod pallet { pub fn change_deposit_owner(origin: OriginFor, delegation_id: DelegationNodeIdOf) -> DispatchResult { let source = ::EnsureOrigin::ensure_origin(origin)?; - let delegation = DelegationNodes::::get(&delegation_id).ok_or(Error::::DelegationNotFound)?; + let delegation = DelegationNodes::::get(delegation_id).ok_or(Error::::DelegationNotFound)?; // Deposit can only be swapped by the owner of the delegation node, not the // parent or another ancestor. @@ -678,7 +678,7 @@ pub mod pallet { pub fn update_deposit(origin: OriginFor, delegation_id: DelegationNodeIdOf) -> DispatchResult { let sender = ensure_signed(origin)?; - let delegation = DelegationNodes::::get(&delegation_id).ok_or(Error::::DelegationNotFound)?; + let delegation = DelegationNodes::::get(delegation_id).ok_or(Error::::DelegationNotFound)?; // Deposit can only be swapped by the owner of the delegation node, not the // parent or another ancestor. diff --git a/pallets/did/src/benchmarking.rs b/pallets/did/src/benchmarking.rs index f9db408cd..8992a5625 100644 --- a/pallets/did/src/benchmarking.rs +++ b/pallets/did/src/benchmarking.rs @@ -115,9 +115,9 @@ fn generate_base_did_call_operation( fn save_service_endpoints(did_subject: &DidIdentifierOf, endpoints: &[DidEndpoint]) { for endpoint in endpoints.iter() { - ServiceEndpoints::::insert(&did_subject, &endpoint.id, endpoint.clone()); + ServiceEndpoints::::insert(did_subject, &endpoint.id, endpoint.clone()); } - DidEndpointsCount::::insert(&did_subject, endpoints.len().saturated_into::()); + DidEndpointsCount::::insert(did_subject, endpoints.len().saturated_into::()); } benchmarks! { diff --git a/pallets/did/src/lib.rs b/pallets/did/src/lib.rs index cfa7e0dc5..ba27ddcc4 100644 --- a/pallets/did/src/lib.rs +++ b/pallets/did/src/lib.rs @@ -1244,7 +1244,7 @@ pub mod pallet { fn deposit( key: &DidIdentifierOf, ) -> Result, >>::Balance>, DispatchError> { - let did_entry = Did::::get(&key).ok_or(Error::::DidNotPresent)?; + let did_entry = Did::::get(key).ok_or(Error::::DidNotPresent)?; Ok(did_entry.deposit) } @@ -1256,8 +1256,8 @@ pub mod pallet { key: &DidIdentifierOf, deposit: Deposit, >>::Balance>, ) -> Result<(), DispatchError> { - let did_entry = Did::::get(&key).ok_or(Error::::DidNotPresent)?; - Did::::insert(&key, DidDetails { deposit, ..did_entry }); + let did_entry = Did::::get(key).ok_or(Error::::DidNotPresent)?; + Did::::insert(key, DidDetails { deposit, ..did_entry }); Ok(()) } diff --git a/pallets/did/src/mock.rs b/pallets/did/src/mock.rs index 537911a72..e9f906f68 100644 --- a/pallets/did/src/mock.rs +++ b/pallets/did/src/mock.rs @@ -481,13 +481,13 @@ impl ExtBuilder { .expect("Deposit owner should have enough balance"); } for did in self.deleted_dids.iter() { - DidBlacklist::::insert(&did, ()); + DidBlacklist::::insert(did, ()); } for (did, endpoints) in self.service_endpoints.iter() { for endpoint in endpoints.iter() { - ServiceEndpoints::::insert(&did, &endpoint.id, endpoint) + ServiceEndpoints::::insert(did, &endpoint.id, endpoint) } - DidEndpointsCount::::insert(&did, endpoints.len().saturated_into::()); + DidEndpointsCount::::insert(did, endpoints.len().saturated_into::()); } }); diff --git a/pallets/pallet-did-lookup/src/account.rs b/pallets/pallet-did-lookup/src/account.rs index b6eb29a93..057bc7f1c 100644 --- a/pallets/pallet-did-lookup/src/account.rs +++ b/pallets/pallet-did-lookup/src/account.rs @@ -111,7 +111,7 @@ impl From for EthereumSigner { fn from(x: libsecp256k1::PublicKey) -> Self { let mut m = [0u8; 64]; m.copy_from_slice(&x.serialize()[1..65]); - let account = H160::from(H256::from_slice(Keccak256::digest(&m).as_slice())); + let account = H160::from(H256::from_slice(Keccak256::digest(m).as_slice())); EthereumSigner(account.into()) } } @@ -141,7 +141,7 @@ impl sp_runtime::traits::Verify for EthereumSignature { Ok(pubkey) => { // TODO This conversion could use a comment. Why H256 first, then H160? // TODO actually, there is probably just a better way to go from Keccak digest. - AccountId20(H160::from(H256::from_slice(Keccak256::digest(&pubkey).as_slice())).0) == *signer + AccountId20(H160::from(H256::from_slice(Keccak256::digest(pubkey).as_slice())).0) == *signer } Err(_) => { log::trace!("Error verifying signature"); diff --git a/pallets/pallet-did-lookup/src/benchmarking.rs b/pallets/pallet-did-lookup/src/benchmarking.rs index e24c0ec29..e3d85c963 100644 --- a/pallets/pallet-did-lookup/src/benchmarking.rs +++ b/pallets/pallet-did-lookup/src/benchmarking.rs @@ -176,7 +176,7 @@ benchmarks! { let sig = sp_io::crypto::ecdsa_sign_prehashed( KeyTypeId(*b"aura"), ð_public_key, - &Keccak256::digest(&wrapped_payload).try_into().unwrap(), + &Keccak256::digest(wrapped_payload).try_into().unwrap(), ).ok_or("Error while building signature.")?; make_free_for_did::(&caller); diff --git a/pallets/pallet-did-lookup/src/lib.rs b/pallets/pallet-did-lookup/src/lib.rs index 5c14302e7..a660322a4 100644 --- a/pallets/pallet-did-lookup/src/lib.rs +++ b/pallets/pallet-did-lookup/src/lib.rs @@ -380,7 +380,7 @@ pub mod pallet { fn deposit( key: &LinkableAccountId, ) -> Result, >>::Balance>, DispatchError> { - let record = ConnectedDids::::get(&key).ok_or(Error::::AssociationNotFound)?; + let record = ConnectedDids::::get(key).ok_or(Error::::AssociationNotFound)?; Ok(record.deposit) } @@ -392,8 +392,8 @@ pub mod pallet { key: &LinkableAccountId, deposit: Deposit, >>::Balance>, ) -> Result<(), DispatchError> { - let record = ConnectedDids::::get(&key).ok_or(Error::::AssociationNotFound)?; - ConnectedDids::::insert(&key, ConnectionRecord { deposit, ..record }); + let record = ConnectedDids::::get(key).ok_or(Error::::AssociationNotFound)?; + ConnectedDids::::insert(key, ConnectionRecord { deposit, ..record }); Ok(()) } diff --git a/pallets/pallet-did-lookup/src/tests.rs b/pallets/pallet-did-lookup/src/tests.rs index 27864d4f1..9b2b77073 100644 --- a/pallets/pallet-did-lookup/src/tests.rs +++ b/pallets/pallet-did-lookup/src/tests.rs @@ -109,7 +109,7 @@ fn test_add_association_account() { ) .is_ok()); assert_eq!( - ConnectedDids::::get(&LinkableAccountId::from(account_hash_alice.clone())), + ConnectedDids::::get(LinkableAccountId::from(account_hash_alice.clone())), Some(ConnectionRecord { did: DID_00, deposit: Deposit { @@ -119,7 +119,7 @@ fn test_add_association_account() { }) ); assert!( - ConnectedAccounts::::get(DID_00, &LinkableAccountId::from(account_hash_alice.clone())).is_some() + ConnectedAccounts::::get(DID_00, LinkableAccountId::from(account_hash_alice.clone())).is_some() ); assert_eq!( Balances::reserved_balance(ACCOUNT_00), @@ -137,7 +137,7 @@ fn test_add_association_account() { } assert!(res.is_ok()); assert_eq!( - ConnectedDids::::get(&LinkableAccountId::from(account_hash_alice.clone())), + ConnectedDids::::get(LinkableAccountId::from(account_hash_alice.clone())), Some(ConnectionRecord { did: DID_01, deposit: Deposit { @@ -147,10 +147,10 @@ fn test_add_association_account() { }) ); assert!( - ConnectedAccounts::::get(DID_00, &LinkableAccountId::from(account_hash_alice.clone())).is_none() + ConnectedAccounts::::get(DID_00, LinkableAccountId::from(account_hash_alice.clone())).is_none() ); assert!( - ConnectedAccounts::::get(DID_01, &LinkableAccountId::from(account_hash_alice.clone())).is_some() + ConnectedAccounts::::get(DID_01, LinkableAccountId::from(account_hash_alice.clone())).is_some() ); assert_eq!( Balances::reserved_balance(ACCOUNT_00), @@ -165,7 +165,7 @@ fn test_add_association_account() { ) .is_ok()); assert_eq!( - ConnectedDids::::get(&LinkableAccountId::from(account_hash_alice.clone())), + ConnectedDids::::get(LinkableAccountId::from(account_hash_alice.clone())), Some(ConnectionRecord { did: DID_01, deposit: Deposit { @@ -175,9 +175,9 @@ fn test_add_association_account() { }) ); assert!( - ConnectedAccounts::::get(DID_00, &LinkableAccountId::from(account_hash_alice.clone())).is_none() + ConnectedAccounts::::get(DID_00, LinkableAccountId::from(account_hash_alice.clone())).is_none() ); - assert!(ConnectedAccounts::::get(DID_01, &LinkableAccountId::from(account_hash_alice)).is_some()); + assert!(ConnectedAccounts::::get(DID_01, LinkableAccountId::from(account_hash_alice)).is_some()); assert_eq!(Balances::reserved_balance(ACCOUNT_00), 0); assert_eq!( Balances::reserved_balance(ACCOUNT_01), @@ -204,7 +204,7 @@ fn test_add_eth_association() { crate::signature::WrapType::Ethereum, ); - let sig = eth_pair.sign_prehashed(&Keccak256::digest(&wrapped_payload).try_into().unwrap()); + let sig = eth_pair.sign_prehashed(&Keccak256::digest(wrapped_payload).try_into().unwrap()); // new association. No overwrite let res = DidLookup::associate_account( @@ -214,7 +214,7 @@ fn test_add_eth_association() { ); assert!(res.is_ok()); assert_eq!( - ConnectedDids::::get(&LinkableAccountId::from(eth_account)), + ConnectedDids::::get(LinkableAccountId::from(eth_account)), Some(ConnectionRecord { did: DID_00, deposit: Deposit { @@ -223,7 +223,7 @@ fn test_add_eth_association() { } }) ); - assert!(ConnectedAccounts::::get(DID_00, &LinkableAccountId::from(eth_account)).is_some()); + assert!(ConnectedAccounts::::get(DID_00, LinkableAccountId::from(eth_account)).is_some()); assert_eq!( Balances::reserved_balance(ACCOUNT_00), ::Deposit::get() @@ -297,8 +297,8 @@ fn test_remove_association_sender() { .execute_with(|| { // remove association assert!(DidLookup::remove_sender_association(Origin::signed(ACCOUNT_00)).is_ok()); - assert_eq!(ConnectedDids::::get(&LinkableAccountId::from(ACCOUNT_00)), None); - assert!(ConnectedAccounts::::get(DID_01, &LinkableAccountId::from(ACCOUNT_00)).is_none()); + assert_eq!(ConnectedDids::::get(LinkableAccountId::from(ACCOUNT_00)), None); + assert!(ConnectedAccounts::::get(DID_01, LinkableAccountId::from(ACCOUNT_00)).is_none()); assert_eq!(Balances::reserved_balance(ACCOUNT_00), 0); }); } @@ -334,8 +334,8 @@ fn test_remove_association_account() { LinkableAccountId::from(ACCOUNT_00.clone()) ) .is_ok()); - assert_eq!(ConnectedDids::::get(&LinkableAccountId::from(ACCOUNT_00)), None); - assert!(ConnectedAccounts::::get(DID_01, &LinkableAccountId::from(ACCOUNT_00)).is_none()); + assert_eq!(ConnectedDids::::get(LinkableAccountId::from(ACCOUNT_00)), None); + assert!(ConnectedAccounts::::get(DID_01, LinkableAccountId::from(ACCOUNT_00)).is_none()); assert_eq!(Balances::reserved_balance(ACCOUNT_01), 0); }); } @@ -349,7 +349,7 @@ fn test_remove_association_account_not_found() { ]) .build() .execute_with(|| { - assert_eq!(ConnectedDids::::get(&LinkableAccountId::from(ACCOUNT_00)), None); + assert_eq!(ConnectedDids::::get(LinkableAccountId::from(ACCOUNT_00)), None); assert_noop!( DidLookup::remove_account_association( diff --git a/pallets/pallet-web3-names/src/lib.rs b/pallets/pallet-web3-names/src/lib.rs index 41bd78449..f2b36ebb0 100644 --- a/pallets/pallet-web3-names/src/lib.rs +++ b/pallets/pallet-web3-names/src/lib.rs @@ -383,7 +383,7 @@ pub mod pallet { ) -> Result, DispatchError> { let name = Web3NameOf::::try_from(name_input.into_inner()).map_err(DispatchError::from)?; - ensure!(!Names::::contains_key(&owner), Error::::OwnerAlreadyExists); + ensure!(!Names::::contains_key(owner), Error::::OwnerAlreadyExists); ensure!(!Owner::::contains_key(&name), Error::::Web3NameAlreadyClaimed); ensure!(!Banned::::contains_key(&name), Error::::Web3NameBanned); @@ -423,7 +423,7 @@ pub mod pallet { /// Specifically: /// - The owner has a previously claimed name fn check_releasing_preconditions(owner: &Web3NameOwnerOf) -> Result, DispatchError> { - let name = Names::::get(&owner).ok_or(Error::::OwnerNotFound)?; + let name = Names::::get(owner).ok_or(Error::::OwnerNotFound)?; Ok(name) } @@ -480,7 +480,7 @@ pub mod pallet { /// `check_banning_preconditions` as it does not verify all the /// preconditions again. pub(crate) fn ban_name(name: &Web3NameOf) { - Banned::::insert(&name, ()); + Banned::::insert(name, ()); } /// Verify that the unbanning preconditions are verified. @@ -510,7 +510,7 @@ pub mod pallet { fn deposit( key: &T::Web3Name, ) -> Result, >>::Balance>, DispatchError> { - let w3n_entry = Owner::::get(&key).ok_or(Error::::Web3NameNotFound)?; + let w3n_entry = Owner::::get(key).ok_or(Error::::Web3NameNotFound)?; Ok(w3n_entry.deposit) } @@ -523,8 +523,8 @@ pub mod pallet { key: &T::Web3Name, deposit: Deposit, >>::Balance>, ) -> Result<(), DispatchError> { - let w3n_entry = Owner::::get(&key).ok_or(Error::::Web3NameNotFound)?; - Owner::::insert(&key, Web3OwnershipOf:: { deposit, ..w3n_entry }); + let w3n_entry = Owner::::get(key).ok_or(Error::::Web3NameNotFound)?; + Owner::::insert(key, Web3OwnershipOf:: { deposit, ..w3n_entry }); Ok(()) } diff --git a/pallets/parachain-staking/src/benchmarking.rs b/pallets/parachain-staking/src/benchmarking.rs index 1a6c10f76..d271363b7 100644 --- a/pallets/parachain-staking/src/benchmarking.rs +++ b/pallets/parachain-staking/src/benchmarking.rs @@ -177,7 +177,7 @@ benchmarks! { let candidates = setup_collator_candidates::(n, None); for (i, c) in candidates.iter().enumerate() { fill_delegators::(m, c.clone(), i.saturated_into::()); - Rewards::::insert(&c, T::CurrencyBalance::one()); + Rewards::::insert(c, T::CurrencyBalance::one()); } let inflation = InflationInfo::new( @@ -296,7 +296,7 @@ benchmarks! { let n in (T::MinCollators::get() + 1) .. T::MaxTopCandidates::get() - 1; let m in 0 .. T::MaxDelegatorsPerCollator::get(); - let u = T::MaxUnstakeRequests::get() as u32 - 1; + let u = T::MaxUnstakeRequests::get() - 1; let candidates = setup_collator_candidates::(n, None); for (i, c) in candidates.iter().enumerate() { fill_delegators::(m, c.clone(), i.saturated_into::()); @@ -519,7 +519,7 @@ benchmarks! { } unlock_unstaked { - let u in 1 .. (T::MaxUnstakeRequests::get() as u32 - 1); + let u in 1 .. (T::MaxUnstakeRequests::get() - 1); let candidate = account("collator", 0u32, COLLATOR_ACCOUNT_SEED); let free_balance = T::CurrencyBalance::from(u128::MAX); diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index cc85b1dc9..163540ea8 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -1980,7 +1980,7 @@ pub mod pallet { // Snapshot exposure for round for weighting reward distribution for account in collators.iter() { let state = - CandidatePool::::get(&account).expect("all members of TopCandidates must be candidates q.e.d"); + CandidatePool::::get(account).expect("all members of TopCandidates must be candidates q.e.d"); num_of_delegators = num_of_delegators.max(state.delegators.len().saturated_into::()); // sum up total stake and amount of collators, delegators @@ -2270,8 +2270,8 @@ pub mod pallet { .map(pallet_session::Pallet::::disable_index); // Kill storage - BlocksAuthored::::remove(&collator); - BlocksRewarded::::remove(&collator); + BlocksAuthored::::remove(collator); + BlocksRewarded::::remove(collator); CandidatePool::::remove(&collator); Ok(()) } diff --git a/pallets/public-credentials/src/benchmarking.rs b/pallets/public-credentials/src/benchmarking.rs index ee452732b..0434da3f8 100644 --- a/pallets/public-credentials/src/benchmarking.rs +++ b/pallets/public-credentials/src/benchmarking.rs @@ -70,7 +70,7 @@ benchmarks! { )); let credential_id = generate_credential_id::(&creation_op, &attester); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); reserve_balance::(&sender); let origin = ::EnsureOrigin::generate_origin(sender, attester); }: _(origin, creation_op) @@ -97,7 +97,7 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(&ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, attester); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); }: _(origin, credential_id_clone, None) @@ -123,7 +123,7 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(&ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, attester); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); Pallet::::revoke(origin.clone(), credential_id.clone(), None).expect("Pallet::revoke should not fail"); let credential_id_clone = credential_id.clone(); @@ -149,7 +149,7 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(&ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, attester); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); }: _(origin, credential_id_clone, None) @@ -175,7 +175,7 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(&ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, attester); Pallet::::add(origin, creation_op).expect("Pallet::add should not fail"); let origin = RawOrigin::Signed(sender); let credential_id_clone = credential_id.clone(); @@ -204,7 +204,7 @@ benchmarks! { reserve_balance::(&deposit_owner_old); reserve_balance::(&deposit_owner_new); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); Pallet::::add(origin, creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); let origin = ::EnsureOrigin::generate_origin(deposit_owner_new.clone(), attester); @@ -227,7 +227,7 @@ benchmarks! { let origin = ::EnsureOrigin::generate_origin(deposit_owner.clone(), attester.clone()); reserve_balance::(&deposit_owner); - ctype::Ctypes::::insert(&ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, attester.clone()); let credential_entry = generate_base_credential_entry::( deposit_owner.clone(), diff --git a/pallets/public-credentials/src/lib.rs b/pallets/public-credentials/src/lib.rs index 8a2c47484..78d5d0505 100644 --- a/pallets/public-credentials/src/lib.rs +++ b/pallets/public-credentials/src/lib.rs @@ -259,7 +259,7 @@ pub mod pallet { } = *credential.clone(); ensure!( - ctype::Ctypes::::contains_key(&ctype_hash), + ctype::Ctypes::::contains_key(ctype_hash), ctype::Error::::CTypeNotFound ); @@ -542,10 +542,10 @@ pub mod pallet { ) -> Result<(T::SubjectId, CredentialEntryOf), Error> { // Verify that the credential exists let credential_subject = - CredentialSubjects::::get(&credential_id).ok_or(Error::::CredentialNotFound)?; + CredentialSubjects::::get(credential_id).ok_or(Error::::CredentialNotFound)?; // Should never happen if the line above succeeds - Credentials::::get(&credential_subject, &credential_id) + Credentials::::get(&credential_subject, credential_id) .map(|entry| (credential_subject, entry)) .ok_or(Error::::InternalError) } @@ -560,7 +560,7 @@ pub mod pallet { // Fails if the credential does not exist OR the caller is different than the // original attester. If successful, saves the additional weight used for access // control and returns it at the end of the function. - Credentials::::try_mutate(&credential_subject, &credential_id, |credential_entry| { + Credentials::::try_mutate(credential_subject, credential_id, |credential_entry| { if let Some(credential) = credential_entry { // Additional weight is 0 if the caller is the attester, otherwise it's the // value returned by the access control check, if it does not fail. @@ -605,8 +605,8 @@ pub mod pallet { deposit: Deposit, >>::Balance>, ) -> Result<(), DispatchError> { let credential_subject = - CredentialSubjects::::get(&credential_id).ok_or(Error::::CredentialNotFound)?; - Credentials::::try_mutate(&credential_subject, &credential_id, |credential_entry| { + CredentialSubjects::::get(credential_id).ok_or(Error::::CredentialNotFound)?; + Credentials::::try_mutate(&credential_subject, credential_id, |credential_entry| { if let Some(credential) = credential_entry { credential.deposit = deposit; Ok(()) diff --git a/pallets/public-credentials/src/tests.rs b/pallets/public-credentials/src/tests.rs index cd3e7faec..c84029d57 100644 --- a/pallets/public-credentials/src/tests.rs +++ b/pallets/public-credentials/src/tests.rs @@ -58,7 +58,7 @@ fn add_successful_without_authorization() { DoubleOrigin(ACCOUNT_00, attester.clone()).into(), Box::new(new_credential_1.clone()) )); - let stored_public_credential_details = Credentials::::get(&subject_id, &credential_id_1) + let stored_public_credential_details = Credentials::::get(subject_id, credential_id_1) .expect("Public credential details should be present on chain."); // Test this pallet logic @@ -67,7 +67,7 @@ fn add_successful_without_authorization() { assert_eq!(stored_public_credential_details.block_number, 0); assert_eq!(stored_public_credential_details.ctype_hash, ctype_hash_1); assert_eq!(stored_public_credential_details.authorization_id, None); - assert_eq!(CredentialSubjects::::get(&credential_id_1), Some(subject_id)); + assert_eq!(CredentialSubjects::::get(credential_id_1), Some(subject_id)); // Check deposit reservation logic assert_eq!(Balances::reserved_balance(ACCOUNT_00), deposit); @@ -92,7 +92,7 @@ fn add_successful_without_authorization() { Box::new(new_credential_2.clone()) )); - let stored_public_credential_details = Credentials::::get(&subject_id, &credential_id_2) + let stored_public_credential_details = Credentials::::get(subject_id, credential_id_2) .expect("Public credential #2 details should be present on chain."); // Test this pallet logic @@ -101,7 +101,7 @@ fn add_successful_without_authorization() { assert_eq!(stored_public_credential_details.block_number, 1); assert_eq!(stored_public_credential_details.ctype_hash, ctype_hash_2); assert_eq!(stored_public_credential_details.authorization_id, None); - assert_eq!(CredentialSubjects::::get(&credential_id_2), Some(subject_id)); + assert_eq!(CredentialSubjects::::get(credential_id_2), Some(subject_id)); // Deposit is 2x now assert_eq!(Balances::reserved_balance(ACCOUNT_00), 2 * deposit); @@ -131,7 +131,7 @@ fn add_successful_with_authorization() { DoubleOrigin(ACCOUNT_00, attester.clone()).into(), Box::new(new_credential.clone()) )); - let stored_public_credential_details = Credentials::::get(&subject_id, &credential_id) + let stored_public_credential_details = Credentials::::get(subject_id, credential_id) .expect("Public credential details should be present on chain."); // Test this pallet logic @@ -140,7 +140,7 @@ fn add_successful_with_authorization() { assert_eq!(stored_public_credential_details.block_number, 0); assert_eq!(stored_public_credential_details.ctype_hash, ctype_hash); assert_eq!(stored_public_credential_details.authorization_id, Some(attester)); - assert_eq!(CredentialSubjects::::get(&credential_id), Some(subject_id)); + assert_eq!(CredentialSubjects::::get(credential_id), Some(subject_id)); }); } @@ -275,7 +275,7 @@ fn revoke_successful() { None, )); - let stored_public_credential_details = Credentials::::get(&subject_id, &credential_id) + let stored_public_credential_details = Credentials::::get(subject_id, credential_id) .expect("Public credential details should be present on chain."); // Test this pallet logic @@ -288,7 +288,7 @@ fn revoke_successful() { None, )); - let stored_public_credential_details_2 = Credentials::::get(&subject_id, &credential_id) + let stored_public_credential_details_2 = Credentials::::get(subject_id, credential_id) .expect("Public credential details should be present on chain."); assert_eq!(stored_public_credential_details, stored_public_credential_details_2); @@ -316,7 +316,7 @@ fn revoke_same_attester_wrong_ac() { Some(MockAccessControl(wrong_submitter)) )); - let stored_public_credential_details = Credentials::::get(&subject_id, &credential_id) + let stored_public_credential_details = Credentials::::get(subject_id, credential_id) .expect("Public credential details should be present on chain."); // Test this pallet logic @@ -415,7 +415,7 @@ fn unrevoke_successful() { None, )); - let stored_public_credential_details = Credentials::::get(&subject_id, &credential_id) + let stored_public_credential_details = Credentials::::get(subject_id, credential_id) .expect("Public credential details should be present on chain."); // Test this pallet logic @@ -428,7 +428,7 @@ fn unrevoke_successful() { None, )); - let stored_public_credential_details_2 = Credentials::::get(&subject_id, &credential_id) + let stored_public_credential_details_2 = Credentials::::get(subject_id, credential_id) .expect("Public credential details should be present on chain."); assert_eq!(stored_public_credential_details, stored_public_credential_details_2); @@ -457,7 +457,7 @@ fn unrevoke_same_attester_wrong_ac() { Some(MockAccessControl(wrong_submitter)) )); - let stored_public_credential_details = Credentials::::get(&subject_id, &credential_id) + let stored_public_credential_details = Credentials::::get(subject_id, credential_id) .expect("Public credential details should be present on chain."); // Test this pallet logic @@ -558,8 +558,8 @@ fn remove_successful() { )); // Test this pallet logic - assert!(Credentials::::get(&subject_id, &credential_id).is_none()); - assert!(CredentialSubjects::::get(&credential_id).is_none()); + assert!(Credentials::::get(subject_id, credential_id).is_none()); + assert!(CredentialSubjects::::get(credential_id).is_none()); // Check deposit release logic assert!(Balances::reserved_balance(ACCOUNT_00).is_zero()); @@ -594,8 +594,8 @@ fn remove_same_attester_wrong_ac() { )); // Test this pallet logic - assert!(Credentials::::get(&subject_id, &credential_id).is_none()); - assert!(CredentialSubjects::::get(&credential_id).is_none()); + assert!(Credentials::::get(subject_id, credential_id).is_none()); + assert!(CredentialSubjects::::get(credential_id).is_none()); }); } @@ -689,8 +689,8 @@ fn reclaim_deposit_successful() { )); // Test this pallet logic - assert!(Credentials::::get(&subject_id, &credential_id).is_none()); - assert!(CredentialSubjects::::get(&credential_id).is_none()); + assert!(Credentials::::get(subject_id, credential_id).is_none()); + assert!(CredentialSubjects::::get(credential_id).is_none()); // Check deposit release logic assert!(Balances::reserved_balance(ACCOUNT_00).is_zero()); @@ -775,7 +775,7 @@ fn test_change_deposit_owner() { // Check assert_eq!( - Credentials::::get(&subject_id, &credential_id) + Credentials::::get(subject_id, credential_id) .expect("credential should exist") .deposit .owner, @@ -867,7 +867,7 @@ fn test_update_deposit() { // Check assert_eq!( - Credentials::::get(&subject_id, &credential_id) + Credentials::::get(subject_id, credential_id) .expect("credential should exist") .deposit .amount, diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index 03aea7823..94a4b7eeb 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -1258,13 +1258,13 @@ impl_runtime_apis! { impl kilt_runtime_api_public_credentials::PublicCredentials, Hash, public_credentials::CredentialEntry::DelegationNodeId>>, PublicCredentialsFilter, PublicCredentialsApiError> for Runtime { fn get_by_id(credential_id: Hash) -> Option::DelegationNodeId>>> { - let subject = public_credentials::CredentialSubjects::::get(&credential_id)?; - public_credentials::Credentials::::get(&subject, &credential_id) + let subject = public_credentials::CredentialSubjects::::get(credential_id)?; + public_credentials::Credentials::::get(subject, credential_id) } fn get_by_subject(subject: Vec, filter: Option>) -> Result::DelegationNodeId>>)>, PublicCredentialsApiError> { let asset_did = AssetDid::try_from(subject).map_err(|_| PublicCredentialsApiError::InvalidSubjectId)?; - let credentials_prefix = public_credentials::Credentials::::iter_prefix(&asset_did); + let credentials_prefix = public_credentials::Credentials::::iter_prefix(asset_did); if let Some(filter) = filter { Ok(credentials_prefix.filter(|(_, entry)| filter.should_include(entry)).collect()) } else { diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index 5e10aac9f..95b62454b 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -1254,13 +1254,13 @@ impl_runtime_apis! { impl kilt_runtime_api_public_credentials::PublicCredentials, Hash, public_credentials::CredentialEntry::DelegationNodeId>>, PublicCredentialsFilter, PublicCredentialsApiError> for Runtime { fn get_by_id(credential_id: Hash) -> Option::DelegationNodeId>>> { - let subject = public_credentials::CredentialSubjects::::get(&credential_id)?; - public_credentials::Credentials::::get(&subject, &credential_id) + let subject = public_credentials::CredentialSubjects::::get(credential_id)?; + public_credentials::Credentials::::get(subject, credential_id) } fn get_by_subject(subject: Vec, filter: Option>) -> Result::DelegationNodeId>>)>, PublicCredentialsApiError> { let asset_did = AssetDid::try_from(subject).map_err(|_| PublicCredentialsApiError::InvalidSubjectId)?; - let credentials_prefix = public_credentials::Credentials::::iter_prefix(&asset_did); + let credentials_prefix = public_credentials::Credentials::::iter_prefix(asset_did); if let Some(filter) = filter { Ok(credentials_prefix.filter(|(_, entry)| filter.should_include(entry)).collect()) } else { diff --git a/runtimes/standalone/src/lib.rs b/runtimes/standalone/src/lib.rs index faf7fdbb4..8cfc60631 100644 --- a/runtimes/standalone/src/lib.rs +++ b/runtimes/standalone/src/lib.rs @@ -1003,13 +1003,13 @@ impl_runtime_apis! { impl kilt_runtime_api_public_credentials::PublicCredentials, Hash, public_credentials::CredentialEntry::DelegationNodeId>>, PublicCredentialsFilter, PublicCredentialsApiError> for Runtime { fn get_by_id(credential_id: Hash) -> Option::DelegationNodeId>>> { - let subject = public_credentials::CredentialSubjects::::get(&credential_id)?; - public_credentials::Credentials::::get(&subject, &credential_id) + let subject = public_credentials::CredentialSubjects::::get(credential_id)?; + public_credentials::Credentials::::get(subject, credential_id) } fn get_by_subject(subject: Vec, filter: Option>) -> Result::DelegationNodeId>>)>, PublicCredentialsApiError> { let asset_did = AssetDid::try_from(subject).map_err(|_| PublicCredentialsApiError::InvalidSubjectId)?; - let credentials_prefix = public_credentials::Credentials::::iter_prefix(&asset_did); + let credentials_prefix = public_credentials::Credentials::::iter_prefix(asset_did); if let Some(filter) = filter { Ok(credentials_prefix.filter(|(_, entry)| filter.should_include(entry)).collect()) } else { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c3889eb24..8a9ff6fb2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly" +channel = "nightly-2022-11-29" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] From 479a782a9c4615859906f60ede4f698bd42f7214 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 11:49:55 +0100 Subject: [PATCH 03/24] Remove +nightly from CI jobs --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aa87b020c..2a6bbc2a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ clippy: timeout: 1 hours script: - rustup show - - cargo +nightly clippy --all-features --all-targets --locked -- -D warnings + - cargo clippy --all-features --all-targets --locked -- -D warnings fmt: # Corresponds to paritytech/ci-linux:production at the time of this PR @@ -19,7 +19,7 @@ fmt: stage: test timeout: 1 hours script: - - cargo +nightly fmt -- --check + - cargo fmt -- --check test: # Corresponds to paritytech/ci-linux:production at the time of this PR From 89089cd002619ea15cbb287b1bd42ba66ab263da Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 11:52:32 +0100 Subject: [PATCH 04/24] Remove debug rustup show command --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2a6bbc2a5..391863b1f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,6 @@ clippy: stage: test timeout: 1 hours script: - - rustup show - cargo clippy --all-features --all-targets --locked -- -D warnings fmt: From 8875d867859bf9c286f2e35b3aadd54bb9de26bc Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 13:47:41 +0100 Subject: [PATCH 05/24] Replace versioned nightly with just nightly --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 8a9ff6fb2..c3889eb24 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2022-11-29" +channel = "nightly" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] From 805d193fca0787bbccbfbe1f138c1b01a486d5e4 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 13:49:36 +0100 Subject: [PATCH 06/24] Revert "Replace versioned nightly with just nightly" This reverts commit 8875d867859bf9c286f2e35b3aadd54bb9de26bc. --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c3889eb24..8a9ff6fb2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly" +channel = "nightly-2022-11-29" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] From de04e4b7326668e07d99b430f484449880ac5e62 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 15:30:09 +0100 Subject: [PATCH 07/24] Use same version as polkadot 0.9.31 release --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 8a9ff6fb2..f5c70e287 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2022-11-29" +channel = "nightly-2022-10-09" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] From d1b9eff53475e4fa69e4f1ba98640fbe669d10f7 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 15:38:40 +0100 Subject: [PATCH 08/24] Address clippy warning --- pallets/delegation/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/delegation/src/benchmarking.rs b/pallets/delegation/src/benchmarking.rs index dcf922b34..73dd553b7 100644 --- a/pallets/delegation/src/benchmarking.rs +++ b/pallets/delegation/src/benchmarking.rs @@ -148,7 +148,7 @@ where )?; // only return first leaf - first_leaf = first_leaf.or(Some((delegation_acc_public, delegation_acc_id, delegation_id))); + first_leaf = first_leaf.or_else(|| Some((delegation_acc_public, delegation_acc_id, delegation_id))); } let (leaf_acc_public, leaf_acc_id, leaf_id) = From b4644f3aa572c0eeb32e3f1344de6c8dd4118236 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 14:13:48 +0100 Subject: [PATCH 09/24] Add block number to stored info for CType --- pallets/attestation/src/mock.rs | 10 ++++++++-- pallets/ctype/src/ctype_entry.rs | 12 ++++++++++++ pallets/ctype/src/lib.rs | 18 +++++++++++++++--- pallets/ctype/src/mock.rs | 10 ++++++++-- pallets/ctype/src/tests.rs | 11 +++++++++-- pallets/delegation/src/mock.rs | 9 ++++++++- pallets/did/src/mock.rs | 8 +++++++- pallets/public-credentials/src/mock.rs | 10 ++++++++-- 8 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 pallets/ctype/src/ctype_entry.rs diff --git a/pallets/attestation/src/mock.rs b/pallets/attestation/src/mock.rs index 489d7b08a..66b7aeeec 100644 --- a/pallets/attestation/src/mock.rs +++ b/pallets/attestation/src/mock.rs @@ -168,7 +168,6 @@ pub fn insert_attestation(claim_hash: ClaimHashOf, details: Attest /// Mocks that are only used internally #[cfg(test)] pub(crate) mod runtime { - use ctype::CtypeCreatorOf; use frame_support::{parameter_types, weights::constants::RocksDbWeight}; use sp_core::{ed25519, sr25519, Pair}; use sp_runtime::{ @@ -177,6 +176,7 @@ pub(crate) mod runtime { MultiSignature, MultiSigner, }; + use ctype::{CtypeCreatorOf, CtypeEntryOf}; use kilt_support::mock::{mock_origin, SubjectId}; use super::*; @@ -366,7 +366,13 @@ pub(crate) mod runtime { ext.execute_with(|| { for ctype in self.ctypes { - ctype::Ctypes::::insert(ctype.0, ctype.1.clone()); + ctype::Ctypes::::insert( + ctype.0, + CtypeEntryOf:: { + creator: ctype.1.clone(), + creation_block_number: 0, + }, + ); } for (claim_hash, details) in self.attestations { diff --git a/pallets/ctype/src/ctype_entry.rs b/pallets/ctype/src/ctype_entry.rs new file mode 100644 index 000000000..05c435d6c --- /dev/null +++ b/pallets/ctype/src/ctype_entry.rs @@ -0,0 +1,12 @@ +use codec::{Decode, Encode, MaxEncodedLen}; +use frame_support::RuntimeDebug; +use scale_info::TypeInfo; + +/// Creation details of a CType. +#[derive(Encode, Decode, RuntimeDebug, MaxEncodedLen, Eq, PartialEq, TypeInfo)] +pub struct CtypeEntry { + /// Identifier of the creator. + pub creator: Creator, + /// Block number in which the creation tx was dispatched. + pub creation_block_number: BlockNumber, +} diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 73f84d530..45b1fa36e 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -42,6 +42,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub mod ctype_entry; pub mod default_weights; #[cfg(any(feature = "mock", test))] @@ -58,6 +59,8 @@ pub use crate::{default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] pub mod pallet { + use crate::ctype_entry::CtypeEntry; + use super::*; use frame_support::{ pallet_prelude::*, @@ -75,6 +78,8 @@ pub mod pallet { /// Type of a CType hash. pub type CtypeHashOf = ::Hash; + pub type CtypeEntryOf = CtypeEntry<::CtypeCreatorId, BlockNumberFor>; + /// Type of a CType creator. pub type CtypeCreatorOf = ::CtypeCreatorId; @@ -105,10 +110,11 @@ pub mod pallet { /// CTypes stored on chain. /// - /// It maps from a CType hash to its creator. + /// It maps from a CType hash to its creator and block number in which it + /// was created. #[pallet::storage] #[pallet::getter(fn ctypes)] - pub type Ctypes = StorageMap<_, Blake2_128Concat, CtypeHashOf, CtypeCreatorOf>; + pub type Ctypes = StorageMap<_, Blake2_128Concat, CtypeHashOf, CtypeEntryOf>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -176,7 +182,13 @@ pub mod pallet { T::FeeCollector::on_unbalanced(imbalance); log::debug!("Creating CType with hash {:?} and creator {:?}", hash, creator); - Ctypes::::insert(hash, creator.clone()); + Ctypes::::insert( + hash, + CtypeEntryOf:: { + creator: creator.clone(), + creation_block_number: frame_system::Pallet::::block_number(), + }, + ); Self::deposit_event(Event::CTypeCreated(creator, hash)); diff --git a/pallets/ctype/src/mock.rs b/pallets/ctype/src/mock.rs index 03919dacb..f5a101490 100644 --- a/pallets/ctype/src/mock.rs +++ b/pallets/ctype/src/mock.rs @@ -44,7 +44,7 @@ pub mod runtime { AccountId32, MultiSignature, }; - use crate::{BalanceOf, Ctypes}; + use crate::{BalanceOf, CtypeEntryOf, Ctypes}; use super::*; @@ -176,7 +176,13 @@ pub mod runtime { ext.execute_with(|| { for (ctype_hash, owner) in self.ctypes_stored.iter() { - Ctypes::::insert(ctype_hash, owner); + Ctypes::::insert( + ctype_hash, + CtypeEntryOf:: { + creator: owner.clone(), + creation_block_number: 0, + }, + ); } }); diff --git a/pallets/ctype/src/tests.rs b/pallets/ctype/src/tests.rs index 936da2f26..b9f32b9a1 100644 --- a/pallets/ctype/src/tests.rs +++ b/pallets/ctype/src/tests.rs @@ -19,7 +19,7 @@ use frame_support::{assert_noop, assert_ok, sp_runtime::traits::Hash}; use kilt_support::mock::mock_origin::DoubleOrigin; -use crate::{self as ctype, mock::runtime::*}; +use crate::{self as ctype, mock::runtime::*, CtypeEntryOf}; // submit_ctype_creation_operation @@ -34,6 +34,7 @@ fn check_successful_ctype_creation() { .with_balances(vec![(deposit_owner.clone(), initial_balance)]) .build() .execute_with(|| { + System::set_block_number(200); assert_ok!(Ctype::add( DoubleOrigin(deposit_owner.clone(), creator.clone()).into(), ctype @@ -41,7 +42,13 @@ fn check_successful_ctype_creation() { let stored_ctype_creator = Ctype::ctypes(&ctype_hash).expect("CType hash should be present on chain."); // Verify the CType has the right owner - assert_eq!(stored_ctype_creator, creator); + assert_eq!( + stored_ctype_creator, + CtypeEntryOf:: { + creator, + creation_block_number: 200 + } + ); assert_eq!( Balances::free_balance(deposit_owner), initial_balance.saturating_sub(::Fee::get()) diff --git a/pallets/delegation/src/mock.rs b/pallets/delegation/src/mock.rs index ef30b34af..a78679afd 100644 --- a/pallets/delegation/src/mock.rs +++ b/pallets/delegation/src/mock.rs @@ -183,6 +183,7 @@ pub(crate) mod runtime { }; use attestation::{mock::insert_attestation, AttestationDetails, ClaimHashOf}; + use ctype::CtypeEntryOf; use kilt_support::{ mock::{mock_origin, SubjectId}, signature::EqualVerify, @@ -491,7 +492,13 @@ pub(crate) mod runtime { ext.execute_with(|| { for (ctype_hash, owner) in self.ctypes.iter() { - ctype::Ctypes::::insert(ctype_hash, owner); + ctype::Ctypes::::insert( + ctype_hash, + CtypeEntryOf:: { + creator: owner.clone(), + creation_block_number: 0, + }, + ); } initialize_pallet(self.delegations, self.delegation_hierarchies); diff --git a/pallets/did/src/mock.rs b/pallets/did/src/mock.rs index e9f906f68..d49cdddc0 100644 --- a/pallets/did/src/mock.rs +++ b/pallets/did/src/mock.rs @@ -472,7 +472,13 @@ impl ExtBuilder { ext.execute_with(|| { for (ctype_hash, owner) in self.ctypes_stored.iter() { - ctype::Ctypes::::insert(ctype_hash, owner); + ctype::Ctypes::::insert( + ctype_hash, + ctype::CtypeEntryOf:: { + creator: owner.to_owned(), + creation_block_number: 0, + }, + ); } for did in self.dids_stored.iter() { diff --git a/pallets/public-credentials/src/mock.rs b/pallets/public-credentials/src/mock.rs index 48f50baff..f10cee76b 100644 --- a/pallets/public-credentials/src/mock.rs +++ b/pallets/public-credentials/src/mock.rs @@ -110,7 +110,7 @@ pub(crate) mod runtime { use kilt_support::mock::{mock_origin, SubjectId}; - use ctype::{CtypeCreatorOf, CtypeHashOf}; + use ctype::{CtypeCreatorOf, CtypeEntryOf, CtypeHashOf}; use crate::{Config, CredentialEntryOf, Error, InputSubjectIdOf, PublicCredentialsAccessControl}; @@ -424,7 +424,13 @@ pub(crate) mod runtime { ext.execute_with(|| { for ctype in self.ctypes { - ctype::Ctypes::::insert(ctype.0, ctype.1.clone()); + ctype::Ctypes::::insert( + ctype.0, + CtypeEntryOf:: { + creator: ctype.1.clone(), + creation_block_number: 0, + }, + ); } for (subject_id, credential_id, credential_entry) in self.public_credentials { From 427d02d1894a9a585e64636b257049129efd66a6 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 29 Nov 2022 15:28:50 +0100 Subject: [PATCH 10/24] Add CType migration --- Cargo.lock | 1 + pallets/ctype/src/lib.rs | 2 +- runtimes/common/Cargo.toml | 3 + runtimes/common/src/migrations.rs | 98 +++++++++++++++---------------- runtimes/peregrine/src/lib.rs | 2 +- runtimes/spiritnet/src/lib.rs | 3 +- 6 files changed, 56 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f73dd9439..c827d41e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8414,6 +8414,7 @@ name = "runtime-common" version = "1.9.0" dependencies = [ "attestation", + "ctype", "frame-support", "frame-system", "kilt-asset-dids", diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 45b1fa36e..e4067abf8 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -73,7 +73,7 @@ pub mod pallet { use sp_std::vec::Vec; /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); /// Type of a CType hash. pub type CtypeHashOf = ::Hash; diff --git a/runtimes/common/Cargo.toml b/runtimes/common/Cargo.toml index 9c3aec069..6b64c9eb8 100644 --- a/runtimes/common/Cargo.toml +++ b/runtimes/common/Cargo.toml @@ -23,6 +23,7 @@ smallvec.workspace = true # Internal dependencies attestation.workspace = true +ctype.workspace = true kilt-support.workspace = true parachain-staking.workspace = true public-credentials.workspace = true @@ -51,6 +52,7 @@ default = ["std"] fast-gov = [] runtime-benchmarks = [ "attestation/runtime-benchmarks", + "ctype/runtime-benchmarks", "frame-support/runtime-benchmarks", "kilt-support/runtime-benchmarks", "parachain-staking/runtime-benchmarks", @@ -61,6 +63,7 @@ runtime-benchmarks = [ std = [ "attestation/std", "codec/std", + "ctype/std", "frame-support/std", "frame-system/std", "kilt-asset-dids/std", diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index 1fce9a577..cbe017f35 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -16,67 +16,67 @@ // If you feel like getting in touch with us, you can do so at info@botlabs.org -use sp_std::marker::PhantomData; - use frame_support::{ - traits::{Get, OnRuntimeUpgrade}, - StorageHasher, Twox128, + pallet_prelude::ValueQuery, + storage_alias, + traits::{GetStorageVersion, OnRuntimeUpgrade}, }; +use sp_runtime::traits::{Get, Zero}; +use sp_std::marker::PhantomData; + +use ctype::{CtypeCreatorOf, CtypeEntryOf}; + +#[storage_alias] +type MigrationCounter = StorageValue, u32, ValueQuery>; -pub struct RemoveRelocationPallets(PhantomData); +pub struct AddCTypeBlockNumber(PhantomData); -impl OnRuntimeUpgrade for RemoveRelocationPallets { +impl OnRuntimeUpgrade for AddCTypeBlockNumber { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result<(), &'static str> { - log::info!("Pre check RemoveRelocationPallets."); - let has_migration_storage = frame_support::storage::migration::have_storage_value( - b"RelayMigration", - b"RelayNumberStrictlyIncreases", - b"", - ); - let has_filter_storage = frame_support::storage::migration::have_storage_value(b"DynFilter", b"Filter", b""); - - match (has_migration_storage, has_filter_storage) { - (false, false) => Err("Pallets not present"), - (true, false) => Err("DynFilter not present"), - (false, true) => Err("RelayMigration not present"), - _ => Ok(()), - } + assert_eq!(ctype::Pallet::::on_chain_storage_version(), 1,); + assert!(MigrationCounter::::get().is_zero()); + + let ctypes_to_migrate = ctype::Ctypes::::iter().count(); + + log::info!("💰 CType pallet pre check: {:?} CTypes", ctypes_to_migrate); + + MigrationCounter::::set(ctypes_to_migrate as u32); + Ok(()) } fn on_runtime_upgrade() -> frame_support::weights::Weight { - let entries: u32 = 2; - if frame_support::storage::unhashed::clear_prefix(&Twox128::hash(b"RelayMigration"), Some(entries), None) - .maybe_cursor - .is_some() - { - log::warn!("Pallet RelayMigration not removed entirely") - } - if frame_support::storage::unhashed::clear_prefix(&Twox128::hash(b"DynFilter"), Some(entries), None) - .maybe_cursor - .is_some() - { - log::warn!("Pallet DynFilter not removed entirely") - } - - ::DbWeight::get().writes((entries * 2).into()) + let current = ctype::Pallet::::current_storage_version(); + let onchain = ctype::Pallet::::on_chain_storage_version(); + + log::info!( + "💰 Running migration with current storage version {:?} / onchain {:?}", + current, + onchain + ); + + let mut num_translations = 0u64; + + ctype::Ctypes::::translate_values(|old: CtypeCreatorOf| { + num_translations = num_translations.saturating_add(1); + Some(CtypeEntryOf:: { + creator: old, + creation_block_number: ::BlockNumber::zero(), + }) + }); + current.put::>(); + + // Num translations + old version read and new version write + T::DbWeight::get().reads_writes(num_translations.saturating_add(1), num_translations.saturating_add(1)) } #[cfg(feature = "try-runtime")] fn post_upgrade() -> Result<(), &'static str> { - log::info!("Post check RemoveRelocationPallets."); - let has_migration_storage = frame_support::storage::migration::have_storage_value( - b"RelayMigration", - b"RelayNumberStrictlyIncreases", - b"", - ); - let has_filter_storage = frame_support::storage::migration::have_storage_value(b"DynFilter", b"Filter", b""); - - match (has_migration_storage, has_filter_storage) { - (false, false) => Ok(()), - (true, false) => Err("RelayMigration still present"), - (false, true) => Err("DynFilter still present"), - (true, true) => Err("Pallets still present"), - } + assert_eq!(ctype::Pallet::::on_chain_storage_version(), 2); + + assert_eq!(MigrationCounter::::get(), ctype::Ctypes::::iter().count() as u32); + + log::info!("💰 CType pallet post checks ok ✅"); + Ok(()) } } diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index 94a4b7eeb..bde833482 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -1056,7 +1056,7 @@ pub type Executive = frame_executive::Executive< Runtime, // Executes pallet hooks in the order of definition in construct_runtime AllPalletsWithSystem, - parachain_staking::migration::StakingPayoutRefactor, + runtime_common::migrations::AddCTypeBlockNumber, >; impl_runtime_apis! { diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index 95b62454b..e4d20004b 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -1051,8 +1051,7 @@ pub type Executive = frame_executive::Executive< Runtime, // Executes pallet hooks in the order of definition in construct_runtime AllPalletsWithSystem, - // EthereumMigration, - parachain_staking::migration::StakingPayoutRefactor, + runtime_common::migrations::AddCTypeBlockNumber, >; impl_runtime_apis! { From d0706eb9a95f441863d1c891996934f05b700ba1 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 08:46:50 +0100 Subject: [PATCH 11/24] Add new origin and set_block_number function + tests --- pallets/ctype/src/lib.rs | 22 +++++++++++++- pallets/ctype/src/mock.rs | 9 +++++- pallets/ctype/src/tests.rs | 61 +++++++++++++++++++++++++++++++++++++- 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index e4067abf8..ee7e6e2b6 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -67,7 +67,7 @@ pub mod pallet { sp_runtime::traits::Hash, traits::{Currency, ExistenceRequirement, OnUnbalanced, StorageVersion, WithdrawReasons}, }; - use frame_system::pallet_prelude::*; + use frame_system::pallet_prelude::{BlockNumberFor, *}; use kilt_support::traits::CallSources; use sp_runtime::{traits::Saturating, SaturatedConversion}; use sp_std::vec::Vec; @@ -91,6 +91,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type EnsureOrigin: EnsureOrigin::Origin>; + type OverarchingOrigin: EnsureOrigin<::Origin>; type OriginSuccess: CallSources, CtypeCreatorOf>; type Event: From> + IsType<::Event>; type Currency: Currency>; @@ -194,5 +195,24 @@ pub mod pallet { Ok(()) } + + #[pallet::weight(0)] + pub fn set_block_number( + origin: OriginFor, + ctype_hash: CtypeHashOf, + block_number: BlockNumberFor, + ) -> DispatchResult { + T::OverarchingOrigin::ensure_origin(origin)?; + Ctypes::::try_mutate(ctype_hash, |ctype_entry| -> Result<(), Error> { + if let Some(ctype_entry) = ctype_entry { + ctype_entry.creation_block_number = block_number; + Ok(()) + } else { + Err(Error::::CTypeNotFound) + } + })?; + + Ok(()) + } } } diff --git a/pallets/ctype/src/mock.rs b/pallets/ctype/src/mock.rs index f5a101490..33d090280 100644 --- a/pallets/ctype/src/mock.rs +++ b/pallets/ctype/src/mock.rs @@ -36,7 +36,8 @@ where #[cfg(test)] pub mod runtime { - use frame_support::{parameter_types, weights::constants::RocksDbWeight}; + use frame_support::{ord_parameter_types, parameter_types, weights::constants::RocksDbWeight}; + use frame_system::EnsureSignedBy; use kilt_support::mock::{mock_origin, SubjectId}; use sp_runtime::{ testing::Header, @@ -133,9 +134,14 @@ pub mod runtime { pub const Fee: Balance = 500; } + ord_parameter_types! { + pub const OverarchingOrigin: AccountId = ACCOUNT_00; + } + impl Config for Test { type CtypeCreatorId = SubjectId; type EnsureOrigin = mock_origin::EnsureDoubleOrigin; + type OverarchingOrigin = EnsureSignedBy; type OriginSuccess = mock_origin::DoubleOrigin; type Event = (); type WeightInfo = (); @@ -147,6 +153,7 @@ pub mod runtime { pub(crate) const DID_00: SubjectId = SubjectId(AccountId32::new([1u8; 32])); pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]); + pub(crate) const ACCOUNT_01: AccountId = AccountId::new([2u8; 32]); #[derive(Clone, Default)] pub(crate) struct ExtBuilder { diff --git a/pallets/ctype/src/tests.rs b/pallets/ctype/src/tests.rs index b9f32b9a1..1fae650a2 100644 --- a/pallets/ctype/src/tests.rs +++ b/pallets/ctype/src/tests.rs @@ -17,9 +17,11 @@ // If you feel like getting in touch with us, you can do so at info@botlabs.org use frame_support::{assert_noop, assert_ok, sp_runtime::traits::Hash}; +use frame_system::RawOrigin; use kilt_support::mock::mock_origin::DoubleOrigin; +use sp_runtime::DispatchError; -use crate::{self as ctype, mock::runtime::*, CtypeEntryOf}; +use crate::{self as ctype, mock::runtime::*, CtypeEntryOf, Ctypes, Error}; // submit_ctype_creation_operation @@ -88,3 +90,60 @@ fn check_duplicate_ctype_creation() { ); }); } + +// set_block_number + +#[test] +fn set_block_number_ok() { + let creator = DID_00; + let ctype = [9u8; 256].to_vec(); + let ctype_hash = ::Hashing::hash(&ctype[..]); + let new_block_number = 500u64; + + ExtBuilder::default() + .with_ctypes(vec![(ctype_hash, creator)]) + .build() + .execute_with(|| { + assert_ok!(Ctype::set_block_number( + RawOrigin::Signed(ACCOUNT_00).into(), + ctype_hash, + new_block_number + )); + assert_eq!( + Ctypes::::get(ctype_hash) + .expect("CType with provided hash should exist.") + .creation_block_number, + new_block_number + ); + }) +} + +#[test] +fn set_block_number_ctype_not_found() { + let ctype = [9u8; 256].to_vec(); + let ctype_hash = ::Hashing::hash(&ctype[..]); + + ExtBuilder::default().build().execute_with(|| { + assert_noop!( + Ctype::set_block_number(RawOrigin::Signed(ACCOUNT_00).into(), ctype_hash, 100u64), + Error::::CTypeNotFound + ); + }) +} + +#[test] +fn set_block_number_bad_origin() { + let creator = DID_00; + let ctype = [9u8; 256].to_vec(); + let ctype_hash = ::Hashing::hash(&ctype[..]); + + ExtBuilder::default() + .with_ctypes(vec![(ctype_hash, creator)]) + .build() + .execute_with(|| { + assert_noop!( + Ctype::set_block_number(RawOrigin::Signed(ACCOUNT_01).into(), ctype_hash, 100u64), + DispatchError::BadOrigin + ); + }) +} From e213ce9d8644044532dd97dcf46d4a90d76c0d4b Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 09:43:43 +0100 Subject: [PATCH 12/24] Fix ctype benchmarking --- pallets/ctype/src/benchmarking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/ctype/src/benchmarking.rs b/pallets/ctype/src/benchmarking.rs index 95726055c..2806cad81 100644 --- a/pallets/ctype/src/benchmarking.rs +++ b/pallets/ctype/src/benchmarking.rs @@ -57,10 +57,10 @@ benchmarks! { }: _(origin, ctype) verify { - let stored_ctype_creator: T::CtypeCreatorId = Ctypes::::get(ctype_hash).expect("CType hash should be present on chain."); + let stored_ctype_entry = Ctypes::::get(ctype_hash).expect("CType hash should be present on chain."); // Verify the CType has the right owner - assert_eq!(stored_ctype_creator, did); + assert_eq!(stored_ctype_entry.creator, did); } } From 1146e6d5ae05a7eb7486a9fd70e38e30c483b8a7 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 10:25:52 +0100 Subject: [PATCH 13/24] Fix all compilation issues --- pallets/attestation/src/benchmarking.rs | 32 +++++++++++++--- pallets/attestation/src/mock.rs | 2 + pallets/delegation/src/benchmarking.rs | 17 ++++++++- pallets/delegation/src/mock.rs | 2 + pallets/did/src/mock.rs | 1 + .../public-credentials/src/benchmarking.rs | 37 +++++++++++++++---- pallets/public-credentials/src/mock.rs | 2 + runtimes/peregrine/src/lib.rs | 3 ++ runtimes/spiritnet/src/lib.rs | 5 +++ runtimes/standalone/src/lib.rs | 1 + 10 files changed, 87 insertions(+), 15 deletions(-) diff --git a/pallets/attestation/src/benchmarking.rs b/pallets/attestation/src/benchmarking.rs index 479e0a65d..572889afe 100644 --- a/pallets/attestation/src/benchmarking.rs +++ b/pallets/attestation/src/benchmarking.rs @@ -21,6 +21,7 @@ use frame_support::traits::{Currency, Get}; use frame_system::RawOrigin; use sp_runtime::traits::Hash; +use ctype::CtypeEntryOf; use kilt_support::traits::GenerateBenchmarkOrigin; use crate::*; @@ -33,6 +34,7 @@ benchmarks! { T: core::fmt::Debug, ::EnsureOrigin: GenerateBenchmarkOrigin, T: ctype::Config, + T::BlockNumber: From } add { @@ -41,7 +43,10 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester.clone()); @@ -66,7 +71,10 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester.clone()); @@ -92,7 +100,10 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester.clone()); @@ -109,7 +120,10 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(sender.clone(), attester); @@ -127,7 +141,10 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); ::Currency::make_free_balance_be(&deposit_owner_old, ::Deposit::get() + ::Deposit::get()); ::Currency::make_free_balance_be(&deposit_owner_new, ::Deposit::get() + ::Deposit::get()); @@ -154,7 +171,10 @@ benchmarks! { let claim_hash: T::Hash = T::Hashing::hash(b"claim"); let ctype_hash: T::Hash = T::Hash::default(); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); ::Currency::make_free_balance_be(&deposit_owner, ::Deposit::get() + ::Deposit::get()); let origin = ::EnsureOrigin::generate_origin(deposit_owner.clone(), attester.clone()); diff --git a/pallets/attestation/src/mock.rs b/pallets/attestation/src/mock.rs index 66b7aeeec..7bb70b991 100644 --- a/pallets/attestation/src/mock.rs +++ b/pallets/attestation/src/mock.rs @@ -169,6 +169,7 @@ pub fn insert_attestation(claim_hash: ClaimHashOf, details: Attest #[cfg(test)] pub(crate) mod runtime { use frame_support::{parameter_types, weights::constants::RocksDbWeight}; + use frame_system::EnsureSigned; use sp_core::{ed25519, sr25519, Pair}; use sp_runtime::{ testing::Header, @@ -267,6 +268,7 @@ pub(crate) mod runtime { type CtypeCreatorId = SubjectId; type EnsureOrigin = mock_origin::EnsureDoubleOrigin; type OriginSuccess = mock_origin::DoubleOrigin; + type OverarchingOrigin = EnsureSigned; type Event = (); type WeightInfo = (); diff --git a/pallets/delegation/src/benchmarking.rs b/pallets/delegation/src/benchmarking.rs index 73dd553b7..a7ff1b164 100644 --- a/pallets/delegation/src/benchmarking.rs +++ b/pallets/delegation/src/benchmarking.rs @@ -32,6 +32,7 @@ use sp_runtime::traits::Zero; use sp_std::{num::NonZeroU32, vec::Vec}; use attestation::AttestationAccessControl; +use ctype::CtypeEntryOf; use kilt_support::{signature::VerifySignature, traits::GenerateBenchmarkOrigin}; const SEED: u32 = 0; @@ -61,6 +62,7 @@ where T::DelegationNodeId: From, T::CtypeCreatorId: From, ::EnsureOrigin: GenerateBenchmarkOrigin, + T::BlockNumber: From, { log::info!("create delegation root"); let root_public = sr25519_generate(KeyTypeId(*b"aura"), None); @@ -74,7 +76,13 @@ where ::Currency::minimum_balance() + ::Deposit::get() + ::Deposit::get(), ); - ctype::Ctypes::::insert(ctype_hash, T::CtypeCreatorId::from(root_acc.clone())); + ctype::Ctypes::::insert( + ctype_hash, + CtypeEntryOf:: { + creator: T::CtypeCreatorId::from(root_acc.clone()), + creation_block_number: 0u64.into(), + }, + ); Pallet::::create_hierarchy( ::EnsureOrigin::generate_origin(sender, root_acc.clone()), @@ -192,6 +200,7 @@ where <::DelegationSignatureVerification as VerifySignature>::Payload, )>, ::EnsureOrigin: GenerateBenchmarkOrigin, + T::BlockNumber: From, { let ( DelegationTriplet:: { @@ -227,6 +236,7 @@ benchmarks! { <::DelegationSignatureVerification as VerifySignature>::Payload, )>, ::EnsureOrigin: GenerateBenchmarkOrigin, + T::BlockNumber: From } create_hierarchy { @@ -234,7 +244,10 @@ benchmarks! { let creator: T::DelegationEntityId = account("creator", 0, SEED); let ctype = ::default(); let delegation = generate_delegation_id::(0); - ctype::Ctypes::::insert(ctype, ::CtypeCreatorId::from(creator.clone())); + ctype::Ctypes::::insert(ctype, CtypeEntryOf:: { + creator: T::CtypeCreatorId::from(creator.clone()), + creation_block_number: 0u64.into(), + }); ::Currency::make_free_balance_be( &sender, ::Currency::minimum_balance() + ::Deposit::get(), diff --git a/pallets/delegation/src/mock.rs b/pallets/delegation/src/mock.rs index a78679afd..d8c7ad6c8 100644 --- a/pallets/delegation/src/mock.rs +++ b/pallets/delegation/src/mock.rs @@ -175,6 +175,7 @@ pub(crate) mod runtime { use codec::Encode; use frame_support::{parameter_types, weights::constants::RocksDbWeight}; + use frame_system::EnsureSigned; use sp_core::{ed25519, sr25519, Pair}; use sp_runtime::{ testing::Header, @@ -283,6 +284,7 @@ pub(crate) mod runtime { type CtypeCreatorId = SubjectId; type EnsureOrigin = mock_origin::EnsureDoubleOrigin; type OriginSuccess = mock_origin::DoubleOrigin; + type OverarchingOrigin = EnsureSigned; type Event = (); type WeightInfo = (); diff --git a/pallets/did/src/mock.rs b/pallets/did/src/mock.rs index d49cdddc0..652a89f8d 100644 --- a/pallets/did/src/mock.rs +++ b/pallets/did/src/mock.rs @@ -196,6 +196,7 @@ impl ctype::Config for Test { type OriginSuccess = DidRawOrigin; type CtypeCreatorId = DidIdentifier; + type OverarchingOrigin = EnsureSigned; type Event = (); type WeightInfo = (); type Currency = Balances; diff --git a/pallets/public-credentials/src/benchmarking.rs b/pallets/public-credentials/src/benchmarking.rs index 0434da3f8..6d1b8ab9f 100644 --- a/pallets/public-credentials/src/benchmarking.rs +++ b/pallets/public-credentials/src/benchmarking.rs @@ -24,6 +24,7 @@ use frame_support::{ }; use sp_std::{boxed::Box, vec, vec::Vec}; +use ctype::CtypeEntryOf; use kilt_support::{ deposit::Deposit, traits::{GenerateBenchmarkOrigin, GetWorstCase}, @@ -53,6 +54,7 @@ benchmarks! { ::EnsureOrigin: GenerateBenchmarkOrigin, ::SubjectId: GetWorstCase + Into> + sp_std::fmt::Debug, ::CredentialId: Default, + T::BlockNumber: From } add { @@ -70,7 +72,10 @@ benchmarks! { )); let credential_id = generate_credential_id::(&creation_op, &attester); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); reserve_balance::(&sender); let origin = ::EnsureOrigin::generate_origin(sender, attester); }: _(origin, creation_op) @@ -97,7 +102,10 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester, + creation_block_number: 0u64.into() + }); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); }: _(origin, credential_id_clone, None) @@ -123,7 +131,10 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester, + creation_block_number: 0u64.into() + }); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); Pallet::::revoke(origin.clone(), credential_id.clone(), None).expect("Pallet::revoke should not fail"); let credential_id_clone = credential_id.clone(); @@ -149,7 +160,10 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester, + creation_block_number: 0u64.into() + }); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); }: _(origin, credential_id_clone, None) @@ -175,7 +189,10 @@ benchmarks! { reserve_balance::(&sender); - ctype::Ctypes::::insert(ctype_hash, attester); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester, + creation_block_number: 0u64.into() + }); Pallet::::add(origin, creation_op).expect("Pallet::add should not fail"); let origin = RawOrigin::Signed(sender); let credential_id_clone = credential_id.clone(); @@ -204,7 +221,10 @@ benchmarks! { reserve_balance::(&deposit_owner_old); reserve_balance::(&deposit_owner_new); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); Pallet::::add(origin, creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); let origin = ::EnsureOrigin::generate_origin(deposit_owner_new.clone(), attester); @@ -227,7 +247,10 @@ benchmarks! { let origin = ::EnsureOrigin::generate_origin(deposit_owner.clone(), attester.clone()); reserve_balance::(&deposit_owner); - ctype::Ctypes::::insert(ctype_hash, attester.clone()); + ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { + creator: attester.clone(), + creation_block_number: 0u64.into() + }); let credential_entry = generate_base_credential_entry::( deposit_owner.clone(), diff --git a/pallets/public-credentials/src/mock.rs b/pallets/public-credentials/src/mock.rs index f10cee76b..807217ebe 100644 --- a/pallets/public-credentials/src/mock.rs +++ b/pallets/public-credentials/src/mock.rs @@ -100,6 +100,7 @@ pub(crate) mod runtime { traits::{ConstU128, ConstU16, ConstU32, ConstU64}, weights::constants::RocksDbWeight, }; + use frame_system::EnsureSigned; use scale_info::TypeInfo; use sp_core::{sr25519, Pair}; use sp_runtime::{ @@ -333,6 +334,7 @@ pub(crate) mod runtime { type CtypeCreatorId = SubjectId; type EnsureOrigin = mock_origin::EnsureDoubleOrigin; type OriginSuccess = mock_origin::DoubleOrigin; + type OverarchingOrigin = EnsureSigned; type Event = (); type WeightInfo = (); diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index bde833482..cc21ae00e 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -556,6 +556,8 @@ impl delegation::Config for Runtime { type Deposit = constants::delegation::DelegationDeposit; } +type CTypeBlockNumberSetOrigin = pallet_collective::EnsureProportionAtLeast; + impl ctype::Config for Runtime { type CtypeCreatorId = AccountId; type Currency = Balances; @@ -564,6 +566,7 @@ impl ctype::Config for Runtime { type EnsureOrigin = did::EnsureDidOrigin; type OriginSuccess = did::DidRawOrigin; + type OverarchingOrigin = CTypeBlockNumberSetOrigin; type Event = Event; type WeightInfo = weights::ctype::WeightInfo; diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index e4d20004b..334d31551 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -553,6 +553,8 @@ impl delegation::Config for Runtime { type Deposit = constants::delegation::DelegationDeposit; } +type CTypeBlockNumberSetOrigin = pallet_collective::EnsureProportionAtLeast; + impl ctype::Config for Runtime { type CtypeCreatorId = AccountId; type Currency = Balances; @@ -561,6 +563,9 @@ impl ctype::Config for Runtime { type EnsureOrigin = did::EnsureDidOrigin; type OriginSuccess = did::DidRawOrigin; + // 3/5 of the technical committees can override the block number of one or more + // CTypes. + type OverarchingOrigin = CTypeBlockNumberSetOrigin; type Event = Event; type WeightInfo = weights::ctype::WeightInfo; diff --git a/runtimes/standalone/src/lib.rs b/runtimes/standalone/src/lib.rs index 8cfc60631..f77366f2a 100644 --- a/runtimes/standalone/src/lib.rs +++ b/runtimes/standalone/src/lib.rs @@ -353,6 +353,7 @@ impl ctype::Config for Runtime { type CtypeCreatorId = DidIdentifier; type EnsureOrigin = did::EnsureDidOrigin; type OriginSuccess = did::DidRawOrigin; + type OverarchingOrigin = EnsureRoot; type Event = Event; type WeightInfo = (); } From 137b0db058537feab5157d5a5ca38968ab8edb96 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 11:16:21 +0100 Subject: [PATCH 14/24] Add default weights for new extrinsic --- pallets/ctype/src/benchmarking.rs | 25 ++++++++++++++++++++++++- pallets/ctype/src/default_weights.rs | 15 ++++++++++++++- pallets/ctype/src/lib.rs | 2 +- runtimes/peregrine/src/weights/ctype.rs | 8 +++++++- runtimes/spiritnet/src/weights/ctype.rs | 6 ++++++ 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/pallets/ctype/src/benchmarking.rs b/pallets/ctype/src/benchmarking.rs index 2806cad81..7b7a7e3e8 100644 --- a/pallets/ctype/src/benchmarking.rs +++ b/pallets/ctype/src/benchmarking.rs @@ -19,7 +19,7 @@ use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; use frame_support::{ sp_runtime::traits::Hash, - traits::{Currency, Get}, + traits::{Currency, EnsureOrigin, Get}, }; use sp_std::{ convert::{TryFrom, TryInto}, @@ -40,6 +40,7 @@ benchmarks! { <::Currency as Currency>>::Balance: TryFrom, <<::Currency as Currency<::AccountId>>::Balance as TryFrom>::Error: Debug, T::EnsureOrigin: GenerateBenchmarkOrigin, + T::BlockNumber: From, } add { @@ -62,6 +63,28 @@ benchmarks! { // Verify the CType has the right owner assert_eq!(stored_ctype_entry.creator, did); } + + set_block_number { + let caller = account("caller", 0, SEED); + let did: T::CtypeCreatorId = account("did", 0, SEED); + + let ctype: Vec = (0u8..u8::MAX).cycle().take(MAX_CTYPE_SIZE.try_into().unwrap()).collect(); + let ctype_hash = ::Hashing::hash(&ctype[..]); + let new_block_number = 500u64.into(); + + let initial_balance = ::Fee::get() * ctype.len().try_into().unwrap() + ::Currency::minimum_balance(); + ::Currency::make_free_balance_be(&caller, initial_balance); + let origin = T::EnsureOrigin::generate_origin(caller, did.clone()); + Pallet::::add(origin, ctype).expect("CType creation should not fail."); + let overarching_origin = T::OverarchingOrigin::successful_origin(); + + }: _(overarching_origin, ctype_hash, new_block_number) + verify { + let stored_ctype_entry = Ctypes::::get(ctype_hash).expect("CType hash should be present on chain."); + + // Verify the CType has the right block number + assert_eq!(stored_ctype_entry.creation_block_number, new_block_number); + } } impl_benchmark_test_suite! { diff --git a/pallets/ctype/src/default_weights.rs b/pallets/ctype/src/default_weights.rs index 49598a802..6e64d75cb 100644 --- a/pallets/ctype/src/default_weights.rs +++ b/pallets/ctype/src/default_weights.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for ctype //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-07, STEPS: {{cmd.steps}}\, REPEAT: {{cmd.repeat}}\, LOW RANGE: {{cmd.lowest_range_values}}\, HIGH RANGE: {{cmd.highest_range_values}}\ +//! DATE: 2022-11-30, STEPS: {{cmd.steps}}\, REPEAT: {{cmd.repeat}}\, LOW RANGE: {{cmd.lowest_range_values}}\, HIGH RANGE: {{cmd.highest_range_values}}\ //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -48,6 +48,7 @@ use sp_std::marker::PhantomData; /// Weight functions needed for ctype. pub trait WeightInfo { fn add(l: u32, ) -> Weight; + fn set_block_number() -> Weight; } /// Weights for ctype using the Substrate node and recommended hardware. @@ -63,6 +64,12 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(3 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } + // Storage: Ctype Ctypes (r:1 w:1) + fn set_block_number() -> Weight { + Weight::from_ref_time(20_685_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } } // For backwards compatibility and tests @@ -77,4 +84,10 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3 as u64)) .saturating_add(RocksDbWeight::get().writes(3 as u64)) } + // Storage: Ctype Ctypes (r:1 w:1) + fn set_block_number() -> Weight { + Weight::from_ref_time(20_685_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } } diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index ee7e6e2b6..61c57a4bd 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -196,7 +196,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(::WeightInfo::set_block_number())] pub fn set_block_number( origin: OriginFor, ctype_hash: CtypeHashOf, diff --git a/runtimes/peregrine/src/weights/ctype.rs b/runtimes/peregrine/src/weights/ctype.rs index e27658f54..f386af435 100644 --- a/runtimes/peregrine/src/weights/ctype.rs +++ b/runtimes/peregrine/src/weights/ctype.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for ctype //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-11-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -57,4 +57,10 @@ impl ctype::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } + // Storage: Ctype Ctypes (r:1 w:1) + fn set_block_number() -> Weight { + Weight::from_ref_time(19_549_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } } diff --git a/runtimes/spiritnet/src/weights/ctype.rs b/runtimes/spiritnet/src/weights/ctype.rs index c3e962d8e..217874f3d 100644 --- a/runtimes/spiritnet/src/weights/ctype.rs +++ b/runtimes/spiritnet/src/weights/ctype.rs @@ -57,4 +57,10 @@ impl ctype::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } + // Storage: Ctype Ctypes (r:1 w:1) + fn set_block_number() -> Weight { + Weight::from_ref_time(19_549_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } } From caf9b2400ee616ae83ed2f7ab6347ce8a688ae34 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 11:31:30 +0100 Subject: [PATCH 15/24] Final chores --- pallets/attestation/src/mock.rs | 2 +- pallets/ctype/src/benchmarking.rs | 2 +- pallets/ctype/src/lib.rs | 4 ++-- pallets/ctype/src/mock.rs | 2 +- pallets/ctype/src/tests.rs | 13 +++++++------ pallets/delegation/src/mock.rs | 2 +- pallets/did/src/mock.rs | 2 +- pallets/public-credentials/src/mock.rs | 2 +- runtimes/peregrine/src/lib.rs | 2 ++ 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pallets/attestation/src/mock.rs b/pallets/attestation/src/mock.rs index 7bb70b991..06b310346 100644 --- a/pallets/attestation/src/mock.rs +++ b/pallets/attestation/src/mock.rs @@ -372,7 +372,7 @@ pub(crate) mod runtime { ctype.0, CtypeEntryOf:: { creator: ctype.1.clone(), - creation_block_number: 0, + creation_block_number: System::block_number(), }, ); } diff --git a/pallets/ctype/src/benchmarking.rs b/pallets/ctype/src/benchmarking.rs index 7b7a7e3e8..e5cd20210 100644 --- a/pallets/ctype/src/benchmarking.rs +++ b/pallets/ctype/src/benchmarking.rs @@ -74,7 +74,7 @@ benchmarks! { let initial_balance = ::Fee::get() * ctype.len().try_into().unwrap() + ::Currency::minimum_balance(); ::Currency::make_free_balance_be(&caller, initial_balance); - let origin = T::EnsureOrigin::generate_origin(caller, did.clone()); + let origin = T::EnsureOrigin::generate_origin(caller, did); Pallet::::add(origin, ctype).expect("CType creation should not fail."); let overarching_origin = T::OverarchingOrigin::successful_origin(); diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 61c57a4bd..6e77f8776 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -59,8 +59,6 @@ pub use crate::{default_weights::WeightInfo, pallet::*}; #[frame_support::pallet] pub mod pallet { - use crate::ctype_entry::CtypeEntry; - use super::*; use frame_support::{ pallet_prelude::*, @@ -72,6 +70,8 @@ pub mod pallet { use sp_runtime::{traits::Saturating, SaturatedConversion}; use sp_std::vec::Vec; + use crate::ctype_entry::CtypeEntry; + /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); diff --git a/pallets/ctype/src/mock.rs b/pallets/ctype/src/mock.rs index 33d090280..cd43a06d0 100644 --- a/pallets/ctype/src/mock.rs +++ b/pallets/ctype/src/mock.rs @@ -187,7 +187,7 @@ pub mod runtime { ctype_hash, CtypeEntryOf:: { creator: owner.clone(), - creation_block_number: 0, + creation_block_number: System::block_number(), }, ); } diff --git a/pallets/ctype/src/tests.rs b/pallets/ctype/src/tests.rs index 1fae650a2..9170783d7 100644 --- a/pallets/ctype/src/tests.rs +++ b/pallets/ctype/src/tests.rs @@ -18,10 +18,11 @@ use frame_support::{assert_noop, assert_ok, sp_runtime::traits::Hash}; use frame_system::RawOrigin; -use kilt_support::mock::mock_origin::DoubleOrigin; use sp_runtime::DispatchError; -use crate::{self as ctype, mock::runtime::*, CtypeEntryOf, Ctypes, Error}; +use kilt_support::mock::mock_origin::DoubleOrigin; + +use crate::{self as ctype, mock::runtime::*}; // submit_ctype_creation_operation @@ -43,10 +44,10 @@ fn check_successful_ctype_creation() { )); let stored_ctype_creator = Ctype::ctypes(&ctype_hash).expect("CType hash should be present on chain."); - // Verify the CType has the right owner + // Verify the CType has the right owner and block number assert_eq!( stored_ctype_creator, - CtypeEntryOf:: { + ctype::CtypeEntryOf:: { creator, creation_block_number: 200 } @@ -110,7 +111,7 @@ fn set_block_number_ok() { new_block_number )); assert_eq!( - Ctypes::::get(ctype_hash) + ctype::Ctypes::::get(ctype_hash) .expect("CType with provided hash should exist.") .creation_block_number, new_block_number @@ -126,7 +127,7 @@ fn set_block_number_ctype_not_found() { ExtBuilder::default().build().execute_with(|| { assert_noop!( Ctype::set_block_number(RawOrigin::Signed(ACCOUNT_00).into(), ctype_hash, 100u64), - Error::::CTypeNotFound + ctype::Error::::CTypeNotFound ); }) } diff --git a/pallets/delegation/src/mock.rs b/pallets/delegation/src/mock.rs index d8c7ad6c8..7502a8d5e 100644 --- a/pallets/delegation/src/mock.rs +++ b/pallets/delegation/src/mock.rs @@ -498,7 +498,7 @@ pub(crate) mod runtime { ctype_hash, CtypeEntryOf:: { creator: owner.clone(), - creation_block_number: 0, + creation_block_number: System::block_number(), }, ); } diff --git a/pallets/did/src/mock.rs b/pallets/did/src/mock.rs index 652a89f8d..14f42dfbc 100644 --- a/pallets/did/src/mock.rs +++ b/pallets/did/src/mock.rs @@ -477,7 +477,7 @@ impl ExtBuilder { ctype_hash, ctype::CtypeEntryOf:: { creator: owner.to_owned(), - creation_block_number: 0, + creation_block_number: System::block_number(), }, ); } diff --git a/pallets/public-credentials/src/mock.rs b/pallets/public-credentials/src/mock.rs index 807217ebe..dd0bd363f 100644 --- a/pallets/public-credentials/src/mock.rs +++ b/pallets/public-credentials/src/mock.rs @@ -430,7 +430,7 @@ pub(crate) mod runtime { ctype.0, CtypeEntryOf:: { creator: ctype.1.clone(), - creation_block_number: 0, + creation_block_number: System::block_number(), }, ); } diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index cc21ae00e..0eb4bb0b7 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -566,6 +566,8 @@ impl ctype::Config for Runtime { type EnsureOrigin = did::EnsureDidOrigin; type OriginSuccess = did::DidRawOrigin; + // 3/5 of the technical committees can override the block number of one or more + // CTypes. type OverarchingOrigin = CTypeBlockNumberSetOrigin; type Event = Event; From 25772b5cd4e15d7fe1e88cd45a7756d84190aef7 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 12:02:53 +0100 Subject: [PATCH 16/24] Fix ctype migration logic --- pallets/ctype/src/lib.rs | 2 +- runtimes/common/src/migrations.rs | 4 ++-- runtimes/peregrine/src/lib.rs | 6 +----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 6e77f8776..a39100696 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -73,7 +73,7 @@ pub mod pallet { use crate::ctype_entry::CtypeEntry; /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); /// Type of a CType hash. pub type CtypeHashOf = ::Hash; diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index cbe017f35..228af5f2a 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -34,7 +34,7 @@ pub struct AddCTypeBlockNumber(PhantomData); impl OnRuntimeUpgrade for AddCTypeBlockNumber { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result<(), &'static str> { - assert_eq!(ctype::Pallet::::on_chain_storage_version(), 1,); + assert_eq!(ctype::Pallet::::on_chain_storage_version(), 0,); assert!(MigrationCounter::::get().is_zero()); let ctypes_to_migrate = ctype::Ctypes::::iter().count(); @@ -72,7 +72,7 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { #[cfg(feature = "try-runtime")] fn post_upgrade() -> Result<(), &'static str> { - assert_eq!(ctype::Pallet::::on_chain_storage_version(), 2); + assert_eq!(ctype::Pallet::::on_chain_storage_version(), 1); assert_eq!(MigrationCounter::::get(), ctype::Ctypes::::iter().count() as u32); diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index 0eb4bb0b7..0c09c0bcf 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -556,8 +556,6 @@ impl delegation::Config for Runtime { type Deposit = constants::delegation::DelegationDeposit; } -type CTypeBlockNumberSetOrigin = pallet_collective::EnsureProportionAtLeast; - impl ctype::Config for Runtime { type CtypeCreatorId = AccountId; type Currency = Balances; @@ -566,9 +564,7 @@ impl ctype::Config for Runtime { type EnsureOrigin = did::EnsureDidOrigin; type OriginSuccess = did::DidRawOrigin; - // 3/5 of the technical committees can override the block number of one or more - // CTypes. - type OverarchingOrigin = CTypeBlockNumberSetOrigin; + type OverarchingOrigin = EnsureRoot; type Event = Event; type WeightInfo = weights::ctype::WeightInfo; From ae3b2b36029f30c477424e06a5603ee6a9b1b910 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 13:19:00 +0100 Subject: [PATCH 17/24] Fix ctype migration --- runtimes/common/src/migrations.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index 228af5f2a..959959047 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -37,9 +37,10 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { assert_eq!(ctype::Pallet::::on_chain_storage_version(), 0,); assert!(MigrationCounter::::get().is_zero()); - let ctypes_to_migrate = ctype::Ctypes::::iter().count(); + // Use iter_keys() on new storage so it won't try to decode values. + let ctypes_to_migrate = ctype::Ctypes::::iter_keys().count(); - log::info!("💰 CType pallet pre check: {:?} CTypes", ctypes_to_migrate); + log::info!("🪪 CType pallet pre check: {:?} CTypes to migrate", ctypes_to_migrate); MigrationCounter::::set(ctypes_to_migrate as u32); Ok(()) @@ -56,12 +57,13 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { ); let mut num_translations = 0u64; + let default_block_number = ::BlockNumber::zero(); ctype::Ctypes::::translate_values(|old: CtypeCreatorOf| { num_translations = num_translations.saturating_add(1); Some(CtypeEntryOf:: { creator: old, - creation_block_number: ::BlockNumber::zero(), + creation_block_number: default_block_number, }) }); current.put::>(); @@ -74,9 +76,17 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { fn post_upgrade() -> Result<(), &'static str> { assert_eq!(ctype::Pallet::::on_chain_storage_version(), 1); + // Use iter() on new storage so it also checks that the new values can be + // decoded after the migration. assert_eq!(MigrationCounter::::get(), ctype::Ctypes::::iter().count() as u32); + if let Some(ctype_entry) = ctype::Ctypes::::iter_values().last() { + assert!(ctype_entry.creation_block_number.is_zero()); + } - log::info!("💰 CType pallet post checks ok ✅"); + log::info!( + "🪪 CType pallet post checks ok, all {:} CTypes have been migrated ✅", + MigrationCounter::::get() + ); Ok(()) } } From 504b386f1035c0722a7bd3206f340ae62f93e464 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Wed, 30 Nov 2022 13:32:15 +0100 Subject: [PATCH 18/24] Final comments --- pallets/ctype/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index a39100696..34b996fef 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -65,7 +65,7 @@ pub mod pallet { sp_runtime::traits::Hash, traits::{Currency, ExistenceRequirement, OnUnbalanced, StorageVersion, WithdrawReasons}, }; - use frame_system::pallet_prelude::{BlockNumberFor, *}; + use frame_system::pallet_prelude::*; use kilt_support::traits::CallSources; use sp_runtime::{traits::Saturating, SaturatedConversion}; use sp_std::vec::Vec; @@ -123,6 +123,9 @@ pub mod pallet { /// A new CType has been created. /// \[creator identifier, CType hash\] CTypeCreated(CtypeCreatorOf, CtypeHashOf), + /// Information about a CType has been updated. + /// \[CType hash\] + CTypeUpdated(CtypeHashOf), } #[pallet::error] @@ -196,6 +199,9 @@ pub mod pallet { Ok(()) } + /// Set the creation block number for a given CType, if found. + /// + /// Emits `CTypeUpdated`. #[pallet::weight(::WeightInfo::set_block_number())] pub fn set_block_number( origin: OriginFor, @@ -212,6 +218,8 @@ pub mod pallet { } })?; + Self::deposit_event(Event::CTypeUpdated(ctype_hash)); + Ok(()) } } From ffc79c2e46e7bf91dae27058bb993de7ddbe10c2 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 13 Dec 2022 09:21:49 +0100 Subject: [PATCH 19/24] Rename ctype property --- pallets/attestation/src/mock.rs | 2 +- pallets/ctype/src/ctype_entry.rs | 2 +- pallets/ctype/src/lib.rs | 4 ++-- pallets/ctype/src/mock.rs | 2 +- pallets/ctype/src/tests.rs | 4 ++-- pallets/delegation/src/mock.rs | 2 +- pallets/did/src/mock.rs | 2 +- pallets/public-credentials/src/mock.rs | 2 +- runtimes/common/src/migrations.rs | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pallets/attestation/src/mock.rs b/pallets/attestation/src/mock.rs index 2cfb394f1..c301c24f3 100644 --- a/pallets/attestation/src/mock.rs +++ b/pallets/attestation/src/mock.rs @@ -372,7 +372,7 @@ pub(crate) mod runtime { ctype.0, CtypeEntryOf:: { creator: ctype.1.clone(), - creation_block_number: System::block_number(), + created_at: System::block_number(), }, ); } diff --git a/pallets/ctype/src/ctype_entry.rs b/pallets/ctype/src/ctype_entry.rs index 05c435d6c..6a0cbd2c7 100644 --- a/pallets/ctype/src/ctype_entry.rs +++ b/pallets/ctype/src/ctype_entry.rs @@ -8,5 +8,5 @@ pub struct CtypeEntry { /// Identifier of the creator. pub creator: Creator, /// Block number in which the creation tx was dispatched. - pub creation_block_number: BlockNumber, + pub created_at: BlockNumber, } diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 86445ad7b..a6bab80f9 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -190,7 +190,7 @@ pub mod pallet { hash, CtypeEntryOf:: { creator: creator.clone(), - creation_block_number: frame_system::Pallet::::block_number(), + created_at: frame_system::Pallet::::block_number(), }, ); @@ -211,7 +211,7 @@ pub mod pallet { T::OverarchingOrigin::ensure_origin(origin)?; Ctypes::::try_mutate(ctype_hash, |ctype_entry| -> Result<(), Error> { if let Some(ctype_entry) = ctype_entry { - ctype_entry.creation_block_number = block_number; + ctype_entry.created_at = block_number; Ok(()) } else { Err(Error::::CTypeNotFound) diff --git a/pallets/ctype/src/mock.rs b/pallets/ctype/src/mock.rs index 57cb4dd61..7f71934e8 100644 --- a/pallets/ctype/src/mock.rs +++ b/pallets/ctype/src/mock.rs @@ -187,7 +187,7 @@ pub mod runtime { ctype_hash, CtypeEntryOf:: { creator: owner.clone(), - creation_block_number: System::block_number(), + created_at: System::block_number(), }, ); } diff --git a/pallets/ctype/src/tests.rs b/pallets/ctype/src/tests.rs index 9170783d7..63dbd40ea 100644 --- a/pallets/ctype/src/tests.rs +++ b/pallets/ctype/src/tests.rs @@ -49,7 +49,7 @@ fn check_successful_ctype_creation() { stored_ctype_creator, ctype::CtypeEntryOf:: { creator, - creation_block_number: 200 + created_at: 200 } ); assert_eq!( @@ -113,7 +113,7 @@ fn set_block_number_ok() { assert_eq!( ctype::Ctypes::::get(ctype_hash) .expect("CType with provided hash should exist.") - .creation_block_number, + .created_at, new_block_number ); }) diff --git a/pallets/delegation/src/mock.rs b/pallets/delegation/src/mock.rs index ac1609955..a289de8d5 100644 --- a/pallets/delegation/src/mock.rs +++ b/pallets/delegation/src/mock.rs @@ -498,7 +498,7 @@ pub(crate) mod runtime { ctype_hash, CtypeEntryOf:: { creator: owner.clone(), - creation_block_number: System::block_number(), + created_at: System::block_number(), }, ); } diff --git a/pallets/did/src/mock.rs b/pallets/did/src/mock.rs index 1039ae641..134001704 100644 --- a/pallets/did/src/mock.rs +++ b/pallets/did/src/mock.rs @@ -477,7 +477,7 @@ impl ExtBuilder { ctype_hash, ctype::CtypeEntryOf:: { creator: owner.to_owned(), - creation_block_number: System::block_number(), + created_at: System::block_number(), }, ); } diff --git a/pallets/public-credentials/src/mock.rs b/pallets/public-credentials/src/mock.rs index c552ff48e..5a83e86fd 100644 --- a/pallets/public-credentials/src/mock.rs +++ b/pallets/public-credentials/src/mock.rs @@ -430,7 +430,7 @@ pub(crate) mod runtime { ctype.0, CtypeEntryOf:: { creator: ctype.1.clone(), - creation_block_number: System::block_number(), + created_at: System::block_number(), }, ); } diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index 959959047..549fac45a 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -63,7 +63,7 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { num_translations = num_translations.saturating_add(1); Some(CtypeEntryOf:: { creator: old, - creation_block_number: default_block_number, + created_at: default_block_number, }) }); current.put::>(); From 147536f03f84b27c823a8296379d56fb99a2b5f7 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 13 Dec 2022 09:23:09 +0100 Subject: [PATCH 20/24] Remove unnecessary return type from closure --- pallets/ctype/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index a6bab80f9..c6fa853cc 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -209,7 +209,7 @@ pub mod pallet { block_number: BlockNumberFor, ) -> DispatchResult { T::OverarchingOrigin::ensure_origin(origin)?; - Ctypes::::try_mutate(ctype_hash, |ctype_entry| -> Result<(), Error> { + Ctypes::::try_mutate(ctype_hash, |ctype_entry| { if let Some(ctype_entry) = ctype_entry { ctype_entry.created_at = block_number; Ok(()) From 4d92056e7b37a14655f461da57441795c1a89605 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 13 Dec 2022 09:38:47 +0100 Subject: [PATCH 21/24] Update migration to use new try-runtime features --- pallets/attestation/src/benchmarking.rs | 12 ++++---- pallets/ctype/src/benchmarking.rs | 4 +-- pallets/delegation/src/benchmarking.rs | 4 +-- .../public-credentials/src/benchmarking.rs | 14 +++++----- runtimes/common/src/migrations.rs | 28 ++++++++----------- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/pallets/attestation/src/benchmarking.rs b/pallets/attestation/src/benchmarking.rs index 13d752e47..0edbd932c 100644 --- a/pallets/attestation/src/benchmarking.rs +++ b/pallets/attestation/src/benchmarking.rs @@ -45,7 +45,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); @@ -73,7 +73,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); @@ -102,7 +102,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); @@ -122,7 +122,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); ::Currency::make_free_balance_be(&sender, ::Deposit::get() + ::Deposit::get()); @@ -143,7 +143,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); ::Currency::make_free_balance_be(&deposit_owner_old, ::Deposit::get() + ::Deposit::get()); ::Currency::make_free_balance_be(&deposit_owner_new, ::Deposit::get() + ::Deposit::get()); @@ -173,7 +173,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); ::Currency::make_free_balance_be(&deposit_owner, ::Deposit::get() + ::Deposit::get()); diff --git a/pallets/ctype/src/benchmarking.rs b/pallets/ctype/src/benchmarking.rs index 16ebdfd8b..31325561e 100644 --- a/pallets/ctype/src/benchmarking.rs +++ b/pallets/ctype/src/benchmarking.rs @@ -78,12 +78,12 @@ benchmarks! { Pallet::::add(origin, ctype).expect("CType creation should not fail."); let overarching_origin = T::OverarchingOrigin::successful_origin(); - }: _(overarching_origin, ctype_hash, new_block_number) + }: _(overarching_origin, ctype_hash, new_block_number) verify { let stored_ctype_entry = Ctypes::::get(ctype_hash).expect("CType hash should be present on chain."); // Verify the CType has the right block number - assert_eq!(stored_ctype_entry.creation_block_number, new_block_number); + assert_eq!(stored_ctype_entry.created_at, new_block_number); } } diff --git a/pallets/delegation/src/benchmarking.rs b/pallets/delegation/src/benchmarking.rs index 1ffa5baa8..5c701f75a 100644 --- a/pallets/delegation/src/benchmarking.rs +++ b/pallets/delegation/src/benchmarking.rs @@ -80,7 +80,7 @@ where ctype_hash, CtypeEntryOf:: { creator: T::CtypeCreatorId::from(root_acc.clone()), - creation_block_number: 0u64.into(), + created_at: 0u64.into(), }, ); @@ -246,7 +246,7 @@ benchmarks! { let delegation = generate_delegation_id::(0); ctype::Ctypes::::insert(ctype, CtypeEntryOf:: { creator: T::CtypeCreatorId::from(creator.clone()), - creation_block_number: 0u64.into(), + created_at: 0u64.into(), }); ::Currency::make_free_balance_be( &sender, diff --git a/pallets/public-credentials/src/benchmarking.rs b/pallets/public-credentials/src/benchmarking.rs index 591c2f3a2..f7a560366 100644 --- a/pallets/public-credentials/src/benchmarking.rs +++ b/pallets/public-credentials/src/benchmarking.rs @@ -74,7 +74,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); reserve_balance::(&sender); let origin = ::EnsureOrigin::generate_origin(sender, attester); @@ -104,7 +104,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester, - creation_block_number: 0u64.into() + created_at: 0u64.into() }); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); @@ -133,7 +133,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester, - creation_block_number: 0u64.into() + created_at: 0u64.into() }); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); Pallet::::revoke(origin.clone(), credential_id.clone(), None).expect("Pallet::revoke should not fail"); @@ -162,7 +162,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester, - creation_block_number: 0u64.into() + created_at: 0u64.into() }); Pallet::::add(origin.clone(), creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); @@ -191,7 +191,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester, - creation_block_number: 0u64.into() + created_at: 0u64.into() }); Pallet::::add(origin, creation_op).expect("Pallet::add should not fail"); let origin = RawOrigin::Signed(sender); @@ -223,7 +223,7 @@ benchmarks! { ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); Pallet::::add(origin, creation_op).expect("Pallet::add should not fail"); let credential_id_clone = credential_id.clone(); @@ -249,7 +249,7 @@ benchmarks! { reserve_balance::(&deposit_owner); ctype::Ctypes::::insert(ctype_hash, CtypeEntryOf:: { creator: attester.clone(), - creation_block_number: 0u64.into() + created_at: 0u64.into() }); let credential_entry = generate_base_credential_entry::( diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index 549fac45a..197c1d65b 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -16,34 +16,27 @@ // If you feel like getting in touch with us, you can do so at info@botlabs.org -use frame_support::{ - pallet_prelude::ValueQuery, - storage_alias, - traits::{GetStorageVersion, OnRuntimeUpgrade}, -}; +use frame_support::traits::{GetStorageVersion, OnRuntimeUpgrade}; use sp_runtime::traits::{Get, Zero}; use sp_std::marker::PhantomData; use ctype::{CtypeCreatorOf, CtypeEntryOf}; -#[storage_alias] -type MigrationCounter = StorageValue, u32, ValueQuery>; +#[cfg(feature = "try-runtime")] +use sp_std::vec::Vec; pub struct AddCTypeBlockNumber(PhantomData); impl OnRuntimeUpgrade for AddCTypeBlockNumber { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result<(), &'static str> { + fn pre_upgrade() -> Result, &'static str> { assert_eq!(ctype::Pallet::::on_chain_storage_version(), 0,); - assert!(MigrationCounter::::get().is_zero()); // Use iter_keys() on new storage so it won't try to decode values. - let ctypes_to_migrate = ctype::Ctypes::::iter_keys().count(); + let ctypes_to_migrate = ctype::Ctypes::::iter_keys().count() as u64; log::info!("🪪 CType pallet pre check: {:?} CTypes to migrate", ctypes_to_migrate); - - MigrationCounter::::set(ctypes_to_migrate as u32); - Ok(()) + Ok(ctypes_to_migrate.to_be_bytes().into()) } fn on_runtime_upgrade() -> frame_support::weights::Weight { @@ -73,19 +66,20 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { } #[cfg(feature = "try-runtime")] - fn post_upgrade() -> Result<(), &'static str> { + fn post_upgrade(state: Vec) -> Result<(), &'static str> { assert_eq!(ctype::Pallet::::on_chain_storage_version(), 1); + let initial_ctype_count = u64::from_be_bytes(state.try_into().expect("input state should be 8 bytes")); // Use iter() on new storage so it also checks that the new values can be // decoded after the migration. - assert_eq!(MigrationCounter::::get(), ctype::Ctypes::::iter().count() as u32); + assert_eq!(initial_ctype_count, ctype::Ctypes::::iter().count() as u64); if let Some(ctype_entry) = ctype::Ctypes::::iter_values().last() { - assert!(ctype_entry.creation_block_number.is_zero()); + assert!(ctype_entry.created_at.is_zero()); } log::info!( "🪪 CType pallet post checks ok, all {:} CTypes have been migrated ✅", - MigrationCounter::::get() + initial_ctype_count ); Ok(()) } From 8b4c9dcc68390383f61372d428cdcbbddf6bcdcc Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 13 Dec 2022 09:41:50 +0100 Subject: [PATCH 22/24] Decode all values after migration --- runtimes/common/src/migrations.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index 197c1d65b..757528eba 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -70,12 +70,9 @@ impl OnRuntimeUpgrade for AddCTypeBlockNumber { assert_eq!(ctype::Pallet::::on_chain_storage_version(), 1); let initial_ctype_count = u64::from_be_bytes(state.try_into().expect("input state should be 8 bytes")); - // Use iter() on new storage so it also checks that the new values can be - // decoded after the migration. assert_eq!(initial_ctype_count, ctype::Ctypes::::iter().count() as u64); - if let Some(ctype_entry) = ctype::Ctypes::::iter_values().last() { - assert!(ctype_entry.created_at.is_zero()); - } + // Verify all migrated ctypes can be decoded under the new type. + ctype::Ctypes::::iter_values().for_each(|v| assert!(v.created_at.is_zero())); log::info!( "🪪 CType pallet post checks ok, all {:} CTypes have been migrated ✅", From d1e2deffad2b35efcb46b70579222a46f878eaca Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Mon, 9 Jan 2023 15:41:45 +0100 Subject: [PATCH 23/24] Replace technical committee with democracy --- runtimes/spiritnet/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index dfa7f2847..fccc76723 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -551,8 +551,6 @@ impl delegation::Config for Runtime { type Deposit = constants::delegation::DelegationDeposit; } -type CTypeBlockNumberSetOrigin = pallet_collective::EnsureProportionAtLeast; - impl ctype::Config for Runtime { type CtypeCreatorId = AccountId; type Currency = Balances; @@ -563,7 +561,7 @@ impl ctype::Config for Runtime { type OriginSuccess = did::DidRawOrigin; // 3/5 of the technical committees can override the block number of one or more // CTypes. - type OverarchingOrigin = CTypeBlockNumberSetOrigin; + type OverarchingOrigin = EnsureRoot; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::ctype::WeightInfo; From ec518eb7b7663dd3c1b2243bc5d82e7835a0746d Mon Sep 17 00:00:00 2001 From: weichweich Date: Mon, 23 Jan 2023 15:55:40 +0100 Subject: [PATCH 24/24] fix: ctype call index --- pallets/ctype/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/ctype/src/lib.rs b/pallets/ctype/src/lib.rs index 854e9878d..61758d8a2 100644 --- a/pallets/ctype/src/lib.rs +++ b/pallets/ctype/src/lib.rs @@ -203,6 +203,7 @@ pub mod pallet { /// Set the creation block number for a given CType, if found. /// /// Emits `CTypeUpdated`. + #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::set_block_number())] pub fn set_block_number( origin: OriginFor,