@aztec/archiver 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e
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 +162 -22
- package/dest/archiver.d.ts +140 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +750 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +12 -2
- package/dest/errors.d.ts +65 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +91 -0
- package/dest/factory.d.ts +8 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +96 -13
- 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 +403 -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 +59 -77
- 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 +91 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +222 -0
- package/dest/modules/data_store_updater.d.ts +86 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +333 -0
- package/dest/modules/instrumentation.d.ts +52 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +53 -18
- package/dest/modules/l1_synchronizer.d.ts +73 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1154 -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 +8 -2
- package/dest/store/block_store.d.ts +230 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +942 -0
- package/dest/store/contract_class_store.d.ts +17 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/store/contract_class_store.js +64 -0
- 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 +7 -3
- package/dest/store/kv_archiver_store.d.ts +377 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +494 -0
- package/dest/store/l2_tips_cache.d.ts +20 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +109 -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 +531 -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 +21 -9
- 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 +210 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +490 -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_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +43 -19
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +211 -80
- 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 +71 -0
- package/package.json +16 -17
- package/src/archiver.ts +510 -0
- package/src/{archiver/config.ts → config.ts} +20 -2
- package/src/errors.ts +146 -0
- package/src/factory.ts +152 -16
- 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 +512 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +79 -102
- 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 +347 -0
- package/src/modules/data_store_updater.ts +437 -0
- package/src/{archiver → modules}/instrumentation.ts +64 -20
- package/src/modules/l1_synchronizer.ts +961 -0
- package/src/{archiver → modules}/validation.ts +7 -2
- package/src/store/block_store.ts +1245 -0
- package/src/store/contract_class_store.ts +82 -0
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +9 -6
- package/src/store/kv_archiver_store.ts +713 -0
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +733 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +27 -10
- package/src/{archiver/structs → structs}/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +747 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +269 -94
- package/src/test/mock_structs.ts +283 -8
- package/src/test/noop_l1_archiver.ts +114 -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/block_store.js +0 -626
- 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_class_store.js +0 -120
- 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/errors.ts +0 -90
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -850
- package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -442
- 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}/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,31 @@ 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 {
|
|
19
|
+
import {
|
|
20
|
+
Checkpoint,
|
|
21
|
+
type CheckpointData,
|
|
22
|
+
L1PublishedData,
|
|
23
|
+
type ProposedCheckpointData,
|
|
24
|
+
PublishedCheckpoint,
|
|
25
|
+
} from '@aztec/stdlib/checkpoint';
|
|
21
26
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
22
|
-
import {
|
|
23
|
-
|
|
27
|
+
import {
|
|
28
|
+
EmptyL1RollupConstants,
|
|
29
|
+
type L1RollupConstants,
|
|
30
|
+
getEpochAtSlot,
|
|
31
|
+
getSlotRangeForEpoch,
|
|
32
|
+
} from '@aztec/stdlib/epoch-helpers';
|
|
33
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
34
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
35
|
+
import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
24
36
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
25
37
|
|
|
26
38
|
/**
|
|
@@ -28,30 +40,65 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
28
40
|
*/
|
|
29
41
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
30
42
|
protected l2Blocks: L2Block[] = [];
|
|
43
|
+
protected checkpointList: Checkpoint[] = [];
|
|
31
44
|
|
|
32
45
|
private provenBlockNumber: number = 0;
|
|
33
46
|
private finalizedBlockNumber: number = 0;
|
|
34
47
|
private checkpointedBlockNumber: number = 0;
|
|
48
|
+
private proposedCheckpointBlockNumber: number = 0;
|
|
35
49
|
|
|
36
50
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
37
51
|
|
|
52
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
38
53
|
public async createBlocks(numBlocks: number) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
await this.createCheckpoints(numBlocks, 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
58
|
+
return Promise.resolve(
|
|
59
|
+
this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
|
|
64
|
+
public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
|
|
65
|
+
for (let c = 0; c < numCheckpoints; c++) {
|
|
66
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
|
|
67
|
+
const startBlockNum = this.l2Blocks.length + 1;
|
|
68
|
+
const slotNumber = SlotNumber(Number(checkpointNum));
|
|
69
|
+
const checkpoint = await Checkpoint.random(checkpointNum, {
|
|
70
|
+
numBlocks: blocksPerCheckpoint,
|
|
71
|
+
startBlockNumber: startBlockNum,
|
|
72
|
+
slotNumber,
|
|
73
|
+
checkpointNumber: checkpointNum,
|
|
74
|
+
});
|
|
75
|
+
this.checkpointList.push(checkpoint);
|
|
76
|
+
this.l2Blocks.push(...checkpoint.blocks);
|
|
43
77
|
}
|
|
44
78
|
|
|
45
|
-
this.log.verbose(
|
|
79
|
+
this.log.verbose(
|
|
80
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
81
|
+
);
|
|
46
82
|
}
|
|
47
83
|
|
|
48
|
-
public
|
|
84
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
49
85
|
this.l2Blocks.push(...blocks);
|
|
50
|
-
this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
|
|
86
|
+
this.log.verbose(`Added ${blocks.length} proposed blocks to the mock L2 block source`);
|
|
51
87
|
}
|
|
52
88
|
|
|
53
89
|
public removeBlocks(numBlocks: number) {
|
|
54
90
|
this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
|
|
91
|
+
const maxBlockNum = this.l2Blocks.length;
|
|
92
|
+
// Remove any checkpoint whose last block is beyond the remaining blocks.
|
|
93
|
+
this.checkpointList = this.checkpointList.filter(c => {
|
|
94
|
+
const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
|
|
95
|
+
return lastBlockNum <= maxBlockNum;
|
|
96
|
+
});
|
|
97
|
+
// Keep tip numbers consistent with remaining blocks.
|
|
98
|
+
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
99
|
+
this.proposedCheckpointBlockNumber = Math.min(this.proposedCheckpointBlockNumber, maxBlockNum);
|
|
100
|
+
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
101
|
+
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
55
102
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
56
103
|
}
|
|
57
104
|
|
|
@@ -66,8 +113,42 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
66
113
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
67
114
|
}
|
|
68
115
|
|
|
116
|
+
public setProposedCheckpointBlockNumber(blockNumber: number) {
|
|
117
|
+
this.proposedCheckpointBlockNumber = blockNumber;
|
|
118
|
+
}
|
|
119
|
+
|
|
69
120
|
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
121
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
70
122
|
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
123
|
+
// Proposed checkpoint is always at least as advanced as checkpointed
|
|
124
|
+
if (this.proposedCheckpointBlockNumber < checkpointedBlockNumber) {
|
|
125
|
+
this.proposedCheckpointBlockNumber = checkpointedBlockNumber;
|
|
126
|
+
}
|
|
127
|
+
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
128
|
+
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
129
|
+
const newCheckpoints: Checkpoint[] = [];
|
|
130
|
+
for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
|
|
131
|
+
const block = this.l2Blocks[blockNum - 1];
|
|
132
|
+
if (!block) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
|
|
139
|
+
const checkpoint = new Checkpoint(
|
|
140
|
+
block.archive,
|
|
141
|
+
CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
|
|
142
|
+
[block],
|
|
143
|
+
checkpointNum,
|
|
144
|
+
);
|
|
145
|
+
newCheckpoints.push(checkpoint);
|
|
146
|
+
}
|
|
147
|
+
// Insert new checkpoints in order by number.
|
|
148
|
+
if (newCheckpoints.length > 0) {
|
|
149
|
+
this.checkpointList.push(...newCheckpoints);
|
|
150
|
+
this.checkpointList.sort((a, b) => a.number - b.number);
|
|
151
|
+
}
|
|
71
152
|
}
|
|
72
153
|
|
|
73
154
|
/**
|
|
@@ -98,6 +179,18 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
98
179
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
99
180
|
}
|
|
100
181
|
|
|
182
|
+
public getCheckpointedL2BlockNumber() {
|
|
183
|
+
return Promise.resolve(BlockNumber(this.checkpointedBlockNumber));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public getFinalizedL2BlockNumber() {
|
|
187
|
+
return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public getProposedCheckpointL2BlockNumber() {
|
|
191
|
+
return Promise.resolve(BlockNumber(this.proposedCheckpointBlockNumber));
|
|
192
|
+
}
|
|
193
|
+
|
|
101
194
|
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
102
195
|
if (number > this.checkpointedBlockNumber) {
|
|
103
196
|
return Promise.resolve(undefined);
|
|
@@ -106,20 +199,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
106
199
|
if (!block) {
|
|
107
200
|
return Promise.resolve(undefined);
|
|
108
201
|
}
|
|
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);
|
|
202
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
116
203
|
}
|
|
117
204
|
|
|
118
|
-
public async getCheckpointedBlocks(
|
|
119
|
-
from: BlockNumber,
|
|
120
|
-
limit: number,
|
|
121
|
-
_proven?: boolean,
|
|
122
|
-
): Promise<CheckpointedL2Block[]> {
|
|
205
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
123
206
|
const result: CheckpointedL2Block[] = [];
|
|
124
207
|
for (let i = 0; i < limit; i++) {
|
|
125
208
|
const blockNum = from + i;
|
|
@@ -139,8 +222,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
139
222
|
* @param number - The block number to return (inclusive).
|
|
140
223
|
* @returns The requested L2 block.
|
|
141
224
|
*/
|
|
142
|
-
public getBlock(number: number) {
|
|
143
|
-
|
|
225
|
+
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
226
|
+
const block = this.l2Blocks[number - 1];
|
|
227
|
+
return Promise.resolve(block);
|
|
144
228
|
}
|
|
145
229
|
|
|
146
230
|
/**
|
|
@@ -148,9 +232,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
148
232
|
* @param number - The block number to return.
|
|
149
233
|
* @returns The requested L2 block.
|
|
150
234
|
*/
|
|
151
|
-
public
|
|
235
|
+
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
152
236
|
const block = this.l2Blocks[number - 1];
|
|
153
|
-
return Promise.resolve(block
|
|
237
|
+
return Promise.resolve(block);
|
|
154
238
|
}
|
|
155
239
|
|
|
156
240
|
/**
|
|
@@ -159,73 +243,60 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
159
243
|
* @param limit - The maximum number of blocks to return.
|
|
160
244
|
* @returns The requested mocked L2 blocks.
|
|
161
245
|
*/
|
|
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
|
-
);
|
|
246
|
+
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
247
|
+
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
168
248
|
}
|
|
169
249
|
|
|
170
|
-
public
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
176
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
177
|
-
return (await this.getPublishedBlockByArchive(archive))?.block.toCheckpoint();
|
|
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
|
-
}),
|
|
250
|
+
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
251
|
+
const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
|
|
252
|
+
return Promise.resolve(
|
|
253
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
188
254
|
);
|
|
189
255
|
}
|
|
190
256
|
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
return
|
|
257
|
+
public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
258
|
+
const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
|
|
259
|
+
return Promise.resolve(checkpoint);
|
|
194
260
|
}
|
|
195
261
|
|
|
196
|
-
public async
|
|
262
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
197
263
|
for (const block of this.l2Blocks) {
|
|
198
264
|
const hash = await block.hash();
|
|
199
265
|
if (hash.equals(blockHash)) {
|
|
200
|
-
return
|
|
201
|
-
block,
|
|
202
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
203
|
-
attestations: [],
|
|
204
|
-
});
|
|
266
|
+
return this.toCheckpointedBlock(block);
|
|
205
267
|
}
|
|
206
268
|
}
|
|
207
269
|
return undefined;
|
|
208
270
|
}
|
|
209
271
|
|
|
210
|
-
public
|
|
272
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
211
273
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
212
274
|
if (!block) {
|
|
213
275
|
return Promise.resolve(undefined);
|
|
214
276
|
}
|
|
215
|
-
return Promise.resolve(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
277
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
281
|
+
for (const block of this.l2Blocks) {
|
|
282
|
+
const hash = await block.hash();
|
|
283
|
+
if (hash.equals(blockHash)) {
|
|
284
|
+
return block;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return undefined;
|
|
222
288
|
}
|
|
223
289
|
|
|
224
|
-
public
|
|
290
|
+
public getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
291
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
292
|
+
return Promise.resolve(block);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
225
296
|
for (const block of this.l2Blocks) {
|
|
226
297
|
const hash = await block.hash();
|
|
227
298
|
if (hash.equals(blockHash)) {
|
|
228
|
-
return block.
|
|
299
|
+
return block.header;
|
|
229
300
|
}
|
|
230
301
|
}
|
|
231
302
|
return undefined;
|
|
@@ -233,31 +304,80 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
233
304
|
|
|
234
305
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
235
306
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
236
|
-
return Promise.resolve(block?.
|
|
307
|
+
return Promise.resolve(block?.header);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public async getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
311
|
+
const block = this.l2Blocks[number - 1];
|
|
312
|
+
if (!block) {
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
header: block.header,
|
|
317
|
+
archive: block.archive,
|
|
318
|
+
blockHash: await block.hash(),
|
|
319
|
+
checkpointNumber: block.checkpointNumber,
|
|
320
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public async getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
325
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
326
|
+
if (!block) {
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
header: block.header,
|
|
331
|
+
archive: block.archive,
|
|
332
|
+
blockHash: await block.hash(),
|
|
333
|
+
checkpointNumber: block.checkpointNumber,
|
|
334
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
335
|
+
};
|
|
237
336
|
}
|
|
238
337
|
|
|
239
338
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
240
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.
|
|
339
|
+
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
241
340
|
}
|
|
242
341
|
|
|
243
342
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
244
|
-
|
|
245
|
-
return this.getBlocksForEpoch(epochNumber).then(blocks => blocks.map(b => b.toCheckpoint()));
|
|
343
|
+
return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
|
|
246
344
|
}
|
|
247
345
|
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
346
|
+
getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
347
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
348
|
+
return Promise.resolve(
|
|
349
|
+
checkpoints.map(
|
|
350
|
+
(checkpoint): CheckpointData => ({
|
|
351
|
+
checkpointNumber: checkpoint.number,
|
|
352
|
+
header: checkpoint.header,
|
|
353
|
+
archive: checkpoint.archive,
|
|
354
|
+
checkpointOutHash: computeCheckpointOutHash(
|
|
355
|
+
checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
356
|
+
),
|
|
357
|
+
startBlock: checkpoint.blocks[0].number,
|
|
358
|
+
blockCount: checkpoint.blocks.length,
|
|
359
|
+
attestations: [],
|
|
360
|
+
l1: this.mockL1DataForCheckpoint(checkpoint),
|
|
361
|
+
}),
|
|
362
|
+
),
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
367
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
368
|
+
return Promise.resolve(
|
|
369
|
+
checkpoints.flatMap(checkpoint => checkpoint.blocks.map(block => this.toCheckpointedBlock(block))),
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
374
|
+
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
255
375
|
return Promise.resolve(blocks);
|
|
256
376
|
}
|
|
257
377
|
|
|
258
|
-
async
|
|
259
|
-
const
|
|
260
|
-
return
|
|
378
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
379
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
380
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
261
381
|
}
|
|
262
382
|
|
|
263
383
|
/**
|
|
@@ -276,7 +396,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
276
396
|
return {
|
|
277
397
|
data: txEffect,
|
|
278
398
|
l2BlockNumber: block.number,
|
|
279
|
-
l2BlockHash:
|
|
399
|
+
l2BlockHash: await block.hash(),
|
|
280
400
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
281
401
|
};
|
|
282
402
|
}
|
|
@@ -290,13 +410,16 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
290
410
|
for (const block of this.l2Blocks) {
|
|
291
411
|
for (const txEffect of block.body.txEffects) {
|
|
292
412
|
if (txEffect.txHash.equals(txHash)) {
|
|
413
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
293
414
|
return new TxReceipt(
|
|
294
415
|
txHash,
|
|
295
|
-
TxStatus.
|
|
296
|
-
|
|
416
|
+
TxStatus.CHECKPOINTED,
|
|
417
|
+
TxExecutionResult.SUCCESS,
|
|
418
|
+
undefined,
|
|
297
419
|
txEffect.transactionFee.toBigInt(),
|
|
298
|
-
|
|
420
|
+
await block.hash(),
|
|
299
421
|
block.number,
|
|
422
|
+
getEpochAtSlot(block.slot, EmptyL1RollupConstants),
|
|
300
423
|
);
|
|
301
424
|
}
|
|
302
425
|
}
|
|
@@ -305,17 +428,19 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
305
428
|
}
|
|
306
429
|
|
|
307
430
|
async getL2Tips(): Promise<L2Tips> {
|
|
308
|
-
const [latest, proven, finalized, checkpointed] = [
|
|
431
|
+
const [latest, proven, finalized, checkpointed, proposedCheckpoint] = [
|
|
309
432
|
await this.getBlockNumber(),
|
|
310
433
|
await this.getProvenBlockNumber(),
|
|
311
434
|
this.finalizedBlockNumber,
|
|
312
435
|
this.checkpointedBlockNumber,
|
|
436
|
+
await this.getProposedCheckpointL2BlockNumber(),
|
|
313
437
|
] as const;
|
|
314
438
|
|
|
315
439
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
316
440
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
317
441
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
318
442
|
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
443
|
+
const proposedCheckpointBlock = this.l2Blocks[proposedCheckpoint - 1];
|
|
319
444
|
|
|
320
445
|
const latestBlockId = {
|
|
321
446
|
number: BlockNumber(latest),
|
|
@@ -333,10 +458,17 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
333
458
|
number: BlockNumber(checkpointed),
|
|
334
459
|
hash: (await checkpointedBlock?.hash())?.toString(),
|
|
335
460
|
};
|
|
461
|
+
const proposedCheckpointBlockId = {
|
|
462
|
+
number: BlockNumber(proposedCheckpoint),
|
|
463
|
+
hash: (await proposedCheckpointBlock?.hash())?.toString(),
|
|
464
|
+
};
|
|
336
465
|
|
|
337
466
|
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
338
467
|
block: blockId,
|
|
339
|
-
checkpoint: {
|
|
468
|
+
checkpoint: {
|
|
469
|
+
number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
|
|
470
|
+
hash: blockId.hash,
|
|
471
|
+
},
|
|
340
472
|
});
|
|
341
473
|
|
|
342
474
|
return {
|
|
@@ -344,14 +476,15 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
344
476
|
checkpointed: makeTipId(checkpointedBlockId),
|
|
345
477
|
proven: makeTipId(provenBlockId),
|
|
346
478
|
finalized: makeTipId(finalizedBlockId),
|
|
479
|
+
proposedCheckpoint: makeTipId(proposedCheckpointBlockId),
|
|
347
480
|
};
|
|
348
481
|
}
|
|
349
482
|
|
|
350
|
-
|
|
483
|
+
getSyncedL2EpochNumber(): Promise<EpochNumber> {
|
|
351
484
|
throw new Error('Method not implemented.');
|
|
352
485
|
}
|
|
353
486
|
|
|
354
|
-
|
|
487
|
+
getSyncedL2SlotNumber(): Promise<SlotNumber> {
|
|
355
488
|
throw new Error('Method not implemented.');
|
|
356
489
|
}
|
|
357
490
|
|
|
@@ -424,4 +557,46 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
424
557
|
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
425
558
|
return Promise.resolve({ valid: true });
|
|
426
559
|
}
|
|
560
|
+
|
|
561
|
+
getProposedCheckpoint(): Promise<ProposedCheckpointData | undefined> {
|
|
562
|
+
return Promise.resolve(undefined);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
566
|
+
return Promise.resolve(undefined);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
570
|
+
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
571
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
572
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
573
|
+
return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** Creates a mock L1PublishedData for a checkpoint. */
|
|
577
|
+
private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
|
|
578
|
+
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** Creates a CheckpointedL2Block from a block using stored checkpoint info. */
|
|
582
|
+
private toCheckpointedBlock(block: L2Block): CheckpointedL2Block {
|
|
583
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === block.number));
|
|
584
|
+
const checkpointNumber = checkpoint?.number ?? block.checkpointNumber;
|
|
585
|
+
return new CheckpointedL2Block(
|
|
586
|
+
checkpointNumber,
|
|
587
|
+
block,
|
|
588
|
+
new L1PublishedData(
|
|
589
|
+
BigInt(block.number),
|
|
590
|
+
BigInt(block.number),
|
|
591
|
+
`0x${block.number.toString(16).padStart(64, '0')}`,
|
|
592
|
+
),
|
|
593
|
+
[],
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
|
|
598
|
+
private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
|
|
599
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
|
|
600
|
+
return checkpoint?.number;
|
|
601
|
+
}
|
|
427
602
|
}
|