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.
This commit is contained in:
Olaoluwa Osuntokun 2018-01-18 14:07:56 -08:00
parent a0cc1d1b2d
commit 69e6ec9954
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
5 changed files with 9 additions and 56 deletions

View File

@ -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
}

View File

@ -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
}

6
lnd.go
View File

@ -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

20
peer.go
View File

@ -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

View File

@ -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,
)
}