breacharbiter: also listen for the co-op chan close signal

This commit is contained in:
Olaoluwa Osuntokun 2018-01-19 17:25:06 -08:00
parent 91d45b37ba
commit 0d75dde153
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 19 additions and 29 deletions

@ -544,6 +544,22 @@ func (b *breachArbiter) breachObserver(
case <-settleSignal:
return
// The channel has been closed cooperatively, so we're done here.
case <-chainEvents.CooperativeClosure:
// Launch a goroutine to cancel out this contract within the
// breachArbiter's main goroutine.
b.wg.Add(1)
go func() {
defer b.wg.Done()
select {
case b.settledContracts <- &chanPoint:
case <-b.quit:
}
}()
b.cfg.CloseLink(&chanPoint, htlcswitch.CloseBreach)
// The channel has been closed by a normal means: force closing with
// the latest commitment transaction.
case <-chainEvents.UnilateralClosure:

@ -12,7 +12,6 @@ import (
"reflect"
"sync"
"testing"
"time"
"github.com/btcsuite/btclog"
"github.com/go-errors/errors"
@ -949,14 +948,6 @@ func TestBreachHandoffSuccess(t *testing.T) {
}
defer cleanUpArb()
// Send the channel to the arbiter so that it set up the receiving end
// of the handoff.
select {
case brar.newContracts <- alice:
case <-time.After(500 * time.Millisecond):
t.Fatalf("unable to register alice with breach arbiter: %v", err)
}
// Send one HTLC to Bob and perform a state transition to lock it in.
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
htlc, _ := createHTLC(0, htlcAmount)
@ -1029,14 +1020,6 @@ func TestBreachHandoffFail(t *testing.T) {
}
defer cleanUpArb()
// Send the channel to the arbiter so that it set up the receiving end
// of the handoff.
select {
case brar.newContracts <- alice:
case <-time.After(500 * time.Millisecond):
t.Fatalf("unable to register alice with breach arbiter: %v", err)
}
// Send one HTLC to Bob and perform a state transition to lock it in.
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
htlc, _ := createHTLC(0, htlcAmount)
@ -1098,21 +1081,12 @@ func TestBreachHandoffFail(t *testing.T) {
alicesPrivKey)
aliceSigner := &mockSigner{aliceKeyPriv}
alice2, err := lnwallet.NewLightningChannel(aliceSigner, notifier,
nil, alice.State())
alice2, err := lnwallet.NewLightningChannel(aliceSigner, nil, alice.State())
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
defer alice2.Stop()
// Send this newer channel to breach arbiter, which should replace the
// prior.
select {
case brar.newContracts <- alice2:
case <-time.After(500 * time.Millisecond):
t.Fatalf("unable to register alice with breach arbiter: %v", err)
}
// Signal a spend of the funding transaction and wait for the close
// observer to exit. This time we are allowing the handoff to succeed.
notifier.Spend(chanPoint, 100, breachTxn)
@ -1390,13 +1364,13 @@ func createInitChannelsWithNotifier(revocationWindow int,
bobSigner := &mockSigner{bobKeyPriv}
channelAlice, err := lnwallet.NewLightningChannel(
aliceSigner, notifier, pCache, aliceChannelState,
aliceSigner, pCache, aliceChannelState,
)
if err != nil {
return nil, nil, nil, err
}
channelBob, err := lnwallet.NewLightningChannel(
bobSigner, notifier, pCache, bobChannelState,
bobSigner, pCache, bobChannelState,
)
if err != nil {
return nil, nil, nil, err