chainntnfs: make historical confirmation rescans async
This commit is contained in:
1 parent
867d8524bf
commit
12816a910d
3 files changed
+137
-53
No files matched your search
@@ -299,24 +299,42 @@ out:
|
||||
b.spendNotifications[op] = make(map[uint64]*spendNotification)
|
||||
}
|
||||
b.spendNotifications[op][msg.spendID] = msg
|
||||
|
||||
case *confirmationNotification:
|
||||
chainntnfs.Log.Infof("New confirmation "+
|
||||
"subscription: txid=%v, numconfs=%v",
|
||||
msg.TxID, msg.NumConfirmations)
|
||||
|
||||
// Lookup whether the transaction is already included in the
|
||||
// active chain.
|
||||
txConf, err := b.historicalConfDetails(
|
||||
msg.TxID, msg.heightHint, uint32(currentHeight),
|
||||
)
|
||||
if err != nil {
|
||||
chainntnfs.Log.Error(err)
|
||||
}
|
||||
bestHeight := uint32(currentHeight)
|
||||
|
||||
// Look up whether the transaction is already
|
||||
// included in the active chain. We'll do this
|
||||
// in a goroutine to prevent blocking
|
||||
// potentially long rescans.
|
||||
b.wg.Add(1)
|
||||
go func() {
|
||||
defer b.wg.Done()
|
||||
|
||||
confDetails, err := b.historicalConfDetails(
|
||||
msg.TxID, msg.heightHint,
|
||||
bestHeight,
|
||||
)
|
||||
if err != nil {
|
||||
chainntnfs.Log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if confDetails != nil {
|
||||
err = b.txConfNotifier.UpdateConfDetails(
|
||||
*msg.TxID, msg.ConfID,
|
||||
confDetails,
|
||||
)
|
||||
if err != nil {
|
||||
chainntnfs.Log.Error(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = b.txConfNotifier.Register(&msg.ConfNtfn, txConf)
|
||||
if err != nil {
|
||||
chainntnfs.Log.Error(err)
|
||||
}
|
||||
case *blockEpochRegistration:
|
||||
chainntnfs.Log.Infof("New block epoch subscription")
|
||||
b.blockEpochClients[msg.epochID] = msg
|
||||
@@ -533,6 +551,14 @@ func (b *BtcdNotifier) confDetailsManually(txid *chainhash.Hash,
|
||||
// Begin scanning blocks at every height to determine where the
|
||||
// transaction was included in.
|
||||
for height := heightHint; height <= currentHeight; height++ {
|
||||
// Ensure we haven't been requested to shut down before
|
||||
// processing the next height.
|
||||
select {
|
||||
case <-b.quit:
|
||||
return nil, ErrChainNotifierShuttingDown
|
||||
default:
|
||||
}
|
||||
|
||||
blockHash, err := b.chainConn.GetBlockHash(int64(height))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get hash from block "+
|
||||
@@ -809,11 +835,15 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
|
||||
heightHint: heightHint,
|
||||
}
|
||||
|
||||
if err := b.txConfNotifier.Register(&ntfn.ConfNtfn); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
select {
|
||||
case <-b.quit:
|
||||
return nil, ErrChainNotifierShuttingDown
|
||||
case b.notificationRegistry <- ntfn:
|
||||
return ntfn.Event, nil
|
||||
case <-b.quit:
|
||||
return nil, ErrChainNotifierShuttingDown
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user