@@ -740,15 +740,23 @@ func (s *UtxoSweeper) collector() {
740740 }
741741}
742742
743- // removeExclusiveGroup removes all inputs in the given exclusive group. This
744- // function is called when one of the exclusive group inputs has been spent. The
745- // other inputs won't ever be spendable and can be removed. This also prevents
746- // them from being part of future sweep transactions that would fail. In
747- // addition sweep transactions of those inputs will be removed from the wallet.
748- func (s * UtxoSweeper ) removeExclusiveGroup (group uint64 ) {
743+ // removeExclusiveGroup removes all inputs in the given exclusive group except
744+ // the input specified by the outpoint. This function is called when one of the
745+ // exclusive group inputs has been spent or updated. The other inputs won't ever
746+ // be spendable and can be removed. This also prevents them from being part of
747+ // future sweep transactions that would fail. In addition sweep transactions of
748+ // those inputs will be removed from the wallet.
749+ func (s * UtxoSweeper ) removeExclusiveGroup (group uint64 , op wire.OutPoint ) {
749750 for outpoint , input := range s .inputs {
750751 outpoint := outpoint
751752
753+ // Skip the input that caused the exclusive group to be removed.
754+ if outpoint == op {
755+ log .Debugf ("Skipped removing exclusive input %v" , input )
756+
757+ continue
758+ }
759+
752760 // Skip inputs that aren't exclusive.
753761 if input .params .ExclusiveGroup == nil {
754762 continue
@@ -767,6 +775,8 @@ func (s *UtxoSweeper) removeExclusiveGroup(group uint64) {
767775 continue
768776 }
769777
778+ log .Debugf ("Removing exclusive group for input %v" , input )
779+
770780 // Signal result channels.
771781 s .signalResult (input , Result {
772782 Err : ErrExclusiveGroupSpend ,
@@ -1367,22 +1377,19 @@ func (s *UtxoSweeper) decideRBFInfo(
13671377func (s * UtxoSweeper ) handleExistingInput (input * sweepInputMessage ,
13681378 oldInput * SweeperInput ) {
13691379
1370- // Before updating the input details, check if an exclusive group was
1371- // set. In case the same input is registered again without an exclusive
1372- // group set, the previous input and its sweep parameters are outdated
1373- // hence need to be replaced. This scenario currently only happens for
1374- // anchor outputs. When a channel is force closed, in the worst case 3
1375- // different sweeps with the same exclusive group are registered with
1376- // the sweeper to bump the closing transaction (cpfp) when its time
1377- // critical. Receiving an input which was already registered with the
1378- // sweeper but now without an exclusive group means non of the previous
1379- // inputs were used as CPFP, so we need to make sure we update the
1380- // sweep parameters but also remove all inputs with the same exclusive
1381- // group because the are outdated too.
1380+ // Before updating the input details, check if a previous exclusive
1381+ // group was set. In case the same input is registered again, the
1382+ // previous input and its sweep parameters are outdated hence need to be
1383+ // replaced. This scenario currently only happens for anchor outputs.
1384+ // When a channel is force closed, in the worst case 3 different sweeps
1385+ // with the same exclusive group are registered with the sweeper to bump
1386+ // the closing transaction (cpfp) when its time critical. Receiving an
1387+ // input which was already registered with the sweeper means none of the
1388+ // previous inputs were used as CPFP, so we need to make sure we update
1389+ // the sweep parameters but also remove all inputs with the same
1390+ // exclusive group because they are outdated too.
13821391 var prevExclGroup * uint64
1383- if oldInput .params .ExclusiveGroup != nil &&
1384- input .params .ExclusiveGroup == nil {
1385-
1392+ if oldInput .params .ExclusiveGroup != nil {
13861393 prevExclGroup = new (uint64 )
13871394 * prevExclGroup = * oldInput .params .ExclusiveGroup
13881395 }
@@ -1401,7 +1408,7 @@ func (s *UtxoSweeper) handleExistingInput(input *sweepInputMessage,
14011408 oldInput .listeners = append (oldInput .listeners , input .resultChan )
14021409
14031410 if prevExclGroup != nil {
1404- s .removeExclusiveGroup (* prevExclGroup )
1411+ s .removeExclusiveGroup (* prevExclGroup , input . input . OutPoint () )
14051412 }
14061413}
14071414
@@ -1493,7 +1500,9 @@ func (s *UtxoSweeper) markInputsSwept(tx *wire.MsgTx, isOurTx bool) {
14931500
14941501 // Remove all other inputs in this exclusive group.
14951502 if input .params .ExclusiveGroup != nil {
1496- s .removeExclusiveGroup (* input .params .ExclusiveGroup )
1503+ s .removeExclusiveGroup (
1504+ * input .params .ExclusiveGroup , outpoint ,
1505+ )
14971506 }
14981507 }
14991508}
@@ -1908,7 +1917,9 @@ func (s *UtxoSweeper) markInputSwept(inp *SweeperInput, tx *wire.MsgTx) {
19081917
19091918 // Remove all other inputs in this exclusive group.
19101919 if inp .params .ExclusiveGroup != nil {
1911- s .removeExclusiveGroup (* inp .params .ExclusiveGroup )
1920+ s .removeExclusiveGroup (
1921+ * inp .params .ExclusiveGroup , inp .OutPoint (),
1922+ )
19121923 }
19131924}
19141925
0 commit comments