Skip to content

Commit

Permalink
Merge pull request #6041 from onflow/bastian/cache-migrations
Browse files Browse the repository at this point in the history
Optionally cache migration results
  • Loading branch information
turbolent authored Jun 7, 2024
2 parents 61b1f26 + 240f552 commit 952cbe4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var (
flagFilterUnreferencedSlabs bool
flagCPUProfile string
flagReportMetrics bool
flagCacheStaticTypeMigrationResults bool
flagCacheEntitlementsMigrationResults bool
)

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -167,6 +169,12 @@ func init() {

Cmd.Flags().BoolVar(&flagReportMetrics, "report-metrics", false,
"report migration metrics")

Cmd.Flags().BoolVar(&flagCacheStaticTypeMigrationResults, "cache-static-type-migration", false,
"cache static type migration results")

Cmd.Flags().BoolVar(&flagCacheEntitlementsMigrationResults, "cache-entitlements-migration", false,
"cache entitlements migration results")
}

func run(*cobra.Command, []string) {
Expand Down Expand Up @@ -380,6 +388,8 @@ func run(*cobra.Command, []string) {
FixSlabsWithBrokenReferences: chainID == flow.Testnet && flagFixSlabsWithBrokenReferences,
FilterUnreferencedSlabs: flagFilterUnreferencedSlabs,
ReportMetrics: flagReportMetrics,
CacheStaticTypeMigrationResults: flagCacheStaticTypeMigrationResults,
CacheEntitlementsMigrationResults: flagCacheEntitlementsMigrationResults,
}

if len(flagInputPayloadFileName) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ type Options struct {
FixSlabsWithBrokenReferences bool
FilterUnreferencedSlabs bool
ReportMetrics bool
CacheStaticTypeMigrationResults bool
CacheEntitlementsMigrationResults bool
}

func NewCadence1Migrations(
Expand Down
14 changes: 12 additions & 2 deletions cmd/util/ledger/migrations/cadence_values_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ func NewCadence1ValueMigration(
diffReporter = rwf.ReportWriter("cadence-value-migration-diff")
}

var staticTypeMigrationCache migrations.StaticTypeCache
if opts.CacheStaticTypeMigrationResults {
staticTypeMigrationCache = migrations.NewDefaultStaticTypeCache()
}

var entitlementsMigrationCache migrations.StaticTypeCache
if opts.CacheEntitlementsMigrationResults {
entitlementsMigrationCache = migrations.NewDefaultStaticTypeCache()
}

return &CadenceBaseMigration{
name: "cadence_value_migration",
reporter: rwf.ReportWriter(cadenceValueMigrationReporterName),
Expand All @@ -263,10 +273,10 @@ func NewCadence1ValueMigration(
reporter *cadenceValueMigrationReporter,
) []migrations.ValueMigration {
return []migrations.ValueMigration{
statictypes.NewStaticTypeMigration().
statictypes.NewStaticTypeMigrationWithCache(staticTypeMigrationCache).
WithCompositeTypeConverter(compositeTypeConverter).
WithInterfaceTypeConverter(interfaceTypeConverter),
entitlements.NewEntitlementsMigration(inter),
entitlements.NewEntitlementsMigrationWithCache(inter, entitlementsMigrationCache),
// After the static type and entitlements migration, we run the type key migration,
// which ensures that even if the previous migrations failed to migrate `Type` values
// used as dictionary keys, they will get re-stored and are accessible by users
Expand Down

0 comments on commit 952cbe4

Please sign in to comment.