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

QA full Cadence 1.0 state migration in Emulator #3098

Closed
turbolent opened this issue Feb 12, 2024 · 29 comments
Closed

QA full Cadence 1.0 state migration in Emulator #3098

turbolent opened this issue Feb 12, 2024 · 29 comments
Assignees

Comments

@turbolent
Copy link
Member

turbolent commented Feb 12, 2024

Goal: Someone (in 4D?) can take a test contract, take snapshot based on v0.42 and run migration on emulator and validate the upgraded contract works correctly.

depends on: onflow/flow-cli#1433

@SupunS
Copy link
Member

SupunS commented Mar 6, 2024

I have already done this testing, so guess we can mark this as done.

Maybe one last thing to test is the final CLI build (for the milestone release), once it is out.

@turbolent
Copy link
Member Author

Nice work doing some initial testing Supun!

Eventually, it would be good to do a final test before the release.

There are still some improvements to the state migration outstanding: onflow/flow-go#5479 and we should re-test once those landed in the Emulator.

It would also be great to test the state migration on a "larger" / "real" project. I had asked Dev Ex on Discord here: https://discord.com/channels/613813861610684416/1123314820763111465/1210727371905171496

@SupunS
Copy link
Member

SupunS commented Mar 6, 2024

ah nice!

@turbolent
Copy link
Member Author

Forgot to mention / just to be clear: Ideally this isn't done by "us" (Cadence team), but maybe by someone familiar with such an example project. cc @j1010001 to maybe connect with Dev Ex / the community

@nvdtf nvdtf self-assigned this Mar 7, 2024
@nvdtf
Copy link
Member

nvdtf commented Mar 11, 2024

I tried testing from CLI branch using ExampleNFT. When I run ... migrate state --db-path=./pre-1.0-state/emulator.sqlite --save-report=./reports --contracts="ExampleNFT" I get:

4:37PM INF created account migrations inner_migrations=1 nWorker=1
4:37PM INF Sorting payloads by address payloads=256 workers=1
4:37PM INF Sorted. Finding account boundaries in sorted payloads duration=0s payloads=256
4:37PM INF Done grouping payloads by account accounts=12 duration=0s
4:37PM ERR could not migrate account error="failed to find all contract registers that need to be changed for address f8d6e0586b0a20c7:\n  - RandomBeaconHistory\n" address=f8d6e0586b0a20c7 migration=*migrations.ChangeContractCodeMigration migration_index=0
4:37PM INF waiting for migration workers to finish
4:37PM INF Top longest migrations top_longest_migrations=[]
4:37PM INF closing migration migration=*migrations.ChangeContractCodeMigration migration_index=0
4:37PM ERR error closing migration error="failed to find all contract registers that need to be changed:\n- address: e5a8b7f23e8b548f\n  - FlowFees\n- address: 0ae53cb6e3f42a79\n  - FlowToken\n- address: ee82856bf20e2aa6\n  - FungibleToken\n  - FungibleTokenMetadataViews\n"
4:37PM INF finished migrating Payloads account_count=12 payload_count=256
❌ Command Error: failed to migrate database: could not migrate accounts: failed to migrate payload: could not migrate account: failed to find all contract registers that need to be changed for address f8d6e0586b0a20c7:
  - RandomBeaconHistory

Seemed to me they are errors regarding upgrading base contracts. The original flow.json file can be seen here. I tried removing extra contracts to only test mine:

{
	"networks": {
		"emulator": "127.0.0.1:3569",
		"mainnet": "access.mainnet.nodes.onflow.org:9000",
		"sandboxnet": "access.sandboxnet.nodes.onflow.org:9000",
		"testnet": "access.devnet.nodes.onflow.org:9000"
	},
	"contracts": {
		"ExampleNFT": "cadence/contracts/exampleNFT/ExampleNFT.cdc"
	},
	"accounts": {
		"emulator-account": {
			"address": "f8d6e0586b0a20c7",
			"key": "e0c1b659658250b0141cd2e847cb68ea1dcfd455cbcf818006bf116189dc0269"
		}
	}
}

