From dbf6a511fcd7992c7705fc6ac7af4c819dd24a18 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 8 Jan 2018 18:56:52 -0800 Subject: [PATCH] htlcswitch: if we detect an InvalidCommitSigError, send over detailed error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we add an additional case when handling a failed commitment signature. If we detect that it’s a InvalidCommitSigError, then we’ll send over an lnwire.Error message with the full details. We don’t yet properly dispatch this error on the reciting side, but that will be done in a follow up a commit. --- htlcswitch/link.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 512c76d0..b494713e 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -893,11 +893,26 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { } case *lnwire.CommitSig: - // We just received a new updates to our local commitment chain, - // validate this new commitment, closing the link if invalid. + // We just received a new updates to our local commitment + // chain, validate this new commitment, closing the link if + // invalid. err := l.channel.ReceiveNewCommitment(msg.CommitSig, msg.HtlcSigs) if err != nil { - l.fail("unable to accept new commitment: %v", err) + // If we were unable to reconstruct their proposed + // commitment, then we'll examine the type of error. If + // it's an InvalidCommitSigError, then we'll send a + // direct error. + // + // TODO(roasbeef): force close chan + if _, ok := err.(*lnwallet.InvalidCommitSigError); ok { + l.cfg.Peer.SendMessage(&lnwire.Error{ + ChanID: l.ChanID(), + Data: []byte(err.Error()), + }) + } + + l.fail("ChannelPoint(%v): unable to accept new "+ + "commitment: %v", l.channel.ChannelPoint(), err) return }