cnct: finish channel arbitrator in StateFullyResolved

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.
This commit is contained in:
Joost Jager 2018-09-10 13:17:55 +02:00
parent b7387a5972
commit 9abe06f3c8
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 25 additions and 23 deletions

View File

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

View File

@ -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: