Merge pull request #1581 from Roasbeef/async-rescan-btcd
chainntnfs/btcdnotify: switch to async rescan call for historical spe…
This commit is contained in:
commit
925879f0fc
@ -7,12 +7,12 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
|
||||||
"github.com/btcsuite/btcd/btcjson"
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -765,12 +765,21 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
|||||||
// and only arrives in the mempool after the getxout call.
|
// and only arrives in the mempool after the getxout call.
|
||||||
if blockHash != nil {
|
if blockHash != nil {
|
||||||
ops := []*wire.OutPoint{outpoint}
|
ops := []*wire.OutPoint{outpoint}
|
||||||
err = b.chainConn.Rescan(blockHash, nil, ops)
|
|
||||||
if err != nil {
|
// In order to ensure that we don't block the caller on
|
||||||
chainntnfs.Log.Errorf("Rescan for spend "+
|
// what may be a long rescan, we'll launch a new
|
||||||
"notification txout failed: %v", err)
|
// goroutine to handle the async result of the rescan.
|
||||||
return nil, err
|
asyncResult := b.chainConn.RescanAsync(
|
||||||
}
|
blockHash, nil, ops,
|
||||||
|
)
|
||||||
|
go func() {
|
||||||
|
rescanErr := asyncResult.Receive()
|
||||||
|
if rescanErr != nil {
|
||||||
|
chainntnfs.Log.Errorf("Rescan for spend "+
|
||||||
|
"notification txout(%x) "+
|
||||||
|
"failed: %v", outpoint, rescanErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user