Skip to content

Commit 358b61b

Browse files
authored
fix(optimism): Prevent repeated executions of current flashblock sequence (#18224)
1 parent 6bcd5e0 commit 358b61b

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

crates/optimism/flashblocks/src/service.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct FlashBlockService<
3737
rx: S,
3838
current: Option<PendingBlock<N>>,
3939
blocks: FlashBlockSequence<N::SignedTx>,
40+
rebuild: bool,
4041
evm_config: EvmConfig,
4142
provider: Provider,
4243
canon_receiver: CanonStateNotifications<N>,
@@ -71,6 +72,7 @@ where
7172
canon_receiver: provider.subscribe_to_canonical_state(),
7273
provider,
7374
cached_state: None,
75+
rebuild: false,
7476
}
7577
}
7678

@@ -187,17 +189,13 @@ where
187189
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
188190
let this = self.get_mut();
189191

190-
let mut new_flashblock = false;
191192
// consume new flashblocks while they're ready
192193
while let Poll::Ready(Some(result)) = this.rx.poll_next_unpin(cx) {
193194
match result {
194-
Ok(flashblock) => {
195-
if let Err(err) = this.blocks.insert(flashblock) {
196-
debug!(%err, "Failed to prepare flashblock");
197-
} else {
198-
new_flashblock = true;
199-
}
200-
}
195+
Ok(flashblock) => match this.blocks.insert(flashblock) {
196+
Ok(_) => this.rebuild = true,
197+
Err(err) => debug!(%err, "Failed to prepare flashblock"),
198+
},
201199
Err(err) => return Poll::Ready(Some(Err(err))),
202200
}
203201
}
@@ -216,16 +214,16 @@ where
216214
}
217215
}
218216

219-
if !new_flashblock && this.current.is_none() {
220-
// no new flashbblocks received since, block is still unchanged
221-
return Poll::Pending
217+
if !this.rebuild && this.current.is_some() {
218+
return Poll::Pending;
222219
}
223220

224221
// try to build a block on top of latest
225222
match this.execute() {
226223
Ok(Some(new_pending)) => {
227224
// built a new pending block
228225
this.current = Some(new_pending.clone());
226+
this.rebuild = false;
229227
return Poll::Ready(Some(Ok(Some(new_pending))));
230228
}
231229
Ok(None) => {

0 commit comments

Comments
 (0)