From 2cb80c4449a5e528980d35d3f014aaefcf78b967 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 11 Sep 2019 10:56:33 +0200 Subject: [PATCH] contractcourt/chain_arbitrator: mark commitment broadcasted before publish Before publishing the close tx to the network and commit to the StateCommitmentBroadcasted state, we mark the commitment as broadcasted and store it to the db. This ensures it will get re-published on startup if we go down. --- contractcourt/channel_arbitrator.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index c15d855e7..42593537d 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -821,6 +821,16 @@ func (c *ChannelArbitrator) stateStep( } closeTx = closeSummary.CloseTx + // Before publishing the transaction, we store it to the + // database, such that we can re-publish later in case it + // didn't propagate. + if err := c.cfg.MarkCommitmentBroadcasted(closeTx); err != nil { + log.Errorf("ChannelArbitrator(%v): unable to "+ + "mark commitment broadcasted: %v", + c.cfg.ChanPoint, err) + return StateError, closeTx, err + } + // With the close transaction in hand, broadcast the // transaction to the network, thereby entering the post // channel resolution state. @@ -840,12 +850,6 @@ func (c *ChannelArbitrator) stateStep( } } - if err := c.cfg.MarkCommitmentBroadcasted(closeTx); err != nil { - log.Errorf("ChannelArbitrator(%v): unable to "+ - "mark commitment broadcasted: %v", - c.cfg.ChanPoint, err) - } - // We go to the StateCommitmentBroadcasted state, where we'll // be waiting for the commitment to be confirmed. nextState = StateCommitmentBroadcasted