@aztec/stdlib 4.0.0-nightly.20260121 → 4.0.0-nightly.20260123
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.
- package/dest/block/checkpointed_l2_block.d.ts +6 -6
- package/dest/block/checkpointed_l2_block.d.ts.map +1 -1
- package/dest/block/checkpointed_l2_block.js +3 -3
- package/dest/block/in_block.d.ts +3 -3
- package/dest/block/in_block.d.ts.map +1 -1
- package/dest/block/index.d.ts +2 -2
- package/dest/block/index.d.ts.map +1 -1
- package/dest/block/index.js +1 -1
- package/dest/block/{l2_block_new.d.ts → l2_block.d.ts} +6 -6
- package/dest/block/l2_block.d.ts.map +1 -0
- package/dest/block/{l2_block_new.js → l2_block.js} +5 -9
- package/dest/block/l2_block_source.d.ts +37 -29
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/l2_block_stream/interfaces.d.ts +3 -3
- package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.d.ts +6 -3
- package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.js +37 -25
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +3 -3
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
- package/dest/block/test/l2_tips_store_test_suite.js +2 -2
- package/dest/checkpoint/checkpoint.d.ts +8 -8
- package/dest/checkpoint/checkpoint.d.ts.map +1 -1
- package/dest/checkpoint/checkpoint.js +4 -4
- package/dest/checkpoint/published_checkpoint.d.ts +2 -2
- package/dest/config/node-rpc-config.js +1 -1
- package/dest/contract/private_function.d.ts +1 -1
- package/dest/contract/private_function.d.ts.map +1 -1
- package/dest/contract/private_function.js +1 -2
- package/dest/epoch-helpers/index.js +1 -1
- package/dest/interfaces/api_limit.d.ts +2 -1
- package/dest/interfaces/api_limit.d.ts.map +1 -1
- package/dest/interfaces/api_limit.js +1 -0
- package/dest/interfaces/archiver.d.ts +1 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +17 -17
- package/dest/interfaces/aztec-node-admin.d.ts +4 -1
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.d.ts +32 -14
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +10 -11
- package/dest/interfaces/block-builder.d.ts +4 -4
- package/dest/interfaces/block-builder.d.ts.map +1 -1
- package/dest/interfaces/l2_logs_source.d.ts +14 -5
- package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
- package/dest/interfaces/prover-client.d.ts +10 -1
- package/dest/interfaces/prover-client.d.ts.map +1 -1
- package/dest/interfaces/prover-client.js +7 -1
- package/dest/interfaces/tx_provider.d.ts +3 -3
- package/dest/interfaces/tx_provider.d.ts.map +1 -1
- package/dest/p2p/block_proposal.d.ts +4 -4
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/block_proposal.js +1 -1
- package/dest/p2p/constants.d.ts +3 -0
- package/dest/p2p/constants.d.ts.map +1 -0
- package/dest/p2p/constants.js +2 -0
- package/dest/p2p/index.d.ts +2 -1
- package/dest/p2p/index.d.ts.map +1 -1
- package/dest/p2p/index.js +1 -0
- package/dest/tests/factories.js +1 -1
- package/dest/tests/jest.d.ts +4 -4
- package/dest/tests/jest.js +9 -9
- package/dest/tests/mocks.d.ts +10 -9
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +15 -10
- package/dest/tx/tx.d.ts +2 -1
- package/dest/tx/tx.d.ts.map +1 -1
- package/dest/tx/tx.js +6 -3
- package/dest/tx/tx_receipt.d.ts +39 -11
- package/dest/tx/tx_receipt.d.ts.map +1 -1
- package/dest/tx/tx_receipt.js +44 -13
- package/dest/tx/validator/error_texts.d.ts +2 -1
- package/dest/tx/validator/error_texts.d.ts.map +1 -1
- package/dest/tx/validator/error_texts.js +2 -0
- package/package.json +9 -9
- package/src/block/checkpointed_l2_block.ts +4 -4
- package/src/block/in_block.ts +2 -2
- package/src/block/index.ts +1 -1
- package/src/block/{l2_block_new.ts → l2_block.ts} +6 -11
- package/src/block/l2_block_source.ts +38 -30
- package/src/block/l2_block_stream/interfaces.ts +2 -2
- package/src/block/l2_block_stream/l2_block_stream.ts +44 -27
- package/src/block/l2_block_stream/l2_tips_store_base.ts +2 -2
- package/src/block/test/l2_tips_store_test_suite.ts +4 -4
- package/src/checkpoint/checkpoint.ts +7 -7
- package/src/config/node-rpc-config.ts +1 -1
- package/src/contract/private_function.ts +1 -2
- package/src/epoch-helpers/index.ts +1 -1
- package/src/interfaces/api_limit.ts +1 -0
- package/src/interfaces/archiver.ts +17 -26
- package/src/interfaces/aztec-node.ts +47 -35
- package/src/interfaces/block-builder.ts +3 -3
- package/src/interfaces/l2_logs_source.ts +17 -4
- package/src/interfaces/prover-client.ts +15 -0
- package/src/interfaces/tx_provider.ts +2 -2
- package/src/p2p/block_proposal.ts +3 -3
- package/src/p2p/constants.ts +3 -0
- package/src/p2p/index.ts +1 -0
- package/src/tests/factories.ts +1 -1
- package/src/tests/jest.ts +9 -9
- package/src/tests/mocks.ts +20 -13
- package/src/tx/tx.ts +8 -9
- package/src/tx/tx_receipt.ts +72 -15
- package/src/tx/validator/error_texts.ts +3 -0
- package/dest/block/l2_block_new.d.ts.map +0 -1
|
@@ -18,15 +18,10 @@ import { BlockHeader } from '../tx/block_header.js';
|
|
|
18
18
|
import { Body } from './body.js';
|
|
19
19
|
import type { L2BlockInfo } from './l2_block_info.js';
|
|
20
20
|
|
|
21
|
-
// TODO(palla/mbps): Delete the existing `L2Block` class and rename this to `L2Block`.
|
|
22
|
-
// TODO(palla/mbps): Consider moving the checkpointNumber and indexWithinCheckpoint to the header:
|
|
23
|
-
// if the blockNumber is there, why not these as well? Consider whether they should be part of the
|
|
24
|
-
// circuits structs though.
|
|
25
|
-
|
|
26
21
|
/**
|
|
27
22
|
* An L2 block with a header and a body.
|
|
28
23
|
*/
|
|
29
|
-
export class
|
|
24
|
+
export class L2Block {
|
|
30
25
|
constructor(
|
|
31
26
|
/** Snapshot of archive tree after the block is applied. */
|
|
32
27
|
public archive: AppendOnlyTreeSnapshot,
|
|
@@ -63,7 +58,7 @@ export class L2BlockNew {
|
|
|
63
58
|
})
|
|
64
59
|
.transform(
|
|
65
60
|
({ archive, header, body, checkpointNumber, indexWithinCheckpoint }) =>
|
|
66
|
-
new
|
|
61
|
+
new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint),
|
|
67
62
|
);
|
|
68
63
|
}
|
|
69
64
|
|
|
@@ -79,7 +74,7 @@ export class L2BlockNew {
|
|
|
79
74
|
const checkpointNumber = CheckpointNumber(reader.readNumber());
|
|
80
75
|
const indexWithinCheckpoint = IndexWithinCheckpoint(reader.readNumber());
|
|
81
76
|
|
|
82
|
-
return new
|
|
77
|
+
return new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
/**
|
|
@@ -143,7 +138,7 @@ export class L2BlockNew {
|
|
|
143
138
|
}
|
|
144
139
|
|
|
145
140
|
static empty(header?: BlockHeader) {
|
|
146
|
-
return new
|
|
141
|
+
return new L2Block(
|
|
147
142
|
AppendOnlyTreeSnapshot.empty(),
|
|
148
143
|
header ?? BlockHeader.empty(),
|
|
149
144
|
Body.empty(),
|
|
@@ -177,11 +172,11 @@ export class L2BlockNew {
|
|
|
177
172
|
txOptions?: Partial<Parameters<typeof Body.random>[0]>;
|
|
178
173
|
makeTxOptions?: (txIndex: number) => Partial<Parameters<typeof Body.random>[0]>;
|
|
179
174
|
} & Partial<Parameters<typeof BlockHeader.random>[0]> = {},
|
|
180
|
-
): Promise<
|
|
175
|
+
): Promise<L2Block> {
|
|
181
176
|
const archive = new AppendOnlyTreeSnapshot(Fr.random(), blockNumber + 1);
|
|
182
177
|
const header = BlockHeader.random({ blockNumber, ...blockHeaderOverrides });
|
|
183
178
|
const body = await Body.random({ txsPerBlock, makeTxOptions, ...txOptions });
|
|
184
|
-
return new
|
|
179
|
+
return new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint);
|
|
185
180
|
}
|
|
186
181
|
|
|
187
182
|
/**
|
|
@@ -21,7 +21,7 @@ import type { IndexedTxEffect } from '../tx/indexed_tx_effect.js';
|
|
|
21
21
|
import type { TxHash } from '../tx/tx_hash.js';
|
|
22
22
|
import type { TxReceipt } from '../tx/tx_receipt.js';
|
|
23
23
|
import type { CheckpointedL2Block } from './checkpointed_l2_block.js';
|
|
24
|
-
import type {
|
|
24
|
+
import type { L2Block } from './l2_block.js';
|
|
25
25
|
import type { ValidateCheckpointNegativeResult, ValidateCheckpointResult } from './validate_block_result.js';
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -52,6 +52,20 @@ export interface L2BlockSource {
|
|
|
52
52
|
*/
|
|
53
53
|
getProvenBlockNumber(): Promise<BlockNumber>;
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Gets the number of the latest L2 block checkpointed seen by the block source implementation.
|
|
57
|
+
* @returns The number of the latest L2 block checkpointed seen by the block source implementation.
|
|
58
|
+
*/
|
|
59
|
+
getCheckpointedL2BlockNumber(): Promise<BlockNumber>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Computes the finalized block number based on the proven block number.
|
|
63
|
+
* A block is considered finalized when it's 2 epochs behind the proven block.
|
|
64
|
+
* TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
65
|
+
* @returns The finalized block number.
|
|
66
|
+
*/
|
|
67
|
+
getFinalizedL2BlockNumber(): Promise<BlockNumber>;
|
|
68
|
+
|
|
55
69
|
/**
|
|
56
70
|
* Gets an l2 block header.
|
|
57
71
|
* @param number - The block number to return or 'latest' for the most recent one.
|
|
@@ -67,15 +81,15 @@ export interface L2BlockSource {
|
|
|
67
81
|
*/
|
|
68
82
|
getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined>;
|
|
69
83
|
|
|
70
|
-
getCheckpointedBlocks(from: BlockNumber, limit: number
|
|
84
|
+
getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]>;
|
|
71
85
|
|
|
72
86
|
/**
|
|
73
|
-
* Retrieves a collection of
|
|
74
|
-
* @param checkpointNumber The first checkpoint to be retrieved
|
|
75
|
-
* @param limit The number of checkpoints to be retrieved
|
|
76
|
-
* @returns The collection of complete checkpoints
|
|
87
|
+
* Retrieves a collection of checkpoints.
|
|
88
|
+
* @param checkpointNumber The first checkpoint to be retrieved.
|
|
89
|
+
* @param limit The number of checkpoints to be retrieved.
|
|
90
|
+
* @returns The collection of complete checkpoints.
|
|
77
91
|
*/
|
|
78
|
-
|
|
92
|
+
getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]>;
|
|
79
93
|
|
|
80
94
|
/**
|
|
81
95
|
* Gets the checkpoints for a given epoch
|
|
@@ -102,21 +116,21 @@ export interface L2BlockSource {
|
|
|
102
116
|
* @param number - The block number to return.
|
|
103
117
|
* @returns The requested L2 block (or undefined if not found).
|
|
104
118
|
*/
|
|
105
|
-
|
|
119
|
+
getL2Block(number: BlockNumber): Promise<L2Block | undefined>;
|
|
106
120
|
|
|
107
121
|
/**
|
|
108
122
|
* Gets an L2 block by its hash.
|
|
109
123
|
* @param blockHash - The block hash to retrieve.
|
|
110
124
|
* @returns The requested L2 block (or undefined if not found).
|
|
111
125
|
*/
|
|
112
|
-
|
|
126
|
+
getL2BlockByHash(blockHash: Fr): Promise<L2Block | undefined>;
|
|
113
127
|
|
|
114
128
|
/**
|
|
115
129
|
* Gets an L2 block by its archive root.
|
|
116
130
|
* @param archive - The archive root to retrieve.
|
|
117
131
|
* @returns The requested L2 block (or undefined if not found).
|
|
118
132
|
*/
|
|
119
|
-
|
|
133
|
+
getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined>;
|
|
120
134
|
|
|
121
135
|
/**
|
|
122
136
|
* Gets a tx effect.
|
|
@@ -143,11 +157,11 @@ export interface L2BlockSource {
|
|
|
143
157
|
getL2EpochNumber(): Promise<EpochNumber | undefined>;
|
|
144
158
|
|
|
145
159
|
/**
|
|
146
|
-
* Returns all block headers for a given epoch.
|
|
160
|
+
* Returns all checkpointed block headers for a given epoch.
|
|
147
161
|
* @dev Use this method only with recent epochs, since it walks the block list backwards.
|
|
148
162
|
* @param epochNumber - The epoch number to return headers for.
|
|
149
163
|
*/
|
|
150
|
-
|
|
164
|
+
getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]>;
|
|
151
165
|
|
|
152
166
|
/**
|
|
153
167
|
* Returns whether the given epoch is completed on L1, based on the current L1 and L2 block numbers.
|
|
@@ -193,49 +207,43 @@ export interface L2BlockSource {
|
|
|
193
207
|
* @param number - The block number to return (inclusive).
|
|
194
208
|
* @returns The requested L2 block.
|
|
195
209
|
*/
|
|
196
|
-
getBlock(number: BlockNumber): Promise<
|
|
197
|
-
|
|
198
|
-
getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]>;
|
|
210
|
+
getBlock(number: BlockNumber): Promise<L2Block | undefined>;
|
|
199
211
|
|
|
200
212
|
/**
|
|
201
|
-
* Returns all blocks for a given epoch.
|
|
213
|
+
* Returns all checkpointed blocks for a given epoch.
|
|
202
214
|
* @dev Use this method only with recent epochs, since it walks the block list backwards.
|
|
203
215
|
* @param epochNumber - The epoch number to return blocks for.
|
|
204
216
|
*/
|
|
205
|
-
|
|
217
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]>;
|
|
206
218
|
|
|
207
219
|
/**
|
|
208
220
|
* Returns all blocks for a given slot.
|
|
209
221
|
* @dev Use this method only with recent slots, since it walks the block list backwards.
|
|
210
222
|
* @param slotNumber - The slot number to return blocks for.
|
|
211
223
|
*/
|
|
212
|
-
getBlocksForSlot(slotNumber: SlotNumber): Promise<
|
|
224
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]>;
|
|
213
225
|
|
|
214
226
|
/**
|
|
215
|
-
* Gets a
|
|
227
|
+
* Gets a checkpointed block by its block hash.
|
|
216
228
|
* @param blockHash - The block hash to retrieve.
|
|
217
229
|
* @returns The requested block (or undefined if not found).
|
|
218
230
|
*/
|
|
219
|
-
|
|
231
|
+
getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined>;
|
|
220
232
|
|
|
221
233
|
/**
|
|
222
|
-
* Gets a
|
|
234
|
+
* Gets a checkpointed block by its archive root.
|
|
223
235
|
* @param archive - The archive root to retrieve.
|
|
224
236
|
* @returns The requested block (or undefined if not found).
|
|
225
237
|
*/
|
|
226
|
-
|
|
238
|
+
getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined>;
|
|
227
239
|
|
|
228
240
|
/**
|
|
229
241
|
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
230
242
|
* @param from - Number of the first block to return (inclusive).
|
|
231
243
|
* @param limit - The maximum number of blocks to return.
|
|
232
|
-
* @param proven - If true, only return blocks that have been proven.
|
|
233
244
|
* @returns The requested L2 blocks.
|
|
234
245
|
*/
|
|
235
|
-
getBlocks(from: BlockNumber, limit: number
|
|
236
|
-
|
|
237
|
-
/** Equivalent to getBlocks but includes publish data. */
|
|
238
|
-
getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]>;
|
|
246
|
+
getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]>;
|
|
239
247
|
}
|
|
240
248
|
|
|
241
249
|
/**
|
|
@@ -247,7 +255,7 @@ export interface L2BlockSink {
|
|
|
247
255
|
* @param block - The L2 block to add.
|
|
248
256
|
* @throws If block number is not incremental (i.e., not exactly one more than the last stored block).
|
|
249
257
|
*/
|
|
250
|
-
addBlock(block:
|
|
258
|
+
addBlock(block: L2Block): Promise<void>;
|
|
251
259
|
}
|
|
252
260
|
|
|
253
261
|
/**
|
|
@@ -344,13 +352,13 @@ export type L2BlockProvenEvent = {
|
|
|
344
352
|
export type L2PruneUnprovenEvent = {
|
|
345
353
|
type: 'l2PruneUnproven';
|
|
346
354
|
epochNumber: EpochNumber;
|
|
347
|
-
blocks:
|
|
355
|
+
blocks: L2Block[];
|
|
348
356
|
};
|
|
349
357
|
|
|
350
358
|
export type L2PruneUncheckpointedEvent = {
|
|
351
359
|
type: 'l2PruneUncheckpointed';
|
|
352
360
|
slotNumber: SlotNumber;
|
|
353
|
-
blocks:
|
|
361
|
+
blocks: L2Block[];
|
|
354
362
|
};
|
|
355
363
|
|
|
356
364
|
export type L2CheckpointEvent = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { L2Block } from '../l2_block.js';
|
|
3
3
|
import type { CheckpointId, L2BlockId, L2Tips } from '../l2_block_source.js';
|
|
4
4
|
|
|
5
5
|
/** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
|
|
@@ -16,7 +16,7 @@ export interface L2BlockStreamEventHandler {
|
|
|
16
16
|
export type L2BlockStreamEvent =
|
|
17
17
|
| /** Emits blocks added to the chain. */ {
|
|
18
18
|
type: 'blocks-added';
|
|
19
|
-
blocks:
|
|
19
|
+
blocks: L2Block[];
|
|
20
20
|
}
|
|
21
21
|
| /** Emits checkpoints published to L1. */ {
|
|
22
22
|
type: 'chain-checkpointed';
|
|
@@ -7,6 +7,9 @@ import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.
|
|
|
7
7
|
import { type L2BlockId, type L2BlockSource, makeL2BlockId } from '../l2_block_source.js';
|
|
8
8
|
import type { L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider } from './interfaces.js';
|
|
9
9
|
|
|
10
|
+
/** Maximum number of checkpoints to prefetch at once during sync. Matches MAX_RPC_CHECKPOINTS_LEN. */
|
|
11
|
+
export const CHECKPOINT_PREFETCH_LIMIT = 50;
|
|
12
|
+
|
|
10
13
|
/** Creates a stream of events for new blocks, chain tips updates, and reorgs, out of polling an archiver or a node. */
|
|
11
14
|
export class L2BlockStream {
|
|
12
15
|
private readonly runningPromise: RunningPromise;
|
|
@@ -16,13 +19,12 @@ export class L2BlockStream {
|
|
|
16
19
|
constructor(
|
|
17
20
|
private l2BlockSource: Pick<
|
|
18
21
|
L2BlockSource,
|
|
19
|
-
'
|
|
22
|
+
'getBlocks' | 'getBlockHeader' | 'getL2Tips' | 'getCheckpoints' | 'getCheckpointedBlocks'
|
|
20
23
|
>,
|
|
21
24
|
private localData: L2BlockStreamLocalDataProvider,
|
|
22
25
|
private handler: L2BlockStreamEventHandler,
|
|
23
26
|
private readonly log = createLogger('types:block_stream'),
|
|
24
27
|
private opts: {
|
|
25
|
-
proven?: boolean;
|
|
26
28
|
pollIntervalMS?: number;
|
|
27
29
|
batchSize?: number;
|
|
28
30
|
startingBlock?: number;
|
|
@@ -30,6 +32,8 @@ export class L2BlockStream {
|
|
|
30
32
|
skipFinalized?: boolean;
|
|
31
33
|
/** When true, checkpoint events will not be emitted. Blocks are still fetched via checkpoints but only blocks-added events are emitted. */
|
|
32
34
|
ignoreCheckpoints?: boolean;
|
|
35
|
+
/** Maximum number of checkpoints to prefetch at once during sync. Defaults to CHECKPOINT_PREFETCH_LIMIT (50). */
|
|
36
|
+
checkpointPrefetchLimit?: number;
|
|
33
37
|
} = {},
|
|
34
38
|
) {
|
|
35
39
|
// Note that RunningPromise is in stopped state by default. This promise won't run until someone invokes `start`,
|
|
@@ -124,7 +128,7 @@ export class L2BlockStream {
|
|
|
124
128
|
if (!this.opts.ignoreCheckpoints) {
|
|
125
129
|
let loop1Iterations = 0;
|
|
126
130
|
while (nextCheckpointToEmit <= sourceTips.checkpointed.checkpoint.number) {
|
|
127
|
-
const checkpoints = await this.l2BlockSource.
|
|
131
|
+
const checkpoints = await this.l2BlockSource.getCheckpoints(nextCheckpointToEmit, 1);
|
|
128
132
|
if (checkpoints.length === 0) {
|
|
129
133
|
break;
|
|
130
134
|
}
|
|
@@ -150,27 +154,36 @@ export class L2BlockStream {
|
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
// Loop 2: Fetch new checkpointed blocks. For each
|
|
157
|
+
// Loop 2: Fetch new checkpointed blocks. For each checkpoint, emit all blocks
|
|
154
158
|
// from that checkpoint that we need, then emit the checkpoint event.
|
|
155
|
-
// We
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
// We prefetch multiple checkpoints, then process them one by one.
|
|
160
|
+
let prefetchedCheckpoints: PublishedCheckpoint[] = [];
|
|
161
|
+
let prefetchIdx = 0;
|
|
162
|
+
let nextCheckpointNumber: CheckpointNumber | undefined;
|
|
159
163
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
// Find the starting checkpoint number
|
|
165
|
+
if (nextBlockNumber <= sourceTips.checkpointed.block.number) {
|
|
166
|
+
const blocks = await this.l2BlockSource.getCheckpointedBlocks(BlockNumber(nextBlockNumber), 1);
|
|
167
|
+
if (blocks.length > 0) {
|
|
168
|
+
nextCheckpointNumber = blocks[0].checkpointNumber;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
while (nextBlockNumber <= sourceTips.checkpointed.block.number && nextCheckpointNumber !== undefined) {
|
|
173
|
+
// Refill the prefetch buffer when exhausted
|
|
174
|
+
if (prefetchIdx >= prefetchedCheckpoints.length) {
|
|
175
|
+
const prefetchLimit = this.opts.checkpointPrefetchLimit ?? CHECKPOINT_PREFETCH_LIMIT;
|
|
176
|
+
prefetchedCheckpoints = await this.l2BlockSource.getCheckpoints(nextCheckpointNumber, prefetchLimit);
|
|
177
|
+
prefetchIdx = 0;
|
|
178
|
+
if (prefetchedCheckpoints.length === 0) {
|
|
168
179
|
break;
|
|
169
180
|
}
|
|
170
|
-
checkpoint = checkpoints[0];
|
|
171
181
|
}
|
|
172
182
|
|
|
183
|
+
const checkpoint = prefetchedCheckpoints[prefetchIdx]!;
|
|
184
|
+
|
|
173
185
|
// Get all blocks from this checkpoint that we need, respecting batchSize
|
|
186
|
+
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.checkpointed.block.number - nextBlockNumber + 1);
|
|
174
187
|
const blocksForCheckpoint = checkpoint.checkpoint.blocks
|
|
175
188
|
.filter(b => b.number >= nextBlockNumber)
|
|
176
189
|
.slice(0, limit);
|
|
@@ -180,23 +193,27 @@ export class L2BlockStream {
|
|
|
180
193
|
await this.emitEvent({ type: 'blocks-added', blocks: blocksForCheckpoint });
|
|
181
194
|
nextBlockNumber = blocksForCheckpoint.at(-1)!.number + 1;
|
|
182
195
|
|
|
183
|
-
// If we've reached the end of this checkpoint, emit the checkpoint event
|
|
196
|
+
// If we've reached the end of this checkpoint, emit the checkpoint event and move to next
|
|
184
197
|
const lastBlockInCheckpoint = checkpoint.checkpoint.blocks.at(-1)!;
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
if (nextBlockNumber > lastBlockInCheckpoint.number) {
|
|
199
|
+
if (!this.opts.ignoreCheckpoints) {
|
|
200
|
+
const lastBlockHash = await lastBlockInCheckpoint.hash();
|
|
201
|
+
await this.emitEvent({
|
|
202
|
+
type: 'chain-checkpointed',
|
|
203
|
+
checkpoint,
|
|
204
|
+
block: makeL2BlockId(lastBlockInCheckpoint.number, lastBlockHash.toString()),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
prefetchIdx++;
|
|
208
|
+
nextCheckpointNumber = CheckpointNumber(nextCheckpointNumber + 1);
|
|
192
209
|
}
|
|
193
210
|
}
|
|
194
211
|
|
|
195
212
|
// Loop 3: Fetch any remaining uncheckpointed (proposed) blocks.
|
|
196
213
|
while (nextBlockNumber <= sourceTips.proposed.number) {
|
|
197
214
|
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.proposed.number - nextBlockNumber + 1);
|
|
198
|
-
this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit}
|
|
199
|
-
const blocks = await this.l2BlockSource.
|
|
215
|
+
this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit}`);
|
|
216
|
+
const blocks = await this.l2BlockSource.getBlocks(BlockNumber(nextBlockNumber), BlockNumber(limit));
|
|
200
217
|
if (blocks.length === 0) {
|
|
201
218
|
break;
|
|
202
219
|
}
|
|
@@ -2,7 +2,7 @@ import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
|
2
2
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
|
|
4
4
|
import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { L2Block } from '../l2_block.js';
|
|
6
6
|
import {
|
|
7
7
|
type CheckpointId,
|
|
8
8
|
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
@@ -109,7 +109,7 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
// Protected helper that subclasses can override for block hash computation
|
|
112
|
-
protected computeBlockHash(block:
|
|
112
|
+
protected computeBlockHash(block: L2Block): Promise<string> {
|
|
113
113
|
return block.hash().then(hash => hash.toString());
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -5,8 +5,8 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
5
5
|
import {
|
|
6
6
|
type CheckpointId,
|
|
7
7
|
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
8
|
+
L2Block,
|
|
8
9
|
type L2BlockId,
|
|
9
|
-
L2BlockNew,
|
|
10
10
|
type L2TipId,
|
|
11
11
|
} from '@aztec/stdlib/block';
|
|
12
12
|
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
@@ -31,8 +31,8 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
|
|
|
31
31
|
blockToCheckpoint.clear();
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
const makeBlock = async (number: number): Promise<
|
|
35
|
-
const block = await
|
|
34
|
+
const makeBlock = async (number: number): Promise<L2Block> => {
|
|
35
|
+
const block = await L2Block.random(BlockNumber(number));
|
|
36
36
|
blockHashes.set(number, (await block.hash()).toString());
|
|
37
37
|
return block;
|
|
38
38
|
};
|
|
@@ -74,7 +74,7 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
|
|
|
74
74
|
checkpointed: makeTipId(checkpointed),
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
const makeCheckpoint = async (checkpointNumber: number, blocks:
|
|
77
|
+
const makeCheckpoint = async (checkpointNumber: number, blocks: L2Block[]): Promise<PublishedCheckpoint> => {
|
|
78
78
|
const checkpoint = await Checkpoint.random(CheckpointNumber(checkpointNumber), {
|
|
79
79
|
numBlocks: blocks.length,
|
|
80
80
|
startBlockNumber: blocks[0].number,
|
|
@@ -13,7 +13,7 @@ import type { FieldsOf } from '@aztec/foundation/types';
|
|
|
13
13
|
|
|
14
14
|
import { z } from 'zod';
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { L2Block } from '../block/l2_block.js';
|
|
17
17
|
import { MAX_BLOCKS_PER_CHECKPOINT } from '../deserialization/index.js';
|
|
18
18
|
import { computeCheckpointOutHash } from '../messaging/out_hash.js';
|
|
19
19
|
import { CheckpointHeader } from '../rollup/checkpoint_header.js';
|
|
@@ -29,7 +29,7 @@ export class Checkpoint {
|
|
|
29
29
|
/** Header of the checkpoint. */
|
|
30
30
|
public header: CheckpointHeader,
|
|
31
31
|
/** L2 blocks in the checkpoint. */
|
|
32
|
-
public blocks:
|
|
32
|
+
public blocks: L2Block[],
|
|
33
33
|
/** Number of the checkpoint. */
|
|
34
34
|
public number: CheckpointNumber,
|
|
35
35
|
) {}
|
|
@@ -43,7 +43,7 @@ export class Checkpoint {
|
|
|
43
43
|
.object({
|
|
44
44
|
archive: AppendOnlyTreeSnapshot.schema,
|
|
45
45
|
header: CheckpointHeader.schema,
|
|
46
|
-
blocks: z.array(
|
|
46
|
+
blocks: z.array(L2Block.schema),
|
|
47
47
|
number: CheckpointNumberSchema,
|
|
48
48
|
})
|
|
49
49
|
.transform(({ archive, header, blocks, number }) => new Checkpoint(archive, header, blocks, number));
|
|
@@ -62,7 +62,7 @@ export class Checkpoint {
|
|
|
62
62
|
return new Checkpoint(
|
|
63
63
|
reader.readObject(AppendOnlyTreeSnapshot),
|
|
64
64
|
reader.readObject(CheckpointHeader),
|
|
65
|
-
reader.readVector(
|
|
65
|
+
reader.readVector(L2Block, MAX_BLOCKS_PER_CHECKPOINT),
|
|
66
66
|
CheckpointNumber(reader.readNumber()),
|
|
67
67
|
);
|
|
68
68
|
}
|
|
@@ -135,16 +135,16 @@ export class Checkpoint {
|
|
|
135
135
|
startBlockNumber?: number;
|
|
136
136
|
previousArchive?: AppendOnlyTreeSnapshot;
|
|
137
137
|
} & Partial<Parameters<typeof CheckpointHeader.random>[0]> &
|
|
138
|
-
Partial<Parameters<typeof
|
|
138
|
+
Partial<Parameters<typeof L2Block.random>[1]> = {},
|
|
139
139
|
) {
|
|
140
140
|
const header = CheckpointHeader.random(options);
|
|
141
141
|
|
|
142
142
|
// Create blocks sequentially to chain archive roots properly.
|
|
143
143
|
// Each block's header.lastArchive must equal the previous block's archive.
|
|
144
|
-
const blocks:
|
|
144
|
+
const blocks: L2Block[] = [];
|
|
145
145
|
let lastArchive = previousArchive;
|
|
146
146
|
for (let i = 0; i < numBlocks; i++) {
|
|
147
|
-
const block = await
|
|
147
|
+
const block = await L2Block.random(BlockNumber(startBlockNumber + i), {
|
|
148
148
|
indexWithinCheckpoint: IndexWithinCheckpoint(i),
|
|
149
149
|
...options,
|
|
150
150
|
...(lastArchive ? { lastArchive } : {}),
|
|
@@ -21,7 +21,7 @@ export const nodeRpcConfigMappings: ConfigMappingsType<NodeRPCConfig> = {
|
|
|
21
21
|
rpcMaxBodySize: {
|
|
22
22
|
env: 'RPC_MAX_BODY_SIZE',
|
|
23
23
|
description: 'Maximum allowed batch size for JSON RPC batch requests.',
|
|
24
|
-
defaultValue: '
|
|
24
|
+
defaultValue: '1mb',
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FUNCTION_TREE_HEIGHT, GeneratorIndex } from '@aztec/constants';
|
|
2
|
-
import { pedersenHash } from '@aztec/foundation/crypto/pedersen';
|
|
3
2
|
import { poseidon2Hash, poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
4
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
4
|
import { type MerkleTree, MerkleTreeCalculator } from '@aztec/foundation/trees';
|
|
@@ -38,7 +37,7 @@ export async function computePrivateFunctionLeaf(fn: PrivateFunction): Promise<B
|
|
|
38
37
|
async function getPrivateFunctionTreeCalculator(): Promise<MerkleTreeCalculator> {
|
|
39
38
|
if (!privateFunctionTreeCalculator) {
|
|
40
39
|
const functionTreeZeroLeaf = (
|
|
41
|
-
await
|
|
40
|
+
await poseidon2Hash(new Array(PRIVATE_FUNCTION_SIZE).fill(0))
|
|
42
41
|
).toBuffer() as Buffer<ArrayBuffer>;
|
|
43
42
|
privateFunctionTreeCalculator = await MerkleTreeCalculator.create(
|
|
44
43
|
FUNCTION_TREE_HEIGHT,
|
|
@@ -69,7 +69,7 @@ export function getSlotRangeForEpoch(
|
|
|
69
69
|
epochNumber: EpochNumber,
|
|
70
70
|
constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
71
71
|
): [SlotNumber, SlotNumber] {
|
|
72
|
-
const startSlot = SlotNumber(epochNumber * constants.epochDuration);
|
|
72
|
+
const startSlot = SlotNumber(Number(epochNumber) * constants.epochDuration);
|
|
73
73
|
return [startSlot, SlotNumber(startSlot + constants.epochDuration - 1)];
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -5,7 +5,7 @@ import type { ApiSchemaFor } from '@aztec/foundation/schemas';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
import { CheckpointedL2Block } from '../block/checkpointed_l2_block.js';
|
|
8
|
-
import {
|
|
8
|
+
import { L2Block } from '../block/l2_block.js';
|
|
9
9
|
import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
|
|
10
10
|
import { ValidateCheckpointResultSchema } from '../block/validate_block_result.js';
|
|
11
11
|
import { Checkpoint } from '../checkpoint/checkpoint.js';
|
|
@@ -82,7 +82,9 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
|
|
|
82
82
|
getRegistryAddress: z.function().args().returns(schemas.EthAddress),
|
|
83
83
|
getBlockNumber: z.function().args().returns(BlockNumberSchema),
|
|
84
84
|
getProvenBlockNumber: z.function().args().returns(BlockNumberSchema),
|
|
85
|
-
|
|
85
|
+
getCheckpointedL2BlockNumber: z.function().args().returns(BlockNumberSchema),
|
|
86
|
+
getFinalizedL2BlockNumber: z.function().args().returns(BlockNumberSchema),
|
|
87
|
+
getBlock: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
|
|
86
88
|
getBlockHeader: z
|
|
87
89
|
.function()
|
|
88
90
|
.args(z.union([BlockNumberSchema, z.literal('latest')]))
|
|
@@ -90,48 +92,37 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
|
|
|
90
92
|
getCheckpointedBlock: z.function().args(BlockNumberSchema).returns(CheckpointedL2Block.schema.optional()),
|
|
91
93
|
getCheckpointedBlocks: z
|
|
92
94
|
.function()
|
|
93
|
-
.args(BlockNumberSchema, schemas.Integer
|
|
95
|
+
.args(BlockNumberSchema, schemas.Integer)
|
|
94
96
|
.returns(z.array(CheckpointedL2Block.schema)),
|
|
95
|
-
getBlocks: z
|
|
96
|
-
|
|
97
|
-
.args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
|
|
98
|
-
.returns(z.array(L2BlockNew.schema)),
|
|
99
|
-
getPublishedCheckpoints: z
|
|
97
|
+
getBlocks: z.function().args(BlockNumberSchema, schemas.Integer).returns(z.array(L2Block.schema)),
|
|
98
|
+
getCheckpoints: z
|
|
100
99
|
.function()
|
|
101
100
|
.args(CheckpointNumberSchema, schemas.Integer)
|
|
102
101
|
.returns(z.array(PublishedCheckpoint.schema)),
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
|
|
106
|
-
.returns(z.array(CheckpointedL2Block.schema)),
|
|
107
|
-
getL2BlocksNew: z
|
|
108
|
-
.function()
|
|
109
|
-
.args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
|
|
110
|
-
.returns(z.array(L2BlockNew.schema)),
|
|
111
|
-
getPublishedBlockByHash: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
|
|
112
|
-
getPublishedBlockByArchive: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
|
|
102
|
+
getCheckpointedBlockByHash: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
|
|
103
|
+
getCheckpointedBlockByArchive: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
|
|
113
104
|
getBlockHeaderByHash: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
|
|
114
105
|
getBlockHeaderByArchive: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
getL2Block: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
|
|
107
|
+
getL2BlockByHash: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
|
|
108
|
+
getL2BlockByArchive: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
|
|
118
109
|
getTxEffect: z.function().args(TxHash.schema).returns(indexedTxSchema().optional()),
|
|
119
110
|
getSettledTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema.optional()),
|
|
120
111
|
getL2SlotNumber: z.function().args().returns(schemas.SlotNumber.optional()),
|
|
121
112
|
getL2EpochNumber: z.function().args().returns(EpochNumberSchema.optional()),
|
|
122
113
|
getCheckpointsForEpoch: z.function().args(EpochNumberSchema).returns(z.array(Checkpoint.schema)),
|
|
123
|
-
|
|
124
|
-
getBlocksForSlot: z.function().args(schemas.SlotNumber).returns(z.array(
|
|
125
|
-
|
|
114
|
+
getCheckpointedBlocksForEpoch: z.function().args(EpochNumberSchema).returns(z.array(CheckpointedL2Block.schema)),
|
|
115
|
+
getBlocksForSlot: z.function().args(schemas.SlotNumber).returns(z.array(L2Block.schema)),
|
|
116
|
+
getCheckpointedBlockHeadersForEpoch: z.function().args(EpochNumberSchema).returns(z.array(BlockHeader.schema)),
|
|
126
117
|
isEpochComplete: z.function().args(EpochNumberSchema).returns(z.boolean()),
|
|
127
118
|
getL2Tips: z.function().args().returns(L2TipsSchema),
|
|
128
119
|
getPrivateLogsByTags: z
|
|
129
120
|
.function()
|
|
130
|
-
.args(z.array(SiloedTag.schema))
|
|
121
|
+
.args(z.array(SiloedTag.schema), optional(z.number().gte(0)))
|
|
131
122
|
.returns(z.array(z.array(TxScopedL2Log.schema))),
|
|
132
123
|
getPublicLogsByTagsFromContract: z
|
|
133
124
|
.function()
|
|
134
|
-
.args(schemas.AztecAddress, z.array(Tag.schema))
|
|
125
|
+
.args(schemas.AztecAddress, z.array(Tag.schema), optional(z.number().gte(0)))
|
|
135
126
|
.returns(z.array(z.array(TxScopedL2Log.schema))),
|
|
136
127
|
getPublicLogs: z.function().args(LogFilterSchema).returns(GetPublicLogsResponseSchema),
|
|
137
128
|
getContractClassLogs: z.function().args(LogFilterSchema).returns(GetContractClassLogsResponseSchema),
|