sweep: remove previous exclusive group upon re-offered inputs

This aims to cover an edge case and also serves as an optimization of
what happens when an input that was offered to the Sweeper with an
exclusive group is re-offered without one. This happens every time we
attempt to sweep the different possible anchors of a channel at the time
of broadcast, as we don't know which commitment transaction will end up
confirming in the chain. Once the commitment transaction confirms
however, we know which anchor output to act upon and re-offer it to the
Sweeper without an exclusive group. At this point, the Sweeper will
continue to attempt sweeping the other anchor output versions even know
we know they are not valid.
This commit is contained in:
Wilmer Paulino 2021-07-14 17:19:22 -07:00 committed by Olaoluwa Osuntokun
parent 5faf3dc03b
commit e1c269c7ed
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

View File

@ -459,9 +459,11 @@ func (s *UtxoSweeper) SweepInput(input input.Input,
return nil, err
}
absoluteTimeLock, _ := input.RequiredLockTime()
log.Infof("Sweep request received: out_point=%v, witness_type=%v, "+
"time_lock=%v, amount=%v, params=(%v)",
input.OutPoint(), input.WitnessType(), input.BlocksToMaturity(),
"relative_time_lock=%v, absolute_time_lock=%v, amount=%v, "+
"params=(%v)", input.OutPoint(), input.WitnessType(),
input.BlocksToMaturity(), absoluteTimeLock,
btcutil.Amount(input.SignDesc().Output.Value), params)
sweeperInput := &sweepInputMessage{
@ -534,6 +536,17 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) {
log.Debugf("Already pending input %v received",
outpoint)
// Before updating the input details, check if
// an exclusive group was set, and if so, assume
// this input as finalized and remove all other
// inputs belonging to the same exclusive group.
var prevExclGroup *uint64
if pendInput.params.ExclusiveGroup != nil &&
input.params.ExclusiveGroup == nil {
prevExclGroup = new(uint64)
*prevExclGroup = *pendInput.params.ExclusiveGroup
}
// Update input details and sweep parameters.
// The re-offered input details may contain a
// change to the unconfirmed parent tx info.
@ -545,6 +558,11 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) {
pendInput.listeners = append(
pendInput.listeners, input.resultChan,
)
if prevExclGroup != nil {
s.removeExclusiveGroup(*prevExclGroup)
}
continue
}