Skip to content

Commit f8b2e5e

Browse files
committed
fix: remove naive seen_txns cache
1 parent b887bd4 commit f8b2e5e

File tree

2 files changed

+2
-48
lines changed

2 files changed

+2
-48
lines changed

src/tasks/block.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ impl BlockBuilder {
153153
tracing::error!(error = %e, "error polling transactions");
154154
}
155155
}
156-
self.tx_poller.evict();
157156
}
158157

159158
async fn _get_bundles(&mut self, in_progress: &mut InProgressBlock) {

src/tasks/tx_poller.rs

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
use std::time::Duration;
2-
use std::{collections::HashMap, time};
3-
41
use alloy::consensus::TxEnvelope;
5-
use alloy_primitives::TxHash;
6-
72
use eyre::Error;
83
use reqwest::{Client, Url};
94
use serde::{Deserialize, Serialize};
@@ -22,61 +17,21 @@ pub struct TxPoller {
2217
pub config: BuilderConfig,
2318
// Reqwest client for fetching transactions from the tx-pool
2419
pub client: Client,
25-
// Maintain a set of transaction hashes to their expiration times
26-
pub seen_txns: HashMap<TxHash, time::Instant>,
2720
}
2821

2922
/// TxPoller implements a poller that fetches unique transactions from the transaction pool.
3023
impl TxPoller {
3124
/// returns a new TxPoller with the given config.
3225
pub fn new(config: &BuilderConfig) -> Self {
33-
Self { config: config.clone(), client: Client::new(), seen_txns: HashMap::new() }
26+
Self { config: config.clone(), client: Client::new() }
3427
}
3528

3629
/// polls the tx-pool for unique transactions and evicts expired transactions.
3730
/// unique transactions that haven't been seen before are sent into the builder pipeline.
3831
pub async fn check_tx_cache(&mut self) -> Result<Vec<TxEnvelope>, Error> {
39-
let mut unique: Vec<TxEnvelope> = Vec::new();
40-
4132
let url: Url = Url::parse(&self.config.tx_pool_url)?.join("transactions")?;
4233
let result = self.client.get(url).send().await?;
4334
let response: TxPoolResponse = from_slice(result.text().await?.as_bytes())?;
44-
45-
response.transactions.iter().for_each(|entry| {
46-
self.check_seen_txs(entry.clone(), &mut unique);
47-
});
48-
49-
Ok(unique)
50-
}
51-
52-
/// checks if the transaction has been seen before and if not, adds it to the unique transactions list.
53-
fn check_seen_txs(&mut self, tx: TxEnvelope, unique: &mut Vec<TxEnvelope>) {
54-
self.seen_txns.entry(*tx.tx_hash()).or_insert_with(|| {
55-
// add to unique transactions
56-
unique.push(tx.clone());
57-
// expiry is now + cache_duration
58-
time::Instant::now() + Duration::from_secs(self.config.tx_pool_cache_duration)
59-
});
60-
}
61-
62-
/// removes entries from seen_txns that have lived past expiry
63-
pub fn evict(&mut self) {
64-
let expired_keys: Vec<TxHash> = self
65-
.seen_txns
66-
.iter()
67-
.filter_map(
68-
|(key, &expiration)| {
69-
if !expiration.elapsed().is_zero() {
70-
Some(*key)
71-
} else {
72-
None
73-
}
74-
},
75-
)
76-
.collect();
77-
78-
for key in expired_keys {
79-
self.seen_txns.remove(&key);
80-
}
35+
Ok(response.transactions)
8136
}
8237
}

0 commit comments

Comments
 (0)