Skip to content

Commit

Permalink
lnwire: add NodeAnnouncement2
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Dec 2, 2024
1 parent 9d67b34 commit 53bdf65
Show file tree
Hide file tree
Showing 3 changed files with 519 additions and 0 deletions.
85 changes: 85 additions & 0 deletions lnwire/lnwire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lnwire
import (
"bytes"
crand "crypto/rand"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"fmt"
Expand Down Expand Up @@ -1660,6 +1661,83 @@ func TestLightningWireProtocol(t *testing.T) {
ChanUpdateDisableOutgoing
}

v[0] = reflect.ValueOf(req)
},
MsgNodeAnnouncement2: func(v []reflect.Value, r *rand.Rand) {
var req NodeAnnouncement2

req.ExtraSignedFields = ExtraSignedFields(
randSignedRangeRecords(t, r),
)
req.Signature.Val = testSchnorrSig

req.NodeID.Val = randRawKey(t)
req.BlockHeight.Val = r.Uint32()
req.Features.Val = *randRawFeatureVector(r)

// Sometimes set the colour field.
if r.Int31()%2 == 0 {
color := tlv.ZeroRecordT[tlv.TlvType1, Color]()
color.Val = Color{
R: uint8(r.Int31()),
G: uint8(r.Int31()),
B: uint8(r.Int31()),
}
req.Color = tlv.SomeRecordT(color)
}

n := r.Intn(33)
b := make([]byte, n)
_, err := rand.Read(b)
require.NoError(t, err)
if n > 0 {
alias := []byte(
base64.StdEncoding.EncodeToString(b),
)
if len(alias) > 32 {
alias = alias[:32]
}

aliasRec := tlv.ZeroRecordT[
tlv.TlvType3, []byte,
]()
aliasRec.Val = alias
}

// Sometimes add some ipv4 addrs.
if r.Int31()%2 == 0 {
ipv4Addr, err := randTCP4Addr(r)
require.NoError(t, err)

ipv4AddrRecord := tlv.ZeroRecordT[
tlv.TlvType5, IPV4Addrs,
]()
ipv4AddrRecord.Val = IPV4Addrs{ipv4Addr}
req.IPV4Addrs = tlv.SomeRecordT(ipv4AddrRecord)
}
// Sometimes add some ipv6 addrs.
if r.Int31()%2 == 0 {
ipv6Addr, err := randTCP6Addr(r)
require.NoError(t, err)

ipv6AddrRecord := tlv.ZeroRecordT[
tlv.TlvType7, IPV6Addrs,
]()
ipv6AddrRecord.Val = IPV6Addrs{ipv6Addr}
req.IPV6Addrs = tlv.SomeRecordT(ipv6AddrRecord)
}
// Sometimes add some torv3 addrs.
if r.Int31()%2 == 0 {
torAddr, err := randV3OnionAddr(r)
require.NoError(t, err)

torAddrRecord := tlv.ZeroRecordT[
tlv.TlvType9, TorV3Addrs,
]()
torAddrRecord.Val = TorV3Addrs{torAddr}
req.TorV3Addrs = tlv.SomeRecordT(torAddrRecord)
}

v[0] = reflect.ValueOf(req)
},
}
Expand Down Expand Up @@ -1902,12 +1980,19 @@ func TestLightningWireProtocol(t *testing.T) {
return mainScenario(&m)
},
},

{
msgType: MsgChannelUpdate2,
scenario: func(m ChannelUpdate2) bool {
return mainScenario(&m)
},
},
{
msgType: MsgNodeAnnouncement2,
scenario: func(m NodeAnnouncement2) bool {
return mainScenario(&m)
},
},
}
for _, test := range tests {
t.Run(test.msgType.String(), func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions lnwire/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (
MsgReplyChannelRange = 264
MsgGossipTimestampRange = 265
MsgChannelAnnouncement2 = 267
MsgNodeAnnouncement2 = 269
MsgChannelUpdate2 = 271
MsgKickoffSig = 777
)
Expand Down Expand Up @@ -181,6 +182,8 @@ func (t MessageType) String() string {
return "MsgAnnounceSignatures2"
case MsgChannelAnnouncement2:
return "ChannelAnnouncement2"
case MsgNodeAnnouncement2:
return "NodeAnnouncement2"
case MsgChannelUpdate2:
return "ChannelUpdate2"
default:
Expand Down Expand Up @@ -316,6 +319,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) {
msg = &AnnounceSignatures2{}
case MsgChannelAnnouncement2:
msg = &ChannelAnnouncement2{}
case MsgNodeAnnouncement2:
msg = &NodeAnnouncement2{}
case MsgChannelUpdate2:
msg = &ChannelUpdate2{}
default:
Expand Down
Loading

0 comments on commit 53bdf65

Please sign in to comment.