chainntnfs/bitcoind: use HistoricalConfDispatch in ntfn registry

This commit is contained in:
Conner Fromknecht 2018-08-26 21:36:17 -07:00
parent 11c231d814
commit a4c9f62c6b
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -254,13 +254,7 @@ out:
}
b.spendNotifications[op][msg.spendID] = msg
case *chainntnfs.ConfNtfn:
chainntnfs.Log.Infof("New confirmation "+
"subscription: txid=%v, numconfs=%v",
msg.TxID, msg.NumConfirmations)
currentHeight := uint32(b.bestBlock.Height)
case *chainntnfs.HistoricalConfDispatch:
// Look up whether the transaction is already
// included in the active chain. We'll do this
// in a goroutine to prevent blocking
@ -270,8 +264,7 @@ out:
defer b.wg.Done()
confDetails, _, err := b.historicalConfDetails(
msg.TxID, msg.HeightHint,
currentHeight,
msg.TxID, msg.StartHeight, msg.EndHeight,
)
if err != nil {
chainntnfs.Log.Error(err)
@ -286,8 +279,7 @@ out:
// cache at tip, since any pending
// rescans have now completed.
err = b.txConfNotifier.UpdateConfDetails(
*msg.TxID, msg.ConfID,
confDetails,
*msg.TxID, confDetails,
)
if err != nil {
chainntnfs.Log.Error(err)
@ -453,7 +445,7 @@ func (b *BitcoindNotifier) handleRelevantTx(tx chain.RelevantTx, bestHeight int3
// historicalConfDetails looks up whether a transaction is already included in a
// block in the active chain and, if so, returns details about the confirmation.
func (b *BitcoindNotifier) historicalConfDetails(txid *chainhash.Hash,
heightHint, currentHeight uint32) (*chainntnfs.TxConfirmation,
startHeight, endHeight uint32) (*chainntnfs.TxConfirmation,
chainntnfs.TxConfStatus, error) {
// We'll first attempt to retrieve the transaction using the node's
@ -469,7 +461,7 @@ func (b *BitcoindNotifier) historicalConfDetails(txid *chainhash.Hash,
case err != nil:
chainntnfs.Log.Debugf("Failed getting conf details from "+
"index (%v), scanning manually", err)
return b.confDetailsManually(txid, heightHint, currentHeight)
return b.confDetailsManually(txid, startHeight, endHeight)
// The transaction was found within the node's mempool.
case txStatus == chainntnfs.TxFoundMempool:
@ -964,12 +956,24 @@ func (b *BitcoindNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
HeightHint: heightHint,
}
if err := b.txConfNotifier.Register(ntfn); err != nil {
chainntnfs.Log.Infof("New confirmation subscription: "+
"txid=%v, numconfs=%v", txid, numConfs)
// Register the conf notification with txconfnotifier. A non-nil value
// for `dispatch` will be returned if we are required to perform a
// manual scan for the confirmation. Otherwise the notifier will begin
// watching at tip for the transaction to confirm.
dispatch, err := b.txConfNotifier.Register(ntfn)
if err != nil {
return nil, err
}
if dispatch == nil {
return ntfn.Event, nil
}
select {
case b.notificationRegistry <- ntfn:
case b.notificationRegistry <- dispatch:
return ntfn.Event, nil
case <-b.quit:
return nil, ErrChainNotifierShuttingDown