Skip to content

Commit

Permalink
refactor: enforce no runtime in pallet (#349)
Browse files Browse the repository at this point in the history
* refactor: clean inflation pallet of runtime code

* refactor: clean pallet did lookup of runtime code

* refactor: move parameter to common

* refactor: clean pallet did of runtime references

* refactor: clean kilt launch of runtime code

* refactor: clean parachain-staking of runtime code

(cherry picked from commit c724119)
  • Loading branch information
weichweich authored and ntn-x2 committed Jun 23, 2022
1 parent 73f1b66 commit f9738f8
Show file tree
Hide file tree
Showing 31 changed files with 527 additions and 603 deletions.
7 changes: 2 additions & 5 deletions Cargo.lock

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

12 changes: 4 additions & 8 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::{kilt_inflation_config, staking::MinCollatorStake, MAX_COLLATOR_STAKE},
AccountId, AuthorityId, Balance, BlockNumber,
};
use sc_service::ChainType;
Expand Down Expand Up @@ -138,10 +138,6 @@ pub fn make_new_spec() -> Result<ChainSpec, String> {
))
}

pub fn kilt_inflation_config() -> InflationInfo {
InflationInfo::from(INFLATION_CONFIG)
}

#[allow(clippy::too_many_arguments)]
fn testnet_genesis(
wasm_binary: &[u8],
Expand Down
11 changes: 3 additions & 8 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::{kilt_inflation_config, staking::MinCollatorStake, 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 Expand Up @@ -244,10 +243,6 @@ pub fn load_spiritnet_spec() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../../res/spiritnet.json")[..])
}

pub fn kilt_inflation_config() -> InflationInfo {
InflationInfo::from(INFLATION_CONFIG)
}

#[allow(clippy::too_many_arguments)]
fn testnet_genesis(
wasm_binary: &[u8],
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 {
fn verify_and_recover_signature(
&self,
payload: &Payload,
Expand Down
Loading

0 comments on commit f9738f8

Please sign in to comment.