diff --git a/breacharbiter.go b/breacharbiter.go index 96cb93d8..5ee799f5 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -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: diff --git a/breacharbiter_test.go b/breacharbiter_test.go index 0ac85795..970144c3 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -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