Skip to content

Commit 6706f45

Browse files
committed
multi: remove tor v2 onion address encoder paths
Drop the v2 onion encoder branches from lnwire.WriteOnionAddr, graph/db.encodeOnionAddr, graph/db.collectAddressRecords, and the tor.OnionHostToFakeIP helper. lnd no longer produces v2 onion addresses on any code path. Decoders for v2 addresses are intentionally retained in lnwire, graph/db, and tor so that existing graph databases and peer-announced v2 addresses continue to deserialize. Update unit tests to use v3 onion fixtures.
1 parent 0a7f915 commit 6706f45

13 files changed

Lines changed: 30 additions & 131 deletions

File tree

chanbackup/single_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ var (
3838
addr1, _ = net.ResolveTCPAddr("tcp", "10.0.0.2:9000")
3939
addr2, _ = net.ResolveTCPAddr("tcp", "10.0.0.3:9000")
4040
addr3 = &tor.OnionAddr{
41-
OnionService: "3g2upl4pq6kufc4m.onion",
42-
Port: 9735,
41+
OnionService: "vww6ybal4bd7szmgncyruucpgfkqahzd" +
42+
"di37ktceo3ah7ngmcopnpyyd.onion",
43+
Port: 9735,
4344
}
4445
addr4 = &lnwire.DNSAddress{
4546
Hostname: "example.com",

graph/db/addr.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ func encodeOnionAddr(w io.Writer, addr *tor.OnionAddr) error {
104104
var suffixIndex int
105105
hostLen := len(addr.OnionService)
106106
switch hostLen {
107-
case tor.V2Len:
108-
if _, err := w.Write([]byte{byte(v2OnionAddr)}); err != nil {
109-
return err
110-
}
111-
suffixIndex = tor.V2Len - tor.OnionSuffixLen
112107
case tor.V3Len:
113108
if _, err := w.Write([]byte{byte(v3OnionAddr)}); err != nil {
114109
return err
@@ -131,12 +126,7 @@ func encodeOnionAddr(w io.Writer, addr *tor.OnionAddr) error {
131126
}
132127

133128
// Sanity check the decoded length.
134-
switch {
135-
case hostLen == tor.V2Len && len(host) != tor.V2DecodedLen:
136-
return fmt.Errorf("onion service %v decoded to invalid host %x",
137-
addr.OnionService, host)
138-
139-
case hostLen == tor.V3Len && len(host) != tor.V3DecodedLen:
129+
if hostLen == tor.V3Len && len(host) != tor.V3DecodedLen {
140130
return fmt.Errorf("onion service %v decoded to invalid host %x",
141131
addr.OnionService, host)
142132
}

graph/db/addr_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ var (
2929
Port: 65535,
3030
}
3131

32-
testOnionV2Addr = &tor.OnionAddr{
33-
OnionService: "3g2upl4pq6kufc4m.onion",
34-
Port: 9735,
35-
}
36-
3732
testOnionV3Addr = &tor.OnionAddr{
3833
OnionService: "vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion", //nolint:ll
3934
Port: 80,
@@ -63,9 +58,6 @@ var addrTests = []struct {
6358
{
6459
expAddr: testIPV6Addr,
6560
},
66-
{
67-
expAddr: testOnionV2Addr,
68-
},
6961
{
7062
expAddr: testOnionV3Addr,
7163
},

graph/db/graph_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ func testNodeInsertionAndDeletion(t *testing.T, v lnwire.GossipVersion) {
400400
// Add 2 IPV6 addresses.
401401
testIPV6Addr,
402402
anotherAddr,
403-
// Add one v2 and one v3 onion address.
404-
testOnionV2Addr,
403+
// Add a v3 onion address.
405404
testOnionV3Addr,
406405
// Add a DNS host address.
407406
testDNSAddr,
@@ -439,7 +438,6 @@ func testNodeInsertionAndDeletion(t *testing.T, v lnwire.GossipVersion) {
439438

440439
// Finally, update the set to only contain the Tor addresses.
441440
expAddrs = []net.Addr{
442-
testOnionV2Addr,
443441
testOnionV3Addr,
444442
}
445443
node = nodeWithAddrs(expAddrs)

graph/db/sql_store.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,7 +4821,6 @@ func collectAddressRecords(addresses []net.Addr) (map[dbAddressType][]string,
48214821
newAddresses := map[dbAddressType][]string{
48224822
addressTypeIPv4: {},
48234823
addressTypeIPv6: {},
4824-
addressTypeTorV2: {},
48254824
addressTypeTorV3: {},
48264825
addressTypeDNS: {},
48274826
addressTypeOpaque: {},
@@ -4844,8 +4843,6 @@ func collectAddressRecords(addresses []net.Addr) (map[dbAddressType][]string,
48444843

48454844
case *tor.OnionAddr:
48464845
switch len(addr.OnionService) {
4847-
case tor.V2Len:
4848-
addAddr(addressTypeTorV2, addr)
48494846
case tor.V3Len:
48504847
addAddr(addressTypeTorV3, addr)
48514848
default:

itest/lnd_channel_graph_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ func testNodeAnnouncement(ht *lntest.HarnessTest) {
378378
advertisedAddrs := []string{
379379
"192.168.1.1:8333",
380380
"[2001:db8:85a3:8d3:1319:8a2e:370:7348]:8337",
381-
"bkb6azqggsaiskzi.onion:9735",
382381
"fomvuglh6h6vcag73xo5t5gv56ombih3zr2xvplkpbfd7wrog4swj" +
383382
"wid.onion:1234",
384383
}
@@ -435,7 +434,6 @@ func testUpdateNodeAnnouncement(ht *lntest.HarnessTest) {
435434
extraAddrs := []string{
436435
"192.168.1.1:8333",
437436
"[2001:db8:85a3:8d3:1319:8a2e:370:7348]:8337",
438-
"bkb6azqggsaiskzi.onion:9735",
439437
"fomvuglh6h6vcag73xo5t5gv56ombih3zr2xvplkpbfd7wrog4swj" +
440438
"wid.onion:1234",
441439
}

lnwire/lnwire_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ func TestDecodeUnknownAddressType(t *testing.T) {
137137

138138
// Add an onion address.
139139
onionAddr := &tor.OnionAddr{
140-
OnionService: "abcdefghijklmnop.onion",
141-
Port: 9065,
140+
OnionService: "abcdefghij" +
141+
"abcdefghijabcdefghij" +
142+
"abcdefghijabcdefghij" +
143+
"234567.onion",
144+
Port: 9065,
142145
}
143146

144147
// Now add an address with an unknown type.

lnwire/message_test.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -964,24 +964,6 @@ func randTCP6Addr(t testing.TB, r *rand.Rand) *net.TCPAddr {
964964
return &net.TCPAddr{IP: addrIP, Port: addrPort}
965965
}
966966

967-
func randV2OnionAddr(t testing.TB, r *rand.Rand) *tor.OnionAddr {
968-
t.Helper()
969-
970-
var serviceID [tor.V2DecodedLen]byte
971-
_, err := r.Read(serviceID[:])
972-
require.NoError(t, err, "unable to read serviceID")
973-
974-
var port [2]byte
975-
_, err = r.Read(port[:])
976-
require.NoError(t, err, "unable to read port")
977-
978-
onionService := tor.Base32Encoding.EncodeToString(serviceID[:])
979-
onionService += tor.OnionSuffix
980-
addrPort := int(binary.BigEndian.Uint16(port[:]))
981-
982-
return &tor.OnionAddr{OnionService: onionService, Port: addrPort}
983-
}
984-
985967
func randV3OnionAddr(t testing.TB, r *rand.Rand) *tor.OnionAddr {
986968
t.Helper()
987969

@@ -1021,11 +1003,10 @@ func randDNSAddr(t testing.TB, r *rand.Rand) *lnwire.DNSAddress {
10211003
func randAddrs(t testing.TB, r *rand.Rand) []net.Addr {
10221004
tcp4Addr := randTCP4Addr(t, r)
10231005
tcp6Addr := randTCP6Addr(t, r)
1024-
v2OnionAddr := randV2OnionAddr(t, r)
10251006
v3OnionAddr := randV3OnionAddr(t, r)
10261007
dnsAddr := randDNSAddr(t, r)
10271008

1028-
return []net.Addr{tcp4Addr, tcp6Addr, v2OnionAddr, v3OnionAddr, dnsAddr}
1009+
return []net.Addr{tcp4Addr, tcp6Addr, v3OnionAddr, dnsAddr}
10291010
}
10301011

10311012
func randAlias(r *rand.Rand) lnwire.NodeAlias {

lnwire/writer.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,6 @@ func WriteOnionAddr(buf *bytes.Buffer, addr *tor.OnionAddr) error {
336336

337337
// Decide the suffixIndex and descriptor.
338338
switch len(addr.OnionService) {
339-
case tor.V2Len:
340-
descriptor = []byte{byte(v2OnionAddr)}
341-
suffixIndex = tor.V2Len - tor.OnionSuffixLen
342-
343339
case tor.V3Len:
344340
descriptor = []byte{byte(v3OnionAddr)}
345341
suffixIndex = tor.V3Len - tor.OnionSuffixLen

lnwire/writer_test.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -501,26 +501,14 @@ func TestWriteOnionAddr(t *testing.T) {
501501
// the error is returned.
502502
name: "invalid base32 encoding",
503503
addr: &tor.OnionAddr{
504-
OnionService: "1234567890123456.onion",
504+
OnionService: "1111111111" +
505+
"11111111111111111111" +
506+
"11111111111111111111" +
507+
"111111.onion",
505508
},
506509
expectedErr: base32.CorruptInputError(0),
507510
expectedBytes: nil,
508511
},
509-
{
510-
// Check write onion v2.
511-
name: "onion address v2",
512-
addr: &tor.OnionAddr{
513-
OnionService: "abcdefghijklmnop.onion",
514-
Port: 9065,
515-
},
516-
expectedErr: nil,
517-
expectedBytes: []byte{
518-
0x3, // The descriptor.
519-
0x0, 0x44, 0x32, 0x14, 0xc7, // The host.
520-
0x42, 0x54, 0xb6, 0x35, 0xcf,
521-
0x23, 0x69, // The port.
522-
},
523-
},
524512
{
525513
// Check write onion v3.
526514
name: "onion address v3",
@@ -566,8 +554,11 @@ func TestWriteNetAddrs(t *testing.T) {
566554
Port: 8080,
567555
}
568556
onionAddr := &tor.OnionAddr{
569-
OnionService: "abcdefghijklmnop.onion",
570-
Port: 9065,
557+
OnionService: "abcdefghij" +
558+
"abcdefghijabcdefghij" +
559+
"abcdefghijabcdefghij" +
560+
"234567.onion",
561+
Port: 9065,
571562
}
572563
dnsAddr := &DNSAddress{
573564
Hostname: "example.com",
@@ -602,14 +593,18 @@ func TestWriteNetAddrs(t *testing.T) {
602593
addr: []net.Addr{tcpAddr, onionAddr, dnsAddr},
603594
expectedErr: nil,
604595
expectedBytes: []byte{
605-
// 7 bytes for TCP and 13 bytes for onion,
596+
// 7 bytes for TCP, 38 bytes for v3 onion,
606597
// 15 bytes for DNS.
607-
0x0, 0x23,
598+
0x0, 0x3c,
608599
// TCP address.
609600
0x1, 0x7f, 0x0, 0x0, 0x1, 0x1f, 0x90,
610-
// Onion address.
611-
0x3, 0x0, 0x44, 0x32, 0x14, 0xc7, 0x42,
612-
0x54, 0xb6, 0x35, 0xcf, 0x23, 0x69,
601+
// V3 onion address.
602+
0x4, 0x0, 0x44, 0x32, 0x14, 0xc7, 0x42, 0x40,
603+
0x11, 0xc, 0x85, 0x31, 0xd0, 0x90, 0x4,
604+
0x43, 0x21, 0x4c, 0x74, 0x24, 0x1, 0x10,
605+
0xc8, 0x53, 0x1d, 0x9, 0x0, 0x44, 0x32,
606+
0x14, 0xc7, 0x42, 0x75, 0xbe, 0x77, 0xdf,
607+
0x23, 0x69,
613608
// DNS address.
614609
0x5, 0xb, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
615610
0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x1f, 0x90,

0 commit comments

Comments
 (0)