-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Assert Storage Key & Value Invariance #13037
Comments
I don't really get how this should work. The following idea goes into the direction you want to achieve here: paritytech/polkadot-sdk#241 |
What don't you understand? ^^ paritytech/polkadot-sdk#241 looks really promising, but it requires either fetching the whole state of a chain -- at least one key for each entry -- or having a snapshot available. |
Why shouldn't this be feasible? I mean you would do this as part of your testing setup, nothing that runs on chain. I don't see any reason this shouldn't work?
Where this lock value is coming from and the other zeroed_and_uninit() is coming from. That also sounds like a lot of mostly useless values "floating" around. From where will pallet users get these values? How do they update these values? |
I dont think you can statically assert that the encoding of a type did not change. The compiler would have to prove to you that the code does the same as before - which is impossible. What you propose IIUC is some fuzzy testing.
This would only check that the one instance of the type does not change its encoding, or?
You would need to generate all instances of that type, so to check that the encoding of an
I dont think that is a problem. Fetching the whole state currently takes about 14 minutes, which is done to check runtime-migrations in the CI eg here. If you really want to do that, you could think about some |
This argument holds also for the But 14 minutes are actually great.
This is the idea here. I would argue that for every primitive type in rust, that is also serializable for substrate-storage, there exist a valid zero-value-encoding. The only exception would be enums, where the zero-encoding would need to encode each variant after the other as a valid encoding to check against. But as you said, this would only indicate that a migration is needed, while |
The reason for this issue is that silent changes in the scale-coding of types -- through changes in the types themselves, or unlikely, changes in the codec -- used for storage keys and values worry me more and more. Even more, since the latest migrations in Substrate mostly were triggered via
OnRuntimeUpgrade
instead of hooks.Proposal
My proposal for a solution would be the following. I have not coded this already, just checked that the traits work and the static assertion fails, but I am not sure if an auto-derive is trivial and so forth.
Codec provides 2 additional traits + auto-derive for
StaticEncode
Storage items of pallets automatically implement the following impl block
Users can opt-out of this by adding
pallet::without_storage_lock
Runtimes must implement
Lock<T>
for everyT
that is a key or a valueAdvantages
Problems
BYTES
for associated types in pallets needs to be constant but runtime specificFor enums it would be needed to actually encode all variants in the "static" representation in order to ensure no variant has changed its encoding.
Edits:
The text was updated successfully, but these errors were encountered: