Feat: continuous flashblock building#311
Closed
julio4 wants to merge 4 commits intoflashbots:mainfrom
Closed
Conversation
3 tasks
40d2e53 to
e5c72dc
Compare
SozinM
reviewed
Nov 4, 2025
SozinM
reviewed
Nov 4, 2025
SozinM
reviewed
Nov 4, 2025
noot
reviewed
Nov 4, 2025
Collaborator
|
i suggest following refactor: |
noot
reviewed
Nov 4, 2025
noot
reviewed
Nov 4, 2025
noot
reviewed
Nov 5, 2025
Comment on lines
+1019
to
+1045
| if block_cancel.is_cancelled() { | ||
| self.record_flashblocks_metrics( | ||
| ctx, | ||
| info, | ||
| ctx.target_flashblock_count(), | ||
| span, | ||
| "Payload building complete, channel closed or job cancelled", | ||
| ); | ||
| return Ok(None); | ||
| } | ||
| // interval end: abort worker and publish current best immediately (below) | ||
| if ctx.cancel.is_cancelled() { | ||
| break; | ||
| } | ||
|
|
||
| // Build one candidate | ||
| best = self.refresh_best_flashblock_candidate( | ||
| best, | ||
| ctx, | ||
| &*info, | ||
| state, | ||
| &state_provider, | ||
| best_txs, | ||
| block_cancel, | ||
| target_gas_for_batch, | ||
| target_da_for_batch, | ||
| )?; |
Contributor
There was a problem hiding this comment.
Suggested change
| if block_cancel.is_cancelled() { | |
| self.record_flashblocks_metrics( | |
| ctx, | |
| info, | |
| ctx.target_flashblock_count(), | |
| span, | |
| "Payload building complete, channel closed or job cancelled", | |
| ); | |
| return Ok(None); | |
| } | |
| // interval end: abort worker and publish current best immediately (below) | |
| if ctx.cancel.is_cancelled() { | |
| break; | |
| } | |
| // Build one candidate | |
| best = self.refresh_best_flashblock_candidate( | |
| best, | |
| ctx, | |
| &*info, | |
| state, | |
| &state_provider, | |
| best_txs, | |
| block_cancel, | |
| target_gas_for_batch, | |
| target_da_for_batch, | |
| )?; | |
| let handle = tokio::task::spawn_blocking(|| { | |
| refresh_best_flashblock_candidate( | |
| best, | |
| ctx, | |
| info, | |
| state, | |
| &state_provider, | |
| best_txs, | |
| block_cancel, | |
| target_gas_for_batch, | |
| target_da_for_batch, | |
| ) | |
| }); | |
| tokio::select! { | |
| biased; | |
| _ = block_cancel.cancelled() => { | |
| break; | |
| } | |
| result = handle => { | |
| match result { | |
| Ok(Ok(Some(new_best))) => { | |
| best = Some(new_best); | |
| } | |
| Ok(Ok(None)) => { | |
| return Ok(None); | |
| } | |
| Ok(Err(e)) => { | |
| return Err(e); | |
| } | |
| Err(e) => { | |
| return Err(eyre::eyre!("flashblock candidate building task panicked: {}", e)); | |
| } | |
| } | |
| } | |
| } |
something like this would address the issue in your description where refresh_best_flashblock_candidate might take too long, would need to refactor refresh_best_flashblock_candidate to not be a method on self, and update type param DB to be Sync.
# Conflicts: # crates/op-rbuilder/src/builders/flashblocks/config.rs # crates/op-rbuilder/src/builders/flashblocks/payload.rs
83089b4 to
e3a1b33
Compare
Member
Author
|
Close as working on a more complete version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
Add a
enable_continuous_buildingflag for flashblock builder enabled by default.When continuous building is enabled, at each interval the builder keep trying building flashblock payloads corresponding to the given interval (a FlashblockCandidate). This is done in a sequential loop so at any time we have one best candidate (after building the first one).
This is implemented in the
build_next_flashblock_continuous, which should provides similar behaviors as the non-continuousbuild_next_flashblock(where we build one flashblock and directly send it).The logic of building a candidate is defined in
refresh_best_flashblock_candidate. Because each candidate can have completely different transactions/ordering, they all need to be built from the same base state. All further mutations are done in a separatesimulation_statebased on the fb base state and saved within the candidate as a coupleCacheState, Option<TransitionState>, which can be used to apply the state of the best candidate and move forward in the building process.This whole process is blocking. However between each candidate building we check for
block_cancelandfb_cancel(and also check forblock_cancelwithinrefresh_best_flashblock_candidatebefore building the final block). This replicates current behavior, however I think that this could cause some isues in specific situations when therefresh_best_flashblock_candidatetakes too much time afterfb_cancelis triggered and could introduce slight delays in payload distribution/start of next flashblock. This could be improved with more careful asynchronous model IMO.It is only useful to try to build a new candidate when the mempool is updated, which is not checked currently and just naively try to build candidates. This can also be improved.