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

Infer the missing borrow type for storage capabilities #6314

Closed
wants to merge 3 commits into from

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Aug 9, 2024

Instead of skipping the capabilities with missing borrow-type, try to infer it as either &AnyResource or &AnyStruct, and continue migrating such values.

@SupunS SupunS self-assigned this Aug 9, 2024
@@ -345,7 +347,71 @@ func (m *IssueStorageCapConMigration) Close() error {
return nil
}

var _ AccountBasedMigration = &IssueStorageCapConMigration{}
func (m *IssueStorageCapConMigration) issueAccountCapabilities(
Copy link
Member Author

@SupunS SupunS Aug 9, 2024

Choose a reason for hiding this comment

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

This method was copied over and modified from Cadence side. Need to access the storage, etc. so having it here makes more sense.
The old method can be removed from cadence (tech-debt).

Copy link
Member

Choose a reason for hiding this comment

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

We might need to re-incorporate the logic from onflow/cadence#3516 once it's merged, or move the changes here to Cadence.

@SupunS SupunS marked this pull request as ready for review August 9, 2024 23:17
@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.

Project coverage is 41.51%. Comparing base (a53b9b8) to head (f28b494).

Files Patch % Lines
cmd/util/ledger/migrations/cadence.go 95.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6314      +/-   ##
==========================================
+ Coverage   41.50%   41.51%   +0.01%     
==========================================
  Files        1965     2009      +44     
  Lines      140713   143244    +2531     
==========================================
+ Hits        58400    59473    +1073     
- Misses      76236    77587    +1351     
- Partials     6077     6184     +107     
Flag Coverage Δ
unittests 41.51% <95.23%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SupunS SupunS force-pushed the supun/fix-storage-cap-migration branch from 9f9f6d3 to f28b494 Compare August 9, 2024 23:27
@SupunS SupunS requested review from a team August 9, 2024 23:47
@SupunS
Copy link
Member Author

SupunS commented Aug 12, 2024

Might not work after onflow/cadence#3516. Need to re-visit.

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Logic and tests look good!

As discussed in the Slack thread, unfortunately due to onflow/cadence#3516, we probably need to refactor the improvement here once that PR is in

@@ -345,7 +347,71 @@ func (m *IssueStorageCapConMigration) Close() error {
return nil
}

var _ AccountBasedMigration = &IssueStorageCapConMigration{}
func (m *IssueStorageCapConMigration) issueAccountCapabilities(
Copy link
Member

Choose a reason for hiding this comment

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

We might need to re-incorporate the logic from onflow/cadence#3516 once it's merged, or move the changes here to Cadence.

Comment on lines +378 to +379
// If the borrow type is missing, treat it as `AnyStruct` or `AnyResource`.
// To determine whether it is a resource, read the target path.
Copy link
Member

Choose a reason for hiding this comment

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

The capability has direct access to the storage path, without any borrow type "restriction", so theoretically the capability could be borrowed with any type. Inferring to &AnyStruct / &AnyResource (or even &Any) might not be sufficient, for two reasons:

  1. The capability could be borrowed with entitlements, but the inferred type does not grant any.

    For example, imagine a capability targeting /storage/flowTokenVault, not having a borrow type, and getting borrowed with auth(FungibleToken.Withdraw) &FlowToken.Vault.

  2. The value stored under the path could change (e.g. even from a resource to a struct or vice-versa), making the inferred borrow type "too restrictive"

The first issue is more problematic than the latter.

Maybe we should just infer a more specific type, based on the stored value at the time of migration. This would make 2) worse, but would at least fix 1)

@SupunS
Copy link
Member Author

SupunS commented Aug 12, 2024

Added to Cadence in onflow/cadence#3519

@SupunS SupunS closed this Aug 12, 2024
@SupunS SupunS deleted the supun/fix-storage-cap-migration branch August 12, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants