p2p: Move message_compact_blocks module errors to error submodule
What changed, and why it matters
This commit is a simple internal code cleanup in the rust-bitcoin library. It moves an error type for compact block network messages into its own submodule and re-exports it. There is no change to how the code behaves, no bug fix, and no security-relevant change.
No action required; this is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors p2p/src/message_compact_blocks.rs by moving SendCmpctDecoderError and its trait implementations into a new error submodule, then re-exporting it with #[doc(no_inline)]. The error type’s visibility and behavior remain unchanged; the inner tuple field is now marked pub(super) instead of implicitly private to the parent module, but this does not alter the public API or runtime behavior. No logic, parsing, or cryptographic code was modified.
Changed components
p2p/src/message_compact_blocks.rsInspect captured patch +31 / −19
diff --git a/p2p/src/message_compact_blocks.rs b/p2p/src/message_compact_blocks.rs
index 4d3a7054..5a886a40 100644
--- a/p2p/src/message_compact_blocks.rs
+++ b/p2p/src/message_compact_blocks.rs
@@ -3,16 +3,16 @@
//!
//! BIP-0152 Compact Blocks network messages
-use core::convert::Infallible;
-use core::fmt;
-
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
use encoding::{ArrayDecoder, ArrayEncoder, Decoder2, Encoder2};
-use internals::write_err;
use crate::consensus::impl_consensus_encoding;
+#[rustfmt::skip] // Keep public re-exports separate.
+#[doc(no_inline)]
+pub use self::error::SendCmpctDecoderError;
+
/// sendcmpct message
#[derive(PartialEq, Eq, Clone, Debug, Copy, PartialOrd, Ord, Hash)]
pub struct SendCmpct {
@@ -73,26 +73,38 @@ impl encoding::Decodable for SendCmpct {
}
}
-/// Errors occuring when decoding a [`SendCmpct`] message.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct SendCmpctDecoderError(<SendCmpctInnerDecoder as encoding::Decoder>::Error);
+impl_consensus_encoding!(SendCmpct, send_compact, version);
+
+/// Error types for [`SendCmpct`] messages.
+pub mod error {
+ use core::convert::Infallible;
+ use core::fmt;
-impl From<Infallible> for SendCmpctDecoderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ use internals::write_err;
+
+ /// Errors occuring when decoding a [`SendCmpct`] message.
+ ///
+ /// [`SendCmpct`]: super::SendCmpct
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct SendCmpctDecoderError(
+ pub(super) <super::SendCmpctInnerDecoder as encoding::Decoder>::Error,
+ );
-impl fmt::Display for SendCmpctDecoderError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write_err!(f, "sendcmpct error"; self.0)
+ impl From<Infallible> for SendCmpctDecoderError {
+ fn from(never: Infallible) -> Self { match never {} }
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for SendCmpctDecoderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
-}
+ impl fmt::Display for SendCmpctDecoderError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write_err!(f, "sendcmpct error"; self.0)
+ }
+ }
-impl_consensus_encoding!(SendCmpct, send_compact, version);
+ #[cfg(feature = "std")]
+ impl std::error::Error for SendCmpctDecoderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
+ }
+}
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for SendCmpct {
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.