Skip to content

Commit 9954101

Browse files
Developed weights file for pallet confidential docs pallet. Developed pallet confidential docs to use the new weights file.
1 parent b901f22 commit 9954101

File tree

5 files changed

+500
-12
lines changed

5 files changed

+500
-12
lines changed

pallets/confidential-docs/src/benchmarking.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
types::{Vault, *},
99
Pallet as ConfidentialDocs,
1010
};
11+
use scale_info::prelude::*;
1112

1213
use frame_benchmarking::v2::*;
1314
use frame_support::{assert_ok, traits::Get};

pallets/confidential-docs/src/lib.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ mod test_util;
1717

1818
mod functions;
1919
pub mod types;
20-
20+
pub mod weights;
21+
use weights::WeightInfo;
2122
#[frame_support::pallet]
2223
pub mod pallet {
2324
//! Provides the backend services and metadata storage for the confidential docs solution
25+
use super::*;
2426
use crate::types::*;
2527
use frame_support::pallet_prelude::*;
2628
use frame_system::pallet_prelude::*;
@@ -63,6 +65,9 @@ pub mod pallet {
6365
/// Maximum groups a user can belong to
6466
#[pallet::constant]
6567
type MaxMemberGroups: Get<u32>;
68+
69+
/// Weight information for extrinsics in this pallet.
70+
type WeightInfo: WeightInfo;
6671
}
6772

6873
#[pallet::pallet]
@@ -246,7 +251,7 @@ pub mod pallet {
246251
/// - `public key`: The users cipher public key
247252
/// - `cid`: The IPFS CID that contains the vaults data
248253
#[pallet::call_index(1)]
249-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
254+
#[pallet::weight(<T as Config>::WeightInfo::set_vault(cid.len() as u32))]
250255
pub fn set_vault(
251256
origin: OriginFor<T>,
252257
user_id: UserId,
@@ -265,7 +270,7 @@ pub mod pallet {
265270
/// - `origin`: The user that is creating/updating an owned document
266271
/// - `owned_doc`: Metadata related to the owned document
267272
#[pallet::call_index(2)]
268-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
273+
#[pallet::weight(<T as Config>::WeightInfo::set_owned_document(owned_doc.cid.len() as u32, owned_doc.name.len() as u32, owned_doc.description.len() as u32, T::MaxOwnedDocs::get()))]
269274
pub fn set_owned_document(origin: OriginFor<T>, owned_doc: OwnedDoc<T>) -> DispatchResult {
270275
let who = ensure_signed(origin)?;
271276
Self::do_set_owned_document(who, owned_doc)
@@ -279,7 +284,7 @@ pub mod pallet {
279284
/// - `origin`: The owner of the document
280285
/// - `cid`: of the document to be removed
281286
#[pallet::call_index(3)]
282-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
287+
#[pallet::weight(<T as Config>::WeightInfo::remove_owned_document(cid.len() as u32, T::DocNameMaxLen::get(), T::DocDescMaxLen::get(), T::MaxOwnedDocs::get()))]
283288
pub fn remove_owned_document(origin: OriginFor<T>, cid: CID) -> DispatchResult {
284289
let who = ensure_signed(origin)?;
285290
Self::do_remove_owned_document(who, cid)
@@ -293,7 +298,7 @@ pub mod pallet {
293298
/// - `origin`: The user that is creating the shared document
294299
/// - `shared_doc`: Metadata related to the shared document
295300
#[pallet::call_index(4)]
296-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
301+
#[pallet::weight(<T as Config>::WeightInfo::share_document(shared_doc.cid.len() as u32, shared_doc.name.len() as u32, shared_doc.description.len() as u32, T::MaxSharedFromDocs::get()))]
297302
pub fn share_document(origin: OriginFor<T>, shared_doc: SharedDoc<T>) -> DispatchResult {
298303
let who = ensure_signed(origin)?;
299304
Self::do_share_document(who, shared_doc)
@@ -308,7 +313,7 @@ pub mod pallet {
308313
/// - `origin`: The "to" user of the shared document
309314
/// - `shared_doc`: Metadata related to the shared document
310315
#[pallet::call_index(5)]
311-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
316+
#[pallet::weight(<T as Config>::WeightInfo::update_shared_document_metadata(shared_doc.cid.len() as u32, shared_doc.name.len() as u32, shared_doc.description.len() as u32))]
312317
pub fn update_shared_document_metadata(
313318
origin: OriginFor<T>,
314319
shared_doc: SharedDoc<T>,
@@ -326,7 +331,7 @@ pub mod pallet {
326331
/// - `origin`: The "to" user of the shared document
327332
/// - `cid`: of the document to be removed
328333
#[pallet::call_index(6)]
329-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
334+
#[pallet::weight(<T as Config>::WeightInfo::remove_shared_document(cid.len() as u32, T::DocNameMaxLen::get(), T::DocDescMaxLen::get(), T::MaxSharedFromDocs::get()))]
330335
pub fn remove_shared_document(origin: OriginFor<T>, cid: CID) -> DispatchResult {
331336
let who = ensure_signed(origin)?;
332337
Self::do_remove_shared_document(who, cid)
@@ -343,7 +348,7 @@ pub mod pallet {
343348
/// - `public_key`: Public key of the group
344349
/// - `cid`: cid of the document containing the private key of the group
345350
#[pallet::call_index(7)]
346-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
351+
#[pallet::weight(<T as Config>::WeightInfo::create_group(cid.len() as u32, name.len() as u32))]
347352
pub fn create_group(
348353
origin: OriginFor<T>,
349354
group: T::AccountId,
@@ -363,7 +368,7 @@ pub mod pallet {
363368
/// - `origin`: The user that is adding the member to the group
364369
/// - `group_member`: GroupMember object containg the details of the member
365370
#[pallet::call_index(8)]
366-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
371+
#[pallet::weight(<T as Config>::WeightInfo::add_group_member(group_member.cid.len() as u32, T::GroupNameMaxLen::get(), T::MaxMemberGroups::get()))]
367372
pub fn add_group_member(
368373
origin: OriginFor<T>,
369374
group_member: GroupMember<T>,
@@ -382,7 +387,7 @@ pub mod pallet {
382387
/// - `group`: AccountId of the group
383388
/// - `member`: AccountId of the user to remove from the group
384389
#[pallet::call_index(9)]
385-
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(1))]
390+
#[pallet::weight(<T as Config>::WeightInfo::add_group_member(<CIDSize as frame_support::traits::TypedGet>::get(), T::GroupNameMaxLen::get(), T::MaxMemberGroups::get()))]
386391
pub fn remove_group_member(
387392
origin: OriginFor<T>,
388393
group: T::AccountId,

pallets/confidential-docs/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl pallet_confidential_docs::Config for Test {
7575
type GroupNameMinLen = GroupNameMinLen;
7676
type GroupNameMaxLen = GroupNameMaxLen;
7777
type MaxMemberGroups = MaxMemberGroups;
78+
type WeightInfo = ();
7879
}
7980

8081
// Build genesis storage according to the mock runtime.

pallets/confidential-docs/src/test_util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::{types::*, Config, Error, Event};
1+
use crate::{types::*, Config};
22
use codec::Encode;
3+
use scale_info::{self, prelude::*};
34
use sp_io::hashing::blake2_256;
45

56
pub fn generate_user_id(id: u8) -> UserId {
@@ -42,7 +43,7 @@ pub fn generate_group_name_sized<T: Config>(id: u8, size: u32) -> GroupName<T> {
4243
generate_vector(4, id, size).try_into().unwrap()
4344
}
4445

45-
pub fn generate_vector(prefix: u8, id: u8, size: u32) -> Vec<u8> {
46+
pub fn generate_vector(prefix: u8, id: u8, size: u32) -> scale_info::prelude::vec::Vec<u8> {
4647
assert!(size > 0, "vector size must be greater than 0");
4748
let mut v = vec![id; size as usize];
4849
v[0] = prefix;

0 commit comments

Comments
 (0)