OpenGov improvements for Kusama (#6372)

* Tweaks to optimise gov2

* Use new inactive funds

* Introduce migrations

* Fixes

* Fixes

* Fixes

* Some constant updates for Fellowship

* Further tweaks

* Lower floor for whitelisted
This commit is contained in:
Gavin Wood
2022-12-05 16:40:25 +00:00
committed by GitHub
parent e79977e694
commit 053b24ebe5
13 changed files with 134 additions and 57 deletions
@@ -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 {
@@ -51,6 +51,8 @@
pub mod migration;
// TODO: Expose the total amount held.
use crate::{
slot_range::SlotRange,
traits::{Auctioneer, Registrar},
@@ -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);
@@ -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;
@@ -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);