mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-05 04:30:16 +02:00
Merge pull request #6546 from carlaKC/bolts-950-warningmessage
lnwire/peer: add ability to read + log peer warning messages
This commit is contained in:
commit
7b56b67f34
8
docs/release-notes/release-notes-0.16.0.md
Normal file
8
docs/release-notes/release-notes-0.16.0.md
Normal file
@ -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
|
||||||
|
|
@ -2008,6 +2008,13 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
|||||||
// Update the mailbox's feerate as well.
|
// Update the mailbox's feerate as well.
|
||||||
l.mailBox.SetFeeRate(fee)
|
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:
|
case *lnwire.Error:
|
||||||
// Error received from remote, MUST fail channel, but should
|
// Error received from remote, MUST fail channel, but should
|
||||||
// only print the contents of the error message if all
|
// only print the contents of the error message if all
|
||||||
|
@ -964,6 +964,12 @@ func TestLightningWireProtocol(t *testing.T) {
|
|||||||
return mainScenario(&m)
|
return mainScenario(&m)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
msgType: MsgWarning,
|
||||||
|
scenario: func(m Warning) bool {
|
||||||
|
return mainScenario(&m)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
msgType: MsgError,
|
msgType: MsgError,
|
||||||
scenario: func(m Error) bool {
|
scenario: func(m Error) bool {
|
||||||
|
@ -22,7 +22,8 @@ type MessageType uint16
|
|||||||
// The currently defined message types within this current version of the
|
// The currently defined message types within this current version of the
|
||||||
// Lightning protocol.
|
// Lightning protocol.
|
||||||
const (
|
const (
|
||||||
MsgInit MessageType = 16
|
MsgWarning MessageType = 1
|
||||||
|
MsgInit = 16
|
||||||
MsgError = 17
|
MsgError = 17
|
||||||
MsgPing = 18
|
MsgPing = 18
|
||||||
MsgPong = 19
|
MsgPong = 19
|
||||||
@ -75,6 +76,8 @@ func ErrorPayloadTooLarge(size int) error {
|
|||||||
// String return the string representation of message type.
|
// String return the string representation of message type.
|
||||||
func (t MessageType) String() string {
|
func (t MessageType) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
|
case MsgWarning:
|
||||||
|
return "Warning"
|
||||||
case MsgInit:
|
case MsgInit:
|
||||||
return "Init"
|
return "Init"
|
||||||
case MsgOpenChannel:
|
case MsgOpenChannel:
|
||||||
@ -175,6 +178,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) {
|
|||||||
var msg Message
|
var msg Message
|
||||||
|
|
||||||
switch msgType {
|
switch msgType {
|
||||||
|
case MsgWarning:
|
||||||
|
msg = &Warning{}
|
||||||
case MsgInit:
|
case MsgInit:
|
||||||
msg = &Init{}
|
msg = &Init{}
|
||||||
case MsgOpenChannel:
|
case MsgOpenChannel:
|
||||||
|
22
lnwire/warning.go
Normal file
22
lnwire/warning.go
Normal file
@ -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
|
||||||
|
}
|
@ -1455,6 +1455,10 @@ out:
|
|||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case *lnwire.Warning:
|
||||||
|
targetChan = msg.ChanID
|
||||||
|
isLinkUpdate = p.handleError(&msg.Error)
|
||||||
|
|
||||||
case *lnwire.Error:
|
case *lnwire.Error:
|
||||||
targetChan = msg.ChanID
|
targetChan = msg.ChanID
|
||||||
isLinkUpdate = p.handleError(msg)
|
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",
|
return fmt.Sprintf("chan_id=%v, id=%v, fail_code=%v",
|
||||||
msg.ChanID, msg.ID, msg.FailureCode)
|
msg.ChanID, msg.ID, msg.FailureCode)
|
||||||
|
|
||||||
|
case *lnwire.Warning:
|
||||||
|
return fmt.Sprintf("%v", msg.Error.Error())
|
||||||
|
|
||||||
case *lnwire.Error:
|
case *lnwire.Error:
|
||||||
return fmt.Sprintf("%v", msg.Error())
|
return fmt.Sprintf("%v", msg.Error())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user