-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: thanks and much gratitude! #282
Changes from 18 commits
a76f37d
6299284
4995444
fe3312b
7760917
11237fb
e037a8f
21ebaff
1403f6f
09655f4
06a1711
c3e5b8b
3941b2a
a90a2cf
10d57db
883e59d
4cf1509
979b8b1
5e544df
ad96003
ea0dec3
572b9e6
ab7f9ed
ebcba63
1fc4b3c
d246ab6
0c07692
4cc3c04
2133775
1962bf6
feef542
e72f5f7
28ec259
a83a697
e9c782e
865af56
e4ecf0d
cc60d3b
67ac756
9cb4c23
2f811aa
f9266bc
0acd108
d45ad85
e32f92d
99162bf
1c4d440
1dba99b
86bf869
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 |
---|---|---|
|
@@ -18,14 +18,21 @@ | |
|
||
use crate::*; | ||
|
||
use codec::{Decode, Encode}; | ||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; | ||
use frame_support::{dispatch::UnfilteredDispatchable, traits::Currency, unsigned::ValidateUnsigned}; | ||
use frame_system::RawOrigin; | ||
use sp_runtime::traits::{One, StaticLookup}; | ||
use sp_runtime::{ | ||
traits::{One, StaticLookup}, | ||
Permill, | ||
}; | ||
|
||
const SEED_1: u32 = 1; | ||
const SEED_2: u32 = 2; | ||
|
||
benchmarks! { | ||
where_clause { where <T as frame_system::Config>::BlockNumber: From<u32> } | ||
|
||
set_registrar_account { | ||
let registrar: AccountIdOf<T> = account("registrar", 0, SEED_1); | ||
let new_registrar: AccountIdOf<T> = account("new_registrar", 0, SEED_2); | ||
|
@@ -44,7 +51,7 @@ benchmarks! { | |
let contributor: AccountIdOf<T> = account("contributor", 0, SEED_2); | ||
let contribution: BalanceOf<T> = BalanceOf::<T>::one(); | ||
RegistrarAccount::<T>::set(registrar.clone()); | ||
}: _(RawOrigin::Signed(registrar), T::Lookup::unlookup(contributor.clone()), contribution) | ||
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. In general, you should be weary of placing a function like Imagine any of the code after the setup is triggering after the timer starts. |
||
}: _(RawOrigin::Signed(registrar), contributor.clone(), contribution) | ||
verify { | ||
assert_eq!( | ||
Contributions::<T>::get(&contributor), | ||
|
@@ -53,13 +60,90 @@ benchmarks! { | |
); | ||
} | ||
|
||
set_config { | ||
let registrar: AccountIdOf<T> = account("registrar", 0, SEED_1); | ||
RegistrarAccount::<T>::set(registrar.clone()); | ||
|
||
let config = GratitudeConfig::<T::BlockNumber> { | ||
vested_share: Permill::from_percent(42), | ||
start_block: 1.into(), | ||
vesting_length: 10.into(), | ||
}; | ||
}: _(RawOrigin::Signed(registrar), config.clone()) | ||
verify { | ||
assert_eq!( | ||
Configuration::<T>::get(), | ||
config, | ||
); | ||
} | ||
|
||
set_reserve_accounts { | ||
let registrar: AccountIdOf<T> = account("registrar", 0, SEED_1); | ||
let reserve_free: AccountIdOf<T> = account("reserve_free", 0, SEED_1); | ||
let reserve_vested: AccountIdOf<T> = account("reserve_vested", 0, SEED_1); | ||
RegistrarAccount::<T>::set(registrar.clone()); | ||
|
||
ntn-x2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}: _( | ||
RawOrigin::Signed(registrar), | ||
T::Lookup::unlookup(reserve_vested.clone()), | ||
T::Lookup::unlookup(reserve_free.clone()) | ||
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. same warning here, just do this above and pass as a new variable. 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. Yes this probably increases the weight a bit. fixed in 865af56 |
||
) | ||
verify { | ||
assert_eq!( | ||
crate::Reserve::<T>::get(), | ||
ntn-x2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ReserveAccounts { | ||
vested: reserve_vested, | ||
free: reserve_free, | ||
} | ||
); | ||
} | ||
|
||
// receive_gratitude is benchmarked together with validate_unsigned to accommodate for the additional cost of validate_unsigned | ||
receive_gratitude { | ||
let registrar: AccountIdOf<T> = account("registrar", 0, SEED_1); | ||
let reserve_free: AccountIdOf<T> = account("reserve_free", 0, SEED_1); | ||
let reserve_vested: AccountIdOf<T> = account("reserve_vested", 0, SEED_1); | ||
let contributor: AccountIdOf<T> = account("contributor", 0, SEED_1); | ||
|
||
let contribution: BalanceOf<T> = CurrencyOf::<T>::minimum_balance() | ||
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.
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. nice! fixed in 865af56 |
||
+ CurrencyOf::<T>::minimum_balance() | ||
+ CurrencyOf::<T>::minimum_balance(); | ||
|
||
RegistrarAccount::<T>::set(registrar); | ||
Reserve::<T>::set(ReserveAccounts { | ||
vested: reserve_vested.clone(), | ||
free: reserve_free.clone(), | ||
}); | ||
Contributions::<T>::insert(&contributor, contribution); | ||
Configuration::<T>::set(GratitudeConfig { | ||
vested_share: Permill::from_percent(50), | ||
start_block: 1.into(), | ||
vesting_length: 10.into(), | ||
}); | ||
CurrencyOf::<T>::make_free_balance_be(&reserve_vested, contribution); | ||
CurrencyOf::<T>::make_free_balance_be(&reserve_free, contribution); | ||
|
||
let source = sp_runtime::transaction_validity::TransactionSource::External; | ||
let call_enc = Call::<T>::receive_gratitude { | ||
ntn-x2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
receiver: contributor.clone(), | ||
}.encode(); | ||
}: { | ||
let call = <Call<T> as Decode>::decode(&mut &*call_enc) | ||
.expect("call is encoded above, encoding must be correct"); | ||
crate::Pallet::<T>::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?; | ||
ntn-x2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
call.dispatch_bypass_filter(RawOrigin::None.into())?; | ||
} | ||
verify { | ||
assert!(crate::Contributions::<T>::get(contributor).is_none()); | ||
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. S: Let's also check whether the contributor received the gratitude. 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. |
||
} | ||
|
||
remove_contribution { | ||
let registrar: AccountIdOf<T> = account("registrar", 0, SEED_1); | ||
let contributor: AccountIdOf<T> = account("contributor", 0, SEED_2); | ||
let contribution: BalanceOf<T> = BalanceOf::<T>::one(); | ||
RegistrarAccount::<T>::set(registrar.clone()); | ||
Contributions::<T>::insert(&contributor, contribution); | ||
}: _(RawOrigin::Signed(registrar), T::Lookup::unlookup(contributor.clone())) | ||
}: _(RawOrigin::Signed(registrar), contributor.clone()) | ||
verify { | ||
assert!( | ||
Contributions::<T>::get(&contributor).is_none(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
//! Autogenerated weights for crowdloan | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
//! DATE: 2021-10-20, STEPS: {{cmd.steps}}\, REPEAT: {{cmd.repeat}}\, LOW RANGE: {{cmd.lowest_range_values}}\, HIGH RANGE: {{cmd.highest_range_values}}\ | ||
//! DATE: 2021-10-27, STEPS: {{cmd.steps}}\, REPEAT: {{cmd.repeat}}\, LOW RANGE: {{cmd.lowest_range_values}}\, HIGH RANGE: {{cmd.highest_range_values}}\ | ||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 | ||
|
||
// Executed Command: | ||
|
@@ -48,24 +48,42 @@ use sp_std::marker::PhantomData; | |
pub trait WeightInfo { | ||
fn set_registrar_account() -> Weight; | ||
fn set_contribution() -> Weight; | ||
fn set_config() -> Weight; | ||
fn set_reserve_accounts() -> Weight; | ||
fn receive_gratitude() -> Weight; | ||
fn remove_contribution() -> Weight; | ||
} | ||
|
||
/// Weights for crowdloan using the Substrate node and recommended hardware. | ||
pub struct SubstrateWeight<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { | ||
fn set_registrar_account() -> Weight { | ||
(18_544_000_u64) | ||
(21_644_000_u64) | ||
.saturating_add(T::DbWeight::get().reads(1_u64)) | ||
.saturating_add(T::DbWeight::get().writes(1_u64)) | ||
} | ||
fn set_contribution() -> Weight { | ||
(20_679_000_u64) | ||
(23_815_000_u64) | ||
.saturating_add(T::DbWeight::get().reads(2_u64)) | ||
.saturating_add(T::DbWeight::get().writes(1_u64)) | ||
} | ||
fn set_config() -> Weight { | ||
(21_247_000_u64) | ||
.saturating_add(T::DbWeight::get().reads(1_u64)) | ||
.saturating_add(T::DbWeight::get().writes(1_u64)) | ||
} | ||
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. are you using an old benchmarking template / version? You should be getting metadata information about the reads and writes from the benchmarking now. https://github.com/paritytech/substrate/blob/master/frame/democracy/src/weights.rs#L79 |
||
fn set_reserve_accounts() -> Weight { | ||
(24_336_000_u64) | ||
.saturating_add(T::DbWeight::get().reads(2_u64)) | ||
.saturating_add(T::DbWeight::get().writes(1_u64)) | ||
} | ||
fn receive_gratitude() -> Weight { | ||
(178_299_000_u64) | ||
.saturating_add(T::DbWeight::get().reads(8_u64)) | ||
.saturating_add(T::DbWeight::get().writes(6_u64)) | ||
} | ||
fn remove_contribution() -> Weight { | ||
(21_661_000_u64) | ||
(25_459_000_u64) | ||
.saturating_add(T::DbWeight::get().reads(2_u64)) | ||
.saturating_add(T::DbWeight::get().writes(1_u64)) | ||
} | ||
|
@@ -74,17 +92,32 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { | |
// For backwards compatibility and tests | ||
impl WeightInfo for () { | ||
fn set_registrar_account() -> Weight { | ||
(18_544_000_u64) | ||
(21_644_000_u64) | ||
.saturating_add(RocksDbWeight::get().reads(1_u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1_u64)) | ||
} | ||
fn set_contribution() -> Weight { | ||
(20_679_000_u64) | ||
(23_815_000_u64) | ||
.saturating_add(RocksDbWeight::get().reads(2_u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1_u64)) | ||
} | ||
fn set_config() -> Weight { | ||
(21_247_000_u64) | ||
.saturating_add(RocksDbWeight::get().reads(1_u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1_u64)) | ||
} | ||
fn set_reserve_accounts() -> Weight { | ||
(24_336_000_u64) | ||
.saturating_add(RocksDbWeight::get().reads(2_u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1_u64)) | ||
} | ||
fn receive_gratitude() -> Weight { | ||
(178_299_000_u64) | ||
.saturating_add(RocksDbWeight::get().reads(8_u64)) | ||
.saturating_add(RocksDbWeight::get().writes(6_u64)) | ||
} | ||
fn remove_contribution() -> Weight { | ||
(21_661_000_u64) | ||
(25_459_000_u64) | ||
.saturating_add(RocksDbWeight::get().reads(2_u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1_u64)) | ||
} | ||
|
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.
This should not be needed? I think it is already configured that this primitive must always be at least U32.
See here: https://github.com/paritytech/substrate/blob/master/frame/system/src/lib.rs#L201
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.
Ah! That's super handy! 865af56