Skip to content
386 changes: 278 additions & 108 deletions dash-spv/src/network/connection.rs

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions dash-spv/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,24 +510,19 @@ impl std::fmt::Debug for ChainState {
}

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

/// Validate proof of work and chain rules.
#[default]
Full,

/// Skip most validation (useful for testing).
None,
}

impl Default for ValidationMode {
fn default() -> Self {
Self::Full
}
}

/// Peer information.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PeerInfo {
Expand Down
22 changes: 21 additions & 1 deletion dash/src/network/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,27 @@ impl Decodable for RawNetworkMessage {
) -> Result<Self, encode::Error> {
let magic = Decodable::consensus_decode_from_finite_reader(r)?;
let cmd = CommandString::consensus_decode_from_finite_reader(r)?;
let raw_payload = CheckedData::consensus_decode_from_finite_reader(r)?.0;
let raw_payload = match CheckedData::consensus_decode_from_finite_reader(r) {
Ok(cd) => cd.0,
Err(encode::Error::InvalidChecksum {
expected,
actual,
}) => {
// Include message command and magic in logging to aid diagnostics
log::warn!(
"Invalid payload checksum for network message '{}' (magic {:#x}): expected {:02x?}, actual {:02x?}",
cmd.0,
magic,
expected,
actual
);
return Err(encode::Error::InvalidChecksum {
expected,
actual,
});
}
Err(e) => return Err(e),
};

let mut mem_d = io::Cursor::new(raw_payload);
let payload = match &cmd.0[..] {
Expand Down
2 changes: 1 addition & 1 deletion dash/src/sml/quorum_entry/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ mod tests {
#[test]
fn test_verify_secure_with_real_operators() {
// Real operator keys for testing verify_secure API
let operator_keys = vec![
let operator_keys = [
PublicKey::<Bls12381G2Impl>::from_bytes_with_mode(
&hex!("86e7ea34cc084da3ed0e90649ad444df0ca25d638164a596b4fbec9567bbcf3e635a8d8457107e7fe76326f3816e34d9"),
SerializationFormat::Modern
Expand Down
2 changes: 1 addition & 1 deletion key-wallet-ffi/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub unsafe extern "C" fn address_array_free(addresses: *mut *mut c_char, count:
}
}
// Free the array itself
let _ = Box::from_raw(std::slice::from_raw_parts_mut(addresses, count));
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(addresses, count));
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions key-wallet-ffi/src/address_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,14 +941,16 @@ pub unsafe extern "C" fn address_info_free(info: *mut FFIAddressInfo) {

// Free the byte arrays
if !info.script_pubkey.is_null() && info.script_pubkey_len > 0 {
let _ = Box::from_raw(std::slice::from_raw_parts_mut(
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(
info.script_pubkey,
info.script_pubkey_len,
));
}
if !info.public_key.is_null() && info.public_key_len > 0 {
let _ =
Box::from_raw(std::slice::from_raw_parts_mut(info.public_key, info.public_key_len));
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(
info.public_key,
info.public_key_len,
));
}
}
}
Expand All @@ -963,7 +965,7 @@ pub unsafe extern "C" fn address_info_free(info: *mut FFIAddressInfo) {
#[no_mangle]
pub unsafe extern "C" fn address_info_array_free(infos: *mut *mut FFIAddressInfo, count: usize) {
if !infos.is_null() && count > 0 {
let array = Box::from_raw(std::slice::from_raw_parts_mut(infos, count));
let array = Box::from_raw(std::ptr::slice_from_raw_parts_mut(infos, count));
for info_ptr in array.iter() {
address_info_free(*info_ptr);
}
Expand Down
4 changes: 2 additions & 2 deletions key-wallet-ffi/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,13 +991,13 @@ pub unsafe extern "C" fn derivation_path_free(
if !indices.is_null() && count > 0 {
unsafe {
// Reconstruct the boxed slice from the raw pointer and let it drop
let _ = Box::from_raw(std::slice::from_raw_parts_mut(indices, count));
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(indices, count));
}
}
if !hardened.is_null() && count > 0 {
unsafe {
// Reconstruct the boxed slice from the raw pointer and let it drop
let _ = Box::from_raw(std::slice::from_raw_parts_mut(hardened, count));
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(hardened, count));
}
}
}
Expand Down
Loading