From d4e650c85d5eb6e268949a8730342e8952ef383a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 20 Jan 2018 20:27:25 -0800 Subject: [PATCH] peer: the chancloser no longer needs to notify the breach arb of settled transactions --- chancloser.go | 13 ------------- fundingmanager.go | 15 +++++++++++++++ lnd.go | 1 + peer.go | 40 ++++++++++++++++++---------------------- rpcserver.go | 2 +- test_utils.go | 4 +--- 6 files changed, 36 insertions(+), 39 deletions(-) diff --git a/chancloser.go b/chancloser.go index ea257014c..a21ca525c 100644 --- a/chancloser.go +++ b/chancloser.go @@ -82,11 +82,6 @@ type chanCloseCfg struct { // broadcastTx broadcasts the passed transaction to the network. broadcastTx func(*wire.MsgTx) error - // settledContracts is a channel that will be sent upon once the - // channel is partially closed. This notifies any sub-systems that they - // no longer need to watch the channel for any on-chain activity. - settledContracts chan<- *wire.OutPoint - // quit is a channel that should be sent upon in the occasion the state // machine shouldk cease all progress and shutdown. quit chan struct{} @@ -452,14 +447,6 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b } } - // As this contract is final, we'll send it over the settled - // contracts channel. - select { - case c.cfg.settledContracts <- &c.chanPoint: - case <-c.cfg.quit: - return nil, false, fmt.Errorf("peer shutting down") - } - // Clear out the current channel state, marking the channel as // being closed within the database. closingTxid := closeTx.TxHash() diff --git a/fundingmanager.go b/fundingmanager.go index d413a9e2a..e3b5309fa 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -169,6 +169,12 @@ type fundingConfig struct { // so that the channel creation process can be completed. Notifier chainntnfs.ChainNotifier + // 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<- wire.OutPoint + // SignMessage signs an arbitrary method with a given public key. The // actual digest signed is the double sha-256 of the message. In the // case that the private key corresponding to the passed public key @@ -1984,6 +1990,15 @@ func (f *fundingManager) handleFundingLocked(fmsg *fundingLockedMsg) { 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.ChanPoint: + case <-f.quit: + return + } + // The funding locked message contains the next commitment point we'll // need to create the next commitment state for the remote party. So // we'll insert that into the channel now before passing it along to diff --git a/lnd.go b/lnd.go index e93b2d8cf..f54657e32 100644 --- a/lnd.go +++ b/lnd.go @@ -268,6 +268,7 @@ func lndMain() error { idPrivKey.PubKey()) return <-errChan }, + ArbiterChan: server.breachArbiter.newContracts, SendToPeer: server.SendToPeer, NotifyWhenOnline: server.NotifyWhenOnline, FindPeer: server.FindPeer, diff --git a/peer.go b/peer.go index e142d4264..e643c223a 100644 --- a/peer.go +++ b/peer.go @@ -382,16 +382,15 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { DecodeOnionObfuscator: p.server.sphinx.ExtractErrorEncrypter, GetLastChannelUpdate: createGetLastUpdate(p.server.chanRouter, p.PubKey(), lnChan.ShortChanID()), - SettledContracts: p.server.breachArbiter.settledContracts, - DebugHTLC: cfg.DebugHTLC, - HodlHTLC: cfg.HodlHTLC, - Registry: p.server.invoices, - Switch: p.server.htlcSwitch, - FwrdingPolicy: *forwardingPolicy, - FeeEstimator: p.server.cc.feeEstimator, - BlockEpochs: blockEpoch, - PreimageCache: p.server.witnessBeacon, - ChainEvents: chainEvents, + DebugHTLC: cfg.DebugHTLC, + HodlHTLC: cfg.HodlHTLC, + Registry: p.server.invoices, + Switch: p.server.htlcSwitch, + FwrdingPolicy: *forwardingPolicy, + FeeEstimator: p.server.cc.feeEstimator, + BlockEpochs: blockEpoch, + PreimageCache: p.server.witnessBeacon, + ChainEvents: chainEvents, UpdateContractSignals: func(signals *contractcourt.ContractSignals) error { return p.server.chainArb.UpdateContractSignals( *chanPoint, signals, @@ -1275,16 +1274,15 @@ out: DecodeOnionObfuscator: p.server.sphinx.ExtractErrorEncrypter, GetLastChannelUpdate: createGetLastUpdate(p.server.chanRouter, p.PubKey(), newChanReq.channel.ShortChanID()), - SettledContracts: p.server.breachArbiter.settledContracts, - DebugHTLC: cfg.DebugHTLC, - HodlHTLC: cfg.HodlHTLC, - Registry: p.server.invoices, - Switch: p.server.htlcSwitch, - FwrdingPolicy: p.server.cc.routingPolicy, - FeeEstimator: p.server.cc.feeEstimator, - BlockEpochs: blockEpoch, - PreimageCache: p.server.witnessBeacon, - ChainEvents: chainEvents, + DebugHTLC: cfg.DebugHTLC, + HodlHTLC: cfg.HodlHTLC, + Registry: p.server.invoices, + Switch: p.server.htlcSwitch, + FwrdingPolicy: p.server.cc.routingPolicy, + FeeEstimator: p.server.cc.feeEstimator, + BlockEpochs: blockEpoch, + PreimageCache: p.server.witnessBeacon, + ChainEvents: chainEvents, UpdateContractSignals: func(signals *contractcourt.ContractSignals) error { return p.server.chainArb.UpdateContractSignals( *chanPoint, signals, @@ -1446,7 +1444,6 @@ func (p *peer) fetchActiveChanCloser(chanID lnwire.ChannelID) (*channelCloser, e channel: channel, unregisterChannel: p.server.htlcSwitch.RemoveLink, broadcastTx: p.server.cc.wallet.PublishTransaction, - settledContracts: p.server.breachArbiter.settledContracts, quit: p.quit, }, deliveryAddr, @@ -1523,7 +1520,6 @@ func (p *peer) handleLocalCloseReq(req *htlcswitch.ChanClose) { channel: channel, unregisterChannel: p.server.htlcSwitch.RemoveLink, broadcastTx: p.server.cc.wallet.PublishTransaction, - settledContracts: p.server.breachArbiter.settledContracts, quit: p.quit, }, deliveryAddr, diff --git a/rpcserver.go b/rpcserver.go index 42ec099be..ada106a7d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -847,7 +847,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, } select { - case r.server.breachArbiter.settledContracts <- chanPoint: + case r.server.breachArbiter.settledContracts <- *chanPoint: case <-r.quit: return fmt.Errorf("server shutting down") } diff --git a/test_utils.go b/test_utils.go index d4e6d97ad..afdfa9ea4 100644 --- a/test_utils.go +++ b/test_utils.go @@ -248,9 +248,7 @@ func createTestPeer(notifier chainntnfs.ChainNotifier, wallet: wallet, } - breachArbiter := &breachArbiter{ - settledContracts: make(chan *wire.OutPoint, 10), - } + breachArbiter := &breachArbiter{} chainArb := contractcourt.NewChainArbitrator( contractcourt.ChainArbitratorConfig{}, nil,