11use std:: {
2+ cmp:: max,
23 collections:: { BinaryHeap , HashMap , HashSet , VecDeque } ,
34 str:: FromStr ,
45} ;
@@ -46,9 +47,10 @@ use spl_token_2022::extension::{
4647 scaled_ui_amount:: ScaledUiAmountConfig ,
4748} ;
4849use surfpool_types:: {
49- AccountChange , AccountProfileState , DEFAULT_SLOT_TIME_MS , Idl , ProfileResult , RpcProfileDepth ,
50- RpcProfileResultConfig , SimnetEvent , TransactionConfirmationStatus , TransactionStatusEvent ,
51- UiAccountChange , UiAccountProfileState , UiProfileResult , VersionedIdl ,
50+ AccountChange , AccountProfileState , DEFAULT_PROFILING_MAP_CAPACITY , DEFAULT_SLOT_TIME_MS ,
51+ FifoMap , Idl , ProfileResult , RpcProfileDepth , RpcProfileResultConfig , SimnetEvent ,
52+ TransactionConfirmationStatus , TransactionStatusEvent , UiAccountChange , UiAccountProfileState ,
53+ UiProfileResult , VersionedIdl ,
5254 types:: {
5355 ComputeUnitsEstimationResult , KeyedProfileResult , UiKeyedProfileResult , UuidOrSignature ,
5456 } ,
@@ -112,7 +114,7 @@ pub struct SurfnetSvm {
112114 pub slot_subscriptions : Vec < Sender < SlotInfo > > ,
113115 pub profile_tag_map : HashMap < String , Vec < UuidOrSignature > > ,
114116 pub simulated_transaction_profiles : HashMap < Uuid , KeyedProfileResult > ,
115- pub executed_transaction_profiles : HashMap < Signature , KeyedProfileResult > ,
117+ pub executed_transaction_profiles : FifoMap < Signature , KeyedProfileResult > ,
116118 pub logs_subscriptions : Vec < LogsSubscriptionData > ,
117119 pub updated_at : u64 ,
118120 pub slot_time : u64 ,
@@ -136,6 +138,7 @@ pub struct SurfnetSvm {
136138 pub registered_idls : HashMap < Pubkey , BinaryHeap < VersionedIdl > > ,
137139 pub feature_set : FeatureSet ,
138140 pub instruction_profiling_enabled : bool ,
141+ pub max_profiles : usize ,
139142}
140143
141144pub const FEATURE : Feature = Feature {
@@ -186,7 +189,7 @@ impl SurfnetSvm {
186189 slot_subscriptions : Vec :: new ( ) ,
187190 profile_tag_map : HashMap :: new ( ) ,
188191 simulated_transaction_profiles : HashMap :: new ( ) ,
189- executed_transaction_profiles : HashMap :: new ( ) ,
192+ executed_transaction_profiles : FifoMap :: default ( ) ,
190193 logs_subscriptions : Vec :: new ( ) ,
191194 updated_at : Utc :: now ( ) . timestamp_millis ( ) as u64 ,
192195 slot_time : DEFAULT_SLOT_TIME_MS ,
@@ -207,6 +210,7 @@ impl SurfnetSvm {
207210 registered_idls : HashMap :: new ( ) ,
208211 feature_set,
209212 instruction_profiling_enabled : true ,
213+ max_profiles : DEFAULT_PROFILING_MAP_CAPACITY ,
210214 } ;
211215
212216 // Generate the initial synthetic blockhash
@@ -240,6 +244,7 @@ impl SurfnetSvm {
240244 self . updated_at = Utc :: now ( ) . timestamp_millis ( ) as u64 ;
241245 self . slot_time = slot_time;
242246 self . instruction_profiling_enabled = do_profile_instructions;
247+ self . set_profiling_map_capacity ( self . max_profiles ) ;
243248
244249 if let Some ( remote_client) = remote_ctx {
245250 let _ = self
@@ -265,6 +270,12 @@ impl SurfnetSvm {
265270 self . instruction_profiling_enabled = do_profile_instructions;
266271 }
267272
273+ pub fn set_profiling_map_capacity ( & mut self , capacity : usize ) {
274+ let clamped_capacity = max ( 1 , capacity) ;
275+ self . max_profiles = clamped_capacity;
276+ self . executed_transaction_profiles = FifoMap :: new ( clamped_capacity) ;
277+ }
278+
268279 /// Airdrops a specified amount of lamports to a single public key.
269280 ///
270281 /// # Arguments
@@ -2345,4 +2356,20 @@ mod tests {
23452356 assert_eq ! ( ui_account, expected_account) ;
23462357 }
23472358 }
2359+
2360+ #[ test]
2361+ fn test_profiling_map_capacity_default ( ) {
2362+ let ( svm, _events_rx, _geyser_rx) = SurfnetSvm :: new ( ) ;
2363+ assert_eq ! (
2364+ svm. executed_transaction_profiles. capacity( ) ,
2365+ DEFAULT_PROFILING_MAP_CAPACITY
2366+ ) ;
2367+ }
2368+
2369+ #[ test]
2370+ fn test_profiling_map_capacity_set ( ) {
2371+ let ( mut svm, _events_rx, _geyser_rx) = SurfnetSvm :: new ( ) ;
2372+ svm. set_profiling_map_capacity ( 10 ) ;
2373+ assert_eq ! ( svm. executed_transaction_profiles. capacity( ) , 10 ) ;
2374+ }
23482375}
0 commit comments