From 69e6ec99547a5e279c5f38792c11458bf457a074 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 18 Jan 2018 14:07:56 -0800 Subject: [PATCH] peer+funding: remove unneeded channel handoff code with the breach arbiter We no longer need to hand off new channels that come online as the chainWatcher will be persistent, and always have an active signal for the entire lifetime of the channel. --- discovery/gossiper.go | 2 +- fundingmanager.go | 34 ++++++---------------------------- lnd.go | 6 +----- peer.go | 20 -------------------- rpcserver.go | 3 +-- 5 files changed, 9 insertions(+), 56 deletions(-) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 9e59d882..26ce951a 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1019,7 +1019,7 @@ func (d *AuthenticatedGossiper) retransmitStaleChannels() error { // existence. if info.AuthProof == nil { log.Debugf("Skipping retransmission of channel "+ - "without AuthProof: %v", info) + "without AuthProof: %v", info.ChannelID) return nil } diff --git a/fundingmanager.go b/fundingmanager.go index d08b8dc8..d413a9e2 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -164,12 +164,6 @@ type fundingConfig struct { // transaction information. FeeEstimator lnwallet.FeeEstimator - // ArbiterChan allows the FundingManager to notify the BreachArbiter - // that a new channel has been created that should be observed to - // ensure that the channel counterparty hasn't broadcast an invalid - // commitment transaction. - ArbiterChan chan<- *lnwallet.LightningChannel - // Notifier is used by the FundingManager to determine when the // channel's funding transaction has been confirmed on the blockchain // so that the channel creation process can be completed. @@ -235,13 +229,11 @@ type fundingConfig struct { // contract breach. RequiredRemoteDelay func(btcutil.Amount) uint16 - // ArbitrateNewChan is to be called once a new channel enters the final + // WatchNewChannel is to be called once a new channel enters the final // funding stage: waiting for on-chain confirmation. This method sends // the channel to the ChainArbitrator so it can watch for any on-chain // events related to the channel. - // - // TODO(roasbeef): pass signal as well? - ArbitrateNewChan func(*channeldb.OpenChannel) error + WatchNewChannel func(*channeldb.OpenChannel) error } // fundingManager acts as an orchestrator/bridge between the wallet's @@ -1209,7 +1201,7 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) { // Now that we've sent over our final signature for this channel, we'll // send it to the ChainArbitrator so it can watch for any on-chain // actions during this final confirmation stage. - if err := f.cfg.ArbitrateNewChan(completeChan); err != nil { + if err := f.cfg.WatchNewChannel(completeChan); err != nil { fndgLog.Error("Unable to send new ChannelPoint(%v) for "+ "arbitration", fundingOut) } @@ -1348,9 +1340,7 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { // we'll send the to be active channel to the ChainArbitrator so it can // watch for any on-chin actions before the channel has fully // confirmed. - // - // TODO(roasbeef): ensure later it also gets new signals - if err := f.cfg.ArbitrateNewChan(completeChan); err != nil { + if err := f.cfg.WatchNewChannel(completeChan); err != nil { fndgLog.Error("Unable to send new ChannelPoint(%v) for "+ "arbitration", fundingPoint) } @@ -1407,7 +1397,7 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { // Go on adding the channel to the channel graph, and crafting // channel announcements. lnChannel, err := lnwallet.NewLightningChannel( - nil, nil, nil, completeChan, + nil, nil, completeChan, ) if err != nil { fndgLog.Errorf("failed creating lnChannel: %v", err) @@ -1415,7 +1405,6 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) { } defer func() { lnChannel.Stop() - lnChannel.CancelObserver() }() err = f.sendFundingLocked(completeChan, lnChannel, shortChanID) @@ -1654,14 +1643,13 @@ func (f *fundingManager) handleFundingConfirmation(completeChan *channeldb.OpenC // We create the state-machine object which wraps the database state. lnChannel, err := lnwallet.NewLightningChannel( - nil, nil, nil, completeChan, + nil, nil, completeChan, ) if err != nil { return err } defer func() { lnChannel.Stop() - lnChannel.CancelObserver() }() chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint) @@ -1993,16 +1981,6 @@ func (f *fundingManager) handleFundingLocked(fmsg *fundingLockedMsg) { fndgLog.Infof("Received duplicate fundingLocked for "+ "ChannelID(%v), ignoring.", chanID) channel.Stop() - channel.CancelObserver() - return - } - - // With the channel retrieved, we'll send the breach arbiter the new - // channel so it can watch for attempts to breach the channel's - // contract by the remote party. - select { - case f.cfg.ArbiterChan <- channel: - case <-f.quit: return } diff --git a/lnd.go b/lnd.go index 5c9ad680..e93b2d8c 100644 --- a/lnd.go +++ b/lnd.go @@ -268,7 +268,6 @@ func lndMain() error { idPrivKey.PubKey()) return <-errChan }, - ArbiterChan: server.breachArbiter.newContracts, SendToPeer: server.SendToPeer, NotifyWhenOnline: server.NotifyWhenOnline, FindPeer: server.FindPeer, @@ -284,7 +283,6 @@ func lndMain() error { // TODO(rosbeef): populate baecon return lnwallet.NewLightningChannel( activeChainControl.signer, - activeChainControl.chainNotifier, server.witnessBeacon, channel) } @@ -359,9 +357,7 @@ func lndMain() error { } return delay }, - ArbitrateNewChan: func(c *channeldb.OpenChannel) error { - return server.chainArb.RequestChannelArbitration(c) - }, + WatchNewChannel: server.chainArb.WatchNewChannel, }) if err != nil { return err diff --git a/peer.go b/peer.go index b93e0d77..eef29233 100644 --- a/peer.go +++ b/peer.go @@ -312,14 +312,6 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { peerLog.Infof("peerID(%v) loading ChannelPoint(%v)", p.id, chanPoint) - select { - case p.server.breachArbiter.newContracts <- lnChan: - case <-p.server.quit: - return fmt.Errorf("server shutting down") - case <-p.quit: - return fmt.Errorf("peer shutting down") - } - // Skip adding any permanently irreconcilable channels to the // htlcswitch. if dbChan.IsBorked { @@ -1220,18 +1212,6 @@ out: p.activeChanMtx.Unlock() close(newChanReq.done) newChanReq.channel.Stop() - newChanReq.channel.CancelObserver() - - // We'll re-send our current channel to the - // breachArbiter to ensure that it has the most - // up to date version. - select { - case p.server.breachArbiter.newContracts <- currentChan: - case <-p.server.quit: - return - case <-p.quit: - return - } // If we're being sent a new channel, and our // existing channel doesn't have the next diff --git a/rpcserver.go b/rpcserver.go index 5e9c4e3c..42ec099b 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -825,7 +825,6 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, return err } channel.Stop() - channel.CancelObserver() _, bestHeight, err := r.server.cc.chainIO.GetBestBlock() if err != nil { @@ -986,7 +985,7 @@ func (r *rpcServer) fetchActiveChannel(chanPoint wire.OutPoint) (*lnwallet.Light // Otherwise, we create a fully populated channel state machine which // uses the db channel as backing storage. return lnwallet.NewLightningChannel( - r.server.cc.wallet.Cfg.Signer, nil, nil, dbChan, + r.server.cc.wallet.Cfg.Signer, nil, dbChan, ) }