From 325d77c431699f934a2fa5da7e1201aa8093dcea Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 12 Mar 2019 17:34:28 -0700 Subject: [PATCH] chancloser+cnct: disable channel before closing --- chancloser.go | 18 ++++++++---------- contractcourt/chain_arbitrator.go | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/chancloser.go b/chancloser.go index a0da1c52..86361569 100644 --- a/chancloser.go +++ b/chancloser.go @@ -427,6 +427,14 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b } c.closingTx = closeTx + // Before closing, we'll attempt to send a disable update for + // the channel. We do so before closing the channel as otherwise + // the current edge policy won't be retrievable from the graph. + if err := c.cfg.disableChannel(c.chanPoint); err != nil { + peerLog.Warnf("Unable to disable channel %v on "+ + "close: %v", c.chanPoint, err) + } + // With the closing transaction crafted, we'll now broadcast it // to the network. peerLog.Infof("Broadcasting cooperative close tx: %v", @@ -440,16 +448,6 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b return nil, false, err } - // We'll attempt to disable the channel in the background to - // avoid blocking due to sending the update message to all - // active peers. - go func() { - if err := c.cfg.disableChannel(c.chanPoint); err != nil { - peerLog.Errorf("Unable to disable channel %v on "+ - "close: %v", c.chanPoint, err) - } - }() - // Finally, we'll transition to the closeFinished state, and // also return the final close signed message we sent. // Additionally, we return true for the second argument to diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 696ddeb2..976600b9 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -635,6 +635,14 @@ func (c *ChainArbitrator) ForceCloseContract(chanPoint wire.OutPoint) (*wire.Msg log.Infof("Attempting to force close ChannelPoint(%v)", chanPoint) + // Before closing, we'll attempt to send a disable update for the + // channel. We do so before closing the channel as otherwise the current + // edge policy won't be retrievable from the graph. + if err := c.cfg.DisableChannel(chanPoint); err != nil { + log.Warnf("Unable to disable channel %v on "+ + "close: %v", chanPoint, err) + } + errChan := make(chan error, 1) respChan := make(chan *wire.MsgTx, 1) @@ -667,16 +675,6 @@ func (c *ChainArbitrator) ForceCloseContract(chanPoint wire.OutPoint) (*wire.Msg return nil, ErrChainArbExiting } - // We'll attempt to disable the channel in the background to - // avoid blocking due to sending the update message to all - // active peers. - go func() { - if err := c.cfg.DisableChannel(chanPoint); err != nil { - log.Errorf("Unable to disable channel %v on "+ - "close: %v", chanPoint, err) - } - }() - return closeTx, nil }