Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
OpenGov improvements for Kusama (#6372)
Browse files Browse the repository at this point in the history
* Tweaks to optimise gov2

* Use new inactive funds

* Introduce migrations

* Fixes

* Fixes

* Fixes

* Some constant updates for Fellowship

* Further tweaks

* Lower floor for whitelisted
  • Loading branch information
gavofyork authored Dec 5, 2022
1 parent f39dbaf commit 48de7a2
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 57 deletions.
45 changes: 44 additions & 1 deletion runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,50 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use frame_support::{storage_alias, Twox64Concat};
use frame_support::{
dispatch::GetStorageVersion, storage_alias, traits::OnRuntimeUpgrade, Twox64Concat,
};

pub struct MigrateToTrackInactive<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> {
fn on_runtime_upgrade() -> Weight {
let current_version = Pallet::<T>::current_storage_version();
let onchain_version = Pallet::<T>::on_chain_storage_version();

if onchain_version == 0 && current_version == 1 {
let mut translated = 0u64;
for index in Funds::<T>::iter_keys() {
let b = CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into()));
CurrencyOf::<T>::deactivate(b);
translated.saturating_inc();
}
current_version.put::<Pallet<T>>();
log::info!(target: "runtime::crowdloan", "Summed {} funds, storage to version {:?}", translated, current_version);
T::DbWeight::get().reads_writes(translated * 2 + 1, translated * 2 + 1)
} else {
log::info!(target: "runtime::crowdloan", "Migration did not execute. This probably should be removed");
T::DbWeight::get().reads(1)
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
let total = Funds::<T>::iter_keys()
.map(|index| {
CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into()))
})
.fold(BalanceOf::<T>::zero(), |a, i| a.saturating_add(i));
Ok((total, CurrencyOf::<T>::active_issuance()).encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(total: Vec<u8>) -> Result<(), &'static str> {
let (total, active) = <(BalanceOf<T>, BalanceOf<T>)>::decode(&mut total.as_slice())
.expect("the state parameter should be something that was generated by pre_upgrade");
assert_eq!(active - total, CurrencyOf::<T>::active_issuance(), "the total be correct");
Ok(())
}
}

/// Migrations for using fund index to create fund accounts instead of para ID.
pub mod crowdloan_index_migration {
Expand Down
5 changes: 5 additions & 0 deletions runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
pub mod migration;

// TODO: Expose the total amount held.

use crate::{
slot_range::SlotRange,
traits::{Auctioneer, Registrar},
Expand Down Expand Up @@ -488,6 +490,7 @@ pub mod pallet {
ensure!(balance > Zero::zero(), Error::<T>::NoContributions);

CurrencyOf::<T>::transfer(&fund_account, &who, balance, AllowDeath)?;
CurrencyOf::<T>::reactivate(balance);

Self::contribution_kill(fund.fund_index, &who);
fund.raised = fund.raised.saturating_sub(balance);
Expand Down Expand Up @@ -527,6 +530,7 @@ pub mod pallet {
break
}
CurrencyOf::<T>::transfer(&fund_account, &who, balance, AllowDeath)?;
CurrencyOf::<T>::reactivate(balance);
Self::contribution_kill(fund.fund_index, &who);
fund.raised = fund.raised.saturating_sub(balance);
refund_count += 1;
Expand Down Expand Up @@ -777,6 +781,7 @@ impl<T: Config> Pallet<T> {
}

CurrencyOf::<T>::transfer(&who, &fund_account, value, existence)?;
CurrencyOf::<T>::deactivate(value);

let balance = old_balance.saturating_add(value);
Self::contribution_put(fund.fund_index, &who, &balance, &memo);
Expand Down
4 changes: 2 additions & 2 deletions runtime/kusama/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub mod currency {
pub const EXISTENTIAL_DEPOSIT: Balance = 1 * CENTS;

pub const UNITS: Balance = 1_000_000_000_000;
pub const CENTS: Balance = UNITS / 30_000;
pub const QUID: Balance = CENTS * 100;
pub const QUID: Balance = UNITS / 30;
pub const CENTS: Balance = QUID / 100;
pub const GRAND: Balance = QUID * 1_000;
pub const MILLICENTS: Balance = CENTS / 1_000;

Expand Down
18 changes: 9 additions & 9 deletions runtime/kusama/src/governance/fellowship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand All @@ -72,7 +72,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand All @@ -94,7 +94,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand Down Expand Up @@ -138,7 +138,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand All @@ -160,7 +160,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand All @@ -182,7 +182,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand All @@ -204,7 +204,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand All @@ -226,7 +226,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand All @@ -248,7 +248,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 4,
min_enactment_period: 1 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
Expand Down
3 changes: 2 additions & 1 deletion runtime/kusama/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ impl pallet_conviction_voting::Config for Runtime {
type Currency = Balances;
type VoteLockingPeriod = VoteLockingPeriod;
type MaxVotes = ConstU32<512>;
type MaxTurnout = frame_support::traits::TotalIssuanceOf<Balances, Self::AccountId>;
type MaxTurnout =
frame_support::traits::tokens::currency::ActiveIssuanceOf<Balances, Self::AccountId>;
type Polls = Referenda;
}

Expand Down
1 change: 1 addition & 0 deletions runtime/kusama/src/governance/origins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub mod pallet_custom_origins {
SmallSpender = 10 * GRAND,
MediumSpender = 100 * GRAND,
BigSpender = 1_000 * GRAND,
Treasurer = 10_000 * GRAND,
}
}

Expand Down
78 changes: 39 additions & 39 deletions runtime/kusama/src/governance/tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ const SUP_BIG_SPENDER: Curve = Curve::make_reciprocal(20, 28, percent(1), percen
const APP_WHITELISTED_CALLER: Curve =
Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100));
const SUP_WHITELISTED_CALLER: Curve =
Curve::make_reciprocal(1, 28, percent(20), percent(10), percent(50));
Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50));

