Skip to content

Commit 8e9d94d

Browse files
Merge pull request #167 from dashpay/feat/investigate-fix-checksum-error
fix: resolve flakey connection errors due to TCP buffer issues
2 parents b864dd4 + 45ddb42 commit 8e9d94d

File tree

7 files changed

+311
-124
lines changed

7 files changed

+311
-124
lines changed

dash-spv/src/network/connection.rs

Lines changed: 278 additions & 108 deletions
Large diffs are not rendered by default.

dash-spv/src/types.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,24 +510,19 @@ impl std::fmt::Debug for ChainState {
510510
}
511511

512512
/// Validation mode for the SPV client.
513-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
513+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
514514
pub enum ValidationMode {
515515
/// Validate only basic structure and signatures.
516516
Basic,
517517

518518
/// Validate proof of work and chain rules.
519+
#[default]
519520
Full,
520521

521522
/// Skip most validation (useful for testing).
522523
None,
523524
}
524525

525-
impl Default for ValidationMode {
526-
fn default() -> Self {
527-
Self::Full
528-
}
529-
}
530-
531526
/// Peer information.
532527
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
533528
pub struct PeerInfo {

dash/src/network/message.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,27 @@ impl Decodable for RawNetworkMessage {
481481
) -> Result<Self, encode::Error> {
482482
let magic = Decodable::consensus_decode_from_finite_reader(r)?;
483483
let cmd = CommandString::consensus_decode_from_finite_reader(r)?;
484-
let raw_payload = CheckedData::consensus_decode_from_finite_reader(r)?.0;
484+
let raw_payload = match CheckedData::consensus_decode_from_finite_reader(r) {
485+
Ok(cd) => cd.0,
486+
Err(encode::Error::InvalidChecksum {
487+
expected,
488+
actual,
489+
}) => {
490+
// Include message command and magic in logging to aid diagnostics
491+
log::warn!(
492+
"Invalid payload checksum for network message '{}' (magic {:#x}): expected {:02x?}, actual {:02x?}",
493+
cmd.0,
494+
magic,
495+
expected,
496+
actual
497+
);
498+
return Err(encode::Error::InvalidChecksum {
499+
expected,
500+
actual,
501+
});
502+
}
503+
Err(e) => return Err(e),
504+
};
485505

486506
let mut mem_d = io::Cursor::new(raw_payload);
487507
let payload = match &cmd.0[..] {

dash/src/sml/quorum_entry/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ mod tests {
221221
#[test]
222222
fn test_verify_secure_with_real_operators() {
223223
// Real operator keys for testing verify_secure API
224-
let operator_keys = vec![
224+
let operator_keys = [
225225
PublicKey::<Bls12381G2Impl>::from_bytes_with_mode(
226226
&hex!("86e7ea34cc084da3ed0e90649ad444df0ca25d638164a596b4fbec9567bbcf3e635a8d8457107e7fe76326f3816e34d9"),
227227
SerializationFormat::Modern

key-wallet-ffi/src/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub unsafe extern "C" fn address_array_free(addresses: *mut *mut c_char, count:
4444
}
4545
}
4646
// Free the array itself
47-
let _ = Box::from_raw(std::slice::from_raw_parts_mut(addresses, count));
47+
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(addresses, count));
4848
}
4949
}
5050
}

key-wallet-ffi/src/address_pool.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,14 +941,16 @@ pub unsafe extern "C" fn address_info_free(info: *mut FFIAddressInfo) {
941941

942942
// Free the byte arrays
943943
if !info.script_pubkey.is_null() && info.script_pubkey_len > 0 {
944-
let _ = Box::from_raw(std::slice::from_raw_parts_mut(
944+
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(
945945
info.script_pubkey,
946946
info.script_pubkey_len,
947947
));
948948
}
949949
if !info.public_key.is_null() && info.public_key_len > 0 {
950-
let _ =
951-
Box::from_raw(std::slice::from_raw_parts_mut(info.public_key, info.public_key_len));
950+
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(
951+
info.public_key,
952+
info.public_key_len,
953+
));
952954
}
953955
}
954956
}
@@ -963,7 +965,7 @@ pub unsafe extern "C" fn address_info_free(info: *mut FFIAddressInfo) {
963965
#[no_mangle]
964966
pub unsafe extern "C" fn address_info_array_free(infos: *mut *mut FFIAddressInfo, count: usize) {
965967
if !infos.is_null() && count > 0 {
966-
let array = Box::from_raw(std::slice::from_raw_parts_mut(infos, count));
968+
let array = Box::from_raw(std::ptr::slice_from_raw_parts_mut(infos, count));
967969
for info_ptr in array.iter() {
968970
address_info_free(*info_ptr);
969971
}

key-wallet-ffi/src/keys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,13 +991,13 @@ pub unsafe extern "C" fn derivation_path_free(
991991
if !indices.is_null() && count > 0 {
992992
unsafe {
993993
// Reconstruct the boxed slice from the raw pointer and let it drop
994-
let _ = Box::from_raw(std::slice::from_raw_parts_mut(indices, count));
994+
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(indices, count));
995995
}
996996
}
997997
if !hardened.is_null() && count > 0 {
998998
unsafe {
999999
// Reconstruct the boxed slice from the raw pointer and let it drop
1000-
let _ = Box::from_raw(std::slice::from_raw_parts_mut(hardened, count));
1000+
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(hardened, count));
10011001
}
10021002
}
10031003
}

0 commit comments

Comments
 (0)