From 94504a9d411fd0eaf49cffe60739248cc81e0871 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 16 Jan 2018 19:57:04 -0800 Subject: [PATCH] breacharbiter: notify the ChainArbitrator of fresh signals for a channel on startup --- breacharbiter.go | 17 +++++++++++++++++ breacharbiter_test.go | 22 ++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/breacharbiter.go b/breacharbiter.go index 07f395afc..3f9b67cb9 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -45,6 +45,14 @@ type BreachConfig struct { // a close type to be included in the channel close summary. CloseLink func(*wire.OutPoint, htlcswitch.ChannelCloseType) + // UpdateCloseSignal allows the breach arbiter to notify the + // ChainArbitrator that a set of new signals for the unilateral closing + // of a channel is now available. This ensures that ifa channel hasn't + // had any updates since it was live, then we're still able to act on + // on-chain events. + UpdateCloseSignal func(*wire.OutPoint, + chan *lnwallet.UnilateralCloseSummary) error + // DB provides access to the user's channels, allowing the breach // arbiter to determine the current state of a user's channels, and how // it should respond to channel closure. @@ -306,6 +314,15 @@ func (b *breachArbiter) contractObserver( chanPoint := channel.ChanPoint b.breachObservers[*chanPoint] = settleSignal + // Before we'll launch our breach observe, we'll send this + // latest set of contract signals to the ChainArbitrator. + // + // TODO(roasbeef): just move now? + err := b.cfg.UpdateCloseSignal(chanPoint, channel.UnilateralClose) + if err != nil { + brarLog.Errorf("unable to update close signals: %v", err) + } + b.wg.Add(1) go b.breachObserver(channel, settleSignal) } diff --git a/breacharbiter_test.go b/breacharbiter_test.go index 828ab7d7c..0ac857951 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -1097,10 +1097,9 @@ func TestBreachHandoffFail(t *testing.T) { aliceKeyPriv, _ := btcec.PrivKeyFromBytes(btcec.S256(), alicesPrivKey) aliceSigner := &mockSigner{aliceKeyPriv} - estimator := &lnwallet.StaticFeeEstimator{FeeRate: 50} alice2, err := lnwallet.NewLightningChannel(aliceSigner, notifier, - estimator, alice.State()) + nil, alice.State()) if err != nil { t.Fatalf("unable to create test channels: %v", err) } @@ -1382,16 +1381,23 @@ func createInitChannelsWithNotifier(revocationWindow int, Db: dbBob, } + pCache := &mockPreimageCache{ + // hash -> preimage + preimageMap: make(map[[32]byte][]byte), + } + aliceSigner := &mockSigner{aliceKeyPriv} bobSigner := &mockSigner{bobKeyPriv} - channelAlice, err := lnwallet.NewLightningChannel(aliceSigner, notifier, - estimator, aliceChannelState) + channelAlice, err := lnwallet.NewLightningChannel( + aliceSigner, notifier, pCache, aliceChannelState, + ) if err != nil { return nil, nil, nil, err } - channelBob, err := lnwallet.NewLightningChannel(bobSigner, notifier, - estimator, bobChannelState) + channelBob, err := lnwallet.NewLightningChannel( + bobSigner, notifier, pCache, bobChannelState, + ) if err != nil { return nil, nil, nil, err } @@ -1476,7 +1482,7 @@ func forceStateTransition(chanA, chanB *lnwallet.LightningChannel) error { return err } - bobRevocation, err := chanB.RevokeCurrentCommitment() + bobRevocation, _, err := chanB.RevokeCurrentCommitment() if err != nil { return err } @@ -1492,7 +1498,7 @@ func forceStateTransition(chanA, chanB *lnwallet.LightningChannel) error { return err } - aliceRevocation, err := chanA.RevokeCurrentCommitment() + aliceRevocation, _, err := chanA.RevokeCurrentCommitment() if err != nil { return err }