const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15] = [
(
0,
pallet_referenda::TrackInfo {
name: "root",
max_deciding: 1,
decision_deposit: 1_000 * GRAND,
prepare_period: 3 * HOURS,
decision_period: 28 * DAYS,
decision_deposit: 100 * GRAND,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 3 * HOURS,
min_approval: APP_ROOT,
Expand All @@ -84,10 +84,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
1,
pallet_referenda::TrackInfo {
name: "whitelisted_caller",
max_deciding: 10,
decision_deposit: 10_000 * GRAND,
prepare_period: 3 * HOURS,
decision_period: 28 * DAYS,
max_deciding: 30,
decision_deposit: 100 * GRAND,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 10 * MINUTES,
min_enactment_period: 30 * MINUTES,
min_approval: APP_WHITELISTED_CALLER,
Expand All @@ -100,8 +100,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "staking_admin",
max_deciding: 10,
decision_deposit: 5 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 2 * DAYS,
min_approval: APP_STAKING_ADMIN,
Expand All @@ -114,8 +114,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "treasurer",
max_deciding: 10,
decision_deposit: 5 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 2 * DAYS,
min_approval: APP_TREASURER,
Expand All @@ -128,8 +128,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "lease_admin",
max_deciding: 10,
decision_deposit: 5 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 2 * DAYS,
min_approval: APP_LEASE_ADMIN,
Expand All @@ -142,8 +142,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "fellowship_admin",
max_deciding: 10,
decision_deposit: 5 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 2 * DAYS,
min_approval: APP_FELLOWSHIP_ADMIN,
Expand All @@ -156,8 +156,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "general_admin",
max_deciding: 10,
decision_deposit: 5 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 2 * DAYS,
min_approval: APP_GENERAL_ADMIN,
Expand All @@ -170,8 +170,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "auction_admin",
max_deciding: 10,
decision_deposit: 5 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 2 * DAYS,
min_approval: APP_AUCTION_ADMIN,
Expand All @@ -184,8 +184,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "referendum_canceller",
max_deciding: 1_000,
decision_deposit: 50 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 7 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 10 * MINUTES,
min_approval: APP_REFERENDUM_CANCELLER,
Expand All @@ -198,8 +198,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "referendum_killer",
max_deciding: 1_000,
decision_deposit: 50 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 10 * MINUTES,
min_approval: APP_REFERENDUM_KILLER,
Expand All @@ -212,10 +212,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "small_tipper",
max_deciding: 200,
decision_deposit: 5 * QUID,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 7 * DAYS,
confirm_period: 3 * HOURS,
min_enactment_period: 28 * DAYS,
min_enactment_period: 24 * HOURS,
min_approval: APP_SMALL_TIPPER,
min_support: SUP_SMALL_TIPPER,
},
Expand All @@ -226,10 +226,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "big_tipper",
max_deciding: 100,
decision_deposit: 50 * QUID,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 7 * DAYS,
confirm_period: 6 * HOURS,
min_enactment_period: 28 * DAYS,
min_enactment_period: 24 * HOURS,
min_approval: APP_BIG_TIPPER,
min_support: SUP_BIG_TIPPER,
},
Expand All @@ -240,10 +240,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "small_spender",
max_deciding: 50,
decision_deposit: 500 * QUID,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 12 * HOURS,
min_enactment_period: 28 * DAYS,
min_enactment_period: 24 * HOURS,
min_approval: APP_SMALL_SPENDER,
min_support: SUP_SMALL_SPENDER,
},
Expand All @@ -254,10 +254,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "medium_spender",
max_deciding: 20,
decision_deposit: 1_500 * QUID,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 24 * HOURS,
min_enactment_period: 28 * DAYS,
min_enactment_period: 24 * HOURS,
min_approval: APP_MEDIUM_SPENDER,
min_support: SUP_MEDIUM_SPENDER,
},
Expand All @@ -268,10 +268,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
name: "big_spender",
max_deciding: 10,
decision_deposit: 5 * GRAND,
prepare_period: 4,
decision_period: 28 * DAYS,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 48 * HOURS,
min_enactment_period: 28 * DAYS,
min_enactment_period: 24 * HOURS,
min_approval: APP_BIG_SPENDER,
min_support: SUP_BIG_SPENDER,
},
Expand Down
Loading

0 comments on commit 48de7a2

Please sign in to comment.