-
Notifications
You must be signed in to change notification settings - Fork 126
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
prevent accidental changes to storage structs #533
base: main
Are you sure you want to change the base?
Conversation
Look good! I have a question, how to get the hash value in freeze_struct()? |
from the compile error |
@@ -0,0 +1,7 @@ | |||
use subtensor_macros::freeze_struct; | |||
|
|||
#[freeze_struct("ecdcaac0f6da589a")] |
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.
How can one calculate this hash in an easy way?
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.
so right now the dev ux is basically you are in one of two scenarios:
- you are adding it to a new struct, in which case you just do
#[freeze_struct]
with zero args and the compiler error will immediately tell you the proper hash code - you are updating an existing struct that already has a hash code, in which case the compiler error the second you change the struct will tell you the new expected hash code, and also encourages you to write a migration etc. if applicable
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.
people running RA will see it literally in their IDE as well
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.
also worth noting it is immune to doc comment changes, they aren't part of the hash code calculation, and arbitrary additional nodes to ignore could also be added to the visitor pattern if desired
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 see, that's cool! but will this work also for generic structs? It seems like it will also break if you rename a generic or field, even if it is the same encoding?
I think it is certainly a cool idea, and if no similar rust crate exists, we can make it an independent Rust crate, and reference it in our docs.
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.
Yeah it could be modified to be immune to name changes. I wasn't sure if that was safe in all cases so I left that out of this one
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.
Same goes for generics, whatever you want it to ignore in the hash code calculation can be added to the visitor pattern
@@ -139,7 +139,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { | |||
// `spec_version`, and `authoring_version` are the same between Wasm and native. | |||
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use | |||
// the compatible custom types. | |||
spec_version: 154, | |||
spec_version: 155, |
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.
Should we just leave this unchanged?
Fixes #513
devnet companion: #550, #554