Asset Pallet: Support repeated destroys to safely destroy large assets (#12310)

* Support repeated destroys to safely destroy large assets

* require freezing accounts before destroying

* support only deleting asset as final stage when there's no assets left

* pre: introduce the RemoveKeyLimit config parameter

* debug_ensure empty account in the right if block

* update to having separate max values for accounts and approvals

* add tests and use RemoveKeyLimit constant

* add useful comments to the extrinsics, and calculate returned weight

* add benchmarking for start_destroy and finish destroy

* push failing benchmark logic

* add benchmark tests for new functions

* update weights via local benchmarks

* remove extra weight file

* Update frame/assets/src/lib.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Update frame/assets/src/types.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Update frame/assets/src/lib.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* effect some changes from codereview

* use NotFrozen error

* remove origin checks, as anyone can complete destruction after owner has begun the process; Add live check for other extrinsics

* fix comments about Origin behaviour

* add AssetStatus docs

* modularize logic to allow calling logic in on_idle and on_initialize hooks

* introduce simple migration for assets details

* reintroduce logging in the migrations

* move deposit_Event out of the mutate block

* Update frame/assets/src/functions.rs

Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>

* Update frame/assets/src/migration.rs

Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>

* move AssetNotLive checkout out of the mutate blocks

* rename RemoveKeysLimit to RemoveItemsLimit

* update docs

* fix event name in benchmark

* fix cargo fmt.

* fix lint in benchmarking

* Empty commit to trigger CI

* Update frame/assets/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/assets/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/assets/src/functions.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/assets/src/functions.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/assets/src/functions.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/assets/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/assets/src/functions.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* effect change suggested during code review

* move limit to a single location

* Update frame/assets/src/functions.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* rename events

* fix weight typo, using rocksdb instead of T::DbWeight. Pending generating weights

* switch to using dead_account.len()

* rename event in the benchmarks

* empty to retrigger CI

* trigger CI to check cumulus dependency

* trigger CI for dependent cumulus

* Update frame/assets/src/migration.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* move is-frozen to the assetStatus enum (#12547)

* add pre and post migration hooks

* update do_transfer logic to add new assert for more correct error messages

* trigger CI

* switch checking AssetStatus from checking Destroying state to checking live state

* fix error type in tests from Frozen to AssetNotLive

* trigger CI

* change ensure check for fn reducible_balance()

* change the error type to Error:<T,I>::IncorrectStatus to be clearer

* Trigger CI

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: parity-processbot <>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Anthony Alaribe
2022-11-15 11:59:47 +02:00
committed by GitHub
parent 8fef631a95
commit 679d2dcd25
11 changed files with 630 additions and 233 deletions
+80 -39
View File
@@ -49,7 +49,10 @@ use sp_std::marker::PhantomData;
pub trait WeightInfo {
fn create() -> Weight;
fn force_create() -> Weight;
fn destroy(c: u32, s: u32, a: u32, ) -> Weight;
fn start_destroy() -> Weight;
fn destroy_accounts(c: u32) -> Weight;
fn destroy_approvals(m: u32) -> Weight;
fn finish_destroy() -> Weight;
fn mint() -> Weight;
fn burn() -> Weight;
fn transfer() -> Weight;
@@ -89,30 +92,49 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Account (r:5002 w:5001)
// Storage: System Account (r:5000 w:5000)
// Storage: Assets Metadata (r:1 w:0)
// Storage: Assets Approvals (r:501 w:500)
/// The range of component `c` is `[0, 5000]`.
/// The range of component `s` is `[0, 5000]`.
/// The range of component `a` is `[0, 500]`.
fn destroy(c: u32, s: u32, a: u32, ) -> Weight {
// Minimum execution time: 76_222_544 nanoseconds.
Weight::from_ref_time(76_864_587_000 as u64)
// Standard Error: 127_086
.saturating_add(Weight::from_ref_time(8_645_143 as u64).saturating_mul(c as u64))
// Standard Error: 127_086
.saturating_add(Weight::from_ref_time(11_281_301 as u64).saturating_mul(s as u64))
.saturating_add(T::DbWeight::get().reads(5 as u64))
fn start_destroy() -> Weight {
Weight::from_ref_time(31_000_000 as u64)
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Account (r:1 w:0)
// Storage: System Account (r:20 w:20)
/// The range of component `c` is `[0, 1000]`.
fn destroy_accounts(c: u32, ) -> Weight {
Weight::from_ref_time(37_000_000 as u64)
// Standard Error: 19_301
.saturating_add(Weight::from_ref_time(25_467_908 as u64).saturating_mul(c as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().reads((2 as u64).saturating_mul(c as u64)))
.saturating_add(T::DbWeight::get().reads((2 as u64).saturating_mul(s as u64)))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(a as u64)))
.saturating_add(T::DbWeight::get().writes(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().writes((2 as u64).saturating_mul(c as u64)))
.saturating_add(T::DbWeight::get().writes((2 as u64).saturating_mul(s as u64)))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Approvals (r:1 w:0)
/// The range of component `a` is `[0, 1000]`.
fn destroy_approvals(a: u32, ) -> Weight {
Weight::from_ref_time(39_000_000 as u64)
// Standard Error: 14_298
.saturating_add(Weight::from_ref_time(27_632_144 as u64).saturating_mul(a as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(a as u64)))
.saturating_add(T::DbWeight::get().writes(1 as u64))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(a as u64)))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Metadata (r:1 w:0)
fn finish_destroy() -> Weight {
Weight::from_ref_time(33_000_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Account (r:1 w:1)
fn mint() -> Weight {
@@ -302,30 +324,49 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Account (r:5002 w:5001)
// Storage: System Account (r:5000 w:5000)
// Storage: Assets Metadata (r:1 w:0)
// Storage: Assets Approvals (r:501 w:500)
/// The range of component `c` is `[0, 5000]`.
/// The range of component `s` is `[0, 5000]`.
/// The range of component `a` is `[0, 500]`.
fn destroy(c: u32, s: u32, a: u32, ) -> Weight {
// Minimum execution time: 76_222_544 nanoseconds.
Weight::from_ref_time(76_864_587_000 as u64)
// Standard Error: 127_086
.saturating_add(Weight::from_ref_time(8_645_143 as u64).saturating_mul(c as u64))
// Standard Error: 127_086
.saturating_add(Weight::from_ref_time(11_281_301 as u64).saturating_mul(s as u64))
.saturating_add(RocksDbWeight::get().reads(5 as u64))
fn start_destroy() -> Weight {
Weight::from_ref_time(31_000_000 as u64)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Account (r:1 w:0)
// Storage: System Account (r:20 w:20)
/// The range of component `c` is `[0, 1000]`.
fn destroy_accounts(c: u32, ) -> Weight {
Weight::from_ref_time(37_000_000 as u64)
// Standard Error: 19_301
.saturating_add(Weight::from_ref_time(25_467_908 as u64).saturating_mul(c as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().reads((2 as u64).saturating_mul(c as u64)))
.saturating_add(RocksDbWeight::get().reads((2 as u64).saturating_mul(s as u64)))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(a as u64)))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
.saturating_add(RocksDbWeight::get().writes((2 as u64).saturating_mul(c as u64)))
.saturating_add(RocksDbWeight::get().writes((2 as u64).saturating_mul(s as u64)))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Approvals (r:1 w:0)
/// The range of component `a` is `[0, 1000]`.
fn destroy_approvals(a: u32, ) -> Weight {
Weight::from_ref_time(39_000_000 as u64)
// Standard Error: 14_298
.saturating_add(Weight::from_ref_time(27_632_144 as u64).saturating_mul(a as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(a as u64)))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(a as u64)))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Metadata (r:1 w:0)
fn finish_destroy() -> Weight {
Weight::from_ref_time(33_000_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Assets Asset (r:1 w:1)
// Storage: Assets Account (r:1 w:1)
fn mint() -> Weight {