@aztec/sequencer-client 0.0.1-commit.f295ac2 → 0.0.1-commit.f8ca9b2f3

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 (41) hide show
  1. package/dest/client/sequencer-client.js +1 -1
  2. package/dest/config.d.ts +1 -2
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +5 -11
  5. package/dest/global_variable_builder/global_builder.js +2 -2
  6. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  7. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  8. package/dest/publisher/sequencer-publisher-metrics.js +12 -4
  9. package/dest/publisher/sequencer-publisher.d.ts +1 -2
  10. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  11. package/dest/publisher/sequencer-publisher.js +39 -18
  12. package/dest/sequencer/checkpoint_proposal_job.d.ts +32 -9
  13. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  14. package/dest/sequencer/checkpoint_proposal_job.js +87 -51
  15. package/dest/sequencer/metrics.d.ts +2 -2
  16. package/dest/sequencer/metrics.d.ts.map +1 -1
  17. package/dest/sequencer/metrics.js +27 -17
  18. package/dest/sequencer/sequencer.d.ts +5 -3
  19. package/dest/sequencer/sequencer.d.ts.map +1 -1
  20. package/dest/sequencer/sequencer.js +8 -3
  21. package/dest/sequencer/timetable.d.ts +1 -4
  22. package/dest/sequencer/timetable.d.ts.map +1 -1
  23. package/dest/sequencer/timetable.js +1 -4
  24. package/dest/test/mock_checkpoint_builder.d.ts +11 -8
  25. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  26. package/dest/test/mock_checkpoint_builder.js +18 -6
  27. package/dest/test/utils.d.ts +8 -8
  28. package/dest/test/utils.d.ts.map +1 -1
  29. package/dest/test/utils.js +5 -5
  30. package/package.json +28 -28
  31. package/src/client/sequencer-client.ts +1 -1
  32. package/src/config.ts +10 -14
  33. package/src/global_variable_builder/global_builder.ts +2 -2
  34. package/src/publisher/sequencer-publisher-metrics.ts +7 -3
  35. package/src/publisher/sequencer-publisher.ts +34 -18
  36. package/src/sequencer/checkpoint_proposal_job.ts +118 -77
  37. package/src/sequencer/metrics.ts +36 -18
  38. package/src/sequencer/sequencer.ts +12 -5
  39. package/src/sequencer/timetable.ts +6 -5
  40. package/src/test/mock_checkpoint_builder.ts +32 -18
  41. package/src/test/utils.ts +17 -11
@@ -1,11 +1,9 @@
1
1
  import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { Timer } from '@aztec/foundation/timer';
4
- import { L2BlockNew } from '@aztec/stdlib/block';
3
+ import { L2Block } from '@aztec/stdlib/block';
5
4
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
6
5
  import { Gas } from '@aztec/stdlib/gas';
