@aztec/pxe 0.0.1-commit.d1f2d6c → 0.0.1-commit.d431d1c
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/block_synchronizer/block_synchronizer.d.ts +4 -6
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +11 -51
- package/dest/config/index.d.ts +1 -3
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +0 -17
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +4 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +4 -7
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -4
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +9 -19
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +6 -5
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -10
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -9
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +5 -17
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +6 -14
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +33 -31
- package/dest/debug/pxe_debug_utils.d.ts +1 -1
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +1 -2
- package/dest/logs/log_service.d.ts +1 -1
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +11 -18
- package/dest/notes/note_service.d.ts +2 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +6 -8
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +3 -4
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +7 -10
- package/dest/storage/note_store/note_store.d.ts +55 -43
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +252 -238
- package/dest/storage/private_event_store/private_event_store.d.ts +4 -17
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +135 -163
- package/dest/tagging/index.d.ts +1 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +0 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -3
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +2 -3
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +2 -5
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +2 -3
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +8 -5
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -3
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +4 -7
- package/dest/tree_membership/tree_membership_service.d.ts +50 -0
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
- package/dest/tree_membership/tree_membership_service.js +75 -0
- package/package.json +16 -16
- package/src/block_synchronizer/block_synchronizer.ts +14 -53
- package/src/config/index.ts +0 -14
- package/src/contract_function_simulator/contract_function_simulator.ts +9 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +3 -12
- package/src/contract_function_simulator/oracle/oracle.ts +13 -26
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -20
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +6 -33
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +38 -46
- package/src/debug/pxe_debug_utils.ts +1 -2
- package/src/logs/log_service.ts +8 -25
- package/src/notes/note_service.ts +11 -15
- package/src/oracle_version.ts +3 -4
- package/src/pxe.ts +8 -32
- package/src/storage/note_store/note_store.ts +313 -279
- package/src/storage/private_event_store/private_event_store.ts +175 -214
- package/src/tagging/index.ts +0 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +1 -11
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +1 -7
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +1 -3
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +17 -5
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +3 -12
- package/src/tree_membership/tree_membership_service.ts +97 -0
- package/dest/storage/note_store/stored_note.d.ts +0 -16
- package/dest/storage/note_store/stored_note.d.ts.map +0 -1
- package/dest/storage/note_store/stored_note.js +0 -43
- package/dest/storage/private_event_store/stored_private_event.d.ts +0 -23
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +0 -1
- package/dest/storage/private_event_store/stored_private_event.js +0 -56
- package/dest/tagging/get_all_logs_by_tags.d.ts +0 -24
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +0 -1
- package/dest/tagging/get_all_logs_by_tags.js +0 -46
- package/src/storage/note_store/stored_note.ts +0 -48
- package/src/storage/private_event_store/stored_private_event.ts +0 -73
- package/src/tagging/get_all_logs_by_tags.ts +0 -68
|
@@ -1,26 +1,86 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import {
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
|
+
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
6
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
7
|
/**
|
|
7
8
|
* Stores decrypted private event logs.
|
|
8
9
|
*/ export class PrivateEventStore {
|
|
9
10
|
storeName = 'private_event';
|
|
10
11
|
#store;
|
|
11
|
-
/**
|
|
12
|
-
/** Multi-map from
|
|
12
|
+
/** Map storing the actual private event log entries, keyed by siloedEventCommitment */ #eventLogs;
|
|
13
|
+
/** Multi-map from contractAddress_scope_eventSelector to siloedEventCommitment for efficient lookup */ #eventsByContractScopeSelector;
|
|
13
14
|
/** Multi-map from block number to siloedEventCommitment for rollback support */ #eventsByBlockNumber;
|
|
14
|
-
/**
|
|
15
|
-
/**
|
|
15
|
+
/** Map from siloedEventCommitment to boolean indicating if log has been seen. */ #seenLogs;
|
|
16
|
+
/** jobId => eventId (event siloed nullifier) => PrivateEventEntry */ #eventLogsInJobStage;
|
|
16
17
|
logger = createLogger('private_event_store');
|
|
17
18
|
constructor(store){
|
|
18
19
|
this.#store = store;
|
|
19
|
-
this.#
|
|
20
|
-
this.#
|
|
20
|
+
this.#eventLogs = this.#store.openMap('private_event_logs');
|
|
21
|
+
this.#eventsByContractScopeSelector = this.#store.openMultiMap('events_by_contract_scope_selector');
|
|
22
|
+
this.#seenLogs = this.#store.openMap('seen_logs');
|
|
21
23
|
this.#eventsByBlockNumber = this.#store.openMultiMap('events_by_block_number');
|
|
22
|
-
this.#
|
|
23
|
-
|
|
24
|
+
this.#eventLogsInJobStage = new Map();
|
|
25
|
+
}
|
|
26
|
+
#keyFor(contractAddress, scope, eventSelector) {
|
|
27
|
+
return `${contractAddress.toString()}_${scope.toString()}_${eventSelector.toString()}`;
|
|
28
|
+
}
|
|
29
|
+
async commit(jobId) {
|
|
30
|
+
await Promise.all([
|
|
31
|
+
...this.#getEventLogsInJobStage(jobId).entries()
|
|
32
|
+
].map(async ([eventId, eventEntry])=>{
|
|
33
|
+
this.logger.verbose('storing private event log (KV store)', eventEntry);
|
|
34
|
+
await Promise.all([
|
|
35
|
+
this.#eventLogs.set(eventId, eventEntry),
|
|
36
|
+
this.#eventsByContractScopeSelector.set(eventEntry.lookupKey, eventId),
|
|
37
|
+
this.#eventsByBlockNumber.set(eventEntry.l2BlockNumber, eventId),
|
|
38
|
+
this.#seenLogs.set(eventId, true)
|
|
39
|
+
]);
|
|
40
|
+
}));
|
|
41
|
+
return this.discardStaged(jobId);
|
|
42
|
+
}
|
|
43
|
+
discardStaged(jobId) {
|
|
44
|
+
this.#eventLogsInJobStage.delete(jobId);
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
#getEventLogsInJobStage(jobId) {
|
|
48
|
+
let jobStage = this.#eventLogsInJobStage.get(jobId);
|
|
49
|
+
if (jobStage === undefined) {
|
|
50
|
+
jobStage = new Map();
|
|
51
|
+
this.#eventLogsInJobStage.set(jobId, jobStage);
|
|
52
|
+
}
|
|
53
|
+
return jobStage;
|
|
54
|
+
}
|
|
55
|
+
async #isSeenLog(jobId, eventId) {
|
|
56
|
+
const eventLogsInJobStage = this.#getEventLogsInJobStage(jobId).get(eventId);
|
|
57
|
+
return !!eventLogsInJobStage || !!await this.#seenLogs.getAsync(eventId);
|
|
58
|
+
}
|
|
59
|
+
#addEventLogToStage(jobId, eventId, eventEntry) {
|
|
60
|
+
this.#getEventLogsInJobStage(jobId).set(eventId, eventEntry);
|
|
61
|
+
}
|
|
62
|
+
async #getEventSiloedNullifiers(contractAddress, scope, eventSelector, jobId) {
|
|
63
|
+
const key = this.#keyFor(contractAddress, scope, eventSelector);
|
|
64
|
+
const eventSiloedNullifiersInStorage = [];
|
|
65
|
+
for await (const eventId of this.#eventsByContractScopeSelector.getValuesAsync(key)){
|
|
66
|
+
eventSiloedNullifiersInStorage.push(eventId);
|
|
67
|
+
}
|
|
68
|
+
if (!jobId) {
|
|
69
|
+
return eventSiloedNullifiersInStorage;
|
|
70
|
+
}
|
|
71
|
+
const eventSiloedNullifiersInJobStage = new Set([
|
|
72
|
+
...this.#getEventLogsInJobStage(jobId).entries()
|
|
73
|
+
].filter(([_, entry])=>entry.lookupKey === key).map(([idx, _])=>idx));
|
|
74
|
+
return [
|
|
75
|
+
...new Set(eventSiloedNullifiersInStorage).union(eventSiloedNullifiersInJobStage)
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
async #getEventLogBySiloedNullifier(eventId, jobId) {
|
|
79
|
+
if (jobId) {
|
|
80
|
+
return this.#getEventLogsInJobStage(jobId).get(eventId) ?? await this.#eventLogs.getAsync(eventId);
|
|
81
|
+
} else {
|
|
82
|
+
return await this.#eventLogs.getAsync(eventId);
|
|
83
|
+
}
|
|
24
84
|
}
|
|
25
85
|
/**
|
|
26
86
|
* Store a private event log.
|
|
@@ -34,26 +94,36 @@ import { StoredPrivateEvent } from './stored_private_event.js';
|
|
|
34
94
|
* txHash - The transaction hash of the event log.
|
|
35
95
|
* blockNumber - The block number in which the event was emitted.
|
|
36
96
|
*/ storePrivateEventLog(eventSelector, randomness, msgContent, siloedEventCommitment, metadata, jobId) {
|
|
37
|
-
|
|
38
|
-
|
|
97
|
+
const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash, txIndexInBlock, eventIndexInTx } = metadata;
|
|
98
|
+
return this.#store.transactionAsync(async ()=>{
|
|
99
|
+
const key = this.#keyFor(contractAddress, scope, eventSelector);
|
|
100
|
+
// The siloed event commitment is guaranteed to be unique as it's inserted into the nullifier tree. For this
|
|
101
|
+
// reason we use it as id.
|
|
39
102
|
const eventId = siloedEventCommitment.toString();
|
|
103
|
+
const hasBeenSeen = await this.#isSeenLog(jobId, eventId);
|
|
104
|
+
if (hasBeenSeen) {
|
|
105
|
+
this.logger.verbose('Ignoring duplicate event log', {
|
|
106
|
+
txHash: txHash.toString(),
|
|
107
|
+
siloedEventCommitment
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
40
111
|
this.logger.verbose('storing private event log (job stage)', {
|
|
41
|
-
eventId,
|
|
42
112
|
contractAddress,
|
|
43
113
|
scope,
|
|
44
114
|
msgContent,
|
|
45
115
|
l2BlockNumber
|
|
46
116
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
117
|
+
this.#addEventLogToStage(jobId, eventId, {
|
|
118
|
+
randomness,
|
|
119
|
+
msgContent: serializeToBuffer(msgContent),
|
|
120
|
+
l2BlockNumber,
|
|
121
|
+
l2BlockHash: l2BlockHash.toBuffer(),
|
|
122
|
+
txHash: txHash.toBuffer(),
|
|
123
|
+
txIndexInBlock,
|
|
124
|
+
eventIndexInTx,
|
|
125
|
+
lookupKey: key
|
|
126
|
+
});
|
|
57
127
|
});
|
|
58
128
|
}
|
|
59
129
|
/**
|
|
@@ -66,57 +136,49 @@ import { StoredPrivateEvent } from './stored_private_event.js';
|
|
|
66
136
|
* scope: - The addresses that decrypted the logs.
|
|
67
137
|
* @returns - The event log contents, augmented with metadata about the transaction and block in which the event was
|
|
68
138
|
* included.
|
|
69
|
-
*/ getPrivateEvents(eventSelector, filter) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const targetScopes = new Set(filter.scopes.map((s)=>s.toString()));
|
|
74
|
-
const eventIds = await toArray(this.#eventsByContractAndEventSelector.getValuesAsync(key));
|
|
139
|
+
*/ async getPrivateEvents(eventSelector, filter) {
|
|
140
|
+
const events = [];
|
|
141
|
+
for (const scope of filter.scopes){
|
|
142
|
+
const eventIds = await this.#getEventSiloedNullifiers(filter.contractAddress, scope, eventSelector);
|
|
75
143
|
for (const eventId of eventIds){
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
if (!eventBuffer) {
|
|
79
|
-
this.logger.verbose(`EventId ${eventId} does not exist in main index but it is referenced from contract event selector index`);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
const storedPrivateEvent = StoredPrivateEvent.fromBuffer(eventBuffer);
|
|
83
|
-
// Filter by block range
|
|
84
|
-
if (storedPrivateEvent.l2BlockNumber < filter.fromBlock || storedPrivateEvent.l2BlockNumber >= filter.toBlock) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
// Filter by scopes
|
|
88
|
-
if (storedPrivateEvent.scopes.intersection(targetScopes).size === 0) {
|
|
144
|
+
const entry = await this.#getEventLogBySiloedNullifier(eventId);
|
|
145
|
+
if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
|
|
89
146
|
continue;
|
|
90
147
|
}
|
|
91
|
-
//
|
|
92
|
-
|
|
148
|
+
// Convert buffer back to Fr array
|
|
149
|
+
const reader = BufferReader.asReader(entry.msgContent);
|
|
150
|
+
const numFields = entry.msgContent.length / Fr.SIZE_IN_BYTES;
|
|
151
|
+
const msgContent = reader.readArray(numFields, Fr);
|
|
152
|
+
const txHash = TxHash.fromBuffer(entry.txHash);
|
|
153
|
+
const l2BlockHash = L2BlockHash.fromBuffer(entry.l2BlockHash);
|
|
154
|
+
if (filter.txHash && !txHash.equals(filter.txHash)) {
|
|
93
155
|
continue;
|
|
94
156
|
}
|
|
95
157
|
events.push({
|
|
96
|
-
l2BlockNumber:
|
|
97
|
-
txIndexInBlock:
|
|
98
|
-
eventIndexInTx:
|
|
158
|
+
l2BlockNumber: entry.l2BlockNumber,
|
|
159
|
+
txIndexInBlock: entry.txIndexInBlock,
|
|
160
|
+
eventIndexInTx: entry.eventIndexInTx,
|
|
99
161
|
event: {
|
|
100
|
-
packedEvent:
|
|
101
|
-
l2BlockNumber: BlockNumber(
|
|
102
|
-
txHash
|
|
103
|
-
l2BlockHash
|
|
162
|
+
packedEvent: msgContent,
|
|
163
|
+
l2BlockNumber: BlockNumber(entry.l2BlockNumber),
|
|
164
|
+
txHash,
|
|
165
|
+
l2BlockHash,
|
|
104
166
|
eventSelector
|
|
105
167
|
}
|
|
106
168
|
});
|
|
107
169
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return events.map((ev)=>ev.event);
|
|
170
|
+
}
|
|
171
|
+
// Sort by block number, then by tx index within block, then by event index within tx
|
|
172
|
+
events.sort((a, b)=>{
|
|
173
|
+
if (a.l2BlockNumber !== b.l2BlockNumber) {
|
|
174
|
+
return a.l2BlockNumber - b.l2BlockNumber;
|
|
175
|
+
}
|
|
176
|
+
if (a.txIndexInBlock !== b.txIndexInBlock) {
|
|
177
|
+
return a.txIndexInBlock - b.txIndexInBlock;
|
|
178
|
+
}
|
|
179
|
+
return a.eventIndexInTx - b.eventIndexInTx;
|
|
119
180
|
});
|
|
181
|
+
return events.map((ev)=>ev.event);
|
|
120
182
|
}
|
|
121
183
|
/**
|
|
122
184
|
* Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
|
|
@@ -137,114 +199,24 @@ import { StoredPrivateEvent } from './stored_private_event.js';
|
|
|
137
199
|
*/ async rollback(blockNumber, synchedBlockNumber) {
|
|
138
200
|
let removedCount = 0;
|
|
139
201
|
for(let block = blockNumber + 1; block <= synchedBlockNumber; block++){
|
|
140
|
-
const eventIds =
|
|
202
|
+
const eventIds = [];
|
|
203
|
+
for await (const eventId of this.#eventsByBlockNumber.getValuesAsync(block)){
|
|
204
|
+
eventIds.push(eventId);
|
|
205
|
+
}
|
|
141
206
|
if (eventIds.length > 0) {
|
|
142
207
|
await this.#eventsByBlockNumber.delete(block);
|
|
143
208
|
for (const eventId of eventIds){
|
|
144
|
-
const
|
|
145
|
-
if (!
|
|
146
|
-
throw new Error(`Event not found for eventId ${eventId}`);
|
|
209
|
+
const entry = await this.#eventLogs.getAsync(eventId);
|
|
210
|
+
if (!entry) {
|
|
211
|
+
throw new Error(`Event log not found for eventId ${eventId}`);
|
|
147
212
|
}
|
|
148
|
-
|
|
149
|
-
await this.#
|
|
150
|
-
await this.#
|
|
213
|
+
await this.#eventLogs.delete(eventId);
|
|
214
|
+
await this.#seenLogs.delete(eventId);
|
|
215
|
+
await this.#eventsByContractScopeSelector.deleteValue(entry.lookupKey, eventId);
|
|
151
216
|
removedCount++;
|
|
152
217
|
}
|
|
153
218
|
}
|
|
154
219
|
}
|
|
155
220
|
this.logger.verbose(`Rolled back ${removedCount} private events after block ${blockNumber}`);
|
|
156
221
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Commits in memory job data to persistent storage.
|
|
159
|
-
*
|
|
160
|
-
* Called by JobCoordinator when a job completes successfully.
|
|
161
|
-
*
|
|
162
|
-
* Note: JobCoordinator wraps all commits in a single transaction, so we don't need our own transactionAsync here
|
|
163
|
-
* (and using one would throw on IndexedDB as it does not support nested txs).
|
|
164
|
-
*
|
|
165
|
-
* @param jobId - The jobId identifying which staged data to commit
|
|
166
|
-
*/ commit(jobId) {
|
|
167
|
-
return this.#withJobLock(jobId, async ()=>{
|
|
168
|
-
for (const [eventId, entry] of this.#getEventsForJob(jobId).entries()){
|
|
169
|
-
const lookupKey = this.#keyFor(entry.contractAddress, entry.eventSelector);
|
|
170
|
-
this.logger.verbose('storing private event log', {
|
|
171
|
-
eventId,
|
|
172
|
-
lookupKey
|
|
173
|
-
});
|
|
174
|
-
await Promise.all([
|
|
175
|
-
this.#events.set(eventId, entry.toBuffer()),
|
|
176
|
-
this.#eventsByContractAndEventSelector.set(lookupKey, eventId),
|
|
177
|
-
this.#eventsByBlockNumber.set(entry.l2BlockNumber, eventId)
|
|
178
|
-
]);
|
|
179
|
-
}
|
|
180
|
-
this.#clearJobData(jobId);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Discards in memory job data without persisting it.
|
|
185
|
-
*/ discardStaged(jobId) {
|
|
186
|
-
return this.#withJobLock(jobId, ()=>Promise.resolve(this.#clearJobData(jobId)));
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Reads an event from in-memory job data first, falling back to persistent storage if not found.
|
|
190
|
-
*
|
|
191
|
-
* Returns undefined if the event does not exist in the store overall.
|
|
192
|
-
*/ async #readEvent(eventId, jobId) {
|
|
193
|
-
const eventForJob = this.#getEventsForJob(jobId).get(eventId);
|
|
194
|
-
if (eventForJob) {
|
|
195
|
-
return eventForJob;
|
|
196
|
-
}
|
|
197
|
-
const buffer = await this.#events.getAsync(eventId);
|
|
198
|
-
return buffer ? StoredPrivateEvent.fromBuffer(buffer) : undefined;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Writes an event to in-memory job data.
|
|
202
|
-
*
|
|
203
|
-
* Writes are only allowed in a job context. Events modified during a job will only be persisted when `commit` is
|
|
204
|
-
* called.
|
|
205
|
-
*/ #writeEvent(eventId, entry, jobId) {
|
|
206
|
-
this.#getEventsForJob(jobId).set(eventId, entry);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Get in-memory data only visible to @param jobId
|
|
210
|
-
*/ #getEventsForJob(jobId) {
|
|
211
|
-
let eventsForJob = this.#eventsForJob.get(jobId);
|
|
212
|
-
if (eventsForJob === undefined) {
|
|
213
|
-
eventsForJob = new Map();
|
|
214
|
-
this.#eventsForJob.set(jobId, eventsForJob);
|
|
215
|
-
}
|
|
216
|
-
return eventsForJob;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Clear data structures supporting a specific job.
|
|
220
|
-
*/ #clearJobData(jobId) {
|
|
221
|
-
this.#eventsForJob.delete(jobId);
|
|
222
|
-
this.#jobLocks.delete(jobId);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Ensures a function can only run once it acquires a unique per-job lock, and handles proper lock release after it
|
|
226
|
-
* runs.
|
|
227
|
-
*
|
|
228
|
-
* This primitive allows concurrent writes on this store without risking data corruption due to unsound write
|
|
229
|
-
* interleaving.
|
|
230
|
-
*/ async #withJobLock(jobId, fn) {
|
|
231
|
-
let lock = this.#jobLocks.get(jobId);
|
|
232
|
-
if (!lock) {
|
|
233
|
-
lock = new Semaphore(1);
|
|
234
|
-
this.#jobLocks.set(jobId, lock);
|
|
235
|
-
}
|
|
236
|
-
await lock.acquire();
|
|
237
|
-
try {
|
|
238
|
-
return await fn();
|
|
239
|
-
} finally{
|
|
240
|
-
lock.release();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Returns a string key based on @param contractAddress and @param eventSelector.
|
|
245
|
-
*
|
|
246
|
-
* The returned key is meant to be used when interacting with index #eventsByContractAndEventSelector.
|
|
247
|
-
*/ #keyFor(contractAddress, eventSelector) {
|
|
248
|
-
return `${contractAddress.toString()}_${eventSelector.toString()}`;
|
|
249
|
-
}
|
|
250
222
|
}
|
package/dest/tagging/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
|
|
12
12
|
export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
|
|
13
13
|
export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
|
|
14
|
-
export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
|
|
15
14
|
export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
|
|
16
15
|
export { type PreTag } from '@aztec/stdlib/logs';
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90YWdnaW5nL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7R0FTRztBQUVILE9BQU8sRUFBRSxxQ0FBcUMsRUFBRSxNQUFNLGlFQUFpRSxDQUFDO0FBQ3hILE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLDhDQUE4QyxDQUFDO0FBQ3hGLE9BQU8sRUFBRSxzQ0FBc0MsRUFBRSxNQUFNLGdCQUFnQixDQUFDO0FBR3hFLE9BQU8sRUFBRSwyQkFBMkIsRUFBRSxHQUFHLEVBQUUsU0FBUyxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDakYsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFFLE1BQU0sb0JBQW9CLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tagging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qCAAqC,EAAE,MAAM,iEAAiE,CAAC;AACxH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,sCAAsC,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tagging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qCAAqC,EAAE,MAAM,iEAAiE,CAAC;AACxH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,sCAAsC,EAAE,MAAM,gBAAgB,CAAC;AAGxE,OAAO,EAAE,2BAA2B,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dest/tagging/index.js
CHANGED
|
@@ -10,6 +10,5 @@
|
|
|
10
10
|
*/ export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
|
|
11
11
|
export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
|
|
12
12
|
export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
|
|
13
|
-
export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
|
|
14
13
|
// Re-export tagging-related types from stdlib
|
|
15
14
|
export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import type { L2BlockHash } from '@aztec/stdlib/block';
|
|
4
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
4
|
import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
5
|
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
@@ -11,5 +10,5 @@ import type { RecipientTaggingStore } from '../../storage/tagging_store/recipien
|
|
|
11
10
|
* @dev This function can be safely executed "in parallel" for other sender-recipient pairs because the data in
|
|
12
11
|
* in the tagging data provider is indexed by the secret and hence completely disjoint.
|
|
13
12
|
*/
|
|
14
|
-
export declare function loadPrivateLogsForSenderRecipientPair(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, taggingStore: RecipientTaggingStore, anchorBlockNumber: BlockNumber,
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
13
|
+
export declare function loadPrivateLogsForSenderRecipientPair(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, taggingStore: RecipientTaggingStore, anchorBlockNumber: BlockNumber, jobId: string): Promise<TxScopedL2Log[]>;
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZF9wcml2YXRlX2xvZ3NfZm9yX3NlbmRlcl9yZWNpcGllbnRfcGFpci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3RhZ2dpbmcvcmVjaXBpZW50X3N5bmMvbG9hZF9wcml2YXRlX2xvZ3NfZm9yX3NlbmRlcl9yZWNpcGllbnRfcGFpci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSwyQkFBMkIsRUFBRSxhQUFhLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUVyRixPQUFPLEtBQUssRUFBRSxxQkFBcUIsRUFBRSxNQUFNLHdEQUF3RCxDQUFDO0FBS3BHOzs7Ozs7R0FNRztBQUNILHdCQUFzQixxQ0FBcUMsQ0FDekQsTUFBTSxFQUFFLDJCQUEyQixFQUNuQyxHQUFHLEVBQUUsWUFBWSxFQUNqQixTQUFTLEVBQUUsU0FBUyxFQUNwQixZQUFZLEVBQUUscUJBQXFCLEVBQ25DLGlCQUFpQixFQUFFLFdBQVcsRUFDOUIsS0FBSyxFQUFFLE1BQU0sR0FDWixPQUFPLENBQUMsYUFBYSxFQUFFLENBQUMsQ0E0RzFCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load_private_logs_for_sender_recipient_pair.d.ts","sourceRoot":"","sources":["../../../src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"load_private_logs_for_sender_recipient_pair.d.ts","sourceRoot":"","sources":["../../../src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAErF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AAKpG;;;;;;GAMG;AACH,wBAAsB,qCAAqC,CACzD,MAAM,EAAE,2BAA2B,EACnC,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,qBAAqB,EACnC,iBAAiB,EAAE,WAAW,EAC9B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,EAAE,CAAC,CA4G1B"}
|
|
@@ -7,7 +7,7 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @dev This function can be safely executed "in parallel" for other sender-recipient pairs because the data in
|
|
9
9
|
* in the tagging data provider is indexed by the secret and hence completely disjoint.
|
|
10
|
-
*/ export async function loadPrivateLogsForSenderRecipientPair(secret, app, aztecNode, taggingStore, anchorBlockNumber,
|
|
10
|
+
*/ export async function loadPrivateLogsForSenderRecipientPair(secret, app, aztecNode, taggingStore, anchorBlockNumber, jobId) {
|
|
11
11
|
// # Explanation of how the algorithm works
|
|
12
12
|
// When we perform the sync we will look at logs that correspond to the tagging index range
|
|
13
13
|
// (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
|
|
@@ -72,7 +72,7 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
72
72
|
const logs = [];
|
|
73
73
|
while(true){
|
|
74
74
|
// Get private logs with their block timestamps and corresponding tagging indexes
|
|
75
|
-
const privateLogsWithIndexes = await loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber
|
|
75
|
+
const privateLogsWithIndexes = await loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber);
|
|
76
76
|
if (privateLogsWithIndexes.length === 0) {
|
|
77
77
|
break;
|
|
78
78
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import type { L2BlockHash } from '@aztec/stdlib/block';
|
|
4
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
4
|
import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
5
|
/**
|
|
@@ -8,8 +7,8 @@ import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/l
|
|
|
8
7
|
* `secret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and `end` is
|
|
9
8
|
* exclusive.
|
|
10
9
|
*/
|
|
11
|
-
export declare function loadLogsForRange(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, start: number, end: number, anchorBlockNumber: BlockNumber
|
|
10
|
+
export declare function loadLogsForRange(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, start: number, end: number, anchorBlockNumber: BlockNumber): Promise<Array<{
|
|
12
11
|
log: TxScopedL2Log;
|
|
13
12
|
taggingIndex: number;
|
|
14
13
|
}>>;
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZF9sb2dzX2Zvcl9yYW5nZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvcmVjaXBpZW50X3N5bmMvdXRpbHMvbG9hZF9sb2dzX2Zvcl9yYW5nZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSwyQkFBMkIsRUFBVSxhQUFhLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUc3Rjs7OztHQUlHO0FBQ0gsd0JBQXNCLGdCQUFnQixDQUNwQyxNQUFNLEVBQUUsMkJBQTJCLEVBQ25DLEdBQUcsRUFBRSxZQUFZLEVBQ2pCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLEtBQUssRUFBRSxNQUFNLEVBQ2IsR0FBRyxFQUFFLE1BQU0sRUFDWCxpQkFBaUIsRUFBRSxXQUFXLEdBQzdCLE9BQU8sQ0FBQyxLQUFLLENBQUM7SUFBRSxHQUFHLEVBQUUsYUFBYSxDQUFDO0lBQUMsWUFBWSxFQUFFLE1BQU0sQ0FBQTtDQUFFLENBQUMsQ0FBQyxDQXdCOUQifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load_logs_for_range.d.ts","sourceRoot":"","sources":["../../../../src/tagging/recipient_sync/utils/load_logs_for_range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"load_logs_for_range.d.ts","sourceRoot":"","sources":["../../../../src/tagging/recipient_sync/utils/load_logs_for_range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,2BAA2B,EAAU,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAG7F;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,2BAA2B,EACnC,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,iBAAiB,EAAE,WAAW,GAC7B,OAAO,CAAC,KAAK,CAAC;IAAE,GAAG,EAAE,aAAa,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAwB9D"}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
2
|
-
import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
3
2
|
/**
|
|
4
3
|
* Gets private logs with their corresponding block timestamps and tagging indexes for the given index range, `app` and
|
|
5
4
|
* `secret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and `end` is
|
|
6
5
|
* exclusive.
|
|
7
|
-
*/ export async function loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber
|
|
6
|
+
*/ export async function loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber) {
|
|
8
7
|
// Derive tags for the window
|
|
9
8
|
const preTags = Array(end - start).fill(0).map((_, i)=>({
|
|
10
9
|
secret,
|
|
11
10
|
index: start + i
|
|
12
11
|
}));
|
|
13
12
|
const siloedTags = await Promise.all(preTags.map((preTag)=>Tag.compute(preTag))).then((tags)=>Promise.all(tags.map((tag)=>SiloedTag.compute(tag, app))));
|
|
14
|
-
|
|
15
|
-
// pagination here.
|
|
16
|
-
const logs = await getAllPrivateLogsByTags(aztecNode, siloedTags, anchorBlockHash);
|
|
13
|
+
const logs = await aztecNode.getPrivateLogsByTags(siloedTags);
|
|
17
14
|
// Pair logs with their corresponding tagging indexes
|
|
18
15
|
const logsWithIndexes = [];
|
|
19
16
|
for(let i = 0; i < logs.length; i++){
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type { L2BlockHash } from '@aztec/stdlib/block';
|
|
3
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
4
3
|
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
5
4
|
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
@@ -17,5 +16,5 @@ import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagg
|
|
|
17
16
|
* @dev This function looks for new indexes, adds them to pending, then it checks status of each pending index and
|
|
18
17
|
* updates its status accordingly.
|
|
19
18
|
*/
|
|
20
|
-
export declare function syncSenderTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, taggingStore: SenderTaggingStore,
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
19
|
+
export declare function syncSenderTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, taggingStore: SenderTaggingStore, jobId: string): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY19zZW5kZXJfdGFnZ2luZ19pbmRleGVzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdGFnZ2luZy9zZW5kZXJfc3luYy9zeW5jX3NlbmRlcl90YWdnaW5nX2luZGV4ZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakUsT0FBTyxLQUFLLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV0RSxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHFEQUFxRCxDQUFDO0FBSzlGOzs7Ozs7Ozs7Ozs7O0dBYUc7QUFDSCx3QkFBc0Isd0JBQXdCLENBQzVDLE1BQU0sRUFBRSwyQkFBMkIsRUFDbkMsR0FBRyxFQUFFLFlBQVksRUFDakIsU0FBUyxFQUFFLFNBQVMsRUFDcEIsWUFBWSxFQUFFLGtCQUFrQixFQUNoQyxLQUFLLEVBQUUsTUFBTSxHQUNaLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FtRWYifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync_sender_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../src/tagging/sender_sync/sync_sender_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"sync_sender_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../src/tagging/sender_sync/sync_sender_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qDAAqD,CAAC;AAK9F;;;;;;;;;;;;;GAaG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,2BAA2B,EACnC,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB,EAChC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAmEf"}
|
|
@@ -14,7 +14,7 @@ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_taggin
|
|
|
14
14
|
* is simply the highest pending index plus one (or finalized if pending is undefined).
|
|
15
15
|
* @dev This function looks for new indexes, adds them to pending, then it checks status of each pending index and
|
|
16
16
|
* updates its status accordingly.
|
|
17
|
-
*/ export async function syncSenderTaggingIndexes(secret, app, aztecNode, taggingStore,
|
|
17
|
+
*/ export async function syncSenderTaggingIndexes(secret, app, aztecNode, taggingStore, jobId) {
|
|
18
18
|
// # Explanation of how syncing works
|
|
19
19
|
//
|
|
20
20
|
// When choosing an index, we select: highest pending index + 1 (or highest finalized index + 1 if no pending).
|
|
@@ -40,7 +40,7 @@ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_taggin
|
|
|
40
40
|
while(true){
|
|
41
41
|
// Load and store indexes for the current window. These indexes may already exist in the database if txs using
|
|
42
42
|
// them were previously sent from this PXE. Any duplicates are handled by the tagging data provider.
|
|
43
|
-
await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore,
|
|
43
|
+
await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore, jobId);
|
|
44
44
|
// Retrieve all indexes within the current window from storage and update their status accordingly.
|
|
45
45
|
const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
|
|
46
46
|
if (pendingTxHashes.length === 0) {
|
|
@@ -8,4 +8,4 @@ export declare function getStatusChangeOfPending(pending: TxHash[], aztecNode: A
|
|
|
8
8
|
txHashesToFinalize: TxHash[];
|
|
9
9
|
txHashesToDrop: TxHash[];
|
|
10
10
|
}>;
|
|
11
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X3N0YXR1c19jaGFuZ2Vfb2ZfcGVuZGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvZ2V0X3N0YXR1c19jaGFuZ2Vfb2ZfcGVuZGluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEVBQUUsTUFBTSxFQUFZLE1BQU0sa0JBQWtCLENBQUM7QUFFcEQ7OztHQUdHO0FBQ0gsd0JBQXNCLHdCQUF3QixDQUM1QyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQ2pCLFNBQVMsRUFBRSxTQUFTLEdBQ25CLE9BQU8sQ0FBQztJQUFFLGtCQUFrQixFQUFFLE1BQU0sRUFBRSxDQUFDO0lBQUMsY0FBYyxFQUFFLE1BQU0sRUFBRSxDQUFBO0NBQUUsQ0FBQyxDQXFDckUifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_status_change_of_pending.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/get_status_change_of_pending.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,MAAM,EAAY,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC;IAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"get_status_change_of_pending.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/get_status_change_of_pending.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,MAAM,EAAY,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC;IAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAqCrE"}
|
|
@@ -3,23 +3,26 @@ import { TxStatus } from '@aztec/stdlib/tx';
|
|
|
3
3
|
* Based on receipts obtained from `aztecNode` returns which pending transactions changed their status to finalized or
|
|
4
4
|
* dropped.
|
|
5
5
|
*/ export async function getStatusChangeOfPending(pending, aztecNode) {
|
|
6
|
-
// Get receipts for all pending tx hashes.
|
|
7
|
-
const receipts = await Promise.all(
|
|
6
|
+
// Get receipts for all pending tx hashes and the finalized block number.
|
|
7
|
+
const [receipts, tips] = await Promise.all([
|
|
8
|
+
Promise.all(pending.map((pendingTxHash)=>aztecNode.getTxReceipt(pendingTxHash))),
|
|
9
|
+
aztecNode.getL2Tips()
|
|
10
|
+
]);
|
|
8
11
|
const txHashesToFinalize = [];
|
|
9
12
|
const txHashesToDrop = [];
|
|
10
13
|
for(let i = 0; i < receipts.length; i++){
|
|
11
14
|
const receipt = receipts[i];
|
|
12
15
|
const txHash = pending[i];
|
|
13
|
-
if (receipt.status === TxStatus.
|
|
16
|
+
if (receipt.status === TxStatus.SUCCESS && receipt.blockNumber && receipt.blockNumber <= tips.finalized.block.number) {
|
|
14
17
|
// Tx has been included in a block and the corresponding block is finalized --> we mark the indexes as
|
|
15
18
|
// finalized.
|
|
16
19
|
txHashesToFinalize.push(txHash);
|
|
17
|
-
} else if (receipt.
|
|
20
|
+
} else if (receipt.status === TxStatus.DROPPED || receipt.status === TxStatus.APP_LOGIC_REVERTED || receipt.status === TxStatus.TEARDOWN_REVERTED || receipt.status === TxStatus.BOTH_REVERTED) {
|
|
18
21
|
// Tx was dropped or reverted --> we drop the corresponding pending indexes.
|
|
19
22
|
// TODO(#17615): Don't drop pending indexes corresponding to non-revertible phases.
|
|
20
23
|
txHashesToDrop.push(txHash);
|
|
21
24
|
} else {
|
|
22
|
-
// Tx is still pending
|
|
25
|
+
// Tx is still pending or the corresponding block is not yet finalized --> we don't do anything.
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
return {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type { L2BlockHash } from '@aztec/stdlib/block';
|
|
3
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
4
3
|
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
5
4
|
import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
|
|
@@ -17,5 +16,5 @@ import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_t
|
|
|
17
16
|
* @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
|
|
18
17
|
* preserving way.
|
|
19
18
|
*/
|
|
20
|
-
export declare function loadAndStoreNewTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, start: number, end: number, aztecNode: AztecNode, taggingStore: SenderTaggingStore,
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
19
|
+
export declare function loadAndStoreNewTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, start: number, end: number, aztecNode: AztecNode, taggingStore: SenderTaggingStore, jobId: string): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvbG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSwyQkFBMkIsRUFBVSxNQUFNLG9CQUFvQixDQUFDO0FBSTlFLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sd0RBQXdELENBQUM7QUFFakc7Ozs7Ozs7Ozs7Ozs7R0FhRztBQUNILHdCQUFzQiw2QkFBNkIsQ0FDakQsTUFBTSxFQUFFLDJCQUEyQixFQUNuQyxHQUFHLEVBQUUsWUFBWSxFQUNqQixLQUFLLEVBQUUsTUFBTSxFQUNiLEdBQUcsRUFBRSxNQUFNLEVBQ1gsU0FBUyxFQUFFLFNBQVMsRUFDcEIsWUFBWSxFQUFFLGtCQUFrQixFQUNoQyxLQUFLLEVBQUUsTUFBTSxpQkFrQmQifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load_and_store_new_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"load_and_store_new_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,2BAA2B,EAAU,MAAM,oBAAoB,CAAC;AAI9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AAEjG;;;;;;;;;;;;;GAaG;AACH,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,2BAA2B,EACnC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB,EAChC,KAAK,EAAE,MAAM,iBAkBd"}
|