But now I'm getting:

❌ Command Error: failed to resolve staged contracts: failed to get address by contract name: contract not found in state

Is there something I'm missing? I was following this guide.

@SupunS
Copy link
Member

SupunS commented Mar 12, 2024

@nvdtf Can you try adding the following, to the flow.json?

"deployments": {
    "emulator": {
        "emulator-account": [
            "ExampleNFT"
        ]
    }
}

If that was the issue, I'll also add this to the migration guide.

@nvdtf
Copy link
Member

nvdtf commented Mar 12, 2024

@SupunS Yeah that fixed the contract not found in state error. Now I'm getting the first error:

6:12PM INF created account migrations inner_migrations=1 nWorker=1
6:12PM INF Sorting payloads by address payloads=256 workers=1
6:12PM INF Sorted. Finding account boundaries in sorted payloads duration=0s payloads=256
6:12PM INF Done grouping payloads by account accounts=12 duration=0s
6:12PM ERR could not migrate account error="failed to find all contract registers that need to be changed for address f8d6e0586b0a20c7:\n  - RandomBeaconHistory\n" address=f8d6e0586b0a20c7 migration=*migrations.ChangeContractCodeMigration migration_index=0
6:12PM INF waiting for migration workers to finish
6:12PM INF Top longest migrations top_longest_migrations=[]
6:12PM INF closing migration migration=*migrations.ChangeContractCodeMigration migration_index=0
6:12PM ERR error closing migration error="failed to find all contract registers that need to be changed:\n- address: e5a8b7f23e8b548f\n  - FlowFees\n- address: 0ae53cb6e3f42a79\n  - FlowToken\n- address: ee82856bf20e2aa6\n  - FungibleToken\n  - FungibleTokenMetadataViews\n"
6:12PM INF finished migrating Payloads account_count=12 payload_count=256
❌ Command Error: failed to migrate database: could not migrate accounts: failed to migrate payload: could not migrate account: failed to find all contract registers that need to be changed for address f8d6e0586b0a20c7:
  - RandomBeaconHistory

The produced reports are empty. Not sure what I'm doing wrong

@turbolent
Copy link
Member Author

turbolent commented Mar 12, 2024

What build of the CLI are you using?

It's likely that the latest release has problems.

@SupunS I'll update the Emulator once onflow/flow-go#5533 and onflow/flow-go#5540 are merged. Would be great to get this updated all the way down to the CLI.

@nvdtf
Copy link
Member

nvdtf commented Mar 12, 2024

The latest release doesn't support migrate state yet. I'm using this branch: https://github.com/onflow/flow-cli/tree/jribbink/migrate-command (PR onflow/flow-cli#1426).
Maybe this needs to be merged with master before testing.

@SupunS
Copy link
Member

SupunS commented Mar 12, 2024

So what is failing is the core-contracts migration. Seems the expected core/system contracts cannot be found in the emulator state. Did the contract addresses change at some point in the emulator? (not sure, but I think I saw somewhere something like that).

6:12PM ERR could not migrate account error="failed to find all contract registers that need to be changed for address f8d6e0586b0a20c7:\n - RandomBeaconHistory\n" address=f8d6e0586b0a20c7 migration=*migrations.ChangeContractCodeMigration migration_index=0

Do you know what's the version of the CLI used to create the old state? Trying to see if it's a version before the RandomBeaconHistory was introduced?

@turbolent
Copy link
Member Author

Yeah, that's likely. Maybe we need to make the update for this contract conditional. Alternatively we should recommend updating the pre-1.0 CLI to the latest version when creating the snapshot

@nvdtf
Copy link
Member

nvdtf commented Mar 12, 2024

That could be likely. My old CLI is v1.4.2 so its a few versions behind. I don't know if it matters, but I run the old one with --contracts that deploys a couple of standards.

@SupunS
Copy link
Member

SupunS commented Mar 12, 2024

