@aztec/archiver 0.80.0 → 0.81.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 +5 -9
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +36 -49
- package/dest/archiver/archiver_store.d.ts +5 -4
- 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 +104 -91
- package/dest/archiver/data_retrieval.d.ts +3 -4
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +8 -3
- package/dest/archiver/index.d.ts +1 -1
- package/dest/archiver/index.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +6 -6
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +24 -21
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +4 -4
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +2 -3
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +9 -41
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +4 -4
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +25 -54
- package/dest/archiver/structs/published.d.ts +1 -10
- package/dest/archiver/structs/published.d.ts.map +1 -1
- package/dest/archiver/structs/published.js +1 -1
- package/dest/test/mock_l2_block_source.d.ts +9 -0
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +13 -0
- package/package.json +13 -13
- package/src/archiver/archiver.ts +44 -60
- package/src/archiver/archiver_store.ts +5 -4
- package/src/archiver/archiver_store_test_suite.ts +116 -93
- package/src/archiver/data_retrieval.ts +11 -10
- package/src/archiver/index.ts +1 -1
- package/src/archiver/kv_archiver_store/block_store.ts +28 -27
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +5 -6
- package/src/archiver/kv_archiver_store/log_store.ts +11 -59
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +35 -66
- package/src/archiver/structs/published.ts +1 -11
- package/src/test/mock_l2_block_source.ts +14 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
2
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { Body, L2Block, L2BlockHash } from '@aztec/stdlib/block';
|
|
@@ -38,19 +39,20 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
38
39
|
}
|
|
39
40
|
return await this.db.transactionAsync(async ()=>{
|
|
40
41
|
for (const block of blocks){
|
|
41
|
-
await this.#blocks.set(block.
|
|
42
|
-
header: block.
|
|
43
|
-
archive: block.
|
|
44
|
-
l1: block.l1
|
|
42
|
+
await this.#blocks.set(block.block.number, {
|
|
43
|
+
header: block.block.header.toBuffer(),
|
|
44
|
+
archive: block.block.archive.toBuffer(),
|
|
45
|
+
l1: block.l1,
|
|
46
|
+
signatures: block.signatures.map((sig)=>sig.toBuffer())
|
|
45
47
|
});
|
|
46
|
-
for(let i = 0; i < block.
|
|
47
|
-
const txEffect = block.
|
|
48
|
+
for(let i = 0; i < block.block.body.txEffects.length; i++){
|
|
49
|
+
const txEffect = block.block.body.txEffects[i];
|
|
48
50
|
await this.#txIndex.set(txEffect.txHash.toString(), [
|
|
49
|
-
block.
|
|
51
|
+
block.block.number,
|
|
50
52
|
i
|
|
51
53
|
]);
|
|
52
54
|
}
|
|
53
|
-
await this.#blockBodies.set((await block.
|
|
55
|
+
await this.#blockBodies.set((await block.block.hash()).toString(), block.block.body.toBuffer());
|
|
54
56
|
}
|
|
55
57
|
await this.#lastSynchedL1Block.set(blocks[blocks.length - 1].l1.blockNumber);
|
|
56
58
|
return true;
|
|
@@ -75,9 +77,9 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
75
77
|
this.#log.warn(`Cannot remove block ${blockNumber} from the store since we don't have it`);
|
|
76
78
|
continue;
|
|
77
79
|
}
|
|
78
|
-
await this.#blocks.delete(block.
|
|
79
|
-
await Promise.all(block.
|
|
80
|
-
const blockHash = (await block.
|
|
80
|
+
await this.#blocks.delete(block.block.number);
|
|
81
|
+
await Promise.all(block.block.body.txEffects.map((tx)=>this.#txIndex.delete(tx.txHash.toString())));
|
|
82
|
+
const blockHash = (await block.block.hash()).toString();
|
|
81
83
|
await this.#blockBodies.delete(blockHash);
|
|
82
84
|
this.#log.debug(`Unwound block ${blockNumber} ${blockHash}`);
|
|
83
85
|
}
|
|
@@ -91,8 +93,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
91
93
|
* @returns The requested L2 blocks
|
|
92
94
|
*/ async *getBlocks(start, limit) {
|
|
93
95
|
for await (const blockStorage of this.#blocks.valuesAsync(this.#computeBlockRange(start, limit))){
|
|
94
|
-
|
|
95
|
-
yield block;
|
|
96
|
+
yield await this.getBlockFromBlockStorage(blockStorage);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
@@ -125,10 +126,12 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
125
126
|
throw new Error(`Could not retrieve body for block ${header.globalVariables.blockNumber.toNumber()} ${blockHash}`);
|
|
126
127
|
}
|
|
127
128
|
const body = Body.fromBuffer(blockBodyBuffer);
|
|
128
|
-
const
|
|
129
|
+
const block = new L2Block(archive, header, body);
|
|
130
|
+
const signatures = blockStorage.signatures.map(Signature.fromBuffer);
|
|
129
131
|
return {
|
|
130
|
-
|
|
131
|
-
l1: blockStorage.l1
|
|
132
|
+
block,
|
|
133
|
+
l1: blockStorage.l1,
|
|
134
|
+
signatures
|
|
132
135
|
};
|
|
133
136
|
}
|
|
134
137
|
/**
|
|
@@ -145,9 +148,9 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
145
148
|
return undefined;
|
|
146
149
|
}
|
|
147
150
|
return {
|
|
148
|
-
data: block.
|
|
149
|
-
l2BlockNumber: block.
|
|
150
|
-
l2BlockHash: (await block.
|
|
151
|
+
data: block.block.body.txEffects[txIndex],
|
|
152
|
+
l2BlockNumber: block.block.number,
|
|
153
|
+
l2BlockHash: (await block.block.hash()).toString()
|
|
151
154
|
};
|
|
152
155
|
}
|
|
153
156
|
/**
|
|
@@ -160,8 +163,8 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
160
163
|
return undefined;
|
|
161
164
|
}
|
|
162
165
|
const block = await this.getBlock(blockNumber);
|
|
163
|
-
const tx = block.
|
|
164
|
-
return new TxReceipt(txHash, TxReceipt.statusFromRevertCode(tx.revertCode), '', tx.transactionFee.toBigInt(), L2BlockHash.fromField(await block.
|
|
166
|
+
const tx = block.block.body.txEffects[txIndex];
|
|
167
|
+
return new TxReceipt(txHash, TxReceipt.statusFromRevertCode(tx.revertCode), '', tx.transactionFee.toBigInt(), L2BlockHash.fromField(await block.block.hash()), block.block.number);
|
|
165
168
|
}
|
|
166
169
|
/**
|
|
167
170
|
* Looks up which block included the requested tx effect.
|
|
@@ -10,7 +10,7 @@ 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
12
|
import type { DataRetrieval } from '../structs/data_retrieval.js';
|
|
13
|
-
import type {
|
|
13
|
+
import type { PublishedL2Block } from '../structs/published.js';
|
|
14
14
|
/**
|
|
15
15
|
* LMDB implementation of the ArchiverDataStore interface.
|
|
16
16
|
*/
|
|
@@ -24,7 +24,7 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
24
24
|
registerContractFunctionSignatures(_address: AztecAddress, signatures: string[]): Promise<void>;
|
|
25
25
|
getContractClass(id: Fr): Promise<ContractClassPublic | undefined>;
|
|
26
26
|
getContractClassIds(): Promise<Fr[]>;
|
|
27
|
-
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
|
|
27
|
+
getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
|
|
28
28
|
addContractClasses(data: ContractClassPublic[], bytecodeCommitments: Fr[], blockNumber: number): Promise<boolean>;
|
|
29
29
|
deleteContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean>;
|
|
30
30
|
getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
|
|
@@ -38,7 +38,7 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
38
38
|
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
39
39
|
* @returns True if the operation is successful.
|
|
40
40
|
*/
|
|
41
|
-
addBlocks(blocks:
|
|
41
|
+
addBlocks(blocks: PublishedL2Block[]): Promise<boolean>;
|
|
42
42
|
/**
|
|
43
43
|
* Unwinds blocks from the database
|
|
44
44
|
* @param from - The tip of the chain, passed for verification purposes,
|
|
@@ -54,7 +54,7 @@ export declare class KVArchiverDataStore implements ArchiverDataStore {
|
|
|
54
54
|
* @param limit - The number of blocks to return.
|
|
55
55
|
* @returns The requested L2 blocks
|
|
56
56
|
*/
|
|
57
|
-
getBlocks(start: number, limit: number): Promise<
|
|
57
|
+
getBlocks(start: number, limit: number): Promise<PublishedL2Block[]>;
|
|
58
58
|
/**
|
|
59
59
|
* Gets up to `limit` amount of L2 blocks headers starting from `from`.
|
|
60
60
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv_archiver_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/kv_archiver_store.ts"],"names":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;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;IAQrD;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAQhE;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAQ9E;;;OAGG;IACH,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1C,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC,sBAAsB,CAAC,WAAW,EAAE,MAAM;IAI1C,4BAA4B,CAAC,aAAa,EAAE,MAAM;IAIlD,8BAA8B,CAAC,aAAa,EAAE,MAAM;IAI1D;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAW7C,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;CAG1C"}
|
|
@@ -53,9 +53,8 @@ import { NullifierStore } from './nullifier_store.js';
|
|
|
53
53
|
getContractClassIds() {
|
|
54
54
|
return this.#contractClassStore.getContractClassIds();
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return contract;
|
|
56
|
+
getContractInstance(address, blockNumber) {
|
|
57
|
+
return this.#contractInstanceStore.getContractInstance(address, blockNumber);
|
|
59
58
|
}
|
|
60
59
|
async addContractClasses(data, bytecodeCommitments, blockNumber) {
|
|
61
60
|
return (await Promise.all(data.map((c, i)=>this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)))).every(Boolean);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/log_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE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B/C;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAWzE;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;IAK3D;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA+EhE;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC;CA6G/E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX
|
|
1
|
+
import { INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
4
4
|
import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, PrivateLog, PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
@@ -25,7 +25,7 @@ import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, P
|
|
|
25
25
|
this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
|
|
26
26
|
this.#logsMaxPageSize = logsMaxPageSize;
|
|
27
27
|
}
|
|
28
|
-
#
|
|
28
|
+
#extractTaggedLogs(block) {
|
|
29
29
|
const taggedLogs = new Map();
|
|
30
30
|
const dataStartIndexForBlock = block.header.state.partial.noteHashTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
31
31
|
block.body.txEffects.forEach((txEffect, txIndex)=>{
|
|
@@ -33,45 +33,16 @@ import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, P
|
|
|
33
33
|
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
34
34
|
txEffect.privateLogs.forEach((log)=>{
|
|
35
35
|
const tag = log.fields[0];
|
|
36
|
+
this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
|
|
36
37
|
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
37
|
-
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, block.number,
|
|
38
|
+
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, log).toBuffer());
|
|
38
39
|
taggedLogs.set(tag.toString(), currentLogs);
|
|
39
40
|
});
|
|
40
|
-
});
|
|
41
|
-
return taggedLogs;
|
|
42
|
-
}
|
|
43
|
-
#extractTaggedLogsFromPublic(block) {
|
|
44
|
-
const taggedLogs = new Map();
|
|
45
|
-
const dataStartIndexForBlock = block.header.state.partial.noteHashTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
46
|
-
block.body.txEffects.forEach((txEffect, txIndex)=>{
|
|
47
|
-
const txHash = txEffect.txHash;
|
|
48
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
49
41
|
txEffect.publicLogs.forEach((log)=>{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// See macros/note/mod/ and see how finalization_log[0] is constructed, to understand this monstrosity. (It wasn't me).
|
|
53
|
-
// Search the codebase for "disgusting encoding" to see other hardcoded instances of this encoding, that you might need to change if you ever find yourself here.
|
|
54
|
-
if (!firstFieldBuf.subarray(0, 27).equals(Buffer.alloc(27)) || firstFieldBuf[29] !== 0) {
|
|
55
|
-
// See parseLogFromPublic - the first field of a tagged log is 5 bytes structured:
|
|
56
|
-
// [ publicLen[0], publicLen[1], 0, privateLen[0], privateLen[1]]
|
|
57
|
-
this.#log.warn(`Skipping public log with invalid first field: ${log.log[0]}`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// Check that the length values line up with the log contents
|
|
61
|
-
const publicValuesLength = firstFieldBuf.subarray(-5).readUint16BE();
|
|
62
|
-
const privateValuesLength = firstFieldBuf.subarray(-5).readUint16BE(3);
|
|
63
|
-
// Add 1 for the first field holding lengths
|
|
64
|
-
const totalLogLength = 1 + publicValuesLength + privateValuesLength;
|
|
65
|
-
// Note that zeroes can be valid log values, so we can only assert that we do not go over the given length
|
|
66
|
-
if (totalLogLength > PUBLIC_LOG_DATA_SIZE_IN_FIELDS || log.log.slice(totalLogLength).find((f)=>!f.isZero())) {
|
|
67
|
-
this.#log.warn(`Skipping invalid tagged public log with first field: ${log.log[0]}`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
// The first elt stores lengths as above => tag is in fields[1]
|
|
71
|
-
const tag = log.log[1];
|
|
72
|
-
this.#log.debug(`Found tagged public log with tag ${tag.toString()} in block ${block.number}`);
|
|
42
|
+
const tag = log.log[0];
|
|
43
|
+
this.#log.debug(`Found public log with tag ${tag.toString()} in block ${block.number}`);
|
|
73
44
|
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
74
|
-
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, block.number,
|
|
45
|
+
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, log).toBuffer());
|
|
75
46
|
taggedLogs.set(tag.toString(), currentLogs);
|
|
76
47
|
});
|
|
77
48
|
});
|
|
@@ -82,10 +53,7 @@ import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, P
|
|
|
82
53
|
* @param blocks - The blocks for which to add the logs.
|
|
83
54
|
* @returns True if the operation is successful.
|
|
84
55
|
*/ addLogs(blocks) {
|
|
85
|
-
const taggedLogsToAdd = blocks.
|
|
86
|
-
this.#extractTaggedLogsFromPrivate(block),
|
|
87
|
-
this.#extractTaggedLogsFromPublic(block)
|
|
88
|
-
]).reduce((acc, val)=>{
|
|
56
|
+
const taggedLogsToAdd = blocks.map((block)=>this.#extractTaggedLogs(block)).reduce((acc, val)=>{
|
|
89
57
|
for (const [tag, logs] of val.entries()){
|
|
90
58
|
const currentLogs = acc.get(tag) ?? [];
|
|
91
59
|
acc.set(tag, currentLogs.concat(logs));
|
|
@@ -168,7 +136,7 @@ import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, P
|
|
|
168
136
|
* that tag.
|
|
169
137
|
*/ async getLogsByTags(tags) {
|
|
170
138
|
const logs = await Promise.all(tags.map((tag)=>this.#logsByTag.getAsync(tag.toString())));
|
|
171
|
-
return logs.map((
|
|
139
|
+
return logs.map((logBuffers)=>logBuffers?.map((logBuffer)=>TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
172
140
|
}
|
|
173
141
|
/**
|
|
174
142
|
* Gets public logs based on the provided filter.
|
|
@@ -9,7 +9,7 @@ import type { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
|
9
9
|
import { type BlockHeader, TxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
10
10
|
import type { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
|
|
11
11
|
import type { DataRetrieval } from '../structs/data_retrieval.js';
|
|
12
|
-
import type {
|
|
12
|
+
import type { PublishedL2Block } from '../structs/published.js';
|
|
13
13
|
/**
|
|
14
14
|
* Simple, in-memory implementation of an archiver data store.
|
|
15
15
|
*/
|
|
@@ -51,7 +51,7 @@ export declare class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
51
51
|
maxLogs: number);
|
|
52
52
|
getContractClass(id: Fr): Promise<ContractClassPublic | undefined>;
|
|
53
53
|
getContractClassIds(): Promise<Fr[]>;
|
|
54
|
-
getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
|
|
54
|
+
getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
|
|
55
55
|
getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
|
|
56
56
|
addFunctions(contractClassId: Fr, newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[], newUnconstrainedFunctions: UnconstrainedFunctionWithMembershipProof[]): Promise<boolean>;
|
|
57
57
|
addContractClasses(data: ContractClassPublic[], bytecodeCommitments: Fr[], blockNumber: number): Promise<boolean>;
|
|
@@ -65,7 +65,7 @@ export declare class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
65
65
|
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
66
66
|
* @returns True if the operation is successful.
|
|
67
67
|
*/
|
|
68
|
-
addBlocks(blocks:
|
|
68
|
+
addBlocks(blocks: PublishedL2Block[]): Promise<boolean>;
|
|
69
69
|
/**
|
|
70
70
|
* Unwinds blocks from the database
|
|
71
71
|
* @param from - The tip of the chain, passed for verification purposes,
|
|
@@ -104,7 +104,7 @@ export declare class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
104
104
|
* @returns The requested L2 blocks.
|
|
105
105
|
* @remarks When "from" is smaller than genesis block number, blocks from the beginning are returned.
|
|
106
106
|
*/
|
|
107
|
-
getBlocks(from: number, limit: number): Promise<
|
|
107
|
+
getBlocks(from: number, limit: number): Promise<PublishedL2Block[]>;
|
|
108
108
|
getBlockHeaders(from: number, limit: number): Promise<BlockHeader[]>;
|
|
109
109
|
/**
|
|
110
110
|
* Gets a tx effect.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory_archiver_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/memory_archiver_store/memory_archiver_store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory_archiver_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/memory_archiver_store/memory_archiver_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;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AC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrG,YAAY,IAAI,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CAG9F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX
|
|
1
|
+
import { INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
@@ -72,7 +72,7 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
72
72
|
getContractClassIds() {
|
|
73
73
|
return Promise.resolve(Array.from(this.contractClasses.keys()).map((key)=>Fr.fromHexString(key)));
|
|
74
74
|
}
|
|
75
|
-
getContractInstance(address) {
|
|
75
|
+
getContractInstance(address, blockNumber) {
|
|
76
76
|
const instance = this.contractInstances.get(address.toString());
|
|
77
77
|
if (!instance) {
|
|
78
78
|
return Promise.resolve(undefined);
|
|
@@ -80,8 +80,7 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
80
80
|
const updates = this.contractInstanceUpdates.get(address.toString()) || [];
|
|
81
81
|
if (updates.length > 0) {
|
|
82
82
|
const lastUpdate = updates[0];
|
|
83
|
-
|
|
84
|
-
if (currentBlockNumber >= lastUpdate.blockOfChange) {
|
|
83
|
+
if (blockNumber >= lastUpdate.blockOfChange) {
|
|
85
84
|
instance.currentContractClassId = lastUpdate.newContractClassId;
|
|
86
85
|
} else if (!lastUpdate.prevContractClassId.isZero()) {
|
|
87
86
|
instance.currentContractClassId = lastUpdate.prevContractClassId;
|
|
@@ -178,11 +177,11 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
178
177
|
}
|
|
179
178
|
this.lastL1BlockNewBlocks = blocks[blocks.length - 1].l1.blockNumber;
|
|
180
179
|
this.l2Blocks.push(...blocks);
|
|
181
|
-
const flatTxEffects = blocks.flatMap((b)=>b.
|
|
180
|
+
const flatTxEffects = blocks.flatMap((b)=>b.block.body.txEffects.map((txEffect)=>({
|
|
182
181
|
block: b,
|
|
183
182
|
txEffect
|
|
184
183
|
})));
|
|
185
|
-
const wrappedTxEffects = await Promise.all(flatTxEffects.map((flatTxEffect)=>wrapInBlock(flatTxEffect.txEffect, flatTxEffect.block.
|
|
184
|
+
const wrappedTxEffects = await Promise.all(flatTxEffects.map((flatTxEffect)=>wrapInBlock(flatTxEffect.txEffect, flatTxEffect.block.block)));
|
|
186
185
|
this.txEffects.push(...wrappedTxEffects);
|
|
187
186
|
return Promise.resolve(true);
|
|
188
187
|
}
|
|
@@ -203,21 +202,22 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
203
202
|
if (block == undefined) {
|
|
204
203
|
break;
|
|
205
204
|
}
|
|
206
|
-
block.
|
|
205
|
+
block.block.body.txEffects.forEach(()=>this.txEffects.pop());
|
|
207
206
|
}
|
|
208
207
|
return Promise.resolve(true);
|
|
209
208
|
}
|
|
210
|
-
#
|
|
209
|
+
#storeTaggedLogs(block) {
|
|
211
210
|
const dataStartIndexForBlock = block.header.state.partial.noteHashTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
212
211
|
block.body.txEffects.forEach((txEffect, txIndex)=>{
|
|
213
212
|
const txHash = txEffect.txHash;
|
|
214
213
|
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
215
214
|
txEffect.privateLogs.forEach((log)=>{
|
|
216
215
|
const tag = log.fields[0];
|
|
216
|
+
this.#log.verbose(`Storing private log with tag ${tag.toString()} from block ${block.number}`);
|
|
217
217
|
const currentLogs = this.taggedLogs.get(tag.toString()) || [];
|
|
218
218
|
this.taggedLogs.set(tag.toString(), [
|
|
219
219
|
...currentLogs,
|
|
220
|
-
new TxScopedL2Log(txHash, dataStartIndexForTx, block.number,
|
|
220
|
+
new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, log)
|
|
221
221
|
]);
|
|
222
222
|
const currentTagsInBlock = this.logTagsPerBlock.get(block.number) || [];
|
|
223
223
|
this.logTagsPerBlock.set(block.number, [
|
|
@@ -225,41 +225,13 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
225
225
|
tag
|
|
226
226
|
]);
|
|
227
227
|
});
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
#storeTaggedLogsFromPublic(block) {
|
|
231
|
-
const dataStartIndexForBlock = block.header.state.partial.noteHashTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
232
|
-
block.body.txEffects.forEach((txEffect, txIndex)=>{
|
|
233
|
-
const txHash = txEffect.txHash;
|
|
234
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
235
228
|
txEffect.publicLogs.forEach((log)=>{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
// Search the codebase for "disgusting encoding" to see other hardcoded instances of this encoding, that you might need to change if you ever find yourself here.
|
|
239
|
-
const firstFieldBuf = log.log[0].toBuffer();
|
|
240
|
-
if (!firstFieldBuf.subarray(0, 27).equals(Buffer.alloc(27)) || firstFieldBuf[29] !== 0) {
|
|
241
|
-
// See parseLogFromPublic - the first field of a tagged log is 8 bytes structured:
|
|
242
|
-
// [ publicLen[0], publicLen[1], 0, privateLen[0], privateLen[1]]
|
|
243
|
-
this.#log.warn(`Skipping public log with invalid first field: ${log.log[0]}`);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
// Check that the length values line up with the log contents
|
|
247
|
-
const publicValuesLength = firstFieldBuf.subarray(-5).readUint16BE();
|
|
248
|
-
const privateValuesLength = firstFieldBuf.subarray(-5).readUint16BE(3);
|
|
249
|
-
// Add 1 for the first field holding lengths
|
|
250
|
-
const totalLogLength = 1 + publicValuesLength + privateValuesLength;
|
|
251
|
-
// Note that zeroes can be valid log values, so we can only assert that we do not go over the given length
|
|
252
|
-
if (totalLogLength > PUBLIC_LOG_DATA_SIZE_IN_FIELDS || log.log.slice(totalLogLength).find((f)=>!f.isZero())) {
|
|
253
|
-
this.#log.warn(`Skipping invalid tagged public log with first field: ${log.log[0]}`);
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
// The first elt stores lengths => tag is in fields[1]
|
|
257
|
-
const tag = log.log[1];
|
|
258
|
-
this.#log.verbose(`Storing public tagged log with tag ${tag.toString()} in block ${block.number}`);
|
|
229
|
+
const tag = log.log[0];
|
|
230
|
+
this.#log.verbose(`Storing public log with tag ${tag.toString()} from block ${block.number}`);
|
|
259
231
|
const currentLogs = this.taggedLogs.get(tag.toString()) || [];
|
|
260
232
|
this.taggedLogs.set(tag.toString(), [
|
|
261
233
|
...currentLogs,
|
|
262
|
-
new TxScopedL2Log(txHash, dataStartIndexForTx, block.number,
|
|
234
|
+
new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, log)
|
|
263
235
|
]);
|
|
264
236
|
const currentTagsInBlock = this.logTagsPerBlock.get(block.number) || [];
|
|
265
237
|
this.logTagsPerBlock.set(block.number, [
|
|
@@ -275,8 +247,7 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
275
247
|
* @returns True if the operation is successful.
|
|
276
248
|
*/ addLogs(blocks) {
|
|
277
249
|
blocks.forEach((block)=>{
|
|
278
|
-
this.#
|
|
279
|
-
this.#storeTaggedLogsFromPublic(block);
|
|
250
|
+
this.#storeTaggedLogs(block);
|
|
280
251
|
this.privateLogsPerBlock.set(block.number, block.body.txEffects.map((txEffect)=>txEffect.privateLogs).flat());
|
|
281
252
|
this.publicLogsPerBlock.set(block.number, block.body.txEffects.map((txEffect)=>txEffect.publicLogs).flat());
|
|
282
253
|
this.contractClassLogsPerBlock.set(block.number, block.body.txEffects.map((txEffect)=>txEffect.contractClassLogs).flat());
|
|
@@ -383,7 +354,7 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
383
354
|
}
|
|
384
355
|
async getBlockHeaders(from, limit) {
|
|
385
356
|
const blocks = await this.getBlocks(from, limit);
|
|
386
|
-
return blocks.map((block)=>block.
|
|
357
|
+
return blocks.map((block)=>block.block.header);
|
|
387
358
|
}
|
|
388
359
|
/**
|
|
389
360
|
* Gets a tx effect.
|
|
@@ -399,9 +370,9 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
399
370
|
* @returns The requested tx receipt (or undefined if not found).
|
|
400
371
|
*/ async getSettledTxReceipt(txHash) {
|
|
401
372
|
for (const block of this.l2Blocks){
|
|
402
|
-
for (const txEffect of block.
|
|
373
|
+
for (const txEffect of block.block.body.txEffects){
|
|
403
374
|
if (txEffect.txHash.equals(txHash)) {
|
|
404
|
-
return new TxReceipt(txHash, TxReceipt.statusFromRevertCode(txEffect.revertCode), '', txEffect.transactionFee.toBigInt(), L2BlockHash.fromField(await block.
|
|
375
|
+
return new TxReceipt(txHash, TxReceipt.statusFromRevertCode(txEffect.revertCode), '', txEffect.transactionFee.toBigInt(), L2BlockHash.fromField(await block.block.hash()), block.block.number);
|
|
405
376
|
}
|
|
406
377
|
}
|
|
407
378
|
}
|
|
@@ -444,8 +415,8 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
444
415
|
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
445
416
|
* that tag.
|
|
446
417
|
*/ getLogsByTags(tags) {
|
|
447
|
-
const
|
|
448
|
-
return Promise.resolve(
|
|
418
|
+
const logs = tags.map((tag)=>this.taggedLogs.get(tag.toString()) || []);
|
|
419
|
+
return Promise.resolve(logs);
|
|
449
420
|
}
|
|
450
421
|
/**
|
|
451
422
|
* Gets public logs based on the provided filter.
|
|
@@ -493,11 +464,11 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
493
464
|
if (blockLogs) {
|
|
494
465
|
for(let logIndex = 0; logIndex < blockLogs.length; logIndex++){
|
|
495
466
|
const log = blockLogs[logIndex];
|
|
496
|
-
const thisTxEffect = block.
|
|
497
|
-
const thisTxIndexInBlock = block.
|
|
467
|
+
const thisTxEffect = block.block.body.txEffects.filter((effect)=>effect.publicLogs.includes(log))[0];
|
|
468
|
+
const thisTxIndexInBlock = block.block.body.txEffects.indexOf(thisTxEffect);
|
|
498
469
|
const thisLogIndexInTx = thisTxEffect.publicLogs.indexOf(log);
|
|
499
470
|
if ((!txHash || thisTxEffect.txHash.equals(txHash)) && (!contractAddress || log.contractAddress.equals(contractAddress)) && thisTxIndexInBlock >= txIndexInBlock && thisLogIndexInTx >= logIndexInTx) {
|
|
500
|
-
logs.push(new ExtendedPublicLog(new LogId(block.
|
|
471
|
+
logs.push(new ExtendedPublicLog(new LogId(block.block.number, thisTxIndexInBlock, thisLogIndexInTx), log));
|
|
501
472
|
if (logs.length === this.maxLogs) {
|
|
502
473
|
return Promise.resolve({
|
|
503
474
|
logs,
|
|
@@ -560,11 +531,11 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
560
531
|
if (blockLogs) {
|
|
561
532
|
for(let logIndex = 0; logIndex < blockLogs.length; logIndex++){
|
|
562
533
|
const log = blockLogs[logIndex];
|
|
563
|
-
const thisTxEffect = block.
|
|
564
|
-
const thisTxIndexInBlock = block.
|
|
534
|
+
const thisTxEffect = block.block.body.txEffects.filter((effect)=>effect.contractClassLogs.includes(log))[0];
|
|
535
|
+
const thisTxIndexInBlock = block.block.body.txEffects.indexOf(thisTxEffect);
|
|
565
536
|
const thisLogIndexInTx = thisTxEffect.contractClassLogs.indexOf(log);
|
|
566
537
|
if ((!txHash || thisTxEffect.txHash.equals(txHash)) && (!contractAddress || log.contractAddress.equals(contractAddress)) && thisTxIndexInBlock >= txIndexInBlock && thisLogIndexInTx >= logIndexInTx) {
|
|
567
|
-
logs.push(new ExtendedContractClassLog(new LogId(block.
|
|
538
|
+
logs.push(new ExtendedContractClassLog(new LogId(block.block.number, thisTxIndexInBlock, thisLogIndexInTx), log));
|
|
568
539
|
if (logs.length === this.maxLogs) {
|
|
569
540
|
return Promise.resolve({
|
|
570
541
|
logs,
|
|
@@ -584,7 +555,7 @@ import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
|
|
|
584
555
|
if (this.l2Blocks.length === 0) {
|
|
585
556
|
return INITIAL_L2_BLOCK_NUM - 1;
|
|
586
557
|
}
|
|
587
|
-
return this.l2Blocks[this.l2Blocks.length - 1].
|
|
558
|
+
return this.l2Blocks[this.l2Blocks.length - 1].block.number;
|
|
588
559
|
}
|
|
589
560
|
/**
|
|
590
561
|
* Gets the number of the latest L2 block processed.
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export type L1Published<T> = {
|
|
3
|
-
data: T;
|
|
4
|
-
l1: L1PublishedData;
|
|
5
|
-
};
|
|
6
|
-
export type L1PublishedData = {
|
|
7
|
-
blockNumber: bigint;
|
|
8
|
-
timestamp: bigint;
|
|
9
|
-
blockHash: string;
|
|
10
|
-
};
|
|
1
|
+
export type { PublishedL2Block, L1PublishedData } from '@aztec/stdlib/block';
|
|
11
2
|
//# sourceMappingURL=published.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"published.d.ts","sourceRoot":"","sources":["../../../src/archiver/structs/published.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"published.d.ts","sourceRoot":"","sources":["../../../src/archiver/structs/published.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { };
|
|
@@ -42,6 +42,15 @@ export declare class MockL2BlockSource implements L2BlockSource {
|
|
|
42
42
|
* @returns The requested mocked L2 blocks.
|
|
43
43
|
*/
|
|
44
44
|
getBlocks(from: number, limit: number, proven?: boolean): Promise<L2Block[]>;
|
|
45
|
+
getPublishedBlocks(from: number, limit: number, proven?: boolean): Promise<{
|
|
46
|
+
block: L2Block;
|
|
47
|
+
l1: {
|
|
48
|
+
blockNumber: bigint;
|
|
49
|
+
blockHash: `0x${string}`;
|
|
50
|
+
timestamp: bigint;
|
|
51
|
+
};
|
|
52
|
+
signatures: never[];
|
|
53
|
+
}[]>;
|
|
45
54
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined>;
|
|
46
55
|
getBlocksForEpoch(epochNumber: bigint): Promise<L2Block[]>;
|
|
47
56
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock_l2_block_source.d.ts","sourceRoot":"","sources":["../../src/test/mock_l2_block_source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mock_l2_block_source.d.ts","sourceRoot":"","sources":["../../src/test/mock_l2_block_source.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,SAAS,EAAY,MAAM,kBAAkB,CAAC;AAEjF;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAM;IAEnC,OAAO,CAAC,iBAAiB,CAAa;IAEtC,OAAO,CAAC,GAAG,CAAiD;IAE/C,YAAY,CAAC,SAAS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IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
2
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { L2Block, L2BlockHash } from '@aztec/stdlib/block';
|
|
@@ -65,6 +66,18 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
65
66
|
*/ getBlocks(from, limit, proven) {
|
|
66
67
|
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit).filter((b)=>!proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber));
|
|
67
68
|
}
|
|
69
|
+
async getPublishedBlocks(from, limit, proven) {
|
|
70
|
+
const blocks = await this.getBlocks(from, limit, proven);
|
|
71
|
+
return blocks.map((block)=>({
|
|
72
|
+
block,
|
|
73
|
+
l1: {
|
|
74
|
+
blockNumber: BigInt(block.number),
|
|
75
|
+
blockHash: Buffer32.random().toString(),
|
|
76
|
+
timestamp: BigInt(block.number)
|
|
77
|
+
},
|
|
78
|
+
signatures: []
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
68
81
|
getBlockHeader(number) {
|
|
69
82
|
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
70
83
|
}
|