From 1477c754f5ba4d964fa7c6bc4e1a08c5fc4ecc64 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 21 Apr 2022 10:53:06 +0200 Subject: [PATCH] lnwire: store unknown address type as OpaqueAddrs Instead of erroring out with encountering an address with an unknown type, we just store the remainder of the addrBytes as OpaqueAddrs so that we are able to rewrite them to the wire when we re-propagate the message. --- lnwire/lnwire.go | 24 +++++++++++++++++++++++- lnwire/lnwire_test.go | 7 +++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index 290fc4ed0..0361d7648 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -804,7 +804,29 @@ func ReadElement(r io.Reader, element interface{}) error { addrBytesRead += aType.AddrLen() default: - return &ErrUnknownAddrType{aType} + // If we don't understand this address type, + // we just store it along with the remaining + // address bytes as type OpaqueAddrs. We need + // to hold onto the bytes so that we can still + // write them back to the wire when we + // propagate this message. + payloadLen := 1 + addrsLen - addrBytesRead + payload := make([]byte, payloadLen) + + // First write a byte for the address type that + // we already read. + payload[0] = byte(aType) + + // Now append the rest of the address bytes. + _, err := io.ReadFull(addrBuf, payload[1:]) + if err != nil { + return err + } + + address = &OpaqueAddrs{ + Payload: payload, + } + addrBytesRead = addrsLen } addresses = append(addresses, address) diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index fb0b746ef..3cbc34803 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -259,8 +259,11 @@ func TestDecodeUnknownAddressType(t *testing.T) { // Now we attempt to parse the bytes and assert that we get an error. var addrs []net.Addr err = ReadElement(buffer, &addrs) - require.Error(t, err) - require.IsType(t, err, &ErrUnknownAddrType{}) + require.NoError(t, err) + require.Len(t, addrs, 3) + require.Equal(t, tcpAddr.String(), addrs[0].String()) + require.Equal(t, onionAddr.String(), addrs[1].String()) + require.Equal(t, hex.EncodeToString(data), addrs[2].String()) } func TestMaxOutPointIndex(t *testing.T) {