@aztec-labs/sequencer-client 6.0.0-nightly.20260829

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +307 -0
  2. package/dest/client/index.d.ts +2 -0
  3. package/dest/client/index.d.ts.map +1 -0
  4. package/dest/client/index.js +1 -0
  5. package/dest/client/sequencer-client.d.ts +94 -0
  6. package/dest/client/sequencer-client.d.ts.map +1 -0
  7. package/dest/client/sequencer-client.js +177 -0
  8. package/dest/config.d.ts +56 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +251 -0
  11. package/dest/global_variable_builder/fee_predictor.d.ts +49 -0
  12. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_predictor.js +127 -0
  14. package/dest/global_variable_builder/fee_provider.d.ts +28 -0
  15. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  16. package/dest/global_variable_builder/fee_provider.js +87 -0
  17. package/dest/global_variable_builder/global_builder.d.ts +28 -0
  18. package/dest/global_variable_builder/global_builder.d.ts.map +1 -0
  19. package/dest/global_variable_builder/global_builder.js +40 -0
  20. package/dest/global_variable_builder/index.d.ts +4 -0
  21. package/dest/global_variable_builder/index.d.ts.map +1 -0
  22. package/dest/global_variable_builder/index.js +3 -0
  23. package/dest/index.d.ts +7 -0
  24. package/dest/index.d.ts.map +1 -0
  25. package/dest/index.js +8 -0
  26. package/dest/publisher/config.d.ts +68 -0
  27. package/dest/publisher/config.d.ts.map +1 -0
  28. package/dest/publisher/config.js +137 -0
  29. package/dest/publisher/index.d.ts +5 -0
  30. package/dest/publisher/index.d.ts.map +1 -0
  31. package/dest/publisher/index.js +4 -0
  32. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  33. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  34. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  35. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  36. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  37. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  38. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +101 -0
  39. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  40. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
  41. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  42. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  43. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
  44. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  45. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  46. package/dest/publisher/l1_tx_failed_store/index.js +3 -0
  47. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  48. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  49. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  50. package/dest/publisher/sequencer-publisher-factory.d.ts +50 -0
  51. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  52. package/dest/publisher/sequencer-publisher-factory.js +75 -0
  53. package/dest/publisher/sequencer-publisher-metrics.d.ts +26 -0
  54. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
  55. package/dest/publisher/sequencer-publisher-metrics.js +101 -0
  56. package/dest/publisher/sequencer-publisher.d.ts +254 -0
  57. package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
  58. package/dest/publisher/sequencer-publisher.js +1784 -0
  59. package/dest/publisher/write_json.d.ts +11 -0
  60. package/dest/publisher/write_json.d.ts.map +1 -0
  61. package/dest/publisher/write_json.js +57 -0
  62. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  63. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  64. package/dest/sequencer/automine/automine_factory.js +85 -0
  65. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  66. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  67. package/dest/sequencer/automine/automine_sequencer.js +732 -0
  68. package/dest/sequencer/automine/index.d.ts +3 -0
  69. package/dest/sequencer/automine/index.d.ts.map +1 -0
  70. package/dest/sequencer/automine/index.js +2 -0
  71. package/dest/sequencer/checkpoint_proposal_job.d.ts +169 -0
  72. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  73. package/dest/sequencer/checkpoint_proposal_job.js +1961 -0
  74. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  75. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  76. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  77. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  78. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  79. package/dest/sequencer/checkpoint_voter.js +106 -0
  80. package/dest/sequencer/config.d.ts +8 -0
  81. package/dest/sequencer/config.d.ts.map +1 -0
  82. package/dest/sequencer/config.js +1 -0
  83. package/dest/sequencer/errors.d.ts +11 -0
  84. package/dest/sequencer/errors.d.ts.map +1 -0
  85. package/dest/sequencer/errors.js +15 -0
  86. package/dest/sequencer/events.d.ts +103 -0
  87. package/dest/sequencer/events.d.ts.map +1 -0
  88. package/dest/sequencer/events.js +1 -0
  89. package/dest/sequencer/inbox_bucket_selector.d.ts +88 -0
  90. package/dest/sequencer/inbox_bucket_selector.d.ts.map +1 -0
  91. package/dest/sequencer/inbox_bucket_selector.js +80 -0
  92. package/dest/sequencer/index.d.ts +6 -0
  93. package/dest/sequencer/index.d.ts.map +1 -0
  94. package/dest/sequencer/index.js +5 -0
  95. package/dest/sequencer/metrics.d.ts +75 -0
  96. package/dest/sequencer/metrics.d.ts.map +1 -0
  97. package/dest/sequencer/metrics.js +343 -0
  98. package/dest/sequencer/missing_committee.d.ts +72 -0
  99. package/dest/sequencer/missing_committee.d.ts.map +1 -0
  100. package/dest/sequencer/missing_committee.js +139 -0
  101. package/dest/sequencer/requests_tracker.d.ts +22 -0
  102. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  103. package/dest/sequencer/requests_tracker.js +33 -0
  104. package/dest/sequencer/sequencer.d.ts +326 -0
  105. package/dest/sequencer/sequencer.d.ts.map +1 -0
  106. package/dest/sequencer/sequencer.js +1495 -0
  107. package/dest/sequencer/types.d.ts +3 -0
  108. package/dest/sequencer/types.d.ts.map +1 -0
  109. package/dest/sequencer/types.js +1 -0
  110. package/dest/sequencer/utils.d.ts +30 -0
  111. package/dest/sequencer/utils.d.ts.map +1 -0
  112. package/dest/sequencer/utils.js +18 -0
  113. package/dest/test/index.d.ts +23 -0
  114. package/dest/test/index.d.ts.map +1 -0
  115. package/dest/test/index.js +6 -0
  116. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  117. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  118. package/dest/test/mock_checkpoint_builder.js +230 -0
  119. package/dest/test/utils.d.ts +67 -0
  120. package/dest/test/utils.d.ts.map +1 -0
  121. package/dest/test/utils.js +121 -0
  122. package/package.json +118 -0
  123. package/src/client/index.ts +1 -0
  124. package/src/client/sequencer-client.ts +281 -0
  125. package/src/config.ts +309 -0
  126. package/src/global_variable_builder/README.md +44 -0
  127. package/src/global_variable_builder/fee_predictor.ts +176 -0
  128. package/src/global_variable_builder/fee_provider.ts +104 -0
  129. package/src/global_variable_builder/global_builder.ts +68 -0
  130. package/src/global_variable_builder/index.ts +3 -0
  131. package/src/index.ts +15 -0
  132. package/src/publisher/config.ts +220 -0
  133. package/src/publisher/index.ts +8 -0
  134. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  135. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  136. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +166 -0
  137. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
  138. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  139. package/src/publisher/sequencer-bundle-simulator.ts +253 -0
  140. package/src/publisher/sequencer-publisher-factory.ts +121 -0
  141. package/src/publisher/sequencer-publisher-metrics.ts +145 -0
  142. package/src/publisher/sequencer-publisher.ts +1719 -0
  143. package/src/publisher/write_json.ts +77 -0
  144. package/src/sequencer/README.md +243 -0
  145. package/src/sequencer/automine/README.md +60 -0
  146. package/src/sequencer/automine/automine_factory.ts +156 -0
  147. package/src/sequencer/automine/automine_sequencer.ts +841 -0
  148. package/src/sequencer/automine/index.ts +6 -0
  149. package/src/sequencer/checkpoint_proposal_job.ts +1889 -0
  150. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  151. package/src/sequencer/checkpoint_voter.ts +118 -0
  152. package/src/sequencer/config.ts +9 -0
  153. package/src/sequencer/errors.ts +21 -0
  154. package/src/sequencer/events.ts +93 -0
  155. package/src/sequencer/inbox_bucket_selector.ts +160 -0
  156. package/src/sequencer/index.ts +5 -0
  157. package/src/sequencer/metrics.ts +463 -0
  158. package/src/sequencer/missing_committee.ts +192 -0
  159. package/src/sequencer/requests_tracker.ts +43 -0
  160. package/src/sequencer/sequencer.ts +1401 -0
  161. package/src/sequencer/types.ts +6 -0
  162. package/src/sequencer/utils.ts +42 -0
  163. package/src/test/index.ts +26 -0
  164. package/src/test/mock_checkpoint_builder.ts +324 -0
  165. package/src/test/utils.ts +215 -0
