@aztec/archiver 0.86.0 → 0.87.0
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/dest/archiver/archiver.d.ts +62 -5
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +362 -91
- package/dest/archiver/archiver_store.d.ts +33 -17
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.js +364 -62
- package/dest/archiver/data_retrieval.d.ts +23 -14
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +86 -38
- package/dest/archiver/errors.d.ts +8 -0
- package/dest/archiver/errors.d.ts.map +1 -1
- package/dest/archiver/errors.js +12 -0
- package/dest/archiver/instrumentation.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +4 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +43 -6
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +3 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +17 -3
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +24 -14
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +37 -11
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +1 -1
- package/dest/archiver/kv_archiver_store/message_store.d.ts +21 -15
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/message_store.js +150 -48
- package/dest/archiver/structs/inbox_message.d.ts +14 -0
- package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
- package/dest/archiver/structs/inbox_message.js +38 -0
- package/dest/rpc/index.d.ts +1 -1
- package/dest/test/mock_l2_block_source.d.ts +2 -0
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +8 -1
- package/dest/test/mock_structs.d.ts +9 -0
- package/dest/test/mock_structs.d.ts.map +1 -0
- package/dest/test/mock_structs.js +37 -0
- package/package.json +15 -15
- package/src/archiver/archiver.ts +431 -108
- package/src/archiver/archiver_store.ts +37 -18
- package/src/archiver/archiver_store_test_suite.ts +307 -52
- package/src/archiver/data_retrieval.ts +130 -53
- package/src/archiver/errors.ts +21 -0
- package/src/archiver/instrumentation.ts +4 -1
- package/src/archiver/kv_archiver_store/block_store.ts +46 -8
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +20 -7
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +61 -17
- package/src/archiver/kv_archiver_store/log_store.ts +6 -2
- package/src/archiver/kv_archiver_store/message_store.ts +209 -53
- package/src/archiver/structs/inbox_message.ts +40 -0
- package/src/test/mock_l2_block_source.ts +9 -1
- package/src/test/mock_structs.ts +49 -0
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
import { Blob, BlobDeserializationError } from '@aztec/blob-lib';
|
|
2
2
|
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
3
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
3
4
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
4
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { numToUInt32BE } from '@aztec/foundation/serialize';
|
|
7
7
|
import { ForwarderAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
8
8
|
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
9
|
-
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
10
9
|
import { Proof } from '@aztec/stdlib/proofs';
|
|
11
10
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
12
|
-
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
11
|
+
import { BlockHeader, GlobalVariables, ProposedBlockHeader, StateReference } from '@aztec/stdlib/tx';
|
|
13
12
|
import { decodeFunctionData, getAbiItem, hexToBytes } from 'viem';
|
|
14
13
|
import { NoBlobBodiesFoundError } from './errors.js';
|
|
14
|
+
export function retrievedBlockToPublishedL2Block(retrievedBlock) {
|
|
15
|
+
const { l2BlockNumber, archiveRoot, stateReference, header: proposedHeader, body, l1, chainId, version, signatures } = retrievedBlock;
|
|
16
|
+
const archive = new AppendOnlyTreeSnapshot(archiveRoot, Number(l2BlockNumber + 1n));
|
|
17
|
+
const globalVariables = GlobalVariables.from({
|
|
18
|
+
chainId,
|
|
19
|
+
version,
|
|
20
|
+
blockNumber: new Fr(l2BlockNumber),
|
|
21
|
+
slotNumber: proposedHeader.slotNumber,
|
|
22
|
+
timestamp: new Fr(proposedHeader.timestamp),
|
|
23
|
+
coinbase: proposedHeader.coinbase,
|
|
24
|
+
feeRecipient: proposedHeader.feeRecipient,
|
|
25
|
+
gasFees: proposedHeader.gasFees
|
|
26
|
+
});
|
|
27
|
+
const header = BlockHeader.from({
|
|
28
|
+
lastArchive: new AppendOnlyTreeSnapshot(proposedHeader.lastArchiveRoot, Number(l2BlockNumber)),
|
|
29
|
+
contentCommitment: proposedHeader.contentCommitment,
|
|
30
|
+
state: stateReference,
|
|
31
|
+
globalVariables,
|
|
32
|
+
totalFees: body.txEffects.reduce((accum, txEffect)=>accum.add(txEffect.transactionFee), Fr.ZERO),
|
|
33
|
+
totalManaUsed: proposedHeader.totalManaUsed
|
|
34
|
+
});
|
|
35
|
+
const block = new L2Block(archive, header, body);
|
|
36
|
+
return {
|
|
37
|
+
block,
|
|
38
|
+
l1,
|
|
39
|
+
signatures
|
|
40
|
+
};
|
|
41
|
+
}
|
|
15
42
|
/**
|
|
16
43
|
* Fetches new L2 blocks.
|
|
17
44
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
@@ -22,6 +49,7 @@ import { NoBlobBodiesFoundError } from './errors.js';
|
|
|
22
49
|
* @returns An array of block; as well as the next eth block to search from.
|
|
23
50
|
*/ export async function retrieveBlocksFromRollup(rollup, publicClient, blobSinkClient, searchStartBlock, searchEndBlock, logger = createLogger('archiver')) {
|
|
24
51
|
const retrievedBlocks = [];
|
|
52
|
+
let rollupConstants;
|
|
25
53
|
do {
|
|
26
54
|
if (searchStartBlock > searchEndBlock) {
|
|
27
55
|
break;
|
|
@@ -35,7 +63,17 @@ import { NoBlobBodiesFoundError } from './errors.js';
|
|
|
35
63
|
}
|
|
36
64
|
const lastLog = l2BlockProposedLogs[l2BlockProposedLogs.length - 1];
|
|
37
65
|
logger.debug(`Got ${l2BlockProposedLogs.length} L2 block processed logs for L2 blocks ${l2BlockProposedLogs[0].args.blockNumber}-${lastLog.args.blockNumber} between L1 blocks ${searchStartBlock}-${searchEndBlock}`);
|
|
38
|
-
|
|
66
|
+
if (rollupConstants === undefined) {
|
|
67
|
+
const [chainId, version] = await Promise.all([
|
|
68
|
+
publicClient.getChainId(),
|
|
69
|
+
rollup.read.getVersion()
|
|
70
|
+
]);
|
|
71
|
+
rollupConstants = {
|
|
72
|
+
chainId: new Fr(chainId),
|
|
73
|
+
version: new Fr(version)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const newBlocks = await processL2BlockProposedLogs(rollup, publicClient, blobSinkClient, l2BlockProposedLogs, rollupConstants, logger);
|
|
39
77
|
retrievedBlocks.push(...newBlocks);
|
|
40
78
|
searchStartBlock = lastLog.blockNumber + 1n;
|
|
41
79
|
}while (searchStartBlock <= searchEndBlock)
|
|
@@ -48,7 +86,7 @@ import { NoBlobBodiesFoundError } from './errors.js';
|
|
|
48
86
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
49
87
|
* @param logs - L2BlockProposed logs.
|
|
50
88
|
* @returns - An array blocks.
|
|
51
|
-
*/
|
|
89
|
+
*/ async function processL2BlockProposedLogs(rollup, publicClient, blobSinkClient, logs, { chainId, version }, logger) {
|
|
52
90
|
const retrievedBlocks = [];
|
|
53
91
|
await asyncPool(10, logs, async (log)=>{
|
|
54
92
|
const l2BlockNumber = log.args.blockNumber;
|
|
@@ -67,7 +105,9 @@ import { NoBlobBodiesFoundError } from './errors.js';
|
|
|
67
105
|
};
|
|
68
106
|
retrievedBlocks.push({
|
|
69
107
|
...block,
|
|
70
|
-
l1
|
|
108
|
+
l1,
|
|
109
|
+
chainId,
|
|
110
|
+
version
|
|
71
111
|
});
|
|
72
112
|
logger.trace(`Retrieved L2 block ${l2BlockNumber} from L1 tx ${log.transactionHash}`, {
|
|
73
113
|
l1BlockNumber: log.blockNumber,
|
|
@@ -125,7 +165,7 @@ export async function getL1BlockTime(publicClient, blockNumber) {
|
|
|
125
165
|
if (rollupFunctionName === 'propose') {
|
|
126
166
|
return callData;
|
|
127
167
|
}
|
|
128
|
-
} catch
|
|
168
|
+
} catch {
|
|
129
169
|
continue;
|
|
130
170
|
}
|
|
131
171
|
}
|
|
@@ -137,9 +177,9 @@ export async function getL1BlockTime(publicClient, blockNumber) {
|
|
|
137
177
|
* TODO: Add retries and error management.
|
|
138
178
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
139
179
|
* @param txHash - Hash of the tx that published it.
|
|
140
|
-
* @param
|
|
180
|
+
* @param l2BlockNumber - L2 block number.
|
|
141
181
|
* @returns L2 block from the calldata, deserialized
|
|
142
|
-
*/ async function getBlockFromRollupTx(publicClient, blobSinkClient, txHash, blobHashes,
|
|
182
|
+
*/ async function getBlockFromRollupTx(publicClient, blobSinkClient, txHash, blobHashes, l2BlockNumber, rollupAddress, logger) {
|
|
143
183
|
const { input: forwarderData, blockHash } = await publicClient.getTransaction({
|
|
144
184
|
hash: txHash
|
|
145
185
|
});
|
|
@@ -151,11 +191,11 @@ export async function getL1BlockTime(publicClient, blockNumber) {
|
|
|
151
191
|
if (rollupFunctionName !== 'propose') {
|
|
152
192
|
throw new Error(`Unexpected rollup method called ${rollupFunctionName}`);
|
|
153
193
|
}
|
|
154
|
-
const [decodedArgs, signatures] = rollupArgs;
|
|
155
|
-
const header =
|
|
194
|
+
const [decodedArgs, signatures, _blobInput] = rollupArgs;
|
|
195
|
+
const header = ProposedBlockHeader.fromBuffer(Buffer.from(hexToBytes(decodedArgs.header)));
|
|
156
196
|
const blobBodies = await blobSinkClient.getBlobSidecar(blockHash, blobHashes);
|
|
157
197
|
if (blobBodies.length === 0) {
|
|
158
|
-
throw new NoBlobBodiesFoundError(Number(
|
|
198
|
+
throw new NoBlobBodiesFoundError(Number(l2BlockNumber));
|
|
159
199
|
}
|
|
160
200
|
let blockFields;
|
|
161
201
|
try {
|
|
@@ -169,21 +209,26 @@ export async function getL1BlockTime(publicClient, blockNumber) {
|
|
|
169
209
|
throw err;
|
|
170
210
|
}
|
|
171
211
|
// The blob source gives us blockFields, and we must construct the body from them:
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${blockNumberFromHeader}`);
|
|
176
|
-
}
|
|
177
|
-
const archive = AppendOnlyTreeSnapshot.fromBuffer(Buffer.concat([
|
|
178
|
-
Buffer.from(hexToBytes(decodedArgs.archive)),
|
|
179
|
-
numToUInt32BE(Number(l2BlockNum + 1n))
|
|
180
|
-
]));
|
|
181
|
-
const block = new L2Block(archive, header, blockBody);
|
|
212
|
+
const body = Body.fromBlobFields(blockFields);
|
|
213
|
+
const archiveRoot = new Fr(Buffer.from(hexToBytes(decodedArgs.archive)));
|
|
214
|
+
const stateReference = StateReference.fromBuffer(Buffer.from(hexToBytes(decodedArgs.stateReference)));
|
|
182
215
|
return {
|
|
183
|
-
|
|
216
|
+
l2BlockNumber,
|
|
217
|
+
archiveRoot,
|
|
218
|
+
stateReference,
|
|
219
|
+
header,
|
|
220
|
+
body,
|
|
184
221
|
signatures: signatures.map(Signature.fromViemSignature)
|
|
185
222
|
};
|
|
186
223
|
}
|
|
224
|
+
/** Given an L1 to L2 message, retrieves its corresponding event from the Inbox. */ export async function retrieveL1ToL2Message(inbox, leaf, fromBlock) {
|
|
225
|
+
const logs = await inbox.getEvents.MessageSent({
|
|
226
|
+
hash: leaf.toString()
|
|
227
|
+
}, {
|
|
228
|
+
fromBlock
|
|
229
|
+
});
|
|
230
|
+
return mapLogsInboxMessage(logs)[0];
|
|
231
|
+
}
|
|
187
232
|
/**
|
|
188
233
|
* Fetch L1 to L2 messages.
|
|
189
234
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
@@ -194,10 +239,7 @@ export async function getL1BlockTime(publicClient, blockNumber) {
|
|
|
194
239
|
* @returns An array of InboxLeaf and next eth block to search from.
|
|
195
240
|
*/ export async function retrieveL1ToL2Messages(inbox, searchStartBlock, searchEndBlock) {
|
|
196
241
|
const retrievedL1ToL2Messages = [];
|
|
197
|
-
|
|
198
|
-
if (searchStartBlock > searchEndBlock) {
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
242
|
+
while(searchStartBlock <= searchEndBlock){
|
|
201
243
|
const messageSentLogs = (await inbox.getEvents.MessageSent({}, {
|
|
202
244
|
fromBlock: searchStartBlock,
|
|
203
245
|
toBlock: searchEndBlock
|
|
@@ -205,17 +247,23 @@ export async function getL1BlockTime(publicClient, blockNumber) {
|
|
|
205
247
|
if (messageSentLogs.length === 0) {
|
|
206
248
|
break;
|
|
207
249
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
250
|
+
retrievedL1ToL2Messages.push(...mapLogsInboxMessage(messageSentLogs));
|
|
251
|
+
searchStartBlock = messageSentLogs.at(-1).blockNumber + 1n;
|
|
252
|
+
}
|
|
253
|
+
return retrievedL1ToL2Messages;
|
|
254
|
+
}
|
|
255
|
+
function mapLogsInboxMessage(logs) {
|
|
256
|
+
return logs.map((log)=>{
|
|
257
|
+
const { index, hash, l2BlockNumber, rollingHash } = log.args;
|
|
258
|
+
return {
|
|
259
|
+
index: index,
|
|
260
|
+
leaf: Fr.fromHexString(hash),
|
|
261
|
+
l1BlockNumber: log.blockNumber,
|
|
262
|
+
l1BlockHash: Buffer32.fromString(log.blockHash),
|
|
263
|
+
l2BlockNumber: l2BlockNumber,
|
|
264
|
+
rollingHash: Buffer16.fromString(rollingHash)
|
|
265
|
+
};
|
|
266
|
+
});
|
|
219
267
|
}
|
|
220
268
|
/** Retrieves L2ProofVerified events from the rollup contract. */ export async function retrieveL2ProofVerifiedEvents(publicClient, rollupAddress, searchStartBlock, searchEndBlock) {
|
|
221
269
|
const logs = await publicClient.getLogs({
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export declare class NoBlobBodiesFoundError extends Error {
|
|
2
2
|
constructor(l2BlockNum: number);
|
|
3
3
|
}
|
|
4
|
+
export declare class InitialBlockNumberNotSequentialError extends Error {
|
|
5
|
+
readonly newBlockNumber: number;
|
|
6
|
+
readonly previousBlockNumber: number | undefined;
|
|
7
|
+
constructor(newBlockNumber: number, previousBlockNumber: number | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare class BlockNumberNotSequentialError extends Error {
|
|
10
|
+
constructor(newBlockNumber: number, previous: number | undefined);
|
|
11
|
+
}
|
|
4
12
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/archiver/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,UAAU,EAAE,MAAM;CAG/B"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/archiver/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,UAAU,EAAE,MAAM;CAG/B;AAED,qBAAa,oCAAqC,SAAQ,KAAK;aAE3C,cAAc,EAAE,MAAM;aACtB,mBAAmB,EAAE,MAAM,GAAG,SAAS;gBADvC,cAAc,EAAE,MAAM,EACtB,mBAAmB,EAAE,MAAM,GAAG,SAAS;CAQ1D;AAED,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS;CAKjE"}
|
package/dest/archiver/errors.js
CHANGED
|
@@ -3,3 +3,15 @@ export class NoBlobBodiesFoundError extends Error {
|
|
|
3
3
|
super(`No blob bodies found for block ${l2BlockNum}`);
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
+
export class InitialBlockNumberNotSequentialError extends Error {
|
|
7
|
+
newBlockNumber;
|
|
8
|
+
previousBlockNumber;
|
|
9
|
+
constructor(newBlockNumber, previousBlockNumber){
|
|
10
|
+
super(`Cannot insert new block ${newBlockNumber} given previous block number in store is ${previousBlockNumber ?? 'undefined'}`), this.newBlockNumber = newBlockNumber, this.previousBlockNumber = previousBlockNumber;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class BlockNumberNotSequentialError extends Error {
|
|
14
|
+
constructor(newBlockNumber, previous){
|
|
15
|
+
super(`Cannot insert new block ${newBlockNumber} given previous block number in batch is ${previous ?? 'undefined'}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/archiver/instrumentation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAKL,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,uBAAuB;
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/archiver/instrumentation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAKL,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,uBAAuB;IAgBhC,OAAO,CAAC,SAAS;IAfnB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,YAAY,CAAY;IAChC,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,oBAAoB,CAAgB;IAC5C,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,GAAG,CAA4C;IAEvD,OAAO;WAyDa,GAAG,CAAC,SAAS,EAAE,eAAe,EAAE,SAAS,CAAC,EAAE,iBAAiB;IAU1E,SAAS,IAAI,OAAO;IAIpB,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;IAS5D,YAAY;IAIZ,qBAAqB,CAAC,WAAW,EAAE,MAAM;IAIzC,qBAAqB,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE;IAaxF,mBAAmB,CAAC,WAAW,EAAE,MAAM;CAG/C"}
|
|
@@ -15,7 +15,9 @@ export declare class BlockStore {
|
|
|
15
15
|
* @param blocks - The L2 blocks to be added to the store.
|
|
16
16
|
* @returns True if the operation is successful.
|
|
17
17
|
*/
|
|
18
|
-
addBlocks(blocks: PublishedL2Block[]
|
|
18
|
+
addBlocks(blocks: PublishedL2Block[], opts?: {
|
|
19
|
+
force?: boolean;
|
|
20
|
+
}): Promise<boolean>;
|
|
19
21
|
/**
|
|
20
22
|
* Unwinds blocks from the database
|
|
21
23
|
* @param from - The tip of the chain, passed for verification purposes,
|
|
@@ -44,6 +46,7 @@ export declare class BlockStore {
|
|
|
44
46
|
* @returns The requested L2 block headers
|
|
45
47
|
*/
|
|
46
48
|
getBlockHeaders(start: number, limit: number): AsyncIterableIterator<BlockHeader>;
|
|
49
|
+
private getBlockStorages;
|
|
47
50
|
private getBlockFromBlockStorage;
|
|
48
51
|
/**
|
|
49
52
|
* Gets a tx effect.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/block_store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAA6C,MAAM,iBAAiB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"block_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/block_store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAA6C,MAAM,iBAAiB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGxF,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,kBAAkB,CA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AuB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAItD,uBAAuB,CAAC,aAAa,EAAE,MAAM;IAIvC,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ/C,sBAAsB,CAAC,WAAW,EAAE,MAAM;CAe3C"}
|
|
@@ -5,6 +5,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
5
5
|
import { Body, L2Block, L2BlockHash } from '@aztec/stdlib/block';
|
|
6
6
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
7
7
|
import { BlockHeader, TxReceipt } from '@aztec/stdlib/tx';
|
|
8
|
+
import { BlockNumberNotSequentialError, InitialBlockNumberNotSequentialError } from '../errors.js';
|
|
8
9
|
export { TxReceipt } from '@aztec/stdlib/tx';
|
|
9
10
|
/**
|
|
10
11
|
* LMDB implementation of the ArchiverDataStore interface.
|
|
@@ -14,7 +15,6 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
14
15
|
/** Map block hash to block body */ #blockBodies;
|
|
15
16
|
/** Stores L1 block number in which the last processed L2 block was included */ #lastSynchedL1Block;
|
|
16
17
|
/** Stores l2 block number of the last proven block */ #lastProvenL2Block;
|
|
17
|
-
/** Stores l2 epoch number of the last proven epoch */ #lastProvenL2Epoch;
|
|
18
18
|
/** Index mapping transaction hash (as a string) to its location in a block */ #txIndex;
|
|
19
19
|
/** Index mapping a contract's address (as a string) to its location in a block */ #contractIndex;
|
|
20
20
|
#log;
|
|
@@ -27,18 +27,34 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
27
27
|
this.#contractIndex = db.openMap('archiver_contract_index');
|
|
28
28
|
this.#lastSynchedL1Block = db.openSingleton('archiver_last_synched_l1_block');
|
|
29
29
|
this.#lastProvenL2Block = db.openSingleton('archiver_last_proven_l2_block');
|
|
30
|
-
this.#lastProvenL2Epoch = db.openSingleton('archiver_last_proven_l2_epoch');
|
|
31
30
|
}
|
|
32
31
|
/**
|
|
33
32
|
* Append new blocks to the store's list.
|
|
34
33
|
* @param blocks - The L2 blocks to be added to the store.
|
|
35
34
|
* @returns True if the operation is successful.
|
|
36
|
-
*/ async addBlocks(blocks) {
|
|
35
|
+
*/ async addBlocks(blocks, opts = {}) {
|
|
37
36
|
if (blocks.length === 0) {
|
|
38
37
|
return true;
|
|
39
38
|
}
|
|
40
39
|
return await this.db.transactionAsync(async ()=>{
|
|
40
|
+
// Check that the block immediately before the first block to be added is present in the store.
|
|
41
|
+
const firstBlockNumber = blocks[0].block.number;
|
|
42
|
+
const [previousBlockNumber] = await toArray(this.#blocks.keysAsync({
|
|
43
|
+
reverse: true,
|
|
44
|
+
limit: 1,
|
|
45
|
+
end: firstBlockNumber - 1
|
|
46
|
+
}));
|
|
47
|
+
const hasPreviousBlock = firstBlockNumber === INITIAL_L2_BLOCK_NUM || previousBlockNumber !== undefined && previousBlockNumber === firstBlockNumber - 1;
|
|
48
|
+
if (!opts.force && !hasPreviousBlock) {
|
|
49
|
+
throw new InitialBlockNumberNotSequentialError(firstBlockNumber, previousBlockNumber);
|
|
50
|
+
}
|
|
51
|
+
// Iterate over blocks array and insert them, checking that the block numbers are sequential.
|
|
52
|
+
let previousBlock = undefined;
|
|
41
53
|
for (const block of blocks){
|
|
54
|
+
if (!opts.force && previousBlock && previousBlock.block.number + 1 !== block.block.number) {
|
|
55
|
+
throw new BlockNumberNotSequentialError(block.block.number, previousBlock.block.number);
|
|
56
|
+
}
|
|
57
|
+
previousBlock = block;
|
|
42
58
|
await this.#blocks.set(block.block.number, {
|
|
43
59
|
header: block.block.header.toBuffer(),
|
|
44
60
|
archive: block.block.archive.toBuffer(),
|
|
@@ -70,6 +86,10 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
70
86
|
if (from !== last) {
|
|
71
87
|
throw new Error(`Can only unwind blocks from the tip (requested ${from} but current tip is ${last})`);
|
|
72
88
|
}
|
|
89
|
+
const proven = await this.getProvenL2BlockNumber();
|
|
90
|
+
if (from - blocksToUnwind < proven) {
|
|
91
|
+
await this.setProvenL2BlockNumber(from - blocksToUnwind);
|
|
92
|
+
}
|
|
73
93
|
for(let i = 0; i < blocksToUnwind; i++){
|
|
74
94
|
const blockNumber = from - i;
|
|
75
95
|
const block = await this.getBlock(blockNumber);
|
|
@@ -92,7 +112,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
92
112
|
* @param limit - The number of blocks to return.
|
|
93
113
|
* @returns The requested L2 blocks
|
|
94
114
|
*/ async *getBlocks(start, limit) {
|
|
95
|
-
for await (const [blockNumber, blockStorage] of this
|
|
115
|
+
for await (const [blockNumber, blockStorage] of this.getBlockStorages(start, limit)){
|
|
96
116
|
const block = await this.getBlockFromBlockStorage(blockNumber, blockStorage);
|
|
97
117
|
if (block) {
|
|
98
118
|
yield block;
|
|
@@ -116,7 +136,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
116
136
|
* @param limit - The number of blocks to return.
|
|
117
137
|
* @returns The requested L2 block headers
|
|
118
138
|
*/ async *getBlockHeaders(start, limit) {
|
|
119
|
-
for await (const [blockNumber, blockStorage] of this
|
|
139
|
+
for await (const [blockNumber, blockStorage] of this.getBlockStorages(start, limit)){
|
|
120
140
|
const header = BlockHeader.fromBuffer(blockStorage.header);
|
|
121
141
|
if (header.getBlockNumber() !== blockNumber) {
|
|
122
142
|
throw new Error(`Block number mismatch when retrieving block header from archive (expected ${blockNumber} but got ${header.getBlockNumber()})`);
|
|
@@ -124,6 +144,19 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
124
144
|
yield header;
|
|
125
145
|
}
|
|
126
146
|
}
|
|
147
|
+
async *getBlockStorages(start, limit) {
|
|
148
|
+
let expectedBlockNumber = start;
|
|
149
|
+
for await (const [blockNumber, blockStorage] of this.#blocks.entriesAsync(this.#computeBlockRange(start, limit))){
|
|
150
|
+
if (blockNumber !== expectedBlockNumber) {
|
|
151
|
+
throw new Error(`Block number mismatch when iterating blocks from archive (expected ${expectedBlockNumber} but got ${blockNumber})`);
|
|
152
|
+
}
|
|
153
|
+
expectedBlockNumber++;
|
|
154
|
+
yield [
|
|
155
|
+
blockNumber,
|
|
156
|
+
blockStorage
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
127
160
|
async getBlockFromBlockStorage(blockNumber, blockStorage) {
|
|
128
161
|
const header = BlockHeader.fromBuffer(blockStorage.header);
|
|
129
162
|
const archive = AppendOnlyTreeSnapshot.fromBuffer(blockStorage.archive);
|
|
@@ -215,7 +248,11 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
215
248
|
return this.#lastSynchedL1Block.set(l1BlockNumber);
|
|
216
249
|
}
|
|
217
250
|
async getProvenL2BlockNumber() {
|
|
218
|
-
|
|
251
|
+
const [latestBlockNumber, provenBlockNumber] = await Promise.all([
|
|
252
|
+
this.getSynchedL2BlockNumber(),
|
|
253
|
+
this.#lastProvenL2Block.getAsync()
|
|
254
|
+
]);
|
|
255
|
+
return (provenBlockNumber ?? 0) > latestBlockNumber ? latestBlockNumber : provenBlockNumber ?? 0;
|
|
219
256
|
}
|
|
220
257
|
setProvenL2BlockNumber(blockNumber) {
|
|
221
258
|
return this.#lastProvenL2Block.set(blockNumber);
|
|
@@ -8,14 +8,16 @@ type ContractInstanceUpdateKey = [string, number] | [string, number, number];
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class ContractInstanceStore {
|
|
10
10
|
#private;
|
|
11
|
+
private db;
|
|
11
12
|
constructor(db: AztecAsyncKVStore);
|
|
12
|
-
addContractInstance(contractInstance: ContractInstanceWithAddress): Promise<void>;
|
|
13
|
+
addContractInstance(contractInstance: ContractInstanceWithAddress, blockNumber: number): Promise<void>;
|
|
13
14
|
deleteContractInstance(contractInstance: ContractInstanceWithAddress): Promise<void>;
|
|
14
15
|
getUpdateKey(contractAddress: AztecAddress, blockNumber: number, logIndex?: number): ContractInstanceUpdateKey;
|
|
15
16
|
addContractInstanceUpdate(contractInstanceUpdate: ContractInstanceUpdateWithAddress, blockNumber: number, logIndex: number): Promise<void>;
|
|
16
17
|
deleteContractInstanceUpdate(contractInstanceUpdate: ContractInstanceUpdateWithAddress, blockNumber: number, logIndex: number): Promise<void>;
|
|
17
18
|
getCurrentContractInstanceClassId(address: AztecAddress, blockNumber: number, originalClassId: Fr): Promise<Fr>;
|
|
18
19
|
getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
|
|
20
|
+
getContractInstanceDeploymentBlockNumber(address: AztecAddress): Promise<number | undefined>;
|
|
19
21
|
}
|
|
20
22
|
export {};
|
|
21
23
|
//# sourceMappingURL=contract_instance_store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_instance_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/contract_instance_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAGjC,MAAM,wBAAwB,CAAC;AAEhC,KAAK,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7E;;GAEG;AACH,qBAAa,qBAAqB;;
|
|
1
|
+
{"version":3,"file":"contract_instance_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/contract_instance_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAGjC,MAAM,wBAAwB,CAAC;AAEhC,KAAK,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7E;;GAEG;AACH,qBAAa,qBAAqB;;IAKpB,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,iBAAiB;IAMzC,mBAAmB,CAAC,gBAAgB,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtG,sBAAsB,CAAC,gBAAgB,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpF,YAAY,CAAC,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,yBAAyB;IAQ9G,yBAAyB,CACvB,sBAAsB,EAAE,iCAAiC,EACzD,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAOhB,4BAA4B,CAC1B,sBAAsB,EAAE,iCAAiC,EACzD,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAMV,iCAAiC,CACrC,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,EAAE,GAClB,OAAO,CAAC,EAAE,CAAC;IAsBR,mBAAmB,CACvB,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAenD,wCAAwC,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAG7F"}
|
|
@@ -2,17 +2,27 @@ import { SerializableContractInstance, SerializableContractInstanceUpdate } from
|
|
|
2
2
|
/**
|
|
3
3
|
* LMDB implementation of the ArchiverDataStore interface.
|
|
4
4
|
*/ export class ContractInstanceStore {
|
|
5
|
+
db;
|
|
5
6
|
#contractInstances;
|
|
7
|
+
#contractInstanceDeployedAt;
|
|
6
8
|
#contractInstanceUpdates;
|
|
7
9
|
constructor(db){
|
|
10
|
+
this.db = db;
|
|
8
11
|
this.#contractInstances = db.openMap('archiver_contract_instances');
|
|
12
|
+
this.#contractInstanceDeployedAt = db.openMap('archiver_contract_instances_deployment_block_number');
|
|
9
13
|
this.#contractInstanceUpdates = db.openMap('archiver_contract_instance_updates');
|
|
10
14
|
}
|
|
11
|
-
addContractInstance(contractInstance) {
|
|
12
|
-
return this
|
|
15
|
+
addContractInstance(contractInstance, blockNumber) {
|
|
16
|
+
return this.db.transactionAsync(async ()=>{
|
|
17
|
+
await this.#contractInstances.set(contractInstance.address.toString(), new SerializableContractInstance(contractInstance).toBuffer());
|
|
18
|
+
await this.#contractInstanceDeployedAt.set(contractInstance.address.toString(), blockNumber);
|
|
19
|
+
});
|
|
13
20
|
}
|
|
14
21
|
deleteContractInstance(contractInstance) {
|
|
15
|
-
return this
|
|
22
|
+
return this.db.transactionAsync(async ()=>{
|
|
23
|
+
await this.#contractInstances.delete(contractInstance.address.toString());
|
|
24
|
+
await this.#contractInstanceDeployedAt.delete(contractInstance.address.toString());
|
|
25
|
+
});
|
|
16
26
|
}
|
|
17
27
|
getUpdateKey(contractAddress, blockNumber, logIndex) {
|
|
18
28
|
if (logIndex === undefined) {
|
|
@@ -38,6 +48,7 @@ import { SerializableContractInstance, SerializableContractInstanceUpdate } from
|
|
|
38
48
|
// We need to find the last update before the given block number
|
|
39
49
|
const queryResult = await this.#contractInstanceUpdates.valuesAsync({
|
|
40
50
|
reverse: true,
|
|
51
|
+
start: this.getUpdateKey(address, 0),
|
|
41
52
|
end: this.getUpdateKey(address, blockNumber + 1),
|
|
42
53
|
limit: 1
|
|
43
54
|
}).next();
|
|
@@ -60,4 +71,7 @@ import { SerializableContractInstance, SerializableContractInstanceUpdate } from
|
|
|
60
71
|
instance.currentContractClassId = await this.getCurrentContractInstanceClassId(address, blockNumber, instance.originalContractClassId);
|
|
61
72
|
return instance;
|
|
62
73
|
}
|
|
74
|
+
getContractInstanceDeploymentBlockNumber(address) {
|
|
75
|
+
return this.#contractInstanceDeployedAt.getAsync(address.toString());
|
|
76
|
+
}
|
|
63
77
|
}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
+
import type { L1BlockId } from '@aztec/ethereum';
|
|
1
2
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type { AztecAsyncKVStore, StoreSize } from '@aztec/kv-store';
|
|
3
|
+
import type { AztecAsyncKVStore, CustomRange, StoreSize } from '@aztec/kv-store';
|
|
3
4
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
6
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
6
|
-
import type { ContractClassPublic, ContractInstanceUpdateWithAddress, ContractInstanceWithAddress, ExecutablePrivateFunctionWithMembershipProof, UtilityFunctionWithMembershipProof } from '@aztec/stdlib/contract';
|
|
7
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceUpdateWithAddress, ContractInstanceWithAddress, ExecutablePrivateFunctionWithMembershipProof, UtilityFunctionWithMembershipProof } from '@aztec/stdlib/contract';
|
|
7
8
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
8
9
|
import { type LogFilter, PrivateLog, type TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
9
|
-
import type { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
10
10
|
import type { BlockHeader, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
11
11
|
import type { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
|
|
12
|
-
import type {
|
|
12
|
+
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
13
13
|
import type { PublishedL2Block } from '../structs/published.js';
|
|
14
|
-
export declare const ARCHIVER_DB_VERSION =
|
|
14
|
+
export declare const ARCHIVER_DB_VERSION = 2;
|
|
15
15
|
/**
|
|
16
16
|
* LMDB implementation of the ArchiverDataStore interface.
|
|
17
17
|
*/
|
|
18
|
-
export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
18
|
+
export declare class KVArchiverDataStore implements ArchiverDataStore, ContractDataSource {
|
|
19
19
|
#private;
|
|
20
20
|
private db;
|
|
21
|
-
static readonly SCHEMA_VERSION =
|
|
21
|
+
static readonly SCHEMA_VERSION = 2;
|
|
22
22
|
private functionNames;
|
|
23
23
|
constructor(db: AztecAsyncKVStore, logsMaxPageSize?: number);
|
|
24
|
+
transactionAsync<T>(callback: () => Promise<T>): Promise<T>;
|
|
25
|
+
getBlockNumber(): Promise<number>;
|
|
26
|
+
getContract(address: AztecAddress, blockNumber?: number): Promise<ContractInstanceWithAddress | undefined>;
|
|
24
27
|
backupTo(path: string, compress?: boolean): Promise<string>;
|
|
25
28
|
close(): Promise<void>;
|
|
26
29
|
getDebugFunctionName(_address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
@@ -28,11 +31,12 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
28
31
|
getContractClass(id: Fr): Promise<ContractClassPublic | undefined>;
|
|
29
32
|
getContractClassIds(): Promise<Fr[]>;
|
|
30
33
|
getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
|
|
34
|
+
getContractInstanceDeploymentBlockNumber(address: AztecAddress): Promise<number | undefined>;
|
|
31
35
|
addContractClasses(data: ContractClassPublic[], bytecodeCommitments: Fr[], blockNumber: number): Promise<boolean>;
|
|
32
36
|
deleteContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean>;
|
|
33
37
|
getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
|
|
34
38
|
addFunctions(contractClassId: Fr, privateFunctions: ExecutablePrivateFunctionWithMembershipProof[], utilityFunctions: UtilityFunctionWithMembershipProof[]): Promise<boolean>;
|
|
35
|
-
addContractInstances(data: ContractInstanceWithAddress[],
|
|
39
|
+
addContractInstances(data: ContractInstanceWithAddress[], blockNumber: number): Promise<boolean>;
|
|
36
40
|
deleteContractInstances(data: ContractInstanceWithAddress[], _blockNumber: number): Promise<boolean>;
|
|
37
41
|
addContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], blockNumber: number): Promise<boolean>;
|
|
38
42
|
deleteContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], blockNumber: number): Promise<boolean>;
|
|
@@ -41,7 +45,9 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
41
45
|
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
42
46
|
* @returns True if the operation is successful.
|
|
43
47
|
*/
|
|
44
|
-
addBlocks(blocks: PublishedL2Block[]
|
|
48
|
+
addBlocks(blocks: PublishedL2Block[], opts?: {
|
|
49
|
+
force?: boolean;
|
|
50
|
+
}): Promise<boolean>;
|
|
45
51
|
/**
|
|
46
52
|
* Unwinds blocks from the database
|
|
47
53
|
* @param from - The tip of the chain, passed for verification purposes,
|
|
@@ -50,6 +56,7 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
50
56
|
* @returns True if the operation is successful
|
|
51
57
|
*/
|
|
52
58
|
unwindBlocks(from: number, blocksToUnwind: number): Promise<boolean>;
|
|
59
|
+
getPublishedBlock(number: number): Promise<PublishedL2Block | undefined>;
|
|
53
60
|
/**
|
|
54
61
|
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
55
62
|
*
|
|
@@ -57,7 +64,7 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
57
64
|
* @param limit - The number of blocks to return.
|
|
58
65
|
* @returns The requested L2 blocks
|
|
59
66
|
*/
|
|
60
|
-
|
|
67
|
+
getPublishedBlocks(start: number, limit: number): Promise<PublishedL2Block[]>;
|
|
61
68
|
/**
|
|
62
69
|
* Gets up to `limit` amount of L2 blocks headers starting from `from`.
|
|
63
70
|
*
|
|
@@ -86,12 +93,12 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
86
93
|
addLogs(blocks: L2Block[]): Promise<boolean>;
|
|
87
94
|
deleteLogs(blocks: L2Block[]): Promise<boolean>;
|
|
88
95
|
getTotalL1ToL2MessageCount(): Promise<bigint>;
|
|
96
|
+
getLastL1ToL2Message(): Promise<InboxMessage | undefined>;
|
|
89
97
|
/**
|
|
90
98
|
* Append L1 to L2 messages to the store.
|
|
91
|
-
* @param messages - The L1 to L2 messages to be added to the store
|
|
92
|
-
* @returns True if the operation is successful.
|
|
99
|
+
* @param messages - The L1 to L2 messages to be added to the store.
|
|
93
100
|
*/
|
|
94
|
-
addL1ToL2Messages(messages:
|
|
101
|
+
addL1ToL2Messages(messages: InboxMessage[]): Promise<void>;
|
|
95
102
|
/**
|
|
96
103
|
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
97
104
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
@@ -138,11 +145,14 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
138
145
|
getProvenL2BlockNumber(): Promise<number>;
|
|
139
146
|
setProvenL2BlockNumber(blockNumber: number): Promise<void>;
|
|
140
147
|
setBlockSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void>;
|
|
141
|
-
|
|
148
|
+
setMessageSynchedL1Block(l1Block: L1BlockId): Promise<void>;
|
|
142
149
|
/**
|
|
143
150
|
* Gets the last L1 block number processed by the archiver
|
|
144
151
|
*/
|
|
145
152
|
getSynchPoint(): Promise<ArchiverL1SynchPoint>;
|
|
146
153
|
estimateSize(): Promise<StoreSize>;
|
|
154
|
+
rollbackL1ToL2MessagesToL2Block(targetBlockNumber: number | bigint): Promise<void>;
|
|
155
|
+
iterateL1ToL2Messages(range?: CustomRange<bigint>): AsyncIterableIterator<InboxMessage>;
|
|
156
|
+
removeL1ToL2Messages(startIndex: bigint): Promise<void>;
|
|
147
157
|
}
|
|
148
158
|
//# sourceMappingURL=kv_archiver_store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv_archiver_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/kv_archiver_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"kv_archiver_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/kv_archiver_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,iCAAiC,EACjC,2BAA2B,EAC3B,4CAA4C,EAC5C,kCAAkC,EACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3G,OAAO,EAAE,KAAK,SAAS,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,KAAK,EAAE,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