@aztec/archiver 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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} +24 -7
- 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 +99 -15
- 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/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/l1/bin/retrieve-calldata.js +152 -0
- 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}/data_retrieval.js +87 -160
- package/dest/l1/debug_tx.d.ts +19 -0
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/l1/debug_tx.js +73 -0
- package/dest/l1/spire_proposer.d.ts +70 -0
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/l1/spire_proposer.js +149 -0
- package/dest/l1/trace_tx.d.ts +97 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/trace_tx.js +91 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/l1/types.js +3 -0
- package/dest/l1/validate_trace.d.ts +32 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +154 -0
- 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/modules/instrumentation.js +138 -0
- 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/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +9 -3
- 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 +36 -23
- 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}/inbox_message.js +6 -5
- package/dest/structs/published.d.ts +2 -0
- 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 +16 -8
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +19 -14
- package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +23 -12
- package/dest/test/mock_l2_block_source.d.ts +59 -20
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +276 -85
- package/dest/test/mock_structs.d.ts +83 -4
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +157 -11
- 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 +20 -20
- package/src/archiver.ts +510 -0
- package/src/{archiver/config.ts → config.ts} +37 -14
- package/src/errors.ts +146 -0
- package/src/factory.ts +154 -17
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/l1/bin/retrieve-calldata.ts +194 -0
- package/src/l1/calldata_retriever.ts +512 -0
- package/src/{archiver → l1}/data_retrieval.ts +146 -233
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +152 -0
- package/src/l1/trace_tx.ts +128 -0
- package/src/l1/types.ts +13 -0
- package/src/l1/validate_trace.ts +229 -0
- package/src/modules/data_source_base.ts +347 -0
- package/src/modules/data_store_updater.ts +437 -0
- package/src/modules/instrumentation.ts +196 -0
- package/src/modules/l1_synchronizer.ts +961 -0
- package/src/{archiver → modules}/validation.ts +13 -8
- 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 +10 -7
- 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 +48 -28
- package/src/{archiver/structs → structs}/inbox_message.ts +7 -7
- package/src/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +747 -0
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +23 -16
- package/src/test/mock_l1_to_l2_message_source.ts +19 -11
- package/src/test/mock_l2_block_source.ts +346 -93
- package/src/test/mock_structs.ts +289 -13
- package/src/test/noop_l1_archiver.ts +114 -0
- package/dest/archiver/archiver.d.ts +0 -287
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1408
- package/dest/archiver/archiver_store.d.ts +0 -255
- 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 -1289
- package/dest/archiver/config.d.ts +0 -21
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.d.ts +0 -79
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- 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 -35
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/instrumentation.js +0 -140
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -370
- 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 -168
- 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 -296
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -336
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
- package/dest/archiver/kv_archiver_store/message_store.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 +0 -3
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- 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 -1858
- package/src/archiver/archiver_store.ts +0 -305
- package/src/archiver/archiver_store_test_suite.ts +0 -1264
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/instrumentation.ts +0 -187
- package/src/archiver/kv_archiver_store/block_store.ts +0 -481
- package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
- package/src/archiver/kv_archiver_store/log_store.ts +0 -406
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
|
-
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
3
|
-
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
7
|
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,
|
|
13
|
+
CheckpointedL2Block,
|
|
11
14
|
L2Block,
|
|
12
|
-
L2BlockHash,
|
|
13
15
|
type L2BlockSource,
|
|
14
16
|
type L2Tips,
|
|
15
|
-
|
|
16
|
-
type ValidateBlockResult,
|
|
17
|
+
type ValidateCheckpointResult,
|
|
17
18
|
} from '@aztec/stdlib/block';
|
|
19
|
+
import {
|
|
20
|
+
Checkpoint,
|
|
21
|
+
type CheckpointData,
|
|
22
|
+
L1PublishedData,
|
|
23
|
+
type ProposedCheckpointData,
|
|
24
|
+
PublishedCheckpoint,
|
|
25
|
+
} from '@aztec/stdlib/checkpoint';
|
|
18
26
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
19
|
-
import {
|
|
20
|
-
|
|
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';
|
|
21
36
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
22
37
|
|
|
23
38
|
/**
|
|
@@ -25,29 +40,65 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
25
40
|
*/
|
|
26
41
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
27
42
|
protected l2Blocks: L2Block[] = [];
|
|
43
|
+
protected checkpointList: Checkpoint[] = [];
|
|
28
44
|
|
|
29
45
|
private provenBlockNumber: number = 0;
|
|
30
46
|
private finalizedBlockNumber: number = 0;
|
|
47
|
+
private checkpointedBlockNumber: number = 0;
|
|
48
|
+
private proposedCheckpointBlockNumber: number = 0;
|
|
31
49
|
|
|
32
50
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
33
51
|
|
|
52
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
34
53
|
public async createBlocks(numBlocks: number) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
|
39
77
|
}
|
|
40
78
|
|
|
41
|
-
this.log.verbose(
|
|
79
|
+
this.log.verbose(
|
|
80
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
81
|
+
);
|
|
42
82
|
}
|
|
43
83
|
|
|
44
|
-
public
|
|
84
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
45
85
|
this.l2Blocks.push(...blocks);
|
|
46
|
-
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`);
|
|
47
87
|
}
|
|
48
88
|
|
|
49
89
|
public removeBlocks(numBlocks: number) {
|
|
50
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);
|
|
51
102
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
52
103
|
}
|
|
53
104
|
|
|
@@ -62,6 +113,44 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
62
113
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
63
114
|
}
|
|
64
115
|
|
|
116
|
+
public setProposedCheckpointBlockNumber(blockNumber: number) {
|
|
117
|
+
this.proposedCheckpointBlockNumber = blockNumber;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
121
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
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
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
65
154
|
/**
|
|
66
155
|
* Method to fetch the rollup contract address at the base-layer.
|
|
67
156
|
* @returns The rollup address.
|
|
@@ -83,11 +172,49 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
83
172
|
* @returns In this mock instance, returns the number of L2 blocks that we've mocked.
|
|
84
173
|
*/
|
|
85
174
|
public getBlockNumber() {
|
|
86
|
-
return Promise.resolve(this.l2Blocks.length);
|
|
175
|
+
return Promise.resolve(BlockNumber(this.l2Blocks.length));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public getProvenBlockNumber() {
|
|
179
|
+
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
180
|
+
}
|
|
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
|
+
|
|
194
|
+
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
195
|
+
if (number > this.checkpointedBlockNumber) {
|
|
196
|
+
return Promise.resolve(undefined);
|
|
197
|
+
}
|
|
198
|
+
const block = this.l2Blocks[number - 1];
|
|
199
|
+
if (!block) {
|
|
200
|
+
return Promise.resolve(undefined);
|
|
201
|
+
}
|
|
202
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
87
203
|
}
|
|
88
204
|
|
|
89
|
-
public
|
|
90
|
-
|
|
205
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
206
|
+
const result: CheckpointedL2Block[] = [];
|
|
207
|
+
for (let i = 0; i < limit; i++) {
|
|
208
|
+
const blockNum = from + i;
|
|
209
|
+
if (blockNum > this.checkpointedBlockNumber) {
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
const block = await this.getCheckpointedBlock(BlockNumber(blockNum));
|
|
213
|
+
if (block) {
|
|
214
|
+
result.push(block);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
91
218
|
}
|
|
92
219
|
|
|
93
220
|
/**
|
|
@@ -95,8 +222,19 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
95
222
|
* @param number - The block number to return (inclusive).
|
|
96
223
|
* @returns The requested L2 block.
|
|
97
224
|
*/
|
|
98
|
-
public getBlock(number: number) {
|
|
99
|
-
|
|
225
|
+
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
226
|
+
const block = this.l2Blocks[number - 1];
|
|
227
|
+
return Promise.resolve(block);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Gets an L2 block (new format).
|
|
232
|
+
* @param number - The block number to return.
|
|
233
|
+
* @returns The requested L2 block.
|
|
234
|
+
*/
|
|
235
|
+
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
236
|
+
const block = this.l2Blocks[number - 1];
|
|
237
|
+
return Promise.resolve(block);
|
|
100
238
|
}
|
|
101
239
|
|
|
102
240
|
/**
|
|
@@ -105,70 +243,60 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
105
243
|
* @param limit - The maximum number of blocks to return.
|
|
106
244
|
* @returns The requested mocked L2 blocks.
|
|
107
245
|
*/
|
|
108
|
-
public getBlocks(from: number, limit: number
|
|
246
|
+
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
247
|
+
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
251
|
+
const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
|
|
109
252
|
return Promise.resolve(
|
|
110
|
-
this.
|
|
111
|
-
.slice(from - 1, from - 1 + limit)
|
|
112
|
-
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
|
|
253
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
113
254
|
);
|
|
114
255
|
}
|
|
115
256
|
|
|
116
|
-
public
|
|
117
|
-
const
|
|
118
|
-
return
|
|
119
|
-
PublishedL2Block.fromFields({
|
|
120
|
-
block,
|
|
121
|
-
l1: {
|
|
122
|
-
blockNumber: BigInt(block.number),
|
|
123
|
-
blockHash: Buffer32.random().toString(),
|
|
124
|
-
timestamp: BigInt(block.number),
|
|
125
|
-
},
|
|
126
|
-
attestations: [],
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
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);
|
|
129
260
|
}
|
|
130
261
|
|
|
131
|
-
public async
|
|
262
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
132
263
|
for (const block of this.l2Blocks) {
|
|
133
264
|
const hash = await block.hash();
|
|
134
265
|
if (hash.equals(blockHash)) {
|
|
135
|
-
return
|
|
136
|
-
block,
|
|
137
|
-
l1: {
|
|
138
|
-
blockNumber: BigInt(block.number),
|
|
139
|
-
blockHash: Buffer32.random().toString(),
|
|
140
|
-
timestamp: BigInt(block.number),
|
|
141
|
-
},
|
|
142
|
-
attestations: [],
|
|
143
|
-
});
|
|
266
|
+
return this.toCheckpointedBlock(block);
|
|
144
267
|
}
|
|
145
268
|
}
|
|
146
269
|
return undefined;
|
|
147
270
|
}
|
|
148
271
|
|
|
149
|
-
public
|
|
272
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
150
273
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
151
274
|
if (!block) {
|
|
152
275
|
return Promise.resolve(undefined);
|
|
153
276
|
}
|
|
154
|
-
return Promise.resolve(
|
|
155
|
-
PublishedL2Block.fromFields({
|
|
156
|
-
block,
|
|
157
|
-
l1: {
|
|
158
|
-
blockNumber: BigInt(block.number),
|
|
159
|
-
blockHash: Buffer32.random().toString(),
|
|
160
|
-
timestamp: BigInt(block.number),
|
|
161
|
-
},
|
|
162
|
-
attestations: [],
|
|
163
|
-
}),
|
|
164
|
-
);
|
|
277
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
165
278
|
}
|
|
166
279
|
|
|
167
|
-
public async
|
|
280
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
168
281
|
for (const block of this.l2Blocks) {
|
|
169
282
|
const hash = await block.hash();
|
|
170
283
|
if (hash.equals(blockHash)) {
|
|
171
|
-
return block
|
|
284
|
+
return block;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
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> {
|
|
296
|
+
for (const block of this.l2Blocks) {
|
|
297
|
+
const hash = await block.hash();
|
|
298
|
+
if (hash.equals(blockHash)) {
|
|
299
|
+
return block.header;
|
|
172
300
|
}
|
|
173
301
|
}
|
|
174
302
|
return undefined;
|
|
@@ -176,26 +304,80 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
176
304
|
|
|
177
305
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
178
306
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
179
|
-
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
|
+
};
|
|
180
336
|
}
|
|
181
337
|
|
|
182
338
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
183
|
-
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);
|
|
184
340
|
}
|
|
185
341
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
342
|
+
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
343
|
+
return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
|
|
344
|
+
}
|
|
345
|
+
|
|
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);
|
|
193
375
|
return Promise.resolve(blocks);
|
|
194
376
|
}
|
|
195
377
|
|
|
196
|
-
async
|
|
197
|
-
const
|
|
198
|
-
return
|
|
378
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
379
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
380
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
199
381
|
}
|
|
200
382
|
|
|
201
383
|
/**
|
|
@@ -214,7 +396,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
214
396
|
return {
|
|
215
397
|
data: txEffect,
|
|
216
398
|
l2BlockNumber: block.number,
|
|
217
|
-
l2BlockHash:
|
|
399
|
+
l2BlockHash: await block.hash(),
|
|
218
400
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
219
401
|
};
|
|
220
402
|
}
|
|
@@ -228,13 +410,16 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
228
410
|
for (const block of this.l2Blocks) {
|
|
229
411
|
for (const txEffect of block.body.txEffects) {
|
|
230
412
|
if (txEffect.txHash.equals(txHash)) {
|
|
413
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
231
414
|
return new TxReceipt(
|
|
232
415
|
txHash,
|
|
233
|
-
TxStatus.
|
|
234
|
-
|
|
416
|
+
TxStatus.CHECKPOINTED,
|
|
417
|
+
TxExecutionResult.SUCCESS,
|
|
418
|
+
undefined,
|
|
235
419
|
txEffect.transactionFee.toBigInt(),
|
|
236
|
-
|
|
420
|
+
await block.hash(),
|
|
237
421
|
block.number,
|
|
422
|
+
getEpochAtSlot(block.slot, EmptyL1RollupConstants),
|
|
238
423
|
);
|
|
239
424
|
}
|
|
240
425
|
}
|
|
@@ -243,37 +428,63 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
243
428
|
}
|
|
244
429
|
|
|
245
430
|
async getL2Tips(): Promise<L2Tips> {
|
|
246
|
-
const [latest, proven, finalized] = [
|
|
431
|
+
const [latest, proven, finalized, checkpointed, proposedCheckpoint] = [
|
|
247
432
|
await this.getBlockNumber(),
|
|
248
433
|
await this.getProvenBlockNumber(),
|
|
249
434
|
this.finalizedBlockNumber,
|
|
435
|
+
this.checkpointedBlockNumber,
|
|
436
|
+
await this.getProposedCheckpointL2BlockNumber(),
|
|
250
437
|
] as const;
|
|
251
438
|
|
|
252
439
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
253
440
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
254
441
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
442
|
+
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
443
|
+
const proposedCheckpointBlock = this.l2Blocks[proposedCheckpoint - 1];
|
|
255
444
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
445
|
+
const latestBlockId = {
|
|
446
|
+
number: BlockNumber(latest),
|
|
447
|
+
hash: (await latestBlock?.hash())?.toString(),
|
|
448
|
+
};
|
|
449
|
+
const provenBlockId = {
|
|
450
|
+
number: BlockNumber(proven),
|
|
451
|
+
hash: (await provenBlock?.hash())?.toString(),
|
|
452
|
+
};
|
|
453
|
+
const finalizedBlockId = {
|
|
454
|
+
number: BlockNumber(finalized),
|
|
455
|
+
hash: (await finalizedBlock?.hash())?.toString(),
|
|
456
|
+
};
|
|
457
|
+
const checkpointedBlockId = {
|
|
458
|
+
number: BlockNumber(checkpointed),
|
|
459
|
+
hash: (await checkpointedBlock?.hash())?.toString(),
|
|
460
|
+
};
|
|
461
|
+
const proposedCheckpointBlockId = {
|
|
462
|
+
number: BlockNumber(proposedCheckpoint),
|
|
463
|
+
hash: (await proposedCheckpointBlock?.hash())?.toString(),
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
467
|
+
block: blockId,
|
|
468
|
+
checkpoint: {
|
|
469
|
+
number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
|
|
470
|
+
hash: blockId.hash,
|
|
268
471
|
},
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
return {
|
|
475
|
+
proposed: latestBlockId,
|
|
476
|
+
checkpointed: makeTipId(checkpointedBlockId),
|
|
477
|
+
proven: makeTipId(provenBlockId),
|
|
478
|
+
finalized: makeTipId(finalizedBlockId),
|
|
479
|
+
proposedCheckpoint: makeTipId(proposedCheckpointBlockId),
|
|
269
480
|
};
|
|
270
481
|
}
|
|
271
482
|
|
|
272
|
-
|
|
483
|
+
getSyncedL2EpochNumber(): Promise<EpochNumber> {
|
|
273
484
|
throw new Error('Method not implemented.');
|
|
274
485
|
}
|
|
275
486
|
|
|
276
|
-
|
|
487
|
+
getSyncedL2SlotNumber(): Promise<SlotNumber> {
|
|
277
488
|
throw new Error('Method not implemented.');
|
|
278
489
|
}
|
|
279
490
|
|
|
@@ -343,7 +554,49 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
343
554
|
return Promise.resolve(false);
|
|
344
555
|
}
|
|
345
556
|
|
|
346
|
-
getPendingChainValidationStatus(): Promise<
|
|
557
|
+
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
347
558
|
return Promise.resolve({ valid: true });
|
|
348
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
|
+
}
|
|
349
602
|
}
|