Skip to content

Commit 49063b1

Browse files
committed
chore: take cache
1 parent ccc6ef7 commit 49063b1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

crates/optimism/flashblocks/src/cache.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl<T: SignedTransaction> SequenceManager<T> {
102102
// Ring buffer automatically evicts oldest entry when full
103103
let txs = std::mem::take(&mut self.pending_transactions);
104104
self.completed_cache.push((completed, txs));
105+
106+
// ensure cache is wiped on new flashblock
107+
let _ = self.pending.take_cached_reads();
105108
}
106109

107110
self.pending_transactions
@@ -123,7 +126,7 @@ impl<T: SignedTransaction> SequenceManager<T> {
123126
///
124127
/// Returns None if nothing is buildable right now.
125128
pub(crate) fn next_buildable_args(
126-
&self,
129+
&mut self,
127130
local_tip_hash: B256,
128131
local_tip_timestamp: u64,
129132
) -> Option<BuildArgs<Vec<WithEncoded<Recovered<T>>>>> {
@@ -132,9 +135,9 @@ impl<T: SignedTransaction> SequenceManager<T> {
132135
let (base, last_flashblock, transactions, cached_state, source_name) =
133136
// Priority 1: Try current pending sequence
134137
if let Some(base) = self.pending.payload_base().filter(|b| b.parent_hash == local_tip_hash) {
138+
let cached_state = self.pending.take_cached_reads().map(|r| (base.parent_hash, r));
135139
let last_fb = self.pending.last_flashblock()?;
136140
let transactions = self.pending_transactions.clone();
137-
let cached_state = self.pending.cached_reads().as_ref().map(|r| (base.parent_hash, r.clone()));
138141
(base, last_fb, transactions, cached_state, "pending")
139142
}
140143
// Priority 2: Try cached sequence with exact parent match
@@ -311,7 +314,7 @@ mod tests {
311314

312315
#[test]
313316
fn test_next_buildable_args_returns_none_when_empty() {
314-
let manager: SequenceManager<OpTxEnvelope> = SequenceManager::new(true);
317+
let mut manager: SequenceManager<OpTxEnvelope> = SequenceManager::new(true);
315318
let local_tip_hash = B256::random();
316319
let local_tip_timestamp = 1000;
317320

crates/optimism/flashblocks/src/sequence.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ impl FlashBlockPendingSequence {
9999
self.cached_reads = Some(cached_reads);
100100
}
101101

102-
/// Returns cached reads for this sequence
103-
pub const fn cached_reads(&self) -> &Option<CachedReads> {
104-
&self.cached_reads
102+
/// Removes the cached reads for this sequence
103+
pub const fn take_cached_reads(&mut self) -> Option<CachedReads> {
104+
self.cached_reads.take()
105105
}
106106

107107
/// Returns the first block number
@@ -405,12 +405,12 @@ mod tests {
405405

406406
let cached_reads = CachedReads::default();
407407
sequence.set_cached_reads(cached_reads);
408-
assert!(sequence.cached_reads().is_some());
408+
assert!(sequence.take_cached_reads().is_some());
409409

410410
let _complete = sequence.finalize().unwrap();
411411

412412
// Cached reads should be cleared
413-
assert!(sequence.cached_reads().is_none());
413+
assert!(sequence.take_cached_reads().is_none());
414414
}
415415

416416
#[test]

0 commit comments

Comments
 (0)