p2p: add serde impls for FilterHash and FilterHeader
What changed, and why it matters
This commit adds optional serialization/deserialization support (via the serde library) for two data types, FilterHash and FilterHeader, used in Bitcoin peer-to-peer compact block filters. It is a routine feature addition, not a security fix or vulnerability patch. There is no indication of a security issue in the code changes themselves.
No security action required. Review as normal feature code. If auditing serde usage, verify that the hashes::impl_serde_for_newtype! macro produces the expected human-readable hex serialization and does not introduce deserialization panics, but this is outside the scope of this commit review.
Security signals we found
No security signals detected
Routine feature-gated serde implementation addition
Uses existing internal macro for serde derivation
Evidence from the diff
The change introduces a new optional ‘serde’ feature in the p2p crate, adds serde as an optional dependency, and uses the existing hashes::impl_serde_for_newtype! macro to derive Serialize/Deserialize implementations for FilterHash and FilterHeader. Lock files and test matrix configuration are updated accordingly. The macro is a standard, well-defined pattern in this codebase. No unsafe code, no parsing logic changes, and no security-sensitive behavior modifications are present.
Changed components
p2p/src/message_filter.rsp2p/Cargo.tomlp2p/rbmt.tomlCargo-minimal.lockCargo-recent.lockInspect captured patch +8 / −2
diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock
index 9a08ea82..36241916 100644
--- a/Cargo-minimal.lock
+++ b/Cargo-minimal.lock
@@ -149,6 +149,7 @@ dependencies = [
"bitcoin_hashes",
"hex-conservative 0.3.0",
"hex_lit",
+ "serde",
]
[[package]]
diff --git a/Cargo-recent.lock b/Cargo-recent.lock
index cf257409..bc09a280 100644
--- a/Cargo-recent.lock
+++ b/Cargo-recent.lock
@@ -148,6 +148,7 @@ dependencies = [
"bitcoin_hashes",
"hex-conservative 0.3.0",
"hex_lit",
+ "serde",
]
[[package]]
diff --git a/p2p/Cargo.toml b/p2p/Cargo.toml
index 5d4bdeb7..c5ba5d10 100644
--- a/p2p/Cargo.toml
+++ b/p2p/Cargo.toml
@@ -16,6 +16,7 @@ exclude = ["tests", "contrib"]
default = ["std"]
std = ["encoding/std", "hashes/std", "network/std", "hex/std", "internals/std", "io/std", "units/std", "bitcoin/std", "primitives/std"]
arbitrary = ["dep:arbitrary", "bitcoin/arbitrary"]
+serde = ["dep:serde", "hashes/serde"]
[dependencies]
bitcoin = { path = "../bitcoin/", default-features = false }
@@ -29,6 +30,7 @@ io = { package = "bitcoin-io", version = "0.5.0", path = "../io", default-featur
units = { package = "bitcoin-units", path = "../units", version = "0.3.0", default-features = false }
arbitrary = { version = "1.4.1", optional = true }
+serde = { version = "1.0.195", default-features = false, features = ["derive", "alloc"], optional = true }
[dev-dependencies]
hex_lit = "0.1.1"
diff --git a/p2p/rbmt.toml b/p2p/rbmt.toml
index c8426f5a..ea6e6cda 100644
--- a/p2p/rbmt.toml
+++ b/p2p/rbmt.toml
@@ -7,11 +7,11 @@ examples = []
# Features to test with the conventional `std` feature enabled.
# Tests each feature alone with std, all pairs, and all together.
-features_with_std = ["arbitrary"]
+features_with_std = ["arbitrary", "serde"]
# Features to test without the `std` feature.
# Tests each feature alone, all pairs, and all together.
-features_without_std = ["arbitrary"]
+features_without_std = ["arbitrary", "serde"]
[lint]
allowed_duplicates = [
diff --git a/p2p/src/message_filter.rs b/p2p/src/message_filter.rs
index f7a464d4..ad3f5c5f 100644
--- a/p2p/src/message_filter.rs
+++ b/p2p/src/message_filter.rs
@@ -31,6 +31,8 @@ hashes::hash_newtype! {
}
hashes::impl_hex_for_newtype!(FilterHash, FilterHeader);
+#[cfg(feature = "serde")]
+hashes::impl_serde_for_newtype!(FilterHash, FilterHeader);
impl FilterHash {
/// Computes the filter header from a filter hash and previous filter header.
Why this scored 19/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.