Skip to content

Commit

Permalink
update usage of NewCadence1Migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Mar 12, 2024
1 parent e8774dd commit 7166e0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 13 additions & 7 deletions storage/migration/cadence1.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package migration

import (
"runtime"

"github.com/onflow/flow-go/cmd/util/ledger/migrations"
"github.com/onflow/flow-go/model/flow"
"github.com/rs/zerolog"
Expand All @@ -31,33 +33,37 @@ import (

func MigrateCadence1(
store *sqlite.Store,
evmContractChange migrations.EVMContractChange,
burnerContractChange migrations.BurnerContractChange,
stagedContracts []migrations.StagedContract,
rwf reporters.ReportWriterFactory,
logger zerolog.Logger,

) error {
payloads, payloadInfo, _, err := util.PayloadsAndAccountsFromEmulatorSnapshot(store.DB())
if err != nil {
return err
}

// TODO: >1 breaks atree storage map iteration
// and requires LinkValueMigration.LinkValueMigration to be thread-safe
const nWorker = 1

// TODO: EVM contract is not deployed in snapshot yet, so can't update it
const evmContractChange = migrations.EVMContractChangeNone
nWorker := runtime.NumCPU()

cadence1Migrations := migrations.NewCadence1Migrations(
logger,
rwf,
nWorker,
flow.Emulator,
false,
false,
evmContractChange,
burnerContractChange,
stagedContracts,
false,
0,
)

for _, migration := range cadence1Migrations {
payloads, err = migration(payloads)
logger.Info().Str("migration", migration.Name).Msg("running migration")
payloads, err = migration.Migrate(payloads)
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion storage/migration/cadence1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ func migrateEmulatorState(t *testing.T, tempEmulatorStatePath string) {
rwf := &NOOPReportWriterFactory{}
stagedContracts := stagedContracts()

err = MigrateCadence1(store, stagedContracts, rwf, logger)
err = MigrateCadence1(
store,
migrations.EVMContractChangeNone,
migrations.BurnerContractChangeDeploy,
stagedContracts,
rwf,
logger,
)
require.NoError(t, err)
require.Empty(t, logWriter.logs)
}
Expand Down

0 comments on commit 7166e0a

Please sign in to comment.