From 412f29665d992b0a803d04e06c3a75d217de5276 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 9 Jan 2023 19:27:48 -0800 Subject: [PATCH] htlcswitch: send an error before marking a channel w/ local data loss In this commit, we move to also send an error before we "fail" our channel when we realize that either we've lost data, or are recovering from some partial state. --- htlcswitch/link.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 23c37cebd0..ff15654a51 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -1049,6 +1049,13 @@ func (l *channelLink) htlcManager() { "data loss: %v", err) } + // Before we fail the link, we'll send an error + // to the other party so they know we can't + // continue. + // + // TODO(roasbeef): use reliable sender here? + l.sendFatalError() + // We determined the commit chains were not possible to // sync. We cautiously fail the channel, but don't // force close. @@ -3452,3 +3459,14 @@ func (l *channelLink) fail(linkErr LinkFailureError, l.failed = true l.cfg.OnChannelFailure(l.ChanID(), l.ShortChanID(), linkErr) } + +// sendFatalError sends an Error message to the remote peer, in order to prompt +// either a force close, or to signal that the channel can no longer continue. +func (l *channelLink) sendFatalError() { + // For fatal errors, we'll set sync=true so we ensure that this is sent + // out before we go to mark the channel as borked. + l.cfg.Peer.SendMessage(true, &lnwire.Error{ + ChanID: l.ChanID(), + Data: []byte("fatal error"), + }) +}