Skip to content

Cadence 1.0 Multi-Staging#1582

Merged
jribbink merged 50 commits into
feature/stable-cadencefrom
jribbink/stage-all
May 15, 2024
Merged

Cadence 1.0 Multi-Staging#1582
jribbink merged 50 commits into
feature/stable-cadencefrom
jribbink/stage-all

Conversation

@jribbink

@jribbink jribbink commented May 7, 2024

Copy link
Copy Markdown
Contributor

Closes #1559

Description

Adds support for staging multiple contracts at once.

Screenshot 2024-05-09 at 3 58 33 PM

Approach:

  • Encapsulate staging functionality in "Staging Service"
  • Staging service can stage multiple contracts at once
  • Staging validator adapted to allow multiple contracts, returns separate errors per contract
  • Local dependency tree of all local/remote checkers is built, everything is cached (contracts, checkers, etc). Checking remote contracts is very expensive, so caching is important. Additionally, it's important that all contracts are validated together, because this way staging order is irrelevant (e.g. validation is done using local copies).

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@jribbink jribbink changed the base branch from master to feature/stable-cadence May 7, 2024 16:28
@codecov-commenter

codecov-commenter commented May 8, 2024

Copy link
Copy Markdown

Comment thread internal/migrate/staging_service.go Outdated
Comment thread internal/migrate/staging_service.go
Comment thread internal/migrate/staging_validator.go Outdated
@bjartek

bjartek commented May 14, 2024

Copy link
Copy Markdown
Collaborator

Just tried to run this on find repo since I have 45 things to stage there and i got

flow migrate stage-contract --all -n testnet
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                           ⚠ Upgrade to Cadence 1.0
     The Crescendo network upgrade, including Cadence 1.0, is coming soon.
     You may need to update your existing contracts to support this change.
                     Please visit our migration guide here:
             https://cadence-lang.org/docs/cadence_migration_guide
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
panic: interface conversion: common.Location is common.IdentifierLocation, not common.AddressLocation

goroutine 1 [running]:
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).parseAndCheckAllStaged.func1({0x104c13e20, 0x140025977a0})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:266 +0x128
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).forEachDependency.func1({0x104c13de0, 0x140024d97e0})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:701 +0xfc
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).forEachDependency.func1({0x104c13de0, 0x14002ac2720})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:702 +0x114
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).forEachDependency(0x14000d477c0, {{{0x140014d0400, 0xb}, {0x3e, 0x5b, 0x4c, 0x62, 0x70, 0x64, 0x62, ...}}, ...}, ...)
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:706 +0xd0
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).parseAndCheckAllStaged(0x14000d477c0)
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:264 +0x1e0
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).Validate(0x14000d477c0, {0x14000238608, 0x2e, 0x1?})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:178 +0x1a8
github.com/onflow/flow-cli/internal/migrate.(*stagingServiceImpl).validateAndStageContracts(0x14000d47800, {0x104c0eb60, 0x1061543e0}, {0x14000238608, 0x2e, 0x4b})
	github.com/onflow/flow-cli/internal/migrate/staging_service.go:101 +0x11c
github.com/onflow/flow-cli/internal/migrate.(*stagingServiceImpl).StageContracts(0x14000d47800, {0x104c0eb60, 0x1061543e0}, {0x14000c31a00?, 0x2e, 0x0?})
	github.com/onflow/flow-cli/internal/migrate/staging_service.go:92 +0x80
github.com/onflow/flow-cli/internal/migrate.stageAll({0x104c000f0, 0x14000d47800}, 0x14000fbcf30, {0x104c359d8?, 0x14000d171a0?})
	github.com/onflow/flow-cli/internal/migrate/stage_contract.go:135 +0xbc
github.com/onflow/flow-cli/internal/migrate.stageContract({0x14000d4b410, 0x0, 0x3}, {{0x0, 0x0}, {0x103ebd395, 0x4}, {0x0, 0x0}, {0x0, ...}, ...}, ...)
	github.com/onflow/flow-cli/internal/migrate/stage_contract.go:92 +0x3cc
github.com/onflow/flow-cli/internal/command.Command.AddToParent.func1(0x14000d51100?, {0x14000d4b410, 0x0, 0x3})
	github.com/onflow/flow-cli/internal/command/command.go:142 +0x4cc
github.com/spf13/cobra.(*Command).execute(0x105fbd4a0, {0x140001b8150, 0x3, 0x3})
	github.com/spf13/cobra@v1.8.0/command.go:987 +0x828
github.com/spf13/cobra.(*Command).ExecuteC(0x1400055d808)
	github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
	github.com/onflow/flow-cli/cmd/flow/main.go:168 +0xd9c

@jribbink

Copy link
Copy Markdown
Contributor Author

Just tried to run this on find repo since I have 45 things to stage there and i got

