From 327420d854580a0e430831a33fbcdb6d28f20df8 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 19 Jun 2018 12:20:30 +0100 Subject: [PATCH 1/3] contractcourt/channel_arbitrator: Cancel block epoch in case of error in Start() --- contractcourt/channel_arbitrator.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index 0ee68313..ac7cdb1a 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -231,6 +231,7 @@ func (c *ChannelArbitrator) Start() error { // machine can act accordingly. c.state, err = c.log.CurrentState() if err != nil { + c.cfg.BlockEpochs.Cancel() return err } @@ -239,6 +240,7 @@ func (c *ChannelArbitrator) Start() error { _, bestHeight, err := c.cfg.ChainIO.GetBestBlock() if err != nil { + c.cfg.BlockEpochs.Cancel() return err } @@ -249,6 +251,7 @@ func (c *ChannelArbitrator) Start() error { uint32(bestHeight), chainTrigger, nil, ) if err != nil { + c.cfg.BlockEpochs.Cancel() return err } @@ -262,6 +265,7 @@ func (c *ChannelArbitrator) Start() error { // relaunch all contract resolvers. unresolvedContracts, err = c.log.FetchUnresolvedContracts() if err != nil { + c.cfg.BlockEpochs.Cancel() return err } From 1c43a0cb362cd8bf849a6a2b9106d4af4f81f8fa Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 19 Jun 2018 12:25:30 +0100 Subject: [PATCH 2/3] contractcourt/chain_arbitrator: delete watcher from activeWatchers --- contractcourt/chain_arbitrator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 5fdb72c0..9fc3023a 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -301,6 +301,7 @@ func (c *ChainArbitrator) resolveContract(chanPoint wire.OutPoint, if ok { chainWatcher.Stop() } + delete(c.activeWatchers, chanPoint) c.Unlock() return nil From d787e74125b7c5fcd1d5f66a6a5585511973b385 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 21 Jun 2018 10:52:49 +0100 Subject: [PATCH 3/3] contractcourt/channel_arbitrator: stop block epoch on channel attendant exit --- contractcourt/channel_arbitrator.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index ac7cdb1a..44e40ce3 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -305,8 +305,6 @@ func (c *ChannelArbitrator) Stop() error { close(c.quit) c.wg.Wait() - c.cfg.BlockEpochs.Cancel() - return nil } @@ -1293,7 +1291,10 @@ func (c *ChannelArbitrator) UpdateContractSignals(newSignals *ContractSignals) { func (c *ChannelArbitrator) channelAttendant(bestHeight int32) { // TODO(roasbeef): tell top chain arb we're done - defer c.wg.Done() + defer func() { + c.cfg.BlockEpochs.Cancel() + c.wg.Done() + }() for { select {