Skip to content

Commit

Permalink
Merge pull request #6572 from onflow/bastian/remove-cadence-migrations
Browse files Browse the repository at this point in the history
Remove Cadence 1.0 / Crescendo migrations
  • Loading branch information
turbolent authored Oct 18, 2024
2 parents 0dde730 + 259697e commit 13dd041
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 12,974 deletions.
89 changes: 2 additions & 87 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package extract

import (
"compress/gzip"
"encoding/hex"
"fmt"
"io"
"os"
"path"
"runtime/pprof"
Expand Down Expand Up @@ -326,7 +324,8 @@ func run(*cobra.Command, []string) {
}
}

chain := flow.ChainID(flagChain).Chain()
// Validate chain ID
_ = flow.ChainID(flagChain).Chain()

if flagNoReport {
log.Warn().Msgf("--no-report flag is deprecated")
Expand Down Expand Up @@ -401,43 +400,6 @@ func run(*cobra.Command, []string) {

log.Info().Msgf("state extraction plan: %s, %s", inputMsg, outputMsg)

chainID := chain.ChainID()

burnerContractChange := migrations.BurnerContractChangeNone
evmContractChange := migrations.EVMContractChangeNone
switch chainID {
case flow.Emulator:
burnerContractChange = migrations.BurnerContractChangeDeploy
evmContractChange = migrations.EVMContractChangeDeployMinimalAndUpdateFull
case flow.Testnet, flow.Mainnet:
burnerContractChange = migrations.BurnerContractChangeUpdate
evmContractChange = migrations.EVMContractChangeUpdateFull
}

stagedContracts, err := migrations.StagedContractsFromCSV(flagStagedContractsFile)
if err != nil {
log.Fatal().Err(err).Msgf("error loading staged contracts: %s", err.Error())
}

opts := migrations.Options{
NWorker: flagNWorker,
DiffMigrations: flagDiffMigration,
LogVerboseDiff: flagLogVerboseDiff,
CheckStorageHealthBeforeMigration: flagCheckStorageHealthBeforeMigration,
ChainID: chainID,
EVMContractChange: evmContractChange,
BurnerContractChange: burnerContractChange,
StagedContracts: stagedContracts,
Prune: flagPrune,
MaxAccountSize: flagMaxAccountSize,
VerboseErrorOutput: flagVerboseErrorOutput,
FixSlabsWithBrokenReferences: chainID == flow.Testnet && flagFixSlabsWithBrokenReferences,
FilterUnreferencedSlabs: flagFilterUnreferencedSlabs,
ReportMetrics: flagReportMetrics,
CacheStaticTypeMigrationResults: flagCacheStaticTypeMigrationResults,
CacheEntitlementsMigrationResults: flagCacheEntitlementsMigrationResults,
}

var extractor extractor
if len(flagInputPayloadFileName) > 0 {
extractor = newPayloadFileExtractor(log.Logger, flagInputPayloadFileName)
Expand All @@ -460,21 +422,6 @@ func run(*cobra.Command, []string) {
var migs []migrations.NamedMigration

switch flagMigration {
case "cadence-1.0":
migs = newCadence1Migrations(
log.Logger,
flagOutputDir,
opts,
)

case "fix-authorizations":
migs = newFixAuthorizationsMigrations(
log.Logger,
flagAuthorizationFixes,
flagOutputDir,
opts,
)

default:
log.Fatal().Msgf("unknown migration: %s", flagMigration)
}
Expand Down Expand Up @@ -557,35 +504,3 @@ func ensureCheckpointFileExist(dir string) error {

return fmt.Errorf("no checkpoint file was found, no root checkpoint file was found in %v, check the --execution-state-dir flag", dir)
}

func readAuthorizationFixes(path string) migrations.AuthorizationFixes {

file, err := os.Open(path)
if err != nil {
log.Fatal().Err(err).Msgf("can't open authorization fixes: %s", path)
}
defer file.Close()

var reader io.Reader = file
if isGzip(file) {
reader, err = gzip.NewReader(file)
if err != nil {
log.Fatal().Err(err).Msgf("failed to create gzip reader for %s", path)
}
}

log.Info().Msgf("Reading authorization fixes from %s ...", path)

fixes, err := migrations.ReadAuthorizationFixes(reader, nil)
if err != nil {
log.Fatal().Err(err).Msgf("failed to read authorization fixes %s", path)
}

log.Info().Msgf("Read %d authorization fixes", len(fixes))

return fixes
}

func isGzip(file *os.File) bool {
return strings.HasSuffix(file.Name(), ".gz")
}
78 changes: 0 additions & 78 deletions cmd/util/cmd/execution-state-extract/execution_state_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"golang.org/x/sync/errgroup"

migrators "github.com/onflow/flow-go/cmd/util/ledger/migrations"
"github.com/onflow/flow-go/cmd/util/ledger/reporters"
"github.com/onflow/flow-go/cmd/util/ledger/util"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/ledger/common/hash"
Expand Down Expand Up @@ -357,80 +356,3 @@ func createTrieFromPayloads(logger zerolog.Logger, payloads []*ledger.Payload) (

return newTrie, nil
}

func newCadence1Migrations(
log zerolog.Logger,
outputDir string,
opts migrators.Options,
) []migrators.NamedMigration {

log.Info().Msg("initializing Cadence 1.0 migrations ...")

rwf := reporters.NewReportFileWriterFactory(outputDir, log)

namedMigrations := migrators.NewCadence1Migrations(
log,
outputDir,
rwf,
opts,
)

// At the end, fix up storage-used discrepancies
namedMigrations = append(
namedMigrations,
migrators.NamedMigration{
Name: "account-usage-migration",
Migrate: migrators.NewAccountBasedMigration(
log,
opts.NWorker,
[]migrators.AccountBasedMigration{
migrators.NewAccountUsageMigration(rwf),
},
),
},
)

log.Info().Msg("initialized migrations")

return namedMigrations
}

func newFixAuthorizationsMigrations(
log zerolog.Logger,
authorizationFixesPath string,
outputDir string,
opts migrators.Options,
) []migrators.NamedMigration {

log.Info().Msg("initializing authorization fix migrations ...")

rwf := reporters.NewReportFileWriterFactory(outputDir, log)

authorizationFixes := readAuthorizationFixes(authorizationFixesPath)

namedMigrations := migrators.NewFixAuthorizationsMigrations(
log,
rwf,
authorizationFixes,
opts,
)

// At the end, fix up storage-used discrepancies
namedMigrations = append(
namedMigrations,
migrators.NamedMigration{
Name: "account-usage-migration",
Migrate: migrators.NewAccountBasedMigration(
log,
opts.NWorker,
[]migrators.AccountBasedMigration{
migrators.NewAccountUsageMigration(rwf),
},
),
},
)

log.Info().Msg("initialized migrations")

return namedMigrations
}
27 changes: 0 additions & 27 deletions cmd/util/ledger/migrations/burner.go

This file was deleted.

Loading

0 comments on commit 13dd041

Please sign in to comment.