Skip to content

Commit

Permalink
reuse cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed May 6, 2024
1 parent 41286b3 commit 3df860d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -219,14 +220,19 @@ func NewCadence1ValueMigrations(
log zerolog.Logger,
rwf reporters.ReportWriterFactory,
opts Options,
) (migrations []NamedMigration) {
) (migs []NamedMigration) {

// Populated by CadenceLinkValueMigrator,
// used by CadenceCapabilityValueMigrator
capabilityMapping := &capcons.CapabilityMapping{}

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.
Expand All @@ -236,7 +242,7 @@ func NewCadence1ValueMigrations(

programs := make(map[common.Location]*interpreter.Program, 1000)

migrations = []NamedMigration{
migs = []NamedMigration{
{
Name: "check-contracts",
Migrate: NewContractCheckingMigration(
Expand All @@ -258,6 +264,7 @@ func NewCadence1ValueMigrations(
programs,
NewCadence1CompositeStaticTypeConverter(opts.ChainID),
NewCadence1InterfaceStaticTypeConverter(opts.ChainID),
staticTypeCache,
opts,
)
},
Expand Down Expand Up @@ -286,8 +293,8 @@ func NewCadence1ValueMigrations(

accountBasedMigration := migrationConstructor(opts)

migrations = append(
migrations,
migs = append(
migs,
NamedMigration{
Name: accountBasedMigration.name,
Migrate: NewAccountBasedMigration(
Expand Down
3 changes: 2 additions & 1 deletion cmd/util/ledger/migrations/cadence_values_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func NewCadence1ValueMigrator(
programs map[runtime.Location]*interpreter.Program,
compositeTypeConverter statictypes.CompositeTypeConverterFunc,
interfaceTypeConverter statictypes.InterfaceTypeConverterFunc,
staticTypeCache *migrations.StaticTypeCache,
opts Options,
) *CadenceBaseMigrator {

Expand All @@ -279,7 +280,7 @@ func NewCadence1ValueMigrator(
statictypes.NewStaticTypeMigration().
WithCompositeTypeConverter(compositeTypeConverter).
WithInterfaceTypeConverter(interfaceTypeConverter),
entitlements.NewEntitlementsMigration(inter),
entitlements.NewEntitlementsMigrationWithCache(inter, staticTypeCache),
string_normalization.NewStringNormalizingMigration(),
}
},
Expand Down

0 comments on commit 3df860d

Please sign in to comment.