flow migrate stage-contract --all -n testnet
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                           ⚠ Upgrade to Cadence 1.0
     The Crescendo network upgrade, including Cadence 1.0, is coming soon.
     You may need to update your existing contracts to support this change.
                     Please visit our migration guide here:
             https://cadence-lang.org/docs/cadence_migration_guide
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
panic: interface conversion: common.Location is common.IdentifierLocation, not common.AddressLocation

goroutine 1 [running]:
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).parseAndCheckAllStaged.func1({0x104c13e20, 0x140025977a0})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:266 +0x128
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).forEachDependency.func1({0x104c13de0, 0x140024d97e0})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:701 +0xfc
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).forEachDependency.func1({0x104c13de0, 0x14002ac2720})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:702 +0x114
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).forEachDependency(0x14000d477c0, {{{0x140014d0400, 0xb}, {0x3e, 0x5b, 0x4c, 0x62, 0x70, 0x64, 0x62, ...}}, ...}, ...)
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:706 +0xd0
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).parseAndCheckAllStaged(0x14000d477c0)
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:264 +0x1e0
github.com/onflow/flow-cli/internal/migrate.(*stagingValidatorImpl).Validate(0x14000d477c0, {0x14000238608, 0x2e, 0x1?})
	github.com/onflow/flow-cli/internal/migrate/staging_validator.go:178 +0x1a8
github.com/onflow/flow-cli/internal/migrate.(*stagingServiceImpl).validateAndStageContracts(0x14000d47800, {0x104c0eb60, 0x1061543e0}, {0x14000238608, 0x2e, 0x4b})
	github.com/onflow/flow-cli/internal/migrate/staging_service.go:101 +0x11c
github.com/onflow/flow-cli/internal/migrate.(*stagingServiceImpl).StageContracts(0x14000d47800, {0x104c0eb60, 0x1061543e0}, {0x14000c31a00?, 0x2e, 0x0?})
	github.com/onflow/flow-cli/internal/migrate/staging_service.go:92 +0x80
github.com/onflow/flow-cli/internal/migrate.stageAll({0x104c000f0, 0x14000d47800}, 0x14000fbcf30, {0x104c359d8?, 0x14000d171a0?})
	github.com/onflow/flow-cli/internal/migrate/stage_contract.go:135 +0xbc
github.com/onflow/flow-cli/internal/migrate.stageContract({0x14000d4b410, 0x0, 0x3}, {{0x0, 0x0}, {0x103ebd395, 0x4}, {0x0, 0x0}, {0x0, ...}, ...}, ...)
	github.com/onflow/flow-cli/internal/migrate/stage_contract.go:92 +0x3cc
github.com/onflow/flow-cli/internal/command.Command.AddToParent.func1(0x14000d51100?, {0x14000d4b410, 0x0, 0x3})
	github.com/onflow/flow-cli/internal/command/command.go:142 +0x4cc
github.com/spf13/cobra.(*Command).execute(0x105fbd4a0, {0x140001b8150, 0x3, 0x3})
	github.com/spf13/cobra@v1.8.0/command.go:987 +0x828
github.com/spf13/cobra.(*Command).ExecuteC(0x1400055d808)
	github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
	github.com/onflow/flow-cli/cmd/flow/main.go:168 +0xd9c

Awesome, thank you so much for doing this. Looks like an easy fix, glad we could catch it before it became an issue 🙏

@bjartek

bjartek commented May 14, 2024

Copy link
Copy Markdown
Collaborator

this is the output now

 flow-ms migrate stage-contract --all -n testnet
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                           ⚠ Upgrade to Cadence 1.0
     The Crescendo network upgrade, including Cadence 1.0, is coming soon.
     You may need to update your existing contracts to support this change.
                     Please visit our migration guide here:
             https://cadence-lang.org/docs/cadence_migration_guide
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
❌ Preliminary validation could not be performed on the following contracts:
  - 35717efbbce11c74.FindMarketDirectOfferEscrow
  - 3e5b4c627064625d.PartyFavorz
  - 35717efbbce11c74.FindLeaseMarketAuctionSoft
  - 35717efbbce11c74.FindMarketAuctionSoft
  - 35717efbbce11c74.FindLeaseMarketSale
  - 35717efbbce11c74.Dandy
  - 35717efbbce11c74.FindForgeOrder
  - 35717efbbce11c74.FindFurnace
  - 35717efbbce11c74.FindMarketDirectOfferSoft
  - 35717efbbce11c74.FindForge
  - 35717efbbce11c74.FindMarketSale
  - 35717efbbce11c74.FindLeaseMarketDirectOfferSoft
  - 35717efbbce11c74.FindThoughts
  - 3e5b4c627064625d.NFGv3
  - 35717efbbce11c74.FindLeaseMarket
  - 35717efbbce11c74.FindVerifier
  - 35717efbbce11c74.FindMarketAuctionEscrow
  - 35717efbbce11c74.FindLostAndFoundWrapper
  - 35717efbbce11c74.FIND
  - 35717efbbce11c74.FindMarketAdmin
  - 35717efbbce11c74.Admin
  - 35717efbbce11c74.FindAirdropper
  - 35717efbbce11c74.NameVoucher
  - 3e5b4c627064625d.Flomies
  - 35717efbbce11c74.FindPack
  - 3e5b4c627064625d.GeneratedExperiences

