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 1 commit
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
11 changes: 10 additions & 1 deletion cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ var (
flagStateCommitment string
flagDatadir string
flagChain string
flagNWorker int
flagNoMigration bool
flagNoReport bool
flagNWorker int
flagValidateMigration bool
)

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -59,6 +60,10 @@ 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")

}

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

if flagValidateMigration {
log.Warn().Msgf("validation flag is enabled and will increase duration of migration")
fxamacker marked this conversation as resolved.
Show resolved Hide resolved
}

err := extractExecutionState(
flagExecutionStateDir,
stateCommitment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,17 @@ 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,
),

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

// This will fix storage used discrepancies caused by the
// DeduplicateContractNamesMigration.
Expand Down
18 changes: 14 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,25 @@ type AtreeRegisterMigrator struct {
rwf reporters.ReportWriterFactory

nWorkers int

validateMigratedValues bool
}

var _ AccountBasedMigration = (*AtreeRegisterMigrator)(nil)
var _ io.Closer = (*AtreeRegisterMigrator)(nil)

func NewAtreeRegisterMigrator(
rwf reporters.ReportWriterFactory,
validateMigratedValues 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,
}

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

if m.validateMigratedValues {
err = validateCadenceValues(address, oldPayloads, newPayloads)
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),
validation.PostMigration(),
},
),
Expand Down
Loading