1
- use super :: eth68:: receipt :: Receipts68 ;
2
- use super :: eth69:: receipt :: Receipts69 ;
1
+ use super :: eth68:: receipts :: Receipts68 ;
2
+ use super :: eth69:: receipts :: Receipts69 ;
3
3
use crate :: rlpx:: {
4
4
error:: RLPxError ,
5
5
message:: RLPxMessage ,
@@ -15,6 +15,7 @@ use ethrex_rlp::{
15
15
error:: { RLPDecodeError , RLPEncodeError } ,
16
16
structs:: { Decoder , Encoder } ,
17
17
} ;
18
+ use tracing:: info;
18
19
19
20
// https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getreceipts-0x0f
20
21
#[ derive( Debug ) ]
@@ -64,6 +65,7 @@ pub(crate) enum Receipts {
64
65
65
66
impl Receipts {
66
67
pub fn new ( id : u64 , receipts : Vec < Vec < Receipt > > , eth : & Capability ) -> Result < Self , RLPxError > {
68
+ info ! ( " eth cap eth/{}" , eth. version) ;
67
69
match eth. version {
68
70
68 => Ok ( Receipts :: Receipts68 ( Receipts68 :: new ( id, receipts) ) ) ,
69
71
69 => Ok ( Receipts :: Receipts69 ( Receipts69 :: new ( id, receipts) ) ) ,
@@ -97,6 +99,7 @@ impl RLPxMessage for Receipts {
97
99
}
98
100
99
101
fn decode ( msg_data : & [ u8 ] ) -> Result < Self , RLPDecodeError > {
102
+ info ! ( "Has Bloom" ) ;
100
103
if has_bloom ( msg_data) ? {
101
104
Ok ( Receipts :: Receipts68 ( Receipts68 :: decode ( msg_data) ?) )
102
105
} else {
@@ -118,14 +121,14 @@ fn has_bloom(msg_data: &[u8]) -> Result<bool, RLPDecodeError> {
118
121
let decoder = Decoder :: new ( & data) ?;
119
122
//check if the list is empty
120
123
if decoder. is_done ( ) {
121
- return Ok ( true ) ;
124
+ return Ok ( false ) ;
122
125
}
123
126
124
127
// inner list
125
128
let ( data, _) = decoder. get_encoded_item ( ) ?;
126
129
let decoder = Decoder :: new ( & data) ?;
127
130
if decoder. is_done ( ) {
128
- return Ok ( true ) ;
131
+ return Ok ( false ) ;
129
132
}
130
133
131
134
// we only need one element
@@ -151,9 +154,8 @@ fn has_bloom(msg_data: &[u8]) -> Result<bool, RLPDecodeError> {
151
154
}
152
155
& data[ length_of_length + 1 ..length_of_length + length + 1 ]
153
156
}
154
- _ => return Err ( RLPDecodeError :: InvalidLength ) ,
157
+ _ => return Ok ( false ) ,
155
158
} ;
156
-
157
159
let data = match data[ 0 ] {
158
160
tx_type if tx_type < 0x7f => & data[ 1 ..] ,
159
161
_ => & data[ 0 ..] ,
@@ -231,11 +233,15 @@ mod tests {
231
233
Receipt :: new( TxType :: EIP7702 , true , 210000 , vec![ ] ) ,
232
234
Receipt :: new( TxType :: EIP7702 , true , 210000 , vec![ ] ) ,
233
235
] ] ;
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 ( ) ;
235
238
236
239
let mut buf = Vec :: new ( ) ;
237
- receipts. encode ( & mut buf) . unwrap ( ) ;
238
-
240
+ receipts68. encode ( & mut buf) . unwrap ( ) ;
239
241
assert ! ( has_bloom( & buf) . unwrap( ) ) ;
242
+
243
+ let mut buf = Vec :: new ( ) ;
244
+ receipts69. encode ( & mut buf) . unwrap ( ) ;
245
+ assert ! ( !has_bloom( & buf) . unwrap( ) ) ;
240
246
}
241
247
}
0 commit comments