@@ -37,25 +37,16 @@ pub use pallet::*;
37
37
pub mod pallet {
38
38
use super :: * ;
39
39
use frame_support:: pallet_prelude:: * ;
40
- use frame_support:: traits:: ReservableCurrency ;
41
40
use frame_system:: pallet_prelude:: * ;
42
41
use sp_core:: H160 ;
43
42
44
43
pub const ARRAY_LIMIT : u32 = 1000 ;
45
44
pub type GetArrayLimit = ConstU32 < ARRAY_LIMIT > ;
46
45
47
- const INTERMEDIATES_NODES_SIZE : u64 = 4096 ;
48
- const MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE : u64 =
49
- ( /* biggest key on moonbeam */ 136 ) + ( /* biggest value on moonbeam */ 142 ) ;
50
-
51
46
/// Pallet for multi block migrations
52
47
#[ pallet:: pallet]
53
48
pub struct Pallet < T > ( PhantomData < T > ) ;
54
49
55
- #[ pallet:: storage]
56
- /// If true, it means that LocalAssets storage has been removed.
57
- pub ( crate ) type LocalAssetsMigrationCompleted < T : Config > = StorageValue < _ , bool , ValueQuery > ;
58
-
59
50
#[ pallet:: storage]
60
51
/// The total number of suicided contracts that were removed
61
52
pub ( crate ) type SuicidedContractsRemoved < T : Config > = StorageValue < _ , u32 , ValueQuery > ;
@@ -68,16 +59,8 @@ pub mod pallet {
68
59
69
60
#[ pallet:: error]
70
61
pub enum Error < T > {
71
- /// There are no more storage entries to be removed
72
- AllStorageEntriesHaveBeenRemoved ,
73
62
/// The limit cannot be zero
74
63
LimitCannotBeZero ,
75
- /// The maximum number of assets cannot be zero
76
- MaxAssetsCannotBeZero ,
77
- /// The limit for unlocking funds is too high
78
- UnlockLimitTooHigh ,
79
- /// There are no more VotingOf entries to be removed and democracy funds to be unlocked
80
- AllDemocracyFundsUnlocked ,
81
64
/// There must be at least one address
82
65
AddressesLengthCannotBeZero ,
83
66
/// The contract is not corrupted (Still exist or properly suicided)
@@ -86,126 +69,6 @@ pub mod pallet {
86
69
87
70
#[ pallet:: call]
88
71
impl < T : Config > Pallet < T > {
89
- // TODO(rodrigo): This extrinsic should be removed once LocalAssets pallet storage is removed
90
- #[ pallet:: call_index( 0 ) ]
91
- #[ pallet:: weight( {
92
- // "*limit" is used twice to account to the possibility that we may need to unreserve
93
- // deposits for every approval
94
- let possible_iterations = max_assets. saturating_add( * limit) . saturating_add( * limit) ;
95
- let proof_size = INTERMEDIATES_NODES_SIZE + ( MAX_LOCAL_ASSETS_STORAGE_ENTRY_SIZE
96
- . saturating_mul( <u64 >:: from( possible_iterations) ) ) ;
97
-
98
- Weight :: from_parts( 0 , proof_size)
99
- . saturating_add( <T as frame_system:: Config >:: DbWeight :: get( )
100
- . reads_writes( ( * max_assets + * limit + 1 ) . into( ) , ( * limit + 1 ) . into( ) ) )
101
- } ) ]
102
- pub fn clear_local_assets_storage (
103
- origin : OriginFor < T > ,
104
- max_assets : u32 ,
105
- limit : u32 ,
106
- ) -> DispatchResultWithPostInfo {
107
- ensure_signed ( origin) ?;
108
- ensure ! ( limit != 0 , Error :: <T >:: LimitCannotBeZero ) ;
109
- ensure ! ( max_assets != 0 , Error :: <T >:: MaxAssetsCannotBeZero ) ;
110
-
111
- ensure ! (
112
- !LocalAssetsMigrationCompleted :: <T >:: get( ) ,
113
- Error :: <T >:: AllStorageEntriesHaveBeenRemoved
114
- ) ;
115
-
116
- let mut allowed_removals = limit;
117
-
118
- const PALLET_PREFIX : & ' static str = "LocalAssets" ;
119
-
120
- struct LocalAssetsStorageAsset ;
121
- impl frame_support:: traits:: StorageInstance for LocalAssetsStorageAsset {
122
- const STORAGE_PREFIX : & ' static str = "Asset" ;
123
- fn pallet_prefix ( ) -> & ' static str {
124
- PALLET_PREFIX
125
- }
126
- }
127
- struct LocalAssetsStorageApprovals ;
128
- impl frame_support:: traits:: StorageInstance for LocalAssetsStorageApprovals {
129
- const STORAGE_PREFIX : & ' static str = "Approvals" ;
130
- fn pallet_prefix ( ) -> & ' static str {
131
- PALLET_PREFIX
132
- }
133
- }
134
-
135
- /// Data concerning an approval.
136
- /// Duplicated the type from pallet_assets (The original type is private)
137
- #[ derive(
138
- Clone , Encode , Decode , Eq , PartialEq , RuntimeDebug , Default , MaxEncodedLen , TypeInfo ,
139
- ) ]
140
- pub struct Approval < Balance , DepositBalance > {
141
- /// The amount of funds approved for the balance transfer from the owner to some delegated
142
- /// target.
143
- pub ( super ) amount : Balance ,
144
- /// The amount reserved on the owner's account to hold this item in storage.
145
- pub ( super ) deposit : DepositBalance ,
146
- }
147
-
148
- type AssetMap = frame_support:: storage:: types:: StorageMap <
149
- LocalAssetsStorageAsset ,
150
- Blake2_128Concat ,
151
- u128 ,
152
- // It is fine to add a dummy `Value` type
153
- // The value is not going to be decoded, since we only care about the keys)
154
- ( ) ,
155
- > ;
156
-
157
- for asset_id in AssetMap :: iter_keys ( ) . take ( max_assets as usize ) {
158
- let approvals_iter = frame_support:: storage:: types:: StorageNMap :: <
159
- LocalAssetsStorageApprovals ,
160
- (
161
- NMapKey < Blake2_128Concat , u128 > , // asset id
162
- NMapKey < Blake2_128Concat , T :: AccountId > , // owner
163
- NMapKey < Blake2_128Concat , T :: AccountId > , // delegate
164
- ) ,
165
- Approval < T :: Balance , T :: Balance > ,
166
- > :: drain_prefix ( ( asset_id, ) ) ;
167
- for ( ( owner, _) , approval) in approvals_iter {
168
- allowed_removals = allowed_removals. saturating_sub ( 1 ) ;
169
- // Unreserve deposit (most likely will be zero)
170
- pallet_balances:: Pallet :: < T > :: unreserve ( & owner, approval. deposit ) ;
171
- // Check if the removal limit was reached
172
- if allowed_removals < 1 {
173
- break ;
174
- }
175
- }
176
- // Remove asset, since it does not contain more approvals
177
- AssetMap :: remove ( asset_id) ;
178
- allowed_removals = allowed_removals. saturating_sub ( 1 ) ;
179
- // Check if the removal limit was reached
180
- if allowed_removals < 1 {
181
- break ;
182
- }
183
- }
184
-
185
- // Remove remaining storage
186
- if allowed_removals > 0 {
187
- let hashed_prefix = sp_io:: hashing:: twox_128 ( PALLET_PREFIX . as_bytes ( ) ) ;
188
-
189
- let keys_removed =
190
- match sp_io:: storage:: clear_prefix ( & hashed_prefix, Some ( allowed_removals) ) {
191
- sp_io:: KillStorageResult :: AllRemoved ( value) => {
192
- LocalAssetsMigrationCompleted :: < T > :: set ( true ) ;
193
- value
194
- }
195
- sp_io:: KillStorageResult :: SomeRemaining ( value) => value,
196
- } ;
197
-
198
- allowed_removals = allowed_removals. saturating_sub ( keys_removed) ;
199
- }
200
-
201
- log:: info!(
202
- "Removed {} storge keys 🧹" ,
203
- limit. saturating_sub( allowed_removals)
204
- ) ;
205
-
206
- Ok ( Pays :: No . into ( ) )
207
- }
208
-
209
72
// TODO(rodrigo): This extrinsic should be removed once the storage of destroyed contracts
210
73
// has been removed
211
74
#[ pallet:: call_index( 1 ) ]
0 commit comments