p2p: Remove legacy encoding from `message_filter`
What changed, and why it matters
This commit removes old-style Bitcoin consensus encoding code from the peer-to-peer message filter module. It replaces hand-written encoding implementations with newer macro-generated ones that were already added elsewhere in the file. There is no indication in the commit that this fixes a security bug; it appears to be a routine cleanup/refactoring change.
No security action required. Treat as normal code hygiene/refactoring. If consuming this library, verify that the new `encoding` macros produce byte-compatible serialization for the affected P2P messages (the commit itself suggests they do).
Security signals we found
No security-relevant keywords in commit title or message
No functional logic change visible in diff—only removal of redundant legacy implementations
No references to vulnerabilities, CVEs, or security reports
No input-validation, bounds-checking, or cryptographic changes
Evidence from the diff
The diff deletes the impl_hashencode! macro and removes impl_consensus_encoding! invocations for GetCFilters, CFilter, GetCFHeaders, CFHeaders, GetCFCheckpt, and CFCheckpt. These types already have encoding::Encode/encoding::Decode implementations defined just above each removed legacy macro call, and FilterHash/FilterHeader are now handled by encoding::encoder_newtype_exact!/decoder_newtype_exact! macros. The change is a migration away from the crate’s older consensus-encoding trait toward a newer encoding module API.
Changed components
p2p/src/message_filter.rsInspect captured patch +0 / −34
diff --git a/p2p/src/message_filter.rs b/p2p/src/message_filter.rs
index 5547aaad..2a960277 100644
--- a/p2p/src/message_filter.rs
+++ b/p2p/src/message_filter.rs
@@ -18,8 +18,6 @@ use primitives::BlockHash;
use units::block::{BlockHeightDecoder, BlockHeightEncoder};
use units::BlockHeight;
-use crate::consensus::impl_consensus_encoding;
-
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(no_inline)]
pub use self::error::{
@@ -49,26 +47,6 @@ impl FilterHash {
}
}
-#[rustfmt::skip]
-macro_rules! impl_hashencode {
- ($hashtype:ident) => {
- impl bitcoin::consensus::Encodable for $hashtype {
- fn consensus_encode<W: bitcoin::io::Write + ?Sized>(&self, w: &mut W) -> core::result::Result<usize, bitcoin::io::Error> {
- self.as_byte_array().consensus_encode(w)
- }
- }
-
- impl bitcoin::consensus::Decodable for $hashtype {
- fn consensus_decode<R: bitcoin::io::BufRead + ?Sized>(r: &mut R) -> core::result::Result<Self, bitcoin::consensus::encode::Error> {
- Ok(Self::from_byte_array(<<$hashtype as hashes::Hash>::Bytes>::consensus_decode(r)?))
- }
- }
- };
-}
-
-impl_hashencode!(FilterHash);
-impl_hashencode!(FilterHeader);
-
encoding::encoder_newtype_exact! {
/// Encoder type for [`FilterHash`].
#[derive(Debug, Clone)]
@@ -237,8 +215,6 @@ impl encoding::Decode for GetCFilters {
}
}
-impl_consensus_encoding!(GetCFilters, filter_type, start_height, stop_hash);
-
/// cfilter message
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct CFilter {
@@ -317,8 +293,6 @@ impl encoding::Decode for CFilter {
}
}
-impl_consensus_encoding!(CFilter, filter_type, block_hash, filter);
-
/// getcfheaders message
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct GetCFHeaders {
@@ -385,8 +359,6 @@ impl encoding::Decode for GetCFHeaders {
}
}
-impl_consensus_encoding!(GetCFHeaders, filter_type, start_height, stop_hash);
-
/// cfheaders message
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct CFHeaders {
@@ -474,8 +446,6 @@ impl encoding::Decode for CFHeaders {
}
}
-impl_consensus_encoding!(CFHeaders, filter_type, stop_hash, previous_filter_header, filter_hashes);
-
/// getcfcheckpt message
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct GetCFCheckpt {
@@ -535,8 +505,6 @@ impl encoding::Decode for GetCFCheckpt {
}
}
-impl_consensus_encoding!(GetCFCheckpt, filter_type, stop_hash);
-
/// cfcheckpt message
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct CFCheckpt {
@@ -615,8 +583,6 @@ impl encoding::Decode for CFCheckpt {
}
}
-impl_consensus_encoding!(CFCheckpt, filter_type, stop_hash, filter_headers);
-
/// Error types for client side block filtering messages.
pub mod error {
use core::convert::Infallible;
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.