From 239416f24274127777bfa28319f67b0d200e3a57 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 18 Jan 2018 14:15:42 -0800 Subject: [PATCH] htlcswitch: update to use new event stream from the chainWatcher --- htlcswitch/link.go | 29 ++++++++++++++--------------- htlcswitch/link_test.go | 1 + htlcswitch/test_utils.go | 20 ++++++++++++-------- nursery_store.go | 4 ++-- test_utils.go | 4 ++-- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index d85d0c6e..f3a14cc8 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -135,6 +135,11 @@ type ChannelLinkConfig struct { // been closed, or when the set of active HTLC's is updated. UpdateContractSignals func(*contractcourt.ContractSignals) error + // ChainEvents is an active subscription to the chain watcher for this + // channel to be notified of any on-chain activity related to this + // channel. + ChainEvents *contractcourt.ChainEventSubscription + // FeeEstimator is an instance of a live fee estimator which will be // used to dynamically regulate the current fee of the commitment // transaction to ensure timely confirmation. @@ -285,9 +290,8 @@ func (l *channelLink) Start() error { // Before we start the link, we'll update the ChainArbitrator with the // set of new channel signals for this channel. if err := l.cfg.UpdateContractSignals(&contractcourt.ContractSignals{ - HtlcUpdates: l.htlcUpdates, - UniCloseSignal: l.channel.UnilateralClose, - ShortChanID: l.channel.ShortChanID(), + HtlcUpdates: l.htlcUpdates, + ShortChanID: l.channel.ShortChanID(), }); err != nil { return err } @@ -313,6 +317,10 @@ func (l *channelLink) Stop() { log.Infof("ChannelLink(%v) is stopping", l) + if l.cfg.ChainEvents.Cancel != nil { + l.cfg.ChainEvents.Cancel() + } + l.channel.Stop() l.mailBox.Stop() @@ -631,10 +639,12 @@ out: // carried out by the remote peer. In the case of such an // event, we'll wipe the channel state from the peer, and mark // the contract as fully settled. Afterwards we can exit. - case <-l.channel.UnilateralCloseSignal: + case <-l.cfg.ChainEvents.UnilateralClosure: log.Warnf("Remote peer has closed ChannelPoint(%v) on-chain", l.channel.ChannelPoint()) + // TODO(roasbeef): move this and above to chainJanitor + // TODO(roasbeef): remove all together go func() { chanPoint := l.channel.ChannelPoint() @@ -649,17 +659,6 @@ out: break out - // A local sub-system has initiated a force close of the active - // channel. In this case we can exit immediately as no further - // updates should be processed for the channel. - case <-l.channel.ForceCloseSignal: - // TODO(roasbeef): path never taken now that server - // force closes's directly? - log.Warnf("ChannelPoint(%v) has been force "+ - "closed, disconnecting from peer(%x)", - l.channel.ChannelPoint(), l.cfg.Peer.PubKey()) - break out - case <-l.logCommitTick: // If we haven't sent or received a new commitment // update in some time, check to see if we have any diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 2f8af7d9..76cdb81d 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1465,6 +1465,7 @@ func newSingleLinkTestHarness(chanAmt btcutil.Amount) (ChannelLink, func(), erro return nil }, Registry: invoiveRegistry, + ChainEvents: &contractcourt.ChainEventSubscription{}, BlockEpochs: globalEpoch, } diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 2c7b587d..85718582 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -268,13 +268,13 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte, } channelAlice, err := lnwallet.NewLightningChannel( - aliceSigner, nil, pCache, aliceChannelState, + aliceSigner, pCache, aliceChannelState, ) if err != nil { return nil, nil, nil, nil, err } channelBob, err := lnwallet.NewLightningChannel( - bobSigner, nil, pCache, bobChannelState, + bobSigner, pCache, bobChannelState, ) if err != nil { return nil, nil, nil, nil, err @@ -319,7 +319,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte, } newAliceChannel, err := lnwallet.NewLightningChannel(aliceSigner, - nil, nil, aliceStoredChannel) + nil, aliceStoredChannel) if err != nil { return nil, nil, errors.Errorf("unable to create new channel: %v", err) @@ -343,7 +343,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte, return nil, nil, errors.New("unable to find stored bob channel") } - newBobChannel, err := lnwallet.NewLightningChannel(bobSigner, nil, + newBobChannel, err := lnwallet.NewLightningChannel(bobSigner, nil, bobStoredChannel) if err != nil { return nil, nil, errors.Errorf("unable to create new channel: %v", @@ -761,7 +761,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel, UpdateContractSignals: func(*contractcourt.ContractSignals) error { return nil }, - SyncStates: true, + ChainEvents: &contractcourt.ChainEventSubscription{}, + SyncStates: true, }, aliceChannel, startingHeight, @@ -799,7 +800,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel, UpdateContractSignals: func(*contractcourt.ContractSignals) error { return nil }, - SyncStates: true, + ChainEvents: &contractcourt.ChainEventSubscription{}, + SyncStates: true, }, firstBobChannel, startingHeight, @@ -837,7 +839,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel, UpdateContractSignals: func(*contractcourt.ContractSignals) error { return nil }, - SyncStates: true, + ChainEvents: &contractcourt.ChainEventSubscription{}, + SyncStates: true, }, secondBobChannel, startingHeight, @@ -875,7 +878,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel, UpdateContractSignals: func(*contractcourt.ContractSignals) error { return nil }, - SyncStates: true, + ChainEvents: &contractcourt.ChainEventSubscription{}, + SyncStates: true, }, carolChannel, startingHeight, diff --git a/nursery_store.go b/nursery_store.go index 8264df91..3ab8ad91 100644 --- a/nursery_store.go +++ b/nursery_store.go @@ -400,7 +400,7 @@ func (ns *nurseryStore) CribToKinder(bby *babyOutput) error { return err } - utxnLog.Tracef("Placing (crib -> baby) output for "+ + utxnLog.Tracef("Transitioning (crib -> baby) output for "+ "chan_point=%v at height_index=%v", chanPoint, maturityHeight) @@ -494,7 +494,7 @@ func (ns *nurseryStore) PreschoolToKinder(kid *kidOutput) error { maturityHeight = lastGradHeight + 1 } - utxnLog.Tracef("Placing (crib -> kid) output for "+ + utxnLog.Infof("Transitioning (crib -> kid) output for "+ "chan_point=%v at height_index=%v", chanPoint, maturityHeight) diff --git a/test_utils.go b/test_utils.go index 55b78be7..d4e6d97a 100644 --- a/test_utils.go +++ b/test_utils.go @@ -222,13 +222,13 @@ func createTestPeer(notifier chainntnfs.ChainNotifier, bobSigner := &mockSigner{bobKeyPriv} channelAlice, err := lnwallet.NewLightningChannel( - aliceSigner, notifier, nil, aliceChannelState, + aliceSigner, nil, aliceChannelState, ) if err != nil { return nil, nil, nil, nil, err } channelBob, err := lnwallet.NewLightningChannel( - bobSigner, notifier, nil, bobChannelState, + bobSigner, nil, bobChannelState, ) if err != nil { return nil, nil, nil, nil, err