difftreelog
Transaction payment and weights fix
in: master
4 files changed
pallets/nft/src/default_weights.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/nft/src/default_weights.rs
@@ -0,0 +1,95 @@
+use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
+
+impl crate::WeightInfo for () {
+ fn create_collection() -> Weight {
+ (70_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(7 as Weight))
+ .saturating_add(DbWeight::get().writes(5 as Weight))
+ }
+ fn destroy_collection() -> Weight {
+ (90_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(5 as Weight))
+ }
+ fn add_to_white_list() -> Weight {
+ (30_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn remove_from_white_list() -> Weight {
+ (35_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn set_public_access_mode() -> Weight {
+ (27_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn set_mint_permission() -> Weight {
+ (27_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn change_collection_owner() -> Weight {
+ (27_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn add_collection_admin() -> Weight {
+ (32_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn remove_collection_admin() -> Weight {
+ (50_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn set_collection_sponsor() -> Weight {
+ (32_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn confirm_sponsorship() -> Weight {
+ (22_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn remove_collection_sponsor() -> Weight {
+ (24_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn create_item(s: usize, ) -> Weight {
+ (130_000_000 as Weight)
+ .saturating_add((2135 as Weight).saturating_mul(s as Weight))
+ .saturating_add(DbWeight::get().reads(10 as Weight))
+ .saturating_add(DbWeight::get().writes(8 as Weight))
+ }
+ fn burn_item() -> Weight {
+ (170_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(9 as Weight))
+ .saturating_add(DbWeight::get().writes(7 as Weight))
+ }
+ fn transfer() -> Weight {
+ (125_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(7 as Weight))
+ .saturating_add(DbWeight::get().writes(7 as Weight))
+ }
+ fn approve() -> Weight {
+ (45_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn transfer_from() -> Weight {
+ (150_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(9 as Weight))
+ .saturating_add(DbWeight::get().writes(8 as Weight))
+ }
+ fn set_offchain_schema() -> Weight {
+ (33_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+}
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -44,6 +44,8 @@
#[cfg(test)]
mod tests;
+mod default_weights;
+
// Structs
// #region
@@ -182,8 +184,32 @@
pub refungible_sponsor_transfer_timeout: u32,
}
-pub trait Trait: system::Trait {
+pub trait WeightInfo {
+ fn create_collection() -> Weight;
+ fn destroy_collection() -> Weight;
+ fn add_to_white_list() -> Weight;
+ fn remove_from_white_list() -> Weight;
+ fn set_public_access_mode() -> Weight;
+ fn set_mint_permission() -> Weight;
+ fn change_collection_owner() -> Weight;
+ fn add_collection_admin() -> Weight;
+ fn remove_collection_admin() -> Weight;
+ fn set_collection_sponsor() -> Weight;
+ fn confirm_sponsorship() -> Weight;
+ fn remove_collection_sponsor() -> Weight;
+ fn create_item(s: usize, ) -> Weight;
+ fn burn_item() -> Weight;
+ fn transfer() -> Weight;
+ fn approve() -> Weight;
+ fn transfer_from() -> Weight;
+ fn set_offchain_schema() -> Weight;
+}
+
+pub trait Trait: system::Trait + Sized {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
+
+ /// Weight information for extrinsics in this pallet.
+ type WeightInfo: WeightInfo;
}
#[cfg(feature = "runtime-benchmarks")]
@@ -326,10 +352,7 @@
///
/// * mode: [CollectionMode] collection type and type dependent data.
// returns collection ID
- #[weight =
- (70_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(7 as Weight))
- .saturating_add(RocksDbWeight::get().writes(5 as Weight))]
+ #[weight = T::WeightInfo::create_collection()]
pub fn create_collection(origin,
collection_name: Vec<u16>,
collection_description: Vec<u16>,
@@ -425,10 +448,7 @@
/// # Arguments
///
/// * collection_id: collection to destroy.
- #[weight =
- (90_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(2 as Weight))
- .saturating_add(RocksDbWeight::get().writes(5 as Weight))]
+ #[weight = T::WeightInfo::destroy_collection()]
pub fn destroy_collection(origin, collection_id: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -475,10 +495,7 @@
/// * collection_id.
///
/// * address.
- #[weight =
- (30_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(3 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::add_to_white_list()]
pub fn add_to_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{
let sender = ensure_signed(origin)?;
@@ -513,10 +530,7 @@
/// * collection_id.
///
/// * address.
- #[weight =
- (35_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(3 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::remove_from_white_list()]
pub fn remove_from_white_list(origin, collection_id: u64, address: T::AccountId) -> DispatchResult{
let sender = ensure_signed(origin)?;
@@ -545,10 +559,7 @@
/// * collection_id.
///
/// * mode: [AccessMode]
- #[weight =
- (27_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(1 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::set_public_access_mode()]
pub fn set_public_access_mode(origin, collection_id: u64, mode: AccessMode) -> DispatchResult
{
let sender = ensure_signed(origin)?;
@@ -574,10 +585,7 @@
/// * collection_id.
///
/// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.
- #[weight =
- (27_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(1 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::set_mint_permission()]
pub fn set_mint_permission(origin, collection_id: u64, mint_permission: bool) -> DispatchResult
{
let sender = ensure_signed(origin)?;
@@ -601,10 +609,7 @@
/// * collection_id.
///
/// * new_owner.
- #[weight =
- (27_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(1 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::change_collection_owner()]
pub fn change_collection_owner(origin, collection_id: u64, new_owner: T::AccountId) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -629,10 +634,7 @@
/// * collection_id: ID of the Collection to add admin for.
///
/// * new_admin_id: Address of new admin to add.
- #[weight =
- (32_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(3 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::add_collection_admin()]
pub fn add_collection_admin(origin, collection_id: u64, new_admin_id: T::AccountId) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -666,10 +668,7 @@
/// * collection_id: ID of the Collection to remove admin for.
///
/// * account_id: Address of admin to remove.
- #[weight =
- (50_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(2 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::remove_collection_admin()]
pub fn remove_collection_admin(origin, collection_id: u64, account_id: T::AccountId) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -694,10 +693,7 @@
/// * collection_id.
///
/// * new_sponsor.
- #[weight =
- (32_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(2 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::set_collection_sponsor()]
pub fn set_collection_sponsor(origin, collection_id: u64, new_sponsor: T::AccountId) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -719,10 +715,7 @@
/// # Arguments
///
/// * collection_id.
- #[weight =
- (22_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(1 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::confirm_sponsorship()]
pub fn confirm_sponsorship(origin, collection_id: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -747,10 +740,7 @@
/// # Arguments
///
/// * collection_id.
- #[weight =
- (24_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(1 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::remove_collection_sponsor()]
pub fn remove_collection_sponsor(origin, collection_id: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -783,11 +773,13 @@
/// * properties: Array of bytes that contains NFT properties. Since NFT Module is agnostic of properties meaning, it is treated purely as an array of bytes.
///
/// * owner: Address, initial owner of the NFT.
- #[weight =
- (130_000_000 as Weight)
- .saturating_add((2135 as Weight).saturating_mul((properties.len() as u64) as Weight))
- .saturating_add(RocksDbWeight::get().reads(10 as Weight))
- .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
+ // #[weight =
+ // (130_000_000 as Weight)
+ // .saturating_add((2135 as Weight).saturating_mul((properties.len() as u64) as Weight))
+ // .saturating_add(RocksDbWeight::get().reads(10 as Weight))
+ // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
+
+ #[weight = T::WeightInfo::create_item(properties.len())]
pub fn create_item(origin, collection_id: u64, properties: Vec<u8>, owner: T::AccountId) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -870,10 +862,7 @@
/// * collection_id: ID of the collection.
///
/// * item_id: ID of NFT to burn.
- #[weight =
- (170_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(9 as Weight))
- .saturating_add(RocksDbWeight::get().writes(7 as Weight))]
+ #[weight = T::WeightInfo::burn_item()]
pub fn burn_item(origin, collection_id: u64, item_id: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -926,10 +915,7 @@
/// * Non-Fungible Mode: Ignored
/// * Fungible Mode: Must specify transferred amount
/// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)
- #[weight =
- (125_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(7 as Weight))
- .saturating_add(RocksDbWeight::get().writes(7 as Weight))]
+ #[weight = T::WeightInfo::transfer()]
pub fn transfer(origin, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -971,10 +957,7 @@
/// * collection_id.
///
/// * item_id: ID of the item.
- #[weight =
- (45_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(3 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::approve()]
pub fn approve(origin, approved: T::AccountId, collection_id: u64, item_id: u64) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -1032,10 +1015,7 @@
/// * item_id: ID of the item.
///
/// * value: Amount to transfer.
- #[weight =
- (150_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(9 as Weight))
- .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
+ #[weight = T::WeightInfo::transfer_from()]
pub fn transfer_from(origin, from: T::AccountId, recipient: T::AccountId, collection_id: u64, item_id: u64, value: u64 ) -> DispatchResult {
let sender = ensure_signed(origin)?;
@@ -1107,10 +1087,7 @@
/// * collection_id.
///
/// * schema: String representing the offchain data schema.
- #[weight =
- (33_000_000 as Weight)
- .saturating_add(RocksDbWeight::get().reads(2 as Weight))
- .saturating_add(RocksDbWeight::get().writes(1 as Weight))]
+ #[weight = T::WeightInfo::set_offchain_schema()]
pub fn set_offchain_schema(
origin,
collection_id: u64,
runtime/src/lib.rsdiffbeforeafterboth84/// Digest item type.84/// Digest item type.85pub type DigestItem = generic::DigestItem<Hash>;85pub type DigestItem = generic::DigestItem<Hash>;868687mod nft_weights;878888/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know89/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know89/// the specifics of the runtime. They can then be made to be agnostic over specific formats90/// the specifics of the runtime. They can then be made to be agnostic over specific formats144 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;145 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;145 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);146 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);146 /// Assume 10% of weight for average on_initialize calls.147 /// Assume 10% of weight for average on_initialize calls.148 // pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()149 // .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();150147 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()151 pub MaximumExtrinsicWeight: Weight = 4_294_967_295; 148 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();152 //pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;149 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;153 pub const MaximumBlockLength: u32 = 4_294_967_295;150 pub const Version: RuntimeVersion = VERSION;154 pub const Version: RuntimeVersion = VERSION;151}155}152156291}295}292296293parameter_types! {297parameter_types! {294 pub const TransactionByteFee: Balance = 1;298 pub const TransactionByteFee: Balance = 10 * MILLICENTS;295}299}296300297impl pallet_transaction_payment::Trait for Runtime {301impl pallet_transaction_payment::Trait for Runtime {310/// Used for the module nft in `./nft.rs`314/// Used for the module nft in `./nft.rs`311impl pallet_nft::Trait for Runtime {315impl pallet_nft::Trait for Runtime {312 type Event = Event;316 type Event = Event;317 type WeightInfo = nft_weights::WeightInfo;313}318}314319315construct_runtime!(320construct_runtime!(runtime/src/nft_weights.rsdiffbeforeafterboth--- /dev/null
+++ b/runtime/src/nft_weights.rs
@@ -0,0 +1,96 @@
+use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
+
+pub struct WeightInfo;
+impl pallet_nft::WeightInfo for WeightInfo {
+ fn create_collection() -> Weight {
+ (70_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(7 as Weight))
+ .saturating_add(DbWeight::get().writes(5 as Weight))
+ }
+ fn destroy_collection() -> Weight {
+ (90_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(5 as Weight))
+ }
+ fn add_to_white_list() -> Weight {
+ (30_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn remove_from_white_list() -> Weight {
+ (35_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn set_public_access_mode() -> Weight {
+ (27_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn set_mint_permission() -> Weight {
+ (27_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn change_collection_owner() -> Weight {
+ (27_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn add_collection_admin() -> Weight {
+ (32_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn remove_collection_admin() -> Weight {
+ (50_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn set_collection_sponsor() -> Weight {
+ (32_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn confirm_sponsorship() -> Weight {
+ (22_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn remove_collection_sponsor() -> Weight {
+ (24_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(1 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn create_item(s: usize, ) -> Weight {
+ (130_000_000 as Weight)
+ .saturating_add((2135 as Weight).saturating_mul(s as Weight))
+ .saturating_add(DbWeight::get().reads(10 as Weight))
+ .saturating_add(DbWeight::get().writes(8 as Weight))
+ }
+ fn burn_item() -> Weight {
+ (170_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(9 as Weight))
+ .saturating_add(DbWeight::get().writes(7 as Weight))
+ }
+ fn transfer() -> Weight {
+ (125_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(7 as Weight))
+ .saturating_add(DbWeight::get().writes(7 as Weight))
+ }
+ fn approve() -> Weight {
+ (45_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(3 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+ fn transfer_from() -> Weight {
+ (150_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(9 as Weight))
+ .saturating_add(DbWeight::get().writes(8 as Weight))
+ }
+ fn set_offchain_schema() -> Weight {
+ (33_000_000 as Weight)
+ .saturating_add(DbWeight::get().reads(2 as Weight))
+ .saturating_add(DbWeight::get().writes(1 as Weight))
+ }
+}