File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
pallets/subtensor/src/utils Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,20 @@ impl<T: Config> Pallet<T> {
38
38
. saturating_add ( total_staked)
39
39
. saturating_add ( total_subnet_locked) ;
40
40
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" ) ;
42
52
ensure ! (
43
- TotalIssuance :: < T > :: get ( ) == expected_total_issuance ,
44
- "TotalIssuance accounting discrepancy " ,
53
+ diff <= DELTA ,
54
+ "TotalIssuance diff greater than allowable delta " ,
45
55
) ;
46
56
47
57
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -1081,10 +1081,13 @@ pub type SignedExtra = (
1081
1081
frame_metadata_hash_extension:: CheckMetadataHash < Runtime > ,
1082
1082
) ;
1083
1083
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.
1085
1087
pallet_subtensor:: migrations:: migrate_init_total_issuance:: initialise_total_issuance:: Migration <
1086
1088
Runtime ,
1087
- > ;
1089
+ > ,
1090
+ ) ;
1088
1091
1089
1092
// Unchecked extrinsic type as expected by this runtime.
1090
1093
pub type UncheckedExtrinsic =
You can’t perform that action at this time.
0 commit comments