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"
@@ -24,6 +25,10 @@ import (
24
25
"github.com/lightningnetwork/lnd/tlv"
25
26
)
26
27
28
+ // spentNotificationTimeout defines the time to wait for a spending event from
29
+ // `RegisterSpendNtfn` when an immediate response is expected.
30
+ const spentNotificationTimeout = 1 * time .Second
31
+
27
32
var (
28
33
// ErrInvalidBumpResult is returned when the bump result is invalid.
29
34
ErrInvalidBumpResult = errors .New ("invalid bump result" )
@@ -1467,6 +1472,25 @@ func (t *TxPublisher) getSpentInputs(
1467
1472
spendingTx .TxHash ())
1468
1473
1469
1474
spentInputs [op ] = spendingTx
1475
+
1476
+ // The above spent event should be returned immediately, yet we
1477
+ // still perform a timeout check here in case it blocks forever.
1478
+ //
1479
+ // TODO(yy): The proper way to fix this is to redesign the area
1480
+ // so we use the async flow for checking whether a given input
1481
+ // is spent or not. A better approach is to implement a new
1482
+ // synchronous method to check for spending, which should be
1483
+ // attempted when implementing SQL into btcwallet.
1484
+ case <- time .After (spentNotificationTimeout ):
1485
+ log .Errorf ("Input is reported as spent by GetUtxo, " +
1486
+ "but spending notification is not returned " +
1487
+ "immediately: input=%v, heightHint=%v" , op ,
1488
+ heightHint )
1489
+
1490
+ // Return with the inputs we've found so far. This
1491
+ // prevents us from treating this known-spent input as
1492
+ // unspent in this cycle.
1493
+ return spentInputs
1470
1494
}
1471
1495
}
1472
1496
0 commit comments