Derive DecodeWithMemTracking for Block#7655
Conversation
georgepisaltu
left a comment
There was a problem hiding this comment.
General comment which isn't blocking for this PR, but wouldn't it make sense to have the Parameter trait require DecodeWithMemTracking? It would get rid of some trait bounds.
I'm not sure. We could. But I just wanted to avoid having to implement |
franciscoaguirre
left a comment
There was a problem hiding this comment.
Approved but maybe having a Codec macro would be the best
There was a problem hiding this comment.
It will be a bit difficult for people to upgrade their code, I think they will get a lot of error that won't be very descriptive, saying some bound are not met for calling like DispatchTransaction and nothing precise about DecodeWithMemTracking.
Looking at this I wonder if it wouldn't be actually simpler to release parity-scale-codec 4.0 with DecodeWithMemTracking automatically bounded for HasCompact and also automatically derived directly by (not sure of this one)Decode derive macro.
With both it will be simpler for user to upgrade.
But maybe the PR is also fine as it is.
Do have opinion @kianenigma ?
| + Parameter | ||
| + DecodeWithMemTracking |
There was a problem hiding this comment.
If you look at the doc of parameter you get:
/// A type that can be used as a parameter in a dispatchable function.
///
/// When usingdecl_moduleall arguments for call functions must implement this trait.
I think Parameter itself should bound DecodeWithMemTracking.
There was a problem hiding this comment.
I agree that it would be ideal to have DecodeWithMemTracking implemented for each structure that can be used as a parameter in a dispatchable function. But if we do this, we will have to implement DecodeWithMemTracking for a lot more structures and it will lead to even more work for each runtime when it upgrades to this version of polkadot-sdk. Also it isn't needed. We only want to use DecodeWithMemLimit for Block and Extrinsic for the moment. So personally I would avoid doing this.
There was a problem hiding this comment.
I don't understand, requiring DecodeWithMemTracking to extrinsic implies requiring parameter of dispatchables to bound DecodeWithMemTracking
Do you mean people are using the trait Parameter for other types?
Or do you mean that we don't need to enforce it at the pallet level and only constraint at the runtime definition that call implements DecodeWithMemTracking.
Because Parameter should be the bound for types used in extrinsics as part of call parameters.
There was a problem hiding this comment.
Done. Sorry, at that point I hadn't checked exactly. I just tried to do Parameter: DecodeWithMemTracking and saw there were a lot of conflicts. So I thought that people were using DecodeWithMemTracking for other types since we already enforce it for RuntimeCall. But looks like the conflicts were coming from types used in tests. Also had to propagate DecodeWithMemTracking to some more traits.
| <T::RuntimeCall as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<T::AccountId> + AsTransactionAuthorizedOrigin + Clone) | ||
| ] | ||
| <T::RuntimeCall as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<T::AccountId> + AsTransactionAuthorizedOrigin + Clone, | ||
| <T::Nonce as codec::HasCompact>::Type: codec::DecodeWithMemTracking |
There was a problem hiding this comment.
I wonder if we shouldn't just add this bound to Nonce directly.
Do we expect use of frame-system without CheckNonce or frame-system-benchmarking.
I agree it is good to be generic, but FRAME a little bit more opinionated would help the user experience I think.
There was a problem hiding this comment.
I wouldn't add HasCompact to Nonce since I don't know if it's always needed.
Also this is temporary. It's happening because HasCompact looks like this:
pub trait HasCompact: Sized {
/// The compact type; this can be
type Type: for<'a> EncodeAsRef<'a, Self> + Decode + From<Self> + Into<Self>;
}
and we avoided adding Type: DecodeWithMemTracking because it would have been a breaking change. But in parity-scale-codec v4 we can add it.
There was a problem hiding this comment.
I think Nonce already bounds HasCompact through BaseArithmetic
There was a problem hiding this comment.
I think we can remove this line now.
| <T::Nonce as codec::HasCompact>::Type: codec::DecodeWithMemTracking |
substrate/frame/transaction-payment/asset-conversion-tx-payment/src/benchmarking.rs
Outdated
Show resolved
Hide resolved
substrate/frame/transaction-payment/asset-conversion-tx-payment/src/lib.rs
Outdated
Show resolved
Hide resolved
substrate/frame/transaction-payment/asset-tx-payment/src/benchmarking.rs
Outdated
Show resolved
Hide resolved
substrate/frame/transaction-payment/asset-tx-payment/src/lib.rs
Outdated
Show resolved
Hide resolved
|
regarding @gui1117's comment on this being a breaking change, let's zoom back and ask:
If for example a bridge related project needs this, it can be implemented for Block/Header type of that specific runtime? I do agree that this will likely break a lot of solochain or parachain teams that have customized anything in Block/Header realm. |
| bump: major | ||
| - name: bridge-hub-westend-runtime | ||
| bump: none | ||
| bump: patch |
There was a problem hiding this comment.
When working on the prdoc for this PR I realized that I also derived DecodeWithMemTracking in some structures from bridge-hub-westend-runtime in pr #7634. So I guess it should also be patch.
We want this for every runtime. For every user of the SDK.
Are you sure? Also the SCALE upgrade would have a some impact for downstream users. |
Yes ok, SCALE upgrade is a massive task as well. Maybe the best would be to bound That said, bounding |
I agree. SCALE upgrade would be a massive task. Also bounding
For context we need this in order to then be able to add a heap memory limit for the blocks and the extrinsics. So we would need this for every runtime. another thing that we could do in order to reduce the impact of this upgrade is to skip implementing @gui1117 @kianenigma @bkchr WDYT ? |
This reverts commit c836733.
gui1117
left a comment
There was a problem hiding this comment.
Some comments, but I think it looks nicer now, less "where clauses" and just some up-front bounds and derive call.
| <T::RuntimeCall as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<T::AccountId> + AsTransactionAuthorizedOrigin + Clone) | ||
| ] | ||
| <T::RuntimeCall as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<T::AccountId> + AsTransactionAuthorizedOrigin + Clone, | ||
| <T::Nonce as codec::HasCompact>::Type: codec::DecodeWithMemTracking |
There was a problem hiding this comment.
I think we can remove this line now.
| <T::Nonce as codec::HasCompact>::Type: codec::DecodeWithMemTracking |
|
@gui1117 I think I addressed all your comments. Can you please take another look ? |
c11b1f8
Related to #7360
This PR adds
DecodeWithMemTrackingas a trait bound forHeader,BlockandTransactionExtensionandderives it for all the types that implement these traits in
polkadot-sdk.