refactor(malachite): restructure service initialization and externalities#5580
refactor(malachite): restructure service initialization and externalities#5580grishasobol wants to merge 22 commits into
Conversation
Gate `Signer` re-export behind `std`, await the now-async `try_emit_or_queue`/`receive_*` calls, switch the service event loop and test env to the new `MalachiteServiceStarter` API, drop unused imports. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…rnals Drop both `disable-tests` cfg gates; port externalities unit tests to the `ChainHead` register / `Option<Arc<dyn Mempool>>` fields and async helpers, port restart_resilience to the `MalachiteServiceStarter` API. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ynced `ChainHead::latest_synced` was only seeded once in the starter, so the producer's quarantine probe never saw new EBs and proposals timed out. Update it in `receive_eb_synced` before waking the producer. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ased validation `Externalities::validate_block_above` now takes `&BlockPayload` and returns `Acceptance<(), String>`; rejection reasons travel in the variant (logged by the core) instead of local `warn!` + `Ok(false)`. Port the multi_validators TestExt impl and drop imports left unused by the core change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… rework Drop all `disable-tests` cfg gates. Port mempool tests to the async Mempool API (proptests drive it via block_on), quarantine tests to the SimpleBlockData/Acceptance signatures (drop `verify_passed` proptest — the depth check now lives in validate_block_above), and flip the unresolved-ref_block test to assert the now-implemented purge. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
`MalachiteConfig` → `MalachiteCoreConfig` / `MalachiteServiceConfig`, `MalachiteService` → `MalachiteCore` (in core), `MalachiteService::new` → `MalachiteServiceStarter::new`. CI docs build runs with `-D warnings`, so the stale links failed `build / docs`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Apply the short, informative doc style across ethexe-malachite and ethexe-malachite-core: one-line field docs, compressed method/struct docs without internal narration, trimmed inline comment blocks. Crate-level docs untouched. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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 Malachite consensus service initialization and externalities layer. The primary goal is to improve the separation of concerns and testability by introducing a builder-pattern starter, simplifying the externalities structure, and adopting more robust async patterns. These changes do not alter consensus behavior but significantly improve the codebase's maintainability and integration with async runtimes. 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 the 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 counterproductive. 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
|
|
@claude opus review |
|
Claude finished @grishasobol's task in 3m 20s —— View job Opus review —
|
There was a problem hiding this comment.
Code Review
This pull request refactors the 'ethexe-malachite' consensus service, introducing 'MalachiteServiceStarter' to separate initialization from execution, updating 'EthexeExternalities' and 'quarantine' to use the 'Acceptance' enum, and converting 'InjectedTxMempool' to use async methods with 'RwLock'. Feedback on these changes includes removing a temporary debug comment in 'ethexe/service/src/lib.rs', replacing a panic with an error in 'externalities.rs', using more idiomatic 'ok_or_else' error conversions in 'quarantine.rs', and reverting or documenting an unintended timeout change in 'starter.rs'.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f154c85e86
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- receive_eb_synced: advance latest_synced by height instead of requiring the synced hash to equal the latest observed head — under lagging sync every BlockSynced was dropped and the producer stalled (codex P1) - wait_for_proposable_content: bail instead of panic on missing mempool - quarantine: Option -> Result via ok_or_else instead of with_context - drop redundant double with_validators + clone in service setup - fix "Malachite not local role" log wording - refresh stale `MalachiteConfig` / `MalachiteService::new` / `receive_new_chain_head` mentions in docs and messages - document the single-writer / no-guard-across-await invariant on ChainHead Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- app loop: propagate fatal errors again — the catch-all made `FinalizationError::Fatal` dead code and silenced the error stream - receive_eb_synced: wake the producer on stale synced blocks too (a lower-height sync may land headers a failed descendant walk needs) - restore the `candidate == parent_advance` short-circuit in find_eb_candidate_for_advancing (no more "X does not descend from X" warn spam every idle round) - drop the redundant compute_mb on BlockFinalized: BlockProposal is always emitted first on every node, so compute is already triggered - make propose_timeout a MalachiteServiceConfig field (default stays 2 * SLOT_DURATION — Ethereum block time can stretch past one slot); test envs use a short timeout so idle rounds don't burn 24s each - MalachiteServiceStarter::new: drop unused async - nextest: reserve 4 threads for ethexe-service tests in the default profile like CI does — heavy multi-validator tests starved under full-suite parallelism and blew the 120s cap (full local suite is 527/527 with this) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…malachite-errors # Conflicts: # ethexe/compute/src/compute.rs # ethexe/malachite/service/src/externalities.rs
…malachite-errors # Conflicts: # ethexe/malachite/service/src/externalities.rs
Re-implements the parent-advance (AdvanceTillEthereumBlock) rule on top of #5580's MalachiteServiceStarter/ChainHead structure: - db init seeds the genesis era's on-chain validator set (a synced block must always have its era's validators in the db). - observer backfills db.validators(era) for every era spanned by a freshly synced chain, so a node joining mid-chain holds historical eras' sets. - new Externalities::validators_for_child_of resolves the era a parent MB advanced into; core app validator_set_for_height verifies each height's certificate against that era's set (falling back to the live shared set). - the on-chain address -> pub key pool is threaded into EthexeExternalities. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0147tTHt6e7mhirSAPwNxRc3
Summary
This PR refactors the Malachite consensus service initialization and externalities layer to improve separation of concerns and enable better testability. Key changes:
New
MalachiteServiceStarter: Extracted service initialization logic into a separate builder type that prepares all components before starting the core engine. This decouples configuration from runtime state.Restructured
EthexeExternalities: Simplified the externalities struct by:ExternalitiesConfigstructOption<SimpleBlockData>chain head with a newChainHeadtype that tracks both latest observed and synced Ethereum blocksMutex<VecDeque>pending events toRwLock<VecDeque>for async-safe accessOption<Arc<dyn Mempool>>) to support non-validator nodesUpdated
Externalitiestrait:validate_block_abovenow returnsAcceptance<(), String>instead ofboolfor richer rejection reasonsprocess_mb_proposalandprocess_mb_finalizedare now async (.awaiton event emission)validate_block_abovetakes&BlockPayloadinstead of owned valueNew
ChainHeadtype: Encapsulates chain head state with separate fields for latest observed and latest synced Ethereum blocks, plus a notification mechanism for async coordination.Renamed core types:
MalachiteConfig→MalachiteServiceConfig,MalachiteService→MalachiteCore(in ethexe-malachite-core), improving clarity about which layer each type belongs to.Added
Acceptance<A, R>enum: New generic type inethexe-commonfor representing accepted/rejected validation results with optional rejection reasons.These changes improve code organization, enable better async/await patterns, and make the service more testable by separating initialization concerns from runtime behavior.
How to test
ethexe/malachite/service/tests/restart_resilience.rshave been updated and should passethexe/malachite/core/tests/multi_validators.rsupdated for newAcceptancereturn typeethexe/service/src/tests/updated for new config and starter typescargo nextest run -p "ethexe-*"to verify all ethexe crates passNotes
MalachiteServiceStarterpattern enables future improvements like lazy initialization and better error handling during startup.awaitevent emission, improving integration with async runtimeOption<Arc<dyn Mempool>>https://claude.ai/code/session_014FBHbneaDtHjPcJDWgV4j4