Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enforce no runtime in pallet #349

Merged
merged 12 commits into from
Apr 6, 2022
5 changes: 1 addition & 4 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions nodes/parachain/src/chain_spec/peregrine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use peregrine_runtime::{
BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, KiltLaunchConfig, MinCollatorStake,
ParachainInfoConfig, ParachainStakingConfig, SessionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig,
VestingConfig, WASM_BINARY,
BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, KiltLaunchConfig, ParachainInfoConfig,
ParachainStakingConfig, SessionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, VestingConfig,
WASM_BINARY,
};
use runtime_common::{
constants::{INFLATION_CONFIG, MAX_COLLATOR_STAKE},
constants::{staking::MinCollatorStake, INFLATION_CONFIG, MAX_COLLATOR_STAKE},
AccountId, AuthorityId, Balance, BlockNumber,
};
use sc_service::ChainType;
Expand Down
7 changes: 3 additions & 4 deletions nodes/parachain/src/chain_spec/spiritnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use runtime_common::{
constants::{INFLATION_CONFIG, KILT, MAX_COLLATOR_STAKE},
constants::{staking::MinCollatorStake, INFLATION_CONFIG, KILT, MAX_COLLATOR_STAKE},
AccountId, AuthorityId, Balance, BlockNumber,
};
use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::traits::Zero;
use spiritnet_runtime::{
BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, KiltLaunchConfig, MinCollatorStake,
ParachainInfoConfig, ParachainStakingConfig, SessionConfig, SystemConfig, TechnicalCommitteeConfig, VestingConfig,
WASM_BINARY,
BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, KiltLaunchConfig, ParachainInfoConfig,
ParachainStakingConfig, SessionConfig, SystemConfig, TechnicalCommitteeConfig, VestingConfig, WASM_BINARY,
};

use crate::chain_spec::{get_account_id_from_seed, get_from_seed, DEFAULT_PARA_ID, TELEMETRY_URL};
Expand Down
6 changes: 2 additions & 4 deletions pallets/attestation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ pub(crate) mod runtime {
use ctype::CtypeCreatorOf;
use frame_support::{parameter_types, weights::constants::RocksDbWeight};
use sp_core::{ed25519, sr25519, Pair};
use sp_keystore::{testing::KeyStore, KeystoreExt};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
MultiSignature, MultiSigner,
};
use std::sync::Arc;

use kilt_support::mock::{mock_origin, SubjectId};

