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

Fixed account diffs #958

Merged
merged 12 commits into from
May 7, 2024
5 changes: 3 additions & 2 deletions pkg/model/account_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"io"
"strconv"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
Expand Down Expand Up @@ -83,8 +84,8 @@ func (d *AccountDiff) String() string {
builder.AddField(stringify.NewStructField("PreviousExpirySlot", uint32(d.PreviousExpirySlot)))
builder.AddField(stringify.NewStructField("NewOutputID", d.NewOutputID))
builder.AddField(stringify.NewStructField("PreviousOutputID", d.PreviousOutputID))
builder.AddField(stringify.NewStructField("BlockIssuerKeysAdded", d.BlockIssuerKeysAdded))
builder.AddField(stringify.NewStructField("BlockIssuerKeysRemoved", d.BlockIssuerKeysRemoved))
builder.AddField(stringify.NewStructField("BlockIssuerKeysAdded", func() string { return strconv.Itoa(d.BlockIssuerKeysAdded.Size()) }()))
builder.AddField(stringify.NewStructField("BlockIssuerKeysRemoved", func() string { return strconv.Itoa(d.BlockIssuerKeysRemoved.Size()) }()))
builder.AddField(stringify.NewStructField("ValidatorStakeChange", d.ValidatorStakeChange))
builder.AddField(stringify.NewStructField("DelegationStakeChange", d.DelegationStakeChange))
builder.AddField(stringify.NewStructField("FixedCostChange", d.FixedCostChange))
Expand Down
11 changes: 9 additions & 2 deletions pkg/protocol/engine/accounts/accountsledger/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,13 @@ func (m *Manager) rollbackAccountTo(accountData *accounts.AccountData, targetSlo
return false, false, ierrors.Wrapf(err, "can't retrieve account, could not load diff for account %s in slot %d", accountData.ID, diffSlot)
}

m.LogDebug("Rolling back account", "accountID", accountData.ID, "slot", diffSlot, "accountData", accountData, "diffChange", diffChange, "destroyed", destroyed)

// update the account data with the diff
accountData.Credits.Update(-diffChange.BICChange, diffChange.PreviousUpdatedSlot)
if diffChange.BICChange != 0 {
accountData.Credits.Update(-diffChange.BICChange, diffChange.PreviousUpdatedSlot)
}

// update the expiry slot of the account if it was changed
if diffChange.PreviousExpirySlot != diffChange.NewExpirySlot {
accountData.ExpirySlot = diffChange.PreviousExpirySlot
Expand Down Expand Up @@ -564,7 +569,9 @@ func (m *Manager) commitAccountTree(slot iotago.SlotIndex, accountDiffChanges ma
diffChange.BICChange -= accountData.Credits.Value - iotago.BlockIssuanceCredits(decayedPreviousCredits)
}

accountData.Credits.Update(diffChange.BICChange, slot)
if diffChange.BICChange != 0 || !exists {
accountData.Credits.Update(diffChange.BICChange, slot)
}
}

// update the expiry slot of the account if it changed
Expand Down
Loading