Skip to content

Commit 9385f06

Browse files
authored
Merge pull request #825 from opentensor/allow-tiny-ti-delta
Allow tiny TI delta
2 parents cdbac35 + 3a02677 commit 9385f06

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pallets/subtensor/src/utils/try_state.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,20 @@ impl<T: Config> Pallet<T> {
3838
.saturating_add(total_staked)
3939
.saturating_add(total_subnet_locked);
4040

41-
// Verify that the calculated total issuance matches the stored TotalIssuance
41+
// Verify the diff between calculated TI and actual TI is less than delta
42+
//
43+
// These values can be off slightly due to float rounding errors.
44+
// They are corrected every runtime upgrade.
45+
const DELTA: u64 = 1000;
46+
let diff = if TotalIssuance::<T>::get() > expected_total_issuance {
47+
TotalIssuance::<T>::get().checked_sub(expected_total_issuance)
48+
} else {
49+
expected_total_issuance.checked_sub(TotalIssuance::<T>::get())
50+
}
51+
.expect("LHS > RHS");
4252
ensure!(
43-
TotalIssuance::<T>::get() == expected_total_issuance,
44-
"TotalIssuance accounting discrepancy",
53+
diff <= DELTA,
54+
"TotalIssuance diff greater than allowable delta",
4555
);
4656

4757
Ok(())

runtime/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,13 @@ pub type SignedExtra = (
10811081
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
10821082
);
10831083

1084-
type Migrations =
1084+
type Migrations = (
1085+
// Leave this migration in the runtime, so every runtime upgrade tiny rounding errors (fractions of fractions
1086+
// of a cent) are cleaned up. These tiny rounding errors occur due to floating point coversion.
10851087
pallet_subtensor::migrations::migrate_init_total_issuance::initialise_total_issuance::Migration<
10861088
Runtime,
1087-
>;
1089+
>,
1090+
);
10881091

10891092
// Unchecked extrinsic type as expected by this runtime.
10901093
pub type UncheckedExtrinsic =

0 commit comments

Comments
 (0)