Skip to content

RPC Stack Refactor#10157

Open
marcosio wants to merge 9 commits intobesu-eth:mainfrom
IoBuilders:feature/rpc-stack-refactor-phase1-clean
Open

RPC Stack Refactor#10157
marcosio wants to merge 9 commits intobesu-eth:mainfrom
IoBuilders:feature/rpc-stack-refactor-phase1-clean

Conversation

@marcosio
Copy link
Copy Markdown
Contributor

@marcosio marcosio commented Apr 1, 2026

Summary

Implements Phase 1 and Phase 2 of the RPC Stack Refactor (#9476), consolidating the RPC architecture from 6 layers to 4 layers.

What Changed

Phase Description Files Classes
Phase 1 Executor Dispatch collapse (Layers 3-4) 4 -3 deleted
Phase 2 Processor Chain consolidation (Layer 5) 15 -3 deleted, +1 created
Net Result: 6 classes consolidated to 2, abstraction layers reduced from 6 to 4

Phase 1: Executor Dispatch (COMPLETE)

Collapsed the executor layer by eliminating intermediate executor classes:

Deleted Lines
AbstractJsonRpcExecutor.java 139
JsonRpcObjectExecutor.java 109
JsonRpcArrayExecutor.java 135
Logic inlined into JsonRpcExecutorHandler.java

Phase 2: Processor Chain (COMPLETE)

Combined timing, tracing, and execution into single processor:

Deleted Lines
BaseJsonRpcProcessor.java 59
TimedJsonRpcProcessor.java 48
TracedJsonRpcProcessor.java 140
Created CombinedJsonRpcProcessor.java (270 lines) - combines all three concerns

Phases NOT Completed

Phase 3: Handler Chain Redundancy - DEFERRED

Proposed: Merge AuthenticationHandler and TimeoutHandler into JsonRpcExecutorHandler
Findings:

  • AuthenticationHandler uses async callback pattern:
    authenticationService.authenticate(token, user -> ctx.put(...));
    ctx.next(); // Called immediately, doesn't wait for auth
  • Modifying this to synchronous would block Vertx worker threads
  • Risk: Architectural change that could cause request hangs
  • Recommendation: Keep AuthenticatedJsonRpcProcessor as safeguard; auth at handler level only is insufficient
    Phase 4: Context Object Proliferation - NOT NEEDED
    Proposed: Eliminate intermediate wrappers (RoutingContext → JsonRpcRequest → JsonRpcRequestContext)
    Findings:
  • Analysis shows these are NOT redundant conversions:
    • JsonRpcRequest = parsed request (required to invoke method)
    • JsonRpcRequestContext = enriched context (request + user + alive check)
  • Each wrapper serves a distinct purpose
  • Attempting to consolidate would complicate code without measurable benefit
    Checklist
  • Code follows the contribution guidelines
  • Tests pass — 86 JSON-RPC tests verified
  • Spotless applied — code formatted
  • Changelog updated — no entry required (pure refactor, no behavior change)
  • Documentation — no updates required (internal refactor, no API changes)
  • Database changes — none (pure in-memory RPC handler refactor)
  • Breaking changes — none
  • GPG signed commit — signed with key 37EB0026150B8BF2
    Test Results
    ./gradlew :ethereum:api:test # 86 tests PASSED
    Related Issues
  • Related to RPC Stack Refactor #9476 (RPC Stack Refactor #9476) (partial implementation)
    Future Work
    If further consolidation is desired:
  1. Phase 3a: Consider making AuthenticationHandler synchronous (requires async→sync refactor)
  2. Phase 3b: Move method-specific timeout logic from TimeoutHandler into JsonRpcExecutorHandler
  3. Alternative to Phase 4: Consider if any of the 151+ JsonRpcRequestContext usages could be simplified without reducing clarity

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests
  • hive tests: Engine or other RPCs modified?

marcosio added 9 commits April 2, 2026 00:11
…or classes

Collapses the RPC executor layer by inlining AbstractJsonRpcExecutor,
JsonRpcObjectExecutor, and JsonRpcArrayExecutor into JsonRpcExecutorHandler.
This is Phase 1 of the RPC Stack Refactor (issue besu-eth#9476), reducing
abstraction layers and preparing for future consolidation.
Changes:
- Inline executeSingleRequest() and executeBatchRequest() logic
- Preserve batch size validation, timeout handling, error responses
- Eliminate 3 classes (383 lines removed), net +195 lines in handler
- All 86 JSON-RPC tests pass

Signed-off-by: Marcos Serradilla Diez <marcos@io.builders>
Collapse Layer 5 processor chain by combining TimedJsonRpcProcessor,
TracedJsonRpcProcessor, and BaseJsonRpcProcessor into a single
CombinedJsonRpcProcessor.
This is Phase 2 of the RPC Stack Refactor (issue besu-eth#9476).
Changes:
- Create CombinedJsonRpcProcessor (timing + tracing + execution in one class)
- Delete TimedJsonRpcProcessor, TracedJsonRpcProcessor, BaseJsonRpcProcessor
- Update JsonRpcHttpService, EngineJsonRpcService, RunnerBuilder
- Update 8 test files to use CombinedJsonRpcProcessor
- Remove redundant requestTimer field (now managed inside CombinedJsonRpcProcessor)
- All 86 API tests pass

Signed-off-by: Marcos Serradilla Diez <marcos@io.builders>
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.

1 participant