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

Replace hash-based validation of migrated Cadence values to use Equal() #5204

Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 26 additions & 9 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import (
)

var (
flagExecutionStateDir string
flagOutputDir string
flagBlockHash string
flagStateCommitment string
flagDatadir string
flagChain string
flagNoMigration bool
flagNoReport bool
flagNWorker int
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 @@ -59,6 +61,13 @@ func init() {
"don't report the state")

Cmd.Flags().IntVar(&flagNWorker, "n-migrate-worker", 10, "number of workers to migrate payload concurrently")

Cmd.Flags().BoolVar(&flagValidateMigration, "validate", false,
fxamacker marked this conversation as resolved.
Show resolved Hide resolved
"validate migrated Cadence values (atree migration)")

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

}

func run(*cobra.Command, []string) {
Expand Down Expand Up @@ -135,6 +144,14 @@ func run(*cobra.Command, []string) {
log.Warn().Msgf("--no-migration flag is deprecated")
}

if flagValidateMigration {
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(
flagExecutionStateDir,
stateCommitment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,18 @@ func extractExecutionState(

rwf := reporters.NewReportFileWriterFactory(dir, log)

cadenceDataValidation := migrators.NewCadenceDataValidationMigrations(rwf, nWorker)

var migrations = []ledger.Migration{
migrators.CreateAccountBasedMigration(
log,
nWorker,
[]migrators.AccountBasedMigration{
cadenceDataValidation.PreMigration(),
migrators.NewAtreeRegisterMigrator(
rwf,
flagValidateMigration,
flagLogVerboseValidationError,
),

&migrators.DeduplicateContractNamesMigration{},
cadenceDataValidation.PostMigration(),

// This will fix storage used discrepancies caused by the
// DeduplicateContractNamesMigration.
Expand Down
21 changes: 17 additions & 4 deletions cmd/util/ledger/migrations/atree_register_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,28 @@ type AtreeRegisterMigrator struct {
rwf reporters.ReportWriterFactory

nWorkers int

validateMigratedValues bool
logVerboseValidationError bool
}

var _ AccountBasedMigration = (*AtreeRegisterMigrator)(nil)
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"),
sampler: sampler,
rwf: rwf,
rw: rwf.ReportWriter("atree-register-migrator"),
validateMigratedValues: validateMigratedValues,
logVerboseValidationError: logVerboseValidationError,
}

return migrator
Expand Down Expand Up @@ -108,6 +114,13 @@ func (m *AtreeRegisterMigrator) MigrateAccount(
return nil, err
}

if m.validateMigratedValues {
err = validateCadenceValues(address, oldPayloads, newPayloads, m.log, m.logVerboseValidationError)
if err != nil {
return nil, err
}
}

newLen := len(newPayloads)

if newLen > originalLen {
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)),
migrations.NewAtreeRegisterMigrator(reporters.NewReportFileWriterFactory(dir, log), true, false),
validation.PostMigration(),
},
),
Expand Down
Loading