-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
benchmarks for pallets #27
base: main
Are you sure you want to change the base?
Changes from all commits
5ad5847
59f1b36
34553b8
3386cd0
300d85d
8223932
b15420a
e595f40
0b44418
05b376a
ed1b78b
3522228
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
[workspace.package] | ||
authors = ["Hashed <https://github.com/hashed-io"] | ||
edition = "2021" | ||
homepage = "https://hashed.io" | ||
repository = "https://github.com/hashed-io/hashed-pallets" | ||
license = "MIT" | ||
|
||
[workspace] | ||
members = [ | ||
'pallets/bitcoin-vaults', | ||
'pallets/confidential-docs', | ||
'pallets/rbac', | ||
'pallets/fruniques', | ||
'pallets/gated-marketplace', | ||
'pallets/mapped-assets', | ||
'pallets/afloat', | ||
'pallets/fund-admin', | ||
'pallets/fund-admin-records', | ||
'pallets/bitcoin-vaults', | ||
'pallets/confidential-docs', | ||
'pallets/rbac', | ||
'pallets/fruniques', | ||
'pallets/gated-marketplace', | ||
'pallets/mapped-assets', | ||
'pallets/afloat', | ||
'pallets/fund-admin', | ||
'pallets/fund-admin-records', | ||
'pallets/example-basic' | ||
] | ||
|
||
[profile.release] | ||
panic = 'unwind' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
[package] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
name = "pallet-afloat" | ||
version = "4.0.0-dev" | ||
description = "" | ||
authors = ["Hashed <https://github.com/hashed-io"] | ||
homepage = "https://hashed.io" | ||
edition = "2021" | ||
license = "MIT" | ||
publish = false | ||
repository = "https://github.com/hashed-io/hashed-pallets" | ||
version = "4.0.0-dev" | ||
authors.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -969,22 +969,22 @@ impl<T: Config> Pallet<T> { | |
ensure!(is_admin_or_owner || offer.creator_id == who, Error::<T>::Unauthorized); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GPT summary of 6a0c05 - f30747:
|
||
|
||
match offer.status { | ||
OfferStatus::CREATED => { | ||
OfferStatus::Created => { | ||
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult { | ||
let offer = offer.as_mut().ok_or(Error::<T>::OfferNotFound)?; | ||
offer.cancellation_date = | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(); | ||
offer.status = OfferStatus::CANCELLED; | ||
offer.status = OfferStatus::Cancelled; | ||
Ok(()) | ||
})?; | ||
Ok(()) | ||
}, | ||
OfferStatus::TF_PENDING_SIGNATURE => { | ||
OfferStatus::PendingTFSignature => { | ||
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult { | ||
let offer = offer.as_mut().ok_or(Error::<T>::OfferNotFound)?; | ||
offer.cancellation_date = | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(); | ||
offer.status = OfferStatus::CANCELLED; | ||
offer.status = OfferStatus::Cancelled; | ||
Ok(()) | ||
})?; | ||
Ok(()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,11 @@ pub mod types; | |
pub mod pallet { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
use frame_support::{ | ||
pallet_prelude::*, | ||
traits::{Currency, Time}, | ||
traits::Currency, | ||
}; | ||
use frame_system::{pallet_prelude::*, RawOrigin}; | ||
use pallet_fruniques::types::{Attributes, CollectionDescription, FruniqueRole, ParentInfo}; | ||
use pallet_gated_marketplace::types::*; | ||
use sp_runtime::traits::Scale; | ||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); | ||
|
||
use crate::types::*; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ use sp_runtime::{ | |
traits::{BlakeTwo256, IdentityLookup}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
BuildStorage, | ||
}; | ||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>; | ||
type Block = frame_system::mocking::MockBlock<Test>; | ||
use frame_system::EnsureRoot; | ||
use system::EnsureSigned; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,21 +72,21 @@ pub enum SignUpArgs { | |
Encode, Decode, Clone, Eq, PartialEq, RuntimeDebugNoBound, MaxEncodedLen, TypeInfo, Copy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
)] | ||
pub enum OfferStatus { | ||
CREATED, | ||
MATCHED, | ||
TF_FILLED, | ||
TF_PENDING_SIGNATURE, | ||
TF_SIGNED, | ||
TF_SUBMITTED, | ||
TF_APPROVED, | ||
APPROVED, | ||
FILLED, | ||
CANCELLED, | ||
Created, | ||
Matched, | ||
FilledByTF, | ||
PendingTFSignature, | ||
SignedTF, | ||
SubmittedTF, | ||
ApprovedTF, | ||
Approved, | ||
Filled, | ||
Cancelled, | ||
} | ||
|
||
impl Default for OfferStatus { | ||
fn default() -> Self { | ||
OfferStatus::CREATED | ||
OfferStatus::Created | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
[package] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
name = "pallet-bitcoin-vaults" | ||
version = "4.0.0-dev" | ||
description = "" | ||
authors = ["Hashed <https://github.com/hashed-io"] | ||
homepage = "https://hashed.io" | ||
edition = "2021" | ||
license = "MIT" | ||
publish = false | ||
repository = "https://github.com/hashed-io/hashed-pallets" | ||
version = "4.0.0-dev" | ||
authors.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
[package] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
name = "pallet-confidential-docs" | ||
version = "4.0.0-dev" | ||
description = "Provides backend services for the confidentials docs solution" | ||
authors = ["Hashed <https://github.com/hashed-io"] | ||
homepage = "https://hashed.io" | ||
edition = "2021" | ||
license = "Unlicense" | ||
publish = false | ||
repository = "https://github.com/hashed-io/hashed-pallets" | ||
version = "4.0.0-dev" | ||
authors.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[package] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
name = "pallet-example-basic" | ||
description = "FRAME example pallet" | ||
version = "4.0.0-dev" | ||
authors.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } | ||
log = { version = "0.4.17", default-features = false } | ||
scale-info = { version = "2.10.0", default-features = false, features = [ | ||
"derive" | ||
] } | ||
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false, optional = true } | ||
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false } | ||
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false } | ||
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false } | ||
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false } | ||
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false } | ||
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false } | ||
|
||
[dev-dependencies] | ||
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", tag = "v1.3.0-rc1", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"log/std", | ||
"pallet-balances/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"pallet-balances/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"pallet-balances/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// This file is part of Substrate. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Benchmarking for `pallet-example-basic`. | ||
|
||
// Only enable this module for benchmarking. | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use crate::*; | ||
use frame_benchmarking::v2::*; | ||
use frame_system::RawOrigin; | ||
|
||
// To actually run this benchmark on pallet-example-basic, we need to put this pallet into the | ||
// runtime and compile it with `runtime-benchmarks` feature. The detail procedures are | ||
// documented at: | ||
// https://docs.substrate.io/reference/how-to-guides/weights/add-benchmarks/ | ||
// | ||
// The auto-generated weight estimate of this pallet is copied over to the `weights.rs` file. | ||
// The exact command of how the estimate generated is printed at the top of the file. | ||
|
||
// Details on using the benchmarks macro can be seen at: | ||
// https://paritytech.github.io/substrate/master/frame_benchmarking/trait.Benchmarking.html#tymethod.benchmarks | ||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
// This will measure the execution time of `set_dummy`. | ||
#[benchmark] | ||
fn set_dummy_benchmark() { | ||
// This is the benchmark setup phase. | ||
// `set_dummy` is a constant time function, hence we hard-code some random value here. | ||
let value = 1000u32.into(); | ||
#[extrinsic_call] | ||
set_dummy(RawOrigin::Root, value); // The execution phase is just running `set_dummy` extrinsic call | ||
|
||
// This is the optional benchmark verification phase, asserting certain states. | ||
assert_eq!(Pallet::<T>::dummy(), Some(value)) | ||
} | ||
|
||
// An example method that returns a Result that can be called within a benchmark | ||
fn example_result_method() -> Result<(), BenchmarkError> { | ||
Ok(()) | ||
} | ||
|
||
// This will measure the execution time of `accumulate_dummy`. | ||
// The benchmark execution phase is shorthanded. When the name of the benchmark case is the same | ||
// as the extrinsic call. `_(...)` is used to represent the extrinsic name. | ||
// The benchmark verification phase is omitted. | ||
#[benchmark] | ||
fn accumulate_dummy() -> Result<(), BenchmarkError> { | ||
let value = 1000u32.into(); | ||
// The caller account is whitelisted for DB reads/write by the benchmarking macro. | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
// an example of calling something result-based within a benchmark using the ? operator | ||
// this necessitates specifying the `Result<(), BenchmarkError>` return type | ||
example_result_method()?; | ||
|
||
// You can use `_` if the name of the Call matches the benchmark name. | ||
#[extrinsic_call] | ||
_(RawOrigin::Signed(caller), value); | ||
|
||
// need this to be compatible with the return type | ||
Ok(()) | ||
} | ||
|
||
/// You can write helper functions in here since its a normal Rust module. | ||
fn setup_vector(len: u32) -> Vec<u32> { | ||
let mut vector = Vec::<u32>::new(); | ||
for i in (0..len).rev() { | ||
vector.push(i); | ||
} | ||
vector | ||
} | ||
|
||
// This will measure the execution time of sorting a vector. | ||
// | ||
// Define `x` as a linear component with range `[0, =10_000]`. This means that the benchmarking | ||
// will assume that the weight grows at a linear rate depending on `x`. | ||
#[benchmark] | ||
fn sort_vector(x: Linear<0, 10_000>) { | ||
let mut vector = setup_vector(x); | ||
|
||
// The benchmark execution phase could also be a closure with custom code: | ||
#[block] | ||
{ | ||
vector.sort(); | ||
} | ||
|
||
// Check that it was sorted correctly. This will not be benchmarked and is just for | ||
// verification. | ||
vector.windows(2).for_each(|w| assert!(w[0] <= w[1])); | ||
} | ||
|
||
// This line generates test cases for benchmarking, and could be run by: | ||
// `cargo test -p pallet-example-basic --all-features`, you will see one line per case: | ||
// `test benchmarking::bench_sort_vector ... ok` | ||
// `test benchmarking::bench_accumulate_dummy ... ok` | ||
// `test benchmarking::bench_set_dummy_benchmark ... ok` in the result. | ||
// | ||
// The line generates three steps per benchmark, with repeat=1 and the three steps are | ||
// [low, mid, high] of the range. | ||
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT summary of c2a02c - 76c07f: