Skip to content

Commit aa9ae03

Browse files
xdustinfacepauldelucia
authored andcommitted
fix: More follow-up to #190 (#193)
The sleep timeout branch introduced in #191 returns an `Err(NetworkError::Timeout)` which leads to a misbehavior update below in the `msg_result` match and eventually in a peer ban. This shouldn't happen because the `sleep` timing out only means that there is no data available right now. Instead, it now returns `Ok(None)` which will just keep things going.
1 parent 8dd0809 commit aa9ae03

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

dash-spv/src/client/sync_coordinator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
1414
use std::time::{Duration, Instant, SystemTime};
1515

16+
use super::{BlockProcessingTask, DashSpvClient, MessageHandler};
1617
use crate::error::{Result, SpvError};
18+
use crate::network::constants::MESSAGE_RECEIVE_TIMEOUT;
1719
use crate::network::NetworkManager;
1820
use crate::storage::StorageManager;
1921
use crate::types::{DetailedSyncProgress, SyncProgress};
2022
use key_wallet_manager::wallet_interface::WalletInterface;
2123

22-
use super::{BlockProcessingTask, DashSpvClient, MessageHandler};
23-
2424
impl<
2525
W: WalletInterface + Send + Sync + 'static,
2626
N: NetworkManager + Send + Sync + 'static,
@@ -491,7 +491,7 @@ impl<
491491
}
492492

493493
// Handle network messages with timeout for responsiveness
494-
match tokio::time::timeout(Duration::from_millis(1000), self.network.receive_message())
494+
match tokio::time::timeout(MESSAGE_RECEIVE_TIMEOUT, self.network.receive_message())
495495
.await
496496
{
497497
Ok(msg_result) => match msg_result {

dash-spv/src/network/manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ impl PeerNetworkManager {
331331
message = peer_guard.receive_message() => {
332332
message
333333
},
334-
_ = tokio::time::sleep(MESSAGE_RECEIVE_TIMEOUT) => {
335-
Err(NetworkError::Timeout)
334+
_ = tokio::time::sleep(MESSAGE_POLL_INTERVAL) => {
335+
Ok(None)
336336
},
337337
_ = shutdown_token.cancelled() => {
338338
log::info!("Breaking peer reader loop for {} - shutdown signal received while reading (iteration {})", addr, loop_iteration);

0 commit comments

Comments
 (0)