refactor(ethexe/processor): split run module into submodules#5266
refactor(ethexe/processor): split run module into submodules#5266
Conversation
- Split ethexe/processor/src/handling/run.rs (1006 lines) into separate module - Create run/ directory with logical components: - mod.rs: Main execution loop, RunContext trait, CommonRunContext - chunks_splitting.rs: Chunk partitioning algorithm and data structures - chunk_execution_spawn.rs: Thread pool spawning and parallel execution - chunk_execution_processing.rs: Journal collection and processing - Update overlaid.rs imports to use re-exported types - All 18 tests pass, no functional changes Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Changed Files
|
Summary of ChangesHello, 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 processor's execution logic by decomposing a large module into smaller, focused submodules. This change improves code organization and readability by separating concerns related to chunk partitioning, parallel execution, and journal processing. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors the chunk execution logic by extracting submodules from ethexe/processor/src/handling/run/mod.rs into dedicated files: chunk_execution_processing.rs, chunk_execution_spawn.rs, and chunks_splitting.rs. The review feedback recommends using a more idiomatic functional approach with fold in collect_chunk_journals to avoid external mutability. Additionally, a suggestion was made to simplify a redundant module path for ExecutionChunks to improve code consistency.
| 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) | ||
| } |
There was a problem hiding this comment.
The current implementation uses map with side effects to update max_gas_spent_in_chunk and then collects the results. A more idiomatic and functional approach would be to use fold. This would eliminate the need for an external mutable variable and make the data transformation more self-contained and clearer.
chunk_outputs
.into_iter()
.fold((Vec::new(), 0u64), |(mut journals, max_gas), (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;
});
journals.push((program_id, program_journals));
(journals, max_gas.max(gas_spent))
})| fn handle_chunk_data( | ||
| &self, | ||
| execution_chunks: &mut ExecutionChunks, | ||
| execution_chunks: &mut chunks_splitting::ExecutionChunks, |
There was a problem hiding this comment.
For consistency with how ActorStateHashWithQueueSize is used in the next line, and to leverage the use statement on line 111, it's better to refer to ExecutionChunks directly without the module path. This improves readability and consistency within the module.
| execution_chunks: &mut chunks_splitting::ExecutionChunks, | |
| execution_chunks: &mut ExecutionChunks, |
Resolves #5120
@gear-tech/dev