@@ -5,7 +5,7 @@ use futures_util::StreamExt;
5
5
use reth_optimism_primitives:: { OpBlock , OpReceipt , OpTransactionSigned } ;
6
6
use rollup_boost:: primitives:: { ExecutionPayloadBaseV1 , FlashblocksPayloadV1 } ;
7
7
use serde:: { Deserialize , Serialize } ;
8
- use std:: { str:: FromStr , sync:: Arc } ;
8
+ use std:: { io :: Read , str:: FromStr , sync:: Arc } ;
9
9
use tokio:: sync:: mpsc;
10
10
use tokio_tungstenite:: { connect_async, tungstenite:: protocol:: Message } ;
11
11
use tracing:: error;
@@ -82,16 +82,14 @@ impl FlashblocksClient {
82
82
83
83
match msg {
84
84
Ok ( Message :: Binary ( bytes) ) => {
85
- // Decode binary message to string first
86
- let text = match String :: from_utf8 ( bytes. to_vec ( ) ) {
85
+ let text = match try_parse_message ( & bytes) {
87
86
Ok ( text) => text,
88
87
Err ( e) => {
89
- error ! ( "Failed to decode binary message: {}" , e) ;
88
+ error ! ( "Failed to decode message: {}" , e) ;
90
89
continue ;
91
90
}
92
91
} ;
93
92
94
- // Then parse JSON
95
93
let payload: FlashblocksPayloadV1 =
96
94
match serde_json:: from_str ( & text) {
97
95
Ok ( m) => m,
@@ -146,6 +144,21 @@ impl FlashblocksClient {
146
144
}
147
145
}
148
146
147
+ fn try_parse_message ( bytes : & [ u8 ] ) -> Result < String , Box < dyn std:: error:: Error > > {
148
+ if let Ok ( text) = String :: from_utf8 ( bytes. to_vec ( ) ) {
149
+ if text. trim_start ( ) . starts_with ( "{" ) {
150
+ return Ok ( text) ;
151
+ }
152
+ }
153
+
154
+ let mut decompressor = brotli:: Decompressor :: new ( bytes, 4096 ) ;
155
+ let mut decompressed = Vec :: new ( ) ;
156
+ decompressor. read_to_end ( & mut decompressed) ?;
157
+
158
+ let text = String :: from_utf8 ( decompressed) ?;
159
+ Ok ( text)
160
+ }
161
+
149
162
fn process_payload ( payload : FlashblocksPayloadV1 , cache : Arc < Cache > ) {
150
163
let metrics = Metrics :: default ( ) ;
151
164
let msg_processing_start_time = Instant :: now ( ) ;
0 commit comments