Skip to content

Commit 406185b

Browse files
committed
add peer & address log, timeout on bad dials
1 parent fce0863 commit 406185b

File tree

7 files changed

+44
-23
lines changed

7 files changed

+44
-23
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ default-members = ["compute"]
99

1010
[workspace.package]
1111
edition = "2021"
12-
version = "0.3.2"
12+
version = "0.3.3"
1313
license = "Apache-2.0"
1414
readme = "README.md"
1515

compute/src/config.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use dkn_p2p::{libp2p::Multiaddr, DriaNetworkType};
1+
use dkn_p2p::{
2+
libp2p::{Multiaddr, PeerId},
3+
DriaNetworkType,
4+
};
25
use dkn_workflows::DriaWorkflowsConfig;
36
use eyre::{eyre, Result};
47
use libsecp256k1::{PublicKey, SecretKey};
@@ -15,8 +18,10 @@ pub struct DriaComputeNodeConfig {
1518
pub secret_key: SecretKey,
1619
/// Wallet public key, derived from the secret key.
1720
pub public_key: PublicKey,
18-
/// Wallet address, derived from the public key.
19-
pub address: [u8; 20],
21+
/// Wallet address in hex, derived from the public key.
22+
pub address: String,
23+
/// Peer ID of the node.
24+
pub peer_id: PeerId,
2025
/// P2P listen address, e.g. `/ip4/0.0.0.0/tcp/4001`.
2126
pub p2p_listen_addr: Multiaddr,
2227
/// Workflow configurations, e.g. models and providers.
@@ -64,14 +69,13 @@ impl DriaComputeNodeConfig {
6469
hex::encode(public_key.serialize_compressed())
6570
);
6671

67-
let address = public_key_to_address(&public_key);
68-
log::info!("Node Address: 0x{}", hex::encode(address));
72+
// print address
73+
let address = hex::encode(public_key_to_address(&public_key));
74+
log::info!("Node Address: 0x{}", address);
6975

7076
// to this here to log the peer id at start
71-
log::info!(
72-
"Node PeerID: {}",
73-
secret_to_keypair(&secret_key).public().to_peer_id()
74-
);
77+
let peer_id = secret_to_keypair(&secret_key).public().to_peer_id();
78+
log::info!("Node PeerID: {}", peer_id);
7579

7680
// parse listen address
7781
let p2p_listen_addr_str = env::var("DKN_P2P_LISTEN_ADDR")
@@ -94,6 +98,7 @@ impl DriaComputeNodeConfig {
9498
secret_key,
9599
public_key,
96100
address,
101+
peer_id,
97102
workflows,
98103
p2p_listen_addr,
99104
network_type,

compute/src/node/core.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl DriaComputeNode {
1111
/// Number of seconds between refreshing for diagnostic prints.
1212
const DIAGNOSTIC_REFRESH_INTERVAL_SECS: u64 = 30;
1313
/// Number of seconds between refreshing the available nodes.
14-
const AVAILABLE_NODES_REFRESH_INTERVAL_SECS: u64 = 30 * 60; // 30 minutes
14+
const AVAILABLE_NODES_REFRESH_INTERVAL_SECS: u64 = 10 * 60; // 30 minutes
1515

1616
// prepare durations for sleeps
1717
let mut diagnostic_refresh_interval =
@@ -41,22 +41,22 @@ impl DriaComputeNode {
4141
// a GossipSub message is received from the channel
4242
// this is expected to be sent by the p2p client
4343
gossipsub_msg_opt = self.gossip_message_rx.recv() => {
44-
let (peer_id, message_id, message) = gossipsub_msg_opt.ok_or(eyre!("message_rx channel closed unexpectedly."))?;
44+
let (propagation_peer_id, message_id, message) = gossipsub_msg_opt.ok_or(eyre!("message_rx channel closed unexpectedly"))?;
4545

4646
// handle the message, returning a message acceptance for the received one
47-
let acceptance = self.handle_message((peer_id, &message_id, message)).await;
47+
let acceptance = self.handle_message((propagation_peer_id, &message_id, message)).await;
4848

4949
// validate the message based on the acceptance
5050
// cant do anything but log if this gives an error as well
51-
if let Err(e) = self.p2p.validate_message(&message_id, &peer_id, acceptance).await {
51+
if let Err(e) = self.p2p.validate_message(&message_id, &propagation_peer_id, acceptance).await {
5252
log::error!("Error validating message {}: {:?}", message_id, e);
5353
}
5454

5555
},
5656

5757
// a Request is received from the channel, sent by p2p client
5858
request_msg_opt = self.request_rx.recv() => {
59-
let request = request_msg_opt.ok_or(eyre!("request_rx channel closed unexpectedly."))?;
59+
let request = request_msg_opt.ok_or(eyre!("request_rx channel closed unexpectedly"))?;
6060
if let Err(e) = self.handle_request(request).await {
6161
log::error!("Error handling request: {:?}", e);
6262
}

compute/src/node/diagnostic.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ impl DriaComputeNode {
4343
));
4444
}
4545

46+
// print peer id and address
47+
diagnostics.push(format!("Peer ID: {}", self.config.peer_id));
48+
diagnostics.push(format!("Address: 0x{}", self.config.address));
49+
4650
// print models
4751
diagnostics.push(format!(
4852
"Models: {}",
@@ -84,8 +88,20 @@ impl DriaComputeNode {
8488
// dial all rpc nodes
8589
for rpc_addr in self.dria_nodes.rpc_nodes.iter() {
8690
log::info!("Dialling RPC node: {}", rpc_addr);
87-
if let Err(e) = self.p2p.dial(rpc_addr.clone()).await {
88-
log::warn!("Error dialling RPC node: {:?}", e);
91+
92+
let fut = self.p2p.dial(rpc_addr.clone());
93+
match tokio::time::timeout(Duration::from_secs(10), fut).await {
94+
Err(timeout) => {
95+
log::error!("Timeout dialling RPC node: {:?}", timeout);
96+
}
97+
Ok(res) => match res {
98+
Err(e) => {
99+
log::warn!("Error dialling RPC node: {:?}", e);
100+
}
101+
Ok(_) => {
102+
log::info!("Successfully dialled RPC node: {}", rpc_addr);
103+
}
104+
},
89105
};
90106
}
91107

compute/src/node/gossipsub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use dkn_p2p::libp2p::gossipsub::{Message, MessageAcceptance, MessageId, TopicSubscriptionFilter};
1+
use dkn_p2p::libp2p::gossipsub::{Message, MessageAcceptance, MessageId};
22
use dkn_p2p::libp2p::PeerId;
33
use eyre::Result;
44

p2p/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl DriaP2PClient {
112112
}
113113

114114
// do a random-walk on the DHT with a random peer
115-
log::info!("Searching for random peers.");
115+
log::info!("Bootstrapping Kademlia DHT.");
116116
let random_peer = PeerId::random();
117117
swarm
118118
.behaviour_mut()

0 commit comments

Comments
 (0)