@@ -473,19 +473,6 @@ mod slim {
473473 account
474474 }
475475
476- /// Read a little-endian u128 from a byte slice.
477- fn read_u128_le ( bytes : & [ u8 ] , offset : usize ) -> u128 {
478- let mut buf = [ 0u8 ; 16 ] ;
479- buf. copy_from_slice ( & bytes[ offset..offset + 16 ] ) ;
480- u128:: from_le_bytes ( buf)
481- }
482-
483- fn read_u32_le ( bytes : & [ u8 ] , offset : usize ) -> u32 {
484- let mut buf = [ 0u8 ; 4 ] ;
485- buf. copy_from_slice ( & bytes[ offset..offset + 4 ] ) ;
486- u32:: from_le_bytes ( buf)
487- }
488-
489476 /// Extract account from end of key (for single-key maps like System.Account, XYK.PoolAssets).
490477 /// Key = prefix(32) + blake2_128_concat(account)(48). Account at last 32 bytes.
491478 fn account_from_key_tail ( key : & [ u8 ] ) -> Option < [ u8 ; 32 ] > {
@@ -666,8 +653,13 @@ mod slim {
666653 allow_list. contains ( account)
667654 }
668655
669- /// Clear unwanted storage entries and recalculate issuances .
656+ /// Clear unwanted storage entries.
670657 /// Must be called inside execute_with().
658+ ///
659+ /// Note: we intentionally do NOT recalculate TotalIssuance. Pools (especially Stableswap)
660+ /// depend on the original share token issuance. Recalculating it from the remaining accounts
661+ /// would set share issuance to zero (since LP holders are removed), breaking pool operations.
662+ /// Slightly inflated issuance is harmless for testing.
671663 pub fn clear_unwanted_entries ( allow_list : & HashSet < [ u8 ; 32 ] > ) {
672664 // (pallet, item, account_is_first_key)
673665 // account_is_first_key=true: double map where AccountId is the first key (offset 48..80)
@@ -681,12 +673,6 @@ mod slim {
681673 ( "Vesting" , "VestingSchedules" , false ) ,
682674 ] ;
683675
684- let mut native_issuance: u128 = 0 ;
685- let mut token_issuances: std:: collections:: HashMap < u32 , u128 > = std:: collections:: HashMap :: new ( ) ;
686-
687- let system_account_prefix = storage_prefix ( "System" , "Account" ) ;
688- let tokens_accounts_prefix = storage_prefix ( "Tokens" , "Accounts" ) ;
689-
690676 for ( pallet, item, account_is_first_key) in & filterable {
691677 let prefix = storage_prefix ( pallet, item) ;
692678 let keys = iter_keys_with_prefix ( & prefix) ;
@@ -704,27 +690,6 @@ mod slim {
704690 if !should_keep ( & account, allow_list) {
705691 sp_io:: storage:: clear ( & key) ;
706692 removed += 1 ;
707- } else if key. starts_with ( & system_account_prefix) {
708- if let Some ( val) = sp_io:: storage:: get ( & key) {
709- if val. len ( ) >= 48 {
710- let free = read_u128_le ( & val, 16 ) ;
711- let reserved = read_u128_le ( & val, 32 ) ;
712- native_issuance = native_issuance. saturating_add ( free) . saturating_add ( reserved) ;
713- }
714- }
715- } else if key. starts_with ( & tokens_accounts_prefix) {
716- // Tokens.Accounts key: prefix(32) + blake2_128(account)(16) + account(32) + twox64(currency)(8) + currency(4) = 92
717- // Currency is last 4 bytes
718- if key. len ( ) >= 92 {
719- let currency_id = read_u32_le ( & key, key. len ( ) - 4 ) ;
720- if let Some ( val) = sp_io:: storage:: get ( & key) {
721- if val. len ( ) >= 32 {
722- let free = read_u128_le ( & val, 0 ) ;
723- let reserved = read_u128_le ( & val, 16 ) ;
724- * token_issuances. entry ( currency_id) . or_insert ( 0 ) += free. saturating_add ( reserved) ;
725- }
726- }
727- }
728693 }
729694 }
730695 }
@@ -733,22 +698,6 @@ mod slim {
733698 println ! ( " Removed {removed}/{total} entries from {pallet}.{item}" ) ;
734699 }
735700 }
736-
737- // Recalculate Balances.TotalIssuance
738- let balances_ti_key = storage_prefix ( "Balances" , "TotalIssuance" ) ;
739- sp_io:: storage:: set ( & balances_ti_key, & native_issuance. to_le_bytes ( ) ) ;
740- println ! ( "Recalculated Balances.TotalIssuance: {native_issuance}" ) ;
741-
742- // Recalculate Tokens.TotalIssuance for each currency
743- let ti_prefix = storage_prefix ( "Tokens" , "TotalIssuance" ) ;
744- for key in iter_keys_with_prefix ( & ti_prefix) {
745- if key. len ( ) >= 44 {
746- let currency_id = read_u32_le ( & key, key. len ( ) - 4 ) ;
747- if let Some ( & new_issuance) = token_issuances. get ( & currency_id) {
748- sp_io:: storage:: set ( & key, & new_issuance. to_le_bytes ( ) ) ;
749- }
750- }
751- }
752701 }
753702}
754703
0 commit comments