Skip to content
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

Upgrade scarb edition to 2024_07 #1138

Merged
merged 7 commits into from
Sep 12, 2024
Merged

Upgrade scarb edition to 2024_07 #1138

merged 7 commits into from
Sep 12, 2024

Conversation

ggonzalez94
Copy link
Collaborator

@ggonzalez94 ggonzalez94 commented Sep 8, 2024

Fixes #1048
This PR upgades our codebase to scarb 2024_07 edition. Biggest changes are:

  • The prelude is much smaller now, and doesn't include any method to access storage(bummer, I know!). So we have to manually import.
  • Storage structs and it's members are not pub by default anymore. So we have to manually define them as pub.
    • This is ok for components(since we want smart contract developers to be able to access compinent's storage variables in their contracts)
    • This is ok for mocks(we don't care)
    • For presets we might want to make it more restrictive, but we can decide in a later issue/PR.

PR Checklist

  • Tests
  • Added entry to CHANGELOG.md

Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ggonzalez94, the PR is looking good. A couple of comments:

  • We can consolidate imports into fewer lines (I signaled a couple of places, but this applies to the entire PR).
  • Note that while adding pub to mocks (and presets) Storage struct makes sense because we access the storage directly in tests, generally, we shouldn't make contracts Storage public, since they are usually not accessed outside the contract itself. I think we shouldn't update doc site examples making the Storage struct public for example.

Comment on lines 16 to 18
use starknet::storage::Map;
use starknet::storage::StorageMapReadAccess;
use starknet::storage::StorageMapWriteAccess;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use starknet::storage::Map;
use starknet::storage::StorageMapReadAccess;
use starknet::storage::StorageMapWriteAccess;
use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess};

Comment on lines 23 to 24
use starknet::storage::StoragePointerReadAccess;
use starknet::storage::StoragePointerWriteAccess;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use starknet::storage::StoragePointerReadAccess;
use starknet::storage::StoragePointerWriteAccess;
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};

@ggonzalez94
Copy link
Collaborator Author

@ericnordelo thanks for taking a look even when this was in draft!

We can consolidate imports into fewer lines (I signaled a couple of places, but this applies to the entire PR).

Agreed! This was just the IDE autocompletion, I was already planning to refactor this

Note that while adding pub to mocks (and presets) Storage struct makes sense because we access the storage directly in tests, generally, we shouldn't make contracts Storage public, since they are usually not accessed outside the contract itself. I think we shouldn't update doc site examples making the Storage struct public for example

When I applied the changes I did it so that it compiles with the edition changes and then we can figure out the best way forward. It is my understanding that before this edition the compiler automatically adds the pub modifier to struct and fields, is that correct? If that's the case then if we want to avoid breaking changes we should apply the same to our components.
If we want to take a more thoughtful decision we should consider, what fields of components we want contracts that embed them have direct access to and fields we want to prevent developers to access? Right now my understanding is that since these are pubby default they could access any field from the contract.

@ggonzalez94 ggonzalez94 marked this pull request as ready for review September 10, 2024 18:14
Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when this does not change the library's public API, we should add an entry to the CHANGELOG for consistency.

@ggonzalez94
Copy link
Collaborator Author

Even when this does not change the library's public API, we should add an entry to the CHANGELOG for consistency.

Absolutely! I was just waiting for #1137 to get merged to avoid merge conflicts. I added a simple entry under the Changed section. Let me know if you think we should add more details.

Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good! I left a couple questions

struct Storage {}
pub struct Storage {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if we make empty storage structs not public?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes much of a difference, right? But it might be easy to overlook adding the pub keyword if we add some field to it. I can remove all pub from all empty storage structs if you feel strongly about this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes much of a difference, right?

Yeahhh this really just occurs with mocks, right? No strong opinions on this. I think it's okay as is

packages/presets/src/account.cairo Show resolved Hide resolved
Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ggonzalez94 ggonzalez94 merged commit 24aacb4 into main Sep 12, 2024
6 checks passed
@ericnordelo ericnordelo deleted the upgrade-edition-2024-07 branch October 22, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update edition to 2024_07
3 participants