mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-09 18:52:09 +02:00
chainntfns/btcdnotifier: fix race condition in notifyBlockEpochs
This commit fixes a race condition in the notifyBlockEpochs detected by the race condition detector. Previously the notifyBlockEpochs function could cause a race condition when a new caller was either cancelling an existing notification intent or creating a new one. We fix this issue by making the call to notifyBlockEpochs synchronous rather than asynchronous. An alternative would be to add a mutex guarding the map state. The channel itself is buffered with a good margin, so there shouldn’t be a huge impact.
This commit is contained in:
@@ -319,8 +319,7 @@ out:
|
|||||||
chainntnfs.Log.Infof("New block: height=%v, sha=%v",
|
chainntnfs.Log.Infof("New block: height=%v, sha=%v",
|
||||||
update.blockHeight, update.blockHash)
|
update.blockHeight, update.blockHash)
|
||||||
|
|
||||||
b.wg.Add(1)
|
b.notifyBlockEpochs(update.blockHeight,
|
||||||
go b.notifyBlockEpochs(update.blockHeight,
|
|
||||||
update.blockHash)
|
update.blockHash)
|
||||||
|
|
||||||
newHeight := update.blockHeight
|
newHeight := update.blockHeight
|
||||||
@@ -469,8 +468,6 @@ func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification,
|
|||||||
// notifyBlockEpochs notifies all registered block epoch clients of the newly
|
// notifyBlockEpochs notifies all registered block epoch clients of the newly
|
||||||
// connected block to the main chain.
|
// connected block to the main chain.
|
||||||
func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash) {
|
func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash) {
|
||||||
defer b.wg.Done()
|
|
||||||
|
|
||||||
epoch := &chainntnfs.BlockEpoch{
|
epoch := &chainntnfs.BlockEpoch{
|
||||||
Height: newHeight,
|
Height: newHeight,
|
||||||
Hash: newSha,
|
Hash: newSha,
|
||||||
|
Reference in New Issue
Block a user