|
1 |
| -use core::marker::PhantomData; |
2 |
| - use frame_support::traits::fungible::Inspect; |
| 1 | +use frame_support::traits::fungible::Inspect; |
3 | 2 |
|
4 |
| -use crate::subnets::subnet::POOL_INITIAL_TAO; |
5 | 3 | use super::*;
|
| 4 | +use crate::subnets::subnet::POOL_INITIAL_TAO; |
6 | 5 |
|
7 |
| -pub(crate) struct TryState<T: Config>(PhantomData<T>); |
8 |
| - |
9 |
| -impl<T: Config> TryState<T> { |
10 |
| - /// Checks [`TotalIssuance`] equals the sum of currency issuance, total stake, and total subnet |
11 |
| - /// locked. |
| 6 | +impl<T: Config> Pallet<T> { |
| 7 | + /// Checks [`TotalIssuance`] equals the sum of currency issuance, total stake, and total subnet |
| 8 | + /// locked. |
12 | 9 | pub(crate) fn check_total_issuance() -> Result<(), sp_runtime::TryRuntimeError> {
|
13 | 10 | // Get the total subnet locked amount
|
14 |
| - let total_subnet_locked = Pallet::<T>::get_total_subnet_locked(); |
| 11 | + let total_subnet_locked = Self::get_total_subnet_locked(); |
15 | 12 |
|
16 | 13 | // Get the total currency issuance
|
17 | 14 | let currency_issuance = T::Currency::total_issuance();
|
@@ -40,31 +37,36 @@ impl<T: Config> TryState<T> {
|
40 | 37 | "TotalIssuance diff greater than allowable delta",
|
41 | 38 | );
|
42 | 39 |
|
43 |
| - Ok(()) |
| 40 | + Ok(()) |
44 | 41 | }
|
45 | 42 |
|
46 |
| - /// Checks the sum of all stakes matches the [`TotalStake`]. |
| 43 | + /// Checks the sum of all stakes matches the [`TotalStake`]. |
| 44 | + #[allow(dead_code)] |
47 | 45 | pub(crate) fn check_total_stake() -> Result<(), sp_runtime::TryRuntimeError> {
|
48 | 46 | // Calculate the total staked amount
|
49 | 47 | let total_staked = SubnetTAO::<T>::iter().fold(0u64, |acc, (netuid, stake)| {
|
50 | 48 | let acc = acc.saturating_add(stake);
|
51 | 49 |
|
52 |
| - if netuid == Pallet::<T>::get_root_netuid() { |
| 50 | + if netuid == Self::get_root_netuid() { |
53 | 51 | // root network doesn't have initial pool TAO
|
54 | 52 | acc
|
55 | 53 | } else {
|
56 | 54 | acc.saturating_sub(POOL_INITIAL_TAO)
|
57 | 55 | }
|
58 | 56 | });
|
59 | 57 |
|
60 |
| - log::warn!("total_staked: {}, TotalStake: {}", total_staked, TotalStake::<T>::get()); |
| 58 | + log::warn!( |
| 59 | + "total_staked: {}, TotalStake: {}", |
| 60 | + total_staked, |
| 61 | + TotalStake::<T>::get() |
| 62 | + ); |
61 | 63 |
|
62 | 64 | // Verify that the calculated total stake matches the stored TotalStake
|
63 | 65 | ensure!(
|
64 | 66 | total_staked == TotalStake::<T>::get(),
|
65 | 67 | "TotalStake does not match total staked",
|
66 | 68 | );
|
67 | 69 |
|
68 |
| - Ok(()) |
69 |
| - } |
| 70 | + Ok(()) |
| 71 | + } |
70 | 72 | }
|
0 commit comments