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

Cadence Account Storage Map Migration #6761

Merged
merged 38 commits into from
Feb 6, 2025

Conversation

turbolent
Copy link
Member

@turbolent turbolent commented Nov 26, 2024

Implement the migration logic for onflow/cadence#3584

  • Add a new system contract AccountV2Migration, which is deployed to the service account during bootstrapping. Its Admin resource is able to trigger the migration for the next batch of accounts to be migrated, by calling the injected scheduleAccountV2Migration function
  • Expose a new function fun scheduleAccountV2Migration(addressStartIndex: UInt64, count: UInt64): Bool to the new contract AccountV2Migration in the service account. It generates the addresses in the given range, and schedules the migration to the new account storage format V2. It essentially just calls the internal Go function runtime.Storage.ScheduleV2Migration() provided by Cadence.

@turbolent turbolent requested review from fxamacker and a team November 26, 2024 00:29
@turbolent turbolent self-assigned this Nov 26, 2024
@fxamacker
Copy link
Member

@turbolent Thanks for working on this part of the integration!

Do we want to create a feature branch and target this PR to the feature branch?

@turbolent
Copy link
Member Author

@onflow/flow-cadence-execution is there a way to call accountV2Migration.DeclareScheduleAccountV2MigrationFunction during bootstrapping?

@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 76.44788% with 61 lines in your changes missing coverage. Please review.

Project coverage is 41.19%. Comparing base (f0d7ec9) to head (b5ab3c4).

Files with missing lines Patch % Lines
fvm/accountV2Migration/contract.go 70.45% 30 Missing and 9 partials ⚠️
fvm/runtime/reusable_cadence_runtime.go 45.45% 12 Missing ⚠️
cmd/execution_builder.go 0.00% 4 Missing ⚠️
fvm/systemcontracts/system_contracts.go 66.66% 3 Missing ⚠️
utils/unittest/execution_state.go 0.00% 2 Missing ⚠️
model/flow/chain.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6761      +/-   ##
==========================================
- Coverage   43.29%   41.19%   -2.10%     
==========================================
  Files        1558     2131     +573     
  Lines      139443   186566   +47123     
==========================================
+ Hits        60366    76865   +16499     
- Misses      74026   103264   +29238     
- Partials     5051     6437    +1386     
Flag Coverage Δ
unittests 41.19% <76.44%> (-2.10%) ⬇️

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.

@janezpodhostnik
Copy link
Contributor

@turbolent during bootstrapping you have access to the function invokeMetaTransaction to that function you have to pass an fvm context.

When you want to run DeclareScheduleAccountV2MigrationFunction you can create a child context NewContextFromParent to which you add WithReusableCadenceRuntimePool and add the new cadence runtime pool.

Let me know if that helps.

@turbolent
Copy link
Member Author

@janezpodhostnik Thanks! It turned out that setting up the functions in the runtime won't work, because an environments chain ID might change (default config chain is MN, but then actual chain is e.g. Emulator). I refactored the code to be similar to the EVM setup, i.e. declaring the functions in the transaction invoker and in the script invoker.

@turbolent turbolent changed the base branch from master to auto-update-onflow-cadence-v1.3.0 December 4, 2024 00:16
@turbolent
Copy link
Member Author

@fxamacker I fixed a few things and added a test in 8b597cb which demonstrates that the migration of the service account works. Next step is probably to write an integration test which does this using the system chunk transaction, but I'm very new to this. Maybe someone from @onflow/flow-cadence-execution can take this on or at least point me in the right direction?

@fxamacker
Copy link
Member

@turbolent Thanks for adding the test and other updates!

Would you like me to start reviewing this PR or should I wait until integration test is added and DRAFT status is removed? No rush, just checking before I begin something needed next week.

@turbolent
Copy link
Member Author

@fxamacker Feel free to already start reviewing it. We'll probably want to have the integration tests before we merge, but feedback is already appreciated, thanks!

Base automatically changed from auto-update-onflow-cadence-v1.3.0 to master January 21, 2025 15:49
@turbolent turbolent requested a review from a team as a code owner January 21, 2025 15:49
@turbolent turbolent requested review from janezpodhostnik, fxamacker and a team January 31, 2025 17:50
Copy link
Member

@fxamacker fxamacker left a comment

Choose a reason for hiding this comment

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

Nice! 👍 I left one minor comment about possibility of automatically disabling batch migration by adding and using something like a max address index.

@turbolent turbolent requested a review from a team January 31, 2025 23:44
@j1010001 j1010001 added this pull request to the merge queue Feb 6, 2025
Merged via the queue into master with commit 10f1894 Feb 6, 2025
56 checks passed
@j1010001 j1010001 deleted the bastian/account-storage-map-migration branch February 6, 2025 19:12
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.

5 participants