@aztec/sequencer-client 0.0.1-commit.3469e52 → 0.0.1-commit.54489865

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 (33) hide show
  1. package/dest/client/sequencer-client.js +1 -1
  2. package/dest/config.d.ts +1 -1
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +1 -3
  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/sequencer/checkpoint_proposal_job.d.ts +4 -4
  10. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  11. package/dest/sequencer/checkpoint_proposal_job.js +17 -7
  12. package/dest/sequencer/metrics.d.ts +2 -2
  13. package/dest/sequencer/metrics.d.ts.map +1 -1
  14. package/dest/sequencer/metrics.js +27 -17
  15. package/dest/sequencer/sequencer.d.ts +3 -3
  16. package/dest/sequencer/sequencer.d.ts.map +1 -1
  17. package/dest/sequencer/sequencer.js +2 -2
  18. package/dest/test/mock_checkpoint_builder.d.ts +11 -8
  19. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  20. package/dest/test/mock_checkpoint_builder.js +18 -4
  21. package/dest/test/utils.d.ts +8 -8
  22. package/dest/test/utils.d.ts.map +1 -1
  23. package/dest/test/utils.js +5 -5
  24. package/package.json +28 -28
  25. package/src/client/sequencer-client.ts +1 -1
  26. package/src/config.ts +1 -3
  27. package/src/global_variable_builder/global_builder.ts +2 -2
  28. package/src/publisher/sequencer-publisher-metrics.ts +7 -3
  29. package/src/sequencer/checkpoint_proposal_job.ts +24 -15
  30. package/src/sequencer/metrics.ts +36 -18
  31. package/src/sequencer/sequencer.ts +4 -4
  32. package/src/test/mock_checkpoint_builder.ts +33 -17
  33. package/src/test/utils.ts +17 -11
@@ -1,11 +1,10 @@
1
1
  import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
- import { L2BlockNew } from '@aztec/stdlib/block';
4
+ import { L2Block } from '@aztec/stdlib/block';
5
5
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
6
6
  import { Gas } from '@aztec/stdlib/gas';
