Skip to content
Merged
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
15 changes: 8 additions & 7 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,12 @@ func (c *Chain) iterNext(
iter *ChainIterator,
blocking bool,
) (*ChainIteratorResult, error) {
c.mutex.RLock()
c.mutex.Lock()
// We get a read lock on the manager for the integrity check and initial block lookup
c.manager.mutex.RLock()
// Verify chain integrity
if err := c.reconcile(); err != nil {
c.mutex.Unlock()
c.manager.mutex.RUnlock()
return nil, err
}
Expand All @@ -402,13 +403,13 @@ func (c *Chain) iterNext(
// Lookup block index for rollback point
tmpBlock, err := c.manager.blockByPoint(iter.rollbackPoint, nil)
if err != nil {
c.mutex.RUnlock()
c.mutex.Unlock()
c.manager.mutex.RUnlock()
return nil, err
}
iter.nextBlockIndex = tmpBlock.ID + 1
}
c.mutex.RUnlock()
c.mutex.Unlock()
c.manager.mutex.RUnlock()
return ret, nil
}
Expand All @@ -421,23 +422,23 @@ func (c *Chain) iterNext(
ret.Block = tmpBlock
iter.nextBlockIndex++
iter.lastPoint = ret.Point
c.mutex.RUnlock()
c.mutex.Unlock()
c.manager.mutex.RUnlock()
return ret, nil
}
// Return any actual error
if !errors.Is(err, ErrBlockNotFound) {
c.mutex.RUnlock()
c.mutex.Unlock()
c.manager.mutex.RUnlock()
return ret, err
}
// Return immediately if we're not blocking
if !blocking {
c.mutex.RUnlock()
c.mutex.Unlock()
c.manager.mutex.RUnlock()
return nil, ErrIteratorChainTip
}
c.mutex.RUnlock()
c.mutex.Unlock()
c.manager.mutex.RUnlock()
// Wait for chain update
c.waitingChanMutex.Lock()
Expand Down
Loading