What changed, and why it matters
This is a small internal code-quality change in the Bitcoin peer-to-peer networking library. It marks a 12-byte message command string type as Copy, which lets the compiler duplicate it more cheaply. The change removes a few unnecessary .clone() calls. There is no security issue here.
No action needed. This is a routine refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit derives Copy for CommandString, a newtype around [u8; 12]. Because the type is small and already derives Clone, adding Copy is idiomatic and allows implicit bitwise copies. The diff updates two call sites to remove explicit .clone() calls. This is a non-functional refactor with no observable behavior change.
Changed components
p2p/src/message.rsCommandStringNetworkMessage::commandV2NetworkMessageDecoderInspect captured patch +3 / −4
diff --git a/p2p/src/message.rs b/p2p/src/message.rs
index bce0606b..882aefde 100644
--- a/p2p/src/message.rs
+++ b/p2p/src/message.rs
@@ -49,7 +49,7 @@ pub const MAX_INV_SIZE: usize = 50_000;
pub const MAX_MSG_SIZE: usize = 5_000_000;
/// Contains the message command.
-#[derive(PartialEq, Eq, Clone, Debug)]
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct CommandString([u8; 12]);
impl CommandString {
@@ -725,7 +725,7 @@ impl NetworkMessage {
/// Panics if the command string is invalid (should never happen for valid message types).
pub fn command(&self) -> CommandString {
match *self {
- Self::Unknown { command: ref c, .. } => c.clone(),
+ Self::Unknown { command: ref c, .. } => *c,
_ => CommandString::try_from(self.cmd()).expect("cmd returns valid commands"),
}
}
@@ -1789,8 +1789,7 @@ impl encoding::Decoder for V2NetworkMessageDecoder {
let command = command_string
.end()
.map_err(V2NetworkMessageDecoderError::Command)?;
- let payload_decoder =
- Self::payload_decoder_from_command(command.clone());
+ let payload_decoder = Self::payload_decoder_from_command(command);
self.state = V2NetworkMessageDecoderState::Payload(payload_decoder);
}
_ => unreachable!("we know we're in the Second state"),
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.