Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions crates/optimism/flashblocks/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct FlashBlockService<
rx: S,
current: Option<PendingBlock<N>>,
blocks: FlashBlockSequence<N::SignedTx>,
rebuild: bool,
evm_config: EvmConfig,
provider: Provider,
canon_receiver: CanonStateNotifications<N>,
Expand Down Expand Up @@ -71,6 +72,7 @@ where
canon_receiver: provider.subscribe_to_canonical_state(),
provider,
cached_state: None,
rebuild: false,
}
}

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

let mut new_flashblock = false;
// consume new flashblocks while they're ready
while let Poll::Ready(Some(result)) = this.rx.poll_next_unpin(cx) {
match result {
Ok(flashblock) => {
if let Err(err) = this.blocks.insert(flashblock) {
debug!(%err, "Failed to prepare flashblock");
} else {
new_flashblock = true;
}
}
Ok(flashblock) => match this.blocks.insert(flashblock) {
Ok(_) => this.rebuild = true,
Err(err) => debug!(%err, "Failed to prepare flashblock"),
},
Err(err) => return Poll::Ready(Some(Err(err))),
}
}
Expand All @@ -216,16 +214,16 @@ where
}
}

if !new_flashblock && this.current.is_none() {
// no new flashbblocks received since, block is still unchanged
return Poll::Pending
if !this.rebuild && this.current.is_some() {
return Poll::Pending;
Comment on lines +217 to +218
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should hold now,
we set on fb and unset after building

}

// try to build a block on top of latest
match this.execute() {
Ok(Some(new_pending)) => {
// built a new pending block
this.current = Some(new_pending.clone());
this.rebuild = false;
return Poll::Ready(Some(Ok(Some(new_pending))));
}
Ok(None) => {
Expand Down
Loading