Skip to content

Commit 2357d25

Browse files
committed
refactor
1 parent c36dc26 commit 2357d25

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

crates/op-rbuilder/src/builders/flashblocks/payload.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,20 @@ impl OpPayloadBuilderCtx<FlashblocksExtraCtx> {
7878
}
7979

8080
/// Increments the flashblock index
81-
pub fn increment_flashblock_index(&mut self) {
81+
pub fn increment_flashblock_index(&mut self) -> u64 {
8282
self.extra_ctx.flashblock_index += 1;
83+
self.extra_ctx.flashblock_index
8384
}
8485

8586
/// Sets the target flashblock count
86-
pub fn set_target_flashblock_count(&mut self, target_flashblock_count: u64) {
87+
pub fn set_target_flashblock_count(&mut self, target_flashblock_count: u64) -> u64 {
8788
self.extra_ctx.target_flashblock_count = target_flashblock_count;
89+
self.extra_ctx.target_flashblock_count
90+
}
91+
92+
/// Returns if the flashblock is the last one
93+
pub fn is_last_flashblock(&self) -> bool {
94+
self.flashblock_index() == self.target_flashblock_count()
8895
}
8996
}
9097

@@ -389,7 +396,7 @@ where
389396
// execute_best_transaction without cancelling parent token
390397
ctx.cancel = cancel_token;
391398
// TODO: remove this
392-
if ctx.flashblock_index() >= ctx.target_flashblock_count() {
399+
if ctx.flashblock_index() > ctx.target_flashblock_count() {
393400
info!(
394401
target: "payload_builder",
395402
target = ctx.target_flashblock_count(),
@@ -413,7 +420,7 @@ where
413420
let flashblock_build_start_time = Instant::now();
414421
let state = StateProviderDatabase::new(&state_provider);
415422
// If it is the last flashblock, we need to account for the builder tx
416-
if ctx.flashblock_index() == ctx.target_flashblock_count() - 1 {
423+
if ctx.is_last_flashblock() {
417424
total_gas_per_batch = total_gas_per_batch.saturating_sub(builder_tx_gas);
418425
// saturating sub just in case, we will log an error if da_limit too small for builder_tx_da_size
419426
if let Some(da_limit) = total_da_per_batch.as_mut() {
@@ -472,7 +479,7 @@ where
472479
.set(payload_tx_simulation_time);
473480

474481
// If it is the last flashblocks, add the builder txn to the block if enabled
475-
if ctx.flashblock_index() == ctx.target_flashblock_count() - 1 {
482+
if ctx.is_last_flashblock() {
476483
ctx.add_builder_tx(&mut info, &mut db, builder_tx_gas, message.clone());
477484
};
478485

@@ -496,8 +503,7 @@ where
496503
return Err(err);
497504
}
498505
Ok((new_payload, mut fb_payload, new_bundle_state)) => {
499-
ctx.increment_flashblock_index(); // fallback block is index 0, so we need to increment here
500-
fb_payload.index = ctx.flashblock_index();
506+
fb_payload.index = ctx.increment_flashblock_index(); // fallback block is index 0, so we need to increment here
501507
fb_payload.base = None;
502508

503509
// We check that child_job got cancelled before sending flashblock.

crates/op-rbuilder/src/tests/flashtestations.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)