-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Drop tor v2 onion production, keep wire codec faithful #10813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
erickcestari
wants to merge
6
commits into
lightningnetwork:master
Choose a base branch
from
erickcestari:tor-v2-cleanup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
95aee06
multi: drop tor v2 onion production, keep wire codec faithful
erickcestari b866b0b
docs: document tor v2 onion handling in 0.21 release notes
erickcestari 144e386
fixup! multi: drop tor v2 onion production, keep wire codec faithful
erickcestari 69946e2
fixup! multi: drop tor v2 onion production, keep wire codec faithful
erickcestari fdbe3bd
fixup! multi: drop tor v2 onion production, keep wire codec faithful
erickcestari 0a40749
fixup! multi: drop tor v2 onion production, keep wire codec faithful
erickcestari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package discovery | ||
|
|
||
| import ( | ||
| "context" | ||
| "net" | ||
| "testing" | ||
|
|
||
| "github.com/btcsuite/btcd/btcec/v2" | ||
| "github.com/lightningnetwork/lnd/autopilot" | ||
| "github.com/lightningnetwork/lnd/tor" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // stubNode is a minimal autopilot.Node implementation used to drive | ||
| // ChannelGraphBootstrapper from a unit test. | ||
| type stubNode struct { | ||
| pub *btcec.PublicKey | ||
| addrs []net.Addr | ||
| } | ||
|
|
||
| func (n *stubNode) PubKey() [33]byte { | ||
| var out [33]byte | ||
| copy(out[:], n.pub.SerializeCompressed()) | ||
| return out | ||
| } | ||
|
|
||
| func (n *stubNode) Addrs() []net.Addr { return n.addrs } | ||
|
|
||
| // stubChannelGraph yields a fixed list of nodes from ForEachNode and is | ||
| // otherwise unused by SampleNodeAddrs. | ||
| type stubChannelGraph struct { | ||
| nodes []autopilot.Node | ||
| } | ||
|
|
||
| func (s *stubChannelGraph) ForEachNode(ctx context.Context, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: missing godoc |
||
| cb func(context.Context, autopilot.Node) error, _ func()) error { | ||
|
|
||
| for _, n := range s.nodes { | ||
| if err := cb(ctx, n); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (s *stubChannelGraph) ForEachNodesChannels(_ context.Context, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Missing godoc |
||
| _ func(context.Context, autopilot.NodeID, | ||
| []*autopilot.ChannelEdge) error, _ func()) error { | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // TestGraphBootstrapperSkipsV2Onion ensures SampleNodeAddrs strips Tor v2 | ||
| // .onion entries from the returned candidate set so the connection manager | ||
| // never attempts to dial an obsolete v2 hidden service surfaced through the | ||
| // channel graph. A node whose remaining addresses include a v3 .onion or | ||
| // plain TCP entry is still returned for those addresses, and a node whose | ||
| // only address is v2 contributes nothing. | ||
| func TestGraphBootstrapperSkipsV2Onion(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| v2 := &tor.OnionAddr{ | ||
| OnionService: "3g2upl4pq6kufc4m.onion", | ||
| Port: 9735, | ||
| } | ||
| v3 := &tor.OnionAddr{ | ||
| OnionService: "4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnz" + | ||
| "jpbi7utijcltosqemad.onion", | ||
| Port: 9735, | ||
| } | ||
| tcp := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 9735} | ||
|
|
||
| mkPub := func(t *testing.T) *btcec.PublicKey { | ||
| t.Helper() | ||
| priv, err := btcec.NewPrivateKey() | ||
| require.NoError(t, err) | ||
|
|
||
| return priv.PubKey() | ||
| } | ||
|
|
||
| mixedPub := mkPub(t) | ||
| v2OnlyPub := mkPub(t) | ||
|
|
||
| graph := &stubChannelGraph{ | ||
| nodes: []autopilot.Node{ | ||
| &stubNode{ | ||
| pub: mixedPub, | ||
| addrs: []net.Addr{v2, v3, tcp}, | ||
| }, | ||
| &stubNode{ | ||
| pub: v2OnlyPub, | ||
| addrs: []net.Addr{v2}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| // Use deterministic sampling so the hash accumulator never skips a | ||
| // node — every eligible address must surface on each call. | ||
| bs, err := NewGraphBootstrapper(graph, true) | ||
| require.NoError(t, err) | ||
|
|
||
| // Ask for more addresses than the graph holds so the bootstrapper | ||
| // drains it in a single pass. | ||
| got, err := bs.SampleNodeAddrs( | ||
| t.Context(), 10, map[autopilot.NodeID]struct{}{}, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| // Collect (pubkey, address) pairs we expect — the v2-only node must | ||
| // not contribute any NetAddress, and the mixed node contributes only | ||
| // v3 and tcp. | ||
| type seenAddr struct { | ||
| pub [33]byte | ||
| addr string | ||
| } | ||
| seen := make(map[seenAddr]struct{}, len(got)) | ||
| for _, na := range got { | ||
| var p [33]byte | ||
| copy(p[:], na.IdentityKey.SerializeCompressed()) | ||
| seen[seenAddr{pub: p, addr: na.Address.String()}] = struct{}{} | ||
| } | ||
|
|
||
| var mixedKey, v2OnlyKey [33]byte | ||
| copy(mixedKey[:], mixedPub.SerializeCompressed()) | ||
| copy(v2OnlyKey[:], v2OnlyPub.SerializeCompressed()) | ||
|
|
||
| // Mixed node yields v3 and tcp entries. | ||
| require.Contains(t, seen, seenAddr{ | ||
| pub: mixedKey, addr: v3.String(), | ||
| }) | ||
| require.Contains(t, seen, seenAddr{ | ||
| pub: mixedKey, addr: tcp.String(), | ||
| }) | ||
|
|
||
| // No v2 entry surfaces, for either node. | ||
| for s := range seen { | ||
| require.NotEqual(t, v2.String(), s.addr, | ||
| "v2 onion %v leaked into candidate set", s.addr) | ||
| require.NotEqual(t, v2OnlyKey, s.pub, | ||
| "v2-only node %x should contribute nothing", s.pub) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.