Skip to content

Commit

Permalink
tests: fix {de,en}coding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fkrause98 committed Oct 31, 2024
1 parent b52fde2 commit c04d319
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 5 additions & 6 deletions crates/networking/p2p/rlpx/eth/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::rlpx::{message::RLPxMessage, utils::snappy_encode};

pub const HASH_FIRST_BYTE_DECODER: u8 = 160;

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum HashOrNumber {
Hash(BlockHash),
Number(BlockNumber),
Expand Down Expand Up @@ -112,12 +112,12 @@ impl GetBlockHeaders {
impl RLPxMessage for GetBlockHeaders {
fn encode(&self, buf: &mut dyn BufMut) -> Result<(), RLPEncodeError> {
let mut encoded_data = vec![];
let limit = self.limit;
let skip = self.skip;
let reverse = self.reverse as u8;
Encoder::new(&mut encoded_data)
.encode_field(&self.id)
.encode_field(&self.startblock)
.encode_field(&self.limit)
.encode_field(&self.skip)
.encode_field(&self.reverse)
.encode_field(&(self.startblock.clone(), limit, skip, reverse))
.finish();
let msg_data = snappy_encode(encoded_data)?;
buf.put_slice(&msg_data);
Expand Down Expand Up @@ -158,7 +158,6 @@ impl RLPxMessage for BlockHeaders {
// Each message is encoded with its own
// message identifier (code).
// Go ethereum reference: https://github.com/ethereum/go-ethereum/blob/20bf543a64d7c2a590b18a1e1d907cae65707013/p2p/transport.go#L94
0x14_u8.encode(buf);
Encoder::new(&mut encoded_data)
.encode_field(&self.id)
.encode_field(&self.block_headers)
Expand Down
5 changes: 4 additions & 1 deletion crates/networking/p2p/rlpx/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ impl Message {
Message::Pong(msg) => msg.encode(buf),
Message::Status(msg) => msg.encode(buf),
Message::GetBlockHeaders(msg) => msg.encode(buf),
Message::BlockHeaders(msg) => msg.encode(buf),
Message::BlockHeaders(msg) => {
0x14_u8.encode(buf);
msg.encode(buf)
}
Message::GetAccountRange(msg) => {
0x21_u8.encode(buf);
msg.encode(buf)
Expand Down

0 comments on commit c04d319

Please sign in to comment.