Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Added logs while exporting accountsledger snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsporn committed Apr 26, 2024
1 parent c0365e8 commit 09a268b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/protocol/engine/accounts/accountsledger/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func (m *Manager) Import(reader io.ReadSeeker) error {
return ierrors.Wrapf(err, "unable to set account %s", accountData.ID)
}

m.LogDebug("Imported account", "accountID", accountData.ID, "outputID", accountData.OutputID, "credits.value", accountData.Credits.Value, "credits.updateSlot", accountData.Credits.UpdateSlot)

return nil
}); err != nil {
return ierrors.Wrap(err, "failed to read account data")
Expand Down Expand Up @@ -77,13 +79,18 @@ func (m *Manager) exportAccountTree(writer io.WriteSeeker, targetIndex iotago.Sl
var accountCount int

if err := m.accountsTree.Stream(func(accountID iotago.AccountID, accountData *accounts.AccountData) error {
m.LogDebug("Exporting account", "accountID", accountID, "outputID", accountData.OutputID, "credits.value", accountData.Credits.Value, "credits.updateSlot", accountData.Credits.UpdateSlot)

wasCreatedAfterTargetSlot, _, err := m.rollbackAccountTo(accountData, targetIndex)
if err != nil {
return ierrors.Wrapf(err, "unable to rollback account %s", accountID)
}

m.LogDebug("Exporting account after rollback", "accountID", accountID, "outputID", accountData.OutputID, "credits.value", accountData.Credits.Value, "credits.updateSlot", accountData.Credits.UpdateSlot)

// Account was created after the target slot, so we don't need to export it.
if wasCreatedAfterTargetSlot {
m.LogDebug("Exporting account was created after target slot", "accountID", accountID, "targetSlot", targetIndex)
return nil
}

Expand Down Expand Up @@ -123,15 +130,21 @@ func (m *Manager) recreateDestroyedAccounts(writer io.WriteSeeker, targetSlot io
}

for accountID, accountData := range destroyedAccounts {
m.LogDebug("Exporting recreated destroyed account", "accountID", accountID, "outputID", accountData.OutputID, "credits.value", accountData.Credits.Value, "credits.updateSlot", accountData.Credits.UpdateSlot)

if wasCreatedAfterTargetSlot, wasDestroyed, err := m.rollbackAccountTo(accountData, targetSlot); err != nil {
return 0, ierrors.Wrapf(err, "unable to rollback account %s to target slot %d", accountID, targetSlot)
} else if wasCreatedAfterTargetSlot {
// Account was created after the target slot, so we don't need to export it.
m.LogDebug("Exporting recreated destroyed account was created after target slot", "accountID", accountID, "targetSlot", targetSlot)

continue
} else if !wasDestroyed {
return 0, ierrors.Errorf("account %s was not destroyed", accountID)
}

m.LogDebug("Exporting recreated destroyed account after rollback", "accountID", accountID, "outputID", accountData.OutputID, "credits.value", accountData.Credits.Value, "credits.updateSlot", accountData.Credits.UpdateSlot)

if err := stream.WriteObject(writer, accountData, (*accounts.AccountData).Bytes); err != nil {
return 0, ierrors.Wrapf(err, "unable to write account %s", accountID)
}
Expand Down

0 comments on commit 09a268b

Please sign in to comment.