@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -22
- package/dest/archiver.d.ts +139 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +699 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +21 -5
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +62 -0
- package/dest/factory.d.ts +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +97 -13
- package/dest/index.d.ts +11 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/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 +148 -0
- package/dest/l1/calldata_retriever.d.ts +118 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +484 -0
- package/dest/l1/data_retrieval.d.ts +89 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver → l1}/data_retrieval.js +80 -153
- 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 +157 -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 +89 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +216 -0
- package/dest/modules/data_store_updater.d.ts +80 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +323 -0
- package/dest/modules/instrumentation.d.ts +39 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +39 -62
- package/dest/modules/l1_synchronizer.d.ts +76 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +196 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +773 -0
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +13 -9
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +354 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +464 -0
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +456 -0
- package/dest/store/message_store.d.ts +40 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
- 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 +193 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +389 -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 +21 -11
- package/dest/test/mock_l2_block_source.d.ts +51 -18
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +245 -82
- package/dest/test/mock_structs.d.ts +80 -4
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +145 -11
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +20 -20
- package/src/archiver.ts +443 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +102 -0
- package/src/factory.ts +143 -13
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +98 -0
- package/src/l1/bin/retrieve-calldata.ts +181 -0
- package/src/l1/calldata_retriever.ts +663 -0
- package/src/{archiver → l1}/data_retrieval.ts +146 -224
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +160 -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 +328 -0
- package/src/modules/data_store_updater.ts +448 -0
- package/src/{archiver → modules}/instrumentation.ts +43 -66
- package/src/modules/l1_synchronizer.ts +932 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +1015 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +13 -9
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
- package/src/store/kv_archiver_store.ts +671 -0
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +637 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
- package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
- package/src/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +607 -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 +18 -11
- package/src/test/mock_l2_block_source.ts +296 -90
- package/src/test/mock_structs.ts +275 -13
- package/src/test/noop_l1_archiver.ts +109 -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/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_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/kv_archiver_store/block_store.ts +0 -481
- 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
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { filterAsync } from '@aztec/foundation/collection';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
7
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
8
|
+
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
9
|
+
import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
10
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
11
|
+
/**
|
|
12
|
+
* A store for logs
|
|
13
|
+
*/ export class LogStore {
|
|
14
|
+
db;
|
|
15
|
+
blockStore;
|
|
16
|
+
// `tag` --> private logs
|
|
17
|
+
#privateLogsByTag;
|
|
18
|
+
// `{contractAddress}_${tag}` --> public logs
|
|
19
|
+
#publicLogsByContractAndTag;
|
|
20
|
+
#privateLogKeysByBlock;
|
|
21
|
+
#publicLogKeysByBlock;
|
|
22
|
+
#publicLogsByBlock;
|
|
23
|
+
#contractClassLogsByBlock;
|
|
24
|
+
#logsMaxPageSize;
|
|
25
|
+
#log;
|
|
26
|
+
constructor(db, blockStore, logsMaxPageSize = 1000){
|
|
27
|
+
this.db = db;
|
|
28
|
+
this.blockStore = blockStore;
|
|
29
|
+
this.#log = createLogger('archiver:log_store');
|
|
30
|
+
this.#privateLogsByTag = db.openMap('archiver_private_tagged_logs_by_tag');
|
|
31
|
+
this.#publicLogsByContractAndTag = db.openMap('archiver_public_tagged_logs_by_tag');
|
|
32
|
+
this.#privateLogKeysByBlock = db.openMap('archiver_private_log_keys_by_block');
|
|
33
|
+
this.#publicLogKeysByBlock = db.openMap('archiver_public_log_keys_by_block');
|
|
34
|
+
this.#publicLogsByBlock = db.openMap('archiver_public_logs_by_block');
|
|
35
|
+
this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
|
|
36
|
+
this.#logsMaxPageSize = logsMaxPageSize;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Extracts tagged logs from a single block, grouping them into private and public maps.
|
|
40
|
+
*
|
|
41
|
+
* @param block - The L2 block to extract logs from.
|
|
42
|
+
* @returns An object containing the private and public tagged logs for the block.
|
|
43
|
+
*/ #extractTaggedLogsFromBlock(block) {
|
|
44
|
+
// SiloedTag (as string) -> array of log buffers.
|
|
45
|
+
const privateTaggedLogs = new Map();
|
|
46
|
+
// "{contractAddress}_{tag}" (as string) -> array of log buffers.
|
|
47
|
+
const publicTaggedLogs = new Map();
|
|
48
|
+
block.body.txEffects.forEach((txEffect)=>{
|
|
49
|
+
const txHash = txEffect.txHash;
|
|
50
|
+
txEffect.privateLogs.forEach((log)=>{
|
|
51
|
+
// Private logs use SiloedTag (already siloed by kernel)
|
|
52
|
+
const tag = log.fields[0];
|
|
53
|
+
this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
|
|
54
|
+
const currentLogs = privateTaggedLogs.get(tag.toString()) ?? [];
|
|
55
|
+
currentLogs.push(new TxScopedL2Log(txHash, block.number, block.timestamp, log.getEmittedFields(), txEffect.noteHashes, txEffect.nullifiers[0]).toBuffer());
|
|
56
|
+
privateTaggedLogs.set(tag.toString(), currentLogs);
|
|
57
|
+
});
|
|
58
|
+
txEffect.publicLogs.forEach((log)=>{
|
|
59
|
+
// Public logs use Tag directly (not siloed) and are stored with contract address
|
|
60
|
+
const tag = log.fields[0];
|
|
61
|
+
const contractAddress = log.contractAddress;
|
|
62
|
+
const key = `${contractAddress.toString()}_${tag.toString()}`;
|
|
63
|
+
this.#log.debug(`Found public log with tag ${tag.toString()} from contract ${contractAddress.toString()} in block ${block.number}`);
|
|
64
|
+
const currentLogs = publicTaggedLogs.get(key) ?? [];
|
|
65
|
+
currentLogs.push(new TxScopedL2Log(txHash, block.number, block.timestamp, log.getEmittedFields(), txEffect.noteHashes, txEffect.nullifiers[0]).toBuffer());
|
|
66
|
+
publicTaggedLogs.set(key, currentLogs);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
privateTaggedLogs,
|
|
71
|
+
publicTaggedLogs
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Extracts and aggregates tagged logs from a list of blocks.
|
|
76
|
+
* @param blocks - The blocks to extract logs from.
|
|
77
|
+
* @returns A map from tag (as string) to an array of serialized private logs belonging to that tag, and a map from
|
|
78
|
+
* "{contractAddress}_{tag}" (as string) to an array of serialized public logs belonging to that key.
|
|
79
|
+
*/ #extractTaggedLogs(blocks) {
|
|
80
|
+
const taggedLogsInBlocks = blocks.map((block)=>this.#extractTaggedLogsFromBlock(block));
|
|
81
|
+
// Now we merge the maps from each block into a single map.
|
|
82
|
+
const privateTaggedLogs = taggedLogsInBlocks.reduce((acc, { privateTaggedLogs })=>{
|
|
83
|
+
for (const [tag, logs] of privateTaggedLogs.entries()){
|
|
84
|
+
const currentLogs = acc.get(tag) ?? [];
|
|
85
|
+
acc.set(tag, currentLogs.concat(logs));
|
|
86
|
+
}
|
|
87
|
+
return acc;
|
|
88
|
+
}, new Map());
|
|
89
|
+
const publicTaggedLogs = taggedLogsInBlocks.reduce((acc, { publicTaggedLogs })=>{
|
|
90
|
+
for (const [key, logs] of publicTaggedLogs.entries()){
|
|
91
|
+
const currentLogs = acc.get(key) ?? [];
|
|
92
|
+
acc.set(key, currentLogs.concat(logs));
|
|
93
|
+
}
|
|
94
|
+
return acc;
|
|
95
|
+
}, new Map());
|
|
96
|
+
return {
|
|
97
|
+
privateTaggedLogs,
|
|
98
|
+
publicTaggedLogs
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async #addPrivateLogs(blocks) {
|
|
102
|
+
const newBlocks = await filterAsync(blocks, async (block)=>!await this.#privateLogKeysByBlock.hasAsync(block.number));
|
|
103
|
+
const { privateTaggedLogs } = this.#extractTaggedLogs(newBlocks);
|
|
104
|
+
const keysOfPrivateLogsToUpdate = Array.from(privateTaggedLogs.keys());
|
|
105
|
+
const currentPrivateTaggedLogs = await Promise.all(keysOfPrivateLogsToUpdate.map(async (key)=>({
|
|
106
|
+
tag: key,
|
|
107
|
+
logBuffers: await this.#privateLogsByTag.getAsync(key)
|
|
108
|
+
})));
|
|
109
|
+
for (const taggedLogBuffer of currentPrivateTaggedLogs){
|
|
110
|
+
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
111
|
+
privateTaggedLogs.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(privateTaggedLogs.get(taggedLogBuffer.tag)));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (const block of newBlocks){
|
|
115
|
+
const privateTagsInBlock = [];
|
|
116
|
+
for (const [tag, logs] of privateTaggedLogs.entries()){
|
|
117
|
+
await this.#privateLogsByTag.set(tag, logs);
|
|
118
|
+
privateTagsInBlock.push(tag);
|
|
119
|
+
}
|
|
120
|
+
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async #addPublicLogs(blocks) {
|
|
124
|
+
const newBlocks = await filterAsync(blocks, async (block)=>!await this.#publicLogKeysByBlock.hasAsync(block.number));
|
|
125
|
+
const { publicTaggedLogs } = this.#extractTaggedLogs(newBlocks);
|
|
126
|
+
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
127
|
+
const currentPublicTaggedLogs = await Promise.all(keysOfPublicLogsToUpdate.map(async (key)=>({
|
|
128
|
+
tag: key,
|
|
129
|
+
logBuffers: await this.#publicLogsByContractAndTag.getAsync(key)
|
|
130
|
+
})));
|
|
131
|
+
for (const taggedLogBuffer of currentPublicTaggedLogs){
|
|
132
|
+
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
133
|
+
publicTaggedLogs.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(publicTaggedLogs.get(taggedLogBuffer.tag)));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
for (const block of newBlocks){
|
|
137
|
+
const blockHash = await block.hash();
|
|
138
|
+
const publicTagsInBlock = [];
|
|
139
|
+
for (const [tag, logs] of publicTaggedLogs.entries()){
|
|
140
|
+
await this.#publicLogsByContractAndTag.set(tag, logs);
|
|
141
|
+
publicTagsInBlock.push(tag);
|
|
142
|
+
}
|
|
143
|
+
await this.#publicLogKeysByBlock.set(block.number, publicTagsInBlock);
|
|
144
|
+
const publicLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
145
|
+
numToUInt32BE(txIndex),
|
|
146
|
+
txEffect.txHash.toBuffer(),
|
|
147
|
+
numToUInt32BE(txEffect.publicLogs.length),
|
|
148
|
+
txEffect.publicLogs.map((log)=>log.toBuffer())
|
|
149
|
+
].flat()).flat();
|
|
150
|
+
await this.#publicLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, publicLogsInBlock));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async #addContractClassLogs(blocks) {
|
|
154
|
+
const newBlocks = await filterAsync(blocks, async (block)=>!await this.#contractClassLogsByBlock.hasAsync(block.number));
|
|
155
|
+
for (const block of newBlocks){
|
|
156
|
+
const blockHash = await block.hash();
|
|
157
|
+
const contractClassLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
158
|
+
numToUInt32BE(txIndex),
|
|
159
|
+
txEffect.txHash.toBuffer(),
|
|
160
|
+
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
161
|
+
txEffect.contractClassLogs.map((log)=>log.toBuffer())
|
|
162
|
+
].flat()).flat();
|
|
163
|
+
await this.#contractClassLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, contractClassLogsInBlock));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Append new logs to the store's list.
|
|
168
|
+
* @param blocks - The blocks for which to add the logs.
|
|
169
|
+
* @returns True if the operation is successful.
|
|
170
|
+
*/ addLogs(blocks) {
|
|
171
|
+
return this.db.transactionAsync(async ()=>{
|
|
172
|
+
await Promise.all([
|
|
173
|
+
this.#addPrivateLogs(blocks),
|
|
174
|
+
this.#addPublicLogs(blocks),
|
|
175
|
+
this.#addContractClassLogs(blocks)
|
|
176
|
+
]);
|
|
177
|
+
return true;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
#packWithBlockHash(blockHash, data) {
|
|
181
|
+
return Buffer.concat([
|
|
182
|
+
blockHash.toBuffer(),
|
|
183
|
+
...data
|
|
184
|
+
]);
|
|
185
|
+
}
|
|
186
|
+
#unpackBlockHash(reader) {
|
|
187
|
+
const blockHash = reader.remainingBytes() > 0 ? reader.readObject(Fr) : undefined;
|
|
188
|
+
if (!blockHash) {
|
|
189
|
+
throw new Error('Failed to read block hash from log entry buffer');
|
|
190
|
+
}
|
|
191
|
+
return new BlockHash(blockHash);
|
|
192
|
+
}
|
|
193
|
+
deleteLogs(blocks) {
|
|
194
|
+
return this.db.transactionAsync(async ()=>{
|
|
195
|
+
await Promise.all(blocks.map(async (block)=>{
|
|
196
|
+
// Delete private logs
|
|
197
|
+
const privateKeys = await this.#privateLogKeysByBlock.getAsync(block.number) ?? [];
|
|
198
|
+
await Promise.all(privateKeys.map((tag)=>this.#privateLogsByTag.delete(tag)));
|
|
199
|
+
// Delete public logs
|
|
200
|
+
const publicKeys = await this.#publicLogKeysByBlock.getAsync(block.number) ?? [];
|
|
201
|
+
await Promise.all(publicKeys.map((key)=>this.#publicLogsByContractAndTag.delete(key)));
|
|
202
|
+
}));
|
|
203
|
+
await Promise.all(blocks.map((block)=>Promise.all([
|
|
204
|
+
this.#publicLogsByBlock.delete(block.number),
|
|
205
|
+
this.#privateLogKeysByBlock.delete(block.number),
|
|
206
|
+
this.#publicLogKeysByBlock.delete(block.number),
|
|
207
|
+
this.#contractClassLogsByBlock.delete(block.number)
|
|
208
|
+
])));
|
|
209
|
+
return true;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
214
|
+
* array implies no logs match that tag.
|
|
215
|
+
* @param tags - The tags to search for.
|
|
216
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
217
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
218
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
219
|
+
*/ async getPrivateLogsByTags(tags, page = 0) {
|
|
220
|
+
const logs = await Promise.all(tags.map((tag)=>this.#privateLogsByTag.getAsync(tag.toString())));
|
|
221
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
222
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
223
|
+
return logs.map((logBuffers)=>logBuffers?.slice(start, end).map((logBuffer)=>TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
227
|
+
* logs is returned. An empty array implies no logs match that tag.
|
|
228
|
+
* @param contractAddress - The contract address to search logs for.
|
|
229
|
+
* @param tags - The tags to search for.
|
|
230
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
231
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
232
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
233
|
+
*/ async getPublicLogsByTagsFromContract(contractAddress, tags, page = 0) {
|
|
234
|
+
const logs = await Promise.all(tags.map((tag)=>{
|
|
235
|
+
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
236
|
+
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
237
|
+
}));
|
|
238
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
239
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
240
|
+
return logs.map((logBuffers)=>logBuffers?.slice(start, end).map((logBuffer)=>TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Gets public logs based on the provided filter.
|
|
244
|
+
* @param filter - The filter to apply to the logs.
|
|
245
|
+
* @returns The requested logs.
|
|
246
|
+
*/ getPublicLogs(filter) {
|
|
247
|
+
if (filter.afterLog) {
|
|
248
|
+
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
249
|
+
} else if (filter.txHash) {
|
|
250
|
+
return this.#filterPublicLogsOfTx(filter);
|
|
251
|
+
} else {
|
|
252
|
+
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async #filterPublicLogsOfTx(filter) {
|
|
256
|
+
if (!filter.txHash) {
|
|
257
|
+
throw new Error('Missing txHash');
|
|
258
|
+
}
|
|
259
|
+
const [blockNumber, txIndex] = await this.blockStore.getTxLocation(filter.txHash) ?? [];
|
|
260
|
+
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
261
|
+
return {
|
|
262
|
+
logs: [],
|
|
263
|
+
maxLogsHit: false
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
const buffer = await this.#publicLogsByBlock.getAsync(blockNumber) ?? Buffer.alloc(0);
|
|
267
|
+
const publicLogsInBlock = [];
|
|
268
|
+
const reader = new BufferReader(buffer);
|
|
269
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
270
|
+
while(reader.remainingBytes() > 0){
|
|
271
|
+
const indexOfTx = reader.readNumber();
|
|
272
|
+
const txHash = reader.readObject(TxHash);
|
|
273
|
+
const numLogsInTx = reader.readNumber();
|
|
274
|
+
publicLogsInBlock[indexOfTx] = {
|
|
275
|
+
txHash,
|
|
276
|
+
logs: []
|
|
277
|
+
};
|
|
278
|
+
for(let i = 0; i < numLogsInTx; i++){
|
|
279
|
+
publicLogsInBlock[indexOfTx].logs.push(reader.readObject(PublicLog));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const txData = publicLogsInBlock[txIndex];
|
|
283
|
+
const logs = [];
|
|
284
|
+
const maxLogsHit = this.#accumulatePublicLogs(logs, blockNumber, blockHash, txIndex, txData.txHash, txData.logs, filter);
|
|
285
|
+
return {
|
|
286
|
+
logs,
|
|
287
|
+
maxLogsHit
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
async #filterPublicLogsBetweenBlocks(filter) {
|
|
291
|
+
const start = filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
292
|
+
const end = filter.toBlock;
|
|
293
|
+
if (typeof end === 'number' && end < start) {
|
|
294
|
+
return {
|
|
295
|
+
logs: [],
|
|
296
|
+
maxLogsHit: true
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const logs = [];
|
|
300
|
+
let maxLogsHit = false;
|
|
301
|
+
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({
|
|
302
|
+
start,
|
|
303
|
+
end
|
|
304
|
+
})){
|
|
305
|
+
const publicLogsInBlock = [];
|
|
306
|
+
const reader = new BufferReader(logBuffer);
|
|
307
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
308
|
+
while(reader.remainingBytes() > 0){
|
|
309
|
+
const indexOfTx = reader.readNumber();
|
|
310
|
+
const txHash = reader.readObject(TxHash);
|
|
311
|
+
const numLogsInTx = reader.readNumber();
|
|
312
|
+
publicLogsInBlock[indexOfTx] = {
|
|
313
|
+
txHash,
|
|
314
|
+
logs: []
|
|
315
|
+
};
|
|
316
|
+
for(let i = 0; i < numLogsInTx; i++){
|
|
317
|
+
publicLogsInBlock[indexOfTx].logs.push(reader.readObject(PublicLog));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
for(let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++){
|
|
321
|
+
const txData = publicLogsInBlock[txIndex];
|
|
322
|
+
maxLogsHit = this.#accumulatePublicLogs(logs, blockNumber, blockHash, txIndex, txData.txHash, txData.logs, filter);
|
|
323
|
+
if (maxLogsHit) {
|
|
324
|
+
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
325
|
+
break loopOverBlocks;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
logs,
|
|
331
|
+
maxLogsHit
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Gets contract class logs based on the provided filter.
|
|
336
|
+
* @param filter - The filter to apply to the logs.
|
|
337
|
+
* @returns The requested logs.
|
|
338
|
+
*/ getContractClassLogs(filter) {
|
|
339
|
+
if (filter.afterLog) {
|
|
340
|
+
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
341
|
+
} else if (filter.txHash) {
|
|
342
|
+
return this.#filterContractClassLogsOfTx(filter);
|
|
343
|
+
} else {
|
|
344
|
+
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async #filterContractClassLogsOfTx(filter) {
|
|
348
|
+
if (!filter.txHash) {
|
|
349
|
+
throw new Error('Missing txHash');
|
|
350
|
+
}
|
|
351
|
+
const [blockNumber, txIndex] = await this.blockStore.getTxLocation(filter.txHash) ?? [];
|
|
352
|
+
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
353
|
+
return {
|
|
354
|
+
logs: [],
|
|
355
|
+
maxLogsHit: false
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
const contractClassLogsBuffer = await this.#contractClassLogsByBlock.getAsync(blockNumber) ?? Buffer.alloc(0);
|
|
359
|
+
const contractClassLogsInBlock = [];
|
|
360
|
+
const reader = new BufferReader(contractClassLogsBuffer);
|
|
361
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
362
|
+
while(reader.remainingBytes() > 0){
|
|
363
|
+
const indexOfTx = reader.readNumber();
|
|
364
|
+
const txHash = reader.readObject(TxHash);
|
|
365
|
+
const numLogsInTx = reader.readNumber();
|
|
366
|
+
contractClassLogsInBlock[indexOfTx] = {
|
|
367
|
+
txHash,
|
|
368
|
+
logs: []
|
|
369
|
+
};
|
|
370
|
+
for(let i = 0; i < numLogsInTx; i++){
|
|
371
|
+
contractClassLogsInBlock[indexOfTx].logs.push(reader.readObject(ContractClassLog));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const txData = contractClassLogsInBlock[txIndex];
|
|
375
|
+
const logs = [];
|
|
376
|
+
const maxLogsHit = this.#accumulateContractClassLogs(logs, blockNumber, blockHash, txIndex, txData.txHash, txData.logs, filter);
|
|
377
|
+
return {
|
|
378
|
+
logs,
|
|
379
|
+
maxLogsHit
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
async #filterContractClassLogsBetweenBlocks(filter) {
|
|
383
|
+
const start = filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
384
|
+
const end = filter.toBlock;
|
|
385
|
+
if (typeof end === 'number' && end < start) {
|
|
386
|
+
return {
|
|
387
|
+
logs: [],
|
|
388
|
+
maxLogsHit: true
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
const logs = [];
|
|
392
|
+
let maxLogsHit = false;
|
|
393
|
+
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#contractClassLogsByBlock.entriesAsync({
|
|
394
|
+
start,
|
|
395
|
+
end
|
|
396
|
+
})){
|
|
397
|
+
const contractClassLogsInBlock = [];
|
|
398
|
+
const reader = new BufferReader(logBuffer);
|
|
399
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
400
|
+
while(reader.remainingBytes() > 0){
|
|
401
|
+
const indexOfTx = reader.readNumber();
|
|
402
|
+
const txHash = reader.readObject(TxHash);
|
|
403
|
+
const numLogsInTx = reader.readNumber();
|
|
404
|
+
contractClassLogsInBlock[indexOfTx] = {
|
|
405
|
+
txHash,
|
|
406
|
+
logs: []
|
|
407
|
+
};
|
|
408
|
+
for(let i = 0; i < numLogsInTx; i++){
|
|
409
|
+
contractClassLogsInBlock[indexOfTx].logs.push(reader.readObject(ContractClassLog));
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
for(let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++){
|
|
413
|
+
const txData = contractClassLogsInBlock[txIndex];
|
|
414
|
+
maxLogsHit = this.#accumulateContractClassLogs(logs, blockNumber, blockHash, txIndex, txData.txHash, txData.logs, filter);
|
|
415
|
+
if (maxLogsHit) {
|
|
416
|
+
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
417
|
+
break loopOverBlocks;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
logs,
|
|
423
|
+
maxLogsHit
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
#accumulatePublicLogs(results, blockNumber, blockHash, txIndex, txHash, txLogs, filter = {}) {
|
|
427
|
+
let maxLogsHit = false;
|
|
428
|
+
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
429
|
+
for(; logIndex < txLogs.length; logIndex++){
|
|
430
|
+
const log = txLogs[logIndex];
|
|
431
|
+
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
432
|
+
results.push(new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txHash, txIndex, logIndex), log));
|
|
433
|
+
if (results.length >= this.#logsMaxPageSize) {
|
|
434
|
+
maxLogsHit = true;
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return maxLogsHit;
|
|
440
|
+
}
|
|
441
|
+
#accumulateContractClassLogs(results, blockNumber, blockHash, txIndex, txHash, txLogs, filter = {}) {
|
|
442
|
+
let maxLogsHit = false;
|
|
443
|
+
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
444
|
+
for(; logIndex < txLogs.length; logIndex++){
|
|
445
|
+
const log = txLogs[logIndex];
|
|
446
|
+
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
447
|
+
results.push(new ExtendedContractClassLog(new LogId(BlockNumber(blockNumber), blockHash, txHash, txIndex, logIndex), log));
|
|
448
|
+
if (results.length >= this.#logsMaxPageSize) {
|
|
449
|
+
maxLogsHit = true;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return maxLogsHit;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { L1BlockId } from '@aztec/ethereum/l1-types';
|
|
2
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { type AztecAsyncKVStore, type CustomRange } from '@aztec/kv-store';
|
|
5
|
+
import { type InboxMessage } from '../structs/inbox_message.js';
|
|
6
|
+
export declare class MessageStoreError extends Error {
|
|
7
|
+
readonly inboxMessage: InboxMessage;
|
|
8
|
+
constructor(message: string, inboxMessage: InboxMessage);
|
|
9
|
+
}
|
|
10
|
+
export declare class MessageStore {
|
|
11
|
+
#private;
|
|
12
|
+
private db;
|
|
13
|
+
constructor(db: AztecAsyncKVStore);
|
|
14
|
+
getTotalL1ToL2MessageCount(): Promise<bigint>;
|
|
15
|
+
/** Gets the last L1 block synced. */
|
|
16
|
+
getSynchedL1Block(): Promise<L1BlockId | undefined>;
|
|
17
|
+
/** Sets the last L1 block synced */
|
|
18
|
+
setSynchedL1Block(l1Block: L1BlockId): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Append L1 to L2 messages to the store.
|
|
21
|
+
* Requires new messages to be in order and strictly after the last message added.
|
|
22
|
+
* Throws if out of order messages are added or if the rolling hash is invalid.
|
|
23
|
+
*/
|
|
24
|
+
addL1ToL2Messages(messages: InboxMessage[]): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
27
|
+
* @param l1ToL2Message - The L1 to L2 message.
|
|
28
|
+
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
29
|
+
*/
|
|
30
|
+
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined>;
|
|
31
|
+
getLastMessage(): Promise<InboxMessage | undefined>;
|
|
32
|
+
getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]>;
|
|
33
|
+
iterateL1ToL2Messages(range?: CustomRange<bigint>): AsyncIterableIterator<InboxMessage>;
|
|
34
|
+
removeL1ToL2Messages(startIndex: bigint): Promise<void>;
|
|
35
|
+
rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber: CheckpointNumber): Promise<void>;
|
|
36
|
+
private indexToKey;
|
|
37
|
+
private leafToIndexKey;
|
|
38
|
+
private increaseTotalMessageCount;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzc2FnZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3JlL21lc3NhZ2Vfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDMUQsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFbkUsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBSXBELE9BQU8sRUFDTCxLQUFLLGlCQUFpQixFQUd0QixLQUFLLFdBQVcsRUFFakIsTUFBTSxpQkFBaUIsQ0FBQztBQUd6QixPQUFPLEVBQ0wsS0FBSyxZQUFZLEVBSWxCLE1BQU0sNkJBQTZCLENBQUM7QUFFckMscUJBQWEsaUJBQWtCLFNBQVEsS0FBSzthQUd4QixZQUFZLEVBQUUsWUFBWTtJQUY1QyxZQUNFLE9BQU8sRUFBRSxNQUFNLEVBQ0MsWUFBWSxFQUFFLFlBQVksRUFJM0M7Q0FDRjtBQUVELHFCQUFhLFlBQVk7O0lBWVgsT0FBTyxDQUFDLEVBQUU7SUFBdEIsWUFBb0IsRUFBRSxFQUFFLGlCQUFpQixFQUt4QztJQUVZLDBCQUEwQixJQUFJLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FFekQ7SUFFRCxxQ0FBcUM7SUFDeEIsaUJBQWlCLElBQUksT0FBTyxDQUFDLFNBQVMsR0FBRyxTQUFTLENBQUMsQ0FRL0Q7SUFFRCxvQ0FBb0M7SUFDdkIsaUJBQWlCLENBQUM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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
@@ -77,18 +78,18 @@ export class MessageStore {
|
|
|
77
78
|
if (!expectedRollingHash.equals(message.rollingHash)) {
|
|
78
79
|
throw new MessageStoreError(`Invalid rolling hash for incoming L1 to L2 message ${message.leaf.toString()} ` + `with index ${message.index} ` + `(expected ${expectedRollingHash.toString()} from previous hash ${previousRollingHash} but got ${message.rollingHash.toString()})`, message);
|
|
79
80
|
}
|
|
80
|
-
// Check index corresponds to the
|
|
81
|
-
const [expectedStart, expectedEnd] = InboxLeaf.
|
|
81
|
+
// Check index corresponds to the checkpoint number.
|
|
82
|
+
const [expectedStart, expectedEnd] = InboxLeaf.indexRangeForCheckpoint(message.checkpointNumber);
|
|
82
83
|
if (message.index < expectedStart || message.index >= expectedEnd) {
|
|
83
|
-
throw new MessageStoreError(`Invalid index ${message.index} for incoming L1 to L2 message ${message.leaf.toString()} ` + `at
|
|
84
|
+
throw new MessageStoreError(`Invalid index ${message.index} for incoming L1 to L2 message ${message.leaf.toString()} ` + `at checkpoint ${message.checkpointNumber} (expected value in range [${expectedStart}, ${expectedEnd}))`, message);
|
|
84
85
|
}
|
|
85
|
-
// Check there are no gaps in the indices within the same
|
|
86
|
-
if (lastMessage && message.
|
|
86
|
+
// Check there are no gaps in the indices within the same checkpoint.
|
|
87
|
+
if (lastMessage && message.checkpointNumber === lastMessage.checkpointNumber && message.index !== lastMessage.index + 1n) {
|
|
87
88
|
throw new MessageStoreError(`Missing prior message for incoming L1 to L2 message ${message.leaf.toString()} ` + `with index ${message.index}`, message);
|
|
88
89
|
}
|
|
89
90
|
// Check the first message in a block has the correct index.
|
|
90
|
-
if ((!lastMessage || message.
|
|
91
|
-
throw new MessageStoreError(`Message ${message.leaf.toString()} for
|
|
91
|
+
if ((!lastMessage || message.checkpointNumber > lastMessage.checkpointNumber) && message.index !== expectedStart) {
|
|
92
|
+
throw new MessageStoreError(`Message ${message.leaf.toString()} for checkpoint ${message.checkpointNumber} has wrong index ` + `${message.index} (expected ${expectedStart})`, message);
|
|
92
93
|
}
|
|
93
94
|
// Perform the insertions.
|
|
94
95
|
await this.#l1ToL2Messages.set(this.indexToKey(message.index), serializeInboxMessage(message));
|
|
@@ -123,17 +124,17 @@ export class MessageStore {
|
|
|
123
124
|
}));
|
|
124
125
|
return msg ? deserializeInboxMessage(msg) : undefined;
|
|
125
126
|
}
|
|
126
|
-
async getL1ToL2Messages(
|
|
127
|
+
async getL1ToL2Messages(checkpointNumber) {
|
|
127
128
|
const messages = [];
|
|
128
|
-
const [startIndex, endIndex] = InboxLeaf.
|
|
129
|
+
const [startIndex, endIndex] = InboxLeaf.indexRangeForCheckpoint(checkpointNumber);
|
|
129
130
|
let lastIndex = startIndex - 1n;
|
|
130
131
|
for await (const msgBuffer of this.#l1ToL2Messages.valuesAsync({
|
|
131
132
|
start: this.indexToKey(startIndex),
|
|
132
133
|
end: this.indexToKey(endIndex)
|
|
133
134
|
})){
|
|
134
135
|
const msg = deserializeInboxMessage(msgBuffer);
|
|
135
|
-
if (msg.
|
|
136
|
-
throw new Error(`L1 to L2 message with index ${msg.index} has invalid
|
|
136
|
+
if (msg.checkpointNumber !== checkpointNumber) {
|
|
137
|
+
throw new Error(`L1 to L2 message with index ${msg.index} has invalid checkpoint number ${msg.checkpointNumber}`);
|
|
137
138
|
} else if (msg.index !== lastIndex + 1n) {
|
|
138
139
|
throw new Error(`Expected L1 to L2 message with index ${lastIndex + 1n} but got ${msg.index}`);
|
|
139
140
|
}
|
|
@@ -164,9 +165,9 @@ export class MessageStore {
|
|
|
164
165
|
this.#log.warn(`Deleted ${deleteCount} L1 to L2 messages from index ${startIndex} from the store`);
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
|
-
|
|
168
|
-
this.#log.debug(`Deleting L1 to L2 messages up to target
|
|
169
|
-
const startIndex = InboxLeaf.
|
|
168
|
+
rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber) {
|
|
169
|
+
this.#log.debug(`Deleting L1 to L2 messages up to target checkpoint ${targetCheckpointNumber}`);
|
|
170
|
+
const startIndex = InboxLeaf.smallestIndexForCheckpoint(CheckpointNumber(targetCheckpointNumber + 1));
|
|
170
171
|
return this.removeL1ToL2Messages(startIndex);
|
|
171
172
|
}
|
|
172
173
|
indexToKey(index) {
|
|
@@ -24,4 +24,4 @@ export type SingletonDataRetrieval<T> = {
|
|
|
24
24
|
*/
|
|
25
25
|
retrievedData: T;
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV9yZXRyaWV2YWwuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdHJ1Y3RzL2RhdGFfcmV0cmlldmFsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxNQUFNLGFBQWEsQ0FBQyxDQUFDLElBQUk7SUFDN0I7O09BRUc7SUFDSCwwQkFBMEIsRUFBRSxNQUFNLENBQUM7SUFDbkM7O09BRUc7SUFDSCxhQUFhLEVBQUUsQ0FBQyxFQUFFLENBQUM7Q0FDcEIsQ0FBQztBQUVGOztHQUVHO0FBQ0gsTUFBTSxNQUFNLHNCQUFzQixDQUFDLENBQUMsSUFBSTtJQUN0Qzs7T0FFRztJQUNILDBCQUEwQixFQUFFLE1BQU0sQ0FBQztJQUNuQzs7T0FFRztJQUNILGFBQWEsRUFBRSxDQUFDLENBQUM7Q0FDbEIsQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data_retrieval.d.ts","sourceRoot":"","sources":["../../src/structs/data_retrieval.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B;;OAEG;IACH,0BAA0B,EAAE,MAAM,CAAC;IACnC;;OAEG;IACH,aAAa,EAAE,CAAC,EAAE,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;IACtC;;OAEG;IACH,0BAA0B,EAAE,MAAM,CAAC;IACnC;;OAEG;IACH,aAAa,EAAE,CAAC,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
export type InboxMessage = {
|
|
5
|
+
index: bigint;
|
|
6
|
+
leaf: Fr;
|
|
7
|
+
checkpointNumber: CheckpointNumber;
|
|
8
|
+
l1BlockNumber: bigint;
|
|
9
|
+
l1BlockHash: Buffer32;
|
|
10
|
+
rollingHash: Buffer16;
|
|
11
|
+
};
|
|
12
|
+
export declare function updateRollingHash(currentRollingHash: Buffer16, leaf: Fr): Buffer16;
|
|
13
|
+
export declare function serializeInboxMessage(message: InboxMessage): Buffer;
|
|
14
|
+
export declare function deserializeInboxMessage(buffer: Buffer): InboxMessage;
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5ib3hfbWVzc2FnZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0cnVjdHMvaW5ib3hfbWVzc2FnZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEVBQUUsUUFBUSxFQ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vB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,QAAQ,CAGlF;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CASnE;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CASpE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { keccak256 } from '@aztec/foundation/crypto';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { BufferReader, bigintToUInt64BE, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
6
|
export function updateRollingHash(currentRollingHash, leaf) {
|
|
6
7
|
const input = Buffer.concat([
|
|
@@ -15,7 +16,7 @@ export function serializeInboxMessage(message) {
|
|
|
15
16
|
message.leaf,
|
|
16
17
|
message.l1BlockHash,
|
|
17
18
|
numToUInt32BE(Number(message.l1BlockNumber)),
|
|
18
|
-
numToUInt32BE(message.
|
|
19
|
+
numToUInt32BE(message.checkpointNumber),
|
|
19
20
|
message.rollingHash
|
|
20
21
|
]);
|
|
21
22
|
}
|
|
@@ -25,14 +26,14 @@ export function deserializeInboxMessage(buffer) {
|
|
|
25
26
|
const leaf = reader.readObject(Fr);
|
|
26
27
|
const l1BlockHash = reader.readObject(Buffer32);
|
|
27
28
|
const l1BlockNumber = BigInt(reader.readNumber());
|
|
28
|
-
const
|
|
29
|
+
const checkpointNumber = CheckpointNumber(reader.readNumber());
|
|
29
30
|
const rollingHash = reader.readObject(Buffer16);
|
|
30
31
|
return {
|
|
31
32
|
index,
|
|
32
33
|
leaf,
|
|
33
34
|
l1BlockHash,
|
|
34
35
|
l1BlockNumber,
|
|
35
|
-
|
|
36
|
+
checkpointNumber,
|
|
36
37
|
rollingHash
|
|
37
38
|
};
|
|
38
39
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGlzaGVkLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RydWN0cy9wdWJsaXNoZWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWSxFQUFFLGVBQWUsRUFBRSxtQkFBbUIsRUFBRSxNQUFNLDBCQUEwQixDQUFDIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"published.d.ts","sourceRoot":"","sources":["../../src/structs/published.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|