Skip to content

Commit

Permalink
Backporting Tech Committee to the dev branch (#353)
Browse files Browse the repository at this point in the history
## Description
<!-- Describe what change this PR is implementing -->

## Types of Changes
Please select the branch type you are merging and fill in the relevant
template.
<!--- Check the following box with an x if the following applies: -->
- [ ] Hotfix
- [ ] Release
- [x] Fix or Feature

## Fix or Feature
<!--- Check the following box with an x if the following applies: -->

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [x] Tech Debt (Code improvements)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Dependency upgrade (A change in substrate or any 3rd party crate
version)

### Migrations and Hooks
<!--- Check the following box with an x if the following applies: -->
- [ ] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

### Checklist for Fix or Feature
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [x] Change has been tested locally.
- [ ] Change adds / updates tests if applicable.
- [x] Changelog doc updated.
- [x] `spec_version` has been incremented.
- [ ] `network-relayer`'s
[events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go)
have been updated according to the blockchain events if applicable.
- [ ] All CI checks have been passed successfully

## Checklist for Hotfix
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] Changelog has been updated.
- [ ] Crate version has been updated.
- [ ] `spec_version` has been incremented.
- [ ] Transaction version has been updated if required.
- [ ] Pull Request to `dev` has been created.
- [ ] Pull Request to `staging` has been created.
- [ ] `network-relayer`'s
[events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go)
have been updated according to the blockchain events if applicable.
- [ ] All CI checks have been passed successfully

## Checklist for Release
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] Change has been deployed to Devnet.
- [ ] Change has been tested in Devnet.
- [ ] Change has been deployed to Qanet.
- [ ] Change has been tested in Qanet.
- [ ] Change has been deployed to Testnet.
- [ ] Change has been tested in Testnet.
- [ ] Changelog has been updated.
- [ ] Crate version has been updated.
- [ ] Spec version has been updated.
- [ ] Transaction version has been updated if required.
- [ ] All CI checks have been passed successfully
  • Loading branch information
yahortsaryk authored Jun 5, 2024
1 parent 3534f1b commit 37c0c05
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [C] Changes is `Cere` Runtime
- [D] Changes is `Cere Dev` Runtime

## [5.4.0]

### Changed
## [5.4.0]

- [C,D] Introduce new events to the DDC Payouts Pallet
- [C,D] `pallet-ddc-clusters-gov`: Introduction of the Cluster Governance pallet for managing clusters protocol parameters.
- [C,D] `WhitelistOrigin` is set to the Technical Committee Collective Body

## [5.3.0]

Expand Down
8 changes: 8 additions & 0 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ pub fn cere_dev_genesis(
ddc_clusters: Default::default(),
ddc_nodes: Default::default(),
ddc_payouts: Default::default(),
tech_comm: cere_dev::TechCommConfig {
members: endowed_accounts
.iter()
.take((endowed_accounts.len() + 1) / 2)
.cloned()
.collect(),
phantom: Default::default(),
},
}
}

Expand Down
7 changes: 5 additions & 2 deletions runtime/cere-dev/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ impl pallet_whitelist::Config for Runtime {
type WeightInfo = pallet_whitelist::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WhitelistOrigin = EnsureRoot<Self::AccountId>;
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
type WhitelistOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureMembers<AccountId, TechCommCollective, 2>,
>;
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<AccountId>, WhitelistedCaller>;
type Preimages = Preimage;
}

Expand Down
80 changes: 67 additions & 13 deletions runtime/cere-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ use frame_support::{
parameter_types,
traits::{
ConstBool, ConstU128, ConstU16, ConstU32, Currency, EitherOf, EitherOfDiverse,
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, Nothing,
OnUnbalanced, WithdrawReasons,
EqualPrivilegeOnly, Everything, GetStorageVersion, Imbalance, InstanceFilter,
KeyOwnerProofSystem, Nothing, OnRuntimeUpgrade, OnUnbalanced, StorageVersion,
WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -115,7 +116,6 @@ use governance::{
ClusterProtocolActivator, ClusterProtocolUpdater, GeneralAdmin, StakingAdmin, Treasurer,
TreasurySpender,
};

/// Generated voter bag information.
mod voter_bags;

Expand Down Expand Up @@ -143,7 +143,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 54001,
spec_version: 54002,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 18,
Expand Down Expand Up @@ -874,11 +874,7 @@ impl pallet_contracts::Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
type Debug = ();
type Environment = ();
type Migrations = (
pallet_contracts::migration::v13::Migration<Runtime>,
pallet_contracts::migration::v14::Migration<Runtime, Balances>,
pallet_contracts::migration::v15::Migration<Runtime>,
);
type Migrations = ();
}

impl pallet_sudo::Config for Runtime {
Expand Down Expand Up @@ -1190,6 +1186,26 @@ impl pallet_ddc_payouts::Config for Runtime {
type VoteScoreToU64 = IdentityConvert; // used for UseNominatorsAndValidatorsMap
}

parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 5 * DAYS;
pub const TechnicalMaxProposals: u32 = 100;
pub const TechnicalMaxMembers: u32 = 100;
}

type TechCommCollective = pallet_collective::Instance3;
impl pallet_collective::Config<TechCommCollective> for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type Proposal = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type MotionDuration = TechnicalMotionDuration;
type MaxProposals = TechnicalMaxProposals;
type MaxMembers = TechnicalMaxMembers;
type SetMembersOrigin = EnsureRoot<AccountId>;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
}

