From 412e05f85f57002a6a73e6bca6ca0f8d74c20a5e Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 23 May 2025 16:14:47 +0200 Subject: [PATCH] lnwire: add *OpaqueAddrs case in WriteElements And then expand the chanbackup unit tests to cover such a case. --- chanbackup/backup_test.go | 1 + chanbackup/multi_test.go | 4 +++- chanbackup/single_test.go | 13 +++++++++++-- lnwire/lnwire.go | 5 +++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/chanbackup/backup_test.go b/chanbackup/backup_test.go index 46696da76..d36fa385b 100644 --- a/chanbackup/backup_test.go +++ b/chanbackup/backup_test.go @@ -157,6 +157,7 @@ func TestFetchStaticChanBackups(t *testing.T) { chanSource.addAddrsForNode(randomChan1.IdentityPub, []net.Addr{addr1}) chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr2}) chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr3}) + chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr4}) // With the channel source populated, we'll now attempt to create a set // of backups for all the channels. This should succeed, as all items diff --git a/chanbackup/multi_test.go b/chanbackup/multi_test.go index eeff81788..3350c773c 100644 --- a/chanbackup/multi_test.go +++ b/chanbackup/multi_test.go @@ -22,7 +22,9 @@ func TestMultiPackUnpack(t *testing.T) { t.Fatalf("unable to gen channel: %v", err) } - single := NewSingle(channel, []net.Addr{addr1, addr2, addr3}) + single := NewSingle( + channel, []net.Addr{addr1, addr2, addr3, addr4}, + ) originalSingles = append(originalSingles, single) multi.StaticBackups = append(multi.StaticBackups, single) diff --git a/chanbackup/single_test.go b/chanbackup/single_test.go index 78957f38b..b3c7471a3 100644 --- a/chanbackup/single_test.go +++ b/chanbackup/single_test.go @@ -41,6 +41,11 @@ var ( OnionService: "3g2upl4pq6kufc4m.onion", Port: 9735, } + addr4 = &lnwire.OpaqueAddrs{ + // The first byte must be an address type we are not yet aware + // of for it to be a valid OpaqueAddrs. + Payload: []byte{math.MaxUint8, 1, 2, 3, 4}, + } ) func assertSingleEqual(t *testing.T, a, b Single) { @@ -314,7 +319,9 @@ func TestSinglePackUnpack(t *testing.T) { channel, err := genRandomOpenChannelShell() require.NoError(t, err, "unable to gen open channel") - singleChanBackup := NewSingle(channel, []net.Addr{addr1, addr2, addr3}) + singleChanBackup := NewSingle( + channel, []net.Addr{addr1, addr2, addr3, addr4}, + ) keyRing := &lnencrypt.MockKeyRing{} @@ -639,7 +646,9 @@ func TestSingleUnconfirmedChannel(t *testing.T) { channel.ShortChannelID.BlockHeight = 0 channel.FundingBroadcastHeight = fundingBroadcastHeight - singleChanBackup := NewSingle(channel, []net.Addr{addr1, addr2, addr3}) + singleChanBackup := NewSingle( + channel, []net.Addr{addr1, addr2, addr3, addr4}, + ) keyRing := &lnencrypt.MockKeyRing{} // Pack it and then unpack it again to make sure everything is written diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index bb0fd55f7..fa43d25bf 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -348,6 +348,11 @@ func WriteElement(w *bytes.Buffer, element interface{}) error { return err } + case *OpaqueAddrs: + if err := WriteOpaqueAddrs(w, e); err != nil { + return err + } + case []net.Addr: // First, we'll encode all the addresses into an intermediate // buffer. We need to do this in order to compute the total