7
6
  import type {
8
- BuildBlockInCheckpointResult,
9
7
  FullNodeBlockBuilderConfig,
10
8
  ICheckpointBlockBuilder,
11
9
  ICheckpointsBuilder,
@@ -15,19 +13,20 @@ import type {
15
13
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
16
14
  import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
17
15
  import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
16
+ import type { BuildBlockInCheckpointResult } from '@aztec/validator-client';
18
17
 
19
18
  /**
20
19
  * A fake CheckpointBuilder for testing that implements the same interface as the real one.
21
20
  * Can be seeded with blocks to return sequentially on each `buildBlock` call.
22
21
  */
23
22
  export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
24
- private blocks: L2BlockNew[] = [];
25
- private builtBlocks: L2BlockNew[] = [];
23
+ private blocks: L2Block[] = [];
24
+ private builtBlocks: L2Block[] = [];
26
25
  private usedTxsPerBlock: Tx[][] = [];
27
26
  private blockIndex = 0;
28
27
 
29
28
  /** Optional function to dynamically provide the block (alternative to seedBlocks) */
30
- private blockProvider: (() => L2BlockNew) | undefined = undefined;
29
+ private blockProvider: (() => L2Block) | undefined = undefined;
31
30
 
32
31
  /** Track calls for assertions */
33
32
  public buildBlockCalls: Array<{
@@ -35,6 +34,8 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
35
34
  timestamp: bigint;
36
35
  opts: PublicProcessorLimits;
37
36
  }> = [];
37
+ /** Track all consumed transaction hashes across buildBlock calls */
38
+ public consumedTxHashes: Set<string> = new Set();
38
39
  public completeCheckpointCalled = false;
39
40
  public getCheckpointCalled = false;
40
41
 
@@ -47,7 +48,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
47
48
  ) {}
48
49
 
49
50
  /** Seed the builder with blocks to return on successive buildBlock calls */
50
- seedBlocks(blocks: L2BlockNew[], usedTxsPerBlock?: Tx[][]): this {
51
+ seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
51
52
  this.blocks = blocks;
52
53
  this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
53
54
  this.blockIndex = 0;
@@ -59,7 +60,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
59
60
  * Set a function that provides blocks dynamically.
60
61
  * Useful for tests where the block is determined at call time (e.g., sequencer tests).
61
62
  */
62
- setBlockProvider(provider: () => L2BlockNew): this {
63
+ setBlockProvider(provider: () => L2Block): this {
63
64
  this.blockProvider = provider;
64
65
  this.blocks = [];
65
66
  return this;
@@ -69,8 +70,8 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
69
70
  return this.constants;
70
71
  }
71
72
 
72
- buildBlock(
73
- _pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
73
+ async buildBlock(
74
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
74
75
  blockNumber: BlockNumber,
75
76
  timestamp: bigint,
76
77
  opts: PublicProcessorLimits,
@@ -78,10 +79,10 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
78
79
  this.buildBlockCalls.push({ blockNumber, timestamp, opts });
79
80
 
80
81
  if (this.errorOnBuild) {
81
- return Promise.reject(this.errorOnBuild);
82
+ throw this.errorOnBuild;
82
83
  }
83
84
 
84
- let block: L2BlockNew;
85
+ let block: L2Block;
85
86
  let usedTxs: Tx[];
86
87
 
87
88
  if (this.blockProvider) {
@@ -97,16 +98,28 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
97
98
  this.builtBlocks.push(block);
98
99
  }
99
100
 
100
- return Promise.resolve({
101
+ // Check that no pending tx has already been consumed
102
+ for await (const tx of pendingTxs) {
103
+ const hash = tx.getTxHash().toString();
104
+ if (this.consumedTxHashes.has(hash)) {
105
+ throw new Error(`Transaction ${hash} was already consumed in a previous block`);
106
+ }
107
+ }
108
+
109
+ // Add used txs to consumed set
110
+ for (const tx of usedTxs) {
111
+ this.consumedTxHashes.add(tx.getTxHash().toString());
112
+ }
113
+
114
+ return {
101
115
  block,
102
116
  publicGas: Gas.empty(),
103
117
  publicProcessorDuration: 0,
104
118
  numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
105
- blockBuildingTimer: new Timer(),
106
119
  usedTxs,
107
120
  failedTxs: [],
108
121
  usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
109
- });
122
+ };
110
123
  }
111
124
 
112
125
  completeCheckpoint(): Promise<Checkpoint> {
@@ -148,7 +161,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
148
161
  * Creates a CheckpointHeader from a block's header for testing.
149
162
  * This is a simplified version that creates a minimal CheckpointHeader.
150
163
  */
151
- private createCheckpointHeader(block: L2BlockNew): CheckpointHeader {
164
+ private createCheckpointHeader(block: L2Block): CheckpointHeader {
152
165
  const header = block.header;
153
166
  const gv = header.globalVariables;
154
167
  return CheckpointHeader.empty({
@@ -170,6 +183,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
170
183
  this.usedTxsPerBlock = [];
171
184
  this.blockIndex = 0;
172
185
  this.buildBlockCalls = [];
186
+ this.consumedTxHashes.clear();
173
187
  this.completeCheckpointCalled = false;
174
188
  this.getCheckpointCalled = false;
175
189
  this.errorOnBuild = undefined;
@@ -197,7 +211,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
197
211
  constants: CheckpointGlobalVariables;
198
212
  l1ToL2Messages: Fr[];
199
213
  previousCheckpointOutHashes: Fr[];
200
- existingBlocks: L2BlockNew[];
214
+ existingBlocks: L2Block[];
201
215
  }> = [];
202
216
  public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
203
217
 
@@ -263,7 +277,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
263
277
  l1ToL2Messages: Fr[],
264
278
  previousCheckpointOutHashes: Fr[],
265
279
  _fork: MerkleTreeWriteOperations,
266
- existingBlocks: L2BlockNew[] = [],
280
+ existingBlocks: L2Block[] = [],
267
281
  ): Promise<ICheckpointBlockBuilder> {
268
282
  this.openCheckpointCalls.push({
269
283
  checkpointNumber,
package/src/test/utils.ts CHANGED
@@ -7,7 +7,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
7
7
  import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import type { P2P } from '@aztec/p2p';
9
9
  import { PublicDataWrite } from '@aztec/stdlib/avm';
10
- import { CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
10
+ import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
11
11
  import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
12
12
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
13
  import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
@@ -30,9 +30,9 @@ export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
30
30
  }
31
31
 
32
32
  /**
33
- * Creates an L2BlockNew from transactions and global variables
33
+ * Creates an L2Block from transactions and global variables
34
34
  */
35
- export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2BlockNew> {
35
+ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2Block> {
36
36
  const processedTxs = await Promise.all(
37
37
  txs.map(tx =>
38
38
  makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
@@ -41,7 +41,13 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
41
41
  const body = new Body(processedTxs.map(tx => tx.txEffect));
42
42
  const header = BlockHeader.empty({ globalVariables });
43
43
  const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
44
- return new L2BlockNew(archive, header, body, CheckpointNumber(globalVariables.blockNumber), IndexWithinCheckpoint(0));
44
+ return new L2Block(
45
+ archive,
46
+ header,
47
+ body,
48
+ CheckpointNumber.fromBlockNumber(globalVariables.blockNumber),
49
+ IndexWithinCheckpoint(0),
50
+ );
45
51
  }
46
52
 
47
53
  /**
@@ -70,10 +76,10 @@ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestat
70
76
  }
71
77
 
72
78
  /**
73
- * Creates a CheckpointHeader from an L2BlockNew for testing purposes.
74
- * Uses mock values for blockHeadersHash, blobsHash and inHash since L2BlockNew doesn't have these fields.
79
+ * Creates a CheckpointHeader from an L2Block for testing purposes.
80
+ * Uses mock values for blockHeadersHash, blobsHash and inHash since L2Block doesn't have these fields.
75
81
  */
76
- function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
82
+ function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
77
83
  const gv = block.header.globalVariables;
78
84
  return new CheckpointHeader(
79
85
  block.header.lastArchive.root,
@@ -93,7 +99,7 @@ function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
93
99
  /**
94
100
  * Creates a block proposal from a block and signature
95
101
  */
96
- export function createBlockProposal(block: L2BlockNew, signature: Signature): BlockProposal {
102
+ export function createBlockProposal(block: L2Block, signature: Signature): BlockProposal {
97
103
  const txHashes = block.body.txEffects.map(tx => tx.txHash);
98
104
  return new BlockProposal(
99
105
  block.header,
@@ -109,7 +115,7 @@ export function createBlockProposal(block: L2BlockNew, signature: Signature): Bl
109
115
  * Creates a checkpoint proposal from a block and signature
110
116
  */
111
117
  export function createCheckpointProposal(
112
- block: L2BlockNew,
118
+ block: L2Block,
113
119
  checkpointSignature: Signature,
114
120
  blockSignature?: Signature,
115
121
  ): CheckpointProposal {
@@ -129,7 +135,7 @@ export function createCheckpointProposal(
129
135
  * In production, the sender is recovered from the signature.
130
136
  */
131
137
  export function createCheckpointAttestation(
132
- block: L2BlockNew,
138
+ block: L2Block,
133
139
  signature: Signature,
134
140
  sender: EthAddress,
135
141
  ): CheckpointAttestation {
@@ -150,7 +156,7 @@ export async function setupTxsAndBlock(
150
156
  globalVariables: GlobalVariables,
151
157
  txCount: number,
152
158
  chainId: Fr,
153
- ): Promise<{ txs: Tx[]; block: L2BlockNew }> {
159
+ ): Promise<{ txs: Tx[]; block: L2Block }> {
154
160
  const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
155
161
  const block = await makeBlock(txs, globalVariables);
156
162
  mockPendingTxs(p2p, txs);