@@ -221,6 +221,30 @@ func (p *SweeperInput) terminated() bool {
221
221
}
222
222
}
223
223
224
+ // isMature returns a boolean indicating whether the input has a timelock that
225
+ // has been reached or not. The locktime found is also returned.
226
+ func (p * SweeperInput ) isMature (currentHeight uint32 ) (bool , uint32 ) {
227
+ locktime , _ := p .RequiredLockTime ()
228
+ if currentHeight < locktime {
229
+ log .Debugf ("Input %v has locktime=%v, current height is %v" ,
230
+ p .OutPoint (), locktime , currentHeight )
231
+
232
+ return false , locktime
233
+ }
234
+
235
+ // If the input has a CSV that's not yet reached, we will skip
236
+ // this input and wait for the expiry.
237
+ locktime = p .BlocksToMaturity () + p .HeightHint ()
238
+ if currentHeight + 1 < locktime {
239
+ log .Debugf ("Input %v has CSV expiry=%v, current height is %v" ,
240
+ p .OutPoint (), locktime , currentHeight )
241
+
242
+ return false , locktime
243
+ }
244
+
245
+ return true , locktime
246
+ }
247
+
224
248
// InputsMap is a type alias for a set of pending inputs.
225
249
type InputsMap = map [wire.OutPoint ]* SweeperInput
226
250
@@ -1027,6 +1051,12 @@ func (s *UtxoSweeper) handlePendingSweepsReq(
1027
1051
1028
1052
resps := make (map [wire.OutPoint ]* PendingInputResponse , len (s .inputs ))
1029
1053
for _ , inp := range s .inputs {
1054
+ // Skip immature inputs for compatibility.
1055
+ mature , _ := inp .isMature (uint32 (s .currentHeight ))
1056
+ if ! mature {
1057
+ continue
1058
+ }
1059
+
1030
1060
// Only the exported fields are set, as we expect the response
1031
1061
// to only be consumed externally.
1032
1062
op := inp .OutPoint ()
@@ -1477,20 +1507,9 @@ func (s *UtxoSweeper) updateSweeperInputs() InputsMap {
1477
1507
1478
1508
// If the input has a locktime that's not yet reached, we will
1479
1509
// skip this input and wait for the locktime to be reached.
1480
- locktime , _ := input .RequiredLockTime ()
1481
- if uint32 (s .currentHeight ) < locktime {
1482
- log .Warnf ("Skipping input %v due to locktime=%v not " +
1483
- "reached, current height is %v" , op , locktime ,
1484
- s .currentHeight )
1485
-
1486
- continue
1487
- }
1488
-
1489
- // If the input has a CSV that's not yet reached, we will skip
1490
- // this input and wait for the expiry.
1491
- locktime = input .BlocksToMaturity () + input .HeightHint ()
1492
- if s .currentHeight < int32 (locktime )- 1 {
1493
- log .Infof ("Skipping input %v due to CSV expiry=%v not " +
1510
+ mature , locktime := input .isMature (uint32 (s .currentHeight ))
1511
+ if ! mature {
1512
+ log .Infof ("Skipping input %v due to locktime=%v not " +
1494
1513
"reached, current height is %v" , op , locktime ,
1495
1514
s .currentHeight )
1496
1515
0 commit comments