From ba2e543bc4a76cf204fd690e0d21310c19e113eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 13 Feb 2024 14:14:16 -0800 Subject: [PATCH 01/18] add support for localnet --- cmd/util/ledger/migrations/change_contract_code_migration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/util/ledger/migrations/change_contract_code_migration.go b/cmd/util/ledger/migrations/change_contract_code_migration.go index 0c7021a3c57..cce577c266f 100644 --- a/cmd/util/ledger/migrations/change_contract_code_migration.go +++ b/cmd/util/ledger/migrations/change_contract_code_migration.go @@ -199,7 +199,7 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp stakingCollectionAddress = mustHexAddress("0x95e019a17d0e23d7") stakingProxyAddress = mustHexAddress("0x7aad92e5a0715d21") - case flow.Emulator: + case flow.Emulator, flow.Localnet: stakingCollectionAddress = common.Address(systemContracts.FlowServiceAccount.Address) stakingProxyAddress = common.Address(systemContracts.FlowServiceAccount.Address) From 47f788f53abc8687579bd22aa646d70618a0ad39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 13 Feb 2024 15:41:57 -0800 Subject: [PATCH 02/18] do not update FT switchboard on localnet --- .../ledger/migrations/change_contract_code_migration.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/util/ledger/migrations/change_contract_code_migration.go b/cmd/util/ledger/migrations/change_contract_code_migration.go index cce577c266f..0c38459fc2e 100644 --- a/cmd/util/ledger/migrations/change_contract_code_migration.go +++ b/cmd/util/ledger/migrations/change_contract_code_migration.go @@ -358,7 +358,11 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp ), } - if chainID != flow.Emulator { + switch chainID { + case flow.Emulator, flow.Localnet: + // skip + + default: contractChanges = append( contractChanges, SystemContractChange{ From f1f58e6881298254361fc5ec5342e4cddad3db73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 13 Feb 2024 15:55:49 -0800 Subject: [PATCH 03/18] update Cadence --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f0169c9fd46..610edc5660a 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multihash v0.2.3 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f - github.com/onflow/cadence v1.0.0-M6 + github.com/onflow/cadence v1.0.0-preview.2.0.20240213230739-27d2386c0cab github.com/onflow/crypto v0.25.0 github.com/onflow/flow v0.3.4 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 diff --git a/go.sum b/go.sum index 74cfefcacda..e5e591f0ce4 100644 --- a/go.sum +++ b/go.sum @@ -2476,8 +2476,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-M6 h1:3Y5xFrmOGMCAaHKNjEwCbnDFlkwZHDzeOtrcX9beWMA= -github.com/onflow/cadence v1.0.0-M6/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240213230739-27d2386c0cab h1:6AxBNV03Ip29tcsJye7uuk4mXEFWH6HPyCE7avP6Zcw= +github.com/onflow/cadence v1.0.0-preview.2.0.20240213230739-27d2386c0cab/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE= From 3e3b847cb18cc3b859e183c765a9249a533d8e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 13 Feb 2024 16:00:45 -0800 Subject: [PATCH 04/18] fix static binary --- cmd/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/Dockerfile b/cmd/Dockerfile index 78b24a4a051..b9629636326 100644 --- a/cmd/Dockerfile +++ b/cmd/Dockerfile @@ -37,7 +37,7 @@ WORKDIR /app ARG GOARCH=amd64 # TAGS can be overriden to modify the go build tags (e.g. build without netgo) -ARG TAGS="netgo" +ARG TAGS="netgo,osusergo" # CC flag can be overwritten to specify a C compiler ARG CC="" # CGO_FLAG uses ADX instructions by default, flag can be overwritten to build without ADX From 3684bcc973c27cfa395a8c296075f447ebfe9632 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Wed, 14 Feb 2024 10:15:35 +0530 Subject: [PATCH 05/18] Assert FlowToken.Vault migration in tests --- .../cadence_values_migration_test.go | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/cmd/util/ledger/migrations/cadence_values_migration_test.go b/cmd/util/ledger/migrations/cadence_values_migration_test.go index d3021bb4113..dbd8a479e6d 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration_test.go +++ b/cmd/util/ledger/migrations/cadence_values_migration_test.go @@ -105,6 +105,11 @@ func TestCadenceValuesMigration(t *testing.T) { // TODO: //func TestCadenceValuesMigrationWithSwappedOrder(t *testing.T) { +var flowTokenAddress = func() common.Address { + address, _ := common.HexToAddress("0ae53cb6e3f42a79") + return address +}() + func checkMigratedPayloads( t *testing.T, address common.Address, @@ -131,10 +136,6 @@ func checkMigratedPayloads( var values []interpreter.Value for key, value := iterator.Next(); key != nil; key, value = iterator.Next() { - identifier := string(key.(interpreter.StringAtreeValue)) - if identifier == "flowTokenVault" || identifier == "flowTokenReceiver" { - continue - } values = append(values, value) } @@ -144,6 +145,12 @@ func checkMigratedPayloads( "Test", ) + flowTokenLocation := common.NewAddressLocation( + nil, + flowTokenAddress, + "FlowToken", + ) + fooInterfaceType := interpreter.NewInterfaceStaticTypeComputeTypeID( nil, testContractLocation, @@ -318,6 +325,25 @@ func checkMigratedPayloads( ), interpreter.NewUnmeteredStringValue("auth_ref"), ), + + interpreter.NewCompositeValue( + mr.Interpreter, + interpreter.EmptyLocationRange, + flowTokenLocation, + "FlowToken.Vault", + common.CompositeKindResource, + []interpreter.CompositeField{ + { + Value: interpreter.NewUnmeteredUFix64Value(0.001 * sema.Fix64Factor), + Name: "balance", + }, + { + Value: interpreter.NewUnmeteredUInt64Value(12321848580485677058), + Name: "uuid", + }, + }, + address, + ), } require.Equal(t, len(expectedValues), len(values)) From 513285a67ca65bb582fdb330616cbad4dcca1bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 14 Feb 2024 09:55:12 -0800 Subject: [PATCH 06/18] fix burner contract deployment and imports in updated system contracts --- .../change_contract_code_migration.go | 126 +++++++++++------- .../ledger/migrations/deploy_migration.go | 2 +- 2 files changed, 80 insertions(+), 48 deletions(-) diff --git a/cmd/util/ledger/migrations/change_contract_code_migration.go b/cmd/util/ledger/migrations/change_contract_code_migration.go index 0c38459fc2e..5fa57a881ef 100644 --- a/cmd/util/ledger/migrations/change_contract_code_migration.go +++ b/cmd/util/ledger/migrations/change_contract_code_migration.go @@ -185,10 +185,44 @@ type SystemContractChangesOptions struct { EVM EVMContractChange } +func BurnerAddressForChain(chainID flow.ChainID) flow.Address { + + systemContracts := systemcontracts.SystemContractsForChain(chainID) + serviceAccountAddress := systemContracts.FlowServiceAccount.Address + fungibleTokenAddress := systemContracts.FungibleToken.Address + + switch chainID { + case flow.Mainnet, flow.Testnet: + return fungibleTokenAddress + + case flow.Emulator, flow.Localnet: + return serviceAccountAddress + + default: + panic(fmt.Errorf("unsupported chain ID: %s", chainID)) + } +} + func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOptions) []SystemContractChange { systemContracts := systemcontracts.SystemContractsForChain(chainID) - var stakingCollectionAddress, stakingProxyAddress common.Address + serviceAccountAddress := systemContracts.FlowServiceAccount.Address + idTableStakingAddress := systemContracts.IDTableStaking.Address + clusterQCAddress := systemContracts.ClusterQC.Address + dkgAddress := systemContracts.DKG.Address + fungibleTokenAddress := systemContracts.FungibleToken.Address + flowTokenAddress := systemContracts.FlowToken.Address + flowFeesAddress := systemContracts.FlowFees.Address + flowStorageFeesAddress := systemContracts.FlowStorageFees.Address + viewResolverAddress := systemContracts.ViewResolver.Address + metadataViewsAddress := systemContracts.MetadataViews.Address + fungibleTokenMetadataViewsAddress := common.Address(fungibleTokenAddress) + fungibleTokenSwitchboardAddress := common.Address(fungibleTokenAddress) + + burnerAddress := BurnerAddressForChain(chainID) + + var stakingCollectionAddress common.Address + var stakingProxyAddress common.Address switch chainID { case flow.Mainnet: @@ -200,37 +234,35 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp stakingProxyAddress = mustHexAddress("0x7aad92e5a0715d21") case flow.Emulator, flow.Localnet: - stakingCollectionAddress = common.Address(systemContracts.FlowServiceAccount.Address) - stakingProxyAddress = common.Address(systemContracts.FlowServiceAccount.Address) + stakingCollectionAddress = common.Address(serviceAccountAddress) + stakingProxyAddress = common.Address(serviceAccountAddress) default: panic(fmt.Errorf("unsupported chain ID: %s", chainID)) } lockedTokensAddress := stakingCollectionAddress - fungibleTokenMetadataViewsAddress := common.Address(systemContracts.FungibleToken.Address) - fungibleTokenSwitchboardAddress := common.Address(systemContracts.FungibleToken.Address) contractChanges := []SystemContractChange{ // epoch related contracts NewSystemContractChange( systemContracts.Epoch, coreContracts.FlowEpoch( - systemContracts.FungibleToken.Address.HexWithPrefix(), - systemContracts.FlowToken.Address.HexWithPrefix(), - systemContracts.IDTableStaking.Address.HexWithPrefix(), - systemContracts.ClusterQC.Address.HexWithPrefix(), - systemContracts.DKG.Address.HexWithPrefix(), - systemContracts.FlowFees.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), + flowTokenAddress.HexWithPrefix(), + idTableStakingAddress.HexWithPrefix(), + clusterQCAddress.HexWithPrefix(), + dkgAddress.HexWithPrefix(), + flowFeesAddress.HexWithPrefix(), ), ), NewSystemContractChange( systemContracts.IDTableStaking, coreContracts.FlowIDTableStaking( - systemContracts.FungibleToken.Address.HexWithPrefix(), - systemContracts.FlowToken.Address.HexWithPrefix(), - systemContracts.FlowFees.Address.HexWithPrefix(), - systemContracts.FlowServiceAccount.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), + flowTokenAddress.HexWithPrefix(), + flowFeesAddress.HexWithPrefix(), + burnerAddress.HexWithPrefix(), true, ), ), @@ -247,10 +279,10 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp NewSystemContractChange( systemContracts.FlowServiceAccount, coreContracts.FlowServiceAccount( - systemContracts.FungibleToken.Address.HexWithPrefix(), - systemContracts.FlowToken.Address.HexWithPrefix(), - systemContracts.FlowFees.Address.HexWithPrefix(), - systemContracts.FlowStorageFees.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), + flowTokenAddress.HexWithPrefix(), + flowFeesAddress.HexWithPrefix(), + flowStorageFeesAddress.HexWithPrefix(), ), ), NewSystemContractChange( @@ -264,22 +296,22 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp NewSystemContractChange( systemContracts.FlowStorageFees, coreContracts.FlowStorageFees( - systemContracts.FungibleToken.Address.HexWithPrefix(), - systemContracts.FlowToken.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), + flowTokenAddress.HexWithPrefix(), ), ), { Address: stakingCollectionAddress, ContractName: "FlowStakingCollection", NewContractCode: string(coreContracts.FlowStakingCollection( - systemContracts.FungibleToken.Address.HexWithPrefix(), - systemContracts.FlowToken.Address.HexWithPrefix(), - systemContracts.IDTableStaking.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), + flowTokenAddress.HexWithPrefix(), + idTableStakingAddress.HexWithPrefix(), stakingProxyAddress.HexWithPrefix(), lockedTokensAddress.HexWithPrefix(), - systemContracts.FlowStorageFees.Address.HexWithPrefix(), - systemContracts.ClusterQC.Address.HexWithPrefix(), - systemContracts.DKG.Address.HexWithPrefix(), + flowStorageFeesAddress.HexWithPrefix(), + clusterQCAddress.HexWithPrefix(), + dkgAddress.HexWithPrefix(), systemContracts.Epoch.Address.HexWithPrefix(), )), }, @@ -292,11 +324,11 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp Address: lockedTokensAddress, ContractName: "LockedTokens", NewContractCode: string(coreContracts.FlowLockedTokens( - systemContracts.FungibleToken.Address.HexWithPrefix(), - systemContracts.FlowToken.Address.HexWithPrefix(), - systemContracts.IDTableStaking.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), + flowTokenAddress.HexWithPrefix(), + idTableStakingAddress.HexWithPrefix(), stakingProxyAddress.HexWithPrefix(), - systemContracts.FlowStorageFees.Address.HexWithPrefix(), + flowStorageFeesAddress.HexWithPrefix(), )), }, @@ -304,26 +336,26 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp NewSystemContractChange( systemContracts.FlowFees, coreContracts.FlowFees( - systemContracts.FungibleToken.Address.HexWithPrefix(), - systemContracts.FlowToken.Address.HexWithPrefix(), - systemContracts.FlowStorageFees.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), + flowTokenAddress.HexWithPrefix(), + flowStorageFeesAddress.HexWithPrefix(), ), ), NewSystemContractChange( systemContracts.FlowToken, coreContracts.FlowToken( - systemContracts.FungibleToken.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), fungibleTokenMetadataViewsAddress.HexWithPrefix(), - systemContracts.MetadataViews.Address.HexWithPrefix(), - systemContracts.ViewResolver.Address.HexWithPrefix(), + metadataViewsAddress.HexWithPrefix(), + burnerAddress.HexWithPrefix(), ), ), NewSystemContractChange( systemContracts.FungibleToken, ftContracts.FungibleToken( // Use `Hex()`, since this method adds the prefix. - systemContracts.ViewResolver.Address.Hex(), - systemContracts.FlowServiceAccount.Address.Hex(), + viewResolverAddress.Hex(), + burnerAddress.Hex(), ), ), { @@ -331,9 +363,9 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp ContractName: "FungibleTokenMetadataViews", NewContractCode: string(ftContracts.FungibleTokenMetadataViews( // Use `Hex()`, since this method adds the prefix. - systemContracts.FungibleToken.Address.Hex(), - systemContracts.MetadataViews.Address.Hex(), - systemContracts.ViewResolver.Address.Hex(), + fungibleTokenAddress.Hex(), + metadataViewsAddress.Hex(), + viewResolverAddress.Hex(), )), }, @@ -341,15 +373,15 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp NewSystemContractChange( systemContracts.NonFungibleToken, nftContracts.NonFungibleToken( - sdk.Address(systemContracts.ViewResolver.Address), + sdk.Address(viewResolverAddress), ), ), NewSystemContractChange( systemContracts.MetadataViews, nftContracts.MetadataViews( - sdk.Address(systemContracts.FungibleToken.Address), + sdk.Address(fungibleTokenAddress), sdk.Address(systemContracts.NonFungibleToken.Address), - sdk.Address(systemContracts.ViewResolver.Address), + sdk.Address(viewResolverAddress), ), ), NewSystemContractChange( @@ -369,7 +401,7 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp Address: fungibleTokenSwitchboardAddress, ContractName: "FungibleTokenSwitchboard", NewContractCode: string(ftContracts.FungibleTokenSwitchboard( - systemContracts.FungibleToken.Address.HexWithPrefix(), + fungibleTokenAddress.HexWithPrefix(), )), }, ) @@ -386,7 +418,7 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOp NewSystemContractChange( systemContracts.EVMContract, evm.ContractCode( - systemContracts.FlowToken.Address, + flowTokenAddress, abiOnly, ), ), diff --git a/cmd/util/ledger/migrations/deploy_migration.go b/cmd/util/ledger/migrations/deploy_migration.go index f0c5e3dab74..e68de9ce746 100644 --- a/cmd/util/ledger/migrations/deploy_migration.go +++ b/cmd/util/ledger/migrations/deploy_migration.go @@ -93,7 +93,7 @@ func NewBurnerDeploymentMigration( Name: "Burner", Code: coreContracts.Burner(), }, - chainID.Chain().ServiceAddress(), + BurnerAddressForChain(chainID), logger, ) } From 4a88ae394adf30cbb78b5bb81aa9b3ae790dcecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 14 Feb 2024 17:03:49 -0800 Subject: [PATCH 07/18] update Cadence --- go.mod | 2 +- go.sum | 4 ++-- insecure/go.mod | 2 +- insecure/go.sum | 4 ++-- integration/go.mod | 2 +- integration/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 26193f082ce..73c387929f5 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multihash v0.2.3 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f - github.com/onflow/cadence v1.0.0-M7 + github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 github.com/onflow/crypto v0.25.0 github.com/onflow/flow v0.3.4 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 diff --git a/go.sum b/go.sum index 8084693a6cb..bd73ed48214 100644 --- a/go.sum +++ b/go.sum @@ -2476,8 +2476,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-M7 h1:hb4LK9lUbFdnDdfU8oqJGSVJtmkOzxwKomhmDcP/Faw= -github.com/onflow/cadence v1.0.0-M7/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 h1:lSRrQc5V/WS9pKQgK7f+sHwhWfZB9Ez4tnkYA2i9Yrc= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE= diff --git a/insecure/go.mod b/insecure/go.mod index ff070d86b90..5c20f64b160 100644 --- a/insecure/go.mod +++ b/insecure/go.mod @@ -205,7 +205,7 @@ require ( github.com/multiformats/go-varint v0.0.7 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f // indirect - github.com/onflow/cadence v1.0.0-M7 // indirect + github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 // indirect github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 // indirect github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7 // indirect github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240205224107-320aa3cf09e0 // indirect diff --git a/insecure/go.sum b/insecure/go.sum index d225043978f..6948971fdfe 100644 --- a/insecure/go.sum +++ b/insecure/go.sum @@ -2463,8 +2463,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-M7 h1:hb4LK9lUbFdnDdfU8oqJGSVJtmkOzxwKomhmDcP/Faw= -github.com/onflow/cadence v1.0.0-M7/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 h1:lSRrQc5V/WS9pKQgK7f+sHwhWfZB9Ez4tnkYA2i9Yrc= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 h1:OI/4F2NK/X/4x3dTUFFDGtuOsSa9pX+jjBeSEcBrY/M= diff --git a/integration/go.mod b/integration/go.mod index e17e05f3b22..1957f43e259 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -19,7 +19,7 @@ require ( github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-ds-badger2 v0.1.3 github.com/ipfs/go-ipfs-blockstore v1.3.0 - github.com/onflow/cadence v1.0.0-M7 + github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 github.com/onflow/crypto v0.25.0 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7 diff --git a/integration/go.sum b/integration/go.sum index f093d64506a..0574605c032 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -2538,8 +2538,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-M7 h1:hb4LK9lUbFdnDdfU8oqJGSVJtmkOzxwKomhmDcP/Faw= -github.com/onflow/cadence v1.0.0-M7/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 h1:lSRrQc5V/WS9pKQgK7f+sHwhWfZB9Ez4tnkYA2i9Yrc= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 h1:OI/4F2NK/X/4x3dTUFFDGtuOsSa9pX+jjBeSEcBrY/M= From 7fa4b7d36f59a06b78455e0190d4f876e278e360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 14 Feb 2024 17:41:36 -0800 Subject: [PATCH 08/18] add TODO --- cmd/util/ledger/migrations/staged_contracts_migration.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/util/ledger/migrations/staged_contracts_migration.go b/cmd/util/ledger/migrations/staged_contracts_migration.go index 29e779901e1..b95c8b3f245 100644 --- a/cmd/util/ledger/migrations/staged_contracts_migration.go +++ b/cmd/util/ledger/migrations/staged_contracts_migration.go @@ -146,6 +146,7 @@ func (m *StagedContractsMigration) MigrateAccount( config := util.RuntimeInterfaceConfig{ GetContractCodeFunc: func(location runtime.Location) ([]byte, error) { + // TODO: also consider updated system contracts return m.contractsByLocation[location], nil }, } From 5f79437f1a48b573bab8d43027a34ea91dff2390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 14 Feb 2024 17:43:23 -0800 Subject: [PATCH 09/18] remove unused/unnecessary GetOrLoadProgramFunc field --- cmd/util/ledger/util/migration_runtime_interface.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cmd/util/ledger/util/migration_runtime_interface.go b/cmd/util/ledger/util/migration_runtime_interface.go index 67291c2dba1..e08f048afc2 100644 --- a/cmd/util/ledger/util/migration_runtime_interface.go +++ b/cmd/util/ledger/util/migration_runtime_interface.go @@ -118,10 +118,6 @@ func (m MigrationRuntimeInterface) GetOrLoadProgram( location runtime.Location, load func() (*interpreter.Program, error), ) (*interpreter.Program, error) { - if m.GetOrLoadProgramFunc != nil { - return m.GetOrLoadProgramFunc(location, load) - } - return m.Programs.GetOrLoadProgram(location, load) } @@ -306,9 +302,6 @@ func (m MigrationRuntimeInterface) RecordTrace(_ string, _ runtime.Location, _ t } type RuntimeInterfaceConfig struct { - // GetOrLoadProgramFunc allows for injecting extra logic - GetOrLoadProgramFunc func(location runtime.Location, load func() (*interpreter.Program, error)) (*interpreter.Program, error) - // GetContractCodeFunc allows for injecting extra logic for code lookup GetContractCodeFunc func(location runtime.Location) ([]byte, error) } From 99af973353f3b25b921f19f9e279114c52bfaf74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 14 Feb 2024 18:49:15 -0800 Subject: [PATCH 10/18] update to latest fixed Cadence --- go.mod | 2 +- go.sum | 4 ++-- insecure/go.mod | 2 +- insecure/go.sum | 4 ++-- integration/go.mod | 2 +- integration/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 73c387929f5..a9ce359cd22 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multihash v0.2.3 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f - github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 + github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 github.com/onflow/crypto v0.25.0 github.com/onflow/flow v0.3.4 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 diff --git a/go.sum b/go.sum index bd73ed48214..06c951d90d3 100644 --- a/go.sum +++ b/go.sum @@ -2476,8 +2476,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 h1:lSRrQc5V/WS9pKQgK7f+sHwhWfZB9Ez4tnkYA2i9Yrc= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 h1:YoAg14oa60fDPdk+PdhhBJKCQfYTS9Z5m5b4IYBpH8k= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE= diff --git a/insecure/go.mod b/insecure/go.mod index 5c20f64b160..217feb3b39c 100644 --- a/insecure/go.mod +++ b/insecure/go.mod @@ -205,7 +205,7 @@ require ( github.com/multiformats/go-varint v0.0.7 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f // indirect - github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 // indirect + github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 // indirect github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 // indirect github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7 // indirect github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240205224107-320aa3cf09e0 // indirect diff --git a/insecure/go.sum b/insecure/go.sum index 6948971fdfe..0a2ff8176cb 100644 --- a/insecure/go.sum +++ b/insecure/go.sum @@ -2463,8 +2463,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 h1:lSRrQc5V/WS9pKQgK7f+sHwhWfZB9Ez4tnkYA2i9Yrc= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 h1:YoAg14oa60fDPdk+PdhhBJKCQfYTS9Z5m5b4IYBpH8k= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 h1:OI/4F2NK/X/4x3dTUFFDGtuOsSa9pX+jjBeSEcBrY/M= diff --git a/integration/go.mod b/integration/go.mod index 1957f43e259..4129960fb4d 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -19,7 +19,7 @@ require ( github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-ds-badger2 v0.1.3 github.com/ipfs/go-ipfs-blockstore v1.3.0 - github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 + github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 github.com/onflow/crypto v0.25.0 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7 diff --git a/integration/go.sum b/integration/go.sum index 0574605c032..95c1fa5f876 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -2538,8 +2538,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568 h1:lSRrQc5V/WS9pKQgK7f+sHwhWfZB9Ez4tnkYA2i9Yrc= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215010111-60d9f29f7568/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 h1:YoAg14oa60fDPdk+PdhhBJKCQfYTS9Z5m5b4IYBpH8k= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 h1:OI/4F2NK/X/4x3dTUFFDGtuOsSa9pX+jjBeSEcBrY/M= From 7e09edd6f413008833cc334d594c009410137aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 14 Feb 2024 19:48:39 -0800 Subject: [PATCH 11/18] generate contract map from all payloads instead of full payload snapshot --- .../migrations/cadence_values_migration.go | 60 +++++++++++++------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/cmd/util/ledger/migrations/cadence_values_migration.go b/cmd/util/ledger/migrations/cadence_values_migration.go index b8d68268fa6..55abdacd163 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration.go +++ b/cmd/util/ledger/migrations/cadence_values_migration.go @@ -21,6 +21,7 @@ import ( "github.com/onflow/flow-go/fvm/environment" "github.com/onflow/flow-go/fvm/tracing" "github.com/onflow/flow-go/ledger" + "github.com/onflow/flow-go/ledger/common/convert" "github.com/onflow/flow-go/model/flow" ) @@ -55,33 +56,58 @@ func (m *CadenceBaseMigrator) InitMigration( // The MigrateAccount function is only given the payloads for the account to be migrated. // However, the migration needs to be able to get the code for contracts of any account. - fullPayloadSnapshot, err := util.NewPayloadSnapshot(allPayloads) + contracts, err := getContractMap(allPayloads) if err != nil { return err } - m.runtimeInterfaceConfig = util.RuntimeInterfaceConfig{ + m.runtimeInterfaceConfig.GetContractCodeFunc = func(location runtime.Location) ([]byte, error) { + addressLocation, ok := location.(common.AddressLocation) + if !ok { + return nil, nil + } - GetContractCodeFunc: func(location runtime.Location) ([]byte, error) { - addressLocation, ok := location.(common.AddressLocation) - if !ok { - return nil, nil - } - contractRegisterID := flow.ContractRegisterID( - flow.Address(addressLocation.Address), - addressLocation.Name, - ) - contract, err := fullPayloadSnapshot.Get(contractRegisterID) - if err != nil { - return nil, fmt.Errorf("failed to get contract code: %w", err) - } - return contract, nil - }, + contract, ok := contracts[addressLocation] + if !ok { + return nil, fmt.Errorf("failed to get contract code for location %s", location) + } + + return contract, nil } return nil } +func getContractMap(allPayloads []*ledger.Payload) (map[common.AddressLocation][]byte, error) { + contracts := make(map[common.AddressLocation][]byte) + + for _, payload := range allPayloads { + registerID, registerValue, err := convert.PayloadToRegister(payload) + if err != nil { + return nil, fmt.Errorf("failed to convert payload to register: %w", err) + } + + contractName := flow.RegisterIDContractName(registerID) + if contractName == "" { + continue + } + + address, err := common.BytesToAddress([]byte(registerID.Owner)) + if err != nil { + return nil, fmt.Errorf("failed to convert register owner to address: %w", err) + } + + addressLocation := common.AddressLocation{ + Address: address, + Name: contractName, + } + + contracts[addressLocation] = registerValue + } + + return contracts, nil +} + func (m *CadenceBaseMigrator) MigrateAccount( _ context.Context, address common.Address, From 5e8b0d95d8eebf7787cb225153f6b1b02325d8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 15 Feb 2024 17:26:11 -0800 Subject: [PATCH 12/18] update Cadence --- go.mod | 2 +- go.sum | 4 ++-- insecure/go.mod | 2 +- insecure/go.sum | 4 ++-- integration/go.mod | 2 +- integration/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index a9ce359cd22..eeedbf6e929 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multihash v0.2.3 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f - github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 + github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1 github.com/onflow/crypto v0.25.0 github.com/onflow/flow v0.3.4 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 diff --git a/go.sum b/go.sum index 06c951d90d3..213a84f750b 100644 --- a/go.sum +++ b/go.sum @@ -2476,8 +2476,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 h1:YoAg14oa60fDPdk+PdhhBJKCQfYTS9Z5m5b4IYBpH8k= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1 h1:bOki/dmy1wSz0/IbJXo3reDkVo9JUrFmvVzv9RrfBv0= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE= diff --git a/insecure/go.mod b/insecure/go.mod index 217feb3b39c..b122d7588a3 100644 --- a/insecure/go.mod +++ b/insecure/go.mod @@ -205,7 +205,7 @@ require ( github.com/multiformats/go-varint v0.0.7 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f // indirect - github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 // indirect + github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1 // indirect github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 // indirect github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7 // indirect github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240205224107-320aa3cf09e0 // indirect diff --git a/insecure/go.sum b/insecure/go.sum index 0a2ff8176cb..a6b08ddf59c 100644 --- a/insecure/go.sum +++ b/insecure/go.sum @@ -2463,8 +2463,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 h1:YoAg14oa60fDPdk+PdhhBJKCQfYTS9Z5m5b4IYBpH8k= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1 h1:bOki/dmy1wSz0/IbJXo3reDkVo9JUrFmvVzv9RrfBv0= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 h1:OI/4F2NK/X/4x3dTUFFDGtuOsSa9pX+jjBeSEcBrY/M= diff --git a/integration/go.mod b/integration/go.mod index 4129960fb4d..329ee0f3618 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -19,7 +19,7 @@ require ( github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-ds-badger2 v0.1.3 github.com/ipfs/go-ipfs-blockstore v1.3.0 - github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 + github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1 github.com/onflow/crypto v0.25.0 github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240206003101-928bf99024d7 diff --git a/integration/go.sum b/integration/go.sum index 95c1fa5f876..f1ee112f0fe 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -2538,8 +2538,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91 h1:YoAg14oa60fDPdk+PdhhBJKCQfYTS9Z5m5b4IYBpH8k= -github.com/onflow/cadence v1.0.0-preview.2.0.20240215024233-4dc882e61d91/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1 h1:bOki/dmy1wSz0/IbJXo3reDkVo9JUrFmvVzv9RrfBv0= +github.com/onflow/cadence v1.0.0-preview.2.0.20240215231353-cab2c8a091f1/go.mod h1:a4mccDU90hmuxCLUFzs9J/ANG/rYbFa36h4Z0bBAqNU= github.com/onflow/crypto v0.25.0 h1:BeWbLsh3ZD13Ej+Uky6kg1PL1ZIVBDVX+2MVBNwqddg= github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240206003101-928bf99024d7 h1:OI/4F2NK/X/4x3dTUFFDGtuOsSa9pX+jjBeSEcBrY/M= From c19d5b431afd45e5551d7a2449a489a9bfdcbccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 15 Feb 2024 17:26:42 -0800 Subject: [PATCH 13/18] test contract update for missing contract is rejected --- .../cadence_values_migration_test.go | 2 +- .../staged_contracts_migration_test.go | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cmd/util/ledger/migrations/cadence_values_migration_test.go b/cmd/util/ledger/migrations/cadence_values_migration_test.go index dbd8a479e6d..07399b97a53 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration_test.go +++ b/cmd/util/ledger/migrations/cadence_values_migration_test.go @@ -89,7 +89,7 @@ func TestCadenceValuesMigration(t *testing.T) { for _, migration := range migrations { payloads, err = migration(payloads) - require.NoError(t, err) + require.NoError(t, err, "migration failed, logs: %v", logWriter.logs) } // Assert the migrated payloads diff --git a/cmd/util/ledger/migrations/staged_contracts_migration_test.go b/cmd/util/ledger/migrations/staged_contracts_migration_test.go index 54e3dfaaca5..e4b4a7a110f 100644 --- a/cmd/util/ledger/migrations/staged_contracts_migration_test.go +++ b/cmd/util/ledger/migrations/staged_contracts_migration_test.go @@ -327,6 +327,33 @@ func TestStagedContractsMigration(t *testing.T) { require.Len(t, payloads, 1) require.Equal(t, update2, string(payloads[0].Value())) }) + + t.Run("missing old contract", func(t *testing.T) { + t.Parallel() + + newCode := "access(all) contract A { access(all) struct B {} }" + + stagedContracts := []StagedContract{ + { + Contract: Contract{ + Name: "A", + Code: []byte(newCode), + }, + Address: address1, + }, + } + + migration := NewStagedContractsMigration(stagedContracts) + + logWriter := &logWriter{} + log := zerolog.New(logWriter) + err := migration.InitMigration(log, nil, 0) + require.NoError(t, err) + + // NOTE: no payloads + _, err = migration.MigrateAccount(ctx, address1, nil) + require.ErrorContains(t, err, "failed to find all contract registers that need to be changed") + }) } func TestStagedContractsWithImports(t *testing.T) { From 1dbb4bfeeda8f0d9c42d7e348ca73f70240f3707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 15 Feb 2024 18:02:42 -0800 Subject: [PATCH 14/18] only report program loading errors once, omit full message for subsequent occurrences --- .../migrations/cadence_values_migration.go | 31 ++++++++++++++++--- fvm/environment/programs.go | 22 ++++++++++++- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/cmd/util/ledger/migrations/cadence_values_migration.go b/cmd/util/ledger/migrations/cadence_values_migration.go index 55abdacd163..c6cf2d2d54d 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration.go +++ b/cmd/util/ledger/migrations/cadence_values_migration.go @@ -2,6 +2,7 @@ package migrations import ( "context" + "errors" "fmt" "io" @@ -251,8 +252,9 @@ func NewCadence1CapabilityValueMigrator( // cadenceValueMigrationReporter is the reporter for cadence value migrations type cadenceValueMigrationReporter struct { - rw reporters.ReportWriter - log zerolog.Logger + rw reporters.ReportWriter + log zerolog.Logger + reportedProgramLoadingErrors map[common.Location]struct{} } var _ capcons.LinkMigrationReporter = &cadenceValueMigrationReporter{} @@ -261,8 +263,9 @@ var _ migrations.Reporter = &cadenceValueMigrationReporter{} func newValueMigrationReporter(rw reporters.ReportWriter, log zerolog.Logger) *cadenceValueMigrationReporter { return &cadenceValueMigrationReporter{ - rw: rw, - log: log, + rw: rw, + log: log, + reportedProgramLoadingErrors: make(map[common.Location]struct{}), } } @@ -284,13 +287,31 @@ func (t *cadenceValueMigrationReporter) Error( migration string, err error, ) { + var message string + + // Only report program loading errors once, + // omit full error message for subsequent occurrences + + var programLoadingError environment.ProgramLoadingError + if errors.As(err, &programLoadingError) { + location := programLoadingError.Location + if _, ok := t.reportedProgramLoadingErrors[location]; ok { + message = "error getting program" + } + t.reportedProgramLoadingErrors[location] = struct{}{} + } + + if message == "" { + message = err.Error() + } + t.log.Error().Msgf( "failed to run %s in account %s, domain %s, key %s: %s", migration, storageKey.Address, storageKey.Key, storageMapKey, - err, + message, ) } diff --git a/fvm/environment/programs.go b/fvm/environment/programs.go index 85c52a843d9..8ca57cdbd10 100644 --- a/fvm/environment/programs.go +++ b/fvm/environment/programs.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/hashicorp/go-multierror" + "golang.org/x/xerrors" "github.com/onflow/cadence" jsoncdc "github.com/onflow/cadence/encoding/json" @@ -18,6 +19,22 @@ import ( "github.com/onflow/flow-go/module/trace" ) +type ProgramLoadingError struct { + Err error + Location common.Location +} + +func (p ProgramLoadingError) Unwrap() error { + return p.Err +} + +var _ error = ProgramLoadingError{} +var _ xerrors.Wrapper = ProgramLoadingError{} + +func (p ProgramLoadingError) Error() string { + return fmt.Sprintf("error getting program %v: %s", p.Location, p.Err) +} + // Programs manages operations around cadence program parsing. // // Note that cadence guarantees that Get/Set methods are called in a LIFO @@ -126,7 +143,10 @@ func (programs *Programs) getOrLoadAddressProgram( loader, ) if err != nil { - return nil, fmt.Errorf("error getting program %v: %w", location, err) + return nil, ProgramLoadingError{ + Err: err, + Location: location, + } } // Add dependencies to the stack. From 4faf9bf6847c10b8d1c9fd5146ded9ef4fd82085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 15 Feb 2024 18:08:03 -0800 Subject: [PATCH 15/18] go mod tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index eeedbf6e929..92003255cd9 100644 --- a/go.mod +++ b/go.mod @@ -111,6 +111,7 @@ require ( github.com/onflow/wal v0.0.0-20230529184820-bc9f8244608d github.com/slok/go-http-metrics v0.10.0 github.com/sony/gobreaker v0.5.0 + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b google.golang.org/genproto/googleapis/bytestream v0.0.0-20231030173426-d783a09b4405 gopkg.in/yaml.v2 v2.4.0 @@ -311,7 +312,6 @@ require ( golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.13.0 // indirect golang.org/x/term v0.15.0 // indirect - golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gonum.org/v1/gonum v0.13.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect From ae39304f1ee36e596068235c1ff2a64edbb7bbb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 16 Feb 2024 12:49:22 -0800 Subject: [PATCH 16/18] share error message handling, cache program loading errors --- cmd/util/ledger/migrations/cadence.go | 30 +++- .../migrations/cadence_values_migration.go | 90 +++++++---- .../ledger/migrations/migrator_runtime.go | 1 + .../util/migration_runtime_interface.go | 141 +++++++++++------- 4 files changed, 174 insertions(+), 88 deletions(-) diff --git a/cmd/util/ledger/migrations/cadence.go b/cmd/util/ledger/migrations/cadence.go index 837b29dcff4..21ffbce60c2 100644 --- a/cmd/util/ledger/migrations/cadence.go +++ b/cmd/util/ledger/migrations/cadence.go @@ -162,14 +162,25 @@ func NewCadence1ValueMigrations( // used by CadenceCapabilityValueMigrator capabilityIDs := &capcons.CapabilityIDMapping{} + errorMessageHandler := &errorMessageHandler{} + for _, accountBasedMigration := range []AccountBasedMigration{ NewCadence1ValueMigrator( rwf, + errorMessageHandler, NewCadence1CompositeStaticTypeConverter(chainID), NewCadence1InterfaceStaticTypeConverter(chainID), ), - NewCadence1LinkValueMigrator(rwf, capabilityIDs), - NewCadence1CapabilityValueMigrator(rwf, capabilityIDs), + NewCadence1LinkValueMigrator( + rwf, + errorMessageHandler, + capabilityIDs, + ), + NewCadence1CapabilityValueMigrator( + rwf, + errorMessageHandler, + capabilityIDs, + ), } { migrations = append( migrations, @@ -226,7 +237,18 @@ func NewCadence1Migrations( stagedContracts []StagedContract, ) []ledger.Migration { return common.Concat( - NewCadence1ContractsMigrations(log, nWorker, chainID, evmContractChange, stagedContracts), - NewCadence1ValueMigrations(log, rwf, nWorker, chainID), + NewCadence1ContractsMigrations( + log, + nWorker, + chainID, + evmContractChange, + stagedContracts, + ), + NewCadence1ValueMigrations( + log, + rwf, + nWorker, + chainID, + ), ) } diff --git a/cmd/util/ledger/migrations/cadence_values_migration.go b/cmd/util/ledger/migrations/cadence_values_migration.go index c6cf2d2d54d..caf4efc4a50 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration.go +++ b/cmd/util/ledger/migrations/cadence_values_migration.go @@ -2,9 +2,11 @@ package migrations import ( "context" - "errors" "fmt" "io" + "sync" + + "errors" "github.com/onflow/cadence/migrations/statictypes" "github.com/onflow/cadence/runtime" @@ -36,6 +38,7 @@ type CadenceBaseMigrator struct { reporter *cadenceValueMigrationReporter, ) []migrations.ValueMigration runtimeInterfaceConfig util.RuntimeInterfaceConfig + errorMessageHandler *errorMessageHandler } var _ AccountBasedMigration = (*CadenceBaseMigrator)(nil) @@ -131,7 +134,7 @@ func (m *CadenceBaseMigrator) MigrateAccount( migrationRuntime.Storage, ) - reporter := newValueMigrationReporter(m.reporter, m.log) + reporter := newValueMigrationReporter(m.reporter, m.log, m.errorMessageHandler) m.log.Info().Msg("Migrating cadence values") @@ -171,6 +174,7 @@ func (m *CadenceBaseMigrator) MigrateAccount( // which runs some of the Cadence value migrations (static types, entitlements, strings) func NewCadence1ValueMigrator( rwf reporters.ReportWriterFactory, + errorMessageHandler *errorMessageHandler, compositeTypeConverter statictypes.CompositeTypeConverterFunc, interfaceTypeConverter statictypes.InterfaceTypeConverterFunc, ) *CadenceBaseMigrator { @@ -190,6 +194,7 @@ func NewCadence1ValueMigrator( string_normalization.NewStringNormalizingMigration(), } }, + errorMessageHandler: errorMessageHandler, } } @@ -198,6 +203,7 @@ func NewCadence1ValueMigrator( // It populates the given map with the IDs of the capability controller it issues. func NewCadence1LinkValueMigrator( rwf reporters.ReportWriterFactory, + errorMessageHandler *errorMessageHandler, capabilityIDs *capcons.CapabilityIDMapping, ) *CadenceBaseMigrator { return &CadenceBaseMigrator{ @@ -221,6 +227,7 @@ func NewCadence1LinkValueMigrator( }, } }, + errorMessageHandler: errorMessageHandler, } } @@ -230,6 +237,7 @@ func NewCadence1LinkValueMigrator( // generated by the link value migration. func NewCadence1CapabilityValueMigrator( rwf reporters.ReportWriterFactory, + errorMessageHandler *errorMessageHandler, capabilityIDs *capcons.CapabilityIDMapping, ) *CadenceBaseMigrator { return &CadenceBaseMigrator{ @@ -247,25 +255,59 @@ func NewCadence1CapabilityValueMigrator( }, } }, + errorMessageHandler: errorMessageHandler, } } +// errorMessageHandler formats error messages from errors. +// It only reports program loading errors once. +type errorMessageHandler struct { + // common.Location -> struct{} + reportedProgramLoadingErrors sync.Map +} + +func (t *errorMessageHandler) FormatError(err error) string { + var message string + + // Only report program loading errors once, + // omit full error message for subsequent occurrences + + var programLoadingError environment.ProgramLoadingError + if errors.As(err, &programLoadingError) { + location := programLoadingError.Location + _, ok := t.reportedProgramLoadingErrors.LoadOrStore(location, struct{}{}) + if ok { + message = "error getting program" + } + } + + if message == "" { + message = err.Error() + } + + return message +} + // cadenceValueMigrationReporter is the reporter for cadence value migrations type cadenceValueMigrationReporter struct { - rw reporters.ReportWriter - log zerolog.Logger - reportedProgramLoadingErrors map[common.Location]struct{} + reportWriter reporters.ReportWriter + log zerolog.Logger + errorMessageHandler *errorMessageHandler } var _ capcons.LinkMigrationReporter = &cadenceValueMigrationReporter{} var _ capcons.CapabilityMigrationReporter = &cadenceValueMigrationReporter{} var _ migrations.Reporter = &cadenceValueMigrationReporter{} -func newValueMigrationReporter(rw reporters.ReportWriter, log zerolog.Logger) *cadenceValueMigrationReporter { +func newValueMigrationReporter( + reportWriter reporters.ReportWriter, + log zerolog.Logger, + errorMessageHandler *errorMessageHandler, +) *cadenceValueMigrationReporter { return &cadenceValueMigrationReporter{ - rw: rw, - log: log, - reportedProgramLoadingErrors: make(map[common.Location]struct{}), + reportWriter: reportWriter, + log: log, + errorMessageHandler: errorMessageHandler, } } @@ -274,7 +316,7 @@ func (t *cadenceValueMigrationReporter) Migrated( storageMapKey interpreter.StorageMapKey, migration string, ) { - t.rw.Write(cadenceValueMigrationReportEntry{ + t.reportWriter.Write(cadenceValueMigrationReportEntry{ StorageKey: storageKey, StorageMapKey: storageMapKey, Migration: migration, @@ -287,23 +329,7 @@ func (t *cadenceValueMigrationReporter) Error( migration string, err error, ) { - var message string - - // Only report program loading errors once, - // omit full error message for subsequent occurrences - - var programLoadingError environment.ProgramLoadingError - if errors.As(err, &programLoadingError) { - location := programLoadingError.Location - if _, ok := t.reportedProgramLoadingErrors[location]; ok { - message = "error getting program" - } - t.reportedProgramLoadingErrors[location] = struct{}{} - } - - if message == "" { - message = err.Error() - } + message := t.errorMessageHandler.FormatError(err) t.log.Error().Msgf( "failed to run %s in account %s, domain %s, key %s: %s", @@ -320,7 +346,7 @@ func (t *cadenceValueMigrationReporter) MigratedPathCapability( addressPath interpreter.AddressPath, borrowType *interpreter.ReferenceStaticType, ) { - t.rw.Write(capConsPathCapabilityMigrationEntry{ + t.reportWriter.Write(capConsPathCapabilityMigrationEntry{ AccountAddress: accountAddress, AddressPath: addressPath, BorrowType: borrowType, @@ -331,7 +357,7 @@ func (t *cadenceValueMigrationReporter) MissingCapabilityID( accountAddress common.Address, addressPath interpreter.AddressPath, ) { - t.rw.Write(capConsMissingCapabilityIDEntry{ + t.reportWriter.Write(capConsMissingCapabilityIDEntry{ AccountAddress: accountAddress, AddressPath: addressPath, }) @@ -341,18 +367,18 @@ func (t *cadenceValueMigrationReporter) MigratedLink( accountAddressPath interpreter.AddressPath, capabilityID interpreter.UInt64Value, ) { - t.rw.Write(capConsLinkMigrationEntry{ + t.reportWriter.Write(capConsLinkMigrationEntry{ AccountAddressPath: accountAddressPath, CapabilityID: capabilityID, }) } func (t *cadenceValueMigrationReporter) CyclicLink(err capcons.CyclicLinkError) { - t.rw.Write(err) + t.reportWriter.Write(err) } func (t *cadenceValueMigrationReporter) MissingTarget(accountAddressPath interpreter.AddressPath) { - t.rw.Write(capConsMissingTargetEntry{ + t.reportWriter.Write(capConsMissingTargetEntry{ AddressPath: accountAddressPath, }) } diff --git a/cmd/util/ledger/migrations/migrator_runtime.go b/cmd/util/ledger/migrations/migrator_runtime.go index ecba2047299..5123bf2d215 100644 --- a/cmd/util/ledger/migrations/migrator_runtime.go +++ b/cmd/util/ledger/migrations/migrator_runtime.go @@ -68,6 +68,7 @@ func newMigratorRuntime( accounts, ), RuntimeInterfaceConfig: config, + ProgramErrors: map[common.Location]error{}, } env := runtime.NewBaseInterpreterEnvironment(runtime.Config{ diff --git a/cmd/util/ledger/util/migration_runtime_interface.go b/cmd/util/ledger/util/migration_runtime_interface.go index e08f048afc2..b9880fd0915 100644 --- a/cmd/util/ledger/util/migration_runtime_interface.go +++ b/cmd/util/ledger/util/migration_runtime_interface.go @@ -19,11 +19,12 @@ import ( // MigrationRuntimeInterface is a runtime interface that can be used in migrations. type MigrationRuntimeInterface struct { RuntimeInterfaceConfig - Accounts environment.Accounts - Programs *environment.Programs + Accounts environment.Accounts + Programs *environment.Programs + ProgramErrors map[common.Location]error } -func (m MigrationRuntimeInterface) ResolveLocation( +func (m *MigrationRuntimeInterface) ResolveLocation( identifiers []runtime.Identifier, location runtime.Location, ) ([]runtime.ResolvedLocation, error) { @@ -84,7 +85,7 @@ func (m MigrationRuntimeInterface) ResolveLocation( return resolvedLocations, nil } -func (m MigrationRuntimeInterface) GetCode(location runtime.Location) ([]byte, error) { +func (m *MigrationRuntimeInterface) GetCode(location runtime.Location) ([]byte, error) { contractLocation, ok := location.(common.AddressLocation) if !ok { return nil, fmt.Errorf("GetCode failed: expected AddressLocation") @@ -98,7 +99,7 @@ func (m MigrationRuntimeInterface) GetCode(location runtime.Location) ([]byte, e return add, nil } -func (m MigrationRuntimeInterface) GetAccountContractCode( +func (m *MigrationRuntimeInterface) GetAccountContractCode( location common.AddressLocation, ) (code []byte, err error) { // First look for staged contracts. @@ -114,190 +115,226 @@ func (m MigrationRuntimeInterface) GetAccountContractCode( return m.Accounts.GetContract(location.Name, flow.Address(location.Address)) } -func (m MigrationRuntimeInterface) GetOrLoadProgram( +func (m *MigrationRuntimeInterface) GetOrLoadProgram( location runtime.Location, load func() (*interpreter.Program, error), ) (*interpreter.Program, error) { - return m.Programs.GetOrLoadProgram(location, load) + return m.Programs.GetOrLoadProgram( + location, + func() (*interpreter.Program, error) { + // If the program is already known to be invalid, + // then return the error immediately, + // without attempting to load the program again + if err, ok := m.ProgramErrors[location]; ok { + return nil, err + } + + // Otherwise, load the program. + // If an error occurs, then record it for subsequent calls + program, err := load() + if err != nil { + m.ProgramErrors[location] = err + } + + return program, err + }, + ) } -func (m MigrationRuntimeInterface) MeterMemory(_ common.MemoryUsage) error { +func (m *MigrationRuntimeInterface) MeterMemory(_ common.MemoryUsage) error { return nil } -func (m MigrationRuntimeInterface) MeterComputation(_ common.ComputationKind, _ uint) error { +func (m *MigrationRuntimeInterface) MeterComputation(_ common.ComputationKind, _ uint) error { return nil } -func (m MigrationRuntimeInterface) GetValue(_, _ []byte) (value []byte, err error) { +func (m *MigrationRuntimeInterface) GetValue(_, _ []byte) (value []byte, err error) { panic("unexpected GetValue call") } -func (m MigrationRuntimeInterface) SetValue(_, _, _ []byte) (err error) { +func (m *MigrationRuntimeInterface) SetValue(_, _, _ []byte) (err error) { panic("unexpected SetValue call") } -func (m MigrationRuntimeInterface) CreateAccount(_ runtime.Address) (address runtime.Address, err error) { +func (m *MigrationRuntimeInterface) CreateAccount(_ runtime.Address) (address runtime.Address, err error) { panic("unexpected CreateAccount call") } -func (m MigrationRuntimeInterface) AddEncodedAccountKey(_ runtime.Address, _ []byte) error { +func (m *MigrationRuntimeInterface) AddEncodedAccountKey(_ runtime.Address, _ []byte) error { panic("unexpected AddEncodedAccountKey call") } -func (m MigrationRuntimeInterface) RevokeEncodedAccountKey(_ runtime.Address, _ int) (publicKey []byte, err error) { +func (m *MigrationRuntimeInterface) RevokeEncodedAccountKey(_ runtime.Address, _ int) (publicKey []byte, err error) { panic("unexpected RevokeEncodedAccountKey call") } -func (m MigrationRuntimeInterface) AddAccountKey(_ runtime.Address, _ *runtime.PublicKey, _ runtime.HashAlgorithm, _ int) (*runtime.AccountKey, error) { +func (m *MigrationRuntimeInterface) AddAccountKey( + _ runtime.Address, + _ *runtime.PublicKey, + _ runtime.HashAlgorithm, + _ int, +) (*runtime.AccountKey, error) { panic("unexpected AddAccountKey call") } -func (m MigrationRuntimeInterface) GetAccountKey(_ runtime.Address, _ int) (*runtime.AccountKey, error) { +func (m *MigrationRuntimeInterface) GetAccountKey(_ runtime.Address, _ int) (*runtime.AccountKey, error) { panic("unexpected GetAccountKey call") } -func (m MigrationRuntimeInterface) RevokeAccountKey(_ runtime.Address, _ int) (*runtime.AccountKey, error) { +func (m *MigrationRuntimeInterface) RevokeAccountKey(_ runtime.Address, _ int) (*runtime.AccountKey, error) { panic("unexpected RevokeAccountKey call") } -func (m MigrationRuntimeInterface) UpdateAccountContractCode(_ common.AddressLocation, _ []byte) (err error) { +func (m *MigrationRuntimeInterface) UpdateAccountContractCode(_ common.AddressLocation, _ []byte) (err error) { panic("unexpected UpdateAccountContractCode call") } -func (m MigrationRuntimeInterface) RemoveAccountContractCode(common.AddressLocation) (err error) { +func (m *MigrationRuntimeInterface) RemoveAccountContractCode(common.AddressLocation) (err error) { panic("unexpected RemoveAccountContractCode call") } -func (m MigrationRuntimeInterface) GetSigningAccounts() ([]runtime.Address, error) { +func (m *MigrationRuntimeInterface) GetSigningAccounts() ([]runtime.Address, error) { panic("unexpected GetSigningAccounts call") } -func (m MigrationRuntimeInterface) ProgramLog(_ string) error { +func (m *MigrationRuntimeInterface) ProgramLog(_ string) error { panic("unexpected ProgramLog call") } -func (m MigrationRuntimeInterface) EmitEvent(_ cadence.Event) error { +func (m *MigrationRuntimeInterface) EmitEvent(_ cadence.Event) error { panic("unexpected EmitEvent call") } -func (m MigrationRuntimeInterface) ValueExists(_, _ []byte) (exists bool, err error) { +func (m *MigrationRuntimeInterface) ValueExists(_, _ []byte) (exists bool, err error) { panic("unexpected ValueExists call") } -func (m MigrationRuntimeInterface) GenerateUUID() (uint64, error) { +func (m *MigrationRuntimeInterface) GenerateUUID() (uint64, error) { panic("unexpected GenerateUUID call") } -func (m MigrationRuntimeInterface) GetComputationLimit() uint64 { +func (m *MigrationRuntimeInterface) GetComputationLimit() uint64 { panic("unexpected GetComputationLimit call") } -func (m MigrationRuntimeInterface) SetComputationUsed(_ uint64) error { +func (m *MigrationRuntimeInterface) SetComputationUsed(_ uint64) error { panic("unexpected SetComputationUsed call") } -func (m MigrationRuntimeInterface) DecodeArgument(_ []byte, _ cadence.Type) (cadence.Value, error) { +func (m *MigrationRuntimeInterface) DecodeArgument(_ []byte, _ cadence.Type) (cadence.Value, error) { panic("unexpected DecodeArgument call") } -func (m MigrationRuntimeInterface) GetCurrentBlockHeight() (uint64, error) { +func (m *MigrationRuntimeInterface) GetCurrentBlockHeight() (uint64, error) { panic("unexpected GetCurrentBlockHeight call") } -func (m MigrationRuntimeInterface) GetBlockAtHeight(_ uint64) (block runtime.Block, exists bool, err error) { +func (m *MigrationRuntimeInterface) GetBlockAtHeight(_ uint64) (block runtime.Block, exists bool, err error) { panic("unexpected GetBlockAtHeight call") } -func (m MigrationRuntimeInterface) ReadRandom([]byte) error { +func (m *MigrationRuntimeInterface) ReadRandom([]byte) error { panic("unexpected ReadRandom call") } -func (m MigrationRuntimeInterface) VerifySignature(_ []byte, _ string, _ []byte, _ []byte, _ runtime.SignatureAlgorithm, _ runtime.HashAlgorithm) (bool, error) { +func (m *MigrationRuntimeInterface) VerifySignature( + _ []byte, + _ string, + _ []byte, + _ []byte, + _ runtime.SignatureAlgorithm, + _ runtime.HashAlgorithm, +) (bool, error) { panic("unexpected VerifySignature call") } -func (m MigrationRuntimeInterface) Hash(_ []byte, _ string, _ runtime.HashAlgorithm) ([]byte, error) { +func (m *MigrationRuntimeInterface) Hash(_ []byte, _ string, _ runtime.HashAlgorithm) ([]byte, error) { panic("unexpected Hash call") } -func (m MigrationRuntimeInterface) GetAccountBalance(_ common.Address) (value uint64, err error) { +func (m *MigrationRuntimeInterface) GetAccountBalance(_ common.Address) (value uint64, err error) { panic("unexpected GetAccountBalance call") } -func (m MigrationRuntimeInterface) GetAccountAvailableBalance(_ common.Address) (value uint64, err error) { +func (m *MigrationRuntimeInterface) GetAccountAvailableBalance(_ common.Address) (value uint64, err error) { panic("unexpected GetAccountAvailableBalance call") } -func (m MigrationRuntimeInterface) GetStorageUsed(_ runtime.Address) (value uint64, err error) { +func (m *MigrationRuntimeInterface) GetStorageUsed(_ runtime.Address) (value uint64, err error) { panic("unexpected GetStorageUsed call") } -func (m MigrationRuntimeInterface) GetStorageCapacity(_ runtime.Address) (value uint64, err error) { +func (m *MigrationRuntimeInterface) GetStorageCapacity(_ runtime.Address) (value uint64, err error) { panic("unexpected GetStorageCapacity call") } -func (m MigrationRuntimeInterface) ImplementationDebugLog(_ string) error { +func (m *MigrationRuntimeInterface) ImplementationDebugLog(_ string) error { panic("unexpected ImplementationDebugLog call") } -func (m MigrationRuntimeInterface) ValidatePublicKey(_ *runtime.PublicKey) error { +func (m *MigrationRuntimeInterface) ValidatePublicKey(_ *runtime.PublicKey) error { panic("unexpected ValidatePublicKey call") } -func (m MigrationRuntimeInterface) GetAccountContractNames(_ runtime.Address) ([]string, error) { +func (m *MigrationRuntimeInterface) GetAccountContractNames(_ runtime.Address) ([]string, error) { panic("unexpected GetAccountContractNames call") } -func (m MigrationRuntimeInterface) AllocateStorageIndex(_ []byte) (atree.StorageIndex, error) { +func (m *MigrationRuntimeInterface) AllocateStorageIndex(_ []byte) (atree.StorageIndex, error) { panic("unexpected AllocateStorageIndex call") } -func (m MigrationRuntimeInterface) ComputationUsed() (uint64, error) { +func (m *MigrationRuntimeInterface) ComputationUsed() (uint64, error) { panic("unexpected ComputationUsed call") } -func (m MigrationRuntimeInterface) MemoryUsed() (uint64, error) { +func (m *MigrationRuntimeInterface) MemoryUsed() (uint64, error) { panic("unexpected MemoryUsed call") } -func (m MigrationRuntimeInterface) InteractionUsed() (uint64, error) { +func (m *MigrationRuntimeInterface) InteractionUsed() (uint64, error) { panic("unexpected InteractionUsed call") } -func (m MigrationRuntimeInterface) SetInterpreterSharedState(_ *interpreter.SharedState) { +func (m *MigrationRuntimeInterface) SetInterpreterSharedState(_ *interpreter.SharedState) { panic("unexpected SetInterpreterSharedState call") } -func (m MigrationRuntimeInterface) GetInterpreterSharedState() *interpreter.SharedState { +func (m *MigrationRuntimeInterface) GetInterpreterSharedState() *interpreter.SharedState { panic("unexpected GetInterpreterSharedState call") } -func (m MigrationRuntimeInterface) AccountKeysCount(_ runtime.Address) (uint64, error) { +func (m *MigrationRuntimeInterface) AccountKeysCount(_ runtime.Address) (uint64, error) { panic("unexpected AccountKeysCount call") } -func (m MigrationRuntimeInterface) BLSVerifyPOP(_ *runtime.PublicKey, _ []byte) (bool, error) { +func (m *MigrationRuntimeInterface) BLSVerifyPOP(_ *runtime.PublicKey, _ []byte) (bool, error) { panic("unexpected BLSVerifyPOP call") } -func (m MigrationRuntimeInterface) BLSAggregateSignatures(_ [][]byte) ([]byte, error) { +func (m *MigrationRuntimeInterface) BLSAggregateSignatures(_ [][]byte) ([]byte, error) { panic("unexpected BLSAggregateSignatures call") } -func (m MigrationRuntimeInterface) BLSAggregatePublicKeys(_ []*runtime.PublicKey) (*runtime.PublicKey, error) { +func (m *MigrationRuntimeInterface) BLSAggregatePublicKeys(_ []*runtime.PublicKey) (*runtime.PublicKey, error) { panic("unexpected BLSAggregatePublicKeys call") } -func (m MigrationRuntimeInterface) ResourceOwnerChanged(_ *interpreter.Interpreter, _ *interpreter.CompositeValue, _ common.Address, _ common.Address) { +func (m *MigrationRuntimeInterface) ResourceOwnerChanged( + _ *interpreter.Interpreter, + _ *interpreter.CompositeValue, + _ common.Address, + _ common.Address, +) { panic("unexpected ResourceOwnerChanged call") } -func (m MigrationRuntimeInterface) GenerateAccountID(_ common.Address) (uint64, error) { +func (m *MigrationRuntimeInterface) GenerateAccountID(_ common.Address) (uint64, error) { panic("unexpected GenerateAccountID call") } -func (m MigrationRuntimeInterface) RecordTrace(_ string, _ runtime.Location, _ time.Duration, _ []attribute.KeyValue) { +func (m *MigrationRuntimeInterface) RecordTrace(_ string, _ runtime.Location, _ time.Duration, _ []attribute.KeyValue) { panic("unexpected RecordTrace call") } From 4198bc75c143f37557ba1dd1aecc7ca93fddc225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Sat, 17 Feb 2024 13:04:15 -0800 Subject: [PATCH 17/18] remove log statements --- cmd/util/ledger/migrations/cadence_values_migration.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmd/util/ledger/migrations/cadence_values_migration.go b/cmd/util/ledger/migrations/cadence_values_migration.go index caf4efc4a50..bd5d51194a5 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration.go +++ b/cmd/util/ledger/migrations/cadence_values_migration.go @@ -136,8 +136,6 @@ func (m *CadenceBaseMigrator) MigrateAccount( reporter := newValueMigrationReporter(m.reporter, m.log, m.errorMessageHandler) - m.log.Info().Msg("Migrating cadence values") - migration.Migrate( &migrations.AddressSliceIterator{ Addresses: []common.Address{ @@ -150,7 +148,6 @@ func (m *CadenceBaseMigrator) MigrateAccount( ), ) - m.log.Info().Msg("Committing changes") err = migration.Commit() if err != nil { return nil, fmt.Errorf("failed to commit changes: %w", err) From 388a11294e702b48d13f62c769a03b4006b0658f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 26 Feb 2024 09:13:38 -0800 Subject: [PATCH 18/18] simplify --- cmd/util/ledger/migrations/cadence_values_migration.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cmd/util/ledger/migrations/cadence_values_migration.go b/cmd/util/ledger/migrations/cadence_values_migration.go index 236b7e980ac..c03659c888f 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration.go +++ b/cmd/util/ledger/migrations/cadence_values_migration.go @@ -264,7 +264,6 @@ type errorMessageHandler struct { } func (t *errorMessageHandler) FormatError(err error) string { - var message string // Only report program loading errors once, // omit full error message for subsequent occurrences @@ -274,15 +273,11 @@ func (t *errorMessageHandler) FormatError(err error) string { location := programLoadingError.Location _, ok := t.reportedProgramLoadingErrors.LoadOrStore(location, struct{}{}) if ok { - message = "error getting program" + return "error getting program" } } - if message == "" { - message = err.Error() - } - - return message + return err.Error() } // cadenceValueMigrationReporter is the reporter for cadence value migrations