Skip to content

Conversation

noot
Copy link
Contributor

@noot noot commented Sep 12, 2025

📝 Summary

  • refactor flashblocks build_payload into separate functions for readability, specifically moved the code executed within the loop to build a flashblock to its own build_next_flashblock fn (didn't change any logic here)
  • removed spawn_timer_task in favour of select statements with ticker inside build_payload for clarity
  • no code logic was changed with this PR, just refactored

💡 Motivation and Context

dug into #209 (this PR also improves the logging) and saw opportunity for clean up

✅ I have completed the following steps:

  • Run make lint
  • Run make test
  • Added tests (if applicable)

@SozinM
Copy link
Collaborator

SozinM commented Sep 12, 2025

This refactoring causes logic change
This is the main with release and load (50 txs/sec):
main release load
This is your branch with the same conditions:
refactor release load

@noot
Copy link
Contributor Author

noot commented Sep 12, 2025

@SozinM I have fixed the timing, let me know how it looks!
Screenshot_2025-09-12_12-55-38

Comment on lines 510 to 524
ctx: &mut OpPayloadBuilderCtx<FlashblocksExtraCtx>,
info: &mut ExecutionInfo<ExtraExecutionInfo>,
total_gas_per_batch: &mut u64,
total_da_per_batch: &mut Option<u64>,
builder_tx_da_size: u64,
builder_tx_gas: u64,
state: &mut State<DB>,
best_txs: &mut NextBestFlashblocksTxs<Pool>,
block_cancel: &CancellationToken,
flashblocks_per_block: u64,
message: Vec<u8>,
best_payload: &BlockCell<OpBuiltPayload>,
gas_per_batch: u64,
da_per_batch: Option<u64>,
span: &tracing::Span,
Copy link
Collaborator

Choose a reason for hiding this comment

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

the gas / da / config variables can be part of the flashblocks ctx I feel. It would reduce the number of arguments here

Comment on lines 514 to 515
builder_tx_da_size: u64,
builder_tx_gas: u64,
Copy link
Collaborator

Choose a reason for hiding this comment

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

there shouldn't be a need to pass this in, can be recalculated for each flashblock. in the future different builder transactions will be inserted depending on whether its the first / last flashblock so it needs to be dynamically calculated per flashblock

@noot noot requested a review from avalonche September 15, 2025 17:53
Comment on lines 80 to 83
total_gas_per_batch: u64,
total_da_per_batch: Option<u64>,
gas_per_batch: u64,
da_per_batch: Option<u64>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you add some comments around what the different fields are here

if let Some(da_limit) = total_da_per_batch.as_mut() {
*da_limit = da_limit.saturating_sub(builder_tx_da_size);
}
ctx.extra_ctx.total_da_per_batch = total_da_per_batch;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not directly assign ctx.extra_ctx.total_da_per_batch to da_per_batch? Same with the other ctx.extra_ctx assignments, may be worth adding a method for modifying these fields here

}
}

ctx.extra_ctx.total_gas_per_batch = total_gas_per_batch;
Copy link
Collaborator

Choose a reason for hiding this comment

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

can simplify with ctx.extra_ctx.total_gas_per_batch += ctx.extra_ctx.gas_per_batch;

.unwrap_or(0);

// Continue with flashblock building
let mut total_gas_per_batch = ctx.extra_ctx.total_gas_per_batch;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: should be named target_gas_for_batch

Copy link
Collaborator

@avalonche avalonche left a comment

Choose a reason for hiding this comment

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

some nits, great work!

@noot noot merged commit c92a924 into main Sep 17, 2025
4 checks passed
@noot noot deleted the noot/build-payload-refactor branch September 17, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants