-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allow nested pallet error, and encode pallet error in 2 bytes. #8081
Comments
once we have metadata with scale-info i think error is just a regular type with its scale-info. |
Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions. |
still relevant to me, also with #8615 which should be able to improve it easily |
Okay, so I would ideally want to use a static assertion here to ensure that the encoded size is less than or equal to 2 bytes. Problem is, there isn't really a method to call the |
The other issue is, the pallet |
We can still make a new trait which definition is: encoded size is at most 2 bytes. Like: trait PalletNestedError {
fn metadata() -> &[&'static str];
fn encode() -> u16;
} I mean we can create a new set of trait and derive macro to declare those errors and they would ensure the constraint we want. We could also just have some test to ensure the max encoded size is less than some value. It might be enough I'm not sure |
We already have assert to ensure size of Call. Similar thing can be done to ensure size of Error |
yes we can also assert this in the integrity test of frame_system pallet |
Not sure we really need this. As I explained/tried to explain on sunday, the error will only use the "maximum" encoded size when there is actually such an error being thrown. What I mean by this, is something like this:
If we are throwing We probably should give people more freedom for this and document this properly so that they understand this. I would assume that 90% of the cases probably still will use only 1 byte. |
Hmm, so I'm not sure if I understand the encoding format correctly, but does SCALE not already do such an optimization for nested enums? And if it does not, then it would look like that we'll have to do some sort of custom encoding scheme to support the case where we use less bytes if the enum variant is not nested. |
yes SCALE does encode like this already, what we need to do is to create trait/derive macro to ensure the error type has constraint so it can be declared only similar to above, and doesn't end up being unconstrained like event which is big. |
Currently pallet error is encoded in one byte, and declare in the metadata some documentation associated to each byte.
But we could encode the error on 2 bytes and allow some nested error. As long as the nested error encode in 1 byte and declare its metadata in some way.
We could implement something like this:
And require
Bar
to implement a trait.The nested error could make use of regular derive macro.
This require also some changes in the metadata, (and we probably want to keep the old metadata format available for off-chain libraries, but this is another issue #8083).
The text was updated successfully, but these errors were encountered: