-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initialise total issuance with a migration
- Loading branch information
Showing
6 changed files
with
90 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use frame_support::traits::{fungible, OnRuntimeUpgrade}; | ||
|
||
use crate::*; | ||
|
||
pub struct Migration; | ||
|
||
impl OnRuntimeUpgrade for Migration { | ||
fn on_runtime_upgrade() -> Weight { | ||
// First, we need to initialize the TotalSubnetLocked | ||
let subnets_len = pallet_subtensor::SubnetLocked::<Runtime>::iter().count() as u64; | ||
let total_subnet_locked: u64 = pallet_subtensor::SubnetLocked::<Runtime>::iter() | ||
.fold(0, |acc, (_, v)| acc.saturating_add(v)); | ||
pallet_subtensor::TotalSubnetLocked::<Runtime>::put(total_subnet_locked); | ||
|
||
// Now, we can rejig the total issuance | ||
let total_account_balances = | ||
<<Runtime as pallet_subtensor::Config>::Currency as fungible::Inspect< | ||
<Runtime as frame_system::Config>::AccountId, | ||
>>::total_issuance(); | ||
let total_stake = pallet_subtensor::TotalStake::<Runtime>::get(); | ||
let total_subnet_locked = pallet_subtensor::TotalSubnetLocked::<Runtime>::get(); | ||
|
||
let prev_total_issuance = pallet_subtensor::TotalIssuance::<Runtime>::get(); | ||
let new_total_issuance = total_account_balances | ||
.saturating_add(total_stake) | ||
.saturating_add(total_subnet_locked); | ||
pallet_subtensor::TotalIssuance::<Runtime>::put(new_total_issuance); | ||
|
||
log::info!( | ||
"Subtensor Pallet TI Rejigged: previously: {:?}, new: {:?}", | ||
prev_total_issuance, | ||
new_total_issuance | ||
); | ||
|
||
<Runtime as frame_system::Config>::DbWeight::get() | ||
.reads_writes(subnets_len.saturating_add(5), 1) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> { | ||
// These are usually checked anyway by try-runtime-cli, but just in case check them again | ||
// explicitly here. | ||
pallet_subtensor::Pallet::<Runtime>::check_accounting_invariants()?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
//! Export migrations from here. | ||
pub mod initialise_ti; |