Skip to content

Commit 7017646

Browse files
committed
Fix has_bloom
1 parent de55189 commit 7017646

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub mod receipt;
1+
pub mod receipts;
22
pub mod status;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub mod receipt;
1+
pub mod receipts;
22
pub mod status;

crates/networking/p2p/rlpx/eth/receipts.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::eth68::receipt::Receipts68;
2-
use super::eth69::receipt::Receipts69;
1+
use super::eth68::receipts::Receipts68;
2+
use super::eth69::receipts::Receipts69;
33
use crate::rlpx::{
44
error::RLPxError,
55
message::RLPxMessage,
@@ -15,6 +15,7 @@ use ethrex_rlp::{
1515
error::{RLPDecodeError, RLPEncodeError},
1616
structs::{Decoder, Encoder},
1717
};
18+
use tracing::info;
1819

1920
// https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getreceipts-0x0f
2021
#[derive(Debug)]
@@ -64,6 +65,7 @@ pub(crate) enum Receipts {
6465

6566
impl Receipts {
6667
pub fn new(id: u64, receipts: Vec<Vec<Receipt>>, eth: &Capability) -> Result<Self, RLPxError> {
68+
info!(" eth cap eth/{}", eth.version);
6769
match eth.version {
6870
68 => Ok(Receipts::Receipts68(Receipts68::new(id, receipts))),
6971
69 => Ok(Receipts::Receipts69(Receipts69::new(id, receipts))),
@@ -97,6 +99,7 @@ impl RLPxMessage for Receipts {
9799
}
98100

99101
fn decode(msg_data: &[u8]) -> Result<Self, RLPDecodeError> {
102+
info!("Has Bloom");
100103
if has_bloom(msg_data)? {
101104
Ok(Receipts::Receipts68(Receipts68::decode(msg_data)?))
102105
} else {
@@ -118,14 +121,14 @@ fn has_bloom(msg_data: &[u8]) -> Result<bool, RLPDecodeError> {
118121
let decoder = Decoder::new(&data)?;
119122
//check if the list is empty
120123
if decoder.is_done() {
121-
return Ok(true);
124+
return Ok(false);
122125
}
123126

124127
// inner list
125128
let (data, _) = decoder.get_encoded_item()?;
126129
let decoder = Decoder::new(&data)?;
127130
if decoder.is_done() {
128-
return Ok(true);
131+
return Ok(false);
129132
}
130133

131134
// we only need one element
@@ -151,9 +154,8 @@ fn has_bloom(msg_data: &[u8]) -> Result<bool, RLPDecodeError> {
151154
}
152155
&data[length_of_length + 1..length_of_length + length + 1]
153156
}
154-
_ => return Err(RLPDecodeError::InvalidLength),
157+
_ => return Ok(false),
155158
};
156-
157159
let data = match data[0] {
158160
tx_type if tx_type < 0x7f => &data[1..],
159161
_ => &data[0..],
@@ -231,11 +233,15 @@ mod tests {
231233
Receipt::new(TxType::EIP7702, true, 210000, vec![]),
232234
Receipt::new(TxType::EIP7702, true, 210000, vec![]),
233235
]];
234-
let receipts = Receipts::new(255, receipts, &Capability::eth(68)).unwrap();
236+
let receipts68 = Receipts::new(255, receipts.clone(), &Capability::eth(68)).unwrap();
237+
let receipts69 = Receipts::new(255, receipts, &Capability::eth(69)).unwrap();
235238

236239
let mut buf = Vec::new();
237-
receipts.encode(&mut buf).unwrap();
238-
240+
receipts68.encode(&mut buf).unwrap();
239241
assert!(has_bloom(&buf).unwrap());
242+
243+
let mut buf = Vec::new();
244+
receipts69.encode(&mut buf).unwrap();
245+
assert!(!has_bloom(&buf).unwrap());
240246
}
241247
}

0 commit comments

Comments
 (0)