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

Remove cricket moments references from atree migration #5242

Merged
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
71 changes: 2 additions & 69 deletions cmd/util/ledger/migrations/atree_register_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ func (m *AtreeRegisterMigrator) MigrateAccount(
})
}

if address == cricketMomentsAddress {
// extra logging for cricket moments
m.log.Info().
Str("address", address.Hex()).
Int("originalLen", originalLen).
Int("newLen", newLen).
Msgf("done migrating cricketMomentsAddress")
}

return newPayloads, nil
}

Expand All @@ -160,32 +151,17 @@ func (m *AtreeRegisterMigrator) migrateAccountStorage(
}
}

if mr.Address == cricketMomentsAddress {
m.log.Info().Msg("Committing storage domain changes")
}

// commit the storage changes
// TODO: for cricket moments `commitNewStorageMaps` already happened potentially
// try switching directly to s.PersistentSlabStorage.FastCommit(runtime.NumCPU())
err := mr.Storage.Commit(mr.Interpreter, false)
if err != nil {
return nil, fmt.Errorf("failed to commit storage: %w", err)
}

if mr.Address == cricketMomentsAddress {
m.log.Info().Msg("Finalizing storage domain changes transaction")
}

// finalize the transaction
result, err := mr.TransactionState.FinalizeMainTransaction()
if err != nil {
return nil, fmt.Errorf("failed to finalize main transaction: %w", err)
}

if mr.Address == cricketMomentsAddress {
m.log.Info().Msg("Storage domain changes transaction finalized")
}

return result.WriteSet, nil
}

Expand Down Expand Up @@ -230,7 +206,7 @@ func (m *AtreeRegisterMigrator) convertStorageDomain(
return fmt.Errorf("failed to read value for key %s: %w", key, err)
}

value, err = m.cloneValue(mr, domain, key, value)
value, err = m.cloneValue(mr, value)

if err != nil {
return fmt.Errorf("failed to clone value for key %s: %w", key, err)
Expand Down Expand Up @@ -276,14 +252,6 @@ func (m *AtreeRegisterMigrator) validateChangesAndCreateNewRegisters(
var statePayload *ledger.Payload
progressLog := func(int) {}

if mr.Address == cricketMomentsAddress {
progressLog = util2.LogProgress(m.log,
util2.DefaultLogProgressConfig(
"applying changes",
len(changes),
))
}

for id, value := range changes {
progressLog(1)
// delete all values that were changed from the original payloads so that we can
Expand Down Expand Up @@ -324,13 +292,7 @@ func (m *AtreeRegisterMigrator) validateChangesAndCreateNewRegisters(

// add all values that were not changed
if len(originalPayloads) > 0 {
if mr.Address == cricketMomentsAddress {
progressLog = util2.LogProgress(m.log,
util2.DefaultLogProgressConfig(
"checking unchanged registers",
len(originalPayloads)),
)
}

for id, value := range originalPayloads {
progressLog(1)

Expand Down Expand Up @@ -366,13 +328,6 @@ func (m *AtreeRegisterMigrator) validateChangesAndCreateNewRegisters(
continue
}

if mr.Address == cricketMomentsAddress {
// to be sure, copy all cricket moments keys
newPayloads = append(newPayloads, value)
m.log.Info().Msgf("copying cricket moments key %s", id)
continue
}

m.rw.Write(migrationProblem{
Address: mr.Address.Hex(),
Key: id.String(),
Expand Down Expand Up @@ -423,31 +378,9 @@ func (m *AtreeRegisterMigrator) validateChangesAndCreateNewRegisters(

func (m *AtreeRegisterMigrator) cloneValue(
mr *migratorRuntime,
domain string,
key interpreter.StorageMapKey,
value interpreter.Value,
) (interpreter.Value, error) {

if isCricketMomentsShardedCollection(mr, value) {
m.log.Info().Msg("migrating CricketMomentsShardedCollection")
value, err := cloneCricketMomentsShardedCollection(
m.log,
m.nWorkers,
mr,
domain,
key,
value,
)

if err != nil {
m.log.Info().Err(err).Msg("failed to clone value")
return nil, err
}

m.log.Info().Msg("done migrating CricketMomentsShardedCollection")
return value, nil
}

err := capturePanic(func() {
// force the value to be read entirely
value = value.Clone(mr.Interpreter)
Expand Down
18 changes: 4 additions & 14 deletions cmd/util/ledger/migrations/cadence_data_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (m *preMigration) MigrateAccount(
payloads []*ledger.Payload,
) ([]*ledger.Payload, error) {

accountHash, err := m.v.hashAccountCadenceValues(m.log, address, payloads)
accountHash, err := m.v.hashAccountCadenceValues(address, payloads)
if err != nil {
m.log.Info().
Err(err).
Expand Down Expand Up @@ -166,7 +166,7 @@ func (m *postMigration) MigrateAccount(
address common.Address,
payloads []*ledger.Payload,
) ([]*ledger.Payload, error) {
newHash, err := m.v.hashAccountCadenceValues(m.log, address, payloads)
newHash, err := m.v.hashAccountCadenceValues(address, payloads)
if err != nil {
m.log.Info().
Err(err).
Expand Down Expand Up @@ -212,7 +212,6 @@ func (m *postMigration) MigrateAccount(
}

func (m *CadenceDataValidationMigrations) hashAccountCadenceValues(
log zerolog.Logger,
address common.Address,
payloads []*ledger.Payload,
) ([]byte, error) {
Expand All @@ -223,7 +222,7 @@ func (m *CadenceDataValidationMigrations) hashAccountCadenceValues(
}

for _, domain := range domains {
domainHash, err := m.hashDomainCadenceValues(log, mr, domain)
domainHash, err := m.hashDomainCadenceValues(mr, domain)
if err != nil {
return nil, fmt.Errorf("failed to hash storage domain %s : %w", domain, err)
}
Expand All @@ -237,7 +236,6 @@ func (m *CadenceDataValidationMigrations) hashAccountCadenceValues(
}

func (m *CadenceDataValidationMigrations) hashDomainCadenceValues(
log zerolog.Logger,
mr *migratorRuntime,
domain string,
) ([]byte, error) {
Expand All @@ -263,7 +261,7 @@ func (m *CadenceDataValidationMigrations) hashDomainCadenceValues(
break
}

h, err := m.recursiveString(log, mr, domain, interpreter.StringStorageMapKey(key.(interpreter.StringAtreeValue)), value, hasher)
h, err := m.recursiveString(value, hasher)
if err != nil {
return nil, fmt.Errorf("failed to convert value to string: %w", err)
}
Expand All @@ -277,17 +275,9 @@ func (m *CadenceDataValidationMigrations) hashDomainCadenceValues(
}

func (m *CadenceDataValidationMigrations) recursiveString(
log zerolog.Logger,
mr *migratorRuntime,
domain string,
key interpreter.StorageMapKey,
value interpreter.Value,
hasher hash.Hasher,
) ([]byte, error) {
if isCricketMomentsShardedCollection(mr, value) {
log.Info().Msg("recursive string hash for cricket moments sharded collection")
return recursiveStringShardedCollection(log, m.nWorkers, mr, domain, key, value)
}

var s string
err := capturePanic(
Expand Down
Loading