55 "fmt"
66 "sync"
77 "sync/atomic"
8+ "time"
89
910 "github.com/btcsuite/btcd/btcutil"
1011 "github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -25,6 +26,10 @@ import (
2526 "github.com/lightningnetwork/lnd/tlv"
2627)
2728
29+ // spentNotificationTimeout defines the time to wait for a spending event from
30+ // `RegisterSpendNtfn` when an immediate response is expected.
31+ const spentNotificationTimeout = 1 * time .Second
32+
2833var (
2934 // ErrInvalidBumpResult is returned when the bump result is invalid.
3035 ErrInvalidBumpResult = errors .New ("invalid bump result" )
@@ -1482,6 +1487,20 @@ func (t *TxPublisher) getSpentInputs(
14821487 spendingTx .TxHash ())
14831488
14841489 spentInputs [op ] = spendingTx
1490+
1491+ // The above spent event should be returned immediately, yet we
1492+ // still perform a timeout check here in case it blocks forever.
1493+ //
1494+ // TODO(yy): The proper way to fix this is to redesign the area
1495+ // so we use the async flow for checking whether a given input
1496+ // is spent or not. A better approach is to implement a new
1497+ // synchronous method to check for spending, which should be
1498+ // attempted when implementing SQL into btcwallet.
1499+ case <- time .After (spentNotificationTimeout ):
1500+ log .Warnf ("Input is reported as spent by GetUtxo, " +
1501+ "but spending notification is not returned " +
1502+ "immediately: input=%v, heightHint=%v" , op ,
1503+ heightHint )
14851504 }
14861505 }
14871506
0 commit comments