From 93981a85c0b47622a3a5e7089b8bca9b80b834c5 Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Thu, 9 Nov 2017 18:18:00 +1000 Subject: [PATCH] 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. --- chainntnfs/btcdnotify/btcd.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index a6b305afe..7001c59df 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -418,6 +418,8 @@ out: // attemptHistoricalDispatch tries to use historical information to decide if a // notification ca be dispatched immediately, or is partially confirmed so it // can skip straight to the confirmations heap. +// +// Returns true if the transaction was either partially or completely confirmed func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification, currentHeight int32) bool { @@ -489,7 +491,7 @@ func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification, } heap.Push(b.confHeap, heapEntry) - return false + return true } // notifyBlockEpochs notifies all registered block epoch clients of the newly