Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 6 additions & 48 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ pallet-election-provider-multi-phase = { git = "https://github.com/PolymeshAssoc
pallet-grandpa = { git = "https://github.com/PolymeshAssociation/polkadot-sdk", branch = "polymesh-v8-stable2512", default-features = false }
pallet-im-online = { git = "https://github.com/PolymeshAssociation/polkadot-sdk", branch = "polymesh-v8-stable2512", default-features = false }
pallet-indices = { git = "https://github.com/PolymeshAssociation/polkadot-sdk", branch = "polymesh-v8-stable2512", default-features = false }
pallet-insecure-randomness-collective-flip = { git = "https://github.com/PolymeshAssociation/polkadot-sdk", branch = "polymesh-v8-stable2512", default-features = false }
pallet-mmr = { git = "https://github.com/PolymeshAssociation/polkadot-sdk", branch = "polymesh-v8-stable2512", default-features = false }
pallet-offences = { git = "https://github.com/PolymeshAssociation/polkadot-sdk", branch = "polymesh-v8-stable2512", default-features = false }
pallet-preimage = { git = "https://github.com/PolymeshAssociation/polkadot-sdk", branch = "polymesh-v8-stable2512", default-features = false }
Expand Down
13 changes: 4 additions & 9 deletions pallets/identity/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
use codec::Encode as _;
use frame_support::dispatch::DispatchResult;
use frame_support::ensure;
use frame_support::traits::{Currency as _, Get as _};
use frame_support::traits::{Currency as _, Get as _, Randomness as _};
use frame_system::ensure_signed;
use pallet_base::{ensure_custom_length_ok, ensure_custom_string_limited};
use pallet_permissions::{AccountCallPermissionsData, CheckAccountCallPermissions};
Expand Down Expand Up @@ -54,8 +54,6 @@ const MAX_NAME_LEN: usize = 60;
// Limit the maximum memory/cpu cost of a key's permissions.
const MAX_PERMISSION_COMPLEXITY: usize = 1_000_000;

type System<T> = frame_system::Pallet<T>;

impl<T: Config> Pallet<T> {
/// Does the identity given by `did` exist?
pub fn is_identity_exists(did: &IdentityId) -> bool {
Expand Down Expand Up @@ -773,17 +771,14 @@ impl<T: Config> Pallet<T> {
Ok(())
}

/// Create a new DID out of the parent block hash and a `nonce`.
/// Create a new DID from BABE randomness and a `nonce`.
fn make_did() -> Result<IdentityId, DispatchError> {
let nonce = MultiPurposeNonce::<T>::get() + 7u64;
// Even if this transaction fails, nonce should be increased for added unpredictability of dids
MultiPurposeNonce::<T>::put(&nonce);

// TODO: Look into getting randomness from `pallet_babe`.
// NB: We can't get the current block's hash while processing
// an extrinsic, so we use parent hash here.
let parent_hash = System::<T>::parent_hash();
let did = IdentityId(blake2_256(&(USER, parent_hash, nonce).encode()));
let (randomness, _) = T::Randomness::random(&nonce.encode());
let did = IdentityId(blake2_256(&(USER, randomness, nonce).encode()));

// Make sure there's no pre-existing entry for the DID
// This should never happen but just being defensive here
Expand Down
3 changes: 3 additions & 0 deletions pallets/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ pub mod pallet {
/// before it is considered unusable.
#[pallet::constant]
type MaxAuthRetries: Get<u8>;

/// Source of randomness for DID generation.
type Randomness: frame_support::traits::Randomness<Self::Hash, BlockNumberFor<Self>>;
}

#[pallet::event]
Expand Down
11 changes: 8 additions & 3 deletions pallets/runtime/common/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ macro_rules! misc_pallet_impls {
/// The set code logic, just the default since we're not a parachain.
type SingleBlockMigrations = (
UpgradeSessionKeys,
RemoveRandomnessCollectiveFlipStorage,
pallet_contracts::Migration<Runtime>,
pallet_grandpa::migrations::MigrateV4ToV5<Runtime>,
pallet_im_online::migration::v1::Migration<Runtime>,
Expand Down Expand Up @@ -516,7 +517,7 @@ macro_rules! misc_pallet_impls {

impl pallet_contracts::Config for Runtime {
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -618,8 +619,14 @@ macro_rules! misc_pallet_impls {
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);

pub const BridgePalletName: &'static str = "Bridge";
pub const RandomnessCollectiveFlipPalletName: &'static str = "RandomnessCollectiveFlip";
}

type RemoveRandomnessCollectiveFlipStorage = frame_support::migrations::RemovePallet<
RandomnessCollectiveFlipPalletName,
<Runtime as frame_system::Config>::DbWeight
>;

impl pallet_preimage::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = polymesh_weights::pallet_preimage::SubstrateWeight;
Expand Down Expand Up @@ -663,8 +670,6 @@ macro_rules! misc_pallet_impls {
pallet_grandpa::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}

impl pallet_insecure_randomness_collective_flip::Config for Runtime {}

impl pallet_treasury::Config for Runtime {
type Currency = Balances;
type WeightInfo = polymesh_weights::pallet_treasury::SubstrateWeight;
Expand Down
2 changes: 0 additions & 2 deletions pallets/runtime/develop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pallet-election-provider-multi-phase = { workspace = true, default-features = fa
pallet-grandpa = { workspace = true, default-features = false }
pallet-im-online = { workspace = true, default-features = false }
pallet-indices = { workspace = true, default-features = false }
pallet-insecure-randomness-collective-flip = { workspace = true, default-features = false }
pallet-mmr = { workspace = true, default-features = false }
pallet-offences = { workspace = true, default-features = false }
pallet-preimage = { workspace = true, default-features = false }
Expand Down Expand Up @@ -146,7 +145,6 @@ std = [
"pallet-group-rpc-runtime-api/std",
"pallet-im-online/std",
"pallet-indices/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-multisig/std",
"pallet-nft/std",
"pallet-pips/std",
Expand Down
4 changes: 1 addition & 3 deletions pallets/runtime/develop/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ impl pallet_identity::Config for Runtime {
type InitialPOLYX = InitialPOLYX;
type MaxGivenAuths = MaxGivenAuths;
type MaxAuthRetries = MaxAuthRetries;
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
}

impl pallet_committee::Config<GovernanceCommittee> for Runtime {
Expand Down Expand Up @@ -395,9 +396,6 @@ mod runtime {
#[runtime::pallet_index(23)]
pub type ImOnline = pallet_im_online::Pallet<Runtime>;

#[runtime::pallet_index(24)]
pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip::Pallet<Runtime>;

#[runtime::pallet_index(25)]
pub type Sudo = pallet_sudo::Pallet<Runtime>;

Expand Down
2 changes: 0 additions & 2 deletions pallets/runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pallet-election-provider-multi-phase = { workspace = true, default-features = fa
pallet-grandpa = { workspace = true, default-features = false }
pallet-im-online = { workspace = true, default-features = false }
pallet-indices = { workspace = true, default-features = false }
pallet-insecure-randomness-collective-flip = { workspace = true, default-features = false }
pallet-mmr = { workspace = true, default-features = false }
pallet-offences = { workspace = true, default-features = false }
pallet-preimage = { workspace = true, default-features = false }
Expand Down Expand Up @@ -159,7 +158,6 @@ std = [
"pallet-protocol-fee-rpc-runtime-api/std",
"pallet-protocol-fee/std",
"pallet-relayer/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-settlement/std",
Expand Down
4 changes: 1 addition & 3 deletions pallets/runtime/mainnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ impl pallet_identity::Config for Runtime {
type InitialPOLYX = InitialPOLYX;
type MaxGivenAuths = MaxGivenAuths;
type MaxAuthRetries = MaxAuthRetries;
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
}

impl pallet_committee::Config<GovernanceCommittee> for Runtime {
Expand Down Expand Up @@ -387,9 +388,6 @@ mod runtime {
#[runtime::pallet_index(23)]
pub type ImOnline = pallet_im_online::Pallet<Runtime>;

#[runtime::pallet_index(24)]
pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip::Pallet<Runtime>;

#[runtime::pallet_index(26)]
pub type Asset = pallet_asset::Pallet<Runtime>;

Expand Down
2 changes: 0 additions & 2 deletions pallets/runtime/testnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pallet-election-provider-multi-phase = { workspace = true, default-features = fa
pallet-grandpa = { workspace = true, default-features = false }
pallet-im-online = { workspace = true, default-features = false }
pallet-indices = { workspace = true, default-features = false }
pallet-insecure-randomness-collective-flip = { workspace = true, default-features = false }
pallet-mmr = { workspace = true, default-features = false }
pallet-offences = { workspace = true, default-features = false }
pallet-preimage = { workspace = true, default-features = false }
Expand Down Expand Up @@ -162,7 +161,6 @@ std = [
"pallet-protocol-fee-rpc-runtime-api/std",
"pallet-protocol-fee/std",
"pallet-relayer/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-settlement/std",
Expand Down
4 changes: 1 addition & 3 deletions pallets/runtime/testnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl pallet_identity::Config for Runtime {
type InitialPOLYX = InitialPOLYX;
type MaxGivenAuths = MaxGivenAuths;
type MaxAuthRetries = MaxAuthRetries;
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
}

impl pallet_committee::Config<GovernanceCommittee> for Runtime {
Expand Down Expand Up @@ -395,9 +396,6 @@ mod runtime {
#[runtime::pallet_index(23)]
pub type ImOnline = pallet_im_online::Pallet<Runtime>;

#[runtime::pallet_index(24)]
pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip::Pallet<Runtime>;

#[runtime::pallet_index(26)]
pub type Asset = pallet_asset::Pallet<Runtime>;

Expand Down
2 changes: 0 additions & 2 deletions pallets/runtime/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pallet-election-provider-multi-phase = { workspace = true, default-features = fa
pallet-grandpa = { workspace = true, default-features = false }
pallet-im-online = { workspace = true, default-features = false }
pallet-indices = { workspace = true, default-features = false }
pallet-insecure-randomness-collective-flip = { workspace = true, default-features = false }
pallet-mmr = { workspace = true, default-features = false }
pallet-offences = { workspace = true, default-features = false }
pallet-preimage = { workspace = true, default-features = false }
Expand Down Expand Up @@ -155,7 +154,6 @@ std = [
"pallet-pips/std",
"pallet-portfolio/std",
"pallet-relayer/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-staking/std",
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/tests/src/corporate_actions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn test(logic: impl FnOnce(AssetId, [User; 3])) {
let asset_id = create_and_issue_sample_asset(&alice);

// Execute the test.
logic(asset_id, [alice, bob, charlie])
logic(asset_id, [alice, charlie, bob])
});
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/runtime/tests/src/group_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ fn disable_member_we() {
None,
None
));
assert_eq!(CommitteeGroup::get_members(), vec![charlie_id, alice_id]);
assert_eq!(CommitteeGroup::get_members(), vec![alice_id, charlie_id]);
assert_eq!(
CommitteeGroup::get_valid_members(),
vec![charlie_id, alice_id, bob_id]
vec![alice_id, charlie_id, bob_id]
);

// Revoke at
Expand Down
Loading