lnwallet: extract pending local updates restore method

Extract method in preparation for restoring dangling remote updates. We
need to get rid of the early return.
This commit is contained in:
Joost Jager committed 2020-01-15 12:37:26 +01:00
1 parent 2d37d341a1
commit ed8fa35ed4
1 file changed
+18 -4
+18 -4
View File
@@ -1814,12 +1814,26 @@ func (lc *LightningChannel) restoreStateLogs(
lc.localUpdateLog.restoreHtlc(&htlc)
}
// If we didn't have a dangling (un-acked) commit for the remote party,
// then we can exit here.
if pendingRemoteCommit == nil {
return nil
// If we have a dangling (un-acked) commit for the remote party, then we
// restore the updates leading up to this commit.
if pendingRemoteCommit != nil {
err := lc.restorePendingLocalUpdates(
pendingRemoteCommitDiff, pendingRemoteKeys,
)
if err != nil {
return err
}
}
return nil
}
// restorePendingLocalUpdates restores the local log updates leading up to the
// given pending remote commitment.
func (lc *LightningChannel) restorePendingLocalUpdates(
pendingRemoteCommitDiff *channeldb.CommitDiff,
pendingRemoteKeys *CommitmentKeyRing) error {
pendingCommit := pendingRemoteCommitDiff.Commitment
pendingHeight := pendingCommit.CommitHeight