-
Notifications
You must be signed in to change notification settings - Fork 359
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
Prefer non-Tor nodes when creating blinded paths #2911
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,16 +358,19 @@ where | |
const MIN_PEER_CHANNELS: usize = 3; | ||
|
||
let network_graph = self.network_graph.deref().read_only(); | ||
let paths = peers.iter() | ||
let mut peer_info = peers.iter() | ||
// Limit to peers with announced channels | ||
.filter(|pubkey| | ||
.filter_map(|pubkey| | ||
network_graph | ||
.node(&NodeId::from_pubkey(pubkey)) | ||
.map(|info| &info.channels[..]) | ||
.map(|channels| channels.len() >= MIN_PEER_CHANNELS) | ||
.unwrap_or(false) | ||
.filter(|info| info.channels.len() >= MIN_PEER_CHANNELS) | ||
.map(|info| (*pubkey, info.is_tor_only())) | ||
) | ||
.map(|pubkey| vec![*pubkey, recipient]) | ||
.collect::<Vec<_>>(); | ||
peer_info.sort_unstable_by(|(_, a_tor_only), (_, b_tor_only)| a_tor_only.cmp(b_tor_only)); | ||
|
||
Comment on lines
+361
to
+371
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. The logic for filtering and sorting peers based on their channel information and Tor status has been updated. While the approach of using
Consider enhancing the documentation within this code segment to explain the rationale behind the filtering and sorting logic, especially for future maintainers or contributors who may not be familiar with the specific objectives of these changes. |
||
let paths = peer_info.into_iter() | ||
.map(|(pubkey, _)| vec![pubkey, recipient]) | ||
.map(|node_pks| BlindedPath::new_for_message(&node_pks, &*self.entropy_source, secp_ctx)) | ||
.take(MAX_PATHS) | ||
.collect::<Result<Vec<_>, _>>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
announce_node_address
is well-structured and follows Rust's idiomatic practices. It correctly constructs aNodeAnnouncement
message and disseminates it to the specified peers. However, consider adding error handling for theunwrap
calls to prevent potential panics in production code.