Skip to content

Commit

Permalink
feat: remove public credentials from spiritnet
Browse files Browse the repository at this point in the history
we test first on peregrine and will later enable this feature on spiritnet
  • Loading branch information
weichweich committed Nov 7, 2022
1 parent 2582408 commit 6d4fcc6
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 179 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions runtimes/spiritnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ hex-literal = {workspace = true, optional = true}
# RPC & Runtime API
frame-system-rpc-runtime-api.workspace = true
kilt-runtime-api-did.workspace = true
kilt-runtime-api-public-credentials.workspace = true
kilt-runtime-api-staking.workspace = true
pallet-transaction-payment-rpc-runtime-api.workspace = true

Expand All @@ -40,7 +39,6 @@ pallet-did-lookup.workspace = true
pallet-inflation.workspace = true
pallet-web3-names.workspace = true
parachain-staking.workspace = true
public-credentials.workspace = true
runtime-common.workspace = true

# Substrate dependencies
Expand Down Expand Up @@ -136,7 +134,6 @@ runtime-benchmarks = [
"pallet-vesting/runtime-benchmarks",
"pallet-web3-names/runtime-benchmarks",
"parachain-staking/runtime-benchmarks",
"public-credentials/runtime-benchmarks",
"runtime-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand All @@ -162,7 +159,6 @@ std = [
"frame-system/std",
"frame-try-runtime/std",
"kilt-runtime-api-did/std",
"kilt-runtime-api-public-credentials/std",
"kilt-runtime-api-staking/std",
"kilt-support/std",
"log/std",
Expand Down Expand Up @@ -191,7 +187,6 @@ std = [
"pallet-xcm/std",
"parachain-info/std",
"parachain-staking/std",
"public-credentials/std",
"runtime-common/std",
"scale-info/std",
"sp-api/std",
Expand Down Expand Up @@ -248,6 +243,5 @@ try-runtime = [
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"parachain-staking/try-runtime",
"public-credentials/try-runtime",
"runtime-common/try-runtime",
]
52 changes: 0 additions & 52 deletions runtimes/spiritnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ use sp_version::RuntimeVersion;
use xcm_executor::XcmExecutor;

use delegation::DelegationAc;
use kilt_support::traits::ItemFilter;
pub use parachain_staking::InflationInfo;
pub use public_credentials;

use runtime_common::{
assets::{AssetDid, PublicCredentialsFilter},
authorization::{AuthorizationId, PalletAuthorize},
constants::{self, EXISTENTIAL_DEPOSIT, KILT},
errors::PublicCredentialsApiError,
fees::{ToAuthor, WeightToFee},
pallet_id, AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights, DidIdentifier,
FeeSplit, Hash, Header, Index, Signature, SlowAdjustingFeeUpdate,
Expand Down Expand Up @@ -670,23 +666,6 @@ impl pallet_utility::Config for Runtime {

impl pallet_randomness_collective_flip::Config for Runtime {}

impl public_credentials::Config for Runtime {
type AccessControl = PalletAuthorize<DelegationAc<Runtime>>;
type AttesterId = DidIdentifier;
type AuthorizationId = AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>;
type CredentialId = Hash;
type CredentialHash = BlakeTwo256;
type Currency = Balances;
type Deposit = runtime_common::constants::public_credentials::Deposit;
type EnsureOrigin = did::EnsureDidOrigin<DidIdentifier, AccountId>;
type MaxEncodedClaimsLength = runtime_common::constants::public_credentials::MaxEncodedClaimsLength;
type MaxSubjectIdLength = runtime_common::constants::public_credentials::MaxSubjectIdLength;
type OriginSuccess = did::DidRawOrigin<AccountId, DidIdentifier>;
type Event = Event;
type SubjectId = runtime_common::assets::AssetDid;
type WeightInfo = weights::public_credentials::WeightInfo<Runtime>;
}

/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, scale_info::TypeInfo,
Expand Down Expand Up @@ -738,7 +717,6 @@ impl InstanceFilter<Call> for ProxyType {
// Excludes `ParachainSystem`
| Call::Preimage(..)
| Call::Proxy(..)
| Call::PublicCredentials(..)
| Call::Scheduler(..)
| Call::Session(..)
| Call::System(..)
Expand Down Expand Up @@ -810,15 +788,6 @@ impl InstanceFilter<Call> for ProxyType {
// Excludes `ParachainSystem`
| Call::Preimage(..)
| Call::Proxy(..)
| Call::PublicCredentials(
// Excludes `reclaim_deposit`
public_credentials::Call::add { .. }
| public_credentials::Call::revoke { .. }
| public_credentials::Call::unrevoke { .. }
| public_credentials::Call::remove { .. }
| public_credentials::Call::update_deposit { .. }
| public_credentials::Call::change_deposit_owner { .. }
)
| Call::Scheduler(..)
| Call::Session(..)
// Excludes `Sudo`
Expand Down Expand Up @@ -951,7 +920,6 @@ construct_runtime! {
Inflation: pallet_inflation = 66,
DidLookup: pallet_did_lookup = 67,
Web3Names: pallet_web3_names = 68,
PublicCredentials: public_credentials = 69,

// Parachains pallets. Start indices at 80 to leave room.

Expand Down Expand Up @@ -999,7 +967,6 @@ impl did::DeriveDidCallAuthorizationVerificationKeyRelationship for Call {
Call::Did(did::Call::create { .. }) => Err(did::RelationshipDeriveError::NotCallableByDid),
Call::Did { .. } => Ok(did::DidVerificationKeyRelationship::Authentication),
Call::Web3Names { .. } => Ok(did::DidVerificationKeyRelationship::Authentication),
Call::PublicCredentials { .. } => Ok(did::DidVerificationKeyRelationship::AssertionMethod),
Call::DidLookup { .. } => Ok(did::DidVerificationKeyRelationship::Authentication),
Call::Utility(pallet_utility::Call::batch { calls }) => single_key_relationship(&calls[..]),
Call::Utility(pallet_utility::Call::batch_all { calls }) => single_key_relationship(&calls[..]),
Expand Down Expand Up @@ -1249,23 +1216,6 @@ impl_runtime_apis! {
}
}

impl kilt_runtime_api_public_credentials::PublicCredentials<Block, Vec<u8>, Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>, PublicCredentialsFilter<Hash, AccountId>, PublicCredentialsApiError> for Runtime {
fn get_credential(credential_id: Hash) -> Option<public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>> {
let subject = public_credentials::CredentialSubjects::<Runtime>::get(&credential_id)?;
public_credentials::Credentials::<Runtime>::get(&subject, &credential_id)
}

fn get_credentials(subject: Vec<u8>, filter: Option<PublicCredentialsFilter<Hash, AccountId>>) -> Result<Vec<(Hash, public_credentials::CredentialEntry<Hash, DidIdentifier, BlockNumber, AccountId, Balance, AuthorizationId<<Runtime as delegation::Config>::DelegationNodeId>>)>, PublicCredentialsApiError> {
let asset_did = AssetDid::try_from(subject).map_err(|_| PublicCredentialsApiError::InvalidSubjectId)?;
let credentials_prefix = public_credentials::Credentials::<Runtime>::iter_prefix(&asset_did);
if let Some(filter) = filter {
Ok(credentials_prefix.filter(|(_, entry)| filter.should_include(entry)).collect())
} else {
Ok(credentials_prefix.collect())
}
}
}

impl kilt_runtime_api_staking::Staking<Block, AccountId, Balance> for Runtime {
fn get_unclaimed_staking_rewards(account: &AccountId) -> Balance {
ParachainStaking::get_unclaimed_staking_rewards(account)
Expand Down Expand Up @@ -1317,7 +1267,6 @@ impl_runtime_apis! {
list_benchmark!(list, extra, pallet_inflation, Inflation);
list_benchmark!(list, extra, parachain_staking, ParachainStaking);
list_benchmark!(list, extra, pallet_web3_names, Web3Names);
list_benchmark!(list, extra, public_credentials, PublicCredentials);

let storage_info = AllPalletsWithSystem::storage_info();

Expand Down Expand Up @@ -1384,7 +1333,6 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_inflation, Inflation);
add_benchmark!(params, batches, parachain_staking, ParachainStaking);
add_benchmark!(params, batches, pallet_web3_names, Web3Names);
add_benchmark!(params, batches, public_credentials, PublicCredentials);

// No benchmarks for these pallets
// add_benchmark!(params, batches, cumulus_pallet_parachain_system, ParachainSystem);
Expand Down
17 changes: 1 addition & 16 deletions runtimes/spiritnet/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use pallet_web3_names::{Web3NameOf, Web3OwnershipOf};
use runtime_common::{
constants::{
attestation::MAX_ATTESTATION_BYTE_LENGTH, did::MAX_DID_BYTE_LENGTH, did_lookup::MAX_CONNECTION_BYTE_LENGTH,
public_credentials::MAX_PUBLIC_CREDENTIAL_STORAGE_LENGTH, web3_names::MAX_NAME_BYTE_LENGTH,
MAX_INDICES_BYTE_LENGTH,
web3_names::MAX_NAME_BYTE_LENGTH, MAX_INDICES_BYTE_LENGTH,
},
AccountId, BlockNumber,
};
Expand Down Expand Up @@ -101,20 +100,6 @@ fn indices_storage_sizes() {
assert_eq!(size, MAX_INDICES_BYTE_LENGTH as usize)
}

#[test]
fn public_credentials_storage_sizes() {
// Stored in Credentials
let credential_entry_max_size = public_credentials::CredentialEntryOf::<Runtime>::max_encoded_len();
// Stored in CredentialsUnicityIndex
let subject_id_max_size = <Runtime as public_credentials::Config>::SubjectId::max_encoded_len();

// Each credential would have a different deposit, so no multiplier here
assert_eq!(
credential_entry_max_size + subject_id_max_size,
MAX_PUBLIC_CREDENTIAL_STORAGE_LENGTH as usize
)
}

#[test]
fn test_derive_did_verification_relation_ctype() {
let c1 = Call::Ctype(ctype::Call::add {
Expand Down
1 change: 0 additions & 1 deletion runtimes/spiritnet/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ pub mod pallet_utility;
pub mod pallet_vesting;
pub mod pallet_web3_names;
pub mod parachain_staking;
pub mod public_credentials;
102 changes: 0 additions & 102 deletions runtimes/spiritnet/src/weights/public_credentials.rs

This file was deleted.

0 comments on commit 6d4fcc6

Please sign in to comment.