lnwallet: only forward freshly locked in HTLC's in ReceiveRevocation
This commit fixes a nasty bug that has been lingering within lnd, and has been noticed due to the added retransmission logic. Before this commit, upon a restart, if we had an active HTLC and received a new commitment update, then we would re-forward ALL active HTLC’s. This could at times lead to a nasty cycle: * We re-forward an HTLC already processed. * We then notice that the time-lock is out of date (retransmitted HTLC), so we go to fail it. * This is detected as a replay attack, so we send an UpdateMalformedHTLC * This second failure ends up creating a nil entry in the log, leading to a panic. * Remote party disconnects. * Upon reconnect we send again as we need to retransmit the changes, this goes on forever. In order to fix this, we now ensure that we only forward HTLC’s that have been newly locked in at this next state. With this, we now avoid the loop described above, and also ensure that we don’t accidentally attempt an HTLC replay attack on our selves. Fixes #528. Fixes #545.
This commit is contained in:
2 files changed
+152
-2
No files matched your search
+11
-2
@@ -3905,18 +3905,27 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ([]*P
|
||||
continue
|
||||
}
|
||||
|
||||
// We'll only forward any new HTLC additions iff, it's "freshly
|
||||
// locked in". Meaning that the HTLC was only *just* considered
|
||||
// locked-in at this new state. By doing this we ensure that we
|
||||
// don't re-forward any already processed HTLC's after a
|
||||
// restart.
|
||||
if htlc.EntryType == Add &&
|
||||
remoteChainTail >= htlc.addCommitHeightRemote &&
|
||||
remoteChainTail == htlc.addCommitHeightRemote &&
|
||||
localChainTail >= htlc.addCommitHeightLocal {
|
||||
|
||||
htlc.isForwarded = true
|
||||
htlcsToForward = append(htlcsToForward, htlc)
|
||||
} else if htlc.EntryType != Add &&
|
||||
continue
|
||||
}
|
||||
|
||||
if htlc.EntryType != Add &&
|
||||
remoteChainTail >= htlc.removeCommitHeightRemote &&
|
||||
localChainTail >= htlc.removeCommitHeightLocal {
|
||||
|
||||
htlc.isForwarded = true
|
||||
htlcsToForward = append(htlcsToForward, htlc)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user