This repository was archived by the owner on Jan 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
imp(discovery): clippy + cleanup #591
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,26 +21,24 @@ pub async fn get_nodes(data: Data<AppState>) -> HttpResponse { | |||||
| } | ||||||
|
|
||||||
| fn filter_nodes_for_pool(nodes: Vec<DiscoveryNode>, pool_id: u32) -> Vec<DiscoveryNode> { | ||||||
| let nodes_for_pool: Vec<DiscoveryNode> = nodes | ||||||
| .iter() | ||||||
| .filter(|node| node.compute_pool_id == pool_id) | ||||||
| .cloned() | ||||||
| .collect(); | ||||||
|
|
||||||
| // Filter out nodes with IPs that are currently active in another pool | ||||||
| let filtered: Vec<DiscoveryNode> = nodes_for_pool | ||||||
| .iter() | ||||||
| .filter(|node| { | ||||||
| // Check if there's any other node with the same IP address in a different pool that is active | ||||||
| !nodes.iter().any(|other| { | ||||||
| other.ip_address == node.ip_address | ||||||
| && other.compute_pool_id != node.compute_pool_id | ||||||
| && other.is_active | ||||||
| }) | ||||||
| }) | ||||||
| .cloned() | ||||||
| .collect(); | ||||||
| filtered | ||||||
| // First pass: collect nodes for the target pool | ||||||
| let mut nodes_for_pool = Vec::new(); | ||||||
| let mut other_active_ips = std::collections::HashSet::new(); | ||||||
|
|
||||||
| // Single pass through all nodes to collect both target pool nodes and active IPs from other pools | ||||||
| for node in nodes { | ||||||
| if node.compute_pool_id == pool_id { | ||||||
| nodes_for_pool.push(node); | ||||||
| } else if node.is_active { | ||||||
| other_active_ips.insert(node.ip_address.clone()); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Filter out nodes whose IPs are active in other pools | ||||||
| nodes_for_pool | ||||||
| .into_iter() | ||||||
| .filter(|node| !other_active_ips.contains(&node.ip_address)) | ||||||
| .collect() | ||||||
| } | ||||||
|
|
||||||
| pub async fn get_nodes_for_pool( | ||||||
|
|
@@ -51,14 +49,14 @@ pub async fn get_nodes_for_pool( | |||||
| let nodes = data.node_store.get_nodes().await; | ||||||
| match nodes { | ||||||
| Ok(nodes) => { | ||||||
| let id_clone = pool_id.clone(); | ||||||
| let pool_contract_id: U256 = match id_clone.parse::<U256>() { | ||||||
| let pool_contract_id: U256 = match pool_id.parse::<U256>() { | ||||||
| Ok(id) => id, | ||||||
| Err(_) => { | ||||||
| return HttpResponse::BadRequest() | ||||||
| .json(ApiResponse::new(false, "Invalid pool ID format")); | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| let pool_id: u32 = match pool_id.parse() { | ||||||
|
||||||
| let pool_id: u32 = match pool_id.parse() { | |
| let parsed_pool_id: u32 = match pool_id.parse() { |
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
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.
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.
[nitpick] You parse
pool_idtwice (once toU256and again tou32). Consider parsing once tou32and converting toU256usingU256::from(parsed_id)to avoid duplication and improve readability.