@aztec/pxe 0.0.1-commit.321f6a9 → 0.0.1-commit.330febf
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 +2 -38
- package/dest/bin/index.d.ts +2 -2
- package/dest/bin/index.d.ts.map +1 -1
- package/dest/bin/index.js +1 -1
- package/dest/bin/oracle_version_helpers.d.ts +1 -15
- package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
- package/dest/bin/oracle_version_helpers.js +0 -21
- package/dest/block_synchronizer/block_synchronizer.d.ts +3 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +5 -18
- package/dest/contract/contract_class_service.d.ts +1 -8
- package/dest/contract/contract_class_service.d.ts.map +1 -1
- package/dest/contract/contract_class_service.js +8 -40
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -8
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +0 -17
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +11 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +6 -2
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +10 -2
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +128 -38
- package/dest/events/event_service.d.ts +13 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +13 -13
- package/dest/logs/log_service.d.ts +13 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +20 -36
- package/dest/messages/tx_resolver_service.d.ts +18 -7
- package/dest/messages/tx_resolver_service.d.ts.map +1 -1
- package/dest/messages/tx_resolver_service.js +9 -8
- package/dest/node/benchmarked_node.d.ts +20 -0
- package/dest/node/benchmarked_node.d.ts.map +1 -0
- package/dest/node/benchmarked_node.js +94 -0
- package/dest/node/caching_aztec_node.d.ts +24 -0
- package/dest/node/caching_aztec_node.d.ts.map +1 -0
- package/dest/node/caching_aztec_node.js +267 -0
- package/dest/notes/note_service.d.ts +12 -6
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +9 -9
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +31 -14
- 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 +2 -2
- package/dest/storage/fact_store/origin_state.d.ts +1 -1
- package/dest/storage/fact_store/origin_state.js +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +23 -8
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +33 -18
- package/dest/tagging/constants.d.ts +9 -1
- package/dest/tagging/constants.d.ts.map +1 -1
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +29 -8
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +29 -10
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +2 -2
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +13 -17
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +6 -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 +23 -38
- package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
- package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/classify_pending_txs.js +61 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +15 -5
- 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 +30 -33
- package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
- package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +41 -0
- package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
- package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
- package/package.json +17 -17
- package/src/bin/check_oracle_version.ts +2 -46
- package/src/bin/index.ts +1 -1
- package/src/bin/oracle_version_helpers.ts +0 -24
- package/src/block_synchronizer/block_synchronizer.ts +6 -23
- package/src/contract/contract_class_service.ts +8 -46
- package/src/contract_function_simulator/contract_function_simulator.ts +0 -17
- package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +16 -1
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +7 -2
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +130 -40
- package/src/events/event_service.ts +24 -14
- package/src/logs/log_service.ts +37 -44
- package/src/messages/tx_resolver_service.ts +22 -11
- package/src/node/benchmarked_node.ts +140 -0
- package/src/node/caching_aztec_node.ts +406 -0
- package/src/notes/note_service.ts +19 -13
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +32 -16
- package/src/storage/contract_store/contract_store.ts +2 -1
- package/src/storage/fact_store/origin_state.ts +1 -1
- package/src/storage/tagging_store/sender_tagging_store.ts +51 -26
- package/src/tagging/constants.ts +12 -0
- package/src/tagging/get_all_logs_by_tags.ts +47 -11
- package/src/tagging/index.ts +6 -1
- package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +19 -22
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +27 -57
- package/src/tagging/sender_sync/utils/classify_pending_txs.ts +91 -0
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +40 -38
- package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +64 -0
- package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +0 -39
- package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +0 -1
- package/dest/contract_function_simulator/aztec_node_read_cache.js +0 -60
- package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/benchmarked_node.js +0 -77
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -17
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -60
- package/src/contract_function_simulator/aztec_node_read_cache.ts +0 -89
- package/src/contract_function_simulator/benchmarked_node.ts +0 -103
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +0 -66
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
2
|
-
export class BenchmarkedNodeFactory {
|
|
3
|
-
static create(node) {
|
|
4
|
-
// Per-method call stats
|
|
5
|
-
const perMethod = {};
|
|
6
|
-
// Round trip tracking
|
|
7
|
-
let inFlightCount = 0;
|
|
8
|
-
let currentRoundTripTimer = null;
|
|
9
|
-
let currentRoundTripMethods = [];
|
|
10
|
-
const roundTrips = {
|
|
11
|
-
roundTrips: 0,
|
|
12
|
-
totalBlockingTime: 0,
|
|
13
|
-
roundTripDurations: [],
|
|
14
|
-
roundTripMethods: []
|
|
15
|
-
};
|
|
16
|
-
return new Proxy(node, {
|
|
17
|
-
get (target, prop) {
|
|
18
|
-
if (prop === 'getStats') {
|
|
19
|
-
return ()=>{
|
|
20
|
-
return {
|
|
21
|
-
perMethod,
|
|
22
|
-
roundTrips
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
} else {
|
|
26
|
-
return function(...args) {
|
|
27
|
-
// Track per-method stats
|
|
28
|
-
if (!perMethod[prop]) {
|
|
29
|
-
perMethod[prop] = {
|
|
30
|
-
times: []
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
// Start of a new round trip batch?
|
|
34
|
-
if (inFlightCount === 0) {
|
|
35
|
-
roundTrips.roundTrips++;
|
|
36
|
-
currentRoundTripTimer = new Timer();
|
|
37
|
-
currentRoundTripMethods = [];
|
|
38
|
-
}
|
|
39
|
-
inFlightCount++;
|
|
40
|
-
currentRoundTripMethods.push(prop);
|
|
41
|
-
const callTimer = new Timer();
|
|
42
|
-
const result = target[prop].apply(target, args);
|
|
43
|
-
// Handle completion - called when the call finishes (after Promise resolves)
|
|
44
|
-
const handleCompletion = ()=>{
|
|
45
|
-
const callTime = callTimer.ms();
|
|
46
|
-
perMethod[prop].times.push(callTime);
|
|
47
|
-
inFlightCount--;
|
|
48
|
-
// End of round trip batch - all concurrent calls completed
|
|
49
|
-
if (inFlightCount === 0 && currentRoundTripTimer) {
|
|
50
|
-
const roundTripTime = currentRoundTripTimer.ms();
|
|
51
|
-
roundTrips.totalBlockingTime += roundTripTime;
|
|
52
|
-
roundTrips.roundTripDurations.push(roundTripTime);
|
|
53
|
-
roundTrips.roundTripMethods.push(currentRoundTripMethods);
|
|
54
|
-
currentRoundTripTimer = null;
|
|
55
|
-
currentRoundTripMethods = [];
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
// If the result is a Promise, chain the completion handler
|
|
59
|
-
if (result && typeof result.then === 'function') {
|
|
60
|
-
return result.then((value)=>{
|
|
61
|
-
handleCompletion();
|
|
62
|
-
return value;
|
|
63
|
-
}, (error)=>{
|
|
64
|
-
handleCompletion();
|
|
65
|
-
throw error;
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
// Synchronous method - handle completion immediately
|
|
69
|
-
handleCompletion();
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
-
/** Classification of a batch of pending tx hashes by the status change implied by their receipts. */
|
|
4
|
-
export type StatusChange = {
|
|
5
|
-
txHashesToFinalize: TxHash[];
|
|
6
|
-
txHashesToDrop: TxHash[];
|
|
7
|
-
txHashesWithExecutionReverted: TxHash[];
|
|
8
|
-
};
|
|
9
|
-
export declare const EMPTY_STATUS_CHANGE: StatusChange;
|
|
10
|
-
/** Concatenates two status changes field-by-field. */
|
|
11
|
-
export declare function mergeStatusChanges(a: StatusChange, b: StatusChange): StatusChange;
|
|
12
|
-
/**
|
|
13
|
-
* Based on receipts obtained from `aztecNode` returns which pending transactions changed their status to finalized,
|
|
14
|
-
* dropped, or execution-reverted (but mined).
|
|
15
|
-
*/
|
|
16
|
-
export declare function getStatusChangeOfPending(pending: TxHash[], aztecNode: AztecNode): Promise<StatusChange>;
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X3N0YXR1c19jaGFuZ2Vfb2ZfcGVuZGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvZ2V0X3N0YXR1c19jaGFuZ2Vfb2ZfcGVuZGluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEVBQUUsTUFBTSxFQUFZLE1BQU0sa0JBQWtCLENBQUM7QUFFcEQscUdBQXFHO0FBQ3JHLE1BQU0sTUFBTSxZQUFZLEdBQUc7SUFDekIsa0JBQWtCLEVBQUUsTUFBTSxFQUFFLENBQUM7SUFDN0IsY0FBYyxFQUFFLE1BQU0sRUFBRSxDQUFDO0lBQ3pCLDZCQUE2QixFQUFFLE1BQU0sRUFBRSxDQUFDO0NBQ3pDLENBQUM7QUFFRixlQUFPLE1BQU0sbUJBQW1CLEVBQUUsWUFJakMsQ0FBQztBQUVGLHNEQUFzRDtBQUN0RCx3QkFBZ0Isa0JBQWtCLENBQUMsQ0FBQyxFQUFFLFlBQVksRUFBRSxDQUFDLEVBQUUsWUFBWSxHQUFHLFlBQVksQ0FNakY7QUFFRDs7O0dBR0c7QUFDSCx3QkFBc0Isd0JBQXdCLENBQUMsT0FBTyxFQUFFLE1BQU0sRUFBRSxFQUFFLFNBQVMsRUFBRSxTQUFTLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQW9DN0cifQ==
|
|
@@ -1 +0,0 @@
|
|
|
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,qGAAqG;AACrG,MAAM,MAAM,YAAY,GAAG;IACzB,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,6BAA6B,EAAE,MAAM,EAAE,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC;AAEF,sDAAsD;AACtD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY,CAMjF;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAoC7G"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { TxStatus } from '@aztec/stdlib/tx';
|
|
2
|
-
export const EMPTY_STATUS_CHANGE = {
|
|
3
|
-
txHashesToFinalize: [],
|
|
4
|
-
txHashesToDrop: [],
|
|
5
|
-
txHashesWithExecutionReverted: []
|
|
6
|
-
};
|
|
7
|
-
/** Concatenates two status changes field-by-field. */ export function mergeStatusChanges(a, b) {
|
|
8
|
-
return {
|
|
9
|
-
txHashesToFinalize: [
|
|
10
|
-
...a.txHashesToFinalize,
|
|
11
|
-
...b.txHashesToFinalize
|
|
12
|
-
],
|
|
13
|
-
txHashesToDrop: [
|
|
14
|
-
...a.txHashesToDrop,
|
|
15
|
-
...b.txHashesToDrop
|
|
16
|
-
],
|
|
17
|
-
txHashesWithExecutionReverted: [
|
|
18
|
-
...a.txHashesWithExecutionReverted,
|
|
19
|
-
...b.txHashesWithExecutionReverted
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Based on receipts obtained from `aztecNode` returns which pending transactions changed their status to finalized,
|
|
25
|
-
* dropped, or execution-reverted (but mined).
|
|
26
|
-
*/ export async function getStatusChangeOfPending(pending, aztecNode) {
|
|
27
|
-
// Get receipts for all pending tx hashes.
|
|
28
|
-
const receipts = await Promise.all(pending.map((pendingTxHash)=>aztecNode.getTxReceipt(pendingTxHash)));
|
|
29
|
-
const txHashesToFinalize = [];
|
|
30
|
-
const txHashesToDrop = [];
|
|
31
|
-
const txHashesWithExecutionReverted = [];
|
|
32
|
-
for(let i = 0; i < receipts.length; i++){
|
|
33
|
-
const receipt = receipts[i];
|
|
34
|
-
const txHash = pending[i];
|
|
35
|
-
if (receipt.status === TxStatus.FINALIZED) {
|
|
36
|
-
// Tx has been included in a block and the corresponding block is finalized
|
|
37
|
-
if (receipt.hasExecutionSucceeded()) {
|
|
38
|
-
// No part of execution reverted - we just finalize all the indexes.
|
|
39
|
-
txHashesToFinalize.push(txHash);
|
|
40
|
-
} else if (receipt.hasExecutionReverted()) {
|
|
41
|
-
// Tx was mined but execution reverted (app logic, teardown, or both). Some logs from the non-revertible
|
|
42
|
-
// phase may still be onchain. We check which tags made it onchain and finalize those; drop the rest.
|
|
43
|
-
txHashesWithExecutionReverted.push(txHash);
|
|
44
|
-
} else {
|
|
45
|
-
// Defensive check - this branch should never be triggered
|
|
46
|
-
throw new Error('Both hasExecutionSucceeded and hasExecutionReverted on the receipt returned false. This should never happen and it implies a bug. Please open an issue.');
|
|
47
|
-
}
|
|
48
|
-
} else if (receipt.isDropped()) {
|
|
49
|
-
// Tx was dropped from the mempool --> we drop the corresponding pending indexes.
|
|
50
|
-
txHashesToDrop.push(txHash);
|
|
51
|
-
} else {
|
|
52
|
-
// Tx is still pending, not yet finalized, or was mined successfully but not yet finalized --> we don't do anything.
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
txHashesToFinalize,
|
|
57
|
-
txHashesToDrop,
|
|
58
|
-
txHashesWithExecutionReverted
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import type { BlockHash, BlockParameter } from '@aztec/stdlib/block';
|
|
4
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
5
|
-
import type { TxHash } from '@aztec/stdlib/tx';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Per-execution cache for immutable Aztec node reads.
|
|
9
|
-
*/
|
|
10
|
-
export class AztecNodeReadCache {
|
|
11
|
-
private readonly cache = new Map<string, Promise<unknown>>();
|
|
12
|
-
|
|
13
|
-
constructor(private readonly aztecNode: AztecNode) {}
|
|
14
|
-
|
|
15
|
-
/** Fetches a block without reissuing the same node request. */
|
|
16
|
-
public getBlock(block: BlockParameter) {
|
|
17
|
-
return this.#cachedRead(`block:${this.#keyPart(block)}`, () => this.aztecNode.getBlock(block));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Fetches a transaction receipt with its effect attached. */
|
|
21
|
-
public getTxReceiptWithEffect(txHash: TxHash) {
|
|
22
|
-
return this.#cachedRead(`tx-receipt-with-effect:${txHash.toString()}`, () =>
|
|
23
|
-
this.aztecNode.getTxReceipt(txHash, { includeTxEffect: true } as const),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Fetches an archive-tree witness for a block hash. */
|
|
28
|
-
public getBlockHashMembershipWitness(referenceBlock: BlockParameter, blockHash: BlockHash) {
|
|
29
|
-
return this.#cachedRead(
|
|
30
|
-
`block-hash-membership-witness:${this.#keyPart(referenceBlock)}:${blockHash.toString()}`,
|
|
31
|
-
() => this.aztecNode.getBlockHashMembershipWitness(referenceBlock, blockHash),
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Fetches a public-data-tree witness for a leaf slot. */
|
|
36
|
-
public getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr) {
|
|
37
|
-
return this.#cachedRead(`public-data-witness:${this.#keyPart(referenceBlock)}:${leafSlot.toString()}`, () =>
|
|
38
|
-
this.aztecNode.getPublicDataWitness(referenceBlock, leafSlot),
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Fetches public storage for a single slot. */
|
|
43
|
-
public getPublicStorageAt(referenceBlock: BlockParameter, contractAddress: AztecAddress, storageSlot: Fr) {
|
|
44
|
-
return this.#cachedRead(
|
|
45
|
-
`public-storage:${this.#keyPart(referenceBlock)}:${contractAddress.toString()}:${storageSlot.toString()}`,
|
|
46
|
-
() => this.aztecNode.getPublicStorageAt(referenceBlock, contractAddress, storageSlot),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Fetches a contiguous public storage range, reusing cached reads for overlapping slots. */
|
|
51
|
-
public getPublicStorageRange(
|
|
52
|
-
referenceBlock: BlockParameter,
|
|
53
|
-
contractAddress: AztecAddress,
|
|
54
|
-
startStorageSlot: Fr,
|
|
55
|
-
numberOfElements: number,
|
|
56
|
-
) {
|
|
57
|
-
const slots = Array(numberOfElements)
|
|
58
|
-
.fill(0)
|
|
59
|
-
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
|
|
60
|
-
|
|
61
|
-
return Promise.all(slots.map(storageSlot => this.getPublicStorageAt(referenceBlock, contractAddress, storageSlot)));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
#cachedRead<T>(key: string, fetch: () => Promise<T>): Promise<T> {
|
|
65
|
-
const cached = this.cache.get(key);
|
|
66
|
-
if (cached) {
|
|
67
|
-
return cached as Promise<T>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const promise = fetch();
|
|
71
|
-
promise.catch(() => this.cache.delete(key));
|
|
72
|
-
this.cache.set(key, promise);
|
|
73
|
-
return promise;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
#keyPart(value: unknown): string {
|
|
77
|
-
if (['string', 'number', 'bigint', 'boolean'].includes(typeof value)) {
|
|
78
|
-
return String(value);
|
|
79
|
-
}
|
|
80
|
-
if (value && typeof value === 'object') {
|
|
81
|
-
const toString = (value as { toString?: () => string }).toString;
|
|
82
|
-
if (toString && toString !== Object.prototype.toString) {
|
|
83
|
-
return toString.call(value);
|
|
84
|
-
}
|
|
85
|
-
return JSON.stringify(value, (_key, nested) => (typeof nested === 'bigint' ? nested.toString() : nested));
|
|
86
|
-
}
|
|
87
|
-
return String(value);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
2
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
3
|
-
import type { NodeStats, RoundTripStats } from '@aztec/stdlib/tx';
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Proxy generator for an AztecNode that tracks the time taken for each RPC call and the number of round trips (actual
|
|
7
|
-
* blocking waits for node responses).
|
|
8
|
-
*
|
|
9
|
-
* A round trip is counted when we transition from 0 to 1 in-flight calls, and ends when all concurrent calls complete.
|
|
10
|
-
* This means parallel calls in Promise.all count as a single round trip.
|
|
11
|
-
*
|
|
12
|
-
* Note that batching of RPC calls in `safe_json_rpc_client.ts` could affect the round trip counts but in places we
|
|
13
|
-
* currently use this information we do not even use HTTP as we have direct access to the Aztec Node instance in TS
|
|
14
|
-
* (i.e. not running against external node) so this is not a problem for now.
|
|
15
|
-
*
|
|
16
|
-
* If you want to use this against external node and the info gets skewed by batching you can set the `maxBatchSize`
|
|
17
|
-
* value in `safe_json_rpc_client.ts` to 1 (the main motivation for batching was to get around parallel http requests
|
|
18
|
-
* limits in web browsers which is not a problem when debugging in node.js).
|
|
19
|
-
*/
|
|
20
|
-
export type BenchmarkedNode = AztecNode & { getStats(): NodeStats };
|
|
21
|
-
|
|
22
|
-
export class BenchmarkedNodeFactory {
|
|
23
|
-
static create(node: AztecNode): BenchmarkedNode {
|
|
24
|
-
// Per-method call stats
|
|
25
|
-
const perMethod: Partial<Record<keyof AztecNode, { times: number[] }>> = {};
|
|
26
|
-
|
|
27
|
-
// Round trip tracking
|
|
28
|
-
let inFlightCount = 0;
|
|
29
|
-
let currentRoundTripTimer: Timer | null = null;
|
|
30
|
-
let currentRoundTripMethods: string[] = [];
|
|
31
|
-
const roundTrips: RoundTripStats = {
|
|
32
|
-
roundTrips: 0,
|
|
33
|
-
totalBlockingTime: 0,
|
|
34
|
-
roundTripDurations: [],
|
|
35
|
-
roundTripMethods: [],
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return new Proxy(node, {
|
|
39
|
-
get(target, prop: keyof BenchmarkedNode) {
|
|
40
|
-
if (prop === 'getStats') {
|
|
41
|
-
return (): NodeStats => {
|
|
42
|
-
return { perMethod, roundTrips };
|
|
43
|
-
};
|
|
44
|
-
} else {
|
|
45
|
-
return function (...args: any[]) {
|
|
46
|
-
// Track per-method stats
|
|
47
|
-
if (!perMethod[prop]) {
|
|
48
|
-
perMethod[prop] = { times: [] };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Start of a new round trip batch?
|
|
52
|
-
if (inFlightCount === 0) {
|
|
53
|
-
roundTrips.roundTrips++;
|
|
54
|
-
currentRoundTripTimer = new Timer();
|
|
55
|
-
currentRoundTripMethods = [];
|
|
56
|
-
}
|
|
57
|
-
inFlightCount++;
|
|
58
|
-
currentRoundTripMethods.push(prop);
|
|
59
|
-
|
|
60
|
-
const callTimer = new Timer();
|
|
61
|
-
const result = (target[prop] as any).apply(target, args);
|
|
62
|
-
|
|
63
|
-
// Handle completion - called when the call finishes (after Promise resolves)
|
|
64
|
-
const handleCompletion = () => {
|
|
65
|
-
const callTime = callTimer.ms();
|
|
66
|
-
perMethod[prop]!.times.push(callTime);
|
|
67
|
-
|
|
68
|
-
inFlightCount--;
|
|
69
|
-
|
|
70
|
-
// End of round trip batch - all concurrent calls completed
|
|
71
|
-
if (inFlightCount === 0 && currentRoundTripTimer) {
|
|
72
|
-
const roundTripTime = currentRoundTripTimer.ms();
|
|
73
|
-
roundTrips.totalBlockingTime += roundTripTime;
|
|
74
|
-
roundTrips.roundTripDurations.push(roundTripTime);
|
|
75
|
-
roundTrips.roundTripMethods.push(currentRoundTripMethods);
|
|
76
|
-
currentRoundTripTimer = null;
|
|
77
|
-
currentRoundTripMethods = [];
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// If the result is a Promise, chain the completion handler
|
|
82
|
-
if (result && typeof result.then === 'function') {
|
|
83
|
-
return result.then(
|
|
84
|
-
(value: any) => {
|
|
85
|
-
handleCompletion();
|
|
86
|
-
return value;
|
|
87
|
-
},
|
|
88
|
-
(error: any) => {
|
|
89
|
-
handleCompletion();
|
|
90
|
-
throw error;
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
} else {
|
|
94
|
-
// Synchronous method - handle completion immediately
|
|
95
|
-
handleCompletion();
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
}) as BenchmarkedNode;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import { TxHash, TxStatus } from '@aztec/stdlib/tx';
|
|
3
|
-
|
|
4
|
-
/** Classification of a batch of pending tx hashes by the status change implied by their receipts. */
|
|
5
|
-
export type StatusChange = {
|
|
6
|
-
txHashesToFinalize: TxHash[];
|
|
7
|
-
txHashesToDrop: TxHash[];
|
|
8
|
-
txHashesWithExecutionReverted: TxHash[];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const EMPTY_STATUS_CHANGE: StatusChange = {
|
|
12
|
-
txHashesToFinalize: [],
|
|
13
|
-
txHashesToDrop: [],
|
|
14
|
-
txHashesWithExecutionReverted: [],
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/** Concatenates two status changes field-by-field. */
|
|
18
|
-
export function mergeStatusChanges(a: StatusChange, b: StatusChange): StatusChange {
|
|
19
|
-
return {
|
|
20
|
-
txHashesToFinalize: [...a.txHashesToFinalize, ...b.txHashesToFinalize],
|
|
21
|
-
txHashesToDrop: [...a.txHashesToDrop, ...b.txHashesToDrop],
|
|
22
|
-
txHashesWithExecutionReverted: [...a.txHashesWithExecutionReverted, ...b.txHashesWithExecutionReverted],
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Based on receipts obtained from `aztecNode` returns which pending transactions changed their status to finalized,
|
|
28
|
-
* dropped, or execution-reverted (but mined).
|
|
29
|
-
*/
|
|
30
|
-
export async function getStatusChangeOfPending(pending: TxHash[], aztecNode: AztecNode): Promise<StatusChange> {
|
|
31
|
-
// Get receipts for all pending tx hashes.
|
|
32
|
-
const receipts = await Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash)));
|
|
33
|
-
|
|
34
|
-
const txHashesToFinalize: TxHash[] = [];
|
|
35
|
-
const txHashesToDrop: TxHash[] = [];
|
|
36
|
-
const txHashesWithExecutionReverted: TxHash[] = [];
|
|
37
|
-
|
|
38
|
-
for (let i = 0; i < receipts.length; i++) {
|
|
39
|
-
const receipt = receipts[i];
|
|
40
|
-
const txHash = pending[i];
|
|
41
|
-
|
|
42
|
-
if (receipt.status === TxStatus.FINALIZED) {
|
|
43
|
-
// Tx has been included in a block and the corresponding block is finalized
|
|
44
|
-
if (receipt.hasExecutionSucceeded()) {
|
|
45
|
-
// No part of execution reverted - we just finalize all the indexes.
|
|
46
|
-
txHashesToFinalize.push(txHash);
|
|
47
|
-
} else if (receipt.hasExecutionReverted()) {
|
|
48
|
-
// Tx was mined but execution reverted (app logic, teardown, or both). Some logs from the non-revertible
|
|
49
|
-
// phase may still be onchain. We check which tags made it onchain and finalize those; drop the rest.
|
|
50
|
-
txHashesWithExecutionReverted.push(txHash);
|
|
51
|
-
} else {
|
|
52
|
-
// Defensive check - this branch should never be triggered
|
|
53
|
-
throw new Error(
|
|
54
|
-
'Both hasExecutionSucceeded and hasExecutionReverted on the receipt returned false. This should never happen and it implies a bug. Please open an issue.',
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
} else if (receipt.isDropped()) {
|
|
58
|
-
// Tx was dropped from the mempool --> we drop the corresponding pending indexes.
|
|
59
|
-
txHashesToDrop.push(txHash);
|
|
60
|
-
} else {
|
|
61
|
-
// Tx is still pending, not yet finalized, or was mined successfully but not yet finalized --> we don't do anything.
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return { txHashesToFinalize, txHashesToDrop, txHashesWithExecutionReverted };
|
|
66
|
-
}
|