-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 <[email protected]>
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 |
@@ -69,6 +69,9 @@ pub use paste; | |||
/// (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case balance op is correct
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be 2 instead of 3?
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 might be the treasury ops you noted above?
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.
Not sure, but this should be 2 for both read and write
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.
yeah, you're right
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.
Left some feedback, but everything else looks good here!
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 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?
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.
Looks good!
* 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 <[email protected]> Co-authored-by: André Silva <[email protected]>
This PR implements weight calculation and refund for the dispatchables in
pallet-identity
.Changes:
set_subs
benchmark (to contain 2 parameters).add_registrar
to newMaxRegistrars
(new errorTooManyRegistrars
)API Notes:
DispatchResultWithPostInfo
)Drive-by Changes:
saturating_add
because it was failing a testRelated to #5596