@@ -6,7 +6,7 @@ use jsonrpsee::{
66 proc_macros:: rpc,
77} ;
88use op_alloy_consensus:: OpTxEnvelope ;
9- use std:: { collections :: HashMap , fmt:: Debug , sync:: Arc , time:: Instant } ;
9+ use std:: { fmt:: Debug , sync:: Arc , time:: Instant } ;
1010use tips_core:: AcceptedBundle ;
1111use tracing:: { debug, info, warn} ;
1212use uuid:: Uuid ;
@@ -22,7 +22,7 @@ pub struct StoredBackrunBundle {
2222}
2323
2424struct BackrunData {
25- by_target_tx : dashmap:: DashMap < TxHash , HashMap < Address , StoredBackrunBundle > > ,
25+ by_target_tx : dashmap:: DashMap < TxHash , Vec < StoredBackrunBundle > > ,
2626 lru : ConcurrentQueue < TxHash > ,
2727}
2828
@@ -87,7 +87,16 @@ impl BackrunBundleStore {
8787
8888 let replaced = {
8989 let mut entry = self . data . by_target_tx . entry ( target_tx_hash) . or_default ( ) ;
90- entry. insert ( backrun_sender, stored_bundle) . is_some ( )
90+ let replaced = if let Some ( pos) = entry. iter ( ) . position ( |b| b. sender == backrun_sender)
91+ {
92+ entry[ pos] = stored_bundle;
93+ true
94+ } else {
95+ entry. push ( stored_bundle) ;
96+ false
97+ } ;
98+ entry. sort_by ( |a, b| b. total_priority_fee . cmp ( & a. total_priority_fee ) ) ;
99+ replaced
91100 } ;
92101
93102 if replaced {
@@ -108,12 +117,10 @@ impl BackrunBundleStore {
108117 }
109118
110119 pub fn get ( & self , target_tx_hash : & TxHash ) -> Option < Vec < StoredBackrunBundle > > {
111- self . data . by_target_tx . get ( target_tx_hash) . map ( |entry| {
112- let mut bundles: Vec < _ > = entry. values ( ) . cloned ( ) . collect ( ) ;
113- // Sort bundles by total_priority_fee (descending)
114- bundles. sort_by ( |a, b| b. total_priority_fee . cmp ( & a. total_priority_fee ) ) ;
115- bundles
116- } )
120+ self . data
121+ . by_target_tx
122+ . get ( target_tx_hash)
123+ . map ( |entry| entry. clone ( ) )
117124 }
118125
119126 pub fn remove ( & self , target_tx_hash : & TxHash ) {
0 commit comments