@@ -14,24 +14,36 @@ use op_alloy_rpc_types::Transaction;
1414use reth_optimism_chainspec:: OpChainSpec ;
1515use reth_optimism_evm:: extract_l1_info;
1616use reth_optimism_primitives:: OpPrimitives ;
17- use reth_optimism_primitives:: { OpBlock , OpReceipt , OpTransactionSigned } ;
17+ use reth_optimism_primitives:: { OpBlock , OpTransactionSigned } ;
1818use reth_optimism_rpc:: OpReceiptBuilder ;
1919use reth_primitives:: Recovered ;
2020use reth_primitives_traits:: block:: body:: BlockBody ;
2121
22+ use op_alloy_rpc_types_engine:: OpFlashblockPayload ;
2223use reth_rpc_eth_api:: transaction:: ConvertReceiptInput ;
2324use reth_rpc_eth_api:: { RpcBlock , RpcReceipt } ;
24- use rollup_boost:: {
25- FlashblockBuilder , FlashblocksPayloadV1 , OpExecutionPayloadEnvelope , PayloadVersion ,
26- } ;
27- use serde:: { Deserialize , Serialize } ;
28- use std:: { collections:: HashMap , str:: FromStr , sync:: Arc } ;
29-
30- #[ derive( Debug , Deserialize , Serialize , Clone , Default ) ]
31- pub struct Metadata {
32- pub receipts : HashMap < String , OpReceipt > ,
33- pub new_account_balances : HashMap < String , String > , // Address -> Balance (hex)
34- pub block_number : u64 ,
25+ use rollup_boost:: { FlashblockBuilder , OpExecutionPayloadEnvelope , PayloadVersion } ;
26+ use std:: { collections:: HashMap , sync:: Arc } ;
27+
28+ /// Convert op_alloy_consensus::OpReceipt to reth_optimism_primitives::OpReceipt
29+ fn convert_receipt ( receipt : & op_alloy_consensus:: OpReceipt ) -> reth_optimism_primitives:: OpReceipt {
30+ match receipt {
31+ op_alloy_consensus:: OpReceipt :: Legacy ( r) => {
32+ reth_optimism_primitives:: OpReceipt :: Legacy ( r. clone ( ) )
33+ }
34+ op_alloy_consensus:: OpReceipt :: Eip2930 ( r) => {
35+ reth_optimism_primitives:: OpReceipt :: Eip2930 ( r. clone ( ) )
36+ }
37+ op_alloy_consensus:: OpReceipt :: Eip1559 ( r) => {
38+ reth_optimism_primitives:: OpReceipt :: Eip1559 ( r. clone ( ) )
39+ }
40+ op_alloy_consensus:: OpReceipt :: Eip7702 ( r) => {
41+ reth_optimism_primitives:: OpReceipt :: Eip7702 ( r. clone ( ) )
42+ }
43+ op_alloy_consensus:: OpReceipt :: Deposit ( r) => {
44+ reth_optimism_primitives:: OpReceipt :: Deposit ( r. clone ( ) )
45+ }
46+ }
3547}
3648
3749#[ derive( Clone ) ]
@@ -65,7 +77,7 @@ impl FlashblocksCache {
6577 ArcSwap :: load ( & self . inner ) . get_receipt ( tx_hash)
6678 }
6779
68- pub fn process_payload ( & self , payload : FlashblocksPayloadV1 ) -> eyre:: Result < ( ) > {
80+ pub fn process_payload ( & self , payload : OpFlashblockPayload ) -> eyre:: Result < ( ) > {
6981 let mut new_state = FlashblocksCacheInner :: clone ( & self . inner . load_full ( ) ) ;
7082 new_state. process_payload ( payload) ?;
7183 self . inner . store ( Arc :: new ( new_state) ) ;
@@ -147,14 +159,8 @@ impl FlashblocksCacheInner {
147159 self . receipts_cache . clear ( ) ;
148160 }
149161
150- pub fn process_payload ( & mut self , payload : FlashblocksPayloadV1 ) -> eyre:: Result < ( ) > {
151- // Convert metadata with error handling
152- let metadata: Metadata = match serde_json:: from_value ( payload. metadata . clone ( ) ) {
153- Ok ( m) => m,
154- Err ( e) => {
155- return Err ( eyre:: eyre!( "Failed to deserialize metadata: {}" , e) ) ;
156- }
157- } ;
162+ pub fn process_payload ( & mut self , payload : OpFlashblockPayload ) -> eyre:: Result < ( ) > {
163+ let metadata = payload. metadata . clone ( ) ;
158164
159165 if payload. index == 0 {
160166 self . reset ( ) ;
@@ -190,7 +196,7 @@ impl FlashblocksCacheInner {
190196 // update the receipts
191197 let receipt = metadata
192198 . receipts
193- . get ( & tx. tx_hash ( ) . to_string ( ) )
199+ . get ( & tx. tx_hash ( ) )
194200 . expect ( "Receipt should exist" ) ;
195201
196202 all_receipts. push ( receipt. clone ( ) ) ;
@@ -226,7 +232,7 @@ impl FlashblocksCacheInner {
226232 timestamp,
227233 } ;
228234 let input: ConvertReceiptInput < ' _ , OpPrimitives > = ConvertReceiptInput {
229- receipt : receipt . clone ( ) ,
235+ receipt : convert_receipt ( receipt ) ,
230236 tx : tx. try_to_recovered_ref ( ) ?,
231237 gas_used : receipt. cumulative_gas_used ( ) - gas_used,
232238 next_log_index,
@@ -250,12 +256,7 @@ impl FlashblocksCacheInner {
250256
251257 // Store account balances
252258 for ( address, balance) in metadata. new_account_balances . iter ( ) {
253- let address = Address :: from_str ( address)
254- . map_err ( |e| eyre:: eyre!( "Failed to parse address: {}" , e) ) ?;
255- let balance = U256 :: from_str ( balance)
256- . map_err ( |e| eyre:: eyre!( "Failed to parse balance: {}" , e) ) ?;
257-
258- self . balance_cache . insert ( address, balance) ;
259+ self . balance_cache . insert ( * address, * balance) ;
259260 }
260261
261262 Ok ( ( ) )
0 commit comments