These contracts depend on the following contracts which have not been staged yet:
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT

You may still stage your contract, however it will be unable to be migrated until the missing contracts are staged by their respective owners.  It is important to monitor the status of your contract using the `flow migrate is-validated` command


should we sort and unique the dependent contracts maybe?

@jribbink

jribbink commented May 14, 2024

Copy link
Copy Markdown
Contributor Author

this is the output now

 flow-ms migrate stage-contract --all -n testnet
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                           ⚠ Upgrade to Cadence 1.0
     The Crescendo network upgrade, including Cadence 1.0, is coming soon.
     You may need to update your existing contracts to support this change.
                     Please visit our migration guide here:
             https://cadence-lang.org/docs/cadence_migration_guide
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
❌ Preliminary validation could not be performed on the following contracts:
  - 35717efbbce11c74.FindMarketDirectOfferEscrow
  - 3e5b4c627064625d.PartyFavorz
  - 35717efbbce11c74.FindLeaseMarketAuctionSoft
  - 35717efbbce11c74.FindMarketAuctionSoft
  - 35717efbbce11c74.FindLeaseMarketSale
  - 35717efbbce11c74.Dandy
  - 35717efbbce11c74.FindForgeOrder
  - 35717efbbce11c74.FindFurnace
  - 35717efbbce11c74.FindMarketDirectOfferSoft
  - 35717efbbce11c74.FindForge
  - 35717efbbce11c74.FindMarketSale
  - 35717efbbce11c74.FindLeaseMarketDirectOfferSoft
  - 35717efbbce11c74.FindThoughts
  - 3e5b4c627064625d.NFGv3
  - 35717efbbce11c74.FindLeaseMarket
  - 35717efbbce11c74.FindVerifier
  - 35717efbbce11c74.FindMarketAuctionEscrow
  - 35717efbbce11c74.FindLostAndFoundWrapper
  - 35717efbbce11c74.FIND
  - 35717efbbce11c74.FindMarketAdmin
  - 35717efbbce11c74.Admin
  - 35717efbbce11c74.FindAirdropper
  - 35717efbbce11c74.NameVoucher
  - 3e5b4c627064625d.Flomies
  - 35717efbbce11c74.FindPack
  - 3e5b4c627064625d.GeneratedExperiences

These contracts depend on the following contracts which have not been staged yet:
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - a983fecbed621163.FiatToken
  - 0afe396ebc8eee65.FLOAT

You may still stage your contract, however it will be unable to be migrated until the missing contracts are staged by their respective owners.  It is important to monitor the status of your contract using the `flow migrate is-validated` command

should we sort and unique the dependent contracts maybe?

Yeah 💯 (I was also planning not to stage contracts if the staged code hasn't changed, just have not added yet)

@bjartek

bjartek commented May 14, 2024

Copy link
Copy Markdown
Collaborator

It did work though, but it stages each contract in a single transaction. Each tx takes about 300 gas so you should be able to do loads of them in one go if you want to.

The command took 5 minutes to run for me :p

@jribbink

Copy link
Copy Markdown
Contributor Author

It did work though, but it stages each contract in a single transaction. Each tx takes about 300 gas so you should be able to do loads of them in one go if you want to.

The command took 5 minutes to run for me :p

Awesome!! Super appreciative that you could run this, it really helps because my manual + unit tests can only go so far... lots of edge cases in this one.

Yeah, doing this in separate transactions is somewhat intentional. I didn't want to run into any headaches related to computation limits, so it seemed more reliable to just stick to individual TX than try to estimate computation & potentially introduce bugs (and since this is what flow project deploy does as well anyways).

I know waiting 5 minutes for the command to run isn't a great experience, but hopefully I can really shave that down by not sending unnecessary TX.

@bjartek

bjartek commented May 14, 2024

Copy link
Copy Markdown
Collaborator

Fair enough. I dont expect to run it that many times

Comment thread internal/migrate/staging_service.go
Comment thread internal/migrate/get_staged_code.go
@jribbink jribbink merged commit 2f95230 into feature/stable-cadence May 15, 2024
@jribbink jribbink deleted the jribbink/stage-all branch May 15, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Improvement Technical work without new features, refactoring, improving tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to stage all contracts

4 participants