@aztec/stdlib 4.0.0-nightly.20260122 → 4.0.0-nightly.20260124
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 +25 -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 +2 -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 +4 -4
- 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/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/delayed_public_mutable/delayed_public_mutable_values.d.ts +2 -2
- package/dest/delayed_public_mutable/delayed_public_mutable_values.d.ts.map +1 -1
- package/dest/delayed_public_mutable/delayed_public_mutable_values.js +7 -10
- package/dest/epoch-helpers/index.js +1 -1
- package/dest/interfaces/archiver.d.ts +1 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +13 -15
- package/dest/interfaces/aztec-node.d.ts +23 -9
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +11 -11
- package/dest/interfaces/block-builder.d.ts +4 -4
- package/dest/interfaces/block-builder.d.ts.map +1 -1
- package/dest/interfaces/configs.d.ts +2 -2
- package/dest/interfaces/configs.d.ts.map +1 -1
- package/dest/interfaces/tx_provider.d.ts +3 -3
- package/dest/interfaces/tx_provider.d.ts.map +1 -1
- package/dest/interfaces/validator.d.ts +2 -2
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/kernel/hints/build_nullifier_read_request_hints.d.ts +3 -3
- package/dest/kernel/hints/build_nullifier_read_request_hints.d.ts.map +1 -1
- package/dest/kernel/hints/build_nullifier_read_request_hints.js +4 -6
- 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/message_validator.d.ts +18 -3
- package/dest/p2p/message_validator.d.ts.map +1 -1
- package/dest/p2p/message_validator.js +2 -1
- 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/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 +24 -30
- package/src/block/l2_block_stream/interfaces.ts +2 -2
- package/src/block/l2_block_stream/l2_block_stream.ts +5 -6
- 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/contract/private_function.ts +1 -2
- package/src/delayed_public_mutable/delayed_public_mutable_values.ts +9 -10
- package/src/epoch-helpers/index.ts +1 -1
- package/src/interfaces/archiver.ts +13 -24
- package/src/interfaces/aztec-node.ts +38 -31
- package/src/interfaces/block-builder.ts +3 -3
- package/src/interfaces/configs.ts +1 -3
- package/src/interfaces/tx_provider.ts +2 -2
- package/src/interfaces/validator.ts +1 -2
- package/src/kernel/hints/build_nullifier_read_request_hints.ts +1 -10
- package/src/p2p/block_proposal.ts +3 -3
- package/src/p2p/message_validator.ts +14 -2
- package/src/tests/factories.ts +1 -1
- package/src/tests/jest.ts +9 -9
- package/src/tests/mocks.ts +20 -13
- package/dest/block/l2_block_new.d.ts.map +0 -1
package/dest/tests/mocks.js
CHANGED
|
@@ -12,7 +12,7 @@ import { AvmCircuitPublicInputs } from '../avm/avm_circuit_public_inputs.js';
|
|
|
12
12
|
import { PublicDataWrite } from '../avm/public_data_write.js';
|
|
13
13
|
import { RevertCode } from '../avm/revert_code.js';
|
|
14
14
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
15
|
-
import { CheckpointedL2Block, CommitteeAttestation,
|
|
15
|
+
import { CheckpointedL2Block, CommitteeAttestation, L2Block } from '../block/index.js';
|
|
16
16
|
import { Checkpoint } from '../checkpoint/checkpoint.js';
|
|
17
17
|
import { L1PublishedData } from '../checkpoint/published_checkpoint.js';
|
|
18
18
|
import { computeContractAddressFromInstance } from '../contract/contract_address.js';
|
|
@@ -212,19 +212,24 @@ export function mockL1ToL2Messages(numL1ToL2Messages) {
|
|
|
212
212
|
length: numL1ToL2Messages
|
|
213
213
|
}, ()=>Fr.random());
|
|
214
214
|
}
|
|
215
|
-
export async function mockCheckpointAndMessages(checkpointNumber, { startBlockNumber = BlockNumber(1), numBlocks = 1, blocks, numTxsPerBlock = 1, numL1ToL2Messages = 1, makeBlockOptions = ()=>({}), previousArchive, ...options } = {}) {
|
|
216
|
-
const slotNumber = options.slotNumber ?? SlotNumber(checkpointNumber * 10);
|
|
215
|
+
export async function mockCheckpointAndMessages(checkpointNumber, { startBlockNumber = BlockNumber(1), numBlocks = 1, blocks, numTxsPerBlock = 1, numL1ToL2Messages = 1, makeBlockOptions = ()=>({}), previousArchive, maxEffects, ...options } = {}) {
|
|
216
|
+
const slotNumber = options.slotNumber ?? SlotNumber(Number(checkpointNumber) * 10);
|
|
217
217
|
const blocksAndMessages = [];
|
|
218
218
|
// Track the previous block's archive to ensure consecutive blocks have consistent archive roots.
|
|
219
219
|
// The current block's header.lastArchive must equal the previous block's archive.
|
|
220
220
|
let lastArchive = previousArchive;
|
|
221
|
+
// Pass maxEffects via txOptions so it reaches TxEffect.random
|
|
222
|
+
const txOptions = maxEffects !== undefined ? {
|
|
223
|
+
maxEffects
|
|
224
|
+
} : {};
|
|
221
225
|
for(let i = 0; i < (blocks?.length ?? numBlocks); i++){
|
|
222
226
|
const blockNumber = BlockNumber(startBlockNumber + i);
|
|
223
227
|
const { block, messages } = {
|
|
224
|
-
block: blocks?.[i] ?? await
|
|
228
|
+
block: blocks?.[i] ?? await L2Block.random(blockNumber, {
|
|
225
229
|
checkpointNumber,
|
|
226
230
|
indexWithinCheckpoint: IndexWithinCheckpoint(i),
|
|
227
231
|
txsPerBlock: numTxsPerBlock,
|
|
232
|
+
txOptions,
|
|
228
233
|
slotNumber,
|
|
229
234
|
...options,
|
|
230
235
|
...makeBlockOptions(blockNumber),
|
|
@@ -390,10 +395,10 @@ export const makeCheckpointProposal = (options)=>{
|
|
|
390
395
|
});
|
|
391
396
|
};
|
|
392
397
|
/**
|
|
393
|
-
* Create a checkpoint attestation from an
|
|
394
|
-
* Note: This is a compatibility function for tests.
|
|
398
|
+
* Create a checkpoint attestation from an L2Block
|
|
399
|
+
* Note: This is a compatibility function for tests. L2Block doesn't have a checkpoint header directly.
|
|
395
400
|
*/ export const makeCheckpointAttestationFromBlock = (block, attesterSigner, proposerSigner)=>{
|
|
396
|
-
// For
|
|
401
|
+
// For L2Block, we create a minimal checkpoint header for testing purposes
|
|
397
402
|
const header = CheckpointHeader.empty({
|
|
398
403
|
lastArchiveRoot: block.header.lastArchive.root,
|
|
399
404
|
slotNumber: block.slot,
|
|
@@ -409,14 +414,14 @@ export const makeCheckpointProposal = (options)=>{
|
|
|
409
414
|
});
|
|
410
415
|
};
|
|
411
416
|
export async function randomPublishedL2Block(l2BlockNumber, opts = {}) {
|
|
412
|
-
const block = await
|
|
417
|
+
const block = await L2Block.random(BlockNumber(l2BlockNumber));
|
|
413
418
|
const l1 = L1PublishedData.fromFields({
|
|
414
419
|
blockNumber: BigInt(block.number),
|
|
415
420
|
timestamp: block.header.globalVariables.timestamp,
|
|
416
421
|
blockHash: Buffer32.random().toString()
|
|
417
422
|
});
|
|
418
423
|
const signers = opts.signers ?? times(3, ()=>Secp256k1Signer.random());
|
|
419
|
-
const checkpoint = await Checkpoint.random(CheckpointNumber(l2BlockNumber), {
|
|
424
|
+
const checkpoint = await Checkpoint.random(CheckpointNumber.fromBlockNumber(BlockNumber(l2BlockNumber)), {
|
|
420
425
|
numBlocks: 0
|
|
421
426
|
});
|
|
422
427
|
checkpoint.blocks = [
|
|
@@ -428,5 +433,5 @@ export async function randomPublishedL2Block(l2BlockNumber, opts = {}) {
|
|
|
428
433
|
header: checkpoint.header
|
|
429
434
|
}));
|
|
430
435
|
const attestations = atts.map((attestation, i)=>new CommitteeAttestation(signers[i].address, attestation.signature));
|
|
431
|
-
return new CheckpointedL2Block(CheckpointNumber(l2BlockNumber), block, l1, attestations);
|
|
436
|
+
return new CheckpointedL2Block(CheckpointNumber.fromBlockNumber(BlockNumber(l2BlockNumber)), block, l1, attestations);
|
|
432
437
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/stdlib",
|
|
3
|
-
"version": "4.0.0-nightly.
|
|
3
|
+
"version": "4.0.0-nightly.20260124",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json",
|
|
@@ -78,14 +78,14 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@aws-sdk/client-s3": "^3.892.0",
|
|
81
|
-
"@aztec/bb.js": "4.0.0-nightly.
|
|
82
|
-
"@aztec/blob-lib": "4.0.0-nightly.
|
|
83
|
-
"@aztec/constants": "4.0.0-nightly.
|
|
84
|
-
"@aztec/ethereum": "4.0.0-nightly.
|
|
85
|
-
"@aztec/foundation": "4.0.0-nightly.
|
|
86
|
-
"@aztec/l1-artifacts": "4.0.0-nightly.
|
|
87
|
-
"@aztec/noir-noirc_abi": "4.0.0-nightly.
|
|
88
|
-
"@aztec/validator-ha-signer": "4.0.0-nightly.
|
|
81
|
+
"@aztec/bb.js": "4.0.0-nightly.20260124",
|
|
82
|
+
"@aztec/blob-lib": "4.0.0-nightly.20260124",
|
|
83
|
+
"@aztec/constants": "4.0.0-nightly.20260124",
|
|
84
|
+
"@aztec/ethereum": "4.0.0-nightly.20260124",
|
|
85
|
+
"@aztec/foundation": "4.0.0-nightly.20260124",
|
|
86
|
+
"@aztec/l1-artifacts": "4.0.0-nightly.20260124",
|
|
87
|
+
"@aztec/noir-noirc_abi": "4.0.0-nightly.20260124",
|
|
88
|
+
"@aztec/validator-ha-signer": "4.0.0-nightly.20260124",
|
|
89
89
|
"@google-cloud/storage": "^7.15.0",
|
|
90
90
|
"axios": "^1.12.0",
|
|
91
91
|
"json-stringify-deterministic": "1.0.12",
|
|
@@ -7,7 +7,7 @@ import { z } from 'zod';
|
|
|
7
7
|
|
|
8
8
|
import { L1PublishedData } from '../checkpoint/published_checkpoint.js';
|
|
9
9
|
import { MAX_BLOCK_HASH_STRING_LENGTH, MAX_COMMITTEE_SIZE } from '../deserialization/index.js';
|
|
10
|
-
import {
|
|
10
|
+
import { L2Block } from './l2_block.js';
|
|
11
11
|
import { CommitteeAttestation } from './proposal/committee_attestation.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -16,7 +16,7 @@ import { CommitteeAttestation } from './proposal/committee_attestation.js';
|
|
|
16
16
|
export class CheckpointedL2Block {
|
|
17
17
|
constructor(
|
|
18
18
|
public checkpointNumber: CheckpointNumber,
|
|
19
|
-
public block:
|
|
19
|
+
public block: L2Block,
|
|
20
20
|
public l1: L1PublishedData,
|
|
21
21
|
public attestations: CommitteeAttestation[],
|
|
22
22
|
) {}
|
|
@@ -24,7 +24,7 @@ export class CheckpointedL2Block {
|
|
|
24
24
|
return z
|
|
25
25
|
.object({
|
|
26
26
|
checkpointNumber: CheckpointNumberSchema,
|
|
27
|
-
block:
|
|
27
|
+
block: L2Block.schema,
|
|
28
28
|
l1: L1PublishedData.schema,
|
|
29
29
|
attestations: z.array(CommitteeAttestation.schema),
|
|
30
30
|
})
|
|
@@ -34,7 +34,7 @@ export class CheckpointedL2Block {
|
|
|
34
34
|
static fromBuffer(bufferOrReader: Buffer | BufferReader): CheckpointedL2Block {
|
|
35
35
|
const reader = BufferReader.asReader(bufferOrReader);
|
|
36
36
|
const checkpointNumber = reader.readNumber();
|
|
37
|
-
const block = reader.readObject(
|
|
37
|
+
const block = reader.readObject(L2Block);
|
|
38
38
|
const l1BlockNumber = reader.readBigInt();
|
|
39
39
|
const l1BlockHash = reader.readString(MAX_BLOCK_HASH_STRING_LENGTH);
|
|
40
40
|
const l1Timestamp = reader.readBigInt();
|
package/src/block/in_block.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BlockNumber, BlockNumberSchema } from '@aztec/foundation/branded-types'
|
|
|
3
3
|
import { type ZodTypeAny, z } from 'zod';
|
|
4
4
|
|
|
5
5
|
import { L2BlockHash } from './block_hash.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { L2Block } from './l2_block.js';
|
|
7
7
|
|
|
8
8
|
export type InBlock = {
|
|
9
9
|
l2BlockNumber: BlockNumber;
|
|
@@ -29,7 +29,7 @@ export function randomDataInBlock<T>(data: T): DataInBlock<T> {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export async function wrapDataInBlock<T>(data: T, block:
|
|
32
|
+
export async function wrapDataInBlock<T>(data: T, block: L2Block): Promise<DataInBlock<T>> {
|
|
33
33
|
return {
|
|
34
34
|
data,
|
|
35
35
|
l2BlockNumber: block.number,
|
package/src/block/index.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -81,15 +81,15 @@ export interface L2BlockSource {
|
|
|
81
81
|
*/
|
|
82
82
|
getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined>;
|
|
83
83
|
|
|
84
|
-
getCheckpointedBlocks(from: BlockNumber, limit: number
|
|
84
|
+
getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]>;
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
* Retrieves a collection of
|
|
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
|
|
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.
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]>;
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* Gets the checkpoints for a given epoch
|
|
@@ -116,21 +116,21 @@ export interface L2BlockSource {
|
|
|
116
116
|
* @param number - The block number to return.
|
|
117
117
|
* @returns The requested L2 block (or undefined if not found).
|
|
118
118
|
*/
|
|
119
|
-
|
|
119
|
+
getL2Block(number: BlockNumber): Promise<L2Block | undefined>;
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* Gets an L2 block by its hash.
|
|
123
123
|
* @param blockHash - The block hash to retrieve.
|
|
124
124
|
* @returns The requested L2 block (or undefined if not found).
|
|
125
125
|
*/
|
|
126
|
-
|
|
126
|
+
getL2BlockByHash(blockHash: Fr): Promise<L2Block | undefined>;
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* Gets an L2 block by its archive root.
|
|
130
130
|
* @param archive - The archive root to retrieve.
|
|
131
131
|
* @returns The requested L2 block (or undefined if not found).
|
|
132
132
|
*/
|
|
133
|
-
|
|
133
|
+
getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined>;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Gets a tx effect.
|
|
@@ -157,11 +157,11 @@ export interface L2BlockSource {
|
|
|
157
157
|
getL2EpochNumber(): Promise<EpochNumber | undefined>;
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
|
-
* Returns all block headers for a given epoch.
|
|
160
|
+
* Returns all checkpointed block headers for a given epoch.
|
|
161
161
|
* @dev Use this method only with recent epochs, since it walks the block list backwards.
|
|
162
162
|
* @param epochNumber - The epoch number to return headers for.
|
|
163
163
|
*/
|
|
164
|
-
|
|
164
|
+
getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]>;
|
|
165
165
|
|
|
166
166
|
/**
|
|
167
167
|
* Returns whether the given epoch is completed on L1, based on the current L1 and L2 block numbers.
|
|
@@ -207,49 +207,43 @@ export interface L2BlockSource {
|
|
|
207
207
|
* @param number - The block number to return (inclusive).
|
|
208
208
|
* @returns The requested L2 block.
|
|
209
209
|
*/
|
|
210
|
-
getBlock(number: BlockNumber): Promise<
|
|
211
|
-
|
|
212
|
-
getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]>;
|
|
210
|
+
getBlock(number: BlockNumber): Promise<L2Block | undefined>;
|
|
213
211
|
|
|
214
212
|
/**
|
|
215
|
-
* Returns all blocks for a given epoch.
|
|
213
|
+
* Returns all checkpointed blocks for a given epoch.
|
|
216
214
|
* @dev Use this method only with recent epochs, since it walks the block list backwards.
|
|
217
215
|
* @param epochNumber - The epoch number to return blocks for.
|
|
218
216
|
*/
|
|
219
|
-
|
|
217
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]>;
|
|
220
218
|
|
|
221
219
|
/**
|
|
222
220
|
* Returns all blocks for a given slot.
|
|
223
221
|
* @dev Use this method only with recent slots, since it walks the block list backwards.
|
|
224
222
|
* @param slotNumber - The slot number to return blocks for.
|
|
225
223
|
*/
|
|
226
|
-
getBlocksForSlot(slotNumber: SlotNumber): Promise<
|
|
224
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]>;
|
|
227
225
|
|
|
228
226
|
/**
|
|
229
|
-
* Gets a
|
|
227
|
+
* Gets a checkpointed block by its block hash.
|
|
230
228
|
* @param blockHash - The block hash to retrieve.
|
|
231
229
|
* @returns The requested block (or undefined if not found).
|
|
232
230
|
*/
|
|
233
|
-
|
|
231
|
+
getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined>;
|
|
234
232
|
|
|
235
233
|
/**
|
|
236
|
-
* Gets a
|
|
234
|
+
* Gets a checkpointed block by its archive root.
|
|
237
235
|
* @param archive - The archive root to retrieve.
|
|
238
236
|
* @returns The requested block (or undefined if not found).
|
|
239
237
|
*/
|
|
240
|
-
|
|
238
|
+
getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined>;
|
|
241
239
|
|
|
242
240
|
/**
|
|
243
241
|
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
244
242
|
* @param from - Number of the first block to return (inclusive).
|
|
245
243
|
* @param limit - The maximum number of blocks to return.
|
|
246
|
-
* @param proven - If true, only return blocks that have been proven.
|
|
247
244
|
* @returns The requested L2 blocks.
|
|
248
245
|
*/
|
|
249
|
-
getBlocks(from: BlockNumber, limit: number
|
|
250
|
-
|
|
251
|
-
/** Equivalent to getBlocks but includes publish data. */
|
|
252
|
-
getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]>;
|
|
246
|
+
getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]>;
|
|
253
247
|
}
|
|
254
248
|
|
|
255
249
|
/**
|
|
@@ -261,7 +255,7 @@ export interface L2BlockSink {
|
|
|
261
255
|
* @param block - The L2 block to add.
|
|
262
256
|
* @throws If block number is not incremental (i.e., not exactly one more than the last stored block).
|
|
263
257
|
*/
|
|
264
|
-
addBlock(block:
|
|
258
|
+
addBlock(block: L2Block): Promise<void>;
|
|
265
259
|
}
|
|
266
260
|
|
|
267
261
|
/**
|
|
@@ -358,13 +352,13 @@ export type L2BlockProvenEvent = {
|
|
|
358
352
|
export type L2PruneUnprovenEvent = {
|
|
359
353
|
type: 'l2PruneUnproven';
|
|
360
354
|
epochNumber: EpochNumber;
|
|
361
|
-
blocks:
|
|
355
|
+
blocks: L2Block[];
|
|
362
356
|
};
|
|
363
357
|
|
|
364
358
|
export type L2PruneUncheckpointedEvent = {
|
|
365
359
|
type: 'l2PruneUncheckpointed';
|
|
366
360
|
slotNumber: SlotNumber;
|
|
367
|
-
blocks:
|
|
361
|
+
blocks: L2Block[];
|
|
368
362
|
};
|
|
369
363
|
|
|
370
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';
|
|
@@ -19,13 +19,12 @@ export class L2BlockStream {
|
|
|
19
19
|
constructor(
|
|
20
20
|
private l2BlockSource: Pick<
|
|
21
21
|
L2BlockSource,
|
|
22
|
-
'
|
|
22
|
+
'getBlocks' | 'getBlockHeader' | 'getL2Tips' | 'getCheckpoints' | 'getCheckpointedBlocks'
|
|
23
23
|
>,
|
|
24
24
|
private localData: L2BlockStreamLocalDataProvider,
|
|
25
25
|
private handler: L2BlockStreamEventHandler,
|
|
26
26
|
private readonly log = createLogger('types:block_stream'),
|
|
27
27
|
private opts: {
|
|
28
|
-
proven?: boolean;
|
|
29
28
|
pollIntervalMS?: number;
|
|
30
29
|
batchSize?: number;
|
|
31
30
|
startingBlock?: number;
|
|
@@ -129,7 +128,7 @@ export class L2BlockStream {
|
|
|
129
128
|
if (!this.opts.ignoreCheckpoints) {
|
|
130
129
|
let loop1Iterations = 0;
|
|
131
130
|
while (nextCheckpointToEmit <= sourceTips.checkpointed.checkpoint.number) {
|
|
132
|
-
const checkpoints = await this.l2BlockSource.
|
|
131
|
+
const checkpoints = await this.l2BlockSource.getCheckpoints(nextCheckpointToEmit, 1);
|
|
133
132
|
if (checkpoints.length === 0) {
|
|
134
133
|
break;
|
|
135
134
|
}
|
|
@@ -174,7 +173,7 @@ export class L2BlockStream {
|
|
|
174
173
|
// Refill the prefetch buffer when exhausted
|
|
175
174
|
if (prefetchIdx >= prefetchedCheckpoints.length) {
|
|
176
175
|
const prefetchLimit = this.opts.checkpointPrefetchLimit ?? CHECKPOINT_PREFETCH_LIMIT;
|
|
177
|
-
prefetchedCheckpoints = await this.l2BlockSource.
|
|
176
|
+
prefetchedCheckpoints = await this.l2BlockSource.getCheckpoints(nextCheckpointNumber, prefetchLimit);
|
|
178
177
|
prefetchIdx = 0;
|
|
179
178
|
if (prefetchedCheckpoints.length === 0) {
|
|
180
179
|
break;
|
|
@@ -213,8 +212,8 @@ export class L2BlockStream {
|
|
|
213
212
|
// Loop 3: Fetch any remaining uncheckpointed (proposed) blocks.
|
|
214
213
|
while (nextBlockNumber <= sourceTips.proposed.number) {
|
|
215
214
|
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.proposed.number - nextBlockNumber + 1);
|
|
216
|
-
this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit}
|
|
217
|
-
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));
|
|
218
217
|
if (blocks.length === 0) {
|
|
219
218
|
break;
|
|
220
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 } : {}),
|
|
@@ -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,
|
|
@@ -68,23 +68,22 @@ export class DelayedPublicMutableValues {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
static async readFromTree(delayedPublicMutableSlot: Fr, readStorage: (storageSlot: Fr) => Promise<Fr>) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return DelayedPublicMutableValues.fromFields(fields);
|
|
71
|
+
const fieldPromises = Array.from({ length: DELAYED_PUBLIC_MUTABLE_VALUES_LEN }).map((_, i) =>
|
|
72
|
+
readStorage(delayedPublicMutableSlot.add(new Fr(i))),
|
|
73
|
+
);
|
|
74
|
+
return DelayedPublicMutableValues.fromFields(await Promise.all(fieldPromises));
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
isEmpty(): boolean {
|
|
79
78
|
return this.svc.isEmpty() && this.sdc.isEmpty();
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
const
|
|
81
|
+
writeToTree(delayedPublicMutableSlot: Fr, storageWrite: (storageSlot: Fr, value: Fr) => Promise<void>) {
|
|
82
|
+
const fieldPromises = this.toFields().map((field, i) =>
|
|
83
|
+
storageWrite(delayedPublicMutableSlot.add(new Fr(i)), field),
|
|
84
|
+
);
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
await storageWrite(delayedPublicMutableSlot.add(new Fr(i)), fields[i]);
|
|
87
|
-
}
|
|
86
|
+
return Promise.all(fieldPromises);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
async hash(): Promise<Fr> {
|
|
@@ -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
|
|