Skip to content

Commit

Permalink
Merge pull request #854 from iotaledger/debug/scheduler-inconsistency
Browse files Browse the repository at this point in the history
Fix accounts ledger rollback and force commitment deadlock
  • Loading branch information
piotrm50 authored Mar 21, 2024
2 parents a3f787a + f2945f0 commit 50023f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ func (c *Commitment) deriveChain(parent *Commitment) func() {
// We will spawn a new one if we ever change back to not being the main child.
// Here we basically move commitments to the parent chain.
if currentChain != nil && currentChain != parentChain {
currentChain.IsEvicted.Trigger()
// TODO: refactor it to use a dedicated WorkerPool
go currentChain.IsEvicted.Trigger()
}

return parentChain
Expand Down
8 changes: 8 additions & 0 deletions pkg/protocol/engine/accounts/accountsledger/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,18 @@ func (m *Manager) PastAccounts(accountIDs iotago.AccountIDs, targetSlot iotago.S
}

func (m *Manager) Rollback(targetSlot iotago.SlotIndex) error {
processedAccounts := ds.NewSet[iotago.AccountID]()
for slot := m.latestCommittedSlot; slot > targetSlot; slot-- {
slotDiff := lo.PanicOnErr(m.slotDiff(slot))
var internalErr error

//nolint:revive
if err := slotDiff.Stream(func(accountID iotago.AccountID, accountDiff *model.AccountDiff, destroyed bool) bool {
// We rollback each account directly to targetSlot, therefore, we should rollback each account only once.
if processedAccounts.Has(accountID) {
return true
}

accountData, exists, err := m.accountsTree.Get(accountID)
if err != nil {
internalErr = ierrors.Wrapf(err, "unable to retrieve account %s to rollback in slot %d", accountID, slot)
Expand All @@ -297,6 +303,8 @@ func (m *Manager) Rollback(targetSlot iotago.SlotIndex) error {
return false
}

processedAccounts.Add(accountID)

return true
}); err != nil {
return ierrors.Wrapf(err, "error in streaming account diffs for slot %s", slot)
Expand Down
5 changes: 1 addition & 4 deletions pkg/protocol/engine/notarization/slotnotarization/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Manager struct {
acceptedTimeFunc func() time.Time
apiProvider iotago.APIProvider

commitmentMutex syncutils.RWMutex
commitmentMutex syncutils.Mutex

module.Module
}
Expand Down Expand Up @@ -170,9 +170,6 @@ func (m *Manager) IsBootstrapped() bool {
}

func (m *Manager) notarizeAcceptedBlock(block *blocks.Block) (err error) {
m.commitmentMutex.RLock()
defer m.commitmentMutex.RUnlock()

if err = m.slotMutations.AddAcceptedBlock(block); err != nil {
return ierrors.Wrap(err, "failed to add accepted block to slot mutations")
}
Expand Down

0 comments on commit 50023f0

Please sign in to comment.