chainntnfs/btcd: use HistoricalConfDispatch in ntfn registry
This commit is contained in:
parent
a4c9f62c6b
commit
6cd0f867ad
@ -324,13 +324,7 @@ out:
|
|||||||
}
|
}
|
||||||
b.spendNotifications[op][msg.spendID] = msg
|
b.spendNotifications[op][msg.spendID] = msg
|
||||||
|
|
||||||
case *chainntnfs.ConfNtfn:
|
case *chainntnfs.HistoricalConfDispatch:
|
||||||
chainntnfs.Log.Infof("New confirmation "+
|
|
||||||
"subscription: txid=%v, numconfs=%v",
|
|
||||||
msg.TxID, msg.NumConfirmations)
|
|
||||||
|
|
||||||
bestHeight := uint32(b.bestBlock.Height)
|
|
||||||
|
|
||||||
// Look up whether the transaction is already
|
// Look up whether the transaction is already
|
||||||
// included in the active chain. We'll do this
|
// included in the active chain. We'll do this
|
||||||
// in a goroutine to prevent blocking
|
// in a goroutine to prevent blocking
|
||||||
@ -340,8 +334,7 @@ out:
|
|||||||
defer b.wg.Done()
|
defer b.wg.Done()
|
||||||
|
|
||||||
confDetails, _, err := b.historicalConfDetails(
|
confDetails, _, err := b.historicalConfDetails(
|
||||||
msg.TxID, msg.HeightHint,
|
msg.TxID, msg.StartHeight, msg.EndHeight,
|
||||||
bestHeight,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
chainntnfs.Log.Error(err)
|
chainntnfs.Log.Error(err)
|
||||||
@ -356,8 +349,7 @@ out:
|
|||||||
// cache at tip, since any pending
|
// cache at tip, since any pending
|
||||||
// rescans have now completed.
|
// rescans have now completed.
|
||||||
err = b.txConfNotifier.UpdateConfDetails(
|
err = b.txConfNotifier.UpdateConfDetails(
|
||||||
*msg.TxID, msg.ConfID,
|
*msg.TxID, confDetails,
|
||||||
confDetails,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
chainntnfs.Log.Error(err)
|
chainntnfs.Log.Error(err)
|
||||||
@ -523,7 +515,7 @@ out:
|
|||||||
// historicalConfDetails looks up whether a transaction is already included in a
|
// historicalConfDetails looks up whether a transaction is already included in a
|
||||||
// block in the active chain and, if so, returns details about the confirmation.
|
// block in the active chain and, if so, returns details about the confirmation.
|
||||||
func (b *BtcdNotifier) historicalConfDetails(txid *chainhash.Hash,
|
func (b *BtcdNotifier) historicalConfDetails(txid *chainhash.Hash,
|
||||||
heightHint, currentHeight uint32) (*chainntnfs.TxConfirmation,
|
startHeight, endHeight uint32) (*chainntnfs.TxConfirmation,
|
||||||
chainntnfs.TxConfStatus, error) {
|
chainntnfs.TxConfStatus, error) {
|
||||||
|
|
||||||
// We'll first attempt to retrieve the transaction using the node's
|
// We'll first attempt to retrieve the transaction using the node's
|
||||||
@ -539,7 +531,7 @@ func (b *BtcdNotifier) historicalConfDetails(txid *chainhash.Hash,
|
|||||||
case err != nil:
|
case err != nil:
|
||||||
chainntnfs.Log.Debugf("Failed getting conf details from "+
|
chainntnfs.Log.Debugf("Failed getting conf details from "+
|
||||||
"index (%v), scanning manually", err)
|
"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.
|
// The transaction was found within the node's mempool.
|
||||||
case txStatus == chainntnfs.TxFoundMempool:
|
case txStatus == chainntnfs.TxFoundMempool:
|
||||||
@ -638,15 +630,15 @@ func (b *BtcdNotifier) confDetailsFromTxIndex(txid *chainhash.Hash,
|
|||||||
// earliest height the transaction could have been included in, to the current
|
// earliest height the transaction could have been included in, to the current
|
||||||
// height in the chain. If the transaction is found, its confirmation details
|
// height in the chain. If the transaction is found, its confirmation details
|
||||||
// are returned. Otherwise, nil is returned.
|
// are returned. Otherwise, nil is returned.
|
||||||
func (b *BtcdNotifier) confDetailsManually(txid *chainhash.Hash, heightHint,
|
func (b *BtcdNotifier) confDetailsManually(txid *chainhash.Hash, startHeight,
|
||||||
currentHeight uint32) (*chainntnfs.TxConfirmation,
|
endHeight uint32) (*chainntnfs.TxConfirmation,
|
||||||
chainntnfs.TxConfStatus, error) {
|
chainntnfs.TxConfStatus, error) {
|
||||||
|
|
||||||
targetTxidStr := txid.String()
|
targetTxidStr := txid.String()
|
||||||
|
|
||||||
// Begin scanning blocks at every height to determine where the
|
// Begin scanning blocks at every height to determine where the
|
||||||
// transaction was included in.
|
// transaction was included in.
|
||||||
for height := heightHint; height <= currentHeight; height++ {
|
for height := startHeight; height <= endHeight; height++ {
|
||||||
// Ensure we haven't been requested to shut down before
|
// Ensure we haven't been requested to shut down before
|
||||||
// processing the next height.
|
// processing the next height.
|
||||||
select {
|
select {
|
||||||
@ -1024,12 +1016,24 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, _ []byte,
|
|||||||
HeightHint: heightHint,
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dispatch == nil {
|
||||||
|
return ntfn.Event, nil
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case b.notificationRegistry <- ntfn:
|
case b.notificationRegistry <- dispatch:
|
||||||
return ntfn.Event, nil
|
return ntfn.Event, nil
|
||||||
case <-b.quit:
|
case <-b.quit:
|
||||||
return nil, ErrChainNotifierShuttingDown
|
return nil, ErrChainNotifierShuttingDown
|
||||||
|
Loading…
Reference in New Issue
Block a user