@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.5476d83
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 +27 -6
- package/dest/archiver/archiver.d.ts +147 -57
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +841 -333
- package/dest/archiver/archiver_store.d.ts +85 -50
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.js +708 -213
- package/dest/archiver/config.d.ts +5 -21
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +21 -12
- package/dest/archiver/data_retrieval.d.ts +32 -27
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +197 -94
- package/dest/archiver/errors.d.ts +9 -1
- package/dest/archiver/errors.d.ts.map +1 -1
- package/dest/archiver/errors.js +12 -0
- package/dest/archiver/index.d.ts +3 -4
- package/dest/archiver/index.d.ts.map +1 -1
- package/dest/archiver/index.js +1 -2
- package/dest/archiver/instrumentation.d.ts +12 -6
- package/dest/archiver/instrumentation.d.ts.map +1 -1
- package/dest/archiver/instrumentation.js +58 -17
- package/dest/archiver/kv_archiver_store/block_store.d.ts +48 -11
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +216 -63
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +3 -3
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.js +12 -18
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +11 -8
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +30 -16
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +50 -35
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +88 -46
- package/dest/archiver/kv_archiver_store/log_store.d.ts +2 -2
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +18 -46
- package/dest/archiver/kv_archiver_store/message_store.d.ts +23 -17
- 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/data_retrieval.d.ts +1 -1
- package/dest/archiver/structs/inbox_message.d.ts +15 -0
- package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
- package/dest/archiver/structs/inbox_message.js +38 -0
- package/dest/archiver/structs/published.d.ts +3 -11
- package/dest/archiver/structs/published.d.ts.map +1 -1
- package/dest/archiver/structs/published.js +1 -1
- package/dest/archiver/validation.d.ts +17 -0
- package/dest/archiver/validation.d.ts.map +1 -0
- package/dest/archiver/validation.js +98 -0
- package/dest/factory.d.ts +8 -13
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -49
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/rpc/index.d.ts +2 -3
- package/dest/rpc/index.d.ts.map +1 -1
- package/dest/rpc/index.js +1 -4
- package/dest/test/index.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts +5 -3
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +14 -1
- package/dest/test/mock_l2_block_source.d.ts +38 -10
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +119 -8
- 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 +28 -30
- package/src/archiver/archiver.ts +1087 -410
- package/src/archiver/archiver_store.ts +97 -55
- package/src/archiver/archiver_store_test_suite.ts +664 -210
- package/src/archiver/config.ts +28 -41
- package/src/archiver/data_retrieval.ts +279 -125
- package/src/archiver/errors.ts +21 -0
- package/src/archiver/index.ts +2 -3
- package/src/archiver/instrumentation.ts +77 -22
- package/src/archiver/kv_archiver_store/block_store.ts +270 -72
- package/src/archiver/kv_archiver_store/contract_class_store.ts +13 -23
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +35 -27
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +127 -63
- package/src/archiver/kv_archiver_store/log_store.ts +24 -62
- package/src/archiver/kv_archiver_store/message_store.ts +209 -53
- package/src/archiver/structs/inbox_message.ts +41 -0
- package/src/archiver/structs/published.ts +2 -11
- package/src/archiver/validation.ts +124 -0
- package/src/factory.ts +24 -66
- package/src/index.ts +1 -1
- package/src/rpc/index.ts +1 -5
- package/src/test/mock_archiver.ts +1 -1
- package/src/test/mock_l1_to_l2_message_source.ts +14 -3
- package/src/test/mock_l2_block_source.ts +158 -13
- package/src/test/mock_structs.ts +49 -0
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
- 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/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
- package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
|
@@ -1,57 +1,112 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
import { mapRange } from '@aztec/kv-store';
|
|
4
6
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import { deserializeInboxMessage, serializeInboxMessage, updateRollingHash } from '../structs/inbox_message.js';
|
|
8
|
+
export class MessageStoreError extends Error {
|
|
9
|
+
inboxMessage;
|
|
10
|
+
constructor(message, inboxMessage){
|
|
11
|
+
super(message), this.inboxMessage = inboxMessage;
|
|
12
|
+
this.name = 'MessageStoreError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class MessageStore {
|
|
8
16
|
db;
|
|
9
|
-
#l1ToL2Messages;
|
|
10
|
-
#l1ToL2MessageIndices;
|
|
11
|
-
#lastSynchedL1Block;
|
|
12
|
-
#totalMessageCount;
|
|
17
|
+
/** Maps from message index to serialized InboxMessage */ #l1ToL2Messages;
|
|
18
|
+
/** Maps from hex-stringified message leaf to its index */ #l1ToL2MessageIndices;
|
|
19
|
+
/** Stores L1 block number and hash of the L1 synchpoint */ #lastSynchedL1Block;
|
|
20
|
+
/** Stores total messages stored */ #totalMessageCount;
|
|
13
21
|
#log;
|
|
14
|
-
#l1ToL2MessagesSubtreeSize;
|
|
15
22
|
constructor(db){
|
|
16
23
|
this.db = db;
|
|
17
24
|
this.#log = createLogger('archiver:message_store');
|
|
18
|
-
this.#l1ToL2MessagesSubtreeSize = 2 ** L1_TO_L2_MSG_SUBTREE_HEIGHT;
|
|
19
25
|
this.#l1ToL2Messages = db.openMap('archiver_l1_to_l2_messages');
|
|
20
26
|
this.#l1ToL2MessageIndices = db.openMap('archiver_l1_to_l2_message_indices');
|
|
21
|
-
this.#lastSynchedL1Block = db.openSingleton('
|
|
27
|
+
this.#lastSynchedL1Block = db.openSingleton('archiver_last_l1_block_id');
|
|
22
28
|
this.#totalMessageCount = db.openSingleton('archiver_l1_to_l2_message_count');
|
|
23
29
|
}
|
|
24
30
|
async getTotalL1ToL2MessageCount() {
|
|
25
31
|
return await this.#totalMessageCount.getAsync() ?? 0n;
|
|
26
32
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
/** Gets the last L1 block synced. */ async getSynchedL1Block() {
|
|
34
|
+
const buffer = await this.#lastSynchedL1Block.getAsync();
|
|
35
|
+
if (!buffer) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const reader = BufferReader.asReader(buffer);
|
|
39
|
+
return {
|
|
40
|
+
l1BlockNumber: reader.readUInt256(),
|
|
41
|
+
l1BlockHash: Buffer32.fromBuffer(reader.readBytes(Buffer32.SIZE))
|
|
42
|
+
};
|
|
32
43
|
}
|
|
33
|
-
async
|
|
34
|
-
|
|
44
|
+
/** Sets the last L1 block synced */ async setSynchedL1Block(l1Block) {
|
|
45
|
+
const buffer = serializeToBuffer([
|
|
46
|
+
l1Block.l1BlockNumber,
|
|
47
|
+
l1Block.l1BlockHash
|
|
48
|
+
]);
|
|
49
|
+
await this.#lastSynchedL1Block.set(buffer);
|
|
35
50
|
}
|
|
36
51
|
/**
|
|
37
52
|
* Append L1 to L2 messages to the store.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
53
|
+
* Requires new messages to be in order and strictly after the last message added.
|
|
54
|
+
* Throws if out of order messages are added or if the rolling hash is invalid.
|
|
40
55
|
*/ addL1ToL2Messages(messages) {
|
|
56
|
+
if (messages.length === 0) {
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
}
|
|
41
59
|
return this.db.transactionAsync(async ()=>{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
let lastMessage = await this.getLastMessage();
|
|
61
|
+
let messageCount = 0;
|
|
62
|
+
for (const message of messages){
|
|
63
|
+
// Check messages are inserted in increasing order, but allow reinserting messages.
|
|
64
|
+
if (lastMessage && message.index <= lastMessage.index) {
|
|
65
|
+
const existing = await this.#l1ToL2Messages.getAsync(this.indexToKey(message.index));
|
|
66
|
+
if (existing && deserializeInboxMessage(existing).rollingHash.equals(message.rollingHash)) {
|
|
67
|
+
// We reinsert instead of skipping in case the message was re-orged and got added in a different L1 block.
|
|
68
|
+
this.#log.trace(`Reinserting message with index ${message.index} in the store`);
|
|
69
|
+
await this.#l1ToL2Messages.set(this.indexToKey(message.index), serializeInboxMessage(message));
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
throw new MessageStoreError(`Cannot insert L1 to L2 message with index ${message.index} before last message with index ${lastMessage.index}`, message);
|
|
73
|
+
}
|
|
74
|
+
// Check rolling hash is valid.
|
|
75
|
+
const previousRollingHash = lastMessage?.rollingHash ?? Buffer16.ZERO;
|
|
76
|
+
const expectedRollingHash = updateRollingHash(previousRollingHash, message.leaf);
|
|
77
|
+
if (!expectedRollingHash.equals(message.rollingHash)) {
|
|
78
|
+
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
|
+
// Check index corresponds to the L2 block number.
|
|
81
|
+
const [expectedStart, expectedEnd] = InboxLeaf.indexRangeFromL2Block(message.l2BlockNumber);
|
|
82
|
+
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 block ${message.l2BlockNumber} (expected value in range [${expectedStart}, ${expectedEnd}))`, message);
|
|
84
|
+
}
|
|
85
|
+
// Check there are no gaps in the indices within the same block.
|
|
86
|
+
if (lastMessage && message.l2BlockNumber === lastMessage.l2BlockNumber && message.index !== lastMessage.index + 1n) {
|
|
87
|
+
throw new MessageStoreError(`Missing prior message for incoming L1 to L2 message ${message.leaf.toString()} ` + `with index ${message.index}`, message);
|
|
88
|
+
}
|
|
89
|
+
// Check the first message in a block has the correct index.
|
|
90
|
+
if ((!lastMessage || message.l2BlockNumber > lastMessage.l2BlockNumber) && message.index !== InboxLeaf.smallestIndexFromL2Block(message.l2BlockNumber)) {
|
|
91
|
+
throw new MessageStoreError(`Message ${message.leaf.toString()} for L2 block ${message.l2BlockNumber} has wrong index ` + `${message.index} (expected ${InboxLeaf.smallestIndexFromL2Block(message.l2BlockNumber)})`, message);
|
|
92
|
+
}
|
|
93
|
+
// Perform the insertions.
|
|
94
|
+
await this.#l1ToL2Messages.set(this.indexToKey(message.index), serializeInboxMessage(message));
|
|
95
|
+
await this.#l1ToL2MessageIndices.set(this.leafToIndexKey(message.leaf), message.index);
|
|
96
|
+
messageCount++;
|
|
97
|
+
this.#log.trace(`Inserted L1 to L2 message ${message.leaf} with index ${message.index} into the store`);
|
|
98
|
+
lastMessage = message;
|
|
45
99
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
await this
|
|
50
|
-
|
|
100
|
+
// Update the L1 sync point to that of the last message added.
|
|
101
|
+
const currentSyncPoint = await this.getSynchedL1Block();
|
|
102
|
+
if (!currentSyncPoint || currentSyncPoint.l1BlockNumber < lastMessage.l1BlockNumber) {
|
|
103
|
+
await this.setSynchedL1Block({
|
|
104
|
+
l1BlockNumber: lastMessage.l1BlockNumber,
|
|
105
|
+
l1BlockHash: lastMessage.l1BlockHash
|
|
106
|
+
});
|
|
51
107
|
}
|
|
52
|
-
|
|
53
|
-
await this
|
|
54
|
-
return true;
|
|
108
|
+
// Update total message count with the number of inserted messages.
|
|
109
|
+
await this.increaseTotalMessageCount(messageCount);
|
|
55
110
|
});
|
|
56
111
|
}
|
|
57
112
|
/**
|
|
@@ -59,27 +114,74 @@ import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
|
59
114
|
* @param l1ToL2Message - The L1 to L2 message.
|
|
60
115
|
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
61
116
|
*/ getL1ToL2MessageIndex(l1ToL2Message) {
|
|
62
|
-
return this.#l1ToL2MessageIndices.getAsync(
|
|
117
|
+
return this.#l1ToL2MessageIndices.getAsync(this.leafToIndexKey(l1ToL2Message));
|
|
118
|
+
}
|
|
119
|
+
async getLastMessage() {
|
|
120
|
+
const [msg] = await toArray(this.#l1ToL2Messages.valuesAsync({
|
|
121
|
+
reverse: true,
|
|
122
|
+
limit: 1
|
|
123
|
+
}));
|
|
124
|
+
return msg ? deserializeInboxMessage(msg) : undefined;
|
|
63
125
|
}
|
|
64
126
|
async getL1ToL2Messages(blockNumber) {
|
|
65
127
|
const messages = [];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
for
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} else {
|
|
78
|
-
undefinedMessageFound = true;
|
|
79
|
-
// We continue iterating over messages here to verify that there are no more messages after the undefined one.
|
|
80
|
-
// --> If this was the case this would imply there is some issue with log fetching.
|
|
128
|
+
const [startIndex, endIndex] = InboxLeaf.indexRangeFromL2Block(blockNumber);
|
|
129
|
+
let lastIndex = startIndex - 1n;
|
|
130
|
+
for await (const msgBuffer of this.#l1ToL2Messages.valuesAsync({
|
|
131
|
+
start: this.indexToKey(startIndex),
|
|
132
|
+
end: this.indexToKey(endIndex)
|
|
133
|
+
})){
|
|
134
|
+
const msg = deserializeInboxMessage(msgBuffer);
|
|
135
|
+
if (msg.l2BlockNumber !== blockNumber) {
|
|
136
|
+
throw new Error(`L1 to L2 message with index ${msg.index} has invalid block number ${msg.l2BlockNumber}`);
|
|
137
|
+
} else if (msg.index !== lastIndex + 1n) {
|
|
138
|
+
throw new Error(`Expected L1 to L2 message with index ${lastIndex + 1n} but got ${msg.index}`);
|
|
81
139
|
}
|
|
140
|
+
lastIndex = msg.index;
|
|
141
|
+
messages.push(msg.leaf);
|
|
82
142
|
}
|
|
83
143
|
return messages;
|
|
84
144
|
}
|
|
145
|
+
async *iterateL1ToL2Messages(range = {}) {
|
|
146
|
+
const entriesRange = mapRange(range, this.indexToKey);
|
|
147
|
+
for await (const msgBuffer of this.#l1ToL2Messages.valuesAsync(entriesRange)){
|
|
148
|
+
yield deserializeInboxMessage(msgBuffer);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
removeL1ToL2Messages(startIndex) {
|
|
152
|
+
this.#log.debug(`Deleting L1 to L2 messages from index ${startIndex}`);
|
|
153
|
+
let deleteCount = 0;
|
|
154
|
+
return this.db.transactionAsync(async ()=>{
|
|
155
|
+
for await (const [key, msgBuffer] of this.#l1ToL2Messages.entriesAsync({
|
|
156
|
+
start: this.indexToKey(startIndex)
|
|
157
|
+
})){
|
|
158
|
+
this.#log.trace(`Deleting L1 to L2 message with index ${key - 1} from the store`);
|
|
159
|
+
await this.#l1ToL2Messages.delete(key);
|
|
160
|
+
await this.#l1ToL2MessageIndices.delete(this.leafToIndexKey(deserializeInboxMessage(msgBuffer).leaf));
|
|
161
|
+
deleteCount++;
|
|
162
|
+
}
|
|
163
|
+
await this.increaseTotalMessageCount(-deleteCount);
|
|
164
|
+
this.#log.warn(`Deleted ${deleteCount} L1 to L2 messages from index ${startIndex} from the store`);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
rollbackL1ToL2MessagesToL2Block(targetBlockNumber) {
|
|
168
|
+
this.#log.debug(`Deleting L1 to L2 messages up to target L2 block ${targetBlockNumber}`);
|
|
169
|
+
const startIndex = InboxLeaf.smallestIndexFromL2Block(targetBlockNumber + 1);
|
|
170
|
+
return this.removeL1ToL2Messages(startIndex);
|
|
171
|
+
}
|
|
172
|
+
indexToKey(index) {
|
|
173
|
+
return Number(index);
|
|
174
|
+
}
|
|
175
|
+
leafToIndexKey(leaf) {
|
|
176
|
+
return leaf.toString();
|
|
177
|
+
}
|
|
178
|
+
async increaseTotalMessageCount(count) {
|
|
179
|
+
if (count === 0) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
return await this.db.transactionAsync(async ()=>{
|
|
183
|
+
const lastTotalMessageCount = await this.getTotalL1ToL2MessageCount();
|
|
184
|
+
await this.#totalMessageCount.set(lastTotalMessageCount + BigInt(count));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
85
187
|
}
|
|
@@ -24,4 +24,4 @@ export type SingletonDataRetrieval<T> = {
|
|
|
24
24
|
*/
|
|
25
25
|
retrievedData: T;
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV9yZXRyaWV2YWwuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcmNoaXZlci9zdHJ1Y3RzL2RhdGFfcmV0cmlldmFsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxNQUFNLGFBQWEsQ0FBQyxDQUFDLElBQUk7SUFDN0I7O09BRUc7SUFDSCwwQkFBMEIsRUFBRSxNQUFNLENBQUM7SUFDbkM7O09BRUc7SUFDSCxhQUFhLEVBQUUsQ0FBQyxFQUFFLENBQUM7Q0FDcEIsQ0FBQztBQUVGOztHQUVHO0FBQ0gsTUFBTSxNQUFNLHNCQUFzQixDQUFDLENBQUMsSUFBSTtJQUN0Qzs7T0FFRztJQUNILDBCQUEwQixFQUFFLE1BQU0sQ0FBQztJQUNuQzs7T0FFRztJQUNILGFBQWEsRUFBRSxDQUFDLENBQUM7Q0FDbEIsQ0FBQyJ9
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import type { UInt32 } from '@aztec/stdlib/types';
|
|
4
|
+
export type InboxMessage = {
|
|
5
|
+
index: bigint;
|
|
6
|
+
leaf: Fr;
|
|
7
|
+
l2BlockNumber: UInt32;
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5ib3hfbWVzc2FnZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FyY2hpdmVyL3N0cnVjdHMvaW5ib3hfbWVzc2FnZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsUUFBUSxFQUFFLFFBQVEsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBRTlELE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUU5QyxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUVsRCxNQUFNLE1BQU0sWUFBWSxHQUFHO0lBQ3pCLEtBQUssRUFBRSxNQUFNLENBQUM7SUFDZCxJQUFJLEVBQUUsRUFBRSxDQUFDO0lBQ1QsYUFBYSxFQUFFLE1BQU0sQ0FBQztJQUN0QixhQUFhLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLFdBQVcsRUFBRSxRQUFRLENBQUM7SUFDdEIsV0FBVyxFQUFFLFFBQVEsQ0FBQztDQUN2QixDQUFDO0FBRUYsd0JBQWdCLGlCQUFpQixDQUFDLGtCQUFrQixFQUFFLFFBQVEsRUFBRSxJQUFJLEVBQUUsRUFBRSxHQUFHLFFBQVEsQ0FHbEY7QUFFRCx3QkFBZ0IscUJBQXFCLENBQUMsT0FBTyxFQUFFLFlBQVksR0FBRyxNQUFNLENBU25FO0FBRUQsd0JBQWdCLHVCQUF1QixDQUFDLE1BQU0sRUFBRSxNQUFNLEdBQUcsWUFBWSxDQVNwRSJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox_message.d.ts","sourceRoot":"","sources":["../../../src/archiver/structs/inbox_message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,EAAE,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,QAAQ,CAAC;IACtB,WAAW,EAAE,QAAQ,CAAC;CACvB,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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { BufferReader, bigintToUInt64BE, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
export function updateRollingHash(currentRollingHash, leaf) {
|
|
6
|
+
const input = Buffer.concat([
|
|
7
|
+
currentRollingHash.toBuffer(),
|
|
8
|
+
leaf.toBuffer()
|
|
9
|
+
]);
|
|
10
|
+
return Buffer16.fromBuffer(keccak256(input));
|
|
11
|
+
}
|
|
12
|
+
export function serializeInboxMessage(message) {
|
|
13
|
+
return serializeToBuffer([
|
|
14
|
+
bigintToUInt64BE(message.index),
|
|
15
|
+
message.leaf,
|
|
16
|
+
message.l1BlockHash,
|
|
17
|
+
numToUInt32BE(Number(message.l1BlockNumber)),
|
|
18
|
+
numToUInt32BE(message.l2BlockNumber),
|
|
19
|
+
message.rollingHash
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
export function deserializeInboxMessage(buffer) {
|
|
23
|
+
const reader = BufferReader.asReader(buffer);
|
|
24
|
+
const index = reader.readUInt64();
|
|
25
|
+
const leaf = reader.readObject(Fr);
|
|
26
|
+
const l1BlockHash = reader.readObject(Buffer32);
|
|
27
|
+
const l1BlockNumber = BigInt(reader.readNumber());
|
|
28
|
+
const l2BlockNumber = reader.readNumber();
|
|
29
|
+
const rollingHash = reader.readObject(Buffer16);
|
|
30
|
+
return {
|
|
31
|
+
index,
|
|
32
|
+
leaf,
|
|
33
|
+
l1BlockHash,
|
|
34
|
+
l1BlockNumber,
|
|
35
|
+
l2BlockNumber,
|
|
36
|
+
rollingHash
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
l1: L1PublishedData;
|
|
5
|
-
};
|
|
6
|
-
export type L1PublishedData = {
|
|
7
|
-
blockNumber: bigint;
|
|
8
|
-
timestamp: bigint;
|
|
9
|
-
blockHash: string;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=published.d.ts.map
|
|
1
|
+
export type { PublishedL2Block } from '@aztec/stdlib/block';
|
|
2
|
+
export type { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGlzaGVkLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXJjaGl2ZXIvc3RydWN0cy9wdWJsaXNoZWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWSxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDNUQsWUFBWSxFQUFFLGVBQWUsRUFBRSxtQkFBbUIsRUFBRSxNQUFNLDBCQUEwQixDQUFDIn0=
|
|
@@ -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,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { type AttestationInfo, type ValidateBlockResult } from '@aztec/stdlib/block';
|
|
4
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
5
|
+
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
export type { ValidateBlockResult };
|
|
7
|
+
/**
|
|
8
|
+
* Extracts attestation information from a published checkpoint.
|
|
9
|
+
* Returns info for each attestation, preserving array indices.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }: PublishedCheckpoint): AttestationInfo[];
|
|
12
|
+
/**
|
|
13
|
+
* Validates the attestations submitted for the given checkpoint.
|
|
14
|
+
* Returns true if the attestations are valid and sufficient, false otherwise.
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateCheckpointAttestations(publishedCheckpoint: PublishedCheckpoint, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, logger?: Logger): Promise<ValidateBlockResult>;
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FyY2hpdmVyL3ZhbGlkYXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFHckQsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDcEQsT0FBTyxFQUNMLEtBQUssZUFBZSxFQUVwQixLQUFLLG1CQUFtQixFQUV6QixNQUFNLHFCQUFxQixDQUFDO0FBQzdCLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDcEUsT0FBTyxFQUFFLEtBQUssaUJBQWlCLEVBQWtCLE1BQU0sNkJBQTZCLENBQUM7QUFHckYsWUFBWSxFQUFFLG1CQUFtQixFQUFFLENBQUM7QUFFcEM7OztHQUdHO0FBQ0gsd0JBQWdCLHlDQUF5QyxDQUFDLEVBQ3hELFVBQVUsRUFDVixZQUFZLEVBQ2IsRUFBRSxtQkFBbUIsR0FBRyxlQUFlLEVBQUUsQ0FHekM7QUFFRDs7O0dBR0c7QUFDSCx3QkFBc0IsOEJBQThCLENBQ2xELG1CQUFtQixFQUFFLG1CQUFtQixFQUN4QyxVQUFVLEVBQUUsVUFBVSxFQUN0QixTQUFTLEVBQUUsSUFBSSxDQUFDLGlCQUFpQixFQUFFLGVBQWUsQ0FBQyxFQUNuRCxNQUFNLENBQUMsRUFBRSxNQUFNLEdBQ2QsT0FBTyxDQUFDLG1CQUFtQixDQUFDLENBc0Y5QiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/archiver/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EAEzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,KAAK,iBAAiB,EAAkB,MAAM,6BAA6B,CAAC;AAGrF,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EACV,YAAY,EACb,EAAE,mBAAmB,GAAG,eAAe,EAAE,CAGzC;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,mBAAmB,CAAC,CAsF9B"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { compactArray } from '@aztec/foundation/collection';
|
|
2
|
+
import { getAttestationInfoFromPayload } from '@aztec/stdlib/block';
|
|
3
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
4
|
+
import { ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
5
|
+
/**
|
|
6
|
+
* Extracts attestation information from a published checkpoint.
|
|
7
|
+
* Returns info for each attestation, preserving array indices.
|
|
8
|
+
*/ export function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }) {
|
|
9
|
+
const payload = ConsensusPayload.fromCheckpoint(checkpoint);
|
|
10
|
+
return getAttestationInfoFromPayload(payload, attestations);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Validates the attestations submitted for the given checkpoint.
|
|
14
|
+
* Returns true if the attestations are valid and sufficient, false otherwise.
|
|
15
|
+
*/ export async function validateCheckpointAttestations(publishedCheckpoint, epochCache, constants, logger) {
|
|
16
|
+
const attestorInfos = getAttestationInfoFromPublishedCheckpoint(publishedCheckpoint);
|
|
17
|
+
const attestors = compactArray(attestorInfos.map((info)=>'address' in info ? info.address : undefined));
|
|
18
|
+
const { checkpoint, attestations } = publishedCheckpoint;
|
|
19
|
+
const headerHash = checkpoint.header.hash();
|
|
20
|
+
const archiveRoot = checkpoint.archive.root.toString();
|
|
21
|
+
const slot = checkpoint.header.slotNumber;
|
|
22
|
+
const epoch = getEpochAtSlot(slot, constants);
|
|
23
|
+
const { committee, seed } = await epochCache.getCommitteeForEpoch(epoch);
|
|
24
|
+
const logData = {
|
|
25
|
+
checkpointNumber: checkpoint.number,
|
|
26
|
+
slot,
|
|
27
|
+
epoch,
|
|
28
|
+
headerHash,
|
|
29
|
+
archiveRoot
|
|
30
|
+
};
|
|
31
|
+
logger?.debug(`Validating attestations for checkpoint ${checkpoint.number} at slot ${slot} in epoch ${epoch}`, {
|
|
32
|
+
committee: (committee ?? []).map((member)=>member.toString()),
|
|
33
|
+
recoveredAttestors: attestorInfos,
|
|
34
|
+
postedAttestations: attestations.map((a)=>(a.address.isZero() ? a.signature : a.address).toString()),
|
|
35
|
+
...logData
|
|
36
|
+
});
|
|
37
|
+
if (!committee || committee.length === 0) {
|
|
38
|
+
logger?.warn(`No committee found for epoch ${epoch} at slot ${slot}. Accepting checkpoint without validation.`, logData);
|
|
39
|
+
return {
|
|
40
|
+
valid: true
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const requiredAttestationCount = Math.floor(committee.length * 2 / 3) + 1;
|
|
44
|
+
const failedValidationResult = (reason)=>({
|
|
45
|
+
valid: false,
|
|
46
|
+
reason,
|
|
47
|
+
block: checkpoint.blocks[0].toBlockInfo(),
|
|
48
|
+
committee,
|
|
49
|
+
seed,
|
|
50
|
+
epoch,
|
|
51
|
+
attestors,
|
|
52
|
+
attestations
|
|
53
|
+
});
|
|
54
|
+
for(let i = 0; i < attestorInfos.length; i++){
|
|
55
|
+
const info = attestorInfos[i];
|
|
56
|
+
// Fail on invalid signatures (no address recovered)
|
|
57
|
+
if (info.status === 'invalid-signature' || info.status === 'empty') {
|
|
58
|
+
logger?.warn(`Attestation with empty or invalid signature at slot ${slot}`, {
|
|
59
|
+
committee,
|
|
60
|
+
invalidIndex: i,
|
|
61
|
+
...logData
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
...failedValidationResult('invalid-attestation'),
|
|
65
|
+
invalidIndex: i
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// Check if the attestor at this index matches the committee member at the same index
|
|
69
|
+
if (info.status === 'recovered-from-signature' || info.status === 'provided-as-address') {
|
|
70
|
+
const signer = info.address.toString();
|
|
71
|
+
const expectedCommitteeMember = committee[i]?.toString();
|
|
72
|
+
if (!expectedCommitteeMember || signer !== expectedCommitteeMember) {
|
|
73
|
+
logger?.warn(`Attestation at index ${i} from ${signer} does not match expected committee member ${expectedCommitteeMember} at slot ${slot}`, {
|
|
74
|
+
committee,
|
|
75
|
+
invalidIndex: i,
|
|
76
|
+
...logData
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
...failedValidationResult('invalid-attestation'),
|
|
80
|
+
invalidIndex: i
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const validAttestationCount = attestorInfos.filter((info)=>info.status === 'recovered-from-signature').length;
|
|
86
|
+
if (validAttestationCount < requiredAttestationCount) {
|
|
87
|
+
logger?.warn(`Insufficient attestations for checkpoint at slot ${slot}`, {
|
|
88
|
+
requiredAttestations: requiredAttestationCount,
|
|
89
|
+
actualAttestations: validAttestationCount,
|
|
90
|
+
...logData
|
|
91
|
+
});
|
|
92
|
+
return failedValidationResult('insufficient-attestations');
|
|
93
|
+
}
|
|
94
|
+
logger?.debug(`Checkpoint attestations validated successfully for checkpoint ${checkpoint.number} at slot ${slot}`, logData);
|
|
95
|
+
return {
|
|
96
|
+
valid: true
|
|
97
|
+
};
|
|
98
|
+
}
|
package/dest/factory.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
|
|
2
1
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
3
|
-
import type
|
|
4
|
-
import type { ArchiverApi, Service } from '@aztec/stdlib/interfaces/server';
|
|
5
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
2
|
+
import { Archiver, type ArchiverDeps } from './archiver/archiver.js';
|
|
6
3
|
import type { ArchiverConfig } from './archiver/config.js';
|
|
4
|
+
import { KVArchiverDataStore } from './archiver/kv_archiver_store/kv_archiver_store.js';
|
|
5
|
+
export declare const ARCHIVER_STORE_NAME = "archiver";
|
|
6
|
+
/** Creates an archiver store. */
|
|
7
|
+
export declare function createArchiverStore(userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig): Promise<KVArchiverDataStore>;
|
|
7
8
|
/**
|
|
8
9
|
* Creates a local archiver.
|
|
9
10
|
* @param config - The archiver configuration.
|
|
@@ -12,13 +13,7 @@ import type { ArchiverConfig } from './archiver/config.js';
|
|
|
12
13
|
* @param telemetry - The telemetry client.
|
|
13
14
|
* @returns The local archiver.
|
|
14
15
|
*/
|
|
15
|
-
export declare function createArchiver(config: ArchiverConfig & DataStoreConfig,
|
|
16
|
+
export declare function createArchiver(config: ArchiverConfig & DataStoreConfig, deps: ArchiverDeps, opts?: {
|
|
16
17
|
blockUntilSync: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
* Creates a remote archiver client.
|
|
20
|
-
* @param config - The archiver configuration.
|
|
21
|
-
* @returns The remote archiver client.
|
|
22
|
-
*/
|
|
23
|
-
export declare function createRemoteArchiver(config: ArchiverConfig): ArchiverApi;
|
|
24
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
18
|
+
}): Promise<Archiver>;
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFPOUQsT0FBTyxFQUFFLFFBQVEsRUFBRSxLQUFLLFlBQVksRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ3JFLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQzNELE9BQU8sRUFBdUIsbUJBQW1CLEVBQUUsTUFBTSxtREFBbUQsQ0FBQztBQUU3RyxlQUFPLE1BQU0sbUJBQW1CLGFBQWEsQ0FBQztBQUU5QyxpQ0FBaUM7QUFDakMsd0JBQXNCLG1CQUFtQixDQUN2QyxVQUFVLEVBQUUsSUFBSSxDQUFDLGNBQWMsRUFBRSx3QkFBd0IsR0FBRyxTQUFTLENBQUMsR0FBRyxlQUFlLGdDQVF6RjtBQUVEOzs7Ozs7O0dBT0c7QUFDSCx3QkFBc0IsY0FBYyxDQUNsQyxNQUFNLEVBQUUsY0FBYyxHQUFHLGVBQWUsRUFDeEMsSUFBSSxFQUFFLFlBQVksRUFDbEIsSUFBSSxHQUFFO0lBQUUsY0FBYyxFQUFFLE9BQU8sQ0FBQTtDQUE2QixHQUMzRCxPQUFPLENBQUMsUUFBUSxDQUFDLENBSW5CIn0=
|
package/dest/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAO9D,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAuB,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAE7G,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAE9C,iCAAiC;AACjC,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,IAAI,CAAC,cAAc,EAAE,wBAAwB,GAAG,SAAS,CAAC,GAAG,eAAe,gCAQzF;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,GAAG,eAAe,EACxC,IAAI,EAAE,YAAY,EAClB,IAAI,GAAE;IAAE,cAAc,EAAE,OAAO,CAAA;CAA6B,GAC3D,OAAO,CAAC,QAAQ,CAAC,CAInB"}
|
package/dest/factory.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
3
|
-
import {
|
|
4
|
-
import { TokenBridgeContractArtifact } from '@aztec/noir-contracts.js/TokenBridge';
|
|
5
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
6
|
-
import { protocolContractNames, protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
3
|
+
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
7
4
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
8
5
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
9
|
-
import { computePublicBytecodeCommitment
|
|
10
|
-
import { getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
|
|
11
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
+
import { computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
12
7
|
import { Archiver } from './archiver/archiver.js';
|
|
13
|
-
import { KVArchiverDataStore } from './archiver/
|
|
14
|
-
|
|
8
|
+
import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './archiver/kv_archiver_store/kv_archiver_store.js';
|
|
9
|
+
export const ARCHIVER_STORE_NAME = 'archiver';
|
|
10
|
+
/** Creates an archiver store. */ export async function createArchiverStore(userConfig) {
|
|
11
|
+
const config = {
|
|
12
|
+
...userConfig,
|
|
13
|
+
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb
|
|
14
|
+
};
|
|
15
|
+
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config, createLogger('archiver:lmdb'));
|
|
16
|
+
return new KVArchiverDataStore(store, config.maxLogs);
|
|
17
|
+
}
|
|
15
18
|
/**
|
|
16
19
|
* Creates a local archiver.
|
|
17
20
|
* @param config - The archiver configuration.
|
|
@@ -19,27 +22,12 @@ import { createArchiverClient } from './rpc/index.js';
|
|
|
19
22
|
* @param opts - The options.
|
|
20
23
|
* @param telemetry - The telemetry client.
|
|
21
24
|
* @returns The local archiver.
|
|
22
|
-
*/ export async function createArchiver(config,
|
|
25
|
+
*/ export async function createArchiver(config, deps, opts = {
|
|
23
26
|
blockUntilSync: true
|
|
24
|
-
}
|
|
25
|
-
const
|
|
26
|
-
const archiverStore = new KVArchiverDataStore(store, config.maxLogs);
|
|
27
|
+
}) {
|
|
28
|
+
const archiverStore = await createArchiverStore(config);
|
|
27
29
|
await registerProtocolContracts(archiverStore);
|
|
28
|
-
|
|
29
|
-
return Archiver.createAndSync(config, archiverStore, {
|
|
30
|
-
telemetry,
|
|
31
|
-
blobSinkClient
|
|
32
|
-
}, opts.blockUntilSync);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates a remote archiver client.
|
|
36
|
-
* @param config - The archiver configuration.
|
|
37
|
-
* @returns The remote archiver client.
|
|
38
|
-
*/ export function createRemoteArchiver(config) {
|
|
39
|
-
if (!config.archiverUrl) {
|
|
40
|
-
throw new Error('Archiver URL is required');
|
|
41
|
-
}
|
|
42
|
-
return createArchiverClient(config.archiverUrl, getComponentsVersionsFromConfig(config, protocolContractTreeRoot, getVKTreeRoot()));
|
|
30
|
+
return Archiver.createAndSync(config, archiverStore, deps, opts.blockUntilSync);
|
|
43
31
|
}
|
|
44
32
|
async function registerProtocolContracts(store) {
|
|
45
33
|
const blockNumber = 0;
|
|
@@ -49,10 +37,10 @@ async function registerProtocolContracts(store) {
|
|
|
49
37
|
const contractClassPublic = {
|
|
50
38
|
...contract.contractClass,
|
|
51
39
|
privateFunctions: [],
|
|
52
|
-
|
|
40
|
+
utilityFunctions: []
|
|
53
41
|
};
|
|
54
42
|
const publicFunctionSignatures = contract.artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
55
|
-
await store.registerContractFunctionSignatures(
|
|
43
|
+
await store.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
56
44
|
const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
|
|
57
45
|
await store.addContractClasses([
|
|
58
46
|
contractClassPublic
|
|
@@ -64,22 +52,3 @@ async function registerProtocolContracts(store) {
|
|
|
64
52
|
], blockNumber);
|
|
65
53
|
}
|
|
66
54
|
}
|
|
67
|
-
// TODO(#10007): Remove this method. We are explicitly registering these contracts
|
|
68
|
-
// here to ensure they are available to all nodes and all prover nodes, since the PXE
|
|
69
|
-
// was tweaked to automatically push contract classes to the node it is registered,
|
|
70
|
-
// but other nodes in the network may require the contract classes to be registered as well.
|
|
71
|
-
// TODO(#10007): Remove the dependency on noir-contracts.js from this package once we remove this.
|
|
72
|
-
async function registerCommonContracts(store) {
|
|
73
|
-
const blockNumber = 0;
|
|
74
|
-
const artifacts = [
|
|
75
|
-
TokenBridgeContractArtifact,
|
|
76
|
-
TokenContractArtifact
|
|
77
|
-
];
|
|
78
|
-
const classes = await Promise.all(artifacts.map(async (artifact)=>({
|
|
79
|
-
...await getContractClassFromArtifact(artifact),
|
|
80
|
-
privateFunctions: [],
|
|
81
|
-
unconstrainedFunctions: []
|
|
82
|
-
})));
|
|
83
|
-
const bytecodeCommitments = await Promise.all(classes.map((x)=>computePublicBytecodeCommitment(x.packedBytecode)));
|
|
84
|
-
await store.addContractClasses(classes, bytecodeCommitments, blockNumber);
|
|
85
|
-
}
|
package/dest/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './archiver/index.js';
|
|
2
2
|
export * from './factory.js';
|
|
3
3
|
export * from './rpc/index.js';
|
|
4
|
-
export {
|
|
5
|
-
//# sourceMappingURL=
|
|
4
|
+
export { retrieveL2ProofVerifiedEvents } from './archiver/data_retrieval.js';
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQixDQUFDO0FBQ3BDLGNBQWMsY0FBYyxDQUFDO0FBQzdCLGNBQWMsZ0JBQWdCLENBQUM7QUFFL0IsT0FBTyxFQUFFLDZCQUE2QixFQUFFLE1BQU0sOEJBQThCLENBQUMifQ==
|
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dest/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './archiver/index.js';
|
|
2
2
|
export * from './factory.js';
|
|
3
3
|
export * from './rpc/index.js';
|
|
4
|
-
export {
|
|
4
|
+
export { retrieveL2ProofVerifiedEvents } from './archiver/data_retrieval.js';
|
package/dest/rpc/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type ArchiverApi } from '@aztec/stdlib/interfaces/server';
|
|
2
2
|
import { type ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
3
|
-
export declare function createArchiverClient(url: string, versions: Partial<ComponentsVersions>, fetch?: (host: string,
|
|
3
|
+
export declare function createArchiverClient(url: string, versions: Partial<ComponentsVersions>, fetch?: (host: string, body: unknown, extraHeaders?: Record<string, string> | undefined, noRetry?: boolean | undefined) => Promise<{
|
|
4
4
|
response: any;
|
|
5
5
|
headers: {
|
|
6
6
|
get: (header: string) => string | null | undefined;
|
|
7
7
|
};
|
|
8
8
|
}>): ArchiverApi;
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ycGMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEtBQUssV0FBVyxFQUFxQixNQUFNLGlDQUFpQyxDQUFDO0FBQ3RGLE9BQU8sRUFBRSxLQUFLLGtCQUFrQixFQUFnQyxNQUFNLDBCQUEwQixDQUFDO0FBR2pHLHdCQUFnQixvQkFBb0IsQ0FDbEMsR0FBRyxFQUFFLE1BQU0sRUFDWCxRQUFRLEVBQUUsT0FBTyxDQUFDLGtCQUFrQixDQUFDLEVBQ3JDLEtBQUs7Ozs7O0VBQW1DLEdBQ3ZDLFdBQVcsQ0FNYiJ9
|