Skip to content
Open
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
27 changes: 25 additions & 2 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,6 @@ pub fn testnet_genesis(
versioned_store_permissions: Some(versioned_store_permissions_config),
content_wg: Some(content_working_group_config),
proposals_codex: Some(ProposalsCodexConfig {
set_validator_count_proposal_voting_period: cpcp
.set_validator_count_proposal_voting_period,
set_validator_count_proposal_grace_period: cpcp
.set_validator_count_proposal_grace_period,
runtime_upgrade_proposal_voting_period: cpcp.runtime_upgrade_proposal_voting_period,
runtime_upgrade_proposal_grace_period: cpcp.runtime_upgrade_proposal_grace_period,
text_proposal_voting_period: cpcp.text_proposal_voting_period,
Expand Down
98 changes: 6 additions & 92 deletions runtime-modules/proposals/codex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ pub trait Trait:

/// Encodes the proposal usint its details
type ProposalEncoder: ProposalEncoder<Self>;

/// 'Set validator count' proposal parameters
type SetValidatorCountProposalParameters: Get<
ProposalParameters<Self::BlockNumber, BalanceOf<Self>>,
>;
}

/// Balance alias for GovernanceCurrency from `common` module. TODO: replace with BalanceOf
Expand Down Expand Up @@ -219,14 +224,6 @@ decl_storage! {
pub ProposalDetailsByProposalId get(fn proposal_details_by_proposal_id):
map hasher(blake2_128_concat) T::ProposalId => ProposalDetailsOf<T>;

/// Voting period for the 'set validator count' proposal
pub SetValidatorCountProposalVotingPeriod get(fn set_validator_count_proposal_voting_period)
config(): T::BlockNumber;

/// Grace period for the 'set validator count' proposal
pub SetValidatorCountProposalGracePeriod get(fn set_validator_count_proposal_grace_period)
config(): T::BlockNumber;

/// Voting period for the 'runtime upgrade' proposal
pub RuntimeUpgradeProposalVotingPeriod get(fn runtime_upgrade_proposal_voting_period)
config(): T::BlockNumber;
Expand Down Expand Up @@ -464,7 +461,7 @@ decl_module! {
description,
staking_account_id,
proposal_details: proposal_details.clone(),
proposal_parameters: proposal_types::parameters::set_validator_count_proposal::<T>(),
proposal_parameters: T::SetValidatorCountProposalParameters::get(),
proposal_code: T::ProposalEncoder::encode_proposal(proposal_details),
exact_execution_block,
};
Expand Down Expand Up @@ -841,89 +838,6 @@ impl<T: Trait> Module<T> {

Ok(())
}

/// Sets config values for the proposals.
/// Should be called on the migration to the new runtime version.
pub fn set_config_values(p: ProposalsConfigParameters) {
<SetValidatorCountProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.set_validator_count_proposal_voting_period,
));
<SetValidatorCountProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.set_validator_count_proposal_grace_period,
));
<RuntimeUpgradeProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.runtime_upgrade_proposal_voting_period,
));
<RuntimeUpgradeProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.runtime_upgrade_proposal_grace_period,
));
<TextProposalVotingPeriod<T>>::put(T::BlockNumber::from(p.text_proposal_voting_period));
<TextProposalGracePeriod<T>>::put(T::BlockNumber::from(p.text_proposal_grace_period));
<SpendingProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.spending_proposal_voting_period,
));
<SpendingProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.spending_proposal_grace_period,
));
<AddWorkingGroupOpeningProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.add_working_group_opening_proposal_voting_period,
));
<AddWorkingGroupOpeningProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.add_working_group_opening_proposal_grace_period,
));
<BeginReviewWorkingGroupLeaderApplicationsProposalVotingPeriod<T>>::put(
T::BlockNumber::from(
p.begin_review_working_group_leader_applications_proposal_voting_period,
),
);
<BeginReviewWorkingGroupLeaderApplicationsProposalGracePeriod<T>>::put(
T::BlockNumber::from(
p.begin_review_working_group_leader_applications_proposal_grace_period,
),
);
<FillWorkingGroupLeaderOpeningProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.fill_working_group_leader_opening_proposal_voting_period,
));
<FillWorkingGroupLeaderOpeningProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.fill_working_group_leader_opening_proposal_grace_period,
));
<SetWorkingGroupMintCapacityProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.set_working_group_mint_capacity_proposal_voting_period,
));
<SetWorkingGroupMintCapacityProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.set_working_group_mint_capacity_proposal_grace_period,
));
<DecreaseWorkingGroupLeaderStakeProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.decrease_working_group_leader_stake_proposal_voting_period,
));
<DecreaseWorkingGroupLeaderStakeProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.decrease_working_group_leader_stake_proposal_grace_period,
));
<SlashWorkingGroupLeaderStakeProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.slash_working_group_leader_stake_proposal_voting_period,
));
<SlashWorkingGroupLeaderStakeProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.slash_working_group_leader_stake_proposal_grace_period,
));
<SetWorkingGroupLeaderRewardProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.set_working_group_leader_reward_proposal_voting_period,
));
<SetWorkingGroupLeaderRewardProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.set_working_group_leader_reward_proposal_grace_period,
));
<TerminateWorkingGroupLeaderRoleProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.terminate_working_group_leader_role_proposal_voting_period,
));
<TerminateWorkingGroupLeaderRoleProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.terminate_working_group_leader_role_proposal_grace_period,
));
<AmendConstitutionProposalVotingPeriod<T>>::put(T::BlockNumber::from(
p.amend_constitution_proposal_voting_period,
));
<AmendConstitutionProposalGracePeriod<T>>::put(T::BlockNumber::from(
p.amend_constitution_proposal_grace_period,
));
}
}

