Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit 15477fe

Browse files
committed
remove key by sender
1 parent 674b361 commit 15477fe

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

crates/op-rbuilder/src/bundles.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use jsonrpsee::{
66
proc_macros::rpc,
77
};
88
use op_alloy_consensus::OpTxEnvelope;
9-
use std::{collections::HashMap, fmt::Debug, sync::Arc, time::Instant};
9+
use std::{fmt::Debug, sync::Arc, time::Instant};
1010
use tips_core::AcceptedBundle;
1111
use tracing::{debug, info, warn};
1212
use uuid::Uuid;
@@ -22,7 +22,7 @@ pub struct StoredBackrunBundle {
2222
}
2323

2424
struct 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

Comments
 (0)