From c90b1dd17ddf9de83f43a14cbaca21395ccef4f3 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 6 Sep 2019 13:14:40 +0200 Subject: [PATCH] chancloser: mark commitment broadcast before publish We call MarkCommitmentBroadcasted before publishing the closing tx to ensure we can attempt to republish at startup if something goes wrong. --- chancloser.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/chancloser.go b/chancloser.go index d78a3824..3c015a5b 100644 --- a/chancloser.go +++ b/chancloser.go @@ -435,6 +435,14 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b "close: %v", c.chanPoint, err) } + // Before publishing the closing tx, we persist it to the + // database, such that it can be republished if something goes + // wrong. + err = c.cfg.channel.MarkCommitmentBroadcasted(closeTx) + if err != nil { + return nil, false, err + } + // With the closing transaction crafted, we'll now broadcast it // to the network. peerLog.Infof("Broadcasting cooperative close tx: %v", @@ -445,11 +453,6 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b return nil, false, err } - err = c.cfg.channel.MarkCommitmentBroadcasted(closeTx) - if err != nil { - return nil, false, 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