Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1552 from NebulousLabs/ndf-fix
Browse files Browse the repository at this point in the history
make /consensus a blocking call - fix ndf
  • Loading branch information
lukechampine committed Jan 18, 2017
2 parents 3fa1ba4 + 3dee273 commit 6e87996
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions modules/consensus/consensusset.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ func (cs *ConsensusSet) CurrentBlock() (block types.Block) {
return types.Block{}
}
defer cs.tg.Done()
cs.mu.RLock()
defer cs.mu.RUnlock()

// Block until a lock can be grabbed on the consensus set, indicating that
// all modules have received the most recent block. The lock is held so that
// there are no race conditions when trying to synchronize nodes.
cs.mu.Lock()
defer cs.mu.Unlock()

_ = cs.db.View(func(tx *bolt.Tx) error {
pb := currentProcessedBlock(tx)
Expand All @@ -266,6 +270,12 @@ func (cs *ConsensusSet) Height() (height types.BlockHeight) {
}
defer cs.tg.Done()

// Block until a lock can be grabbed on the consensus set, indicating that
// all modules have received the most recent block. The lock is held so that
// there are no race conditions when trying to synchronize nodes.
cs.mu.Lock()
defer cs.mu.Unlock()

_ = cs.db.View(func(tx *bolt.Tx) error {
height = blockHeight(tx)
return nil
Expand Down

0 comments on commit 6e87996

Please sign in to comment.