parameter_types! {
pub const ClustersGovPalletId: PalletId = PalletId(*b"clustgov");
pub const ClusterProposalDuration: BlockNumber = 7 * DAYS;
Expand Down Expand Up @@ -1291,6 +1307,7 @@ construct_runtime!(
Origins: pallet_origins::{Origin},
Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event<T>},
// End OpenGov.
TechComm: pallet_collective::<Instance3>,
DdcClustersGov: pallet_ddc_clusters_gov,
}
);
Expand Down Expand Up @@ -1329,11 +1346,47 @@ pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;

#[cfg(feature = "try-runtime")]
use sp_runtime::DispatchError;
pub struct TechCommSetV4Storage;
impl OnRuntimeUpgrade for TechCommSetV4Storage {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let log_target = "tech-comm-v4-migration";
let on_chain_storage_version = <TechComm as GetStorageVersion>::on_chain_storage_version();
if on_chain_storage_version == 0 {
log::info!(
target: log_target,
"Upgrading storage version to v4",
);
StorageVersion::new(4).put::<TechComm>();
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
} else {
log::warn!(
target: log_target,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
on_chain_storage_version,
);
<Runtime as frame_system::Config>::DbWeight::get().reads(1)
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
let on_chain_storage_version = <TechComm as GetStorageVersion>::on_chain_storage_version();
assert_eq!(on_chain_storage_version, 0, "Tech Comm version is not v0");
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_prev_state: Vec<u8>) -> Result<(), DispatchError> {
let on_chain_storage_version = <TechComm as GetStorageVersion>::on_chain_storage_version();
assert_eq!(on_chain_storage_version, 4, "Tech Comm version is not v4");
Ok(())
}
}

/// Runtime migrations
type Migrations = (
pallet_ddc_clusters::migrations::v2::MigrateToV2<Runtime>,
pallet_ddc_staking::migrations::v1::MigrateToV1<Runtime>,
);
type Migrations = (TechCommSetV4Storage,);

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand Down Expand Up @@ -1393,6 +1446,7 @@ mod benches {
[pallet_referenda, Referenda]
[pallet_whitelist, Whitelist]
[pallet_preimage, Preimage]
[pallet_collective, TechComm]
[pallet_ddc_clusters_gov, DdcClustersGov]
);
}
Expand Down
7 changes: 5 additions & 2 deletions runtime/cere/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ impl pallet_whitelist::Config for Runtime {
type WeightInfo = pallet_whitelist::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WhitelistOrigin = EnsureRoot<Self::AccountId>;
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
type WhitelistOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureMembers<AccountId, TechCommCollective, 3>,
>;
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<AccountId>, WhitelistedCaller>;
type Preimages = Preimage;
}

Expand Down
24 changes: 23 additions & 1 deletion runtime/cere/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 54001,
spec_version: 54002,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 18,
Expand Down Expand Up @@ -1192,6 +1192,26 @@ impl pallet_ddc_staking::Config for Runtime {
type ClusterUnboningDelay = ClusterUnboningDelay;
}

parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 5 * DAYS;
pub const TechnicalMaxProposals: u32 = 100;
pub const TechnicalMaxMembers: u32 = 100;
}

type TechCommCollective = pallet_collective::Instance3;
impl pallet_collective::Config<TechCommCollective> for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type Proposal = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type MotionDuration = TechnicalMotionDuration;
type MaxProposals = TechnicalMaxProposals;
type MaxMembers = TechnicalMaxMembers;
type SetMembersOrigin = EnsureRoot<AccountId>;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
}

parameter_types! {
pub const ClustersGovPalletId: PalletId = PalletId(*b"clustgov");
pub const ClusterProposalDuration: BlockNumber = 7 * DAYS;
Expand Down Expand Up @@ -1293,6 +1313,7 @@ construct_runtime!(
Origins: pallet_origins::{Origin},
Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event<T>},
// End OpenGov.
TechComm: pallet_collective::<Instance3>,
DdcClustersGov: pallet_ddc_clusters_gov,
}
);
Expand Down Expand Up @@ -1395,6 +1416,7 @@ mod benches {
[pallet_referenda, Referenda]
[pallet_whitelist, Whitelist]
[pallet_preimage, Preimage]
[pallet_collective, TechComm]
[pallet_ddc_clusters_gov, DdcClustersGov]
);
}
Expand Down

0 comments on commit 37c0c05

Please sign in to comment.