Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse static type cache across migrations in different accounts #5847

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading