1- use std:: sync:: Arc ;
1+ use std:: { sync:: Arc , time :: Instant } ;
22
33use alloy_consensus:: { Header , Sealed } ;
44use alloy_eips:: BlockNumberOrTag ;
@@ -20,7 +20,7 @@ use reth::revm::{
2020use reth_rpc_convert:: RpcTransaction ;
2121use reth_rpc_eth_api:: { RpcBlock , RpcReceipt } ;
2222
23- use crate :: { rpc:: PendingBlocksAPI , subscription:: Flashblock } ;
23+ use crate :: { metrics :: Metrics , rpc:: PendingBlocksAPI , subscription:: Flashblock } ;
2424
2525pub struct PendingBlocksBuilder {
2626 flashblocks : Vec < Flashblock > ,
@@ -208,8 +208,20 @@ impl PendingBlocks {
208208 self . db_cache . clone ( )
209209 }
210210
211+ /// Returns a clone of the bundle state.
212+ ///
213+ /// NOTE: This clones the entire BundleState, which contains a HashMap of all touched
214+ /// accounts and their storage slots. The cost scales with the number of accounts and
215+ /// storage slots modified in the flashblock. Monitor `bundle_state_clone_duration` and
216+ /// `bundle_state_clone_size` metrics to track if this becomes a bottleneck.
211217 pub fn get_bundle_state ( & self ) -> BundleState {
212- self . bundle_state . clone ( )
218+ let metrics = Metrics :: default ( ) ;
219+ let size = self . bundle_state . state . len ( ) ;
220+ let start = Instant :: now ( ) ;
221+ let cloned = self . bundle_state . clone ( ) ;
222+ metrics. bundle_state_clone_duration . record ( start. elapsed ( ) ) ;
223+ metrics. bundle_state_clone_size . record ( size as f64 ) ;
224+ cloned
213225 }
214226
215227 pub fn get_transactions_for_block ( & self , block_number : BlockNumber ) -> Vec < Transaction > {
0 commit comments