Skip to content

refactor(ethexe/processor): split run module into separate files#5267

Open
playX18 wants to merge 3 commits intomasterfrom
ap/refactor-run-module
Open

refactor(ethexe/processor): split run module into separate files#5267
playX18 wants to merge 3 commits intomasterfrom
ap/refactor-run-module

Conversation

@playX18
Copy link
Copy Markdown
Member

@playX18 playX18 commented Mar 30, 2026

Resolves #5120

  • Extract chunks_splitting logic to dedicated module
  • Extract chunk_execution_spawn logic to dedicated module
  • Extract chunk_execution_processing logic to dedicated module

@gear-tech/dev

- Extract chunks_splitting logic to dedicated module
- Extract chunk_execution_spawn logic to dedicated module
- Extract chunk_execution_processing logic to dedicated module
- Improve code organization and maintainability
@playX18 playX18 requested review from breathx and grishasobol March 30, 2026 03:47
@playX18 playX18 self-assigned this Mar 30, 2026
@playX18 playX18 added A0-pleasereview PR is ready to be reviewed by the team D8-ethexe ethexe-related PR labels Mar 30, 2026
@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com bot commented Mar 30, 2026

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the ethexe processor's run module by decomposing it into smaller, more focused files. This change improves the modularity of the codebase, making it easier to navigate and maintain the logic responsible for splitting, spawning, and processing execution chunks.

Highlights

  • Code Refactoring: Split the monolithic run module into three dedicated modules: chunks_splitting, chunk_execution_spawn, and chunk_execution_processing.
  • Improved Maintainability: Enhanced code readability and maintainability by organizing logic into separate files based on their specific responsibilities within the chunk execution pipeline.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the ethexe/processor/src/handling/run module by extracting its internal logic into dedicated files: chunk_execution_processing.rs, chunk_execution_spawn.rs, and chunks_splitting.rs. This reorganization improves code structure and maintainability. The review feedback suggests a more idiomatic approach in collect_chunk_journals by using fold instead of map to avoid side effects when calculating the maximum gas spent and collecting journals.

Comment on lines +54 to +73
let mut max_gas_spent_in_chunk = 0u64;

let chunk_journals = chunk_outputs
.into_iter()
.map(
|(program_id, new_state_hash, program_journals, gas_spent)| {
// Handle state updates that occurred during journal processing within the runtime (allocations, pages).
// This should happen before processing the journal notes because `send_dispatch` from another program can modify the state.
ctx.inner_mut().transitions.modify(program_id, |state, _| {
state.hash = new_state_hash;
});

max_gas_spent_in_chunk = max_gas_spent_in_chunk.max(gas_spent);

(program_id, program_journals)
},
)
.collect();

(chunk_journals, max_gas_spent_in_chunk)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better maintainability and adherence to functional programming principles, it's preferable to avoid side effects within a map closure. The current implementation mutates max_gas_spent_in_chunk from within the map.

Using fold would be more idiomatic here. It can build the chunk_journals vector and calculate the maximum gas spent in a single, side-effect-free pass.

Suggested change
let mut max_gas_spent_in_chunk = 0u64;
let chunk_journals = chunk_outputs
.into_iter()
.map(
|(program_id, new_state_hash, program_journals, gas_spent)| {
// Handle state updates that occurred during journal processing within the runtime (allocations, pages).
// This should happen before processing the journal notes because `send_dispatch` from another program can modify the state.
ctx.inner_mut().transitions.modify(program_id, |state, _| {
state.hash = new_state_hash;
});
max_gas_spent_in_chunk = max_gas_spent_in_chunk.max(gas_spent);
(program_id, program_journals)
},
)
.collect();
(chunk_journals, max_gas_spent_in_chunk)
chunk_outputs.into_iter().fold(
(Vec::with_capacity(chunk_outputs.len()), 0u64),
|(mut chunk_journals, max_gas_spent_in_chunk),
(program_id, new_state_hash, program_journals, gas_spent)| {
// Handle state updates that occurred during journal processing within the runtime (allocations, pages).
// This should happen before processing the journal notes because `send_dispatch` from another program can modify the state.
ctx.inner_mut().transitions.modify(program_id, |state, _| {
state.hash = new_state_hash;
});
chunk_journals.push((program_id, program_journals));
(
chunk_journals,
max_gas_spent_in_chunk.max(gas_spent),
)
},
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A0-pleasereview PR is ready to be reviewed by the team D8-ethexe ethexe-related PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ethexe: processor run split to several files and move to separate module

1 participant