|
1 | 1 | use colored::Colorize;
|
2 |
| -use dkn_p2p::libp2p::multiaddr::Protocol; |
3 | 2 | use std::time::Duration;
|
4 | 3 |
|
5 |
| -use crate::{refresh_dria_nodes, utils::get_points, DriaComputeNode, DRIA_COMPUTE_NODE_VERSION}; |
| 4 | +use crate::{utils::get_points, DriaComputeNode, DRIA_COMPUTE_NODE_VERSION}; |
6 | 5 |
|
7 | 6 | /// Number of seconds such that if the last heartbeat ACK is older than this, the node is considered unreachable.
|
8 | 7 | const HEARTBEAT_LIVENESS_SECS: Duration = Duration::from_secs(150);
|
@@ -81,51 +80,31 @@ impl DriaComputeNode {
|
81 | 80 | HEARTBEAT_LIVENESS_SECS.as_secs()
|
82 | 81 | );
|
83 | 82 | }
|
84 |
| - |
85 |
| - // added rpc nodes check, sometimes this happens when API is down / bugs for some reason |
86 |
| - if self.dria_nodes.rpc_peerids.is_empty() { |
87 |
| - log::error!("No RPC peer IDs were found to be available, please restart your node!",); |
88 |
| - } |
89 | 83 | }
|
90 | 84 |
|
91 | 85 | /// Updates the local list of available nodes by refreshing it.
|
92 | 86 | /// Dials the RPC nodes again for better connectivity.
|
93 | 87 | pub(crate) async fn handle_available_nodes_refresh(&mut self) {
|
94 | 88 | log::info!("Refreshing available Dria nodes.");
|
95 | 89 |
|
96 |
| - // refresh available nodes |
97 |
| - if let Err(e) = refresh_dria_nodes(&mut self.dria_nodes).await { |
98 |
| - log::error!("Error refreshing available nodes: {:?}", e); |
| 90 | + // FIXME: what to do for refreshing nodes |
| 91 | + // if let Err(e) = refresh_dria_nodes(&mut self.dria_nodes).await { |
| 92 | + // log::error!("Error refreshing available nodes: {:?}", e); |
| 93 | + // }; |
| 94 | + |
| 95 | + // TODO: check if we are connected to the node, and dial again if not |
| 96 | + |
| 97 | + // dial the RPC |
| 98 | + log::info!("Dialling RPC at: {}", self.dria_nodes.addr); |
| 99 | + let fut = self |
| 100 | + .p2p |
| 101 | + .dial(self.dria_nodes.peer_id, self.dria_nodes.addr.clone()); |
| 102 | + match tokio::time::timeout(Duration::from_secs(10), fut).await { |
| 103 | + Err(timeout) => log::error!("Timeout dialling RPC node: {:?}", timeout), |
| 104 | + Ok(res) => match res { |
| 105 | + Err(e) => log::warn!("Error dialling RPC node: {:?}", e), |
| 106 | + Ok(_) => log::info!("Successfully dialled RPC!"), |
| 107 | + }, |
99 | 108 | };
|
100 |
| - |
101 |
| - // dial all rpc nodes |
102 |
| - for addr in self.dria_nodes.rpc_addrs.iter() { |
103 |
| - log::info!("Dialling RPC node: {}", addr); |
104 |
| - |
105 |
| - // get peer id from rpc address |
106 |
| - if let Some(peer_id) = addr.iter().find_map(|p| match p { |
107 |
| - Protocol::P2p(peer_id) => Some(peer_id), |
108 |
| - _ => None, |
109 |
| - }) { |
110 |
| - let fut = self.p2p.dial(peer_id, addr.clone()); |
111 |
| - match tokio::time::timeout(Duration::from_secs(10), fut).await { |
112 |
| - Err(timeout) => { |
113 |
| - log::error!("Timeout dialling RPC node: {:?}", timeout); |
114 |
| - } |
115 |
| - Ok(res) => match res { |
116 |
| - Err(e) => { |
117 |
| - log::warn!("Error dialling RPC node: {:?}", e); |
118 |
| - } |
119 |
| - Ok(_) => { |
120 |
| - log::info!("Successfully dialled RPC node: {}", addr); |
121 |
| - } |
122 |
| - }, |
123 |
| - }; |
124 |
| - } else { |
125 |
| - log::warn!("Missing peerID in address: {}", addr); |
126 |
| - } |
127 |
| - } |
128 |
| - |
129 |
| - log::info!("Finished refreshing!"); |
130 | 109 | }
|
131 | 110 | }
|
0 commit comments