Skip to content

Commit

Permalink
allow tiny ti delta
Browse files Browse the repository at this point in the history
  • Loading branch information
orriin committed Sep 20, 2024
1 parent 2069a48 commit 0b2f65c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pallets/subtensor/src/utils/try_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ impl<T: Config> Pallet<T> {
.saturating_add(total_staked)
.saturating_add(total_subnet_locked);

// Verify that the calculated total issuance matches the stored TotalIssuance
// Verify the diff between calculated TI and actual TI is less than delta
//
// These values can be off slightly due to float rounding errors.
// They are corrected every runtime upgrade.
const DELTA: u64 = 1000;
let diff = if TotalIssuance::<T>::get() > expected_total_issuance {
TotalIssuance::<T>::get() - expected_total_issuance
} else {
expected_total_issuance - TotalIssuance::<T>::get()
};
ensure!(
TotalIssuance::<T>::get() == expected_total_issuance,
"TotalIssuance accounting discrepancy",
diff <= DELTA,
"TotalIssuance diff greater than allowable delta",
);

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,8 @@ pub type SignedExtra = (
);

type Migrations =
// Leave this migration in the runtime to clean up tiny rounding errors (fractions of fractions
// of a cent) that occur due to floating point rounding errs every runtime upgrade.
pallet_subtensor::migrations::migrate_init_total_issuance::initialise_total_issuance::Migration<
Runtime,
>;
Expand Down

0 comments on commit 0b2f65c

Please sign in to comment.