Skip to content

Commit

Permalink
cnct: finish channel arbitrator in StateFullyResolved
Browse files Browse the repository at this point in the history
Previously the arbitrator wasn't advanced to the final stage after
the last contract resolved.

Also channel arbitrator now does not ignore a log error anymore
unresolved contracts cannot be retrieved.
  • Loading branch information
joostjager committed Feb 1, 2019
1 parent b7387a5 commit 9abe06f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
43 changes: 24 additions & 19 deletions contractcourt/channel_arbitrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,19 @@ func (c *ChannelArbitrator) stateStep(triggerHeight uint32,
log.Infof("ChannelArbitrator(%v): still awaiting contract "+
"resolution", c.cfg.ChanPoint)

nextState = StateWaitingFullResolution
numUnresolved, err := c.log.FetchUnresolvedContracts()
if err != nil {
return StateError, closeTx, err
}

// If we still have unresolved contracts, then we'll stay alive
// to oversee their resolution.
if len(numUnresolved) != 0 {
nextState = StateWaitingFullResolution
break
}

nextState = StateFullyResolved

// If we start as fully resolved, then we'll end as fully resolved.
case StateFullyResolved:
Expand Down Expand Up @@ -1722,29 +1734,22 @@ func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
log.Infof("ChannelArbitrator(%v): a contract has been "+
"fully resolved!", c.cfg.ChanPoint)

numUnresolved, err := c.log.FetchUnresolvedContracts()
nextState, _, err := c.advanceState(
uint32(bestHeight), chainTrigger,
)
if err != nil {
log.Errorf("unable to query resolved "+
"contracts: %v", err)
}

// If we still have unresolved contracts, then we'll
// stay alive to oversee their resolution.
if len(numUnresolved) != 0 {
continue
log.Errorf("unable to advance state: %v", err)
}

log.Infof("ChannelArbitrator(%v): all contracts fully "+
"resolved, exiting", c.cfg.ChanPoint)
// If we don't have anything further to do after
// advancing our state, then we'll exit.
if nextState == StateFullyResolved {
log.Infof("ChannelArbitrator(%v): all "+
"contracts fully resolved, exiting",
c.cfg.ChanPoint)

// Otherwise, our job is finished here, the contract is
// now fully resolved! We'll mark it as such, then exit
// ourselves.
if err := c.cfg.MarkChannelResolved(); err != nil {
log.Errorf("unable to mark contract "+
"resolved: %v", err)
return
}
return

// We've just received a request to forcibly close out the
// channel. We'll
Expand Down
5 changes: 1 addition & 4 deletions contractcourt/channel_arbitrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
notifier.spendChan <- &chainntnfs.SpendDetail{}

// At this point channel should be marked as resolved.

// It should transition StateWaitingFullResolution ->
// StateFullyResolved, but this isn't happening.
// assertStateTransitions(t, arbLog.newStates, StateFullyResolved)
assertStateTransitions(t, arbLog.newStates, StateFullyResolved)

select {
case <-resolved:
Expand Down

0 comments on commit 9abe06f

Please sign in to comment.