impl<T: Trait> ProposalObserver<T> for Module<T> {
Expand Down
15 changes: 0 additions & 15 deletions runtime-modules/proposals/codex/src/proposal_types/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
use crate::{BalanceOf, Module, ProposalParameters};

// Proposal parameters for the 'Set validator count' proposal
pub(crate) fn set_validator_count_proposal<T: crate::Trait>(
) -> ProposalParameters<T::BlockNumber, BalanceOf<T>> {
ProposalParameters {
voting_period: <Module<T>>::set_validator_count_proposal_voting_period(),
grace_period: <Module<T>>::set_validator_count_proposal_grace_period(),
approval_quorum_percentage: 66,
approval_threshold_percentage: 80,
slashing_quorum_percentage: 60,
slashing_threshold_percentage: 80,
required_stake: Some(<BalanceOf<T>>::from(100_000_u32)),
constitutionality: 1,
}
}

// Proposal parameters for the upgrade runtime proposal
pub(crate) fn runtime_upgrade_proposal<T: crate::Trait>(
) -> ProposalParameters<T::BlockNumber, BalanceOf<T>> {
Expand Down
21 changes: 20 additions & 1 deletion runtime-modules/proposals/codex/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sp_runtime::{
use sp_staking::SessionIndex;
pub use system;

use crate::{ProposalDetailsOf, ProposalEncoder};
use crate::{ProposalDetailsOf, ProposalEncoder, ProposalParameters};
use proposals_engine::VotersParameters;
use sp_runtime::testing::TestXt;

Expand Down Expand Up @@ -254,11 +254,30 @@ impl staking::SessionInterface<u64> for Test {
}
}

parameter_types! {
pub SetValidatorCountProposalParameters: ProposalParameters<u64, u64> = set_validator_count_proposal();
}

// Proposal parameters for the 'Set validator count' proposal
pub(crate) fn set_validator_count_proposal() -> ProposalParameters<u64, u64> {
ProposalParameters {
voting_period: 43200,
grace_period: 0,
approval_quorum_percentage: 66,
approval_threshold_percentage: 80,
slashing_quorum_percentage: 60,
slashing_threshold_percentage: 80,
required_stake: Some(100_000),
constitutionality: 1,
}
}

impl crate::Trait for Test {
type TextProposalMaxLength = TextProposalMaxLength;
type RuntimeUpgradeWasmProposalMaxLength = RuntimeUpgradeWasmProposalMaxLength;
type MembershipOriginValidator = ();
type ProposalEncoder = ();
type SetValidatorCountProposalParameters = SetValidatorCountProposalParameters;
}

impl ProposalEncoder<Test> for () {
Expand Down
114 changes: 1 addition & 113 deletions runtime-modules/proposals/codex/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use hiring::ActivateOpeningAt;
use proposals_engine::ProposalParameters;
use working_group::OpeningPolicyCommitment;

use crate::proposal_types::ProposalsConfigParameters;
use crate::*;
use crate::{Error, ProposalDetails};
pub use mock::*;
Expand Down Expand Up @@ -373,9 +372,7 @@ fn create_set_validator_count_proposal_common_checks_succeed() {
None,
)
},
proposal_parameters: crate::proposal_types::parameters::set_validator_count_proposal::<
Test,
>(),
proposal_parameters: <Test as crate::Trait>::SetValidatorCountProposalParameters::get(),
proposal_details: ProposalDetails::SetValidatorCount(4),
};
proposal_fixture.check_all();
Expand Down Expand Up @@ -413,115 +410,6 @@ fn create_set_validator_count_proposal_failed_with_invalid_validator_count() {
});
}

