@aztec/archiver 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6
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/README.md +156 -22
- package/dest/archiver.d.ts +138 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +732 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +11 -1
- package/dest/errors.d.ts +53 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +75 -0
- package/dest/factory.d.ts +8 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +90 -8
- package/dest/index.d.ts +11 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +135 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +402 -0
- package/dest/l1/data_retrieval.d.ts +88 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +54 -71
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
- package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +89 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +216 -0
- package/dest/modules/data_store_updater.d.ts +88 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +342 -0
- package/dest/modules/instrumentation.d.ts +50 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +36 -12
- package/dest/modules/l1_synchronizer.d.ts +72 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1147 -0
- package/dest/{archiver → modules}/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +6 -0
- package/dest/store/block_store.d.ts +195 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.js +248 -101
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +12 -8
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +367 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +481 -0
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +57 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +533 -0
- package/dest/store/message_store.d.ts +44 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +14 -1
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +202 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +455 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -3
- package/dest/test/mock_l2_block_source.d.ts +38 -19
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +183 -77
- package/dest/test/mock_structs.d.ts +81 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +152 -7
- package/dest/test/noop_l1_archiver.d.ts +26 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +72 -0
- package/package.json +16 -17
- package/src/archiver.ts +486 -0
- package/src/{archiver/config.ts → config.ts} +19 -1
- package/src/{archiver/errors.ts → errors.ts} +52 -24
- package/src/factory.ts +141 -10
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +511 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +75 -94
- package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
- package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +333 -0
- package/src/modules/data_store_updater.ts +464 -0
- package/src/{archiver → modules}/instrumentation.ts +46 -14
- package/src/modules/l1_synchronizer.ts +967 -0
- package/src/{archiver → modules}/validation.ts +5 -0
- package/src/{archiver/kv_archiver_store → store}/block_store.ts +309 -141
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +12 -8
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
- package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +294 -39
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +736 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +20 -1
- package/src/test/fake_l1_state.ts +698 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l2_block_source.ts +233 -93
- package/src/test/mock_structs.ts +283 -8
- package/src/test/noop_l1_archiver.ts +115 -0
- package/dest/archiver/archiver.d.ts +0 -307
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -2102
- package/dest/archiver/archiver_store.d.ts +0 -315
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/dest/archiver/config.d.ts +0 -22
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -54
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -164
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -159
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -316
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -401
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -40
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts +0 -112
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.js +0 -471
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -2265
- package/src/archiver/archiver_store.ts +0 -380
- package/src/archiver/archiver_store_test_suite.ts +0 -2842
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/log_store.ts +0 -516
- package/src/archiver/l1/README.md +0 -98
- package/src/archiver/l1/calldata_retriever.ts +0 -641
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
package/src/test/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export * from './mock_structs.js';
|
|
1
2
|
export * from './mock_l2_block_source.js';
|
|
2
3
|
export * from './mock_l1_to_l2_message_source.js';
|
|
3
4
|
export * from './mock_archiver.js';
|
|
5
|
+
// NOTE: noop_l1_archiver.js is intentionally NOT exported here because it imports
|
|
6
|
+
// jest-mock-extended, which depends on @jest/globals and can only run inside Jest.
|
|
7
|
+
// Import it directly: import { NoopL1Archiver } from '@aztec/archiver/test/noop-l1';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import {
|
|
3
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
4
4
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
5
5
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
6
6
|
|
|
@@ -56,8 +56,9 @@ export class MockPrefilledArchiver extends MockArchiver {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const fromBlock = this.l2Blocks.length;
|
|
59
|
-
|
|
60
|
-
this.
|
|
59
|
+
const checkpointsToAdd = this.prefilled.slice(fromBlock, fromBlock + numBlocks);
|
|
60
|
+
this.addProposedBlocks(checkpointsToAdd.flatMap(c => c.blocks));
|
|
61
|
+
this.checkpointList.push(...checkpointsToAdd);
|
|
61
62
|
return Promise.resolve();
|
|
62
63
|
}
|
|
63
64
|
}
|
|
@@ -8,19 +8,25 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
8
8
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
10
|
import {
|
|
11
|
+
type BlockData,
|
|
12
|
+
BlockHash,
|
|
11
13
|
CheckpointedL2Block,
|
|
12
14
|
L2Block,
|
|
13
|
-
L2BlockHash,
|
|
14
|
-
L2BlockNew,
|
|
15
15
|
type L2BlockSource,
|
|
16
16
|
type L2Tips,
|
|
17
|
-
PublishedL2Block,
|
|
18
17
|
type ValidateCheckpointResult,
|
|
19
18
|
} from '@aztec/stdlib/block';
|
|
20
|
-
import { type
|
|
19
|
+
import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
21
20
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
22
|
-
import {
|
|
23
|
-
|
|
21
|
+
import {
|
|
22
|
+
EmptyL1RollupConstants,
|
|
23
|
+
type L1RollupConstants,
|
|
24
|
+
getEpochAtSlot,
|
|
25
|
+
getSlotRangeForEpoch,
|
|
26
|
+
} from '@aztec/stdlib/epoch-helpers';
|
|
27
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
28
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
29
|
+
import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
24
30
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
25
31
|
|
|
26
32
|
/**
|
|
@@ -28,6 +34,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
28
34
|
*/
|
|
29
35
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
30
36
|
protected l2Blocks: L2Block[] = [];
|
|
37
|
+
protected checkpointList: Checkpoint[] = [];
|
|
31
38
|
|
|
32
39
|
private provenBlockNumber: number = 0;
|
|
33
40
|
private finalizedBlockNumber: number = 0;
|
|
@@ -35,23 +42,55 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
35
42
|
|
|
36
43
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
37
44
|
|
|
45
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
38
46
|
public async createBlocks(numBlocks: number) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
await this.createCheckpoints(numBlocks, 1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
51
|
+
return Promise.resolve(
|
|
52
|
+
this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
|
|
57
|
+
public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
|
|
58
|
+
for (let c = 0; c < numCheckpoints; c++) {
|
|
59
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
|
|
60
|
+
const startBlockNum = this.l2Blocks.length + 1;
|
|
61
|
+
const slotNumber = SlotNumber(Number(checkpointNum));
|
|
62
|
+
const checkpoint = await Checkpoint.random(checkpointNum, {
|
|
63
|
+
numBlocks: blocksPerCheckpoint,
|
|
64
|
+
startBlockNumber: startBlockNum,
|
|
65
|
+
slotNumber,
|
|
66
|
+
checkpointNumber: checkpointNum,
|
|
67
|
+
});
|
|
68
|
+
this.checkpointList.push(checkpoint);
|
|
69
|
+
this.l2Blocks.push(...checkpoint.blocks);
|
|
43
70
|
}
|
|
44
71
|
|
|
45
|
-
this.log.verbose(
|
|
72
|
+
this.log.verbose(
|
|
73
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
74
|
+
);
|
|
46
75
|
}
|
|
47
76
|
|
|
48
|
-
public
|
|
77
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
49
78
|
this.l2Blocks.push(...blocks);
|
|
50
|
-
this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
|
|
79
|
+
this.log.verbose(`Added ${blocks.length} proposed blocks to the mock L2 block source`);
|
|
51
80
|
}
|
|
52
81
|
|
|
53
82
|
public removeBlocks(numBlocks: number) {
|
|
54
83
|
this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
|
|
84
|
+
const maxBlockNum = this.l2Blocks.length;
|
|
85
|
+
// Remove any checkpoint whose last block is beyond the remaining blocks.
|
|
86
|
+
this.checkpointList = this.checkpointList.filter(c => {
|
|
87
|
+
const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
|
|
88
|
+
return lastBlockNum <= maxBlockNum;
|
|
89
|
+
});
|
|
90
|
+
// Keep tip numbers consistent with remaining blocks.
|
|
91
|
+
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
92
|
+
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
93
|
+
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
55
94
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
56
95
|
}
|
|
57
96
|
|
|
@@ -67,7 +106,33 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
67
106
|
}
|
|
68
107
|
|
|
69
108
|
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
109
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
70
110
|
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
111
|
+
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
112
|
+
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
113
|
+
const newCheckpoints: Checkpoint[] = [];
|
|
114
|
+
for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
|
|
115
|
+
const block = this.l2Blocks[blockNum - 1];
|
|
116
|
+
if (!block) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
|
|
123
|
+
const checkpoint = new Checkpoint(
|
|
124
|
+
block.archive,
|
|
125
|
+
CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
|
|
126
|
+
[block],
|
|
127
|
+
checkpointNum,
|
|
128
|
+
);
|
|
129
|
+
newCheckpoints.push(checkpoint);
|
|
130
|
+
}
|
|
131
|
+
// Insert new checkpoints in order by number.
|
|
132
|
+
if (newCheckpoints.length > 0) {
|
|
133
|
+
this.checkpointList.push(...newCheckpoints);
|
|
134
|
+
this.checkpointList.sort((a, b) => a.number - b.number);
|
|
135
|
+
}
|
|
71
136
|
}
|
|
72
137
|
|
|
73
138
|
/**
|
|
@@ -98,6 +163,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
98
163
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
99
164
|
}
|
|
100
165
|
|
|
166
|
+
public getCheckpointedL2BlockNumber() {
|
|
167
|
+
return Promise.resolve(BlockNumber(this.checkpointedBlockNumber));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public getFinalizedL2BlockNumber() {
|
|
171
|
+
return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
|
|
172
|
+
}
|
|
173
|
+
|
|
101
174
|
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
102
175
|
if (number > this.checkpointedBlockNumber) {
|
|
103
176
|
return Promise.resolve(undefined);
|
|
@@ -106,20 +179,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
106
179
|
if (!block) {
|
|
107
180
|
return Promise.resolve(undefined);
|
|
108
181
|
}
|
|
109
|
-
|
|
110
|
-
CheckpointNumber(number),
|
|
111
|
-
block.toL2Block(),
|
|
112
|
-
new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
|
|
113
|
-
[],
|
|
114
|
-
);
|
|
115
|
-
return Promise.resolve(checkpointedBlock);
|
|
182
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
116
183
|
}
|
|
117
184
|
|
|
118
|
-
public async getCheckpointedBlocks(
|
|
119
|
-
from: BlockNumber,
|
|
120
|
-
limit: number,
|
|
121
|
-
_proven?: boolean,
|
|
122
|
-
): Promise<CheckpointedL2Block[]> {
|
|
185
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
123
186
|
const result: CheckpointedL2Block[] = [];
|
|
124
187
|
for (let i = 0; i < limit; i++) {
|
|
125
188
|
const blockNum = from + i;
|
|
@@ -139,8 +202,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
139
202
|
* @param number - The block number to return (inclusive).
|
|
140
203
|
* @returns The requested L2 block.
|
|
141
204
|
*/
|
|
142
|
-
public getBlock(number: number) {
|
|
143
|
-
|
|
205
|
+
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
206
|
+
const block = this.l2Blocks[number - 1];
|
|
207
|
+
return Promise.resolve(block);
|
|
144
208
|
}
|
|
145
209
|
|
|
146
210
|
/**
|
|
@@ -148,9 +212,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
148
212
|
* @param number - The block number to return.
|
|
149
213
|
* @returns The requested L2 block.
|
|
150
214
|
*/
|
|
151
|
-
public
|
|
215
|
+
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
152
216
|
const block = this.l2Blocks[number - 1];
|
|
153
|
-
return Promise.resolve(block
|
|
217
|
+
return Promise.resolve(block);
|
|
154
218
|
}
|
|
155
219
|
|
|
156
220
|
/**
|
|
@@ -159,73 +223,60 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
159
223
|
* @param limit - The maximum number of blocks to return.
|
|
160
224
|
* @returns The requested mocked L2 blocks.
|
|
161
225
|
*/
|
|
162
|
-
public getBlocks(from: number, limit: number
|
|
163
|
-
return Promise.resolve(
|
|
164
|
-
this.l2Blocks
|
|
165
|
-
.slice(from - 1, from - 1 + limit)
|
|
166
|
-
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public async getPublishedCheckpoints(from: CheckpointNumber, limit: number) {
|
|
171
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
172
|
-
return (await this.getPublishedBlocks(from, limit)).map(block => block.toPublishedCheckpoint());
|
|
226
|
+
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
227
|
+
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
173
228
|
}
|
|
174
229
|
|
|
175
|
-
public
|
|
176
|
-
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
public async getPublishedBlocks(from: number, limit: number, proven?: boolean) {
|
|
181
|
-
const blocks = await this.getBlocks(from, limit, proven);
|
|
182
|
-
return blocks.map(block =>
|
|
183
|
-
PublishedL2Block.fromFields({
|
|
184
|
-
block,
|
|
185
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
186
|
-
attestations: [],
|
|
187
|
-
}),
|
|
230
|
+
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
231
|
+
const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
|
|
232
|
+
return Promise.resolve(
|
|
233
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
188
234
|
);
|
|
189
235
|
}
|
|
190
236
|
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
return
|
|
237
|
+
public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
238
|
+
const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
|
|
239
|
+
return Promise.resolve(checkpoint);
|
|
194
240
|
}
|
|
195
241
|
|
|
196
|
-
public async
|
|
242
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
197
243
|
for (const block of this.l2Blocks) {
|
|
198
244
|
const hash = await block.hash();
|
|
199
245
|
if (hash.equals(blockHash)) {
|
|
200
|
-
return
|
|
201
|
-
block,
|
|
202
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
203
|
-
attestations: [],
|
|
204
|
-
});
|
|
246
|
+
return this.toCheckpointedBlock(block);
|
|
205
247
|
}
|
|
206
248
|
}
|
|
207
249
|
return undefined;
|
|
208
250
|
}
|
|
209
251
|
|
|
210
|
-
public
|
|
252
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
211
253
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
212
254
|
if (!block) {
|
|
213
255
|
return Promise.resolve(undefined);
|
|
214
256
|
}
|
|
215
|
-
return Promise.resolve(
|
|
216
|
-
PublishedL2Block.fromFields({
|
|
217
|
-
block,
|
|
218
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
219
|
-
attestations: [],
|
|
220
|
-
}),
|
|
221
|
-
);
|
|
257
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
222
258
|
}
|
|
223
259
|
|
|
224
|
-
public async
|
|
260
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
225
261
|
for (const block of this.l2Blocks) {
|
|
226
262
|
const hash = await block.hash();
|
|
227
263
|
if (hash.equals(blockHash)) {
|
|
228
|
-
return block
|
|
264
|
+
return block;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
public getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
271
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
272
|
+
return Promise.resolve(block);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
276
|
+
for (const block of this.l2Blocks) {
|
|
277
|
+
const hash = await block.hash();
|
|
278
|
+
if (hash.equals(blockHash)) {
|
|
279
|
+
return block.header;
|
|
229
280
|
}
|
|
230
281
|
}
|
|
231
282
|
return undefined;
|
|
@@ -233,31 +284,80 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
233
284
|
|
|
234
285
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
235
286
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
236
|
-
return Promise.resolve(block?.
|
|
287
|
+
return Promise.resolve(block?.header);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public async getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
291
|
+
const block = this.l2Blocks[number - 1];
|
|
292
|
+
if (!block) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
header: block.header,
|
|
297
|
+
archive: block.archive,
|
|
298
|
+
blockHash: await block.hash(),
|
|
299
|
+
checkpointNumber: block.checkpointNumber,
|
|
300
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public async getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
305
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
306
|
+
if (!block) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
header: block.header,
|
|
311
|
+
archive: block.archive,
|
|
312
|
+
blockHash: await block.hash(),
|
|
313
|
+
checkpointNumber: block.checkpointNumber,
|
|
314
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
315
|
+
};
|
|
237
316
|
}
|
|
238
317
|
|
|
239
318
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
240
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.
|
|
319
|
+
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
241
320
|
}
|
|
242
321
|
|
|
243
322
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
244
|
-
|
|
245
|
-
return this.getBlocksForEpoch(epochNumber).then(blocks => blocks.map(b => b.toCheckpoint()));
|
|
323
|
+
return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
|
|
246
324
|
}
|
|
247
325
|
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
326
|
+
getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
327
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
328
|
+
return Promise.resolve(
|
|
329
|
+
checkpoints.map(
|
|
330
|
+
(checkpoint): CheckpointData => ({
|
|
331
|
+
checkpointNumber: checkpoint.number,
|
|
332
|
+
header: checkpoint.header,
|
|
333
|
+
archive: checkpoint.archive,
|
|
334
|
+
checkpointOutHash: computeCheckpointOutHash(
|
|
335
|
+
checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
336
|
+
),
|
|
337
|
+
startBlock: checkpoint.blocks[0].number,
|
|
338
|
+
blockCount: checkpoint.blocks.length,
|
|
339
|
+
attestations: [],
|
|
340
|
+
l1: this.mockL1DataForCheckpoint(checkpoint),
|
|
341
|
+
}),
|
|
342
|
+
),
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
347
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
348
|
+
return Promise.resolve(
|
|
349
|
+
checkpoints.flatMap(checkpoint => checkpoint.blocks.map(block => this.toCheckpointedBlock(block))),
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
354
|
+
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
255
355
|
return Promise.resolve(blocks);
|
|
256
356
|
}
|
|
257
357
|
|
|
258
|
-
async
|
|
259
|
-
const
|
|
260
|
-
return
|
|
358
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
359
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
360
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
261
361
|
}
|
|
262
362
|
|
|
263
363
|
/**
|
|
@@ -276,7 +376,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
276
376
|
return {
|
|
277
377
|
data: txEffect,
|
|
278
378
|
l2BlockNumber: block.number,
|
|
279
|
-
l2BlockHash:
|
|
379
|
+
l2BlockHash: await block.hash(),
|
|
280
380
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
281
381
|
};
|
|
282
382
|
}
|
|
@@ -290,13 +390,16 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
290
390
|
for (const block of this.l2Blocks) {
|
|
291
391
|
for (const txEffect of block.body.txEffects) {
|
|
292
392
|
if (txEffect.txHash.equals(txHash)) {
|
|
393
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
293
394
|
return new TxReceipt(
|
|
294
395
|
txHash,
|
|
295
|
-
TxStatus.
|
|
296
|
-
|
|
396
|
+
TxStatus.CHECKPOINTED,
|
|
397
|
+
TxExecutionResult.SUCCESS,
|
|
398
|
+
undefined,
|
|
297
399
|
txEffect.transactionFee.toBigInt(),
|
|
298
|
-
|
|
400
|
+
await block.hash(),
|
|
299
401
|
block.number,
|
|
402
|
+
getEpochAtSlot(block.slot, EmptyL1RollupConstants),
|
|
300
403
|
);
|
|
301
404
|
}
|
|
302
405
|
}
|
|
@@ -336,7 +439,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
336
439
|
|
|
337
440
|
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
338
441
|
block: blockId,
|
|
339
|
-
checkpoint: {
|
|
442
|
+
checkpoint: {
|
|
443
|
+
number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
|
|
444
|
+
hash: blockId.hash,
|
|
445
|
+
},
|
|
340
446
|
});
|
|
341
447
|
|
|
342
448
|
return {
|
|
@@ -347,11 +453,11 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
347
453
|
};
|
|
348
454
|
}
|
|
349
455
|
|
|
350
|
-
|
|
456
|
+
getSyncedL2EpochNumber(): Promise<EpochNumber> {
|
|
351
457
|
throw new Error('Method not implemented.');
|
|
352
458
|
}
|
|
353
459
|
|
|
354
|
-
|
|
460
|
+
getSyncedL2SlotNumber(): Promise<SlotNumber> {
|
|
355
461
|
throw new Error('Method not implemented.');
|
|
356
462
|
}
|
|
357
463
|
|
|
@@ -424,4 +530,38 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
424
530
|
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
425
531
|
return Promise.resolve({ valid: true });
|
|
426
532
|
}
|
|
533
|
+
|
|
534
|
+
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
535
|
+
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
536
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
537
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
538
|
+
return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Creates a mock L1PublishedData for a checkpoint. */
|
|
542
|
+
private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
|
|
543
|
+
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** Creates a CheckpointedL2Block from a block using stored checkpoint info. */
|
|
547
|
+
private toCheckpointedBlock(block: L2Block): CheckpointedL2Block {
|
|
548
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === block.number));
|
|
549
|
+
const checkpointNumber = checkpoint?.number ?? block.checkpointNumber;
|
|
550
|
+
return new CheckpointedL2Block(
|
|
551
|
+
checkpointNumber,
|
|
552
|
+
block,
|
|
553
|
+
new L1PublishedData(
|
|
554
|
+
BigInt(block.number),
|
|
555
|
+
BigInt(block.number),
|
|
556
|
+
`0x${block.number.toString(16).padStart(64, '0')}`,
|
|
557
|
+
),
|
|
558
|
+
[],
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
|
|
563
|
+
private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
|
|
564
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
|
|
565
|
+
return checkpoint?.number;
|
|
566
|
+
}
|
|
427
567
|
}
|