mirror of https://github.com/BTCPrivate/lnd.git
breacharbiter: also listen for the co-op chan close signal
This commit is contained in:
parent
91d45b37ba
commit
0d75dde153
|
@ -544,6 +544,22 @@ func (b *breachArbiter) breachObserver(
|
||||||
case <-settleSignal:
|
case <-settleSignal:
|
||||||
return
|
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 channel has been closed by a normal means: force closing with
|
||||||
// the latest commitment transaction.
|
// the latest commitment transaction.
|
||||||
case <-chainEvents.UnilateralClosure:
|
case <-chainEvents.UnilateralClosure:
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btclog"
|
"github.com/btcsuite/btclog"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
@ -949,14 +948,6 @@ func TestBreachHandoffSuccess(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer cleanUpArb()
|
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.
|
// Send one HTLC to Bob and perform a state transition to lock it in.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlc, _ := createHTLC(0, htlcAmount)
|
htlc, _ := createHTLC(0, htlcAmount)
|
||||||
|
@ -1029,14 +1020,6 @@ func TestBreachHandoffFail(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer cleanUpArb()
|
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.
|
// Send one HTLC to Bob and perform a state transition to lock it in.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlc, _ := createHTLC(0, htlcAmount)
|
htlc, _ := createHTLC(0, htlcAmount)
|
||||||
|
@ -1098,21 +1081,12 @@ func TestBreachHandoffFail(t *testing.T) {
|
||||||
alicesPrivKey)
|
alicesPrivKey)
|
||||||
aliceSigner := &mockSigner{aliceKeyPriv}
|
aliceSigner := &mockSigner{aliceKeyPriv}
|
||||||
|
|
||||||
alice2, err := lnwallet.NewLightningChannel(aliceSigner, notifier,
|
alice2, err := lnwallet.NewLightningChannel(aliceSigner, nil, alice.State())
|
||||||
nil, alice.State())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create test channels: %v", err)
|
t.Fatalf("unable to create test channels: %v", err)
|
||||||
}
|
}
|
||||||
defer alice2.Stop()
|
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
|
// Signal a spend of the funding transaction and wait for the close
|
||||||
// observer to exit. This time we are allowing the handoff to succeed.
|
// observer to exit. This time we are allowing the handoff to succeed.
|
||||||
notifier.Spend(chanPoint, 100, breachTxn)
|
notifier.Spend(chanPoint, 100, breachTxn)
|
||||||
|
@ -1390,13 +1364,13 @@ func createInitChannelsWithNotifier(revocationWindow int,
|
||||||
bobSigner := &mockSigner{bobKeyPriv}
|
bobSigner := &mockSigner{bobKeyPriv}
|
||||||
|
|
||||||
channelAlice, err := lnwallet.NewLightningChannel(
|
channelAlice, err := lnwallet.NewLightningChannel(
|
||||||
aliceSigner, notifier, pCache, aliceChannelState,
|
aliceSigner, pCache, aliceChannelState,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
channelBob, err := lnwallet.NewLightningChannel(
|
channelBob, err := lnwallet.NewLightningChannel(
|
||||||
bobSigner, notifier, pCache, bobChannelState,
|
bobSigner, pCache, bobChannelState,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
|
|
Loading…
Reference in New Issue