Skip to content

Commit

Permalink
Add flag for verbose validation error logging
Browse files Browse the repository at this point in the history
Added flag --log-verbose-validation-error to enable logging of entire
Cadence values on validation error during atree migration.
  • Loading branch information
fxamacker committed Jan 9, 2024
1 parent 074e115 commit 706b5a5
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 62 deletions.
32 changes: 20 additions & 12 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import (
)

var (
flagExecutionStateDir string
flagOutputDir string
flagBlockHash string
flagStateCommitment string
flagDatadir string
flagChain string
flagNWorker int
flagNoMigration bool
flagNoReport bool
flagValidateMigration bool
flagExecutionStateDir string
flagOutputDir string
flagBlockHash string
flagStateCommitment string
flagDatadir string
flagChain string
flagNWorker int
flagNoMigration bool
flagNoReport bool
flagValidateMigration bool
flagLogVerboseValidationError bool
)

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -62,7 +63,10 @@ func init() {
Cmd.Flags().IntVar(&flagNWorker, "n-migrate-worker", 10, "number of workers to migrate payload concurrently")

Cmd.Flags().BoolVar(&flagValidateMigration, "validate", false,
"validate migrated Cadence values")
"validate migrated Cadence values (atree migration)")

Cmd.Flags().BoolVar(&flagLogVerboseValidationError, "log-verbose-validation-error", false,
"log entire Cadence values on validation error (atree migration)")

}

Expand Down Expand Up @@ -141,7 +145,11 @@ func run(*cobra.Command, []string) {
}

if flagValidateMigration {
log.Warn().Msgf("validation flag is enabled and will increase duration of migration")
log.Warn().Msgf("atree migration validation 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")
}

err := extractExecutionState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func extractExecutionState(
migrators.NewAtreeRegisterMigrator(
rwf,
flagValidateMigration,
flagLogVerboseValidationError,
),

&migrators.DeduplicateContractNamesMigration{},
Expand Down
15 changes: 9 additions & 6 deletions cmd/util/ledger/migrations/atree_register_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ type AtreeRegisterMigrator struct {

nWorkers int

validateMigratedValues bool
validateMigratedValues bool
logVerboseValidationError bool
}

var _ AccountBasedMigration = (*AtreeRegisterMigrator)(nil)
Expand All @@ -45,15 +46,17 @@ var _ io.Closer = (*AtreeRegisterMigrator)(nil)
func NewAtreeRegisterMigrator(
rwf reporters.ReportWriterFactory,
validateMigratedValues bool,
logVerboseValidationError bool,
) *AtreeRegisterMigrator {

sampler := util2.NewTimedSampler(30 * time.Second)

migrator := &AtreeRegisterMigrator{
sampler: sampler,
rwf: rwf,
rw: rwf.ReportWriter("atree-register-migrator"),
validateMigratedValues: validateMigratedValues,
sampler: sampler,
rwf: rwf,
rw: rwf.ReportWriter("atree-register-migrator"),
validateMigratedValues: validateMigratedValues,
logVerboseValidationError: logVerboseValidationError,
}

return migrator
Expand Down Expand Up @@ -112,7 +115,7 @@ func (m *AtreeRegisterMigrator) MigrateAccount(
}

if m.validateMigratedValues {
err = validateCadenceValues(address, oldPayloads, newPayloads)
err = validateCadenceValues(address, oldPayloads, newPayloads, m.log, m.logVerboseValidationError)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAtreeRegisterMigration(t *testing.T) {
migrations.CreateAccountBasedMigration(log, 2,
[]migrations.AccountBasedMigration{
validation.PreMigration(),
migrations.NewAtreeRegisterMigrator(reporters.NewReportFileWriterFactory(dir, log), true),
migrations.NewAtreeRegisterMigrator(reporters.NewReportFileWriterFactory(dir, log), true, false),
validation.PostMigration(),
},
),
Expand Down
Loading

0 comments on commit 706b5a5

Please sign in to comment.