Merge pull request #3154 from halseth/chainntfs-neutrino-async-getutxo
neutrinonotify: async call GetUtxo from RegisterSpendNtfn
This commit is contained in:
commit
0139300a00
@ -740,10 +740,14 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// With the filter updated, we'll dispatch our historical rescan to
|
// With the filter updated, we'll dispatch our historical rescan to
|
||||||
// ensure we detect the spend if it happened in the past. We'll ensure
|
// ensure we detect the spend if it happened in the past.
|
||||||
// that neutrino is caught up to the starting height before we attempt
|
n.wg.Add(1)
|
||||||
// to fetch the UTXO from the chain. If we're behind, then we may miss a
|
go func() {
|
||||||
// notification dispatch.
|
defer n.wg.Done()
|
||||||
|
|
||||||
|
// We'll ensure that neutrino is caught up to the starting
|
||||||
|
// height before we attempt to fetch the UTXO from the chain.
|
||||||
|
// If we're behind, then we may miss a notification dispatch.
|
||||||
for {
|
for {
|
||||||
n.bestBlockMtx.RLock()
|
n.bestBlockMtx.RLock()
|
||||||
currentHeight := uint32(n.bestBlock.Height)
|
currentHeight := uint32(n.bestBlock.Height)
|
||||||
@ -753,7 +757,11 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 200)
|
select {
|
||||||
|
case <-time.After(time.Millisecond * 200):
|
||||||
|
case <-n.quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spendReport, err := n.p2pNode.GetUtxo(
|
spendReport, err := n.p2pNode.GetUtxo(
|
||||||
@ -767,7 +775,8 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
|||||||
neutrino.QuitChan(n.quit),
|
neutrino.QuitChan(n.quit),
|
||||||
)
|
)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
return nil, err
|
chainntnfs.Log.Errorf("Failed getting UTXO: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a spend report was returned, and the transaction is present, then
|
// If a spend report was returned, and the transaction is present, then
|
||||||
@ -790,8 +799,10 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
|||||||
// blocks.
|
// blocks.
|
||||||
err = n.txNotifier.UpdateSpendDetails(spendRequest, spendDetails)
|
err = n.txNotifier.UpdateSpendDetails(spendRequest, spendDetails)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
chainntnfs.Log.Errorf("Failed to update spend details: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
return ntfn.Event, nil
|
return ntfn.Event, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user