Skip to content

Commit

Permalink
add specific account dump
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Sep 13, 2023
1 parent d97e171 commit ab9077a
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions cmd/util/ledger/migrations/atree_register_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ var skippableAccountError = errors.New("account is skippable")
func (m *AtreeRegisterMigrator) MigratePayloads(
_ context.Context,
address common.Address,
payloads []*ledger.Payload,
oldPayloads []*ledger.Payload,
) ([]*ledger.Payload, error) {

if address == common.ZeroAddress {
return payloads, nil
return oldPayloads, nil
}

if reason, ok := knownProblematicAccounts[address]; ok {
m.log.Info().
Str("account", address.Hex()).
Str("reason", reason).
Msg("Account is known to have issues. Skipping it.")
return payloads, nil
return oldPayloads, nil
}

// create all the runtime components we need for the migration
mr, err := m.newMigratorRuntime(address, payloads)
mr, err := m.newMigratorRuntime(address, oldPayloads)
if err != nil {
return nil, fmt.Errorf("failed to create migrator runtime: %w", err)
}
Expand All @@ -113,22 +113,22 @@ func (m *AtreeRegisterMigrator) MigratePayloads(
changes, err := m.migrateAccountStorage(mr)
if err != nil {
if errors.Is(err, skippableAccountError) {
return payloads, nil
return oldPayloads, nil
}
return nil, fmt.Errorf("failed to convert storage for address %s: %w", address.Hex(), err)
}

originalLen := len(payloads)
originalLen := len(oldPayloads)

newRegisters, err := m.validateChangesAndCreateNewRegisters(mr, changes)
newPayloads, err := m.validateChangesAndCreateNewRegisters(mr, changes)
if err != nil {
if errors.Is(err, skippableAccountError) {
return payloads, nil
return oldPayloads, nil
}
return nil, err
}

newLen := len(newRegisters)
newLen := len(newPayloads)

if newLen > originalLen {
m.rw.Write(migrationProblem{
Expand All @@ -139,7 +139,11 @@ func (m *AtreeRegisterMigrator) MigratePayloads(
})
}

return newRegisters, nil
if _, ok := accountsToLog[address]; ok {
m.dumpAccount(mr.Address, oldPayloads, newPayloads)
}

return newPayloads, nil
}

func (m *AtreeRegisterMigrator) migrateAccountStorage(
Expand Down Expand Up @@ -229,6 +233,7 @@ func (m *AtreeRegisterMigrator) convertStorageDomain(
return nil
}()
if err != nil {

m.rw.Write(migrationProblem{
Address: address.Hex(),
Key: string(key),
Expand Down Expand Up @@ -385,21 +390,25 @@ func (m *AtreeRegisterMigrator) validateChangesAndCreateNewRegisters(
}

//if hasMissingKeys && m.sampler.Sample(zerolog.InfoLevel) {
// before := m.rwf.ReportWriter(fmt.Sprintf("account-before-%s", address.Hex()))
// for _, p := range payloads {
// before.Write(p)
// }
// before.Close()
//
// after := m.rwf.ReportWriter(fmt.Sprintf("account-after-%s", address.Hex()))
// for _, p := range newPayloads {
// after.Write(p)
// }
// after.Close()
// m.dumpAccount(mr.Address, mr.Payloads, newPayloads)
//}
return newPayloads, nil
}

func (m *AtreeRegisterMigrator) dumpAccount(address common.Address, before, after []*ledger.Payload) {
beforeWriter := m.rwf.ReportWriter(fmt.Sprintf("account-before-%s", address.Hex()))
for _, p := range before {
beforeWriter.Write(p)
}
beforeWriter.Close()

afterWriter := m.rwf.ReportWriter(fmt.Sprintf("account-after-%s", address.Hex()))
for _, p := range after {
afterWriter.Write(p)
}
afterWriter.Close()
}

//
//func (m *AtreeRegisterMigrator) checkStorageHealth(
// mr *migratorRuntime,
Expand Down Expand Up @@ -500,6 +509,12 @@ var knownProblematicAccounts = map[common.Address]string{
mustHexToAddress("7d8c7e050c694eaa"): "Broken contract Test",
mustHexToAddress("ba53f16ede01972d"): "Broken contract FanTopPermission",
mustHexToAddress("c843c1f5a4805c3a"): "Broken contract FanTopPermission",
mustHexToAddress("48d3be92e6e4a973"): "Broken contract FanTopPermission",
}

var accountsToLog = map[common.Address]string{
// Testnet accounts
mustHexToAddress("ff8bbaa2905b7bd6"): "Small account that increased in size",
}

func mustHexToAddress(hex string) common.Address {
Expand Down

0 comments on commit ab9077a

Please sign in to comment.