refactor(aztec-node): split server.ts into factory + focused modules - #24283
Merged
Conversation
…vice factory Move the ~580-line `AztecNodeService.createAndSync` static method (and its `checkConfigMatchesRollup` helper) out of `server.ts` into a new `factory.ts` as a free function `createAztecNodeService`, mirroring the `createProverNode` / `createValidatorClient` factories in other subsystems. Convert the `AztecNodeService` constructor from ~28 positional parameters to a single `AztecNodeServiceDeps` object so call sites name each dependency. This surfaced a latent bug in the TXE state machine, which passed `VERSION` and `CHAIN_ID` into the `l1ChainId` and `version` slots in the wrong order (both happened to be `1`); the named object fixes it. Update all `createAndSync` call sites (node bin, local-network, e2e fixtures) and the direct constructor call in the TXE state machine. `server.ts` drops ~590 lines and a large set of now-unused imports.
…module Move the node's Merkle-tree and membership-witness queries (findLeavesIndexes, the note-hash / block-hash / L1-to-L2 / nullifier / low-nullifier witnesses, getPublicDataWitness, getPublicStorageAt, getL2ToL1Messages, getL2ToL1MembershipWitness, getL1ToL2MessageCheckpoint) together with the block-resolution and reorg-aware sync engine (getWorldState, resolveBlockNumber, syncWorldState) into a new `NodeWorldStateQueries` collaborator under `src/modules/`. `AztecNodeService` keeps thin delegating methods (mirroring `nodePublicCallsSimulator`), so the public and RPC surface is unchanged. `getWorldState` remains as a protected delegate so subclasses and tests can still exercise the node's sync behavior. `normalizeBlockParameter` is injected into the module for now; a follow-up extracts it as a free function.
Move normalizeBlockParameter, isBlockTag, isCheckpointTag, and resolveCheckpointParameter out of `AztecNodeService` into `src/modules/block_parameter.ts` as pure free functions (resolveCheckpointParameter takes the block source as an argument for its tip lookups). `NodeWorldStateQueries` now imports `normalizeBlockParameter` directly instead of receiving it as an injected dependency, and `AztecNodeService` calls the free functions from its remaining block/checkpoint read methods.
…der module Move getBlock, getBlockData, getBlocks, getCheckpoint, getCheckpoints and their private checkpoint-context helpers into a new `NodeBlockProvider` collaborator under `src/modules/`, built over the block source. The provider owns the response assembly (block_response_helpers) and the block/checkpoint parameter normalization; `AztecNodeService` keeps thin delegating methods so the public and RPC surface is unchanged.
Move getTxReceipt and its private helpers (assembleMinedReceipt, deriveMinedStatus) into a new `NodeTxReceiptBuilder` collaborator under `src/modules/`, built over the tx pool, block source, and debug log store. `AztecNodeService` keeps a thin delegating getTxReceipt. server.ts is now ~860 lines, down from ~2140 at the start of this refactor.
spalladino
force-pushed
the
spl/refactor-server-ts
branch
from
June 25, 2026 14:32
3d8125e to
e834ed7
Compare
alexghr
approved these changes
Jun 25, 2026
Collaborator
Flakey Tests🤖 says: This CI run detected 2 tests that failed, but were tolerated due to a .test_patterns.yml entry. |
spalladino
added a commit
that referenced
this pull request
Jun 25, 2026
…NodeTestContext The upstream refactor (#24283) replaced AztecNodeService.createAndSync with the new createAztecNodeService factory in epochs_test.ts (the source that SingleNodeTestContext was extracted from in this PR). Port the same rename to the relocated file.
AztecBot
added a commit
that referenced
this pull request
Jun 26, 2026
merge-train/spartan-v5 has landed in v5-next and auto-pulled into this train. Its server.ts refactor (#24283) rewrote the imports and dropped inspectBlockParameter, but this train's getContract change (#24207) still calls it in the reference-block-not-found error, so the merged server.ts references an unimported symbol and the yarn-project build fails. Re-add inspectBlockParameter to the existing @aztec/stdlib/block import.
spalladino
added a commit
that referenced
this pull request
Jun 26, 2026
…NodeTestContext The upstream refactor (#24283) replaced AztecNodeService.createAndSync with the new createAztecNodeService factory in epochs_test.ts (the source that SingleNodeTestContext was extracted from in this PR). Port the same rename to the relocated file.
mverzilli
added a commit
that referenced
this pull request
Jun 26, 2026
## Why `merge-train/spartan-v5` ([#24272](#24272)) has landed in `v5-next` and been auto-pulled into this train (merge commit `34209c32`), so the cross-train build break is now live on the `merge-train/fairies-v5` tip itself — `yarn-project` no longer compiles (`make: *** [Makefile:359: yarn-project] Error 1`, in `compile_all`). ## Root cause In `aztec-node/src/aztec-node/server.ts`: - spartan-v5's [#24283](#24283) (`split server.ts into factory + focused modules`) rewrote the imports and dropped `inspectBlockParameter` — its own uses moved into `modules/node_world_state_queries.ts`, which imports it correctly. - This train's [#24207](#24207) (`make node.getContract take an optional reference block`) still calls `inspectBlockParameter(referenceBlock)` in `getContract`'s reference-block-not-found error. The auto-merge took spartan-v5's import block, leaving `getContract` referencing an unimported symbol → `Cannot find name 'inspectBlockParameter'`. ## Fix Re-add `inspectBlockParameter` to the existing `@aztec/stdlib/block` import in `server.ts` (it is the only remaining consumer there, and the symbol is still exported from that module). One-line change; the error message is unchanged. Since the train tip already contains spartan-v5's refactor, this PR's own CI now builds the actual merged tree, so it verifies the fix directly. Refs [#24223](#24223), [#24207](#24207), [#24283](#24283).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
aztec-node/src/aztec-node/server.tshad grown to ~2100 lines, mixing node construction, world-state/witness queries, block and checkpoint reads, and tx-receipt assembly into one file. This follows the recentNodePublicCallsSimulatorextraction to keep the file navigable.Approach
AztecNodeServicekeeps its public and RPC surface unchanged — every extracted method now delegates to a focused collaborator. The work is split into five self-contained, individually-buildable commits:createAndSyncto a freecreateAztecNodeServicefactory infactory.ts(mirrorscreateProverNode), and convert the ~28-positional constructor to a singleAztecNodeServiceDepsobject.modules/node_world_state_queries.ts.normalizeBlockParameter/isBlockTag/isCheckpointTag/resolveCheckpointParameterblock-parameter helpers as pure free functions inmodules/block_parameter.ts.modules/node_block_provider.ts.getTxReceiptand receipt assembly intomodules/node_tx_receipt.ts.The deps-object constructor also surfaced a latent bug in the TXE state machine, which was passing
VERSION/CHAIN_IDinto thel1ChainId/versionslots swapped (harmless until now since both were1); fixed here.