chainntfns: Fix off by 1 block height error

In the historical dispatch of btcdnotify, the dispatcher checks if a
transaction has been included in a block. If this check happens before
the notifier has processed the update, it's possible that the
currentHeight of the notifier and the currentHeight of the chain might
be out of sync which causes an off by one error when calculating a
target height for the transaction confirmation. This change uses the
height of the block the transaction was found in, rather than the
currentHeight that's known by the notifier to eliminate this.
This commit is contained in:
Sam Lewis 2017-11-09 21:18:13 +10:00 committed by Olaoluwa Osuntokun
parent 93981a85c0
commit 1f95b660b9
1 changed files with 5 additions and 5 deletions

View File

@ -295,7 +295,7 @@ out:
// If the notification can be partially or
// fully dispatched, then we can skip the first
// phase for ntfns.
if b.attemptHistoricalDispatch(msg, currentHeight) {
if b.attemptHistoricalDispatch(msg) {
continue
}
@ -420,8 +420,8 @@ out:
// 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 {
func (b *BtcdNotifier) attemptHistoricalDispatch(
msg *confirmationsNotification) bool {
chainntnfs.Log.Infof("Attempting to trigger dispatch for %v from "+
"historical chain", msg.txid)
@ -482,8 +482,8 @@ func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification,
// Otherwise, the transaction has only been *partially* confirmed, so
// we need to insert it into the confirmation heap.
confsLeft := msg.numConfirmations - uint32(tx.Confirmations)
confHeight := uint32(currentHeight) + confsLeft
// Find the block height at which this transaction will be confirmed
confHeight := uint32(block.Height) + msg.numConfirmations - 1
heapEntry := &confEntry{
msg,
confDetails,