#[test]
fn set_default_proposal_parameters_succeeded() {
initial_test_ext().execute_with(|| {
let p = ProposalsConfigParameters::default();

// nothing is set
assert_eq!(<SetValidatorCountProposalVotingPeriod<Test>>::get(), 0);

ProposalCodex::set_config_values(p);

assert_eq!(
<SetValidatorCountProposalVotingPeriod<Test>>::get(),
p.set_validator_count_proposal_voting_period as u64
);
assert_eq!(
<SetValidatorCountProposalGracePeriod<Test>>::get(),
p.set_validator_count_proposal_grace_period as u64
);
assert_eq!(
<RuntimeUpgradeProposalVotingPeriod<Test>>::get(),
p.runtime_upgrade_proposal_voting_period as u64
);
assert_eq!(
<RuntimeUpgradeProposalGracePeriod<Test>>::get(),
p.runtime_upgrade_proposal_grace_period as u64
);
assert_eq!(
<TextProposalVotingPeriod<Test>>::get(),
p.text_proposal_voting_period as u64
);
assert_eq!(
<TextProposalGracePeriod<Test>>::get(),
p.text_proposal_grace_period as u64
);
assert_eq!(
<SpendingProposalVotingPeriod<Test>>::get(),
p.spending_proposal_voting_period as u64
);
assert_eq!(
<SpendingProposalGracePeriod<Test>>::get(),
p.spending_proposal_grace_period as u64
);
assert_eq!(
<AddWorkingGroupOpeningProposalVotingPeriod<Test>>::get(),
p.add_working_group_opening_proposal_voting_period as u64
);
assert_eq!(
<AddWorkingGroupOpeningProposalGracePeriod<Test>>::get(),
p.add_working_group_opening_proposal_grace_period as u64
);
assert_eq!(
<BeginReviewWorkingGroupLeaderApplicationsProposalVotingPeriod<Test>>::get(),
p.begin_review_working_group_leader_applications_proposal_voting_period as u64
);
assert_eq!(
<BeginReviewWorkingGroupLeaderApplicationsProposalGracePeriod<Test>>::get(),
p.begin_review_working_group_leader_applications_proposal_grace_period as u64
);
assert_eq!(
<FillWorkingGroupLeaderOpeningProposalVotingPeriod<Test>>::get(),
p.fill_working_group_leader_opening_proposal_voting_period as u64
);
assert_eq!(
<FillWorkingGroupLeaderOpeningProposalGracePeriod<Test>>::get(),
p.fill_working_group_leader_opening_proposal_grace_period as u64
);
assert_eq!(
<SetWorkingGroupMintCapacityProposalVotingPeriod<Test>>::get(),
p.set_working_group_mint_capacity_proposal_voting_period as u64
);
assert_eq!(
<SetWorkingGroupMintCapacityProposalGracePeriod<Test>>::get(),
p.set_working_group_mint_capacity_proposal_grace_period as u64
);
assert_eq!(
<DecreaseWorkingGroupLeaderStakeProposalVotingPeriod<Test>>::get(),
p.decrease_working_group_leader_stake_proposal_voting_period as u64
);
assert_eq!(
<DecreaseWorkingGroupLeaderStakeProposalGracePeriod<Test>>::get(),
p.decrease_working_group_leader_stake_proposal_grace_period as u64
);
assert_eq!(
<SlashWorkingGroupLeaderStakeProposalVotingPeriod<Test>>::get(),
p.slash_working_group_leader_stake_proposal_voting_period as u64
);
assert_eq!(
<SlashWorkingGroupLeaderStakeProposalGracePeriod<Test>>::get(),
p.slash_working_group_leader_stake_proposal_grace_period as u64
);
assert_eq!(
<SetWorkingGroupLeaderRewardProposalVotingPeriod<Test>>::get(),
p.set_working_group_leader_reward_proposal_voting_period as u64
);
assert_eq!(
<SetWorkingGroupLeaderRewardProposalGracePeriod<Test>>::get(),
p.set_working_group_leader_reward_proposal_grace_period as u64
);
assert_eq!(
<TerminateWorkingGroupLeaderRoleProposalVotingPeriod<Test>>::get(),
p.terminate_working_group_leader_role_proposal_voting_period as u64
);
assert_eq!(
<TerminateWorkingGroupLeaderRoleProposalGracePeriod<Test>>::get(),
p.terminate_working_group_leader_role_proposal_grace_period as u64
);
});
}

#[test]
fn create_add_working_group_leader_opening_proposal_common_checks_succeed() {
// This uses strum crate for enum iteration
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ version = '7.6.0'
[dependencies]
# Third-party dependencies
serde = { version = "1.0.101", optional = true, features = ["derive"] }
lazy_static = {version = "1.4.0", features = ["spin_no_std"] }
lite-json = { version = '0.1.3', default-features = false}
codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }

# Substrate primitives
Expand Down
Loading