Macro or tests to ensure storage elements consistency #912
Labels
crcl-cross-chain
Circle cross-chain related.
crcl-protocol
Circle protocol related.
crcl-runtime
Circle runtime related.
I8-enhancement
An additional feature.
P5-soon
Issue should be addressed soon.
Currently, we have a few rather complex storage types. E.g. the permissions storage and the tranches in the pools. My main concern is, that changes to dependent structs might slip through unnoticed and result in runtime errors upon decoding.
In order to mitigate this risk, we need some logic that ensures storage elements are invariant over time and if an invariant is broken, we get an error (either compilation or through tests).
Needs
Implementation
Generally, I am not in favor of doing this in any specific way, but in order to make this ticket approachable more easily, I draw two "possible" (might also not work) ways to realize what we want.
Proposal A
We write a macro that automatically implements a trait for our storage elements. Best through
derive
. The trait could look something like:Finally, we would need to have a test section in the integration-tests that for each runtime has an assert for each of our storage elements of kind:
We could also try to bring into another trait into substrate as a PR that all storage elements get an additional bound that checks their invariance. But I am 99% sure, that this won't happen as it is a serious breaking change for all consumers of substrate.
Proposal B
This proposal is more simple and more work:
Proposal C
I know that parity is doing some crazy stuff within their macros when setting up their polkadot nodes. Basically, they check, whether the given code initializes all fields of a struct during compilation and return a compilation error, if this is not the case.
I guess we could use a similar approach here and check during compilation if the hashes match. But is more of interest from a rust-nerdy perspective than from a solution-wise one.
The text was updated successfully, but these errors were encountered: