Skip to content

refactor(aztec-node): split server.ts into factory + focused modules - #24283

Merged
spalladino merged 5 commits into
merge-train/spartan-v5from
spl/refactor-server-ts
Jun 25, 2026
Merged

refactor(aztec-node): split server.ts into factory + focused modules#24283
spalladino merged 5 commits into
merge-train/spartan-v5from
spl/refactor-server-ts

Conversation

@spalladino

@spalladino spalladino commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Context

aztec-node/src/aztec-node/server.ts had 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 recent NodePublicCallsSimulator extraction to keep the file navigable.

Approach

AztecNodeService keeps 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:

  • Move createAndSync to a free createAztecNodeService factory in factory.ts (mirrors createProverNode), and convert the ~28-positional constructor to a single AztecNodeServiceDeps object.
  • Extract the world-state/witness query cluster into modules/node_world_state_queries.ts.
  • Extract the normalizeBlockParameter/isBlockTag/isCheckpointTag/resolveCheckpointParameter block-parameter helpers as pure free functions in modules/block_parameter.ts.
  • Extract block and checkpoint reads into modules/node_block_provider.ts.
  • Extract getTxReceipt and receipt assembly into modules/node_tx_receipt.ts.

The deps-object constructor also surfaced a latent bug in the TXE state machine, which was passing VERSION/CHAIN_ID into the l1ChainId/version slots swapped (harmless until now since both were 1); fixed here.

…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
spalladino force-pushed the spl/refactor-server-ts branch from 3d8125e to e834ed7 Compare June 25, 2026 14:32
@AztecBot

Copy link
Copy Markdown
Collaborator

Flakey Tests

🤖 says: This CI run detected 2 tests that failed, but were tolerated due to a .test_patterns.yml entry.

\033FLAKED\033 (8;;http://ci.aztec-labs.com/a8d5f346e269c668�a8d5f346e269c6688;;�):  yarn-project/end-to-end/scripts/run_test.sh simple src/e2e_epochs/epochs_optimistic_proving.parallel.test.ts "handles a reorg arriving while the top of the epoch is proving" (244s) (code: 0) group:e2e-p2p-epoch-flakes
\033FLAKED\033 (8;;http://ci.aztec-labs.com/7d8ad07c73ce84e2�7d8ad07c73ce84e28;;�):  yarn-project/end-to-end/scripts/run_test.sh simple src/e2e_offchain_payment.test.ts (72s) (code: 0)

@spalladino
spalladino merged commit 826ab3c into merge-train/spartan-v5 Jun 25, 2026
15 checks passed
@spalladino
spalladino deleted the spl/refactor-server-ts branch June 25, 2026 15:38
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).
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.

3 participants