chainntnfs/btcdnotify: recognize JSON-RPC error in RegisterSpendNtfn
This commit fixes a prior bug in the logic for registering a new spend notification. Previously, if the transaction wasn’t found in the mempool or already confirmed within the chain, then GetRawTransactionVerbose would return an error which would cause the function itself to exit with an error. This issue would then cause the server to be unable to start up as the breach arbiter would be unable to register for spend notifications for all the channels that it needed to be watching. We fix this error simply by recognizing the particular JSON-RPC error that will be returned in this scenario and treating it as a benign error.
This commit is contained in:
parent
ed7eae819a
commit
5044cd6468
@ -506,6 +506,8 @@ func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash
|
||||
go func(ntfnChan chan *chainntnfs.BlockEpoch, cancelChan chan struct{},
|
||||
clientWg *sync.WaitGroup) {
|
||||
|
||||
// TODO(roasbeef): move to goroutine per client, use sync queue
|
||||
|
||||
defer clientWg.Done()
|
||||
defer b.wg.Done()
|
||||
|
||||
@ -664,18 +666,26 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
||||
if txout == nil {
|
||||
transaction, err := b.chainConn.GetRawTransactionVerbose(&outpoint.Hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
jsonErr, ok := err.(*btcjson.RPCError)
|
||||
switch {
|
||||
case ok && jsonErr.Code == -5:
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
blockhash, err := chainhash.NewHashFromStr(transaction.BlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if transaction != nil {
|
||||
blockhash, err := chainhash.NewHashFromStr(transaction.BlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ops := []*wire.OutPoint{outpoint}
|
||||
if err := b.chainConn.Rescan(blockhash, nil, ops); err != nil {
|
||||
chainntnfs.Log.Errorf("Rescan for spend notification txout failed: %v", err)
|
||||
return nil, err
|
||||
ops := []*wire.OutPoint{outpoint}
|
||||
if err := b.chainConn.Rescan(blockhash, nil, ops); err != nil {
|
||||
chainntnfs.Log.Errorf("Rescan for spend "+
|
||||
"notification txout failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user