From f5ef4992e0c57e5fbb0046accdf64c5192ef9a7b Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Mon, 16 May 2022 12:07:48 -0400 Subject: [PATCH 1/3] lnwire: add warning message wrapping existing Error message structure This commit adds Warning messages to lnwire, as introduced in bolts/950. It does not include reading/writing of warning messages, which will be covered in followup commits. --- lnwire/lnwire_test.go | 6 ++++++ lnwire/message.go | 7 ++++++- lnwire/warning.go | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lnwire/warning.go diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index ec528a38a..44d6cfb9b 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -964,6 +964,12 @@ func TestLightningWireProtocol(t *testing.T) { return mainScenario(&m) }, }, + { + msgType: MsgWarning, + scenario: func(m Warning) bool { + return mainScenario(&m) + }, + }, { msgType: MsgError, scenario: func(m Error) bool { diff --git a/lnwire/message.go b/lnwire/message.go index e6de25d25..ac57c8a29 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -22,7 +22,8 @@ type MessageType uint16 // The currently defined message types within this current version of the // Lightning protocol. const ( - MsgInit MessageType = 16 + MsgWarning MessageType = 1 + MsgInit = 16 MsgError = 17 MsgPing = 18 MsgPong = 19 @@ -75,6 +76,8 @@ func ErrorPayloadTooLarge(size int) error { // String return the string representation of message type. func (t MessageType) String() string { switch t { + case MsgWarning: + return "Warning" case MsgInit: return "Init" case MsgOpenChannel: @@ -175,6 +178,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) { var msg Message switch msgType { + case MsgWarning: + msg = &Warning{} case MsgInit: msg = &Init{} case MsgOpenChannel: diff --git a/lnwire/warning.go b/lnwire/warning.go new file mode 100644 index 000000000..bc75eaf6b --- /dev/null +++ b/lnwire/warning.go @@ -0,0 +1,22 @@ +package lnwire + +// A compile time check to ensure Warning implements the lnwire.Message +// interface. +var _ Message = (*Warning)(nil) + +// Warning is used to express non-critical errors in the protocol, providing +// a "soft" way for nodes to communicate failures. Since it has the same +// structure as errors, warnings simply include an Error so that we can leverage +// their encode/decode functionality, and over write the MsgType function to +// differentiate them. +type Warning struct { + Error +} + +// MsgType returns the integer uniquely identifying an Warning message on the +// wire. +// +// This is part of the lnwire.Message interface. +func (c *Warning) MsgType() MessageType { + return MsgWarning +} From 99828b8ebb72e18be69a7870d5342d20a748412c Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Mon, 16 May 2022 12:19:07 -0400 Subject: [PATCH 2/3] multi: add ability to read warning messages and log on link level Warning messages are intended to add "softer" failure modes for peers, so to start with we simply log the warnings sent to us. While we "may" disconnect from the peer according to the spec, we start with the least extreme option (which is also not a change in behavior because previously we'd just log that we received an unknown odd message). --- htlcswitch/link.go | 7 +++++++ peer/brontide.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 6c553e31c..7680909e8 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -1996,6 +1996,13 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { // Update the mailbox's feerate as well. l.mailBox.SetFeeRate(fee) + // In the case where we receive a warning message from our peer, just + // log it and move on. We choose not to disconnect from our peer, + // although we "MAY" do so according to the specification. + case *lnwire.Warning: + l.log.Warnf("received warning message from peer: %v", + msg.Error.Error()) + case *lnwire.Error: // Error received from remote, MUST fail channel, but should // only print the contents of the error message if all diff --git a/peer/brontide.go b/peer/brontide.go index dd0576fba..83e108903 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -1455,6 +1455,10 @@ out: break out } + case *lnwire.Warning: + targetChan = msg.ChanID + isLinkUpdate = p.handleError(&msg.Error) + case *lnwire.Error: targetChan = msg.ChanID isLinkUpdate = p.handleError(msg) @@ -1688,6 +1692,9 @@ func messageSummary(msg lnwire.Message) string { return fmt.Sprintf("chan_id=%v, id=%v, fail_code=%v", msg.ChanID, msg.ID, msg.FailureCode) + case *lnwire.Warning: + return fmt.Sprintf("%v", msg.Error.Error()) + case *lnwire.Error: return fmt.Sprintf("%v", msg.Error()) From 4df0759ad5a0254b7c9c53c4581d473161a7e5f3 Mon Sep 17 00:00:00 2001 From: Carla Kirk-Cohen Date: Mon, 16 May 2022 15:19:19 -0400 Subject: [PATCH 3/3] docs: add 0.16 release notes and add warning logging PR --- docs/release-notes/release-notes-0.16.0.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docs/release-notes/release-notes-0.16.0.md diff --git a/docs/release-notes/release-notes-0.16.0.md b/docs/release-notes/release-notes-0.16.0.md new file mode 100644 index 000000000..b5d805d9b --- /dev/null +++ b/docs/release-notes/release-notes-0.16.0.md @@ -0,0 +1,8 @@ +# Release Notes + +## Misc +* Warning messages from peers are now recognized and [logged](https://github.com/lightningnetwork/lnd/pull/6546) by lnd. + +# Contributors (Alphabetical Order) +* Carla Kirk-Cohen +