-
Notifications
You must be signed in to change notification settings - Fork 766
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
Add debugging info for StorageWeightReclaim
#5594
Conversation
StorageWeightReclaim
_info: &sp_runtime::traits::DispatchInfoOf<Self::Call>, | ||
_len: usize, | ||
) -> Result<Self::Pre, sp_runtime::transaction_validity::TransactionValidityError> { | ||
Ok(get_proof_size()) | ||
Ok((get_proof_size(), call.clone())) |
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.
Cloning the entire call is a little bit too expensive.
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.
What about adding the GetCallMetadata
to T::RuntimeCall
and debugging the corresponding CallMetadata
? We'd miss the call arguments, but at least it already points in the right direction. In that case we could also add the extrinsic number, as you suggested.
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.
You can just see the transaction with all its arguments in the block explorer. I don't see any need to log them.
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.
Alright, I just pushed the changes as per your suggestion.
@@ -183,13 +183,13 @@ where | |||
if consumed_weight > benchmarked_weight { | |||
log::error!( | |||
target: LOG_TARGET, | |||
"Benchmarked storage weight smaller than consumed storage weight. benchmarked: {benchmarked_weight} consumed: {consumed_weight} unspent: {unspent}" | |||
"Benchmarked storage weight smaller than consumed storage weight. call: {call:?} benchmarked: {benchmarked_weight} consumed: {consumed_weight} unspent: {unspent}" |
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.
Instead of the call we could print the frame_system::Pallet::extrinsic_count()
. Then you have the index of the transaction.
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 find that less straightforward. You might check the logs at a later point in time, when the state could, for instance, have been pruned. In that scenario you wouldn't be able to retrieve the block (after taking the time to inspect the block in PolkadotJS).
Also, it'd take more time to figure out which extrinsic is. My purpose is to increase as much as possible developer productivity, and the most go-to way I found is this one.
That being said, I understand passing the call and printing its debug information has a performance penalty. Still, I think it'd be better off with the proposed changes, as a small performance penalty could potentially save hours of debugging and improve overall productivity.
Still... if you think otherwise, I'll change it as per your suggestion. But I'd prefer to softly push for the proposed solution, as in my opinion it represents the best trade-off.
EDIT: besides, looking at the implementation of extrinsic_count()
:
/// Gets extrinsics count.
pub fn extrinsic_count() -> u32 {
ExtrinsicCount::<T>::get().unwrap_or_default()
}
It does access an storage item. Wouldn't that introduce a higher performance penalty than the proposed solution?
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.
You might check the logs at a later point in time, when the state could, for instance, have been pruned. In that scenario you wouldn't be able to retrieve the block (after taking the time to inspect the block in PolkadotJS).
State pruning is different to blocks pruning. Block pruning needs to be enabled directly.
We don't have that much memory and wasting the memory just for some debugging which is only required in 0.01% of the cases is not a good idea.
It does access an storage item. Wouldn't that introduce a higher performance penalty than the proposed solution?
The storage item will only be accessed when the log level is enabled . For the release build on chain logging should be disabled any way. Thus, this should not lead to any performance impacts on production networks.
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.
some debugging which is only required in 0.01% of the cases is not a good idea.
I'd say an incorrectly benchmarked custom pallet in a parachain is much more common than that. Still, I implemented it as per your suggestion.
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.
Just take all the nodes into account that need to execute the block and that are not used for debugging. Debugging is a small fraction and you get the index of the transaction and that gives you all the information for free.
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.
@bkchr please double check, but to me it looks like ExtrinsicCount
is not updated on the fly, but only at the end of the block here (also in line with the docs):
polkadot-sdk/substrate/frame/system/src/lib.rs
Lines 2048 to 2054 in fcea4ff
pub fn note_finished_extrinsics() { | |
let extrinsic_index: u32 = | |
storage::unhashed::take(well_known_keys::EXTRINSIC_INDEX).unwrap_or_default(); | |
ExtrinsicCount::<T>::put(extrinsic_index); | |
ExecutionPhase::<T>::put(Phase::Finalization); | |
} | |
I think we should use extrinsic_index()
instead which seems to be updated after every xt.
polkadot-sdk/substrate/frame/system/src/lib.rs
Line 2042 in fcea4ff
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &next_extrinsic_index); |
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.
🙈
016421a
When inspecting the logs we often encounter the following message: `Benchmarked storage weight smaller than consumed storage weight. benchmarked: {benchmarked_weight} consumed: {consumed_weight} unspent: {unspent}` However, it is very hard to guess which call is causing the issue. With the changes proposed in this PR, information about the call is provided so that we can easily identify the source of the problem without further delay, and this way work more efficiently in solving the issue. --------- Co-authored-by: Bastian Köcher <[email protected]> (cherry picked from commit 016421a)
Successfully created backport PR for |
Successfully created backport PR for |
When inspecting the logs we often encounter the following message: `Benchmarked storage weight smaller than consumed storage weight. benchmarked: {benchmarked_weight} consumed: {consumed_weight} unspent: {unspent}` However, it is very hard to guess which call is causing the issue. With the changes proposed in this PR, information about the call is provided so that we can easily identify the source of the problem without further delay, and this way work more efficiently in solving the issue. --------- Co-authored-by: Bastian Köcher <[email protected]> (cherry picked from commit 016421a)
Backport #5594 into `stable2407` from Moliholy. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: José Molina Colmenero <[email protected]>
Backport #5594 into `stable2409` from Moliholy. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: José Molina Colmenero <[email protected]>
When inspecting the logs we often encounter the following message:
Benchmarked storage weight smaller than consumed storage weight. benchmarked: {benchmarked_weight} consumed: {consumed_weight} unspent: {unspent}
However, it is very hard to guess which call is causing the issue.
With the changes proposed in this PR, information about the call is provided so that we can easily identify the source of the problem without further delay, and this way work more efficiently in solving the issue.