From 3df860d640642bd96d946e6dbb32f65f21783cff Mon Sep 17 00:00:00 2001 From: Daniel Sainati Date: Mon, 6 May 2024 11:21:33 -0400 Subject: [PATCH] reuse cache --- cmd/util/ledger/migrations/cadence.go | 15 +++++++++++---- .../ledger/migrations/cadence_values_migration.go | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/util/ledger/migrations/cadence.go b/cmd/util/ledger/migrations/cadence.go index 779ff95a312..2354177a773 100644 --- a/cmd/util/ledger/migrations/cadence.go +++ b/cmd/util/ledger/migrations/cadence.go @@ -4,6 +4,7 @@ import ( _ "embed" "fmt" + "github.com/onflow/cadence/migrations" "github.com/onflow/cadence/migrations/capcons" "github.com/onflow/cadence/migrations/statictypes" "github.com/onflow/cadence/runtime/common" @@ -219,7 +220,7 @@ func NewCadence1ValueMigrations( log zerolog.Logger, rwf reporters.ReportWriterFactory, opts Options, -) (migrations []NamedMigration) { +) (migs []NamedMigration) { // Populated by CadenceLinkValueMigrator, // used by CadenceCapabilityValueMigrator @@ -227,6 +228,11 @@ func NewCadence1ValueMigrations( errorMessageHandler := &errorMessageHandler{} + // As the proper migrated static type is computed for each old type, + // the entitlements migration will store that info in this cache to be + // reused across accounts for instances of the same types + staticTypeCache := &migrations.StaticTypeCache{} + // The value migrations are run as account-based migrations, // i.e. the migrations are only given the payloads for the account to be migrated. // However, the migrations need to be able to get the code for contracts of any account. @@ -236,7 +242,7 @@ func NewCadence1ValueMigrations( programs := make(map[common.Location]*interpreter.Program, 1000) - migrations = []NamedMigration{ + migs = []NamedMigration{ { Name: "check-contracts", Migrate: NewContractCheckingMigration( @@ -258,6 +264,7 @@ func NewCadence1ValueMigrations( programs, NewCadence1CompositeStaticTypeConverter(opts.ChainID), NewCadence1InterfaceStaticTypeConverter(opts.ChainID), + staticTypeCache, opts, ) }, @@ -286,8 +293,8 @@ func NewCadence1ValueMigrations( accountBasedMigration := migrationConstructor(opts) - migrations = append( - migrations, + migs = append( + migs, NamedMigration{ Name: accountBasedMigration.name, Migrate: NewAccountBasedMigration( diff --git a/cmd/util/ledger/migrations/cadence_values_migration.go b/cmd/util/ledger/migrations/cadence_values_migration.go index ba653e5fb6f..5c62be0a295 100644 --- a/cmd/util/ledger/migrations/cadence_values_migration.go +++ b/cmd/util/ledger/migrations/cadence_values_migration.go @@ -255,6 +255,7 @@ func NewCadence1ValueMigrator( programs map[runtime.Location]*interpreter.Program, compositeTypeConverter statictypes.CompositeTypeConverterFunc, interfaceTypeConverter statictypes.InterfaceTypeConverterFunc, + staticTypeCache *migrations.StaticTypeCache, opts Options, ) *CadenceBaseMigrator { @@ -279,7 +280,7 @@ func NewCadence1ValueMigrator( statictypes.NewStaticTypeMigration(). WithCompositeTypeConverter(compositeTypeConverter). WithInterfaceTypeConverter(interfaceTypeConverter), - entitlements.NewEntitlementsMigration(inter), + entitlements.NewEntitlementsMigrationWithCache(inter, staticTypeCache), string_normalization.NewStringNormalizingMigration(), } },