@@ -102,7 +102,7 @@ mod tests;
102
102
use crate :: {
103
103
exec:: { AccountIdOf , ErrorOrigin , ExecError , Executable , Key , Stack as ExecStack } ,
104
104
gas:: GasMeter ,
105
- storage:: { meter:: Meter as StorageMeter , ContractInfo , DeletedContract } ,
105
+ storage:: { meter:: Meter as StorageMeter , ContractInfo , DeletionQueueManager } ,
106
106
wasm:: { OwnerInfo , PrefabWasmModule , TryInstantiate } ,
107
107
weights:: WeightInfo ,
108
108
} ;
@@ -245,33 +245,6 @@ pub mod pallet {
245
245
/// memory usage of your runtime.
246
246
type CallStack : Array < Item = Frame < Self > > ;
247
247
248
- /// The maximum number of contracts that can be pending for deletion.
249
- ///
250
- /// When a contract is deleted by calling `seal_terminate` it becomes inaccessible
251
- /// immediately, but the deletion of the storage items it has accumulated is performed
252
- /// later. The contract is put into the deletion queue. This defines how many
253
- /// contracts can be queued up at the same time. If that limit is reached `seal_terminate`
254
- /// will fail. The action must be retried in a later block in that case.
255
- ///
256
- /// The reasons for limiting the queue depth are:
257
- ///
258
- /// 1. The queue is in storage in order to be persistent between blocks. We want to limit
259
- /// the amount of storage that can be consumed.
260
- /// 2. The queue is stored in a vector and needs to be decoded as a whole when reading
261
- /// it at the end of each block. Longer queues take more weight to decode and hence
262
- /// limit the amount of items that can be deleted per block.
263
- #[ pallet:: constant]
264
- type DeletionQueueDepth : Get < u32 > ;
265
-
266
- /// The maximum amount of weight that can be consumed per block for lazy trie removal.
267
- ///
268
- /// The amount of weight that is dedicated per block to work on the deletion queue. Larger
269
- /// values allow more trie keys to be deleted in each block but reduce the amount of
270
- /// weight that is left for transactions. See [`Self::DeletionQueueDepth`] for more
271
- /// information about the deletion queue.
272
- #[ pallet:: constant]
273
- type DeletionWeightLimit : Get < Weight > ;
274
-
275
248
/// The amount of balance a caller has to pay for each byte of storage.
276
249
///
277
250
/// # Note
@@ -329,25 +302,6 @@ pub mod pallet {
329
302
. saturating_add ( T :: WeightInfo :: on_process_deletion_queue_batch ( ) )
330
303
}
331
304
332
- fn on_initialize ( _block : T :: BlockNumber ) -> Weight {
333
- // We want to process the deletion_queue in the on_idle hook. Only in the case
334
- // that the queue length has reached its maximal depth, we process it here.
335
- let max_len = T :: DeletionQueueDepth :: get ( ) as usize ;
336
- let queue_len = <DeletionQueue < T > >:: decode_len ( ) . unwrap_or ( 0 ) ;
337
- if queue_len >= max_len {
338
- // We do not want to go above the block limit and rather avoid lazy deletion
339
- // in that case. This should only happen on runtime upgrades.
340
- let weight_limit = T :: BlockWeights :: get ( )
341
- . max_block
342
- . saturating_sub ( System :: < T > :: block_weight ( ) . total ( ) )
343
- . min ( T :: DeletionWeightLimit :: get ( ) ) ;
344
- ContractInfo :: < T > :: process_deletion_queue_batch ( weight_limit)
345
- . saturating_add ( T :: WeightInfo :: on_process_deletion_queue_batch ( ) )
346
- } else {
347
- T :: WeightInfo :: on_process_deletion_queue_batch ( )
348
- }
349
- }
350
-
351
305
fn integrity_test ( ) {
352
306
// Total runtime memory is expected to have 128Mb upper limit
353
307
const MAX_RUNTIME_MEM : u32 = 1024 * 1024 * 128 ;
@@ -860,12 +814,6 @@ pub mod pallet {
860
814
/// in this error. Note that this usually shouldn't happen as deploying such contracts
861
815
/// is rejected.
862
816
NoChainExtension ,
863
- /// Removal of a contract failed because the deletion queue is full.
864
- ///
865
- /// This can happen when calling `seal_terminate`.
866
- /// The queue is filled by deleting contracts and emptied by a fixed amount each block.
867
- /// Trying again during another block is the only way to resolve this issue.
868
- DeletionQueueFull ,
869
817
/// A contract with the same AccountId already exists.
870
818
DuplicateContract ,
871
819
/// A contract self destructed in its constructor.
@@ -949,10 +897,15 @@ pub mod pallet {
949
897
/// Evicted contracts that await child trie deletion.
950
898
///
951
899
/// Child trie deletion is a heavy operation depending on the amount of storage items
952
- /// stored in said trie. Therefore this operation is performed lazily in `on_initialize`.
900
+ /// stored in said trie. Therefore this operation is performed lazily in `on_idle`.
901
+ #[ pallet:: storage]
902
+ pub ( crate ) type DeletionQueue < T : Config > = StorageMap < _ , Twox64Concat , u32 , TrieId > ;
903
+
904
+ /// A pair of monotonic counters used to track the latest contract marked for deletion
905
+ /// and the latest deleted contract in queue.
953
906
#[ pallet:: storage]
954
- pub ( crate ) type DeletionQueue < T : Config > =
955
- StorageValue < _ , BoundedVec < DeletedContract , T :: DeletionQueueDepth > , ValueQuery > ;
907
+ pub ( crate ) type DeletionQueueCounter < T : Config > =
908
+ StorageValue < _ , DeletionQueueManager < T > , ValueQuery > ;
956
909
}
957
910
958
911
/// Context of a contract invocation.
0 commit comments