Skip to content

Commit ea6c132

Browse files
committed
sweep: add timeout when waiting for spending event
1 parent 5502d91 commit ea6c132

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sweep/fee_bumper.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
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+
2833
var (
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

Comments
 (0)