From 902e1e77cbeddeab0096c4a7fc1bf515b1f5a345 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 16 May 2018 13:40:43 +0200 Subject: [PATCH] lnwallet/channel: init localUpdateLog with index from remoteCommit, remoteUpdateLog from localCommit This commit fixes a bug within channel.go that would lead to the content of the update logs and their indexes getting out of sync during restores. The scenario that could occur was that the localUpdateLog was initiated with a log index taken from the localCommitment. Updates we send (which are added to the localUpdateLog) will be added to the remote commitment first. The problem happened when an update was sent and added to the remote commitment, but not ACKed. Since it was not ACKed, we would not add it to our local commitment. During a restart/restore we would init the localUpdateLog with a height too low, such that when going through the outgoing HTLCs on the remote commitment, we would restore an HTLC at an index higher than our local log HTLC counter. The symmetric change is done to the remoteUpdateLog. --- lnwallet/channel.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 1ddb26573..16c90af4b 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1340,10 +1340,10 @@ func NewLightningChannel(signer Signer, pCache PreimageCache, // First, initialize the update logs with their current counter values // from the local and remote commitments. localUpdateLog := newUpdateLog( - localCommit.LocalLogIndex, localCommit.LocalHtlcIndex, + remoteCommit.LocalLogIndex, remoteCommit.LocalHtlcIndex, ) remoteUpdateLog := newUpdateLog( - remoteCommit.RemoteLogIndex, remoteCommit.RemoteHtlcIndex, + localCommit.RemoteLogIndex, localCommit.RemoteHtlcIndex, ) lc := &LightningChannel{