Skip to content

Commit 7ab7212

Browse files
feat: enhance error handling for invalid checksums
Improved logging and proactive disconnection for peers sending messages with invalid checksums. This change ensures that potential message corruption is addressed promptly, enhancing network stability.
1 parent b864dd4 commit 7ab7212

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

dash-spv/src/network/connection.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,24 @@ impl TcpConnection {
461461
expected,
462462
actual,
463463
}) => {
464-
// Special handling for checksum errors - skip the message and return empty queue
465-
tracing::warn!("Skipping message with invalid checksum from {}: expected {:02x?}, actual {:02x?}",
466-
self.address, expected, actual);
464+
// Extra logging and proactively disconnect on checksum mismatches
465+
tracing::warn!(
466+
"Invalid checksum from {}: expected {:02x?}, actual {:02x?} — disconnecting peer",
467+
self.address,
468+
expected,
469+
actual
470+
);
467471

468472
// Check if this looks like a version message corruption by checking for all-zeros checksum
469473
if actual == [0, 0, 0, 0] {
470-
tracing::warn!("All-zeros checksum detected from {}, likely corrupted version message - skipping", self.address);
474+
tracing::warn!(
475+
"All-zeros checksum from {} indicates likely corrupted stream/version message — disconnecting",
476+
self.address
477+
);
471478
}
472479

473-
// Return empty queue instead of failing the connection
474-
Ok(None)
480+
// Treat as peer disconnect so upper layers drop and reconnect
481+
Err(NetworkError::PeerDisconnected)
475482
}
476483
Err(e) => {
477484
tracing::error!("Failed to decode message from {}: {}", self.address, e);

0 commit comments

Comments
 (0)