7
7
  import type {
8
- BuildBlockInCheckpointResult,
9
8
  FullNodeBlockBuilderConfig,
10
9
  ICheckpointBlockBuilder,
11
10
  ICheckpointsBuilder,
@@ -15,19 +14,20 @@ import type {
15
14
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
16
15
  import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
17
16
  import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
17
+ import type { BuildBlockInCheckpointResultWithTimer } from '@aztec/validator-client';
18
18
 
19
19
  /**
20
20
  * A fake CheckpointBuilder for testing that implements the same interface as the real one.
21
21
  * Can be seeded with blocks to return sequentially on each `buildBlock` call.
22
22
  */
23
23
  export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
24
- private blocks: L2BlockNew[] = [];
25
- private builtBlocks: L2BlockNew[] = [];
24
+ private blocks: L2Block[] = [];
25
+ private builtBlocks: L2Block[] = [];
26
26
  private usedTxsPerBlock: Tx[][] = [];
27
27
  private blockIndex = 0;
28
28
 
29
29
  /** Optional function to dynamically provide the block (alternative to seedBlocks) */
30
- private blockProvider: (() => L2BlockNew) | undefined = undefined;
30
+ private blockProvider: (() => L2Block) | undefined = undefined;
31
31
 
32
32
  /** Track calls for assertions */
33
33
  public buildBlockCalls: Array<{
@@ -35,6 +35,8 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
35
35
  timestamp: bigint;
36
36
  opts: PublicProcessorLimits;
37
37
  }> = [];
38
+ /** Track all consumed transaction hashes across buildBlock calls */
39
+ public consumedTxHashes: Set<string> = new Set();
38
40
  public completeCheckpointCalled = false;
39
41
  public getCheckpointCalled = false;
40
42
 
@@ -47,7 +49,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
47
49
  ) {}
48
50
 
49
51
  /** Seed the builder with blocks to return on successive buildBlock calls */
50
- seedBlocks(blocks: L2BlockNew[], usedTxsPerBlock?: Tx[][]): this {
52
+ seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
51
53
  this.blocks = blocks;
52
54
  this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
53
55
  this.blockIndex = 0;
@@ -59,7 +61,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
59
61
  * Set a function that provides blocks dynamically.
60
62
  * Useful for tests where the block is determined at call time (e.g., sequencer tests).
61
63
  */
62
- setBlockProvider(provider: () => L2BlockNew): this {
64
+ setBlockProvider(provider: () => L2Block): this {
63
65
  this.blockProvider = provider;
64
66
  this.blocks = [];
65
67
  return this;
@@ -69,19 +71,19 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
69
71
  return this.constants;
70
72
  }
71
73
 
72
- buildBlock(
73
- _pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
74
+ async buildBlock(
75
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
74
76
  blockNumber: BlockNumber,
75
77
  timestamp: bigint,
76
78
  opts: PublicProcessorLimits,
77
- ): Promise<BuildBlockInCheckpointResult> {
79
+ ): Promise<BuildBlockInCheckpointResultWithTimer> {
78
80
  this.buildBlockCalls.push({ blockNumber, timestamp, opts });
79
81
 
80
82
  if (this.errorOnBuild) {
81
- return Promise.reject(this.errorOnBuild);
83
+ throw this.errorOnBuild;
82
84
  }
83
85
 
84
- let block: L2BlockNew;
86
+ let block: L2Block;
85
87
  let usedTxs: Tx[];
86
88
 
87
89
  if (this.blockProvider) {
@@ -97,7 +99,20 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
97
99
  this.builtBlocks.push(block);
98
100
  }
99
101
 
100
- return Promise.resolve({
102
+ // Check that no pending tx has already been consumed
103
+ for await (const tx of pendingTxs) {
104
+ const hash = tx.getTxHash().toString();
105
+ if (this.consumedTxHashes.has(hash)) {
106
+ throw new Error(`Transaction ${hash} was already consumed in a previous block`);
107
+ }
108
+ }
109
+
110
+ // Add used txs to consumed set
111
+ for (const tx of usedTxs) {
112
+ this.consumedTxHashes.add(tx.getTxHash().toString());
113
+ }
114
+
115
+ return {
101
116
  block,
102
117
  publicGas: Gas.empty(),
103
118
  publicProcessorDuration: 0,
@@ -106,7 +121,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
106
121
  usedTxs,
107
122
  failedTxs: [],
108
123
  usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
109
- });
124
+ };
110
125
  }
111
126
 
112
127
  completeCheckpoint(): Promise<Checkpoint> {
@@ -148,7 +163,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
148
163
  * Creates a CheckpointHeader from a block's header for testing.
149
164
  * This is a simplified version that creates a minimal CheckpointHeader.
150
165
  */
151
- private createCheckpointHeader(block: L2BlockNew): CheckpointHeader {
166
+ private createCheckpointHeader(block: L2Block): CheckpointHeader {
152
167
  const header = block.header;
153
168
  const gv = header.globalVariables;
154
169
  return CheckpointHeader.empty({
@@ -170,6 +185,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
170
185
  this.usedTxsPerBlock = [];
171
186
  this.blockIndex = 0;
172
187
  this.buildBlockCalls = [];
188
+ this.consumedTxHashes.clear();
173
189
  this.completeCheckpointCalled = false;
174
190
  this.getCheckpointCalled = false;
175
191
  this.errorOnBuild = undefined;
@@ -197,7 +213,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
197
213
  constants: CheckpointGlobalVariables;
198
214
  l1ToL2Messages: Fr[];
199
215
  previousCheckpointOutHashes: Fr[];
200
- existingBlocks: L2BlockNew[];
216
+ existingBlocks: L2Block[];
201
217
  }> = [];
202
218
  public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
203
219
 
@@ -263,7 +279,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
263
279
  l1ToL2Messages: Fr[],
264
280
  previousCheckpointOutHashes: Fr[],
265
281
  _fork: MerkleTreeWriteOperations,
266
- existingBlocks: L2BlockNew[] = [],
282
+ existingBlocks: L2Block[] = [],
267
283
  ): Promise<ICheckpointBlockBuilder> {
268
284
  this.openCheckpointCalls.push({
269
285
  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);