-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com> # Conflicts: # frame/example/src/lib.rs
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com> # Conflicts: # bin/node/runtime/src/lib.rs # frame/example/src/lib.rs
@@ -496,7 +506,9 @@ pub mod pallet { | |||
// calls to be executed - we don't need to care why. Because it's privileged, we can | |||
// assume it's a one-off operation and substantial processing/storage/memory can be used | |||
// without worrying about gameability or attack scenarios. | |||
#[pallet::weight(WeightForSetDummy::<T>(<BalanceOf<T>>::from(100u32)))] |
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.
the documentation for WeightForSetDummy
is outdated now.
Maybe we can just remove it as we prefer to just show benchmarking way, not sure. cc @kianenigma
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.
I am thinking it is a good way to showcasing how to set the weight: 1) thru benchmarking, 2) manually setting it via WeightForSetDummy, and it shows setting an extrinsic call as operational call.
I think it will be great showing runtime developers alternatives that they can override the measured benchmarking and tweak the weight function as they want. Will there be some scenarios that this is necessary for dev?
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.
ideally what people need to understand is that pallet::weight take into argument any type which implements:
WeighData<(Arg1, Arg2, ..)>
ClassifyDispatch<(Arg1, Arg2, ..)>
PaysFee<(Arg1, Arg2, ..)>
where Arg1, Arg2, ..., are the type of the argument of the call.
Make we can keep WeightForSetDummy for this call.
I think if we keep WeightForSetDummy in the code and never use it, people can't understand how to use it.
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.
oh boy I totally have forgotten about these manual weights.
I think they can stay, only if we mention that this is an advanced feature if you want some custom functionality. Most often, you want to use WeightInfo
stuff only.
If too much for now, @jimmychu0807 you can remove it in this PR, make a new Issue in the devhub for custom weight calculators and ping me there, I can help with that.
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.
@kianenigma We kind of have that in devhub here, though we should probably move it to the Transaction Weight document.
And the example implementation of WeightForSetDummy demonstrates what you could customize.
Added additional comment in code for readers to consider running benchmarking toolchain instead of manually setting weight unless they know what they are doing.
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
@@ -292,7 +310,9 @@ impl<T: pallet_balances::Config> WeighData<(&BalanceOf<T>,)> for WeightForSetDum | |||
{ |
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.
re: #8301 (comment)
In here, we start implementing the WeightData, ClassifyDispatch, and PaysFee. In each implementations, we do use the paramter (&BalanceOf<T>)
. Is that what you mean to "use it" in your comment?
@kianenigma @shawntabrizi @thiolliere I did a clean up on the pallet code, comment, and benchmarking code in pallet-example. See if this PR is okay to merge. btw, how do I fix the CI error of |
/// The overarching event type. | ||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>; | ||
type WeightInfo: WeightInfo; |
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.
type WeightInfo: WeightInfo; | |
/// Somethign representing the weights of this pallet. | |
type WeightInfo: WeightInfo; |
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.
LGTM
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Signed-off-by: Jimmy Chu <jimmychu0807@gmail.com>
thanks @kianenigma @thiolliere @shawntabrizi for the review! |
* master: (84 commits) Duplicate logging to stdout (#8495) Fix sync restart (#8497) client: fix justifications migration (#8489) helper macro to create storage types on the fly (#8456) Make `BlockImport` and `Verifier` async (#8472) Get rid of `test-helpers` feature in sc-consensus-babe (#8486) Enhancement on Substrate Node Template (#8473) Add Social Network (#8065) Prepare UI tests for Rust 1.51 & new CI image (#8474) Benchmarking pallet-example (#8301) Use pathbuf for remote externalities (#8480) Bring back the on_finalize weight of staking. (#8463) Implement `fungible::*` for Balances (#8454) make types within `generate_solution_type` macro explicit (#8447) [pallet-staking] Refund unused weight for `payout_stakers` (#8458) Use `async_trait` in sc-consensus-slots (#8461) Repot frame_support::traits; introduce some new currency stuff (#8435) Fix &mut self -> &self in add_known_address (#8468) Add NetworkService::add_known_address (#8467) Fix companion check (#8464) ...
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
pallet-example
weights.rs
inpallet-example
, so it can be referenced in documentation / substrate devhub.Before you submitting, please check that:
A*
for PR status (one required)B*
for changelog (one required)C*
for release notes (exactly one required)D*
for various implications/requirementsFixes #228
orRelated #1337
.Refer to the contributing guide for details.
After you've read this notice feel free to remove it.
Thank you!
✄ -----------------------------------------------------------------------------