-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Problem
The node currently hardcodes a single worker per validator (worker_id = 0). The EpochManager, network layer, and several initialization paths assume exactly one worker. This blocks the ability to run independent fee markets, specialized transaction pools, or any form of worker-level parallelism.
Goal
Refactor the node to support N independent workers per validator. Each worker operates as a standalone unit with its own:
- libp2p swarm (dedicated gossip topics, listen address, network key)
- RPC server (unique port)
- Transaction pool
- Batch builder + batch validator
LocalNetworkinstance for primary communication
Workers share only the Primary (consensus) and the execution engine (block production). The num_workers count is a consensus-level parameter — all validators must agree on it.
Why
The immediate motivation is multiple fee markets. Once multi-worker is in place, a follow-up (Phase 2) spawns 2 workers by default:
- Worker 0 (General): accepts all transactions, standard EIP-1559 fee market
- Worker 1 (Whitelisted Transfers): accepts only whitelisted ERC-20
transfer/transferFromcalls, operates with a reduced base fee
This architecture also enables future process separation — workers can be extracted into standalone processes communicating with the primary over RPC.
Design Constraints
- Workers are fully independent — no cross-worker shared state. Each worker has its own network identity, pool, and gossip topics.
- Per-worker gossip topics —
tn-worker-{id}andtn-txn-{id}replace the current globaltn-workerandtn-txntopics. This provides network-level isolation. - Per-worker
LocalNetwork— each worker gets its ownLocalNetworkinstance for primary communication. The primary registers as the handler on every worker'sLocalNetwork. This is the seam for future process separation. num_workersis a consensus parameter — changing it requires a coordinated upgrade across all validators. Defaults to1for backward compatibility.- Execution engine is shared — batches from all workers are processed sequentially by the same engine. Worker ID is already encoded in the block
difficultyfield. - Faucet on worker 0 only — the testnet faucet attaches to the general-purpose worker.
Current State
Much of the infrastructure already supports N workers but is only called with worker_id = 0:
ExecutionNodeInner.workers: Vec<WorkerComponents>— vec exists, only 1 elementGasAccumulator— supports N workers internally, but initialized withnew(1)BatchValidator— already storesworker_idand rejects mismatched batchesadjust_base_fees()— loops overnum_workers()but is a no-op- Block
difficultyfield — already encodesbatch_index << 16 | worker_id
Hardcoded locations that block multi-worker:
| Location | Current | Fix |
|---|---|---|
manager.rs spawn_worker_node_components() |
let worker_id = 0; |
Loop over 0..num_workers |
manager.rs GasAccumulator::new(1) |
Hardcoded 1 worker | Use num_workers |
manager.rs catchup_accumulator() |
gas_accumulator.base_fee(0) |
Restore per-worker base fees |
manager.rs EpochManager struct |
Singular worker_network_handle |
Vec<WorkerNetworkHandle> |
manager.rs create_consensus() |
Returns (PrimaryNode, WorkerNode) |
Returns (PrimaryNode, Vec<WorkerNode>) |
config/genesis.rs NodeP2pInfo |
Single worker: NetworkInfo |
workers: Vec<NetworkInfo> |
config/node.rs Parameters |
No num_workers field |
Add num_workers: u16 (default 1) |
config/network.rs |
Global topics tn-worker, tn-txn |
Per-worker tn-worker-{id}, tn-txn-{id} |
config/consensus.rs |
Single LocalNetwork |
Vec<LocalNetwork> |
This PR: Tests
Update existing tests that hardcode worker_id = 0 and add new multi-worker integration tests that verify N workers operate independently.
Scope
Update existing test fixtures:
| File | What to update |
|---|---|
crates/node/tests/it/main.rs (lines 142, 309, 438) |
Batch construction with worker_id: 0 — parameterize or test multiple worker_ids |
crates/consensus/primary/src/tests/proposer_tests.rs (lines 65, 112) |
Proposer tests with worker_id: 0 in header payloads — ensure proposer handles digests from multiple workers |
crates/consensus/worker/tests/it/network_tests.rs (line 41) |
Worker network tests — test per-worker topic subscriptions and message isolation |
crates/execution/faucet/tests/it/faucet.rs (lines 296, 646) |
Faucet tests with hardcoded worker_id — verify faucet only attaches to worker 0 |
crates/batch-validator/src/validator.rs (lines 279, 302) |
Batch validator tests — add test for cross-worker batch rejection (worker 1 batch sent to worker 0 validator) |
Update test-utils-committee builder:
crates/test-utils-committee/src/builder.rs— generate per-worker network info (multiple addresses + keys per validator)
New multi-worker integration test:
- Spawn a test environment with 2+ workers per validator
- Verify batches from different workers are independently validated
- Verify execution correctly attributes blocks to the right worker (check
difficultyfield) - Verify per-worker gas accumulation
- Verify per-worker base fee isolation
- Verify cross-worker batch rejection (worker 1 batch rejected by worker 0's validator)
blocked by #554 #555 #556 #557 #558
- Can be developed in parallel with PRs 2-5 against the configuration changes from PR 1