Skip to content

Commit

Permalink
lnwallet: convert PendingUpdates to FullySynced
Browse files Browse the repository at this point in the history
This commit improves the channel state machine by converting the
objective PendingUpdates method to a subjective FullySynced method
which is to be used in place of PendingUpdates. The new FullySynced
method is fully encompassing and replaces any upper state required by
the state machine which wraps this one.

The new FullySynced method is identical to PendingUpdates aside from
the fact that: it now also factors in the log message index of the
remote commitment chain, and also introduces a concept of an “owed
commitment”. A commitment chain owes a commitment if the height of the
local commitment chain is higher than that of the remote chain.
  • Loading branch information
Roasbeef committed Apr 12, 2017
1 parent 4cd277c commit 31acace
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1725,21 +1725,24 @@ func (lc *LightningChannel) ReceiveNewCommitment(rawSig []byte) error {
return nil
}

// PendingUpdates returns a boolean value reflecting if there are any pending
// updates which need to be committed. The state machine has pending updates if
// the local log index on the local and remote chain tip aren't identical. This
// indicates that either we have pending updates they need to commit, or vice
// versa.
func (lc *LightningChannel) PendingUpdates() bool {
// FullSynced returns a boolean value reflecting if both commitment chains
// (remote+local) are fully in sync. Both commitment chains are fully in sync
// if the tip of each chain includes the latest committed changes from both
// sides.
func (lc *LightningChannel) FullySynced() bool {
lc.RLock()
defer lc.RUnlock()

// TODO(roasbeef): instead check our current counter?
oweCommitment := (lc.localCommitChain.tip().height >
lc.remoteCommitChain.tip().height)

fullySynced := (lc.localCommitChain.tip().ourMessageIndex ==
localUpdatesSynced := (lc.localCommitChain.tip().ourMessageIndex ==
lc.remoteCommitChain.tip().ourMessageIndex)

return !fullySynced
remoteUpdatesSynced := (lc.localCommitChain.tip().theirMessageIndex ==
lc.remoteCommitChain.tip().theirMessageIndex)

return !oweCommitment && localUpdatesSynced && remoteUpdatesSynced
}

// RevokeCurrentCommitment revokes the next lowest unrevoked commitment
Expand Down

0 comments on commit 31acace

Please sign in to comment.