Updated the guide with these points

@turbolent
Copy link
Member Author

@nvdtf Can you please re-try with the latest pre-1.0 CLI to create the snapshot, and with the 1.0 feature branch: https://github.com/onflow/flow-cli/tree/feature/stable-cadence – it has the migrate command now, and improved migration code.

There are a couple known issues, but I'm also currently updating the CLI once again to the latest migration code with fixes for the known issues.

@turbolent
Copy link
Member Author

@nvdtf I finished the update, can you please retry with the latest CLI preview release: https://github.com/onflow/flow-cli/releases/tag/v1.12.0-cadence-v1.0.0-preview.9 ?

@nvdtf
Copy link
Member

nvdtf commented Mar 14, 2024

Thanks for the updates! Looks like the previous errors are all solved. I'm using the latest released flow-c1 v1.12.0-cadence-v1.0.0-preview.9 and now I'm getting this error migrating ExampleNFT:
Seems like its complaining about core contract updates like NonFungibleToken.

11:08AM INF running migration migration=burner-deployment-migration
11:08AM WRN empty value for key f8d6e0586b0a20c7/$41
11:08AM INF running migration migration=system-contracts-update-migration
11:08AM INF created account migrations inner_migrations=1 nWorker=16
11:08AM INF Sorting payloads by address payloads=223 workers=16
11:08AM INF Sorted. Finding account boundaries in sorted payloads duration=0s payloads=223
11:08AM INF Done grouping payloads by account accounts=12 duration=0s
11:08AM INF processing account group progress 1/12 (8.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 2/12 (16.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 3/12 (25.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 4/12 (33.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 5/12 (41.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 6/12 (50.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 7/12 (58.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 8/12 (66.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 9/12 (75.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 10/12 (83.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 11/12 (91.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 12/12 (100.0%) total time 0s
11:08AM INF waiting for migration workers to finish
11:08AM INF Top longest migrations top_longest_migrations=["0000000000000000 [payloads: 1]: 42ns","0000000000000000 [payloads: 3]: 49ns","0000000000000000 [payloads: 7]: 51ns","179b6b1cb6755e31 [payloads: 16]: 6.662µs","e03daebed8ca0615 [payloads: 15]: 8.819µs","f3fcd2c1a78f5eee [payloads: 9]: 13.443µs","0000000000000000 [payloads: 1]: 111ns","01cf0e2f2f715450 [payloads: 7]: 19.423µs","e5a8b7f23e8b548f [payloads: 13]: 102.694µs","0ae53cb6e3f42a79 [payloads: 12]: 67.221µs","f8d6e0586b0a20c7 [payloads: 126]: 197.083µs","ee82856bf20e2aa6 [payloads: 13]: 99.975µs"]
11:08AM INF closing migration migration=*migrations.ChangeContractCodeMigration migration_index=0
11:08AM INF finished migrating Payloads account_count=12 payload_count=223
11:08AM INF running migration migration=staged-contracts-update-migration
11:08AM INF created account migrations inner_migrations=1 nWorker=16
11:08AM INF Sorting payloads by address payloads=223 workers=16
11:08AM INF Sorted. Finding account boundaries in sorted payloads duration=0s payloads=223
11:08AM INF Done grouping payloads by account accounts=12 duration=0s
11:08AM INF processing account group progress 1/12 (8.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 2/12 (16.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 3/12 (25.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 4/12 (33.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 5/12 (41.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 6/12 (50.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 7/12 (58.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 8/12 (66.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 9/12 (75.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 10/12 (83.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 11/12 (91.7%) elapsed: 0s, eta 0s
11:08AM ERR failed to update contract ExampleNFT in account 0xf8d6e0586b0a20c7 error="Checking failed:\nerror: GetCode failed: expected AddressLocation\n--> NonFungibleToken\n\nerror: GetCode failed: expected AddressLocation\n--> ViewResolver\n\nerror: GetCode failed: expected AddressLocation\n--> MetadataViews\n\nerror: cannot find type in this scope: `NonFungibleToken`\n  --> f8d6e0586b0a20c7.ExampleNFT:17:33\n\nerror: cannot find type in this scope: `NonFungibleToken`\n  --> f8d6e0586b0a20c7.ExampleNFT:25:30\n\nerror: cannot find type in this scope: `ViewResolver`\n  --> f8d6e0586b0a20c7.ExampleNFT:25:52\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:127:37\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:44:24\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:35:37\n\nerror: cannot find type in this scope: `NonFungibleToken`\n  --> f8d6e0586b0a20c7.ExampleNFT:58:51\n\nerror: ambiguous intersection type\n  --> f8d6e0586b0a20c7.ExampleNFT:58:50\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:160:15\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:160:43\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:160:103\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:160:102\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:169:41\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:169:40\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:188:56\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:188:55\n\nerror: cannot find type in this scope: `ViewResolver`\n   --> f8d6e0586b0a20c7.ExampleNFT:193:63\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:193:62\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:203:51\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:203:50\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:276:24\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:210:60\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:210:59\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:221:17\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:221:12\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:222:17\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:222:12\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:233:22\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:233:17\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:244:22\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:244:17\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:234:37\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:239:61\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:239:60\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:245:28\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:246:26\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:251:23\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:254:33\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:258:35\n\nerror: cannot infer type from dictionary literal: requires an explicit type annotation\n   --> f8d6e0586b0a20c7.ExampleNFT:257:29\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:64:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:64:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:65:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:65:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:66:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:66:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:67:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:67:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:68:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:68:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:69:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:69:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:70:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:70:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:71:21\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:71:16\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:77:26\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:77:21\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:85:26\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:85:21\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:93:26\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:93:21\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:97:26\n\nerror: cannot infer type parameter: `T`\n  --> f8d6e0586b0a20c7.ExampleNFT:97:21\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:101:26\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:101:21\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:103:26\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:103:21\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:105:26\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:105:21\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:107:26\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:107:21\n\nerror: cannot find variable in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:78:27\n\nerror: cannot find variable in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:81:35\n\nerror: cannot find variable in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:88:38\n\nerror: cannot find type in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:89:38\n\nerror: cannot find variable in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:90:27\n\nerror: cannot find variable in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:94:27\n\nerror: cannot find variable in this scope: `MetadataViews`\n  --> f8d6e0586b0a20c7.ExampleNFT:98:27\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:102:27\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:104:112\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:104:107\n\nerror: cannot find type in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:106:112\n\nerror: cannot infer type parameter: `T`\n   --> f8d6e0586b0a20c7.ExampleNFT:106:107\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:110:37\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:113:42\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:117:41\n\nerror: cannot find variable in this scope: `MetadataViews`\n   --> f8d6e0586b0a20c7.ExampleNFT:118:35\n\nerror: cannot find type in this scope: `NonFungibleToken`\n   --> f8d6e0586b0a20c7.ExampleNFT:189:45\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:189:44\n\nerror: cannot find type in this scope: `ViewResolver`\n   --> f8d6e0586b0a20c7.ExampleNFT:195:32\n\nerror: ambiguous intersection type\n   --> f8d6e0586b0a20c7.ExampleNFT:195:31\n" migration=StagedContractsMigration migration_index=0
11:08AM INF processing account group progress 12/12 (100.0%) total time 0s
11:08AM INF waiting for migration workers to finish
11:08AM INF Top longest migrations top_longest_migrations=["0000000000000000 [payloads: 7]: 38ns","0000000000000000 [payloads: 1]: 38ns","01cf0e2f2f715450 [payloads: 7]: 2.08µs","0000000000000000 [payloads: 1]: 47ns","0000000000000000 [payloads: 3]: 45ns","e03daebed8ca0615 [payloads: 15]: 6.877µs","179b6b1cb6755e31 [payloads: 16]: 4.545µs","e5a8b7f23e8b548f [payloads: 13]: 11.947µs","ee82856bf20e2aa6 [payloads: 13]: 6.012µs","f3fcd2c1a78f5eee [payloads: 9]: 10.626µs","0ae53cb6e3f42a79 [payloads: 12]: 3.752µs","f8d6e0586b0a20c7 [payloads: 126]: 2.530871ms"]
11:08AM INF closing migration migration=*migrations.StagedContractsMigration migration_index=0
11:08AM INF finished migrating Payloads account_count=12 payload_count=223
11:08AM INF running migration migration=contracts
11:08AM INF extracting contracts from payloads ...
11:08AM INF extracted 24 contracts from payloads
11:08AM INF running migration migration=cadence-value-migration
11:08AM INF created account migrations inner_migrations=1 nWorker=16
11:08AM INF Sorting payloads by address payloads=223 workers=16
11:08AM INF Sorted. Finding account boundaries in sorted payloads duration=0s payloads=223
11:08AM INF Done grouping payloads by account accounts=12 duration=0s
11:08AM INF processing account group progress 1/12 (8.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 2/12 (16.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 3/12 (25.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 4/12 (33.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 5/12 (41.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 6/12 (50.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 7/12 (58.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 8/12 (66.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 9/12 (75.0%) elapsed: 0s, eta 0s
11:08AM ERR failed to run EntitlementsMigration in account 179b6b1cb6755e31, domain public, key exampleNFTCollection: error getting program 179b6b1cb6755e31.ExampleNFT: failed to derive value: load program failed: Parsing failed:
error: `pub` is no longer a valid access keyword
  --> :16:0
   |
16 | pub contract ExampleNFT: NonFungibleToken, ViewResolver {
   | ^^^

error: `pub` is no longer a valid access keyword
  --> :19:4
   |
19 |     pub var totalSupply: UInt64
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :22:4
   |
22 |     pub event ContractInitialized()
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :25:4
   |
25 |     pub event Withdraw(id: UInt64, from: Address?)
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :28:4
   |
28 |     pub event Deposit(id: UInt64, to: Address?)
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :31:4
   |
31 |     pub let CollectionStoragePath: StoragePath
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :32:4
   |
32 |     pub let CollectionPublicPath: PublicPath
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :33:4
   |
33 |     pub let MinterStoragePath: StoragePath
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :39:4
   |
39 |     pub resource NFT: NonFungibleToken.INFT, MetadataViews.Resolver {
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :42:8
   |
42 |         pub let id: UInt64
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :45:8
   |
45 |         pub let name: String
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :46:8
   |
46 |         pub let description: String
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :47:8
   |
47 |         pub let thumbnail: String
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :72:8
   |
72 |         pub fun getViews(): [Type] {
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :90:8
   |
90 |         pub fun resolveView(_ view: Type): AnyStruct? {
   |         ^^^

error: restricted types have been removed; replace with the concrete type or an equivalent intersection type
   --> :123:70
    |
123 |                         publicCollection: Type<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic}>(),
    |                                                                       ^^^^^^^^^^
 migration=cadence-value-migration migration_index=0
11:08AM INF processing account group progress 10/12 (83.3%) elapsed: 0s, eta 0s
11:08AM ERR failed to run EntitlementsMigration in account e03daebed8ca0615, domain public, key exampleNFTCollection: error getting program migration=cadence-value-migration migration_index=0
11:08AM INF processing account group progress 11/12 (91.7%) elapsed: 0s, eta 0s
11:08AM ERR failed to run EntitlementsMigration in account f8d6e0586b0a20c7, domain public, key exampleNFTCollection: error getting program f8d6e0586b0a20c7.ExampleNFT: failed to derive value: load program failed: Parsing failed:
error: `pub` is no longer a valid access keyword
  --> :16:0
   |
16 | pub contract ExampleNFT: NonFungibleToken, ViewResolver {
   | ^^^

error: `pub` is no longer a valid access keyword
  --> :19:4
   |
19 |     pub var totalSupply: UInt64
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :22:4
   |
22 |     pub event ContractInitialized()
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :25:4
   |
25 |     pub event Withdraw(id: UInt64, from: Address?)
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :28:4
   |
28 |     pub event Deposit(id: UInt64, to: Address?)
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :31:4
   |
31 |     pub let CollectionStoragePath: StoragePath
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :32:4
   |
32 |     pub let CollectionPublicPath: PublicPath
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :33:4
   |
33 |     pub let MinterStoragePath: StoragePath
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :39:4
   |
39 |     pub resource NFT: NonFungibleToken.INFT, MetadataViews.Resolver {
   |     ^^^

error: `pub` is no longer a valid access keyword
  --> :42:8
   |
42 |         pub let id: UInt64
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :45:8
   |
45 |         pub let name: String
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :46:8
   |
46 |         pub let description: String
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :47:8
   |
47 |         pub let thumbnail: String
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :72:8
   |
72 |         pub fun getViews(): [Type] {
   |         ^^^

error: `pub` is no longer a valid access keyword
  --> :90:8
   |
90 |         pub fun resolveView(_ view: Type): AnyStruct? {
   |         ^^^

error: restricted types have been removed; replace with the concrete type or an equivalent intersection type
   --> :123:70
    |
123 |                         publicCollection: Type<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic}>(),
    |                                                                       ^^^^^^^^^^
 migration=cadence-value-migration migration_index=0
11:08AM INF processing account group progress 12/12 (100.0%) total time 0s
11:08AM INF waiting for migration workers to finish
11:08AM INF Top longest migrations top_longest_migrations=["0000000000000000 [payloads: 1]: 116ns","0000000000000000 [payloads: 3]: 123ns","0000000000000000 [payloads: 1]: 148ns","0000000000000000 [payloads: 7]: 160ns","ee82856bf20e2aa6 [payloads: 13]: 9.57517ms","f3fcd2c1a78f5eee [payloads: 9]: 9.664567ms","e5a8b7f23e8b548f [payloads: 13]: 9.634567ms","01cf0e2f2f715450 [payloads: 7]: 9.680698ms","0ae53cb6e3f42a79 [payloads: 12]: 9.55088ms","179b6b1cb6755e31 [payloads: 16]: 10.669387ms","e03daebed8ca0615 [payloads: 15]: 11.455668ms","f8d6e0586b0a20c7 [payloads: 126]: 34.780316ms"]
11:08AM INF closing migration migration=*migrations.CadenceBaseMigrator migration_index=0
11:08AM INF Created report file filename=reports/cadence-value-migrator_1710439682.json
11:08AM INF finished migrating Payloads account_count=12 payload_count=223
11:08AM INF running migration migration=cadence-link-value-migration
11:08AM INF created account migrations inner_migrations=1 nWorker=16
11:08AM INF Sorting payloads by address payloads=223 workers=16
11:08AM INF Sorted. Finding account boundaries in sorted payloads duration=0s payloads=223
11:08AM INF Done grouping payloads by account accounts=12 duration=0s
11:08AM INF processing account group progress 1/12 (8.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 2/12 (16.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 3/12 (25.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 4/12 (33.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 5/12 (41.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 6/12 (50.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 7/12 (58.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 8/12 (66.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 9/12 (75.0%) elapsed: 0s, eta 0s
11:08AM ERR failed to run LinkValueMigration in account 179b6b1cb6755e31, domain public, key exampleNFTCollection: error getting program migration=cadence-link-value-migration migration_index=0
11:08AM INF processing account group progress 10/12 (83.3%) elapsed: 0s, eta 0s
11:08AM ERR failed to run LinkValueMigration in account e03daebed8ca0615, domain public, key exampleNFTCollection: error getting program migration=cadence-link-value-migration migration_index=0
11:08AM INF processing account group progress 11/12 (91.7%) elapsed: 0s, eta 0s
11:08AM ERR failed to run LinkValueMigration in account f8d6e0586b0a20c7, domain public, key exampleNFTCollection: error getting program migration=cadence-link-value-migration migration_index=0
11:08AM INF processing account group progress 12/12 (100.0%) total time 0s
11:08AM INF waiting for migration workers to finish
11:08AM INF Top longest migrations top_longest_migrations=["0000000000000000 [payloads: 7]: 35ns","0000000000000000 [payloads: 1]: 47ns","0000000000000000 [payloads: 3]: 49ns","0000000000000000 [payloads: 1]: 125ns","f3fcd2c1a78f5eee [payloads: 9]: 6.133383ms","01cf0e2f2f715450 [payloads: 7]: 5.971066ms","0ae53cb6e3f42a79 [payloads: 12]: 6.052855ms","ee82856bf20e2aa6 [payloads: 13]: 6.269648ms","e5a8b7f23e8b548f [payloads: 13]: 6.275197ms","179b6b1cb6755e31 [payloads: 16]: 6.824198ms","e03daebed8ca0615 [payloads: 15]: 7.146598ms","f8d6e0586b0a20c7 [payloads: 126]: 22.187773ms"]
11:08AM INF closing migration migration=*migrations.CadenceBaseMigrator migration_index=0
11:08AM INF Created report file filename=reports/cadence-link-value-migrator_1710439682.json
11:08AM INF finished migrating Payloads account_count=12 payload_count=223
11:08AM INF running migration migration=cadence-capability-value-migration
11:08AM INF created account migrations inner_migrations=1 nWorker=16
11:08AM INF Sorting payloads by address payloads=267 workers=16
11:08AM INF Sorted. Finding account boundaries in sorted payloads duration=0s payloads=267
11:08AM INF Done grouping payloads by account accounts=12 duration=0s
11:08AM INF processing account group progress 1/12 (8.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 2/12 (16.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 3/12 (25.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 4/12 (33.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 5/12 (41.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 6/12 (50.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 7/12 (58.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 8/12 (66.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 9/12 (75.0%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 10/12 (83.3%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 11/12 (91.7%) elapsed: 0s, eta 0s
11:08AM INF processing account group progress 12/12 (100.0%) total time 0s
11:08AM INF waiting for migration workers to finish
11:08AM INF Top longest migrations top_longest_migrations=["0000000000000000 [payloads: 1]: 88ns","0000000000000000 [payloads: 7]: 106ns","0000000000000000 [payloads: 1]: 98ns","0000000000000000 [payloads: 3]: 182ns","01cf0e2f2f715450 [payloads: 12]: 366.951µs","e5a8b7f23e8b548f [payloads: 18]: 362.943µs","ee82856bf20e2aa6 [payloads: 18]: 452.193µs","179b6b1cb6755e31 [payloads: 21]: 517.866µs","0ae53cb6e3f42a79 [payloads: 17]: 393.027µs","f3fcd2c1a78f5eee [payloads: 14]: 512.641µs","e03daebed8ca0615 [payloads: 20]: 715.23µs","f8d6e0586b0a20c7 [payloads: 135]: 2.668002ms"]
11:08AM INF closing migration migration=*migrations.CadenceBaseMigrator migration_index=0
11:08AM INF Created report file filename=reports/cadence-capability-value-migrator_1710439682.json
11:08AM INF finished migrating Payloads account_count=12 payload_count=267

@SupunS
Copy link
Member

SupunS commented Mar 14, 2024

Looking into it, could be a bug in the migration. Think I know what's happening

@turbolent
Copy link
Member Author

turbolent commented Mar 14, 2024

I think the problem is that developers will likely use string-location imports, e.g. import "Foo" in their contracts, when they're updating, just as when they're deploying. The CLI rewrites those imports during deployment to addresses, based on the config. However, the state migration in flow-go assumes contracts are in "on-chain" format, with address-location imports (e.g. import Foo from 0x123)

Do we have that import-rewrite logic integrated in the flow migrate command? cc @jribbink

@SupunS
Copy link
Member

SupunS commented Mar 14, 2024

@nvdtf Does the contracts section in flow.json points to the 'updated' code of ExampleNFT?

{
 "contracts": {
    "ExampleNFT": "updated_ExampleNFT.cdc"
  },
}

@nvdtf
Copy link
Member

nvdtf commented Mar 14, 2024

@SupunS Yes it points to the updated version. After I saw the error I double checked to make sure. Wasn't sure why its complaining about all pub modifiers.

@SupunS
Copy link
Member

SupunS commented Mar 15, 2024

So there were two issues:

Once both of these fixes are merged, I'll do another CLI build.

@SupunS
Copy link
Member

SupunS commented Mar 19, 2024

@nvdtf A new CLI release with the fix is now available: https://github.com/onflow/flow-cli/releases/tag/v1.15.0-cadence-v1.0.0-preview.12

Can you please try with the new release and see if that works fine?

@nvdtf
Copy link
Member

nvdtf commented Mar 19, 2024

Thanks for the new releases! We're one step closer to getting a successful run now.

We found out the new NFTv2 changes are flagged as invalid contract updates in the migration function:

image

Some of the contract updates are not supported out-of-the-box with migration.
@SupunS is trying to find a fix now to relax contract update requirements, or change NFTv2 implementation for token standards to better support migration.

@joshuahannan
Copy link
Member

I think it makes sense to update the ExampleNFT contract to not add those path fields in the Collection.

It also makes sense that it would complain about the mismatching ownedNFTs field because before it was

pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT}

and now it is

access(contract) var ownedNFTs: @{UInt64: ExampleNFT.NFT}

which would be an invalid upgrade. I didn't realize we were actually going to be migrating ExampleNFT, so I just built it how I thought a developer should build their new NFT contracts without worrying about migrations. But I guess since we are using it for migrations, then we do need to revert those field additions and changes.

I can review a PR to the flow-nft repo if y'all make one this week and I can help get the dependencies updated in all the contracts repos so we can get flow-go and the CLI updated also. Shouldn't take too long once the ExampleNFT changes are made

@SupunS
Copy link
Member

SupunS commented Mar 20, 2024

Thanks Josh for having a look!

But I guess since we are using it for migrations, then we do need to revert those field additions and changes.

We are not actually doing any migrations to the ExampleNFT by default. Navid just used this as a sample to test the contract updates/migrations. IINM the idea behind is that to see if people follows this template (ExampleNFT), would they still be able to migrate their contracts. And if not what do we need to change.

This did uncover some of the rules that need to be / could be relaxed in the contract-update-validator. And for others, like the new fields, I believe developers could work around by adjusting their code.

@nvdtf
Copy link
Member

nvdtf commented Mar 22, 2024

🎉 I ran a successful migration with ExampleNFT:

import "NonFungibleToken"
import "ExampleNFT"
import "ViewResolver"

/// Script to get NFT IDs in an account's collection
///
access(all) fun main(address: Address): [UInt64] {
    let account = getAccount(address)

    let collectionRef = account.capabilities.borrow<&{
        NonFungibleToken.CollectionPublic,
        ExampleNFT.ExampleNFTCollectionPublic,
        ViewResolver.ResolverCollection
    }>(
        /public/exampleNFTCollection
      ) ?? panic("Could not borrow capability from collection at specified path")

    return collectionRef.getIDs()
}

@turbolent
Copy link
Member Author

That's awesome!

Once recently identified bugs (see https://github.com/onflow/cadence/milestone/27) have been fixed, we should re-run this test case

@turbolent
Copy link
Member Author

@nvdtf Could you please re-test using the latest CLI preview release? Once it's been verified that everything works as expected, could you please close the issue?

@nvdtf
Copy link
Member

nvdtf commented Apr 10, 2024

Executed the above test again. No errors and got expected output. Closing issue.
Tested with Flow CLI v1.17.0-cadence-v1.0.0-preview.18

@nvdtf nvdtf closed this as completed Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

5 participants