Skip to content

Commit

Permalink
fix(eth-wire): encode p2p message id as valid rlp (paradigmxyz#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored and gakonst committed Dec 7, 2022
1 parent 4f370e9 commit 2b6ef0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions crates/net/eth-wire/src/p2pstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl P2PMessage {
/// compressed in the `p2p` subprotocol.
impl Encodable for P2PMessage {
fn encode(&self, out: &mut dyn bytes::BufMut) {
out.put_u8(self.message_id() as u8);
(self.message_id() as u8).encode(out);
match self {
P2PMessage::Hello(msg) => msg.encode(out),
P2PMessage::Disconnect(msg) => msg.encode(out),
Expand Down Expand Up @@ -926,6 +926,7 @@ mod tests {
let mut hello_encoded = Vec::new();
hello.encode(&mut hello_encoded);

assert_eq!(hello_encoded[0], P2PMessageID::Hello as u8);
// zero is encoded as 0x80, the empty string code in RLP
assert_eq!(hello_encoded[0], EMPTY_STRING_CODE);
}
}
2 changes: 1 addition & 1 deletion crates/primitives/src/hex_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl FromStr for Bytes {
hex::decode(value)
}
.map(Into::into)
.map_err(|e| ParseBytesError(format!("Invalid hex: {}", e)))
.map_err(|e| ParseBytesError(format!("Invalid hex: {e}")))
}
}

Expand Down

0 comments on commit 2b6ef0a

Please sign in to comment.