5
5
"fmt"
6
6
"sync"
7
7
"sync/atomic"
8
+ "time"
8
9
9
10
"github.com/btcsuite/btcd/btcutil"
10
11
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -25,6 +26,10 @@ import (
25
26
"github.com/lightningnetwork/lnd/tlv"
26
27
)
27
28
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
+
28
33
var (
29
34
// ErrInvalidBumpResult is returned when the bump result is invalid.
30
35
ErrInvalidBumpResult = errors .New ("invalid bump result" )
@@ -1482,6 +1487,20 @@ func (t *TxPublisher) getSpentInputs(
1482
1487
spendingTx .TxHash ())
1483
1488
1484
1489
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 )
1485
1504
}
1486
1505
}
1487
1506
0 commit comments