Skip to content

Commit

Permalink
Merge pull request lightningnetwork#894 from Roasbeef/peer-stop-channel
Browse files Browse the repository at this point in the history
peer: ensure we stop the channel if error happens in loadActiveChannels
  • Loading branch information
Roasbeef authored Mar 20, 2018
2 parents 9c0fc02 + fda3b87 commit 3d49deb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
p.server.cc.signer, p.server.witnessBeacon, dbChan,
)
if err != nil {
lnChan.Stop()
return err
}

Expand All @@ -325,6 +326,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
if dbChan.IsBorked {
peerLog.Warnf("ChannelPoint(%v) is borked, won't "+
"start.", chanPoint)
lnChan.Stop()
continue
}

Expand All @@ -333,15 +335,18 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
if _, ok := p.failedChannels[chanID]; ok {
peerLog.Warnf("ChannelPoint(%v) is failed, won't "+
"start.", chanPoint)
lnChan.Stop()
continue
}

blockEpoch, err := p.server.cc.chainNotifier.RegisterBlockEpochNtfn()
if err != nil {
lnChan.Stop()
return err
}
_, currentHeight, err := p.server.cc.chainIO.GetBestBlock()
if err != nil {
lnChan.Stop()
return err
}

Expand All @@ -351,6 +356,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
graph := p.server.chanDB.ChannelGraph()
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint)
if err != nil && err != channeldb.ErrEdgeNotFound {
lnChan.Stop()
return err
}

Expand Down Expand Up @@ -394,6 +400,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
*chanPoint, false,
)
if err != nil {
lnChan.Stop()
return err
}
linkCfg := htlcswitch.ChannelLinkConfig{
Expand Down Expand Up @@ -430,6 +437,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
uint32(currentHeight))

if err := p.server.htlcSwitch.AddLink(link); err != nil {
lnChan.Stop()
return err
}
}
Expand Down

0 comments on commit 3d49deb

Please sign in to comment.