From ed8fa35ed44a8e2569c0f875284444cf8dd587db Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 6 Jan 2020 13:14:25 +0100 Subject: [PATCH] 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. --- lnwallet/channel.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 367e0407..08d68506 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -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