@aztec/pxe 0.0.1-commit.ffe5b04ea → 0.0.1-commit.fff30aa
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/bin/check_oracle_version.js +4 -4
- package/dest/block_synchronizer/block_synchronizer.d.ts +3 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +10 -0
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +13 -5
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +36 -9
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +17 -9
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +33 -21
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +51 -20
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +188 -46
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +13 -39
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +27 -49
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +74 -42
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +252 -87
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
- package/dest/contract_logging.d.ts +9 -4
- package/dest/contract_logging.d.ts.map +1 -1
- package/dest/contract_logging.js +21 -6
- package/dest/contract_sync/contract_sync_service.d.ts +6 -5
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +62 -43
- package/dest/contract_sync/helpers.d.ts +2 -3
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +7 -2
- package/dest/debug/pxe_debug_utils.d.ts +3 -3
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts +1 -2
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +0 -1
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +2 -2
- package/dest/entrypoints/client/lazy/index.d.ts +1 -2
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +0 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +2 -2
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +2 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -2
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +2 -2
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +16 -4
- package/dest/events/private_event_filter_validator.d.ts +3 -2
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +15 -0
- package/dest/logs/log_service.d.ts +7 -8
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +27 -37
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +4 -5
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +14 -5
- package/dest/notes_filter.d.ts +2 -3
- package/dest/notes_filter.d.ts.map +1 -1
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
- package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +12 -15
- package/dest/pxe.d.ts +11 -9
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +48 -29
- package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +36 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +1 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +4 -2
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +1 -1
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +2 -2
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +3 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
- 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 -16
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- 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 +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
- 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 +24 -11
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_synchronizer.ts +12 -0
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +50 -13
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
- package/src/contract_function_simulator/oracle/interfaces.ts +54 -29
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +262 -66
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +36 -69
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +427 -116
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- package/src/contract_logging.ts +18 -5
- package/src/contract_sync/contract_sync_service.ts +99 -75
- package/src/contract_sync/helpers.ts +4 -4
- package/src/debug/pxe_debug_utils.ts +3 -3
- package/src/entrypoints/client/bundle/index.ts +0 -1
- package/src/entrypoints/client/bundle/utils.ts +2 -3
- package/src/entrypoints/client/lazy/index.ts +0 -1
- package/src/entrypoints/client/lazy/utils.ts +2 -3
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +1 -2
- package/src/entrypoints/server/utils.ts +2 -3
- package/src/events/event_service.ts +17 -4
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/logs/log_service.ts +57 -78
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +18 -8
- package/src/notes_filter.ts +1 -3
- package/src/oracle_version.ts +20 -10
- package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
- package/src/private_kernel/private_kernel_oracle.ts +14 -14
- package/src/pxe.ts +75 -34
- package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +44 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +8 -6
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +2 -5
- package/src/storage/private_event_store/private_event_store.ts +4 -0
- package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
- package/src/tagging/index.ts +1 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +5 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
- package/dest/access_scopes.d.ts +0 -9
- package/dest/access_scopes.d.ts.map +0 -1
- package/dest/access_scopes.js +0 -6
- package/src/access_scopes.ts +0 -9
|
@@ -85,9 +85,24 @@ interface ContainsNote {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
const selectPropertyFromPackedNoteContent = (noteData: Fr[], selector: PropertySelector): Fr => {
|
|
88
|
+
if (selector.index >= noteData.length) {
|
|
89
|
+
throw new Error(`Property selector index ${selector.index} out of bounds for note with ${noteData.length} fields`);
|
|
90
|
+
}
|
|
91
|
+
if (selector.offset + selector.length > Fr.SIZE_IN_BYTES) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Property selector range (offset=${selector.offset}, length=${selector.length}) exceeds Fr buffer size of ${Fr.SIZE_IN_BYTES} bytes`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
88
96
|
const noteValueBuffer = noteData[selector.index].toBuffer();
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
// Noir's PropertySelector counts offset from the LSB (last byte of the big-endian buffer),
|
|
98
|
+
// so offset=0,length=Fr.SIZE_IN_BYTES reads the entire field, and offset=0,length=1 reads the last byte.
|
|
99
|
+
const start = Fr.SIZE_IN_BYTES - selector.offset - selector.length;
|
|
100
|
+
const end = Fr.SIZE_IN_BYTES - selector.offset;
|
|
101
|
+
const noteValue = noteValueBuffer.subarray(start, end);
|
|
102
|
+
// Left-pad to Fr.SIZE_IN_BYTES so Fr.fromBuffer interprets the value correctly.
|
|
103
|
+
const padded = Buffer.alloc(Fr.SIZE_IN_BYTES);
|
|
104
|
+
noteValue.copy(padded, Fr.SIZE_IN_BYTES - noteValue.length);
|
|
105
|
+
return Fr.fromBuffer(padded);
|
|
91
106
|
};
|
|
92
107
|
|
|
93
108
|
const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]): T[] =>
|
|
@@ -103,7 +118,11 @@ const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]):
|
|
|
103
118
|
[Comparator.GTE]: () => !noteValueFr.lt(value),
|
|
104
119
|
};
|
|
105
120
|
|
|
106
|
-
|
|
121
|
+
const fn = comparatorSelector[comparator];
|
|
122
|
+
if (!fn) {
|
|
123
|
+
throw new Error(`Invalid comparator value: ${comparator}`);
|
|
124
|
+
}
|
|
125
|
+
return fn();
|
|
107
126
|
}),
|
|
108
127
|
);
|
|
109
128
|
|
|
@@ -29,6 +29,7 @@ export class ProxiedContractStoreFactory {
|
|
|
29
29
|
}
|
|
30
30
|
instance.currentContractClassId = realInstance.currentContractClassId;
|
|
31
31
|
instance.originalContractClassId = realInstance.originalContractClassId;
|
|
32
|
+
instance.initializationHash = realInstance.initializationHash;
|
|
32
33
|
return instance;
|
|
33
34
|
} else {
|
|
34
35
|
return target.getContractInstance(address);
|
|
@@ -47,6 +48,9 @@ export class ProxiedContractStoreFactory {
|
|
|
47
48
|
return fn;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Function with selector ${selector} not found in stub artifact for overridden contract at ${contractAddress}. The stub does not implement this function.`,
|
|
53
|
+
);
|
|
50
54
|
} else {
|
|
51
55
|
return target.getFunctionArtifact(contractAddress, selector);
|
|
52
56
|
}
|
|
@@ -64,6 +68,9 @@ export class ProxiedContractStoreFactory {
|
|
|
64
68
|
return fn;
|
|
65
69
|
}
|
|
66
70
|
}
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Function with selector ${selector} not found in stub artifact for overridden contract at ${contractAddress}. The stub does not implement this function.`,
|
|
73
|
+
);
|
|
67
74
|
} else {
|
|
68
75
|
return target.getFunctionArtifactWithDebugMetadata(contractAddress, selector);
|
|
69
76
|
}
|
|
@@ -78,6 +85,6 @@ export class ProxiedContractStoreFactory {
|
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
},
|
|
81
|
-
});
|
|
88
|
+
}) satisfies ContractStore;
|
|
82
89
|
}
|
|
83
90
|
}
|
package/src/contract_logging.ts
CHANGED
|
@@ -5,18 +5,22 @@ import type { DebugLog } from '@aztec/stdlib/logs';
|
|
|
5
5
|
|
|
6
6
|
/** Resolves a contract address to a human-readable name, if available. */
|
|
7
7
|
export type ContractNameResolver = (address: AztecAddress) => Promise<string | undefined>;
|
|
8
|
+
export type CONTRACT_LOG_KIND = 'aztecnr' | 'user';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* Creates a logger whose output is prefixed with `
|
|
11
|
+
* Creates a logger whose output is prefixed with `contract:<name>(<addrAbbrev>)`.
|
|
11
12
|
*/
|
|
12
13
|
export async function createContractLogger(
|
|
13
14
|
contractAddress: AztecAddress,
|
|
14
15
|
getContractName: ContractNameResolver,
|
|
16
|
+
kind: CONTRACT_LOG_KIND,
|
|
15
17
|
options?: { instanceId?: string },
|
|
16
18
|
): Promise<Logger> {
|
|
17
19
|
const addrAbbrev = contractAddress.toString().slice(0, 10);
|
|
18
20
|
const name = await getContractName(contractAddress);
|
|
19
|
-
|
|
21
|
+
|
|
22
|
+
const prefix = kind == 'aztecnr' ? 'aztecnr' : 'contract';
|
|
23
|
+
const module = name ? `${prefix}:${name}(${addrAbbrev})` : `${prefix}:Unknown(${addrAbbrev})`;
|
|
20
24
|
return createLogger(module, options);
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -29,11 +33,20 @@ export function logContractMessage(logger: Logger, level: LogLevel, message: str
|
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* Displays debug logs collected during public function simulation,
|
|
32
|
-
* using the `
|
|
36
|
+
* using the `contract:` prefixed logger format.
|
|
33
37
|
*/
|
|
34
38
|
export async function displayDebugLogs(debugLogs: DebugLog[], getContractName: ContractNameResolver): Promise<void> {
|
|
35
39
|
for (const log of debugLogs) {
|
|
36
|
-
const
|
|
37
|
-
|
|
40
|
+
const { kind, message } = stripAztecnrLogPrefix(log.message);
|
|
41
|
+
const logger = await createContractLogger(log.contractAddress, getContractName, kind);
|
|
42
|
+
logContractMessage(logger, log.level, message, log.fields);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function stripAztecnrLogPrefix(message: string): { kind: CONTRACT_LOG_KIND; message: string } {
|
|
47
|
+
if (message.startsWith('[aztec-nr] ')) {
|
|
48
|
+
return { kind: 'aztecnr', message: message.slice('[aztec-nr] '.length) };
|
|
49
|
+
} else {
|
|
50
|
+
return { kind: 'user', message };
|
|
38
51
|
}
|
|
39
52
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
2
3
|
import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
6
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
6
7
|
|
|
7
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
8
8
|
import type { StagedStore } from '../job_coordinator/job_coordinator.js';
|
|
9
9
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
10
10
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
11
11
|
import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
12
12
|
|
|
13
|
+
/** Maximum number of scope syncs running concurrently across the PXE. */
|
|
14
|
+
const MAX_CONCURRENT_SCOPE_SYNCS = 5;
|
|
15
|
+
|
|
13
16
|
/**
|
|
14
17
|
* Service for syncing the private state of contracts and verifying that the PXE holds the current class artifact.
|
|
15
18
|
* It uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
|
|
@@ -20,12 +23,17 @@ export class ContractSyncService implements StagedStore {
|
|
|
20
23
|
readonly storeName = 'contract_sync';
|
|
21
24
|
|
|
22
25
|
// Tracks contracts synced since last wipe. The cache is keyed per individual scope address
|
|
23
|
-
// (`contractAddress:scopeAddress`), or `contractAddress:*` for
|
|
26
|
+
// (`contractAddress:scopeAddress`), or `contractAddress:*` for all scopes (all accounts).
|
|
24
27
|
// The value is a promise that resolves when the contract is synced.
|
|
25
28
|
private syncedContracts: Map<string, Promise<void>> = new Map();
|
|
26
29
|
|
|
27
|
-
// Per-job
|
|
28
|
-
private
|
|
30
|
+
// Per-job excluded contract addresses - these contracts should not be synced.
|
|
31
|
+
private excludedFromSync: Map<string, Set<string>> = new Map();
|
|
32
|
+
|
|
33
|
+
// Bounds the number of scope syncs running concurrently. Scopes beyond this limit queue here. Sized to trade off
|
|
34
|
+
// parallelism on non-ACIR work (node RPC, note store reads) against memory pressure from concurrent circuit
|
|
35
|
+
// execution.
|
|
36
|
+
#syncSlot = new Semaphore(MAX_CONCURRENT_SCOPE_SYNCS);
|
|
29
37
|
|
|
30
38
|
constructor(
|
|
31
39
|
private aztecNode: AztecNode,
|
|
@@ -35,8 +43,8 @@ export class ContractSyncService implements StagedStore {
|
|
|
35
43
|
) {}
|
|
36
44
|
|
|
37
45
|
/** Sets contracts that should be skipped during sync for a specific job. */
|
|
38
|
-
|
|
39
|
-
this.
|
|
46
|
+
setExcludedFromSync(jobId: string, addresses: Set<string>): void {
|
|
47
|
+
this.excludedFromSync.set(jobId, addresses);
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
/**
|
|
@@ -51,75 +59,42 @@ export class ContractSyncService implements StagedStore {
|
|
|
51
59
|
async ensureContractSynced(
|
|
52
60
|
contractAddress: AztecAddress,
|
|
53
61
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
54
|
-
utilityExecutor: (call: FunctionCall, scopes:
|
|
62
|
+
utilityExecutor: (call: FunctionCall, scopes: AztecAddress[]) => Promise<any>,
|
|
55
63
|
anchorBlockHeader: BlockHeader,
|
|
56
64
|
jobId: string,
|
|
57
|
-
scopes:
|
|
65
|
+
scopes: AztecAddress[],
|
|
58
66
|
): Promise<void> {
|
|
59
|
-
|
|
60
|
-
const overrides = this.overriddenContracts.get(jobId);
|
|
61
|
-
if (overrides?.has(contractAddress.toString())) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Skip sync if we already synced for "all scopes", or if we have an empty list of scopes
|
|
66
|
-
const allScopesKey = toKey(contractAddress, 'ALL_SCOPES');
|
|
67
|
-
const allScopesExisting = this.syncedContracts.get(allScopesKey);
|
|
68
|
-
if (allScopesExisting || (scopes !== 'ALL_SCOPES' && scopes.length == 0)) {
|
|
67
|
+
if (this.#shouldSkipSync(jobId, contractAddress)) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
unsyncedScopesKeys.forEach(key => this.syncedContracts.set(key, promise));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const promises = toKeys(contractAddress, scopes).map(key => this.syncedContracts.get(key)!);
|
|
96
|
-
await Promise.all(promises);
|
|
71
|
+
this.#startSyncIfNeeded(
|
|
72
|
+
contractAddress,
|
|
73
|
+
scopes,
|
|
74
|
+
() => verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
|
|
75
|
+
scope =>
|
|
76
|
+
syncState(
|
|
77
|
+
contractAddress,
|
|
78
|
+
this.contractStore,
|
|
79
|
+
functionToInvokeAfterSync,
|
|
80
|
+
utilityExecutor,
|
|
81
|
+
this.noteStore,
|
|
82
|
+
this.aztecNode,
|
|
83
|
+
anchorBlockHeader,
|
|
84
|
+
jobId,
|
|
85
|
+
scope,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
await this.#awaitSync(contractAddress, scopes);
|
|
97
90
|
}
|
|
98
91
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
scopes: AccessScopes,
|
|
106
|
-
): Promise<void> {
|
|
107
|
-
this.log.debug(`Syncing contract ${contractAddress}`);
|
|
108
|
-
await Promise.all([
|
|
109
|
-
syncState(
|
|
110
|
-
contractAddress,
|
|
111
|
-
this.contractStore,
|
|
112
|
-
functionToInvokeAfterSync,
|
|
113
|
-
utilityExecutor,
|
|
114
|
-
this.noteStore,
|
|
115
|
-
this.aztecNode,
|
|
116
|
-
anchorBlockHeader,
|
|
117
|
-
jobId,
|
|
118
|
-
scopes,
|
|
119
|
-
),
|
|
120
|
-
verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
|
|
121
|
-
]);
|
|
122
|
-
this.log.debug(`Contract ${contractAddress} synced`);
|
|
92
|
+
/** Clears sync cache entries for the given scopes of a contract. */
|
|
93
|
+
invalidateContractForScopes(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
|
|
94
|
+
if (scopes.length === 0) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
scopes.forEach(scope => this.syncedContracts.delete(toKey(contractAddress, scope)));
|
|
123
98
|
}
|
|
124
99
|
|
|
125
100
|
/** Clears sync cache. Called by BlockSynchronizer when anchor block changes. */
|
|
@@ -129,8 +104,8 @@ export class ContractSyncService implements StagedStore {
|
|
|
129
104
|
}
|
|
130
105
|
|
|
131
106
|
commit(jobId: string): Promise<void> {
|
|
132
|
-
// Clear
|
|
133
|
-
this.
|
|
107
|
+
// Clear excluded contracts for this job
|
|
108
|
+
this.excludedFromSync.delete(jobId);
|
|
134
109
|
return Promise.resolve();
|
|
135
110
|
}
|
|
136
111
|
|
|
@@ -138,15 +113,64 @@ export class ContractSyncService implements StagedStore {
|
|
|
138
113
|
// We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
|
|
139
114
|
// the sync are also undone.
|
|
140
115
|
this.syncedContracts.clear();
|
|
141
|
-
this.
|
|
116
|
+
this.excludedFromSync.delete(jobId);
|
|
142
117
|
return Promise.resolve();
|
|
143
118
|
}
|
|
144
|
-
|
|
119
|
+
/** Returns true if sync should be skipped for this contract */
|
|
120
|
+
#shouldSkipSync(jobId: string, contractAddress: AztecAddress): boolean {
|
|
121
|
+
return !!this.excludedFromSync.get(jobId)?.has(contractAddress.toString());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* If there are unsynced scopes, starts one sync per scope (bounded by #syncSlot) and stores each promise in the
|
|
126
|
+
* cache with per-scope error cleanup. The verifyFn runs once for the whole fan-out and is awaited by every new
|
|
127
|
+
* scope's promise, matching the pre-parallelization invariant that a cache-miss batch re-verifies the class id.
|
|
128
|
+
*/
|
|
129
|
+
#startSyncIfNeeded(
|
|
130
|
+
contractAddress: AztecAddress,
|
|
131
|
+
scopes: AztecAddress[],
|
|
132
|
+
verifyFn: () => Promise<void>,
|
|
133
|
+
syncScopeFn: (scope: AztecAddress) => Promise<void>,
|
|
134
|
+
): void {
|
|
135
|
+
const scopesToSync = scopes.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
136
|
+
if (scopesToSync.length === 0) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
145
139
|
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
this.log.debug(`Syncing contract ${contractAddress} for ${scopesToSync.length} scope(s)`);
|
|
141
|
+
const verifyPromise = verifyFn();
|
|
142
|
+
|
|
143
|
+
for (const scope of scopesToSync) {
|
|
144
|
+
const key = toKey(contractAddress, scope);
|
|
145
|
+
const promise = Promise.all([verifyPromise, this.#runBounded(() => syncScopeFn(scope))])
|
|
146
|
+
.then(() => {})
|
|
147
|
+
.catch(err => {
|
|
148
|
+
this.syncedContracts.delete(key);
|
|
149
|
+
throw err;
|
|
150
|
+
});
|
|
151
|
+
this.syncedContracts.set(key, promise);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Runs fn while holding a slot in #syncSlot, bounding total concurrent scope syncs. */
|
|
156
|
+
async #runBounded<T>(fn: () => Promise<T>): Promise<T> {
|
|
157
|
+
await this.#syncSlot.acquire();
|
|
158
|
+
try {
|
|
159
|
+
return await fn();
|
|
160
|
+
} finally {
|
|
161
|
+
this.#syncSlot.release();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Collects all relevant scope promises (including in-flight ones from concurrent calls) and awaits them. */
|
|
166
|
+
async #awaitSync(contractAddress: AztecAddress, scopes: AztecAddress[]): Promise<void> {
|
|
167
|
+
const promises = scopes
|
|
168
|
+
.map(scope => this.syncedContracts.get(toKey(contractAddress, scope)))
|
|
169
|
+
.filter(p => p !== undefined);
|
|
170
|
+
await Promise.all(promises);
|
|
171
|
+
}
|
|
148
172
|
}
|
|
149
173
|
|
|
150
|
-
function toKey(contract: AztecAddress, scope: AztecAddress
|
|
151
|
-
return
|
|
174
|
+
function toKey(contract: AztecAddress, scope: AztecAddress) {
|
|
175
|
+
return `${contract.toString()}:${scope.toString()}`;
|
|
152
176
|
}
|
|
@@ -6,7 +6,6 @@ import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '
|
|
|
6
6
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
7
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
8
8
|
|
|
9
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
10
9
|
import { NoteService } from '../notes/note_service.js';
|
|
11
10
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
12
11
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
@@ -43,16 +42,16 @@ export async function syncState(
|
|
|
43
42
|
contractAddress: AztecAddress,
|
|
44
43
|
contractStore: ContractStore,
|
|
45
44
|
functionToInvokeAfterSync: FunctionSelector | null,
|
|
46
|
-
utilityExecutor: (privateSyncCall: FunctionCall, scopes:
|
|
45
|
+
utilityExecutor: (privateSyncCall: FunctionCall, scopes: AztecAddress[]) => Promise<any>,
|
|
47
46
|
noteStore: NoteStore,
|
|
48
47
|
aztecNode: AztecNode,
|
|
49
48
|
anchorBlockHeader: BlockHeader,
|
|
50
49
|
jobId: string,
|
|
51
|
-
|
|
50
|
+
scope: AztecAddress,
|
|
52
51
|
) {
|
|
53
52
|
// Protocol contracts don't have private state to sync
|
|
54
53
|
if (!isProtocolContract(contractAddress)) {
|
|
55
|
-
const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [], contractAddress);
|
|
54
|
+
const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [scope], contractAddress);
|
|
56
55
|
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
|
|
57
56
|
throw new Error(
|
|
58
57
|
'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
@@ -60,6 +59,7 @@ export async function syncState(
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
const noteService = new NoteService(noteStore, aztecNode, anchorBlockHeader, jobId);
|
|
62
|
+
const scopes: AztecAddress[] = [scope];
|
|
63
63
|
|
|
64
64
|
// Both sync_state and syncNoteNullifiers interact with the note store, but running them in parallel is safe
|
|
65
65
|
// because note store is designed to handle concurrent operations.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
4
|
import type { NoteDao } from '@aztec/stdlib/note';
|
|
4
5
|
import type { ContractOverrides } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
7
7
|
import type { BlockSynchronizer } from '../block_synchronizer/block_synchronizer.js';
|
|
8
8
|
import type { ContractFunctionSimulator } from '../contract_function_simulator/contract_function_simulator.js';
|
|
9
9
|
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
|
|
@@ -22,7 +22,7 @@ export class PXEDebugUtils {
|
|
|
22
22
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
23
23
|
call: FunctionCall,
|
|
24
24
|
authWitnesses: AuthWitness[] | undefined,
|
|
25
|
-
scopes:
|
|
25
|
+
scopes: AztecAddress[],
|
|
26
26
|
jobId: string,
|
|
27
27
|
) => Promise<any>;
|
|
28
28
|
|
|
@@ -41,7 +41,7 @@ export class PXEDebugUtils {
|
|
|
41
41
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
42
42
|
call: FunctionCall,
|
|
43
43
|
authWitnesses: AuthWitness[] | undefined,
|
|
44
|
-
scopes:
|
|
44
|
+
scopes: AztecAddress[],
|
|
45
45
|
jobId: string,
|
|
46
46
|
) => Promise<any>,
|
|
47
47
|
) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BBPrivateKernelProver } from '@aztec/bb-prover/client';
|
|
2
1
|
import { BBBundlePrivateKernelProver } from '@aztec/bb-prover/client/bundle';
|
|
3
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
3
|
import { createStore } from '@aztec/kv-store/indexeddb';
|
|
@@ -9,7 +8,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
9
8
|
import type { PXEConfig } from '../../../config/index.js';
|
|
10
9
|
import { PXE } from '../../../pxe.js';
|
|
11
10
|
import { PXE_DATA_SCHEMA_VERSION } from '../../../storage/metadata.js';
|
|
12
|
-
import type
|
|
11
|
+
import { type PXECreationOptions, isPrivateKernelProver } from '../../pxe_creation_options.js';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Create and start an PXE instance with the given AztecNode.
|
|
@@ -44,7 +43,7 @@ export async function createPXE(
|
|
|
44
43
|
const proverLogger = loggers.prover ?? createLogger('pxe:bb:wasm:bundle', { actor });
|
|
45
44
|
|
|
46
45
|
let prover;
|
|
47
|
-
if (options.proverOrOptions
|
|
46
|
+
if (isPrivateKernelProver(options.proverOrOptions)) {
|
|
48
47
|
prover = options.proverOrOptions;
|
|
49
48
|
} else {
|
|
50
49
|
prover = new BBBundlePrivateKernelProver(simulator, { ...options.proverOrOptions, logger: proverLogger });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BBPrivateKernelProver } from '@aztec/bb-prover/client';
|
|
2
1
|
import { BBLazyPrivateKernelProver } from '@aztec/bb-prover/client/lazy';
|
|
3
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
3
|
import { createStore } from '@aztec/kv-store/indexeddb';
|
|
@@ -9,7 +8,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
9
8
|
import type { PXEConfig } from '../../../config/index.js';
|
|
10
9
|
import { PXE } from '../../../pxe.js';
|
|
11
10
|
import { PXE_DATA_SCHEMA_VERSION } from '../../../storage/metadata.js';
|
|
12
|
-
import type
|
|
11
|
+
import { type PXECreationOptions, isPrivateKernelProver } from '../../pxe_creation_options.js';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Create and start an PXE instance with the given AztecNode.
|
|
@@ -44,7 +43,7 @@ export async function createPXE(
|
|
|
44
43
|
const proverLogger = loggers.prover ?? createLogger('pxe:bb:wasm:bundle', { actor });
|
|
45
44
|
|
|
46
45
|
let prover;
|
|
47
|
-
if (options.proverOrOptions
|
|
46
|
+
if (isPrivateKernelProver(options.proverOrOptions)) {
|
|
48
47
|
prover = options.proverOrOptions;
|
|
49
48
|
} else {
|
|
50
49
|
prover = new BBLazyPrivateKernelProver(simulator, { ...options.proverOrOptions, logger: proverLogger });
|
|
@@ -12,3 +12,10 @@ export type PXECreationOptions = {
|
|
|
12
12
|
store?: AztecAsyncKVStore;
|
|
13
13
|
simulator?: CircuitSimulator;
|
|
14
14
|
};
|
|
15
|
+
|
|
16
|
+
/** Checks if the given value implements the PrivateKernelProver interface via duck-typing. */
|
|
17
|
+
export function isPrivateKernelProver(value: unknown): value is PrivateKernelProver {
|
|
18
|
+
return (
|
|
19
|
+
typeof value === 'object' && value !== null && typeof (value as PrivateKernelProver).createChonkProof === 'function'
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from '../../access_scopes.js';
|
|
2
1
|
export * from '../../notes_filter.js';
|
|
3
2
|
export * from '../../pxe.js';
|
|
4
3
|
export * from '../../config/index.js';
|
|
@@ -6,7 +5,7 @@ export * from '../../error_enriching.js';
|
|
|
6
5
|
export * from '../../storage/index.js';
|
|
7
6
|
export * from './utils.js';
|
|
8
7
|
export { NoteService } from '../../notes/note_service.js';
|
|
9
|
-
export {
|
|
8
|
+
export { ORACLE_VERSION_MAJOR, ORACLE_VERSION_MINOR } from '../../oracle_version.js';
|
|
10
9
|
export { type PXECreationOptions } from '../pxe_creation_options.js';
|
|
11
10
|
export { JobCoordinator } from '../../job_coordinator/job_coordinator.js';
|
|
12
11
|
export { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BBPrivateKernelProver } from '@aztec/bb-prover/client';
|
|
2
1
|
import { BBBundlePrivateKernelProver } from '@aztec/bb-prover/client/bundle';
|
|
3
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
3
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
@@ -10,7 +9,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
10
9
|
import type { PXEConfig } from '../../config/index.js';
|
|
11
10
|
import { PXE } from '../../pxe.js';
|
|
12
11
|
import { PXE_DATA_SCHEMA_VERSION } from '../../storage/index.js';
|
|
13
|
-
import type
|
|
12
|
+
import { type PXECreationOptions, isPrivateKernelProver } from '../pxe_creation_options.js';
|
|
14
13
|
|
|
15
14
|
type PXEConfigWithoutDefaults = Omit<PXEConfig, 'l1Contracts' | 'l1ChainId' | 'l2BlockBatchSize' | 'rollupVersion'>;
|
|
16
15
|
|
|
@@ -49,7 +48,7 @@ export async function createPXE(
|
|
|
49
48
|
const proverLogger = loggers.prover ?? createLogger('pxe:bb:native', { actor });
|
|
50
49
|
|
|
51
50
|
let prover;
|
|
52
|
-
if (options.proverOrOptions
|
|
51
|
+
if (isPrivateKernelProver(options.proverOrOptions)) {
|
|
53
52
|
prover = options.proverOrOptions;
|
|
54
53
|
} else {
|
|
55
54
|
prover = new BBBundlePrivateKernelProver(simulator, { ...options.proverOrOptions, logger: proverLogger });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import type { EventSelector } from '@aztec/stdlib/abi';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
@@ -13,6 +14,7 @@ export class EventService {
|
|
|
13
14
|
private readonly aztecNode: AztecNode,
|
|
14
15
|
private readonly privateEventStore: PrivateEventStore,
|
|
15
16
|
private readonly jobId: string,
|
|
17
|
+
private readonly log = createLogger('pxe:event_service'),
|
|
16
18
|
) {}
|
|
17
19
|
|
|
18
20
|
public async validateAndStoreEvent(
|
|
@@ -36,19 +38,30 @@ export class EventService {
|
|
|
36
38
|
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
37
39
|
|
|
38
40
|
if (!txEffect) {
|
|
39
|
-
|
|
41
|
+
// We error out instead of just logging a warning and skipping the event because this would indicate a bug. This
|
|
42
|
+
// is because the node has already served info about this tx either when obtaining the log (TxScopedL2Log contain
|
|
43
|
+
// tx info) or when getting metadata for the offchain message (before the message got passed to `process_log`).
|
|
44
|
+
throw new Error(`Could not find tx effect for tx hash ${txHash} when processing an event.`);
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
if (txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
43
|
-
|
|
48
|
+
// We should never process a message from a tx past the anchor block. If we got here, a preprocessing step made
|
|
49
|
+
// a mistake.
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Obtained a newer tx effect for ${txHash} for an event validation request than the anchor block ${anchorBlockNumber}. This is a bug as smart contracts should not issue event validation requests for events from blocks newer than the anchor block.`,
|
|
52
|
+
);
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
// Find the index of the event commitment in the nullifiers array to determine event ordering within the tx
|
|
47
56
|
const eventIndexInTx = txEffect.data.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
|
|
48
57
|
if (eventIndexInTx === -1) {
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
// Unlike in NoteService, this might not be a bug since the commitment hasn't been verified yet in the message
|
|
59
|
+
// processing pipeline. A malformed or malicious message could trigger this condition. Because of this we don't
|
|
60
|
+
// error out and we just show a warning.
|
|
61
|
+
this.log.warn(
|
|
62
|
+
`Skipping event whose commitment is not present in its tx. siloedEventCommitment=${siloedEventCommitment}, contract=${contractAddress}, selector=${selector}, eventCommitment=${eventCommitment}, txHash=${txHash}`,
|
|
51
63
|
);
|
|
64
|
+
return;
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
return this.privateEventStore.storePrivateEventLog(
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
2
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
3
3
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
|
|
5
6
|
import type { PrivateEventStoreFilter } from '../storage/private_event_store/private_event_store.js';
|
|
6
7
|
|
|
7
8
|
export class PrivateEventFilterValidator {
|
|
8
|
-
|
|
9
|
+
private readonly log = createLogger('pxe:private_event_filter_validator');
|
|
10
|
+
|
|
11
|
+
constructor(private readonly lastBlock: BlockNumber) {}
|
|
9
12
|
|
|
10
13
|
validate(filter: PrivateEventFilter): PrivateEventStoreFilter {
|
|
11
14
|
let { fromBlock, toBlock } = filter;
|
|
@@ -35,6 +38,23 @@ export class PrivateEventFilterValidator {
|
|
|
35
38
|
throw new Error('toBlock must be strictly greater than fromBlock');
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
// Cap the requested range to the synced block range. Without this, callers that pass a large
|
|
42
|
+
// toBlock (e.g. Number.MAX_SAFE_INTEGER as a "give me everything" idiom) would silently receive
|
|
43
|
+
// only the events that happen to be synced and believe they have complete coverage.
|
|
44
|
+
// We warn + cap rather than throw so callers don't need to query the last synced block before
|
|
45
|
+
// every request (which would also be unreliable, as the block can advance between the two calls).
|
|
46
|
+
const syncedUpperBound = BlockNumber(this.lastBlock + 1);
|
|
47
|
+
if (fromBlock >= syncedUpperBound) {
|
|
48
|
+
this.log.warn(
|
|
49
|
+
`Requested fromBlock ${fromBlock} is past last synced block ${this.lastBlock}; no events will be returned until PXE syncs further.`,
|
|
50
|
+
);
|
|
51
|
+
} else if (toBlock > syncedUpperBound) {
|
|
52
|
+
this.log.warn(
|
|
53
|
+
`Requested toBlock ${toBlock} exceeds last synced block ${this.lastBlock}; capping to ${syncedUpperBound}. Retry once PXE is further synced for complete coverage.`,
|
|
54
|
+
);
|
|
55
|
+
toBlock = syncedUpperBound;
|
|
56
|
+
}
|
|
57
|
+
|
|
38
58
|
return {
|
|
39
59
|
contractAddress: filter.contractAddress,
|
|
40
60
|
scopes: filter.scopes,
|