contractcourt+itest: fix lingering pending channel after breach

This fixes an issue where the contract court could leave a completely
swept commit tx unresolved if it was swept by the remote party.

This could happen if (our) commit tx just published was actually a
previously revoked state, in which case the remote party would claim the
funds via a justice transaction.

This manifested itself in the testRevokedCloseRetribution integration
test where at the end of the test Bob was left with a pending channel
that never resolved itself.
This commit is contained in:
Matheus Degiovani 2020-01-08 09:06:59 -03:00
parent 338e12ecd0
commit d71a4ee033
2 changed files with 30 additions and 5 deletions

@ -239,24 +239,40 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
// possible and publish the sweep tx. When the sweep tx
// confirms, it signals us through the result channel with the
// outcome. Wait for this to happen.
recovered := true
select {
case sweepResult := <-resultChan:
if sweepResult.Err != nil {
switch sweepResult.Err {
case sweep.ErrRemoteSpend:
// If the remote party was able to sweep this output
// it's likely what we sent was actually a revoked
// commitment. Report the error and continue to wrap up
// the contract.
c.log.Errorf("local commitment output was swept by "+
"remote party via %v", sweepResult.Tx.TxHash())
recovered = false
case nil:
// No errors, therefore continue processing.
c.log.Infof("local commitment output fully resolved by "+
"sweep tx: %v", sweepResult.Tx.TxHash())
default:
// Unknown errors.
c.log.Errorf("unable to sweep input: %v",
sweepResult.Err)
return nil, sweepResult.Err
}
c.log.Infof("commit tx fully resolved by sweep tx: %v",
sweepResult.Tx.TxHash())
case <-c.quit:
return nil, errResolverShuttingDown
}
// Funds have been swept and balance is no longer in limbo.
c.reportLock.Lock()
c.currentReport.RecoveredBalance = c.currentReport.LimboBalance
if recovered {
// We only record the balance as recovered if it actually came
// back to us.
c.currentReport.RecoveredBalance = c.currentReport.LimboBalance
}
c.currentReport.LimboBalance = 0
c.reportLock.Unlock()

@ -7586,6 +7586,15 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
}
assertNodeNumChannels(t, carol, 0)
// Mine enough blocks for Bob's channel arbitrator to wrap up the
// references to the breached channel. The chanarb waits for commitment
// tx's confHeight+CSV-1 blocks and since we've already mined one that
// included the justice tx we only need to mine extra DefaultCSV-2
// blocks to unlock it.
mineBlocks(t, net, lntest.DefaultCSV-2, 0)
assertNumPendingChannels(t, net.Bob, 0, 0)
}
// testRevokedCloseRetributionZeroValueRemoteOutput tests that Dave is able