@aztec/archiver 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448
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 +12 -6
- package/dest/archiver.d.ts +14 -9
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +97 -115
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +34 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +45 -16
- package/dest/factory.d.ts +5 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +32 -28
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +191 -259
- package/dest/l1/data_retrieval.d.ts +11 -11
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +36 -35
- 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/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +17 -10
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +39 -77
- package/dest/modules/data_store_updater.d.ts +25 -12
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +125 -94
- package/dest/modules/instrumentation.d.ts +18 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +53 -18
- package/dest/modules/l1_synchronizer.d.ts +7 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +180 -139
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +69 -31
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +358 -137
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +16 -72
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +6 -2
- package/dest/store/kv_archiver_store.d.ts +64 -27
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +77 -30
- 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 +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +150 -53
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +21 -9
- package/dest/test/fake_l1_state.d.ts +21 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +133 -26
- package/dest/test/index.js +3 -1
- 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 +30 -9
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +161 -90
- package/dest/test/mock_structs.d.ts +6 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +20 -6
- 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 +14 -13
- package/src/archiver.ts +128 -141
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +48 -26
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +32 -38
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +81 -101
- package/src/modules/data_store_updater.ts +138 -124
- package/src/modules/instrumentation.ts +63 -19
- package/src/modules/l1_synchronizer.ts +204 -174
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +456 -177
- package/src/store/contract_class_store.ts +16 -110
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +120 -46
- package/src/store/l2_tips_cache.ts +128 -0
- package/src/store/log_store.ts +224 -63
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +178 -30
- package/src/test/index.ts +3 -0
- 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 +215 -88
- package/src/test/mock_structs.ts +42 -12
- package/src/test/noop_l1_archiver.ts +114 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { range } from '@aztec/foundation/array';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { isDefined } from '@aztec/foundation/types';
|
|
3
|
-
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
4
4
|
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
5
5
|
import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
6
6
|
/**
|
|
@@ -64,7 +64,7 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
|
64
64
|
if (!checkpointData) {
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
67
|
-
return BlockNumber(checkpointData.startBlock + checkpointData.
|
|
67
|
+
return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
68
68
|
}
|
|
69
69
|
getCheckpointedBlocks(from, limit) {
|
|
70
70
|
return this.store.getCheckpointedBlocks(from, limit);
|
|
@@ -75,6 +75,12 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
|
75
75
|
getBlockHeaderByArchive(archive) {
|
|
76
76
|
return this.store.getBlockHeaderByArchive(archive);
|
|
77
77
|
}
|
|
78
|
+
getBlockData(number) {
|
|
79
|
+
return this.store.getBlockData(number);
|
|
80
|
+
}
|
|
81
|
+
getBlockDataByArchive(archive) {
|
|
82
|
+
return this.store.getBlockDataByArchive(archive);
|
|
83
|
+
}
|
|
78
84
|
async getL2Block(number) {
|
|
79
85
|
// If the number provided is -ve, then return the latest block.
|
|
80
86
|
if (number < 0) {
|
|
@@ -90,7 +96,13 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
|
90
96
|
return this.store.getTxEffect(txHash);
|
|
91
97
|
}
|
|
92
98
|
getSettledTxReceipt(txHash) {
|
|
93
|
-
return this.store.getSettledTxReceipt(txHash);
|
|
99
|
+
return this.store.getSettledTxReceipt(txHash, this.l1Constants);
|
|
100
|
+
}
|
|
101
|
+
getProposedCheckpoint() {
|
|
102
|
+
return this.store.getProposedCheckpoint();
|
|
103
|
+
}
|
|
104
|
+
getProposedCheckpointOnly() {
|
|
105
|
+
return this.store.getProposedCheckpointOnly();
|
|
94
106
|
}
|
|
95
107
|
isPendingChainInvalid() {
|
|
96
108
|
return this.getPendingChainValidationStatus().then((status)=>!status.valid);
|
|
@@ -100,11 +112,11 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
|
100
112
|
valid: true
|
|
101
113
|
};
|
|
102
114
|
}
|
|
103
|
-
getPrivateLogsByTags(tags, page) {
|
|
104
|
-
return this.store.getPrivateLogsByTags(tags, page);
|
|
115
|
+
getPrivateLogsByTags(tags, page, upToBlockNumber) {
|
|
116
|
+
return this.store.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
105
117
|
}
|
|
106
|
-
getPublicLogsByTagsFromContract(contractAddress, tags, page) {
|
|
107
|
-
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
118
|
+
getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber) {
|
|
119
|
+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
108
120
|
}
|
|
109
121
|
getPublicLogs(filter) {
|
|
110
122
|
return this.store.getPublicLogs(filter);
|
|
@@ -146,89 +158,39 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
|
146
158
|
}
|
|
147
159
|
async getCheckpoints(checkpointNumber, limit) {
|
|
148
160
|
const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const publishedCheckpoint = new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations.map((x)=>CommitteeAttestation.fromBuffer(x)));
|
|
156
|
-
fullCheckpoints.push(publishedCheckpoint);
|
|
161
|
+
return Promise.all(checkpoints.map((ch)=>this.getPublishedCheckpointFromCheckpointData(ch)));
|
|
162
|
+
}
|
|
163
|
+
async getPublishedCheckpointFromCheckpointData(checkpoint) {
|
|
164
|
+
const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpoint.checkpointNumber);
|
|
165
|
+
if (!blocksForCheckpoint) {
|
|
166
|
+
throw new Error(`Blocks for checkpoint ${checkpoint.checkpointNumber} not found`);
|
|
157
167
|
}
|
|
158
|
-
|
|
168
|
+
const fullCheckpoint = new Checkpoint(checkpoint.archive, checkpoint.header, blocksForCheckpoint, checkpoint.checkpointNumber);
|
|
169
|
+
return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
|
|
159
170
|
}
|
|
160
171
|
getBlocksForSlot(slotNumber) {
|
|
161
172
|
return this.store.getBlocksForSlot(slotNumber);
|
|
162
173
|
}
|
|
163
174
|
async getCheckpointedBlocksForEpoch(epochNumber) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
168
|
-
const blocks = [];
|
|
169
|
-
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
|
|
170
|
-
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
|
|
171
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
172
|
-
const slot = (b)=>b.header.slotNumber;
|
|
173
|
-
while(checkpoint && slot(checkpoint) >= start){
|
|
174
|
-
if (slot(checkpoint) <= end) {
|
|
175
|
-
// push the blocks on backwards
|
|
176
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
177
|
-
for(let i = endBlock; i >= checkpoint.startBlock; i--){
|
|
178
|
-
const checkpointedBlock = await this.getCheckpointedBlock(BlockNumber(i));
|
|
179
|
-
if (checkpointedBlock) {
|
|
180
|
-
blocks.push(checkpointedBlock);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
185
|
-
}
|
|
186
|
-
return blocks.reverse();
|
|
175
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
176
|
+
const blocks = await Promise.all(checkpointsData.flatMap((checkpoint)=>range(checkpoint.blockCount, checkpoint.startBlock).map((blockNumber)=>this.getCheckpointedBlock(BlockNumber(blockNumber)))));
|
|
177
|
+
return blocks.filter(isDefined);
|
|
187
178
|
}
|
|
188
179
|
async getCheckpointedBlockHeadersForEpoch(epochNumber) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
193
|
-
const blocks = [];
|
|
194
|
-
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
|
|
195
|
-
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
|
|
196
|
-
let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
197
|
-
const slot = (b)=>b.header.slotNumber;
|
|
198
|
-
while(checkpoint && slot(checkpoint) >= start){
|
|
199
|
-
if (slot(checkpoint) <= end) {
|
|
200
|
-
// push the blocks on backwards
|
|
201
|
-
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
202
|
-
for(let i = endBlock; i >= checkpoint.startBlock; i--){
|
|
203
|
-
const block = await this.getBlockHeader(BlockNumber(i));
|
|
204
|
-
if (block) {
|
|
205
|
-
blocks.push(block);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
|
|
210
|
-
}
|
|
211
|
-
return blocks.reverse();
|
|
180
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
181
|
+
const blocks = await Promise.all(checkpointsData.flatMap((checkpoint)=>range(checkpoint.blockCount, checkpoint.startBlock).map((blockNumber)=>this.getBlockHeader(BlockNumber(blockNumber)))));
|
|
182
|
+
return blocks.filter(isDefined);
|
|
212
183
|
}
|
|
213
184
|
async getCheckpointsForEpoch(epochNumber) {
|
|
185
|
+
const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
|
|
186
|
+
return Promise.all(checkpointsData.map((data)=>this.getPublishedCheckpointFromCheckpointData(data).then((p)=>p.checkpoint)));
|
|
187
|
+
}
|
|
188
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given epoch. */ getCheckpointsDataForEpoch(epochNumber) {
|
|
214
189
|
if (!this.l1Constants) {
|
|
215
190
|
throw new Error('L1 constants not set');
|
|
216
191
|
}
|
|
217
192
|
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
218
|
-
|
|
219
|
-
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
|
|
220
|
-
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
|
|
221
|
-
let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
|
|
222
|
-
const slot = (b)=>b.header.slotNumber;
|
|
223
|
-
while(checkpointData && slot(checkpointData) >= start){
|
|
224
|
-
if (slot(checkpointData) <= end) {
|
|
225
|
-
// push the checkpoints on backwards
|
|
226
|
-
const [checkpoint] = await this.getCheckpoints(checkpointData.checkpointNumber, 1);
|
|
227
|
-
checkpoints.push(checkpoint.checkpoint);
|
|
228
|
-
}
|
|
229
|
-
checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
|
|
230
|
-
}
|
|
231
|
-
return checkpoints.reverse();
|
|
193
|
+
return this.store.getCheckpointDataForSlotRange(start, end);
|
|
232
194
|
}
|
|
233
195
|
async getBlock(number) {
|
|
234
196
|
// If the number provided is -ve, then return the latest block.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
3
|
-
import type
|
|
3
|
+
import { type ProposedCheckpointInput, type PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
4
4
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
5
|
+
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
5
6
|
/** Result of adding checkpoints with information about any pruned blocks. */
|
|
6
7
|
type ReconcileCheckpointsResult = {
|
|
7
8
|
/** Blocks that were pruned due to conflict with L1 checkpoints. */
|
|
@@ -12,31 +13,34 @@ type ReconcileCheckpointsResult = {
|
|
|
12
13
|
/** Archiver helper module to handle updates to the data store. */
|
|
13
14
|
export declare class ArchiverDataStoreUpdater {
|
|
14
15
|
private store;
|
|
16
|
+
private l2TipsCache?;
|
|
17
|
+
private opts;
|
|
15
18
|
private readonly log;
|
|
16
|
-
constructor(store: KVArchiverDataStore
|
|
19
|
+
constructor(store: KVArchiverDataStore, l2TipsCache?: L2TipsCache | undefined, opts?: {
|
|
20
|
+
rollupManaLimit?: number;
|
|
21
|
+
});
|
|
17
22
|
/**
|
|
18
|
-
* Adds proposed
|
|
19
|
-
*
|
|
20
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
21
|
-
* and individually broadcasted functions from the block logs.
|
|
23
|
+
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
24
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
25
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
|
|
22
26
|
*
|
|
23
|
-
* @param
|
|
27
|
+
* @param block - The proposed L2 block to add.
|
|
24
28
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
25
29
|
* @returns True if the operation is successful.
|
|
26
30
|
*/
|
|
27
|
-
|
|
31
|
+
addProposedBlock(block: L2Block, pendingChainValidationStatus?: ValidateCheckpointResult): Promise<boolean>;
|
|
28
32
|
/**
|
|
29
33
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
30
34
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
31
35
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
32
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
33
|
-
* and individually broadcasted functions from the checkpoint block logs.
|
|
36
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
34
37
|
*
|
|
35
38
|
* @param checkpoints - The published checkpoints to add.
|
|
36
39
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
37
40
|
* @returns Result with information about any pruned blocks.
|
|
38
41
|
*/
|
|
39
42
|
addCheckpoints(checkpoints: PublishedCheckpoint[], pendingChainValidationStatus?: ValidateCheckpointResult): Promise<ReconcileCheckpointsResult>;
|
|
43
|
+
setProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput): Promise<void>;
|
|
40
44
|
private pruneMismatchingLocalBlocks;
|
|
41
45
|
/**
|
|
42
46
|
* Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
|
|
@@ -59,6 +63,16 @@ export declare class ArchiverDataStoreUpdater {
|
|
|
59
63
|
* @returns True if the operation is successful.
|
|
60
64
|
*/
|
|
61
65
|
removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
68
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
69
|
+
*/
|
|
70
|
+
setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
73
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
74
|
+
*/
|
|
75
|
+
setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void>;
|
|
62
76
|
/** Extracts and stores contract data from a single block. */
|
|
63
77
|
private addContractDataToDb;
|
|
64
78
|
/** Removes contract data associated with a block. */
|
|
@@ -67,7 +81,6 @@ export declare class ArchiverDataStoreUpdater {
|
|
|
67
81
|
private updatePublishedContractClasses;
|
|
68
82
|
private updateDeployedContractInstances;
|
|
69
83
|
private updateUpdatedContractInstances;
|
|
70
|
-
private storeBroadcastedIndividualFunctions;
|
|
71
84
|
}
|
|
72
85
|
export {};
|
|
73
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
86
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV9zdG9yZV91cGRhdGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9kYXRhX3N0b3JlX3VwZGF0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBUWhGLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQzdFLE9BQU8sRUFBRSxLQUFLLHVCQUF1QixFQUFFLEtBQUssbUJBQW1CLEVBQXNCLE1BQU0sMEJBQTBCLENBQUM7QUFTdEgsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUN6RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQVE3RCw2RUFBNkU7QUFDN0UsS0FBSywwQkFBMEIsR0FBRztJQUNoQyxtRUFBbUU7SUFDbkUsWUFBWSxFQUFFLE9BQU8sRUFBRSxHQUFHLFNBQVMsQ0FBQztJQUNwQyxpRkFBaUY7SUFDakYsOEJBQThCLEVBQUUsV0FBVyxHQUFHLFNBQVMsQ0FBQztDQUN6RCxDQUFDO0FBRUYsa0VBQWtFO0FBQ2xFLHFCQUFhLHdCQUF3QjtJQUlqQyxPQUFPLENBQUMsS0FBSztJQUNiLE9BQU8sQ0FBQyxXQUFXLENBQUM7SUFDcEIsT0FBTyxDQUFDLElBQUk7SUFMZCxPQUFPLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBMEM7SUFFOUQsWUFDVSxLQUFLLEVBQUUsbUJBQW1CLEVBQzFCLFdBQVcsQ0FBQyx5QkFBYSxFQUN6QixJQUFJLEdBQUU7UUFBRSxlQUFlLENBQUMsRUFBRSxNQUFNLENBQUE7S0FBTyxFQUM3QztJQUVKOzs7Ozs7OztPQVFHO0lBQ1UsZ0JBQWdCLENBQzNCLEtBQUssRUFBRSxPQUFPLEVBQ2QsNEJBQTRCLENBQUMsRUFBRSx3QkFBd0IsR0FDdEQsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQWlCbEI7SUFFRDs7Ozs7Ozs7O09BU0c7SUFDVSxjQUFjLENBQ3pCLFdBQVcsRUFBRSxtQkFBbUIsRUFBRSxFQUNsQyw0QkFBNEIsQ0FBQyxFQUFFLHdCQUF3QixHQUN0RCxPQUFPLENBQUMsMEJBQTBCLENBQUMsQ0E2QnJDO0lBRVkscUJBQXFCLENBQUMsa0JBQWtCLEVBQUUsdUJBQXVCLGlCQU83RTtZQVFhLDJCQUEyQjtJQW1FekM7Ozs7Ozs7O09BUUc7SUFDVSwrQkFBK0IsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQW1CekY7WUFNYSxpQkFBaUI7SUFhL0I7Ozs7Ozs7O09BUUc7SUFDVSxzQkFBc0IsQ0FBQyxnQkFBZ0IsRUFBRSxnQkFBZ0IsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBZXhGO0lBRUQ7OztPQUdHO0lBQ1UseUJBQXlCLENBQUMsZ0JBQWdCLEVBQUUsZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUt4RjtJQUVEOzs7T0FHRztJQUNVLDRCQUE0QixDQUFDLGdCQUFnQixFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FLM0Y7SUFFRCw2REFBNkQ7SUFDN0QsT0FBTyxDQUFDLG1CQUFtQjtJQUkzQixxREFBcUQ7SUFDckQsT0FBTyxDQUFDLHdCQUF3QjtZQUtsQixzQkFBc0I7WUFpQnRCLDhCQUE4QjtZQStDOUIsK0JBQStCO1lBMEMvQiw4QkFBOEI7Q0FzQjdDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data_store_updater.d.ts","sourceRoot":"","sources":["../../src/modules/data_store_updater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"data_store_updater.d.ts","sourceRoot":"","sources":["../../src/modules/data_store_updater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAQhF,OAAO,KAAK,EAAE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAsB,MAAM,0BAA0B,CAAC;AAStH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAQ7D,6EAA6E;AAC7E,KAAK,0BAA0B,GAAG;IAChC,mEAAmE;IACnE,YAAY,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IACpC,iFAAiF;IACjF,8BAA8B,EAAE,WAAW,GAAG,SAAS,CAAC;CACzD,CAAC;AAEF,kEAAkE;AAClE,qBAAa,wBAAwB;IAIjC,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,WAAW,CAAC;IACpB,OAAO,CAAC,IAAI;IALd,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0C;IAE9D,YACU,KAAK,EAAE,mBAAmB,EAC1B,WAAW,CAAC,yBAAa,EACzB,IAAI,GAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAA;KAAO,EAC7C;IAEJ;;;;;;;;OAQG;IACU,gBAAgB,CAC3B,KAAK,EAAE,OAAO,EACd,4BAA4B,CAAC,EAAE,wBAAwB,GACtD,OAAO,CAAC,OAAO,CAAC,CAiBlB;IAED;;;;;;;;;OASG;IACU,cAAc,CACzB,WAAW,EAAE,mBAAmB,EAAE,EAClC,4BAA4B,CAAC,EAAE,wBAAwB,GACtD,OAAO,CAAC,0BAA0B,CAAC,CA6BrC;IAEY,qBAAqB,CAAC,kBAAkB,EAAE,uBAAuB,iBAO7E;YAQa,2BAA2B;IAmEzC;;;;;;;;OAQG;IACU,+BAA+B,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAmBzF;YAMa,iBAAiB;IAa/B;;;;;;;;OAQG;IACU,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAexF;IAED;;;OAGG;IACU,yBAAyB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxF;IAED;;;OAGG;IACU,4BAA4B,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAK3F;IAED,6DAA6D;IAC7D,OAAO,CAAC,mBAAmB;IAI3B,qDAAqD;IACrD,OAAO,CAAC,wBAAwB;YAKlB,sBAAsB;YAiBtB,8BAA8B;YA+C9B,+BAA+B;YA0C/B,8BAA8B;CAsB7C"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import {
|
|
2
|
+
import { filterAsync } from '@aztec/foundation/collection';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { ContractClassPublishedEvent
|
|
4
|
+
import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
5
5
|
import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
7
|
+
import { computeContractAddressFromInstance, computeContractClassId } from '@aztec/stdlib/contract';
|
|
8
8
|
/** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
|
|
9
9
|
Operation[Operation["Store"] = 0] = "Store";
|
|
10
10
|
Operation[Operation["Delete"] = 1] = "Delete";
|
|
@@ -12,50 +12,61 @@ import groupBy from 'lodash.groupby';
|
|
|
12
12
|
}(Operation || {});
|
|
13
13
|
/** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
|
|
14
14
|
store;
|
|
15
|
+
l2TipsCache;
|
|
16
|
+
opts;
|
|
15
17
|
log;
|
|
16
|
-
constructor(store){
|
|
18
|
+
constructor(store, l2TipsCache, opts = {}){
|
|
17
19
|
this.store = store;
|
|
20
|
+
this.l2TipsCache = l2TipsCache;
|
|
21
|
+
this.opts = opts;
|
|
18
22
|
this.log = createLogger('archiver:store_updater');
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
|
-
* Adds proposed
|
|
22
|
-
*
|
|
23
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
24
|
-
* and individually broadcasted functions from the block logs.
|
|
25
|
+
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
26
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
27
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
|
|
25
28
|
*
|
|
26
|
-
* @param
|
|
29
|
+
* @param block - The proposed L2 block to add.
|
|
27
30
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
28
31
|
* @returns True if the operation is successful.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
await this.store.
|
|
32
|
+
*/ async addProposedBlock(block, pendingChainValidationStatus) {
|
|
33
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
34
|
+
await this.store.addProposedBlock(block);
|
|
32
35
|
const opResults = await Promise.all([
|
|
33
36
|
// Update the pending chain validation status if provided
|
|
34
37
|
pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
35
|
-
// Add any logs emitted during the retrieved
|
|
36
|
-
this.store.addLogs(
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
// Add any logs emitted during the retrieved block
|
|
39
|
+
this.store.addLogs([
|
|
40
|
+
block
|
|
41
|
+
]),
|
|
42
|
+
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
43
|
+
this.addContractDataToDb(block)
|
|
39
44
|
]);
|
|
45
|
+
await this.l2TipsCache?.refresh();
|
|
40
46
|
return opResults.every(Boolean);
|
|
41
47
|
});
|
|
48
|
+
return result;
|
|
42
49
|
}
|
|
43
50
|
/**
|
|
44
51
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
45
52
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
46
53
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
47
|
-
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events
|
|
48
|
-
* and individually broadcasted functions from the checkpoint block logs.
|
|
54
|
+
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
49
55
|
*
|
|
50
56
|
* @param checkpoints - The published checkpoints to add.
|
|
51
57
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
52
58
|
* @returns Result with information about any pruned blocks.
|
|
53
|
-
*/ addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
54
|
-
|
|
59
|
+
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
60
|
+
for (const checkpoint of checkpoints){
|
|
61
|
+
validateCheckpoint(checkpoint.checkpoint, {
|
|
62
|
+
rollupManaLimit: this.opts?.rollupManaLimit
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
55
66
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
56
67
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
57
68
|
await this.store.addCheckpoints(checkpoints);
|
|
58
|
-
// Filter out blocks that were already inserted via
|
|
69
|
+
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
59
70
|
const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
60
71
|
await Promise.all([
|
|
61
72
|
// Update the pending chain validation status if provided
|
|
@@ -65,11 +76,20 @@ import groupBy from 'lodash.groupby';
|
|
|
65
76
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
66
77
|
...newBlocks.map((block)=>this.addContractDataToDb(block))
|
|
67
78
|
]);
|
|
79
|
+
await this.l2TipsCache?.refresh();
|
|
68
80
|
return {
|
|
69
81
|
prunedBlocks,
|
|
70
82
|
lastAlreadyInsertedBlockNumber
|
|
71
83
|
};
|
|
72
84
|
});
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
async setProposedCheckpoint(proposedCheckpoint) {
|
|
88
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
89
|
+
await this.store.setProposedCheckpoint(proposedCheckpoint);
|
|
90
|
+
await this.l2TipsCache?.refresh();
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
73
93
|
}
|
|
74
94
|
/**
|
|
75
95
|
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
@@ -113,7 +133,7 @@ import groupBy from 'lodash.groupby';
|
|
|
113
133
|
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
114
134
|
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
115
135
|
} else {
|
|
116
|
-
this.log.
|
|
136
|
+
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
117
137
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
118
138
|
return {
|
|
119
139
|
prunedBlocks,
|
|
@@ -147,15 +167,20 @@ import groupBy from 'lodash.groupby';
|
|
|
147
167
|
* @param blockNumber - Remove all blocks with number greater than this.
|
|
148
168
|
* @returns The removed blocks.
|
|
149
169
|
* @throws Error if any block to be removed is checkpointed.
|
|
150
|
-
*/ removeUncheckpointedBlocksAfter(blockNumber) {
|
|
151
|
-
|
|
170
|
+
*/ async removeUncheckpointedBlocksAfter(blockNumber) {
|
|
171
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
152
172
|
// Verify we're only removing uncheckpointed blocks
|
|
153
173
|
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
154
174
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
155
175
|
throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
156
176
|
}
|
|
157
|
-
|
|
177
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
178
|
+
// Clear the proposed checkpoint if it exists, since its blocks have been pruned
|
|
179
|
+
await this.store.deleteProposedCheckpoint();
|
|
180
|
+
await this.l2TipsCache?.refresh();
|
|
181
|
+
return result;
|
|
158
182
|
});
|
|
183
|
+
return result;
|
|
159
184
|
}
|
|
160
185
|
/**
|
|
161
186
|
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
@@ -179,17 +204,38 @@ import groupBy from 'lodash.groupby';
|
|
|
179
204
|
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
180
205
|
* @returns True if the operation is successful.
|
|
181
206
|
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
207
|
+
return await this.store.transactionAsync(async ()=>{
|
|
208
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
209
|
+
const opResults = await Promise.all([
|
|
210
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
211
|
+
this.store.setPendingChainValidationStatus({
|
|
212
|
+
valid: true
|
|
213
|
+
}),
|
|
214
|
+
// Remove contract data for all blocks being removed
|
|
215
|
+
...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
|
|
216
|
+
this.store.deleteLogs(blocksRemoved)
|
|
217
|
+
]);
|
|
218
|
+
await this.l2TipsCache?.refresh();
|
|
219
|
+
return opResults.every(Boolean);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
224
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
225
|
+
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
226
|
+
await this.store.transactionAsync(async ()=>{
|
|
227
|
+
await this.store.setProvenCheckpointNumber(checkpointNumber);
|
|
228
|
+
await this.l2TipsCache?.refresh();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
233
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
234
|
+
*/ async setFinalizedCheckpointNumber(checkpointNumber) {
|
|
235
|
+
await this.store.transactionAsync(async ()=>{
|
|
236
|
+
await this.store.setFinalizedCheckpointNumber(checkpointNumber);
|
|
237
|
+
await this.l2TipsCache?.refresh();
|
|
238
|
+
});
|
|
193
239
|
}
|
|
194
240
|
/** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
|
|
195
241
|
return this.updateContractDataOnDb(block, 0);
|
|
@@ -204,31 +250,62 @@ import groupBy from 'lodash.groupby';
|
|
|
204
250
|
return (await Promise.all([
|
|
205
251
|
this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
|
|
206
252
|
this.updateDeployedContractInstances(privateLogs, block.number, operation),
|
|
207
|
-
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
208
|
-
operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
|
|
253
|
+
this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
|
|
209
254
|
])).every(Boolean);
|
|
210
255
|
}
|
|
211
256
|
/**
|
|
212
257
|
* Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
|
|
213
258
|
*/ async updatePublishedContractClasses(allLogs, blockNum, operation) {
|
|
214
259
|
const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
contractClasses.
|
|
218
|
-
|
|
219
|
-
// TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
|
|
220
|
-
const commitments = await Promise.all(contractClasses.map((c)=>computePublicBytecodeCommitment(c.packedBytecode)));
|
|
221
|
-
return await this.store.addContractClasses(contractClasses, commitments, blockNum);
|
|
222
|
-
} else if (operation == 1) {
|
|
260
|
+
if (operation == 1) {
|
|
261
|
+
const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
|
|
262
|
+
if (contractClasses.length > 0) {
|
|
263
|
+
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
223
264
|
return await this.store.deleteContractClasses(contractClasses, blockNum);
|
|
224
265
|
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
// Compute bytecode commitments and validate class IDs in a single pass.
|
|
269
|
+
const contractClasses = [];
|
|
270
|
+
for (const event of contractClassPublishedEvents){
|
|
271
|
+
const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
|
|
272
|
+
const computedClassId = await computeContractClassId({
|
|
273
|
+
artifactHash: contractClass.artifactHash,
|
|
274
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
275
|
+
publicBytecodeCommitment: contractClass.publicBytecodeCommitment
|
|
276
|
+
});
|
|
277
|
+
if (!computedClassId.equals(contractClass.id)) {
|
|
278
|
+
this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
|
|
279
|
+
blockNum,
|
|
280
|
+
contractClassId: event.contractClassId.toString()
|
|
281
|
+
});
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
contractClasses.push(contractClass);
|
|
285
|
+
}
|
|
286
|
+
if (contractClasses.length > 0) {
|
|
287
|
+
contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
288
|
+
return await this.store.addContractClasses(contractClasses, blockNum);
|
|
225
289
|
}
|
|
226
290
|
return true;
|
|
227
291
|
}
|
|
228
292
|
/**
|
|
229
293
|
* Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
|
|
230
294
|
*/ async updateDeployedContractInstances(allLogs, blockNum, operation) {
|
|
231
|
-
const
|
|
295
|
+
const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
|
|
296
|
+
// Verify that each instance's address matches the one derived from its fields if we're adding
|
|
297
|
+
const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
|
|
298
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
299
|
+
if (!computedAddress.equals(instance.address)) {
|
|
300
|
+
this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
|
|
301
|
+
instanceAddress: instance.address.toString(),
|
|
302
|
+
computedAddress: computedAddress.toString(),
|
|
303
|
+
blockNum
|
|
304
|
+
});
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
return true;
|
|
308
|
+
});
|
|
232
309
|
if (contractInstances.length > 0) {
|
|
233
310
|
contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
|
|
234
311
|
if (operation == 0) {
|
|
@@ -253,50 +330,4 @@ import groupBy from 'lodash.groupby';
|
|
|
253
330
|
}
|
|
254
331
|
return true;
|
|
255
332
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Stores the functions that were broadcasted individually.
|
|
258
|
-
*
|
|
259
|
-
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
|
|
260
|
-
* and will be deleted as part of the class if needed.
|
|
261
|
-
*/ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
|
|
262
|
-
// Filter out private and utility function broadcast events
|
|
263
|
-
const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
|
|
264
|
-
const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
|
|
265
|
-
// Group all events by contract class id
|
|
266
|
-
for (const [classIdString, classEvents] of Object.entries(groupBy([
|
|
267
|
-
...privateFnEvents,
|
|
268
|
-
...utilityFnEvents
|
|
269
|
-
], (e)=>e.contractClassId.toString()))){
|
|
270
|
-
const contractClassId = Fr.fromHexString(classIdString);
|
|
271
|
-
const contractClass = await this.store.getContractClass(contractClassId);
|
|
272
|
-
if (!contractClass) {
|
|
273
|
-
this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
|
|
274
|
-
continue;
|
|
275
|
-
}
|
|
276
|
-
// Split private and utility functions, and filter out invalid ones
|
|
277
|
-
const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
|
|
278
|
-
const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
|
|
279
|
-
const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
|
|
280
|
-
const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
|
|
281
|
-
fn,
|
|
282
|
-
valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
|
|
283
|
-
})));
|
|
284
|
-
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
285
|
-
const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
|
|
286
|
-
fn,
|
|
287
|
-
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
|
|
288
|
-
})));
|
|
289
|
-
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
|
|
290
|
-
const validFnCount = validPrivateFns.length + validUtilityFns.length;
|
|
291
|
-
if (validFnCount !== allFns.length) {
|
|
292
|
-
this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
|
|
293
|
-
}
|
|
294
|
-
// Store the functions in the contract class in a single operation
|
|
295
|
-
if (validFnCount > 0) {
|
|
296
|
-
this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
|
|
297
|
-
}
|
|
298
|
-
return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
|
|
299
|
-
}
|
|
300
|
-
return true;
|
|
301
|
-
}
|
|
302
333
|
}
|