Calculate and refund weight for identity pallet#5680
Conversation
|
It looks like @apopiak signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>
|
Does the PR need a Polkadot companion if it doesn't change the parameters and only the return type of the Dispatchables? |
|
Never mind, I need to add |
| /// (or not) by each arm. Syntax is available to allow for only the range to be drawn upon if | ||
| /// desired, allowing an alternative instancing expression to be given. | ||
| /// | ||
| /// Note that the ranges are *inclusive* on both sides. This is in contrast to ranges in Rust which |
There was a problem hiding this comment.
As a follow up, we can just change the macro syntax to MIN ..= MAX, which I also think solve this syntax mismatch right?
frame/identity/src/lib.rs
Outdated
| extra_fields: impl Into<Weight> | ||
| ) -> Weight { | ||
| db.reads_writes(1, 1) | ||
| + db.reads_writes(1, 1) // balance ops |
There was a problem hiding this comment.
This should be excluded because balance read/write targets the System.Account storage item, which will already be updated this block because a user submitted an extrinsic, and their nonce/fee will be charged.
There was a problem hiding this comment.
Same for the other balance operations in this PR. It would only apply if the user whose balance is changing is NOT the caller.
| extra_fields: impl Into<Weight> | ||
| ) -> Weight { | ||
| db.reads_writes(3, subs.into() + 3) // 2 `take`s + S deletions | ||
| + db.reads_writes(1, 1) // balance ops |
There was a problem hiding this comment.
This case balance op is correct
There was a problem hiding this comment.
But you seem to be missing a write to the treasury account (which I think you would skip anyway since treasury is written to every block, but for further analysis, would be good to double check why you might have missed treasury)
There was a problem hiding this comment.
I should have noted that the I could not account for 1 read and 1 write in the first line.
You think that might be the treasury? Where does it come in? Through Slashed::on_unbalanced?
There was a problem hiding this comment.
Yes, you can see the configuration in the Node runtime, but also you can see it in our DB logs
There was a problem hiding this comment.
So the benchmark says there are 4 reads and subs + 4 writes.
I'm happy to subtract 1 for the balance op, but I don't know how to trace whether the treasury one is a duplicate. With "DB logs" do you mean the logs under the DB benchmark? How would I tell that it's the treasury? Is it a special address?
There was a problem hiding this comment.
I have added treasury to our "whitelist" so it should show up now explicitly in the name and remove itself automatically from the read count.
The way I figured it out is that i used the DB logs and walked through the code to identify each read/write operation on the DB log with some code that was written.
I suggest you do the same
| subs: impl Into<Weight> + Copy, | ||
| extra_fields: impl Into<Weight> | ||
| ) -> Weight { | ||
| db.reads_writes(3, subs.into() + 3) // 2 `take`s + S deletions |
There was a problem hiding this comment.
This should be 2 instead of 3?
There was a problem hiding this comment.
This might be the treasury ops you noted above?
There was a problem hiding this comment.
Not sure, but this should be 2 for both read and write
shawntabrizi
left a comment
There was a problem hiding this comment.
Left some feedback, but everything else looks good here!
shawntabrizi
left a comment
There was a problem hiding this comment.
This looks right.
I guess my last worry would be any chances of overflow in the weight math.
Some of these values are directly controllable by the end user right?
* Companion PR for paritytech#5501 * Bump runtime versions * add MaxRegistrars config * Pull substrate master in PR-5501 * Attempt to fix pin commit again * update to substrate master Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: André Silva <andre.beat@gmail.com>
This PR implements weight calculation and refund for the dispatchables in
pallet-identity.Changes:
set_subsbenchmark (to contain 2 parameters).add_registrarto newMaxRegistrars(new errorTooManyRegistrars)API Notes:
DispatchResultWithPostInfo)Drive-by Changes:
saturating_addbecause it was failing a testRelated to #5596