p2p: Move message_bloom module errors to error submodule
What changed, and why it matters
This commit is a straightforward internal code reorganization. It moves three error type definitions for bloom filter network messages into a new 'error' submodule and re-exports them. There is no functional change to how the code behaves, no bug fix, and no security-relevant change.
No security action needed. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors p2p/src/message_bloom.rs by relocating FilterLoadDecoderError, BloomFlagsDecoderError, and FilterAddDecoderError into a new pub mod error submodule with pub(super) visibility adjustments to the inner fields. It adds #[doc(no_inline)] re-exports and updates doc links. The From
Changed components
p2p/src/message_bloom.rsInspect captured patch +88 / −69
diff --git a/p2p/src/message_bloom.rs b/p2p/src/message_bloom.rs
index 27febcf0..0b5c291b 100644
--- a/p2p/src/message_bloom.rs
+++ b/p2p/src/message_bloom.rs
@@ -5,8 +5,6 @@
//! This module describes BIP-0037 Connection Bloom filtering network messages.
use alloc::vec::Vec;
-use core::convert::Infallible;
-use core::fmt;
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
@@ -15,11 +13,14 @@ use encoding::{
ArrayDecoder, ArrayEncoder, ByteVecDecoder, BytesEncoder, CompactSizeEncoder, Decoder4,
Encoder2, Encoder3,
};
-use internals::write_err;
use io::{BufRead, Write};
use crate::consensus::impl_consensus_encoding;
+#[rustfmt::skip] // Keep public re-exports separate.
+#[doc(no_inline)]
+pub use self::error::{BloomFlagsDecoderError, FilterAddDecoderError, FilterLoadDecoderError};
+
/// `filterload` message sets the current bloom filter
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FilterLoad {
@@ -110,25 +111,6 @@ impl encoding::Decodable for FilterLoad {
}
}
-/// An error occuring when decoding a [`FilterLoad`] message.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct FilterLoadDecoderError(<FilterLoadInnerDecoder as encoding::Decoder>::Error);
-
-impl From<Infallible> for FilterLoadDecoderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
-
-impl fmt::Display for FilterLoadDecoderError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write_err!(f, "filterload error"; self.0)
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for FilterLoadDecoderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
-}
-
impl_consensus_encoding!(FilterLoad, filter, hash_funcs, tweak, flags);
/// Bloom filter update flags
@@ -205,38 +187,6 @@ impl encoding::Decodable for BloomFlags {
fn decoder() -> Self::Decoder { BloomFlagsDecoder(ArrayDecoder::new()) }
}
-/// An error occurring when decoding a [`BloomFlags`].
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub enum BloomFlagsDecoderError {
- /// Inner decoder error.
- Decoder(<ArrayDecoder<1> as encoding::Decoder>::Error),
- /// The flag is not known.
- UnknownFlag(u8),
-}
-
-impl From<Infallible> for BloomFlagsDecoderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
-
-impl fmt::Display for BloomFlagsDecoderError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Self::Decoder(d) => write_err!(f, "bloomflags error"; d),
- Self::UnknownFlag(flag) => write!(f, "unknown bloomflag {}", flag),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for BloomFlagsDecoderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::Decoder(d) => Some(d),
- Self::UnknownFlag(_f) => None,
- }
- }
-}
-
impl Encodable for BloomFlags {
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
w.write_all(&[match self {
@@ -314,26 +264,95 @@ impl encoding::Decodable for FilterAdd {
fn decoder() -> Self::Decoder { FilterAddDecoder(FilterAddInnerDecoder::new()) }
}
-/// An error decoding a [`FilterAdd`] message.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct FilterAddDecoderError(<FilterAddInnerDecoder as encoding::Decoder>::Error);
+impl_consensus_encoding!(FilterAdd, data);
-impl From<Infallible> for FilterAddDecoderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+/// Error types for bloom filter messages.
+pub mod error {
+ use core::convert::Infallible;
+ use core::fmt;
+
+ use internals::write_err;
+
+ /// An error occuring when decoding a [`FilterLoad`] message.
+ ///
+ /// [`FilterLoad`]: super::FilterLoad
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct FilterLoadDecoderError(
+ pub(super) <super::FilterLoadInnerDecoder as encoding::Decoder>::Error,
+ );
-impl fmt::Display for FilterAddDecoderError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write_err!(f, "filteradd error"; self.0)
+ impl From<Infallible> for FilterLoadDecoderError {
+ fn from(never: Infallible) -> Self { match never {} }
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for FilterAddDecoderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
-}
+ impl fmt::Display for FilterLoadDecoderError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write_err!(f, "filterload error"; self.0)
+ }
+ }
-impl_consensus_encoding!(FilterAdd, data);
+ #[cfg(feature = "std")]
+ impl std::error::Error for FilterLoadDecoderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
+ }
+
+ /// An error occurring when decoding a [`BloomFlags`].
+ ///
+ /// [`BloomFlags`]: super::BloomFlags
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub enum BloomFlagsDecoderError {
+ /// Inner decoder error.
+ Decoder(<super::BloomFlagsInnerDecoder as encoding::Decoder>::Error),
+ /// The flag is not known.
+ UnknownFlag(u8),
+ }
+
+ impl From<Infallible> for BloomFlagsDecoderError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
+ impl fmt::Display for BloomFlagsDecoderError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::Decoder(d) => write_err!(f, "bloomflags error"; d),
+ Self::UnknownFlag(flag) => write!(f, "unknown bloomflag {}", flag),
+ }
+ }
+ }
+
+ #[cfg(feature = "std")]
+ impl std::error::Error for BloomFlagsDecoderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::Decoder(d) => Some(d),
+ Self::UnknownFlag(_f) => None,
+ }
+ }
+ }
+
+ /// An error decoding a [`FilterAdd`] message.
+ ///
+ /// [`FilterAdd`]: super::FilterAdd
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct FilterAddDecoderError(
+ pub(super) <super::FilterAddInnerDecoder as encoding::Decoder>::Error,
+ );
+
+ impl From<Infallible> for FilterAddDecoderError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
+ impl fmt::Display for FilterAddDecoderError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write_err!(f, "filteradd error"; self.0)
+ }
+ }
+
+ #[cfg(feature = "std")]
+ impl std::error::Error for FilterAddDecoderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
+ }
+}
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for BloomFlags {
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.