-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat!: autoload storage slots #1120
Conversation
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.
Very clean implementation and good UX choices. Left just a couple of nits/suggestions.
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.
IMO it is a bit weird that we try to get the storage slots path from the bin path. What do you think that instead we ask for the sway project folder. From there we can get both the bin and the storage slots and we can generate nice error messages. Something like this:
let contract = Contract::load_from(
"some/path/sway_project_name",
LoadConfiguration::default().
)?;
That's a good point. In the implementation we're essentially just grabbing the project dir anyway: let dir = contract_binary.parent()?;
let binary_filename = contract_binary.file_stem()?.to_str()?;
Some(dir.join(format!("{binary_filename}-storage_slots.json"))) And then grabbing the project name (which is the bin name) and slapping the storage_slots string in front of it... Might as well just grab the dir name. I don't have super strong opinions on this, but I agree it could be confusing for the end user. |
I share your feelings, but have the following reservations: If we start giving project paths to the We would expect that the user gave us the root dir of the project (the one where But is the build a Is the project titled the same as the dir? The What if somebody just wants to load a contract binary from outside a project? We would need to support them and provide an alternative, custom-path-loading mechanism. Or they would need to recreate this folder structure by hand. If we start accepting project paths, then we would probably want to be consistent in the Although it seems |
Co-authored-by: Rodrigo Araújo <[email protected]>
I agree. Let's use this until we have something better! |
## Description - Bump harness template to v0.48.0 for [intro-to-sway guide](FuelLabs/docs-hub#55) - Used auto loading [storage slots ](FuelLabs/fuels-rs#1120) ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. Co-authored-by: Igor Rončević <[email protected]>
closes: #1117 #1118
Storage slots are now loaded automatically by default (an opt-out exists).
If the
StorageConfiguration
indicates that autoload should take place,Contract::load_from
will try and discover the storage slots file in the same directory as the contract binary to be loaded.If it is for some reason missing this constitutes an error. The user will be guided to either provide the file or disable autoloading.
Any additional storage slots configured in
StorageConfiguration
act as an override taking precedence over what was loaded from the storage slots file.Enabling the autoloading uncovered a bug where we didn't account for storage slots when calculating the heap data offset for predicates.
Breaking
The storage configuration interface changed
Autoloading by default might change behavior.
Checklist