p2p: Remove legacy encoding from `lib`
What changed, and why it matters
This commit removes old-style encoding implementations from three simple data types (ProtocolVersion, ServiceFlags, and Magic) in the rust-bitcoin peer-to-peer library. It is a routine code cleanup that switches these types to use a newer, dedicated encoding macro. There is no indication of a security bug being fixed.
No security action required. Treat as normal refactoring/cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff deletes manual Encodable/Decodable trait implementations for ProtocolVersion, ServiceFlags, and Magic in p2p/src/lib.rs. These implementations delegated directly to the inner u32/u64 values. The commit already has replacement encoding::encoder_newtype_exact! macro-based encoders in place, so this is a pure removal of redundant legacy code. No behavioral change or vulnerability remediation is visible in the diff.
Changed components
p2p/src/lib.rsProtocolVersionServiceFlagsMagicInspect captured patch +0 / −42
diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs
index e51af80d..b0c22e5c 100644
--- a/p2p/src/lib.rs
+++ b/p2p/src/lib.rs
@@ -43,10 +43,8 @@ use core::{fmt, ops};
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
-use bitcoin::consensus::encode::{self, Decodable, Encodable};
use encoding::{ArrayDecoder, ArrayEncoder};
use internals::impl_to_hex_from_lower_hex;
-use io::{BufRead, Write};
use network::{Network, TestnetVersion};
#[rustfmt::skip]
@@ -114,20 +112,6 @@ impl From<ProtocolVersion> for u32 {
fn from(version: ProtocolVersion) -> Self { version.0 }
}
-impl Encodable for ProtocolVersion {
- #[inline]
- fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
- self.0.consensus_encode(w)
- }
-}
-
-impl Decodable for ProtocolVersion {
- #[inline]
- fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> Result<Self, encode::Error> {
- Ok(Self(Decodable::consensus_decode(r)?))
- }
-}
-
encoding::encoder_newtype_exact! {
/// The encoder for the [`ProtocolVersion`] type.
#[derive(Debug, Clone)]
@@ -323,20 +307,6 @@ impl ops::BitXorAssign for ServiceFlags {
fn bitxor_assign(&mut self, rhs: Self) { let _ = self.remove(rhs); }
}
-impl Encodable for ServiceFlags {
- #[inline]
- fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
- self.0.consensus_encode(w)
- }
-}
-
-impl Decodable for ServiceFlags {
- #[inline]
- fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> Result<Self, encode::Error> {
- Ok(Self(Decodable::consensus_decode(r)?))
- }
-}
-
encoding::encoder_newtype_exact! {
/// The encoder for the [`ServiceFlags`] type.
#[derive(Debug, Clone)]
@@ -479,18 +449,6 @@ impl fmt::UpperHex for Magic {
}
}
-impl Encodable for Magic {
- fn consensus_encode<W: Write + ?Sized>(&self, writer: &mut W) -> Result<usize, io::Error> {
- self.0.consensus_encode(writer)
- }
-}
-
-impl Decodable for Magic {
- fn consensus_decode<R: BufRead + ?Sized>(reader: &mut R) -> Result<Self, encode::Error> {
- Ok(Self(Decodable::consensus_decode(reader)?))
- }
-}
-
encoding::encoder_newtype_exact! {
/// The encoder type for network [`Magic`].
#[derive(Debug, Clone)]
Why this scored 15/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.