chainntnfs: Fix btcdnotify dispatch race condition

This race condition can occur if a transaction is included in a block
right when a notification is being added to the notifier for it AND when
the confirmation requires > 1 confirmations. In this case, the
confirmation gets added to the confirmation heap twice.
This commit is contained in:
Sam Lewis 2017-11-09 18:18:00 +10:00 committed by Olaoluwa Osuntokun
parent b3509d491a
commit 93981a85c0

@ -418,6 +418,8 @@ out:
// attemptHistoricalDispatch tries to use historical information to decide if a // attemptHistoricalDispatch tries to use historical information to decide if a
// notification ca be dispatched immediately, or is partially confirmed so it // notification ca be dispatched immediately, or is partially confirmed so it
// can skip straight to the confirmations heap. // can skip straight to the confirmations heap.
//
// Returns true if the transaction was either partially or completely confirmed
func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification, func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification,
currentHeight int32) bool { currentHeight int32) bool {
@ -489,7 +491,7 @@ func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification,
} }
heap.Push(b.confHeap, heapEntry) heap.Push(b.confHeap, heapEntry)
return false return true
} }
// notifyBlockEpochs notifies all registered block epoch clients of the newly // notifyBlockEpochs notifies all registered block epoch clients of the newly