Skip to content

Commit 2f4e850

Browse files
committed
sweep: add timeout when waiting for spending event
1 parent 04dc199 commit 2f4e850

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"
@@ -24,6 +25,10 @@ import (
2425
"github.com/lightningnetwork/lnd/tlv"
2526
)
2627

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+
2732
var (
2833
// ErrInvalidBumpResult is returned when the bump result is invalid.
2934
ErrInvalidBumpResult = errors.New("invalid bump result")
@@ -1467,6 +1472,20 @@ func (t *TxPublisher) getSpentInputs(
14671472
spendingTx.TxHash())
14681473

14691474
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)
14701489
}
14711490
}
14721491

0 commit comments

Comments
 (0)