@@ -0,0 +1,121 @@
1
+ import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec-labs/foundation/branded-types';
2
+ import { times } from '@aztec-labs/foundation/collection';
3
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
4
+ import { Signature } from '@aztec-labs/foundation/eth-signature';
5
+ import { PublicDataWrite } from '@aztec-labs/stdlib/avm';
6
+ import { Body, CommitteeAttestation, L2Block } from '@aztec-labs/stdlib/block';
7
+ import { DEFAULT_BLOCK_DURATION_MS } from '@aztec-labs/stdlib/config';
8
+ import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec-labs/stdlib/p2p';
9
+ import { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
10
+ import { TEST_COORDINATION_SIGNATURE_CONTEXT, makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec-labs/stdlib/testing';
11
+ import { DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME, DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME, DEFAULT_MIN_BLOCK_DURATION, DEFAULT_P2P_PROPAGATION_TIME, ProposerTimetable } from '@aztec-labs/stdlib/timetable';
12
+ import { BlockHeader, makeProcessedTxFromPrivateOnlyTx } from '@aztec-labs/stdlib/tx';
13
+ // Re-export mock classes from their dedicated file
14
+ export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
15
+ /**
16
+ * Builds a {@link ProposerTimetable} for tests from a millisecond block duration and optional budgets,
17
+ * filling unset budgets with the shared `DEFAULT_*` values the sequencer config layer applies. Mirrors how
18
+ * the sequencer constructs its timetable so tests exercise the same budget resolution.
19
+ */ export function makeProposerTimetable(opts) {
20
+ return new ProposerTimetable({
21
+ l1Constants: opts.l1Constants,
22
+ blockDuration: (opts.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
23
+ minBlockDuration: opts.minBlockDuration ?? DEFAULT_MIN_BLOCK_DURATION,
24
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
25
+ checkpointProposalPrepareTime: opts.checkpointProposalPrepareTime ?? DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
26
+ checkpointProposalInitTime: DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME
27
+ });
28
+ }
29
+ /**
30
+ * Creates a mock transaction with a specific seed for deterministic testing
31
+ */ export async function makeTx(seed, chainId) {
32
+ const tx = await mockTxForRollup(seed);
33
+ if (chainId) {
34
+ tx.data.constants.txContext.chainId = chainId;
35
+ }
36
+ return tx;
37
+ }
38
+ /**
39
+ * Creates an L2Block from transactions and global variables
40
+ */ export async function makeBlock(txs, globalVariables) {
41
+ const processedTxs = await Promise.all(txs.map((tx)=>makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables)));
42
+ const body = new Body(processedTxs.map((tx)=>tx.txEffect));
43
+ const header = BlockHeader.empty({
44
+ globalVariables
45
+ });
46
+ const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
47
+ return new L2Block(archive, header, body, CheckpointNumber.fromBlockNumber(globalVariables.blockNumber), IndexWithinCheckpoint(0));
48
+ }
49
+ /**
50
+ * Mocks the P2P client to return specific pending transactions
51
+ */ export function mockPendingTxs(p2p, txs) {
52
+ p2p.getPendingTxCount.mockResolvedValue(txs.length);
53
+ p2p.hasEligiblePendingTxs.mockImplementation((minCount)=>Promise.resolve(txs.length >= minCount));
54
+ p2p.iteratePendingTxs.mockImplementation(()=>mockTxIterator(Promise.resolve(txs)));
55
+ p2p.iterateEligiblePendingTxs.mockImplementation(()=>mockTxIterator(Promise.resolve(txs)));
56
+ }
57
+ /**
58
+ * Creates an async iterator for transactions
59
+ */ export async function* mockTxIterator(txs) {
60
+ for (const tx of (await txs)){
61
+ yield tx;
62
+ }
63
+ }
64
+ /**
65
+ * Creates mock committee attestations from a signer
66
+ */ export function createMockSignatures(signer) {
67
+ const mockedSig = Signature.random();
68
+ return [
69
+ new CommitteeAttestation(signer.address, mockedSig)
70
+ ];
71
+ }
72
+ /**
73
+ * Creates a CheckpointHeader from an L2Block for testing purposes.
74
+ * Uses mock values for blockHeadersHash and blobsHash since L2Block doesn't have these fields.
75
+ */ function createCheckpointHeaderFromBlock(block) {
76
+ const gv = block.header.globalVariables;
77
+ return new CheckpointHeader(block.header.lastArchive.root, Fr.random(), Fr.random(), Fr.random(), Fr.random(), gv.slotNumber, gv.timestamp, gv.coinbase, gv.feeRecipient, gv.gasFees, block.header.totalManaUsed, block.header.totalFees);
78
+ }
79
+ /**
80
+ * Creates a block proposal from a block and signature
81
+ */ export function createBlockProposal(block, signature) {
82
+ const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
83
+ return new BlockProposal(block.header, block.indexWithinCheckpoint, block.archive.root, txHashes, signature, TEST_COORDINATION_SIGNATURE_CONTEXT);
84
+ }
85
+ /**
86
+ * Creates a checkpoint proposal from a block and signature
87
+ */ export function createCheckpointProposal(block, checkpointSignature, blockSignature, feeAssetPriceModifier = 0n) {
88
+ const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
89
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
90
+ return new CheckpointProposal(checkpointHeader, block.archive.root, feeAssetPriceModifier, checkpointSignature, TEST_COORDINATION_SIGNATURE_CONTEXT, {
91
+ blockHeader: block.header,
92
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
93
+ txHashes,
94
+ signature: blockSignature ?? checkpointSignature
95
+ });
96
+ }
97
+ /**
98
+ * Creates a checkpoint attestation from a block and signature.
99
+ * Note: We manually set the sender since we use random signatures in tests.
100
+ * In production, the sender is recovered from the signature.
101
+ */ export function createCheckpointAttestation(block, signature, sender, feeAssetPriceModifier = 0n) {
102
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
103
+ const payload = new ConsensusPayload(checkpointHeader, block.archive.root, feeAssetPriceModifier, TEST_COORDINATION_SIGNATURE_CONTEXT);
104
+ const attestation = new CheckpointAttestation(payload, signature, signature);
105
+ // Bypass signature recovery for testing since we use random signatures
106
+ attestation.getSender = ()=>sender;
107
+ attestation.getProposer = ()=>sender;
108
+ return attestation;
109
+ }
110
+ /**
111
+ * Creates transactions and a block, and mocks P2P to return them.
112
+ * Helper for tests that need to set up a block with transactions.
113
+ */ export async function setupTxsAndBlock(p2p, globalVariables, txCount, chainId) {
114
+ const txs = await Promise.all(times(txCount, (i)=>makeTx(i + 1, chainId)));
115
+ const block = await makeBlock(txs, globalVariables);
116
+ mockPendingTxs(p2p, txs);
117
+ return {
118
+ txs,
119
+ block
120
+ };
121
+ }
package/package.json ADDED
@@ -0,0 +1,118 @@
1
+ {
2
+ "name": "@aztec-labs/sequencer-client",
3
+ "version": "6.0.0-nightly.20260829",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./dest/index.js",
7
+ "./automine": "./dest/sequencer/automine/index.js",
8
+ "./config": "./dest/config.js",
9
+ "./test": "./dest/test/index.js"
10
+ },
11
+ "typedocOptions": {
12
+ "entryPoints": [
13
+ "./src/index.ts"
14
+ ],
15
+ "name": "Sequencer Client",
16
+ "tsconfig": "./tsconfig.json"
17
+ },
18
+ "inherits": [
19
+ "../package.common.json"
20
+ ],
21
+ "scripts": {
22
+ "build": "yarn clean && ../scripts/tsc.sh",
23
+ "build:dev": "../scripts/tsc.sh --watch",
24
+ "clean": "rm -rf ./dest .tsbuildinfo",
25
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
26
+ "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"",
27
+ "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --config jest.integration.config.json"
28
+ },
29
+ "dependencies": {
30
+ "@aztec-labs/archiver": "6.0.0-nightly.20260829",
31
+ "@aztec-labs/blob-client": "6.0.0-nightly.20260829",
32
+ "@aztec-labs/blob-lib": "6.0.0-nightly.20260829",
33
+ "@aztec-labs/constants": "6.0.0-nightly.20260829",
34
+ "@aztec-labs/epoch-cache": "6.0.0-nightly.20260829",
35
+ "@aztec-labs/ethereum": "6.0.0-nightly.20260829",
36
+ "@aztec-labs/foundation": "6.0.0-nightly.20260829",
37
+ "@aztec-labs/node-keystore": "6.0.0-nightly.20260829",
38
+ "@aztec-labs/p2p": "6.0.0-nightly.20260829",
39
+ "@aztec-labs/prover-client": "6.0.0-nightly.20260829",
40
+ "@aztec-labs/simulator": "6.0.0-nightly.20260829",
41
+ "@aztec-labs/slasher": "6.0.0-nightly.20260829",
42
+ "@aztec-labs/stdlib": "6.0.0-nightly.20260829",
43
+ "@aztec-labs/telemetry-client": "6.0.0-nightly.20260829",
44
+ "@aztec-labs/validator-client": "6.0.0-nightly.20260829",
45
+ "@aztec-labs/validator-ha-signer": "6.0.0-nightly.20260829",
46
+ "@aztec/l1-artifacts": "6.0.0-nightly.20260826",
47
+ "lodash.chunk": "^4.2.0",
48
+ "tslib": "^2.4.0",
49
+ "viem": "npm:@aztec/viem@2.38.2",
50
+ "zod": "^4"
51
+ },
52
+ "devDependencies": {
53
+ "@aztec-labs/noir-protocol-circuits-types": "6.0.0-nightly.20260829",
54
+ "@aztec-labs/protocol-contracts": "6.0.0-nightly.20260829",
55
+ "@aztec-labs/world-state": "6.0.0-nightly.20260829",
56
+ "@electric-sql/pglite": "^0.3.14",
57
+ "@jest/globals": "^30.0.0",
58
+ "@types/jest": "^30.0.0",
59
+ "@types/lodash.chunk": "^4.2.7",
60
+ "@types/lodash.pick": "^4.4.7",
61
+ "@types/node": "^22.15.17",
62
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
63
+ "concurrently": "^7.6.0",
64
+ "eslint": "^9.26.0",
65
+ "express": "^4.21.2",
66
+ "jest": "^30.0.0",
67
+ "jest-mock-extended": "^4.0.0",
68
+ "prettier": "^3.5.3",
69
+ "ts-node": "^10.9.1",
70
+ "typescript": "^5.3.3"
71
+ },
72
+ "files": [
73
+ "dest",
74
+ "src",
75
+ "!*.test.*"
76
+ ],
77
+ "types": "./dest/index.d.ts",
78
+ "engines": {
79
+ "node": ">=20.10"
80
+ },
81
+ "jest": {
82
+ "extensionsToTreatAsEsm": [
83
+ ".ts"
84
+ ],
85
+ "transform": {
86
+ "^.+\\.tsx?$": [
87
+ "@swc/jest",
88
+ {
89
+ "jsc": {
90
+ "parser": {
91
+ "syntax": "typescript",
92
+ "decorators": true
93
+ },
94
+ "transform": {
95
+ "decoratorVersion": "2022-03"
96
+ }
97
+ }
98
+ }
99
+ ]
100
+ },
101
+ "moduleNameMapper": {
102
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
103
+ },
104
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
105
+ "rootDir": "./src",
106
+ "reporters": [
107
+ "default"
108
+ ],
109
+ "testTimeout": 120000,
110
+ "setupFiles": [
111
+ "../../foundation/src/jest/setup.mjs"
112
+ ],
113
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
114
+ "setupFilesAfterEnv": [
115
+ "../../foundation/src/jest/setupAfterEnv.mjs"
116
+ ]
117
+ }
118
+ }
@@ -0,0 +1 @@
1
+ export * from './sequencer-client.js';
@@ -0,0 +1,281 @@
1
+ import type { BlobClientInterface } from '@aztec-labs/blob-client/client';
2
+ import { MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec-labs/constants';
3
+ import { EpochCache } from '@aztec-labs/epoch-cache';
4
+ import { getPublicClient } from '@aztec-labs/ethereum/client';
5
+ import { GovernanceProposerContract, RollupContract } from '@aztec-labs/ethereum/contracts';
6
+ import { type Delayer, L1TxUtils } from '@aztec-labs/ethereum/l1-tx-utils';
7
+ import { PublisherManager } from '@aztec-labs/ethereum/publisher-manager';
8
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
9
+ import { createLogger } from '@aztec-labs/foundation/log';
10
+ import type { DateProvider } from '@aztec-labs/foundation/timer';
11
+ import type { KeystoreManager } from '@aztec-labs/node-keystore';
12
+ import type { P2P } from '@aztec-labs/p2p';
13
+ import type { SlasherClientInterface } from '@aztec-labs/slasher';
14
+ import type { L2BlockSink, L2BlockSource, ProposedCheckpointSink } from '@aztec-labs/stdlib/block';
15
+ import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec-labs/stdlib/interfaces/server';
16
+ import type { L1ToL2MessageSource } from '@aztec-labs/stdlib/messaging';
17
+ import { L1Metrics, type TelemetryClient } from '@aztec-labs/telemetry-client';
18
+ import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec-labs/validator-client';
19
+
20
+ import { type SequencerClientConfig, getPublisherConfigFromSequencerConfig } from '../config.js';
21
+ import type { GlobalVariableBuilder } from '../global_variable_builder/index.js';
22
+ import { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
23
+ import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
24
+
25
+ /**
26
+ * Encapsulates the full sequencer and publisher.
27
+ */
28
+ export class SequencerClient {
29
+ constructor(
30
+ protected publisherManager: PublisherManager<L1TxUtils>,
31
+ protected sequencer: Sequencer,
32
+ protected checkpointsBuilder: FullNodeCheckpointsBuilder,
33
+ protected validatorClient?: ValidatorClient,
34
+ private l1Metrics?: L1Metrics,
35
+ private delayer_?: Delayer,
36
+ ) {}
37
+
38
+ /**
39
+ * Initializes a new instance.
40
+ * @param config - Configuration for the sequencer, publisher, and L1 tx sender.
41
+ * @param p2pClient - P2P client that provides the txs to be sequenced.
42
+ * @param validatorClient - Validator client performs attestation duties when rotating proposers.
43
+ * @param worldStateSynchronizer - Provides access to world state.
44
+ * @param contractDataSource - Provides access to contract bytecode for public executions.
45
+ * @param l2BlockSource - Provides information about the previously published blocks.
46
+ * @param l1ToL2MessageSource - Provides access to L1 to L2 messages.
47
+ * @param prover - An instance of a block prover
48
+ * @returns A new running instance.
49
+ */
50
+ public static async new(
51
+ config: SequencerClientConfig,
52
+ deps: {
53
+ validatorClient: ValidatorClient;
54
+ p2pClient: P2P;
55
+ worldStateSynchronizer: WorldStateSynchronizer;
56
+ slasherClient: SlasherClientInterface | undefined;
57
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
58
+ l2BlockSource: L2BlockSource & L2BlockSink & ProposedCheckpointSink;
59
+ l1ToL2MessageSource: L1ToL2MessageSource;
60
+ telemetry: TelemetryClient;
61
+ publisherFactory?: SequencerPublisherFactory;
62
+ blobClient: BlobClientInterface;
63
+ dateProvider: DateProvider;
64
+ epochCache?: EpochCache;
65
+ l1TxUtils: L1TxUtils[];
66
+ funderL1TxUtils?: L1TxUtils;
67
+ nodeKeyStore: KeystoreManager;
68
+ globalVariableBuilder: GlobalVariableBuilder;
69
+ },
70
+ ) {
71
+ const {
72
+ validatorClient,
73
+ p2pClient,
74
+ worldStateSynchronizer,
75
+ slasherClient,
76
+ checkpointsBuilder,
77
+ l2BlockSource,
78
+ l1ToL2MessageSource,
79
+ telemetry: telemetryClient,
80
+ } = deps;
81
+ const { l1RpcUrls: rpcUrls, l1ChainId: chainId } = config;
82
+ const log = createLogger('sequencer');
83
+ const publicClient = getPublicClient(config);
84
+ const l1TxUtils = deps.l1TxUtils;
85
+ const l1Metrics = new L1Metrics(
86
+ telemetryClient.getMeter('L1PublisherMetrics'),
87
+ publicClient,
88
+ l1TxUtils.map(x => x.getSenderAddress()),
89
+ );
90
+ const publisherManager = new PublisherManager(l1TxUtils, getPublisherConfigFromSequencerConfig(config), {
91
+ bindings: log.getBindings(),
92
+ funder: deps.funderL1TxUtils,
93
+ });
94
+ const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
95
+ const [l1GenesisTime, slotDuration, rollupManaLimit] = await Promise.all([
96
+ rollupContract.getL1GenesisTime(),
97
+ rollupContract.getSlotDuration(),
98
+ rollupContract.getManaLimit().then(Number),
99
+ ] as const);
100
+
101
+ const governanceProposerContract = new GovernanceProposerContract(
102
+ publicClient,
103
+ config.governanceProposerAddress.toString(),
104
+ );
105
+ const epochCache =
106
+ deps.epochCache ??
107
+ (await EpochCache.create(
108
+ config.rollupAddress,
109
+ {
110
+ l1RpcUrls: rpcUrls,
111
+ l1ChainId: chainId,
112
+ viemPollingIntervalMS: config.viemPollingIntervalMS,
113
+ ethereumSlotDuration: config.ethereumSlotDuration,
114
+ },
115
+ { dateProvider: deps.dateProvider },
116
+ ));
117
+
118
+ const publisherFactory =
119
+ deps.publisherFactory ??
120
+ new SequencerPublisherFactory(config, {
121
+ telemetry: telemetryClient,
122
+ blobClient: deps.blobClient,
123
+ epochCache,
124
+ governanceProposerContract,
125
+ rollupContract,
126
+ dateProvider: deps.dateProvider,
127
+ publisherManager,
128
+ nodeKeyStore: NodeKeystoreAdapter.fromKeyStoreManager(deps.nodeKeyStore),
129
+ logger: log,
130
+ });
131
+
132
+ const ethereumSlotDuration = config.ethereumSlotDuration;
133
+
134
+ const globalsBuilder = deps.globalVariableBuilder;
135
+
136
+ const { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock } = capPerBlockLimits(config, rollupManaLimit, log);
137
+
138
+ const l1Constants = {
139
+ l1GenesisTime,
140
+ slotDuration: Number(slotDuration),
141
+ ethereumSlotDuration,
142
+ rollupManaLimit,
143
+ epochDuration: config.aztecEpochDuration,
144
+ };
145
+
146
+ const sequencer = new Sequencer(
147
+ publisherFactory,
148
+ validatorClient,
149
+ globalsBuilder,
150
+ p2pClient,
151
+ worldStateSynchronizer,
152
+ slasherClient,
153
+ l2BlockSource,
154
+ l1ToL2MessageSource,
155
+ checkpointsBuilder,
156
+ l1Constants,
157
+ deps.dateProvider,
158
+ epochCache,
159
+ rollupContract,
160
+ { ...config, maxL2BlockGas, maxDABlockGas, maxTxsPerBlock },
161
+ telemetryClient,
162
+ log,
163
+ );
164
+
165
+ sequencer.init();
166
+
167
+ // Extract the shared delayer from the first L1TxUtils instance (all instances share the same delayer)
168
+ const delayer = l1TxUtils[0]?.delayer;
169
+
170
+ return new SequencerClient(publisherManager, sequencer, checkpointsBuilder, validatorClient, l1Metrics, delayer);
171
+ }
172
+
173
+ /**
174
+ * Updates sequencer and validator client config.
175
+ * @param config - New parameters.
176
+ */
177
+ public updateConfig(config: SequencerConfig & Partial<ValidatorClientFullConfig>) {
178
+ this.sequencer.updateConfig(config);
179
+ this.checkpointsBuilder.updateConfig(config);
180
+ this.validatorClient?.updateConfig(config);
181
+ }
182
+
183
+ /**
184
+ * Starts (or resumes) the sequencer, validator, publishers, and metrics. Each underlying start is
185
+ * idempotent, so this is safe to call after a previous {@link pause} to resume building and publishing.
186
+ * The publisher manager is started before the sequencer's poll loop so publishing is ready before the
187
+ * sequencer first tries to publish to L1.
188
+ */
189
+ public async start() {
190
+ await this.validatorClient?.start();
191
+ await this.publisherManager.start();
192
+ this.sequencer.start();
193
+ this.l1Metrics?.start();
194
+ }
195
+
196
+ /**
197
+ * Stops the sequencer, validator, publishers, and metrics for good, draining in-flight work. This is the
198
+ * final teardown path: stopping the validator client closes its slashing-protection database. For a
199
+ * restartable pause (e.g. around a test clock warp) use {@link pause} instead.
200
+ */
201
+ public async stop() {
202
+ await this.sequencer.stop();
203
+ await this.validatorClient?.stop();
204
+ await this.publisherManager.stop();
205
+ this.l1Metrics?.stop();
206
+ }
207
+
208
+ /**
209
+ * Gracefully pauses block production, waiting for in-flight work to finish rather than interrupting it,
210
+ * while leaving the validator, publishers, and metrics running so the sequencer can be resumed with
211
+ * {@link start}. Used by tests that pause sequencers around an L1 clock warp.
212
+ */
213
+ public async pause() {
214
+ await this.sequencer.pause();
215
+ }
216
+
217
+ /** Triggers an immediate run of the sequencer, bypassing the polling interval. */
218
+ public trigger() {
219
+ return this.sequencer.trigger();
220
+ }
221
+
222
+ public getSequencer(): Sequencer {
223
+ return this.sequencer;
224
+ }
225
+
226
+ /** Updates the publisher factory's node keystore adapter after a keystore reload. */
227
+ public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
228
+ this.sequencer.updatePublisherNodeKeyStore(adapter);
229
+ }
230
+
231
+ /** Returns the shared tx delayer for sequencer L1 txs, if enabled. Test-only. */
232
+ getDelayer(): Delayer | undefined {
233
+ return this.delayer_;
234
+ }
235
+
236
+ get validatorAddresses(): EthAddress[] | undefined {
237
+ return this.sequencer.getValidatorAddresses();
238
+ }
239
+
240
+ get maxL2BlockGas(): number | undefined {
241
+ return this.sequencer.maxL2BlockGas;
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Caps operator-provided per-block limits at checkpoint-level limits.
247
+ * Returns undefined for any limit the operator didn't set — the checkpoint builder handles redistribution.
248
+ */
249
+ function capPerBlockLimits(
250
+ config: SequencerClientConfig,
251
+ rollupManaLimit: number,
252
+ log: ReturnType<typeof createLogger>,
253
+ ): { maxL2BlockGas: number | undefined; maxDABlockGas: number | undefined; maxTxsPerBlock: number | undefined } {
254
+ let maxL2BlockGas = config.maxL2BlockGas;
255
+ if (maxL2BlockGas !== undefined && maxL2BlockGas > rollupManaLimit) {
256
+ log.warn(`Provided MAX_L2_BLOCK_GAS ${maxL2BlockGas} exceeds rollup mana limit ${rollupManaLimit} (capping)`);
257
+ maxL2BlockGas = rollupManaLimit;
258
+ }
259
+
260
+ let maxDABlockGas = config.maxDABlockGas;
261
+ if (maxDABlockGas !== undefined && maxDABlockGas > MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT) {
262
+ log.warn(
263
+ `Provided MAX_DA_BLOCK_GAS ${maxDABlockGas} exceeds DA checkpoint limit ${MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT} (capping)`,
264
+ );
265
+ maxDABlockGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
266
+ }
267
+
268
+ let maxTxsPerBlock = config.maxTxsPerBlock;
269
+ if (
270
+ maxTxsPerBlock !== undefined &&
271
+ config.maxTxsPerCheckpoint !== undefined &&
272
+ maxTxsPerBlock > config.maxTxsPerCheckpoint
273
+ ) {
274
+ log.warn(
275
+ `Provided MAX_TX_PER_BLOCK ${maxTxsPerBlock} exceeds MAX_TX_PER_CHECKPOINT ${config.maxTxsPerCheckpoint} (capping)`,
276
+ );
277
+ maxTxsPerBlock = config.maxTxsPerCheckpoint;
278
+ }
279
+
280
+ return { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock };
281
+ }