Merge pull request #1417 from halseth/chanarb-stop

Properly stop ChannelArbitrators/blockEpocs
This commit is contained in:
Olaoluwa Osuntokun 2018-06-21 13:42:20 +01:00 committed by GitHub
commit 70217422b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

@ -301,6 +301,7 @@ func (c *ChainArbitrator) resolveContract(chanPoint wire.OutPoint,
if ok { if ok {
chainWatcher.Stop() chainWatcher.Stop()
} }
delete(c.activeWatchers, chanPoint)
c.Unlock() c.Unlock()
return nil return nil

@ -231,6 +231,7 @@ func (c *ChannelArbitrator) Start() error {
// machine can act accordingly. // machine can act accordingly.
c.state, err = c.log.CurrentState() c.state, err = c.log.CurrentState()
if err != nil { if err != nil {
c.cfg.BlockEpochs.Cancel()
return err return err
} }
@ -239,6 +240,7 @@ func (c *ChannelArbitrator) Start() error {
_, bestHeight, err := c.cfg.ChainIO.GetBestBlock() _, bestHeight, err := c.cfg.ChainIO.GetBestBlock()
if err != nil { if err != nil {
c.cfg.BlockEpochs.Cancel()
return err return err
} }
@ -249,6 +251,7 @@ func (c *ChannelArbitrator) Start() error {
uint32(bestHeight), chainTrigger, nil, uint32(bestHeight), chainTrigger, nil,
) )
if err != nil { if err != nil {
c.cfg.BlockEpochs.Cancel()
return err return err
} }
@ -262,6 +265,7 @@ func (c *ChannelArbitrator) Start() error {
// relaunch all contract resolvers. // relaunch all contract resolvers.
unresolvedContracts, err = c.log.FetchUnresolvedContracts() unresolvedContracts, err = c.log.FetchUnresolvedContracts()
if err != nil { if err != nil {
c.cfg.BlockEpochs.Cancel()
return err return err
} }
@ -301,8 +305,6 @@ func (c *ChannelArbitrator) Stop() error {
close(c.quit) close(c.quit)
c.wg.Wait() c.wg.Wait()
c.cfg.BlockEpochs.Cancel()
return nil return nil
} }
@ -1289,7 +1291,10 @@ func (c *ChannelArbitrator) UpdateContractSignals(newSignals *ContractSignals) {
func (c *ChannelArbitrator) channelAttendant(bestHeight int32) { func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
// TODO(roasbeef): tell top chain arb we're done // TODO(roasbeef): tell top chain arb we're done
defer c.wg.Done() defer func() {
c.cfg.BlockEpochs.Cancel()
c.wg.Done()
}()
for { for {
select { select {