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

Add migration diff util for testing and debugging migrations #5499

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 26 additions & 2 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var (
flagValidateMigration bool
flagAllowPartialStateFromPayloads bool
flagLogVerboseValidationError bool
flagDiffMigration bool
flagLogVerboseDiff bool
flagStagedContractsFile string
flagInputPayloadFileName string
flagOutputPayloadFileName string
Expand Down Expand Up @@ -81,6 +83,12 @@ func init() {
Cmd.Flags().BoolVar(&flagLogVerboseValidationError, "log-verbose-validation-error", false,
"log entire Cadence values on validation error (atree migration)")

Cmd.Flags().BoolVar(&flagDiffMigration, "diff", false,
"compare Cadence values and log diff (migration)")

Cmd.Flags().BoolVar(&flagLogVerboseDiff, "log-verbose-diff", false,
"log entire Cadence values on diff (requires --diff flag)")

Cmd.Flags().StringVar(&flagStagedContractsFile, "staged-contracts", "",
"Staged contracts CSV file")

Expand Down Expand Up @@ -139,6 +147,10 @@ func run(*cobra.Command, []string) {
log.Fatal().Msg("--extract-payloads-by-address requires --output-payload-filename to be specified")
}

if flagValidateMigration && flagDiffMigration {
log.Fatal().Msg("Both --validate and --diff are enabled, please specify only one (or none) of these")
}

if len(flagBlockHash) > 0 {
blockID, err := flow.HexStringToIdentifier(flagBlockHash)
if err != nil {
Expand Down Expand Up @@ -241,11 +253,19 @@ func run(*cobra.Command, []string) {
}

if flagValidateMigration {
log.Warn().Msgf("atree migration validation flag is enabled and will increase duration of migration")
log.Warn().Msgf("--validate flag is enabled and will increase duration of migration")
}

if flagLogVerboseValidationError {
log.Warn().Msgf("atree migration has verbose validation error logging enabled which may increase size of log")
log.Warn().Msgf("--log-verbose-validation-error flag is enabled which may increase size of log")
}

if flagDiffMigration {
log.Warn().Msgf("--diff flag is enabled and will increase duration of migration")
}

if flagLogVerboseDiff {
log.Warn().Msgf("--log-verbose-diff flag is enabled which may increase size of log")
}

var inputMsg string
Expand Down Expand Up @@ -299,6 +319,8 @@ func run(*cobra.Command, []string) {
flagOutputDir,
flagNWorker,
!flagNoMigration,
flagDiffMigration,
flagLogVerboseDiff,
chainID,
evmContractChange,
stagedContracts,
Expand All @@ -314,6 +336,8 @@ func run(*cobra.Command, []string) {
flagOutputDir,
flagNWorker,
!flagNoMigration,
flagDiffMigration,
flagLogVerboseDiff,
chainID,
evmContractChange,
stagedContracts,
Expand Down
12 changes: 12 additions & 0 deletions cmd/util/cmd/execution-state-extract/execution_state_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func extractExecutionState(
outputDir string,
nWorker int, // number of concurrent worker to migration payloads
runMigrations bool,
diffMigrations bool,
logVerboseDiff bool,
chainID flow.ChainID,
evmContractChange migrators.EVMContractChange,
stagedContracts []migrators.StagedContract,
Expand Down Expand Up @@ -97,6 +99,8 @@ func extractExecutionState(
dir,
nWorker,
runMigrations,
diffMigrations,
logVerboseDiff,
chainID,
evmContractChange,
stagedContracts,
Expand Down Expand Up @@ -204,6 +208,8 @@ func extractExecutionStateFromPayloads(
outputDir string,
nWorker int, // number of concurrent worker to migation payloads
runMigrations bool,
diffMigrations bool,
logVerboseDiff bool,
chainID flow.ChainID,
evmContractChange migrators.EVMContractChange,
stagedContracts []migrators.StagedContract,
Expand All @@ -224,6 +230,8 @@ func extractExecutionStateFromPayloads(
dir,
nWorker,
runMigrations,
diffMigrations,
logVerboseDiff,
chainID,
evmContractChange,
stagedContracts,
Expand Down Expand Up @@ -372,6 +380,8 @@ func newMigrations(
dir string,
nWorker int,
runMigrations bool,
diffMigrations bool,
logVerboseDiff bool,
chainID flow.ChainID,
evmContractChange migrators.EVMContractChange,
stagedContracts []migrators.StagedContract,
Expand All @@ -387,6 +397,8 @@ func newMigrations(
rwf,
nWorker,
chainID,
diffMigrations,
logVerboseDiff,
evmContractChange,
stagedContracts,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func TestExtractExecutionState(t *testing.T) {
outdir,
10,
false,
false,
false,
flow.Emulator,
// TODO:
migrations.EVMContractChangeNone,
Expand Down
8 changes: 8 additions & 0 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func NewCadence1ValueMigrations(
rwf reporters.ReportWriterFactory,
nWorker int,
chainID flow.ChainID,
diffMigrations bool,
logVerboseDiff bool,
) (migrations []NamedMigration) {

// Populated by CadenceLinkValueMigrator,
Expand All @@ -177,6 +179,8 @@ func NewCadence1ValueMigrations(
for _, accountBasedMigration := range []*CadenceBaseMigrator{
NewCadence1ValueMigrator(
rwf,
diffMigrations,
logVerboseDiff,
errorMessageHandler,
NewCadence1CompositeStaticTypeConverter(chainID),
NewCadence1InterfaceStaticTypeConverter(chainID),
Expand Down Expand Up @@ -261,6 +265,8 @@ func NewCadence1Migrations(
rwf reporters.ReportWriterFactory,
nWorker int,
chainID flow.ChainID,
diffMigrations bool,
logVerboseDiff bool,
evmContractChange EVMContractChange,
stagedContracts []StagedContract,
) []NamedMigration {
Expand All @@ -277,6 +283,8 @@ func NewCadence1Migrations(
rwf,
nWorker,
chainID,
diffMigrations,
logVerboseDiff,
),
)
}
Loading