@aztec/archiver 0.0.1-commit.e3c1de76 → 0.0.1-commit.e57c76e
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 +19 -11
- package/dest/archiver.d.ts +58 -18
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +284 -160
- package/dest/config.d.ts +4 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +21 -14
- package/dest/errors.d.ts +55 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +81 -14
- package/dest/factory.d.ts +14 -9
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +55 -39
- package/dest/index.d.ts +12 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +11 -2
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- package/dest/l1/calldata_retriever.d.ts +74 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +201 -260
- package/dest/l1/data_retrieval.d.ts +26 -17
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +43 -48
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/trace_tx.d.ts +12 -66
- package/dest/l1/trace_tx.d.ts.map +1 -1
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +40 -0
- package/dest/modules/data_source_base.d.ts +74 -45
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +269 -181
- package/dest/modules/data_store_updater.d.ts +49 -17
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +211 -121
- package/dest/modules/instrumentation.d.ts +21 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +44 -9
- package/dest/modules/l1_synchronizer.d.ts +14 -12
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +443 -211
- package/dest/modules/outbox_trees_resolver.d.ts +62 -0
- package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
- package/dest/modules/outbox_trees_resolver.js +162 -0
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +6 -6
- package/dest/store/block_store.d.ts +174 -72
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +739 -272
- package/dest/store/contract_class_store.d.ts +17 -4
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +24 -68
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +37 -2
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +25 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +26 -0
- package/dest/store/log_store.d.ts +42 -37
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +262 -388
- package/dest/store/log_store_codec.d.ts +70 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +101 -0
- package/dest/store/message_store.d.ts +11 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +51 -9
- package/dest/test/fake_l1_state.d.ts +25 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +166 -32
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- 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 +64 -47
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +323 -214
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +13 -6
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +27 -10
- package/package.json +14 -14
- package/src/archiver.ts +359 -183
- package/src/config.ts +24 -11
- package/src/errors.ts +122 -21
- package/src/factory.ts +79 -38
- package/src/index.ts +19 -2
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +260 -379
- package/src/l1/data_retrieval.ts +59 -70
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +55 -0
- package/src/modules/data_source_base.ts +354 -226
- package/src/modules/data_store_updater.ts +248 -153
- package/src/modules/instrumentation.ts +56 -9
- package/src/modules/l1_synchronizer.ts +585 -258
- package/src/modules/outbox_trees_resolver.ts +199 -0
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +917 -343
- package/src/store/contract_class_store.ts +31 -103
- package/src/store/contract_instance_store.ts +51 -5
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +35 -0
- package/src/store/log_store.ts +303 -499
- package/src/store/log_store_codec.ts +132 -0
- package/src/store/message_store.ts +60 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +213 -42
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +391 -232
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +49 -10
- package/dest/store/kv_archiver_store.d.ts +0 -340
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -446
- package/src/store/kv_archiver_store.ts +0 -639
|
@@ -1,31 +1,88 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
2
|
import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
-
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import {
|
|
8
|
+
import { Body, GENESIS_BLOCK_HEADER_HASH, GENESIS_CHECKPOINT_HEADER_HASH, L2Block } from '@aztec/stdlib/block';
|
|
9
9
|
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
10
10
|
import { EmptyL1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
11
|
-
import {
|
|
11
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
12
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
|
+
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
14
|
+
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
12
15
|
/**
|
|
13
16
|
* A mocked implementation of L2BlockSource to be used in tests.
|
|
14
17
|
*/ export class MockL2BlockSource {
|
|
15
18
|
l2Blocks = [];
|
|
19
|
+
checkpointList = [];
|
|
16
20
|
provenBlockNumber = 0;
|
|
17
21
|
finalizedBlockNumber = 0;
|
|
18
22
|
checkpointedBlockNumber = 0;
|
|
23
|
+
proposedCheckpointBlockNumber = 0;
|
|
24
|
+
initialHeader = BlockHeader.empty();
|
|
25
|
+
initialHeaderHash = GENESIS_BLOCK_HEADER_HASH;
|
|
26
|
+
genesisArchiveRoot;
|
|
27
|
+
genesisBlock;
|
|
19
28
|
log = createLogger('archiver:mock_l2_block_source');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
/** Returns the initial header used to synthesize block 0. */ getInitialHeader() {
|
|
30
|
+
return this.initialHeader;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets the initial header used to synthesize block 0. Tests that wire up a real
|
|
34
|
+
* world-state should call this with `worldState.getInitialHeader()` so the L2BlockStream
|
|
35
|
+
* agrees on the genesis hash on both sides. Precomputes and caches the header hash so
|
|
36
|
+
* `getGenesisBlockHash()` can return synchronously.
|
|
37
|
+
*/ async setInitialHeader(header) {
|
|
38
|
+
this.initialHeader = header;
|
|
39
|
+
this.initialHeaderHash = await header.hash();
|
|
40
|
+
this.genesisBlock = undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the precomputed hash of the genesis block header. Defaults to the static
|
|
44
|
+
* {@link GENESIS_BLOCK_HEADER_HASH} unless {@link setInitialHeader} has been called with a
|
|
45
|
+
* custom header.
|
|
46
|
+
*/ getGenesisBlockHash() {
|
|
47
|
+
return this.initialHeaderHash;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sets the post-genesis archive root used to synthesize block 0. Mirrors the real archiver,
|
|
51
|
+
* whose synthetic block 0 carries `new AppendOnlyTreeSnapshot(genesisArchiveRoot, 1)` rather
|
|
52
|
+
* than `AppendOnlyTreeSnapshot.empty()`. Tests wiring up a real world-state should set this so
|
|
53
|
+
* archive-based block lookups against the mock match production semantics.
|
|
54
|
+
*/ setGenesisArchiveRoot(root) {
|
|
55
|
+
this.genesisArchiveRoot = root;
|
|
56
|
+
this.genesisBlock = undefined;
|
|
57
|
+
}
|
|
58
|
+
getGenesisBlock() {
|
|
59
|
+
if (this.genesisBlock) {
|
|
60
|
+
return this.genesisBlock;
|
|
61
|
+
}
|
|
62
|
+
const archive = this.genesisArchiveRoot ? new AppendOnlyTreeSnapshot(this.genesisArchiveRoot, 1) : AppendOnlyTreeSnapshot.empty();
|
|
63
|
+
return this.genesisBlock = new L2Block(archive, this.initialHeader, Body.empty(), CheckpointNumber.ZERO, IndexWithinCheckpoint(0));
|
|
64
|
+
}
|
|
65
|
+
/** Creates blocks grouped into single-block checkpoints. */ async createBlocks(numBlocks) {
|
|
66
|
+
await this.createCheckpoints(numBlocks, 1);
|
|
67
|
+
}
|
|
68
|
+
getCheckpointNumber() {
|
|
69
|
+
return Promise.resolve(this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length));
|
|
70
|
+
}
|
|
71
|
+
/** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */ async createCheckpoints(numCheckpoints, blocksPerCheckpoint = 1) {
|
|
72
|
+
for(let c = 0; c < numCheckpoints; c++){
|
|
73
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
|
|
74
|
+
const startBlockNum = this.l2Blocks.length + 1;
|
|
75
|
+
const slotNumber = SlotNumber(Number(checkpointNum));
|
|
76
|
+
const checkpoint = await Checkpoint.random(checkpointNum, {
|
|
77
|
+
numBlocks: blocksPerCheckpoint,
|
|
78
|
+
startBlockNumber: startBlockNum,
|
|
79
|
+
slotNumber,
|
|
80
|
+
checkpointNumber: checkpointNum
|
|
25
81
|
});
|
|
26
|
-
this.
|
|
82
|
+
this.checkpointList.push(checkpoint);
|
|
83
|
+
this.l2Blocks.push(...checkpoint.blocks);
|
|
27
84
|
}
|
|
28
|
-
this.log.verbose(`Created ${
|
|
85
|
+
this.log.verbose(`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`);
|
|
29
86
|
}
|
|
30
87
|
addProposedBlocks(blocks) {
|
|
31
88
|
this.l2Blocks.push(...blocks);
|
|
@@ -33,6 +90,17 @@ import { TxExecutionResult, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
33
90
|
}
|
|
34
91
|
removeBlocks(numBlocks) {
|
|
35
92
|
this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
|
|
93
|
+
const maxBlockNum = this.l2Blocks.length;
|
|
94
|
+
// Remove any checkpoint whose last block is beyond the remaining blocks.
|
|
95
|
+
this.checkpointList = this.checkpointList.filter((c)=>{
|
|
96
|
+
const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
|
|
97
|
+
return lastBlockNum <= maxBlockNum;
|
|
98
|
+
});
|
|
99
|
+
// Keep tip numbers consistent with remaining blocks.
|
|
100
|
+
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
101
|
+
this.proposedCheckpointBlockNumber = Math.min(this.proposedCheckpointBlockNumber, maxBlockNum);
|
|
102
|
+
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
103
|
+
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
36
104
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
37
105
|
}
|
|
38
106
|
setProvenBlockNumber(provenBlockNumber) {
|
|
@@ -44,8 +112,40 @@ import { TxExecutionResult, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
44
112
|
}
|
|
45
113
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
46
114
|
}
|
|
115
|
+
setProposedCheckpointBlockNumber(blockNumber) {
|
|
116
|
+
this.proposedCheckpointBlockNumber = blockNumber;
|
|
117
|
+
}
|
|
47
118
|
setCheckpointedBlockNumber(checkpointedBlockNumber) {
|
|
119
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
48
120
|
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
121
|
+
// Proposed checkpoint is always at least as advanced as checkpointed
|
|
122
|
+
if (this.proposedCheckpointBlockNumber < checkpointedBlockNumber) {
|
|
123
|
+
this.proposedCheckpointBlockNumber = checkpointedBlockNumber;
|
|
124
|
+
}
|
|
125
|
+
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
126
|
+
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
127
|
+
const newCheckpoints = [];
|
|
128
|
+
for(let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++){
|
|
129
|
+
const block = this.l2Blocks[blockNum - 1];
|
|
130
|
+
if (!block) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (this.checkpointList.some((c)=>c.blocks.some((b)=>b.number === block.number))) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
|
|
137
|
+
const checkpoint = new Checkpoint(block.archive, CheckpointHeader.random({
|
|
138
|
+
slotNumber: block.header.globalVariables.slotNumber
|
|
139
|
+
}), [
|
|
140
|
+
block
|
|
141
|
+
], checkpointNum);
|
|
142
|
+
newCheckpoints.push(checkpoint);
|
|
143
|
+
}
|
|
144
|
+
// Insert new checkpoints in order by number.
|
|
145
|
+
if (newCheckpoints.length > 0) {
|
|
146
|
+
this.checkpointList.push(...newCheckpoints);
|
|
147
|
+
this.checkpointList.sort((a, b)=>a.number - b.number);
|
|
148
|
+
}
|
|
49
149
|
}
|
|
50
150
|
/**
|
|
51
151
|
* Method to fetch the rollup contract address at the base-layer.
|
|
@@ -59,199 +159,93 @@ import { TxExecutionResult, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
59
159
|
*/ getRegistryAddress() {
|
|
60
160
|
return Promise.resolve(EthAddress.random());
|
|
61
161
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/ getBlockNumber() {
|
|
66
|
-
return Promise.resolve(BlockNumber(this.l2Blocks.length));
|
|
67
|
-
}
|
|
68
|
-
getProvenBlockNumber() {
|
|
69
|
-
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
70
|
-
}
|
|
71
|
-
getCheckpointedL2BlockNumber() {
|
|
72
|
-
return Promise.resolve(BlockNumber(this.checkpointedBlockNumber));
|
|
73
|
-
}
|
|
74
|
-
getFinalizedL2BlockNumber() {
|
|
75
|
-
return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
|
|
76
|
-
}
|
|
77
|
-
getCheckpointedBlock(number) {
|
|
78
|
-
if (number > this.checkpointedBlockNumber) {
|
|
79
|
-
return Promise.resolve(undefined);
|
|
162
|
+
async getBlockNumber(query) {
|
|
163
|
+
if (!query) {
|
|
164
|
+
return BlockNumber(this.l2Blocks.length);
|
|
80
165
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return Promise.resolve(undefined);
|
|
166
|
+
if ('number' in query) {
|
|
167
|
+
return query.number;
|
|
84
168
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
async getCheckpointedBlocks(from, limit) {
|
|
89
|
-
const result = [];
|
|
90
|
-
for(let i = 0; i < limit; i++){
|
|
91
|
-
const blockNum = from + i;
|
|
92
|
-
if (blockNum > this.checkpointedBlockNumber) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
const block = await this.getCheckpointedBlock(BlockNumber(blockNum));
|
|
96
|
-
if (block) {
|
|
97
|
-
result.push(block);
|
|
98
|
-
}
|
|
169
|
+
if ('tag' in query) {
|
|
170
|
+
return BlockNumber(this.resolveBlockTag(query.tag));
|
|
99
171
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Gets an l2 block.
|
|
104
|
-
* @param number - The block number to return (inclusive).
|
|
105
|
-
* @returns The requested L2 block.
|
|
106
|
-
*/ getBlock(number) {
|
|
107
|
-
const block = this.l2Blocks[number - 1];
|
|
108
|
-
return Promise.resolve(block);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Gets an L2 block (new format).
|
|
112
|
-
* @param number - The block number to return.
|
|
113
|
-
* @returns The requested L2 block.
|
|
114
|
-
*/ getL2Block(number) {
|
|
115
|
-
const block = this.l2Blocks[number - 1];
|
|
116
|
-
return Promise.resolve(block);
|
|
172
|
+
const block = await this.getBlock(query);
|
|
173
|
+
return block ? block.header.globalVariables.blockNumber : undefined;
|
|
117
174
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
* @param from - Number of the first block to return (inclusive).
|
|
121
|
-
* @param limit - The maximum number of blocks to return.
|
|
122
|
-
* @returns The requested mocked L2 blocks.
|
|
123
|
-
*/ getBlocks(from, limit) {
|
|
124
|
-
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
125
|
-
}
|
|
126
|
-
getCheckpoints(from, limit) {
|
|
127
|
-
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
128
|
-
const blocks = this.l2Blocks.slice(from - 1, from - 1 + limit);
|
|
129
|
-
return Promise.all(blocks.map(async (block)=>{
|
|
130
|
-
// Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
|
|
131
|
-
const checkpoint = await Checkpoint.random(block.checkpointNumber, {
|
|
132
|
-
numBlocks: 1
|
|
133
|
-
});
|
|
134
|
-
checkpoint.blocks = [
|
|
135
|
-
block
|
|
136
|
-
];
|
|
137
|
-
return new PublishedCheckpoint(checkpoint, new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()), []);
|
|
138
|
-
}));
|
|
175
|
+
getProposedCheckpointL2BlockNumber() {
|
|
176
|
+
return Promise.resolve(BlockNumber(this.proposedCheckpointBlockNumber));
|
|
139
177
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (!block) {
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
// Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
|
|
147
|
-
const checkpoint = await Checkpoint.random(block.checkpointNumber, {
|
|
148
|
-
numBlocks: 1
|
|
149
|
-
});
|
|
150
|
-
checkpoint.blocks = [
|
|
151
|
-
block
|
|
152
|
-
];
|
|
153
|
-
return checkpoint;
|
|
154
|
-
}
|
|
155
|
-
async getCheckpointedBlockByHash(blockHash) {
|
|
156
|
-
for (const block of this.l2Blocks){
|
|
157
|
-
const hash = await block.hash();
|
|
158
|
-
if (hash.equals(blockHash)) {
|
|
159
|
-
return CheckpointedL2Block.fromFields({
|
|
160
|
-
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
161
|
-
block,
|
|
162
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
163
|
-
attestations: []
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
getCheckpointedBlockByArchive(archive) {
|
|
170
|
-
const block = this.l2Blocks.find((b)=>b.archive.root.equals(archive));
|
|
171
|
-
if (!block) {
|
|
178
|
+
getCheckpoint(query) {
|
|
179
|
+
const checkpoint = this.resolveCheckpointQuery(query);
|
|
180
|
+
if (!checkpoint) {
|
|
172
181
|
return Promise.resolve(undefined);
|
|
173
182
|
}
|
|
174
|
-
return Promise.resolve(
|
|
175
|
-
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
176
|
-
block,
|
|
177
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
178
|
-
attestations: []
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
async getL2BlockByHash(blockHash) {
|
|
182
|
-
for (const block of this.l2Blocks){
|
|
183
|
-
const hash = await block.hash();
|
|
184
|
-
if (hash.equals(blockHash)) {
|
|
185
|
-
return block;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return undefined;
|
|
183
|
+
return Promise.resolve(new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), []));
|
|
189
184
|
}
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
return Promise.resolve(
|
|
185
|
+
getCheckpoints(query) {
|
|
186
|
+
const checkpoints = this.resolveCheckpointsQuery(query);
|
|
187
|
+
return Promise.resolve(checkpoints.map((checkpoint)=>new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])));
|
|
193
188
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
189
|
+
getCheckpointByArchive(archive) {
|
|
190
|
+
const checkpoint = this.checkpointList.find((c)=>c.archive.root.equals(archive));
|
|
191
|
+
return Promise.resolve(checkpoint);
|
|
192
|
+
}
|
|
193
|
+
getCheckpointData(query) {
|
|
194
|
+
const checkpoint = this.resolveCheckpointQuery(query);
|
|
195
|
+
if (!checkpoint) {
|
|
196
|
+
return Promise.resolve(undefined);
|
|
200
197
|
}
|
|
201
|
-
return
|
|
198
|
+
return Promise.resolve(this.checkpointToData(checkpoint));
|
|
202
199
|
}
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
return Promise.resolve(
|
|
200
|
+
getCheckpointsData(query) {
|
|
201
|
+
const checkpoints = this.resolveCheckpointsQuery(query);
|
|
202
|
+
return Promise.resolve(checkpoints.map((c)=>this.checkpointToData(c)));
|
|
206
203
|
}
|
|
207
|
-
|
|
208
|
-
return
|
|
204
|
+
checkpointToData(checkpoint) {
|
|
205
|
+
return {
|
|
206
|
+
checkpointNumber: checkpoint.number,
|
|
207
|
+
header: checkpoint.header,
|
|
208
|
+
archive: checkpoint.archive,
|
|
209
|
+
checkpointOutHash: computeCheckpointOutHash(checkpoint.blocks.map((b)=>b.body.txEffects.map((tx)=>tx.l2ToL1Msgs))),
|
|
210
|
+
startBlock: checkpoint.blocks[0].number,
|
|
211
|
+
blockCount: checkpoint.blocks.length,
|
|
212
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
213
|
+
attestations: [],
|
|
214
|
+
l1: this.mockL1DataForCheckpoint(checkpoint)
|
|
215
|
+
};
|
|
209
216
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
217
|
+
resolveCheckpointQuery(query) {
|
|
218
|
+
if ('number' in query) {
|
|
219
|
+
return this.checkpointList[query.number - 1];
|
|
220
|
+
}
|
|
221
|
+
if ('slot' in query) {
|
|
222
|
+
return this.checkpointList.find((c)=>c.header.slotNumber === query.slot);
|
|
223
|
+
}
|
|
224
|
+
switch(query.tag){
|
|
225
|
+
case 'checkpointed':
|
|
226
|
+
return this.checkpointList[this.checkpointList.length - 1];
|
|
227
|
+
case 'proven':
|
|
228
|
+
{
|
|
229
|
+
const provenCheckpoint = this.checkpointList.filter((c)=>c.blocks.some((b)=>b.number <= this.provenBlockNumber));
|
|
230
|
+
return provenCheckpoint.at(-1);
|
|
231
|
+
}
|
|
232
|
+
case 'finalized':
|
|
233
|
+
{
|
|
234
|
+
const finalizedCheckpoint = this.checkpointList.filter((c)=>c.blocks.some((b)=>b.number <= this.finalizedBlockNumber));
|
|
235
|
+
return finalizedCheckpoint.at(-1);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
230
238
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const blocks = this.l2Blocks.filter((b)=>{
|
|
237
|
-
const slot = b.header.globalVariables.slotNumber;
|
|
238
|
-
return slot >= start && slot <= end;
|
|
239
|
-
});
|
|
240
|
-
return Promise.resolve(blocks.map((block)=>CheckpointedL2Block.fromFields({
|
|
241
|
-
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
242
|
-
block,
|
|
243
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
244
|
-
attestations: []
|
|
245
|
-
})));
|
|
239
|
+
resolveCheckpointsQuery(query) {
|
|
240
|
+
if ('from' in query) {
|
|
241
|
+
return this.checkpointList.slice(query.from - 1, query.from - 1 + query.limit);
|
|
242
|
+
}
|
|
243
|
+
return this.getCheckpointsInEpoch(query.epoch);
|
|
246
244
|
}
|
|
247
245
|
getBlocksForSlot(slotNumber) {
|
|
248
246
|
const blocks = this.l2Blocks.filter((b)=>b.header.globalVariables.slotNumber === slotNumber);
|
|
249
247
|
return Promise.resolve(blocks);
|
|
250
248
|
}
|
|
251
|
-
async getCheckpointedBlockHeadersForEpoch(epochNumber) {
|
|
252
|
-
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
253
|
-
return checkpointedBlocks.map((b)=>b.block.header);
|
|
254
|
-
}
|
|
255
249
|
/**
|
|
256
250
|
* Gets a tx effect.
|
|
257
251
|
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
@@ -269,69 +263,82 @@ import { TxExecutionResult, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
269
263
|
data: txEffect,
|
|
270
264
|
l2BlockNumber: block.number,
|
|
271
265
|
l2BlockHash: await block.hash(),
|
|
272
|
-
txIndexInBlock: block.body.txEffects.
|
|
266
|
+
txIndexInBlock: block.body.txEffects.findIndex((t)=>t.txHash.equals(txHash)),
|
|
267
|
+
slotNumber: block.header.globalVariables.slotNumber
|
|
273
268
|
};
|
|
274
269
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
* @returns The requested tx receipt (or undefined if not found).
|
|
279
|
-
*/ async getSettledTxReceipt(txHash) {
|
|
280
|
-
for (const block of this.l2Blocks){
|
|
281
|
-
for (const txEffect of block.body.txEffects){
|
|
282
|
-
if (txEffect.txHash.equals(txHash)) {
|
|
283
|
-
// In mock, assume all txs are checkpointed with successful execution
|
|
284
|
-
return new TxReceipt(txHash, TxStatus.CHECKPOINTED, TxExecutionResult.SUCCESS, undefined, txEffect.transactionFee.toBigInt(), await block.hash(), block.number);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return undefined;
|
|
270
|
+
getL2ToL1MembershipWitness() {
|
|
271
|
+
// Mock does not back the L2-to-L1 message witness flow.
|
|
272
|
+
return Promise.resolve(undefined);
|
|
289
273
|
}
|
|
290
274
|
async getL2Tips() {
|
|
291
|
-
const [latest, proven, finalized, checkpointed] = [
|
|
275
|
+
const [latest, proven, finalized, checkpointed, proposedCheckpoint] = [
|
|
292
276
|
await this.getBlockNumber(),
|
|
293
|
-
|
|
277
|
+
this.provenBlockNumber,
|
|
294
278
|
this.finalizedBlockNumber,
|
|
295
|
-
this.checkpointedBlockNumber
|
|
279
|
+
this.checkpointedBlockNumber,
|
|
280
|
+
await this.getProposedCheckpointL2BlockNumber()
|
|
296
281
|
];
|
|
297
282
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
298
283
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
299
284
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
300
285
|
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
286
|
+
const proposedCheckpointBlock = this.l2Blocks[proposedCheckpoint - 1];
|
|
287
|
+
// For genesis tips (block number 0) report the dynamic initial header hash so consumers
|
|
288
|
+
// running L2BlockStream against this mock agree at block 0 with their local tip store.
|
|
289
|
+
const genesisHash = (await this.initialHeader.hash()).toString();
|
|
290
|
+
const tipHash = async (block, number)=>{
|
|
291
|
+
if (block) {
|
|
292
|
+
return (await block.hash()).toString();
|
|
293
|
+
}
|
|
294
|
+
return number === 0 ? genesisHash : '';
|
|
295
|
+
};
|
|
301
296
|
const latestBlockId = {
|
|
302
297
|
number: BlockNumber(latest),
|
|
303
|
-
hash:
|
|
298
|
+
hash: await tipHash(latestBlock, latest)
|
|
304
299
|
};
|
|
305
300
|
const provenBlockId = {
|
|
306
301
|
number: BlockNumber(proven),
|
|
307
|
-
hash:
|
|
302
|
+
hash: await tipHash(provenBlock, proven)
|
|
308
303
|
};
|
|
309
304
|
const finalizedBlockId = {
|
|
310
305
|
number: BlockNumber(finalized),
|
|
311
|
-
hash:
|
|
306
|
+
hash: await tipHash(finalizedBlock, finalized)
|
|
312
307
|
};
|
|
313
308
|
const checkpointedBlockId = {
|
|
314
309
|
number: BlockNumber(checkpointed),
|
|
315
|
-
hash:
|
|
310
|
+
hash: await tipHash(checkpointedBlock, checkpointed)
|
|
316
311
|
};
|
|
317
|
-
const
|
|
312
|
+
const proposedCheckpointBlockId = {
|
|
313
|
+
number: BlockNumber(proposedCheckpoint),
|
|
314
|
+
hash: await tipHash(proposedCheckpointBlock, proposedCheckpoint)
|
|
315
|
+
};
|
|
316
|
+
const makeTipId = (blockId)=>{
|
|
317
|
+
const checkpointNumber = this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0);
|
|
318
|
+
// Match production semantics: checkpoint 0 is fully synthetic (no real checkpoint header
|
|
319
|
+
// exists at 0), so its hash stays at the protocol constant `GENESIS_CHECKPOINT_HEADER_HASH`
|
|
320
|
+
// even though the block-0 hash is dynamic. See L2TipsCache for the production path.
|
|
321
|
+
const hash = checkpointNumber === 0 ? GENESIS_CHECKPOINT_HEADER_HASH.toString() : blockId.hash;
|
|
322
|
+
return {
|
|
318
323
|
block: blockId,
|
|
319
324
|
checkpoint: {
|
|
320
|
-
number:
|
|
321
|
-
hash
|
|
325
|
+
number: checkpointNumber,
|
|
326
|
+
hash
|
|
322
327
|
}
|
|
323
|
-
}
|
|
328
|
+
};
|
|
329
|
+
};
|
|
324
330
|
return {
|
|
325
331
|
proposed: latestBlockId,
|
|
326
332
|
checkpointed: makeTipId(checkpointedBlockId),
|
|
327
333
|
proven: makeTipId(provenBlockId),
|
|
328
|
-
finalized: makeTipId(finalizedBlockId)
|
|
334
|
+
finalized: makeTipId(finalizedBlockId),
|
|
335
|
+
proposedCheckpoint: makeTipId(proposedCheckpointBlockId)
|
|
329
336
|
};
|
|
330
337
|
}
|
|
331
|
-
|
|
338
|
+
getSyncedL2EpochNumber() {
|
|
332
339
|
throw new Error('Method not implemented.');
|
|
333
340
|
}
|
|
334
|
-
|
|
341
|
+
getSyncedL2SlotNumber() {
|
|
335
342
|
throw new Error('Method not implemented.');
|
|
336
343
|
}
|
|
337
344
|
isEpochComplete(_epochNumber) {
|
|
@@ -340,9 +347,12 @@ import { TxExecutionResult, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
340
347
|
getL1Constants() {
|
|
341
348
|
return Promise.resolve(EmptyL1RollupConstants);
|
|
342
349
|
}
|
|
350
|
+
isPruneDueAtSlot(_slot) {
|
|
351
|
+
return Promise.resolve(false);
|
|
352
|
+
}
|
|
343
353
|
getGenesisValues() {
|
|
344
354
|
return Promise.resolve({
|
|
345
|
-
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
355
|
+
genesisArchiveRoot: this.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT)
|
|
346
356
|
});
|
|
347
357
|
}
|
|
348
358
|
getL1Timestamp() {
|
|
@@ -383,6 +393,88 @@ import { TxExecutionResult, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
383
393
|
syncImmediate() {
|
|
384
394
|
return Promise.resolve();
|
|
385
395
|
}
|
|
396
|
+
async getBlock(query) {
|
|
397
|
+
if ('number' in query) {
|
|
398
|
+
if (query.number === 0) {
|
|
399
|
+
return this.getGenesisBlock();
|
|
400
|
+
}
|
|
401
|
+
return this.l2Blocks[query.number - 1];
|
|
402
|
+
}
|
|
403
|
+
if ('hash' in query) {
|
|
404
|
+
const genesis = this.getGenesisBlock();
|
|
405
|
+
if ((await genesis.hash()).equals(query.hash)) {
|
|
406
|
+
return genesis;
|
|
407
|
+
}
|
|
408
|
+
for (const b of this.l2Blocks){
|
|
409
|
+
const hash = await b.hash();
|
|
410
|
+
if (hash.equals(query.hash)) {
|
|
411
|
+
return b;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return undefined;
|
|
415
|
+
}
|
|
416
|
+
if ('archive' in query) {
|
|
417
|
+
const genesis = this.getGenesisBlock();
|
|
418
|
+
if (genesis.archive.root.equals(query.archive)) {
|
|
419
|
+
return genesis;
|
|
420
|
+
}
|
|
421
|
+
return this.l2Blocks.find((b)=>b.archive.root.equals(query.archive));
|
|
422
|
+
}
|
|
423
|
+
const number = this.resolveBlockTag(query.tag);
|
|
424
|
+
if (number === 0) {
|
|
425
|
+
return this.getGenesisBlock();
|
|
426
|
+
}
|
|
427
|
+
return this.l2Blocks[number - 1];
|
|
428
|
+
}
|
|
429
|
+
resolveBlockTag(tag) {
|
|
430
|
+
switch(tag){
|
|
431
|
+
case 'latest':
|
|
432
|
+
case 'proposed':
|
|
433
|
+
return this.l2Blocks.length;
|
|
434
|
+
case 'checkpointed':
|
|
435
|
+
return this.checkpointedBlockNumber;
|
|
436
|
+
case 'proven':
|
|
437
|
+
return this.provenBlockNumber;
|
|
438
|
+
case 'finalized':
|
|
439
|
+
return this.finalizedBlockNumber;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
getBlocks(query) {
|
|
443
|
+
let blocks;
|
|
444
|
+
if ('from' in query) {
|
|
445
|
+
blocks = this.l2Blocks.slice(query.from - 1, query.from - 1 + query.limit);
|
|
446
|
+
} else {
|
|
447
|
+
const epochCheckpoints = this.getCheckpointsInEpoch(query.epoch);
|
|
448
|
+
blocks = epochCheckpoints.flatMap((c)=>c.blocks);
|
|
449
|
+
}
|
|
450
|
+
if (query.onlyCheckpointed) {
|
|
451
|
+
blocks = blocks.filter((b)=>b.header.globalVariables.blockNumber <= this.checkpointedBlockNumber);
|
|
452
|
+
}
|
|
453
|
+
return Promise.resolve(blocks);
|
|
454
|
+
}
|
|
455
|
+
async getBlockData(query) {
|
|
456
|
+
const block = await this.getBlock(query);
|
|
457
|
+
if (!block) {
|
|
458
|
+
return undefined;
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
header: block.header,
|
|
462
|
+
archive: block.archive,
|
|
463
|
+
blockHash: await block.hash(),
|
|
464
|
+
checkpointNumber: block.checkpointNumber,
|
|
465
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
async getBlocksData(query) {
|
|
469
|
+
const blocks = await this.getBlocks(query);
|
|
470
|
+
return Promise.all(blocks.map(async (block)=>({
|
|
471
|
+
header: block.header,
|
|
472
|
+
archive: block.archive,
|
|
473
|
+
blockHash: await block.hash(),
|
|
474
|
+
checkpointNumber: block.checkpointNumber,
|
|
475
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint
|
|
476
|
+
})));
|
|
477
|
+
}
|
|
386
478
|
isPendingChainInvalid() {
|
|
387
479
|
return Promise.resolve(false);
|
|
388
480
|
}
|
|
@@ -391,4 +483,21 @@ import { TxExecutionResult, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
391
483
|
valid: true
|
|
392
484
|
});
|
|
393
485
|
}
|
|
486
|
+
getProposedCheckpointData(_query) {
|
|
487
|
+
return Promise.resolve(undefined);
|
|
488
|
+
}
|
|
489
|
+
/** Returns checkpoints whose slot falls within the given epoch. */ getCheckpointsInEpoch(epochNumber) {
|
|
490
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
491
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, {
|
|
492
|
+
epochDuration
|
|
493
|
+
});
|
|
494
|
+
return this.checkpointList.filter((c)=>c.header.slotNumber >= start && c.header.slotNumber <= end);
|
|
495
|
+
}
|
|
496
|
+
/** Creates a mock L1PublishedData for a checkpoint. */ mockL1DataForCheckpoint(checkpoint) {
|
|
497
|
+
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
498
|
+
}
|
|
499
|
+
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */ findCheckpointNumberForBlock(blockNumber) {
|
|
500
|
+
const checkpoint = this.checkpointList.find((c)=>c.blocks.some((b)=>b.number === blockNumber));
|
|
501
|
+
return checkpoint?.number;
|
|
502
|
+
}
|
|
394
503
|
}
|