Expand Down Expand Up @@ -368,8 +366,8 @@ pub(crate) mod runtime {
pub fn build_with_keystore(self) -> sp_io::TestExternalities {
let mut ext = self.build();

let keystore = KeyStore::new();
ext.register_extension(KeystoreExt(Arc::new(keystore)));
let keystore = sp_keystore::testing::KeyStore::new();
ext.register_extension(sp_keystore::KeystoreExt(std::sync::Arc::new(keystore)));

ext
}
Expand Down
6 changes: 2 additions & 4 deletions pallets/delegation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,11 @@ pub(crate) mod runtime {
use codec::Encode;
use frame_support::{parameter_types, weights::constants::RocksDbWeight};
use sp_core::{ed25519, sr25519, Pair};
use sp_keystore::{testing::KeyStore, KeystoreExt};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
MultiSignature, MultiSigner,
};
use sp_std::sync::Arc;

use attestation::{mock::insert_attestation, AttestationDetails, ClaimHashOf};
use kilt_support::{
Expand Down Expand Up @@ -510,8 +508,8 @@ pub(crate) mod runtime {
pub fn build_with_keystore(self) -> sp_io::TestExternalities {
let mut ext = self.build();

let keystore = KeyStore::new();
ext.register_extension(KeystoreExt(Arc::new(keystore)));
let keystore = sp_keystore::testing::KeyStore::new();
ext.register_extension(sp_keystore::KeystoreExt(sp_std::sync::Arc::new(keystore)));

ext
}
Expand Down
12 changes: 6 additions & 6 deletions pallets/did/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ env_logger = {version = "0.8.3"}
serde = {version = "1.0.132"}

ctype = {features = ["mock"], path = "../ctype"}

frame-benchmarking = {branch = "polkadot-v0.9.17", default-features = false, git = "https://github.com/paritytech/substrate"}
pallet-balances = {branch = "polkadot-v0.9.17", default-features = false, git = "https://github.com/paritytech/substrate"}
runtime-common = {default-features = false, path = "../../runtimes/common"}
sp-keystore = {branch = "polkadot-v0.9.17", default-features = false, git = "https://github.com/paritytech/substrate"}

[dependencies]
# Internal dependencies
ctype = {optional = true, path = "../ctype"}
ctype = {path = "../ctype", optional = true}
kilt-support = {default-features = false, path = "../../support"}
runtime-common = {default-features = false, path = "../../runtimes/common"}

# External dependencies
env_logger = {default-features = false, optional = true, version = "0.8.3"}
env_logger = {default-features = false, version = "0.8.3", optional = true}
hex = {default-features = false, features = ["alloc"], version = "0.4.2"}
log = "0.4"

Expand All @@ -42,7 +43,7 @@ sp-std = {branch = "polkadot-v0.9.17", default-features = false, git = "https://

# benchmarking
frame-benchmarking = {branch = "polkadot-v0.9.17", default-features = false, git = "https://github.com/paritytech/substrate", optional = true}
pallet-balances = {optional = true, branch = "polkadot-v0.9.17", default-features = false, git = "https://github.com/paritytech/substrate"}
pallet-balances = {branch = "polkadot-v0.9.17", default-features = false, git = "https://github.com/paritytech/substrate", optional = true}
sp-keystore = {branch = "polkadot-v0.9.17", default-features = false, git = "https://github.com/paritytech/substrate", optional = true}

[features]
Expand All @@ -66,7 +67,6 @@ std = [
"frame-support/std",
"frame-system/std",
"hex/std",
"runtime-common/std",
"kilt-support/std",
"kilt-support/std",
"log/std",
Expand Down
7 changes: 3 additions & 4 deletions pallets/did/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, Zero};
use frame_support::{assert_ok, traits::Currency};
use frame_system::RawOrigin;
use kilt_support::signature::VerifySignature;
use runtime_common::AccountId;
use sp_core::{crypto::KeyTypeId, ecdsa, ed25519, sr25519};
use sp_io::crypto::{ecdsa_generate, ecdsa_sign, ed25519_generate, ed25519_sign, sr25519_generate, sr25519_sign};
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSigner};
use sp_std::{convert::TryInto, vec::Vec};

use crate::{
Expand Down Expand Up @@ -118,9 +117,9 @@ fn save_service_endpoints<T: Config>(did_subject: &DidIdentifierOf<T>, endpoints
benchmarks! {
where_clause {
where
T::DidIdentifier: From<AccountId>,
T::DidIdentifier: From<AccountId32>,
<T as frame_system::Config>::Origin: From<RawOrigin<T::DidIdentifier>>,
<T as frame_system::Config>::AccountId: From<AccountId>,
<T as frame_system::Config>::AccountId: From<AccountId32>,
}

/* create extrinsic */
Expand Down
2 changes: 1 addition & 1 deletion pallets/did/src/did_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub trait DidVerifiableIdentifier {
) -> Result<DidVerificationKey, SignatureError>;
}

impl DidVerifiableIdentifier for runtime_common::DidIdentifier {
impl<I: AsRef<[u8; 32]>> DidVerifiableIdentifier for I {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm up for better solution. This was the first thing that came to my mind. But it's definitely not the best solution since not every 32 Byte array is a DidVerifiableIdentifier. 🤔 On the other hand why not? You could try it on anything that is somehow a 32 Byte array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use the same trait requirements that the pallet requires?

type DidIdentifier: Parameter + DidVerifiableIdentifier + MaxEncodedLen;

Or if we want to be even more general, just taking whatever is needed from the Parameter type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the implementation the requirement I: AsRef<[u8; 32]> should be enough. But I would like to limit it to the actual type that is the DidIdentifier and not just all things that can be referenced as a [u8; 32]. Which is also an AccountId. But I think there is no way around that. 🤷 Adding more constraints maybe reduce the number of types this is implemented for, but I'm not sure if it's worth it? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not spend too much on this, but if that's the only trait required right now in the method implementation and it's compiling, I would go on with that.

fn verify_and_recover_signature(
&self,
payload: &Payload,
Expand Down
Loading