@aztec/pxe 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c
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/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +13 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +74 -20
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +57 -34
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +197 -82
- package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +45 -28
- package/dest/contract_function_simulator/index.d.ts +2 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
- 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 +7 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
- 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 +2 -2
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +17 -13
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
- package/dest/contract_function_simulator/oracle/oracle.d.ts +12 -10
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +67 -44
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +44 -50
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +83 -54
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +67 -33
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +131 -110
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +55 -0
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -17
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +31 -8
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- 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 +32 -9
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +5 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +4 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +39 -16
- package/dest/events/event_service.d.ts +6 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +19 -22
- package/dest/events/private_event_filter_validator.d.ts +5 -5
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +5 -6
- package/dest/job_coordinator/job_coordinator.d.ts +75 -0
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
- package/dest/job_coordinator/job_coordinator.js +94 -0
- package/dest/logs/log_service.d.ts +8 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +28 -30
- package/dest/notes/note_service.d.ts +10 -9
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +34 -38
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +3 -3
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +2 -2
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +16 -10
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +12 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +24 -24
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +94 -2
- package/dest/pxe.d.ts +76 -58
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +149 -138
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +130 -23
- package/dest/storage/contract_store/contract_store.d.ts +42 -16
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -84
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +50 -51
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +284 -263
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +47 -7
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +231 -73
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +15 -8
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +19 -9
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +253 -101
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +60 -0
- package/dest/tagging/index.d.ts +3 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -10
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -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 +12 -12
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
- 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 +5 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +8 -8
- 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 +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +5 -2
- 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 +10 -5
- package/package.json +27 -18
- package/src/access_scopes.ts +9 -0
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +93 -32
- package/src/config/index.ts +14 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +350 -143
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/index.ts +1 -1
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +22 -12
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
- package/src/contract_function_simulator/oracle/oracle.ts +79 -47
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +119 -137
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +198 -115
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/helpers.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +63 -18
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +23 -16
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +24 -17
- package/src/entrypoints/pxe_creation_options.ts +4 -2
- package/src/entrypoints/server/index.ts +4 -0
- package/src/entrypoints/server/utils.ts +33 -41
- package/src/events/event_service.ts +19 -25
- package/src/events/private_event_filter_validator.ts +3 -5
- package/src/job_coordinator/job_coordinator.ts +150 -0
- package/src/logs/log_service.ts +40 -34
- package/src/notes/note_service.ts +41 -45
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +2 -2
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +39 -28
- package/src/private_kernel/private_kernel_execution_prover.ts +15 -14
- package/src/private_kernel/private_kernel_oracle.ts +116 -36
- package/src/pxe.ts +280 -209
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +159 -23
- package/src/storage/contract_store/contract_store.ts +186 -96
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +326 -320
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +301 -79
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +106 -20
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +294 -109
- package/src/tagging/constants.ts +10 -0
- package/src/tagging/get_all_logs_by_tags.ts +92 -0
- package/src/tagging/index.ts +2 -11
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +25 -11
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +10 -7
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -13
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +16 -4
- package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
- package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_node.js +0 -27
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
- package/dest/public_storage/public_storage_service.d.ts +0 -24
- package/dest/public_storage/public_storage_service.d.ts.map +0 -1
- package/dest/public_storage/public_storage_service.js +0 -26
- package/dest/tree_membership/tree_membership_service.d.ts +0 -52
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -84
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
- package/src/public_storage/public_storage_service.ts +0 -33
- package/src/tree_membership/tree_membership_service.ts +0 -112
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../
|
|
1
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
|
|
2
2
|
import { findHighestIndexes } from './utils/find_highest_indexes.js';
|
|
3
3
|
import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
4
4
|
/**
|
|
@@ -7,13 +7,13 @@ 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, anchorBlockHash, 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]
|
|
14
14
|
//
|
|
15
15
|
// highestAgedIndex is the highest index that was used in a tx that is included in a block at least
|
|
16
|
-
// `
|
|
16
|
+
// `MAX_TX_LIFETIME` seconds ago.
|
|
17
17
|
// highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
|
|
18
18
|
//
|
|
19
19
|
// "(" denotes an open end of the range - the index is not included in the range.
|
|
@@ -25,19 +25,19 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
25
25
|
// ever appear.
|
|
26
26
|
//
|
|
27
27
|
// This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
|
|
28
|
-
// - a transaction's maximum inclusion timestamp is at most `
|
|
28
|
+
// - a transaction's maximum inclusion timestamp is at most `MAX_TX_LIFETIME` seconds after
|
|
29
29
|
// the timestamp of its anchor block; and
|
|
30
30
|
// - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
|
|
31
31
|
//
|
|
32
32
|
// Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
|
|
33
|
-
// least `
|
|
33
|
+
// least `MAX_TX_LIFETIME` seconds in the past. Then there is no possibility of any *other* device
|
|
34
34
|
// trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
|
|
35
35
|
// a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
|
|
36
36
|
// chosen a larger index.
|
|
37
37
|
// If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
|
|
38
38
|
// because it would already have been expired.
|
|
39
39
|
//
|
|
40
|
-
// Therefore, once we see that index `I` has been used in a block that is at least `
|
|
40
|
+
// Therefore, once we see that index `I` has been used in a block that is at least `MAX_TX_LIFETIME`
|
|
41
41
|
// seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
|
|
42
42
|
//
|
|
43
43
|
// ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
|
|
@@ -55,14 +55,14 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
55
55
|
throw new Error('Node failed to return latest block header when syncing logs');
|
|
56
56
|
}
|
|
57
57
|
[finalizedBlockNumber, currentTimestamp] = [
|
|
58
|
-
l2Tips.finalized.number,
|
|
58
|
+
l2Tips.finalized.block.number,
|
|
59
59
|
latestBlockHeader.globalVariables.timestamp
|
|
60
60
|
];
|
|
61
61
|
}
|
|
62
62
|
let start, end;
|
|
63
63
|
{
|
|
64
|
-
const currentHighestAgedIndex = await taggingStore.getHighestAgedIndex(secret);
|
|
65
|
-
const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret);
|
|
64
|
+
const currentHighestAgedIndex = await taggingStore.getHighestAgedIndex(secret, jobId);
|
|
65
|
+
const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret, jobId);
|
|
66
66
|
// We don't want to include the highest aged index so we start from `currentHighestAgedIndex + 1` (or 0 if not set)
|
|
67
67
|
start = currentHighestAgedIndex === undefined ? 0 : currentHighestAgedIndex + 1;
|
|
68
68
|
// The highest index a sender can choose is "highest finalized index + window length" but given that
|
|
@@ -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, anchorBlockHash);
|
|
76
76
|
if (privateLogsWithIndexes.length === 0) {
|
|
77
77
|
break;
|
|
78
78
|
}
|
|
@@ -80,7 +80,7 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
80
80
|
const { highestAgedIndex, highestFinalizedIndex } = findHighestIndexes(privateLogsWithIndexes, currentTimestamp, finalizedBlockNumber);
|
|
81
81
|
// Store updates in data provider and update local variables
|
|
82
82
|
if (highestAgedIndex !== undefined) {
|
|
83
|
-
await taggingStore.updateHighestAgedIndex(secret, highestAgedIndex);
|
|
83
|
+
await taggingStore.updateHighestAgedIndex(secret, highestAgedIndex, jobId);
|
|
84
84
|
}
|
|
85
85
|
if (highestFinalizedIndex === undefined) {
|
|
86
86
|
break;
|
|
@@ -89,7 +89,7 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
89
89
|
// This is just a sanity check as this should never happen.
|
|
90
90
|
throw new Error('Highest aged index lower than highest finalized index invariant violated');
|
|
91
91
|
}
|
|
92
|
-
await taggingStore.updateHighestFinalizedIndex(secret, highestFinalizedIndex);
|
|
92
|
+
await taggingStore.updateHighestFinalizedIndex(secret, highestFinalizedIndex, jobId);
|
|
93
93
|
// For the next iteration we want to look only at indexes for which we have not attempted to load logs yet while
|
|
94
94
|
// ensuring that we do not look further than WINDOW_LEN ahead of the highest finalized index.
|
|
95
95
|
start = end;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_TX_LIFETIME } from '@aztec/constants';
|
|
2
2
|
/**
|
|
3
3
|
* Finds the highest aged and the highest finalized tagging indexes.
|
|
4
4
|
*/ export function findHighestIndexes(privateLogsWithIndexes, currentTimestamp, finalizedBlockNumber) {
|
|
@@ -6,7 +6,7 @@ import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
|
|
|
6
6
|
let highestFinalizedIndex = undefined;
|
|
7
7
|
for (const { log, taggingIndex } of privateLogsWithIndexes){
|
|
8
8
|
const ageInSeconds = currentTimestamp - log.blockTimestamp;
|
|
9
|
-
if (ageInSeconds >= BigInt(
|
|
9
|
+
if (ageInSeconds >= BigInt(MAX_TX_LIFETIME) && (highestAgedIndex === undefined || taggingIndex > highestAgedIndex)) {
|
|
10
10
|
highestAgedIndex = taggingIndex;
|
|
11
11
|
}
|
|
12
12
|
if (log.blockNumber <= finalizedBlockNumber && (highestFinalizedIndex === undefined || taggingIndex > highestFinalizedIndex)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
4
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
5
|
import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
6
|
/**
|
|
@@ -7,8 +8,8 @@ import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/l
|
|
|
7
8
|
* `secret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and `end` is
|
|
8
9
|
* exclusive.
|
|
9
10
|
*/
|
|
10
|
-
export declare function loadLogsForRange(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, start: number, end: number, anchorBlockNumber: BlockNumber): Promise<Array<{
|
|
11
|
+
export declare function loadLogsForRange(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, start: number, end: number, anchorBlockNumber: BlockNumber, anchorBlockHash: BlockHash): Promise<Array<{
|
|
11
12
|
log: TxScopedL2Log;
|
|
12
13
|
taggingIndex: number;
|
|
13
14
|
}>>;
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZF9sb2dzX2Zvcl9yYW5nZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvcmVjaXBpZW50X3N5bmMvdXRpbHMvbG9hZF9sb2dzX2Zvcl9yYW5nZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNyRCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSwyQkFBMkIsRUFBVSxhQUFhLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUs3Rjs7OztHQUlHO0FBQ0gsd0JBQXNCLGdCQUFnQixDQUNwQyxNQUFNLEVBQUUsMkJBQTJCLEVBQ25DLEdBQUcsRUFBRSxZQUFZLEVBQ2pCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLEtBQUssRUFBRSxNQUFNLEVBQ2IsR0FBRyxFQUFFLE1BQU0sRUFDWCxpQkFBaUIsRUFBRSxXQUFXLEVBQzlCLGVBQWUsRUFBRSxTQUFTLEdBQ3pCLE9BQU8sQ0FBQyxLQUFLLENBQUM7SUFBRSxHQUFHLEVBQUUsYUFBYSxDQUFDO0lBQUMsWUFBWSxFQUFFLE1BQU0sQ0FBQTtDQUFFLENBQUMsQ0FBQyxDQTBCOUQifQ==
|
|
@@ -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,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,2BAA2B,EAAU,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
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,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,2BAA2B,EAAU,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAK7F;;;;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,EAC9B,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,KAAK,CAAC;IAAE,GAAG,EAAE,aAAa,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CA0B9D"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
2
|
+
import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
2
3
|
/**
|
|
3
4
|
* Gets private logs with their corresponding block timestamps and tagging indexes for the given index range, `app` and
|
|
4
5
|
* `secret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and `end` is
|
|
5
6
|
* exclusive.
|
|
6
|
-
*/ export async function loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber) {
|
|
7
|
+
*/ export async function loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber, anchorBlockHash) {
|
|
7
8
|
// Derive tags for the window
|
|
8
9
|
const preTags = Array(end - start).fill(0).map((_, i)=>({
|
|
9
10
|
secret,
|
|
10
11
|
index: start + i
|
|
11
12
|
}));
|
|
12
13
|
const siloedTags = await Promise.all(preTags.map((preTag)=>Tag.compute(preTag))).then((tags)=>Promise.all(tags.map((tag)=>SiloedTag.compute(tag, app))));
|
|
13
|
-
|
|
14
|
+
// We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
|
|
15
|
+
// pagination here.
|
|
16
|
+
const logs = await getAllPrivateLogsByTags(aztecNode, siloedTags, anchorBlockHash);
|
|
14
17
|
// Pair logs with their corresponding tagging indexes
|
|
15
18
|
const logsWithIndexes = [];
|
|
16
19
|
for(let i = 0; i < logs.length; i++){
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
2
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
4
|
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
4
5
|
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
@@ -16,5 +17,5 @@ import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagg
|
|
|
16
17
|
* @dev This function looks for new indexes, adds them to pending, then it checks status of each pending index and
|
|
17
18
|
* updates its status accordingly.
|
|
18
19
|
*/
|
|
19
|
-
export declare function syncSenderTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, taggingStore: SenderTaggingStore): Promise<void>;
|
|
20
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
export declare function syncSenderTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, aztecNode: AztecNode, taggingStore: SenderTaggingStore, anchorBlockHash: BlockHash, jobId: string): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY19zZW5kZXJfdGFnZ2luZ19pbmRleGVzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdGFnZ2luZy9zZW5kZXJfc3luYy9zeW5jX3NlbmRlcl90YWdnaW5nX2luZGV4ZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDckQsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakUsT0FBTyxLQUFLLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV0RSxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHFEQUFxRCxDQUFDO0FBSzlGOzs7Ozs7Ozs7Ozs7O0dBYUc7QUFDSCx3QkFBc0Isd0JBQXdCLENBQzVDLE1BQU0sRUFBRSwyQkFBMkIsRUFDbkMsR0FBRyxFQUFFLFlBQVksRUFDakIsU0FBUyxFQUFFLFNBQVMsRUFDcEIsWUFBWSxFQUFFLGtCQUFrQixFQUNoQyxlQUFlLEVBQUUsU0FBUyxFQUMxQixLQUFLLEVBQUUsTUFBTSxHQUNaLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FtRWYifQ==
|
|
@@ -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,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,
|
|
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,qBAAqB,CAAC;AACrD,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,eAAe,EAAE,SAAS,EAC1B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAmEf"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../
|
|
1
|
+
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
|
|
2
2
|
import { getStatusChangeOfPending } from './utils/get_status_change_of_pending.js';
|
|
3
3
|
import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_tagging_indexes.js';
|
|
4
4
|
/**
|
|
@@ -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, anchorBlockHash, 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).
|
|
@@ -32,7 +32,7 @@ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_taggin
|
|
|
32
32
|
// # Note on performance
|
|
33
33
|
// Each window advance requires two queries (logs + tx status). For example, syncing indexes 0–500 with a window of
|
|
34
34
|
// 100 takes at least 10 round trips (5 windows × 2 queries).
|
|
35
|
-
const finalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
|
|
35
|
+
const finalizedIndex = await taggingStore.getLastFinalizedIndex(secret, jobId);
|
|
36
36
|
let start = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
|
|
37
37
|
let end = start + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN;
|
|
38
38
|
let previousFinalizedIndex = finalizedIndex;
|
|
@@ -40,17 +40,17 @@ 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, anchorBlockHash, jobId);
|
|
44
44
|
// Retrieve all indexes within the current window from storage and update their status accordingly.
|
|
45
|
-
const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end);
|
|
45
|
+
const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
|
|
46
46
|
if (pendingTxHashes.length === 0) {
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
49
|
const { txHashesToFinalize, txHashesToDrop } = await getStatusChangeOfPending(pendingTxHashes, aztecNode);
|
|
50
|
-
await taggingStore.dropPendingIndexes(txHashesToDrop);
|
|
51
|
-
await taggingStore.finalizePendingIndexes(txHashesToFinalize);
|
|
50
|
+
await taggingStore.dropPendingIndexes(txHashesToDrop, jobId);
|
|
51
|
+
await taggingStore.finalizePendingIndexes(txHashesToFinalize, jobId);
|
|
52
52
|
// We check if the finalized index has been updated.
|
|
53
|
-
newFinalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
|
|
53
|
+
newFinalizedIndex = await taggingStore.getLastFinalizedIndex(secret, jobId);
|
|
54
54
|
if (previousFinalizedIndex !== newFinalizedIndex) {
|
|
55
55
|
// A new finalized index was found, so we'll run the loop again. For example:
|
|
56
56
|
// - Previous finalized index: 10
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X3N0YXR1c19jaGFuZ2Vfb2ZfcGVuZGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvZ2V0X3N0YXR1c19jaGFuZ2Vfb2ZfcGVuZGluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEVBQUUsTUFBTSxFQUFZLE1BQU0sa0JBQWtCLENBQUM7QUFFcEQ7OztHQUdHO0FBQ0gsd0JBQXNCLHdCQUF3QixDQUM1QyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQ2pCLFNBQVMsRUFBRSxTQUFTLEdBQ25CLE9BQU8sQ0FBQztJQUFFLGtCQUFrQixFQUFFLE1BQU0sRUFBRSxDQUFDO0lBQUMsY0FBYyxFQUFFLE1BQU0sRUFBRSxDQUFBO0NBQUUsQ0FBQyxDQXlCckUifQ==
|
|
@@ -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,CAyBrE"}
|
|
@@ -3,26 +3,23 @@ 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
|
|
8
|
-
Promise.all(pending.map((pendingTxHash)=>aztecNode.getTxReceipt(pendingTxHash))),
|
|
9
|
-
aztecNode.getL2Tips()
|
|
10
|
-
]);
|
|
6
|
+
// Get receipts for all pending tx hashes.
|
|
7
|
+
const receipts = await Promise.all(pending.map((pendingTxHash)=>aztecNode.getTxReceipt(pendingTxHash)));
|
|
11
8
|
const txHashesToFinalize = [];
|
|
12
9
|
const txHashesToDrop = [];
|
|
13
10
|
for(let i = 0; i < receipts.length; i++){
|
|
14
11
|
const receipt = receipts[i];
|
|
15
12
|
const txHash = pending[i];
|
|
16
|
-
if (receipt.status === TxStatus.
|
|
13
|
+
if (receipt.status === TxStatus.FINALIZED && receipt.hasExecutionSucceeded()) {
|
|
17
14
|
// Tx has been included in a block and the corresponding block is finalized --> we mark the indexes as
|
|
18
15
|
// finalized.
|
|
19
16
|
txHashesToFinalize.push(txHash);
|
|
20
|
-
} else if (receipt.
|
|
17
|
+
} else if (receipt.isDropped() || receipt.hasExecutionReverted()) {
|
|
21
18
|
// Tx was dropped or reverted --> we drop the corresponding pending indexes.
|
|
22
19
|
// TODO(#17615): Don't drop pending indexes corresponding to non-revertible phases.
|
|
23
20
|
txHashesToDrop.push(txHash);
|
|
24
21
|
} else {
|
|
25
|
-
// Tx is still pending or
|
|
22
|
+
// Tx is still pending, not yet finalized, or was mined successfully but not yet finalized --> we don't do anything.
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
2
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
4
|
import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
4
5
|
import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
|
|
@@ -13,6 +14,8 @@ import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_t
|
|
|
13
14
|
* @param end - The ending index (exclusive) of the window to process.
|
|
14
15
|
* @param aztecNode - The Aztec node instance to query for logs.
|
|
15
16
|
* @param taggingStore - The data provider to store pending indexes.
|
|
17
|
+
* @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
|
|
18
|
+
* preserving way.
|
|
16
19
|
*/
|
|
17
|
-
export declare function loadAndStoreNewTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, start: number, end: number, aztecNode: AztecNode, taggingStore: SenderTaggingStore): Promise<void>;
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
export declare function loadAndStoreNewTaggingIndexes(secret: DirectionalAppTaggingSecret, app: AztecAddress, start: number, end: number, aztecNode: AztecNode, taggingStore: SenderTaggingStore, anchorBlockHash: BlockHash, jobId: string): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvbG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNyRCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSwyQkFBMkIsRUFBVSxNQUFNLG9CQUFvQixDQUFDO0FBSTlFLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sd0RBQXdELENBQUM7QUFHakc7Ozs7Ozs7Ozs7Ozs7R0FhRztBQUNILHdCQUFzQiw2QkFBNkIsQ0FDakQsTUFBTSxFQUFFLDJCQUEyQixFQUNuQyxHQUFHLEVBQUUsWUFBWSxFQUNqQixLQUFLLEVBQUUsTUFBTSxFQUNiLEdBQUcsRUFBRSxNQUFNLEVBQ1gsU0FBUyxFQUFFLFNBQVMsRUFDcEIsWUFBWSxFQUFFLGtCQUFrQixFQUNoQyxlQUFlLEVBQUUsU0FBUyxFQUMxQixLQUFLLEVBQUUsTUFBTSxpQkFrQmQifQ==
|
|
@@ -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,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,2BAA2B,EAAU,MAAM,oBAAoB,CAAC;AAI9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;
|
|
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,qBAAqB,CAAC;AACrD,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;AAGjG;;;;;;;;;;;;;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,eAAe,EAAE,SAAS,EAC1B,KAAK,EAAE,MAAM,iBAkBd"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
2
2
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
3
4
|
/**
|
|
4
5
|
* Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
|
|
5
6
|
* @remarks This function is one of two places by which a pending index can get to the tagging data provider. The other
|
|
@@ -11,14 +12,16 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
11
12
|
* @param end - The ending index (exclusive) of the window to process.
|
|
12
13
|
* @param aztecNode - The Aztec node instance to query for logs.
|
|
13
14
|
* @param taggingStore - The data provider to store pending indexes.
|
|
14
|
-
|
|
15
|
+
* @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
|
|
16
|
+
* preserving way.
|
|
17
|
+
*/ export async function loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore, anchorBlockHash, jobId) {
|
|
15
18
|
// We compute the tags for the current window of indexes
|
|
16
19
|
const preTagsForWindow = Array(end - start).fill(0).map((_, i)=>({
|
|
17
20
|
secret,
|
|
18
21
|
index: start + i
|
|
19
22
|
}));
|
|
20
23
|
const siloedTagsForWindow = await Promise.all(preTagsForWindow.map(async (preTag)=>SiloedTag.compute(await Tag.compute(preTag), app)));
|
|
21
|
-
const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode);
|
|
24
|
+
const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode, anchorBlockHash);
|
|
22
25
|
const highestIndexMap = getTxHighestIndexMap(txsForTags, preTagsForWindow);
|
|
23
26
|
// Now we iterate over the map, reconstruct the preTags and tx hash and store them in the db.
|
|
24
27
|
for (const [txHashStr, highestIndex] of highestIndexMap.entries()){
|
|
@@ -28,13 +31,15 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
28
31
|
secret,
|
|
29
32
|
index: highestIndex
|
|
30
33
|
}
|
|
31
|
-
], txHash);
|
|
34
|
+
], txHash, jobId);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
// Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
|
|
35
38
|
// an array for each tag.
|
|
36
|
-
async function getTxsContainingTags(tags, aztecNode) {
|
|
37
|
-
|
|
39
|
+
async function getTxsContainingTags(tags, aztecNode, anchorBlockHash) {
|
|
40
|
+
// We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
|
|
41
|
+
// pagination here.
|
|
42
|
+
const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
|
|
38
43
|
return allLogs.map((logs)=>logs.map((log)=>log.txHash));
|
|
39
44
|
}
|
|
40
45
|
// Returns a map of txHash to the highest index for that txHash.
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.ff7989d6c",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"typedocOptions": {
|
|
6
|
+
"entryPoints": [
|
|
7
|
+
"./src/entrypoints/server/index.ts",
|
|
8
|
+
"./src/entrypoints/client/lazy/index.ts",
|
|
9
|
+
"./src/config/index.ts"
|
|
10
|
+
],
|
|
11
|
+
"name": "PXE",
|
|
12
|
+
"tsconfig": "./tsconfig.json"
|
|
13
|
+
},
|
|
5
14
|
"exports": {
|
|
6
15
|
"./server": "./dest/entrypoints/server/index.js",
|
|
7
16
|
"./client/lazy": "./dest/entrypoints/client/lazy/index.js",
|
|
@@ -11,7 +20,7 @@
|
|
|
11
20
|
},
|
|
12
21
|
"bin": "./dest/bin/index.js",
|
|
13
22
|
"scripts": {
|
|
14
|
-
"build": "yarn clean && yarn generate &&
|
|
23
|
+
"build": "yarn clean && yarn generate && ../scripts/tsc.sh",
|
|
15
24
|
"build:dev": "../scripts/tsc.sh --watch",
|
|
16
25
|
"clean": "rm -rf ./dest .tsbuildinfo ./src/config/package_info.ts",
|
|
17
26
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
@@ -61,19 +70,19 @@
|
|
|
61
70
|
]
|
|
62
71
|
},
|
|
63
72
|
"dependencies": {
|
|
64
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
65
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
66
|
-
"@aztec/builder": "0.0.1-commit.
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
69
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
70
|
-
"@aztec/key-store": "0.0.1-commit.
|
|
71
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
72
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
73
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
74
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
75
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
76
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
73
|
+
"@aztec/bb-prover": "0.0.1-commit.ff7989d6c",
|
|
74
|
+
"@aztec/bb.js": "0.0.1-commit.ff7989d6c",
|
|
75
|
+
"@aztec/builder": "0.0.1-commit.ff7989d6c",
|
|
76
|
+
"@aztec/constants": "0.0.1-commit.ff7989d6c",
|
|
77
|
+
"@aztec/ethereum": "0.0.1-commit.ff7989d6c",
|
|
78
|
+
"@aztec/foundation": "0.0.1-commit.ff7989d6c",
|
|
79
|
+
"@aztec/key-store": "0.0.1-commit.ff7989d6c",
|
|
80
|
+
"@aztec/kv-store": "0.0.1-commit.ff7989d6c",
|
|
81
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.ff7989d6c",
|
|
82
|
+
"@aztec/noir-types": "0.0.1-commit.ff7989d6c",
|
|
83
|
+
"@aztec/protocol-contracts": "0.0.1-commit.ff7989d6c",
|
|
84
|
+
"@aztec/simulator": "0.0.1-commit.ff7989d6c",
|
|
85
|
+
"@aztec/stdlib": "0.0.1-commit.ff7989d6c",
|
|
77
86
|
"koa": "^2.16.1",
|
|
78
87
|
"koa-router": "^13.1.1",
|
|
79
88
|
"lodash.omit": "^4.5.0",
|
|
@@ -82,14 +91,14 @@
|
|
|
82
91
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
83
92
|
},
|
|
84
93
|
"devDependencies": {
|
|
85
|
-
"@aztec/merkle-tree": "0.0.1-commit.
|
|
86
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
94
|
+
"@aztec/merkle-tree": "0.0.1-commit.ff7989d6c",
|
|
95
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.ff7989d6c",
|
|
87
96
|
"@jest/globals": "^30.0.0",
|
|
88
97
|
"@types/jest": "^30.0.0",
|
|
89
98
|
"@types/lodash.omit": "^4.5.7",
|
|
90
99
|
"@types/lodash.times": "^4.3.9",
|
|
91
100
|
"@types/node": "^22.15.17",
|
|
92
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
101
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
93
102
|
"jest": "^30.0.0",
|
|
94
103
|
"jest-mock-extended": "^4.0.0",
|
|
95
104
|
"lodash.times": "^4.3.2",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Controls which accounts' private state and keys are accessible during execution.
|
|
5
|
+
* - `'ALL_SCOPES'`: All registered accounts' private state and keys are accessible.
|
|
6
|
+
* - `AztecAddress[]` with entries: Only the specified accounts' private state and keys are accessible.
|
|
7
|
+
* - `[]` (empty array): Deny-all. No private state is visible and no keys are accessible.
|
|
8
|
+
*/
|
|
9
|
+
export type AccessScopes = 'ALL_SCOPES' | AztecAddress[];
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
4
|
import type { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
4
|
-
import { L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
|
|
5
|
+
import { BlockHash, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
|
|
5
6
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
7
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
6
8
|
|
|
7
|
-
import type {
|
|
9
|
+
import type { BlockSynchronizerConfig } from '../config/index.js';
|
|
10
|
+
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
|
|
8
11
|
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
9
12
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
13
|
+
import type { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* The BlockSynchronizer class orchestrates synchronization between PXE and Aztec node, maintaining an up-to-date
|
|
@@ -20,26 +24,32 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
20
24
|
|
|
21
25
|
constructor(
|
|
22
26
|
private node: AztecNode,
|
|
27
|
+
private store: AztecAsyncKVStore,
|
|
23
28
|
private anchorBlockStore: AnchorBlockStore,
|
|
24
29
|
private noteStore: NoteStore,
|
|
30
|
+
private privateEventStore: PrivateEventStore,
|
|
25
31
|
private l2TipsStore: L2TipsKVStore,
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
private contractSyncService: ContractSyncService,
|
|
33
|
+
private config: Partial<BlockSynchronizerConfig> = {},
|
|
34
|
+
bindings?: LoggerBindings,
|
|
28
35
|
) {
|
|
29
|
-
this.log =
|
|
30
|
-
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
31
|
-
? createLogger(loggerOrSuffix ? `pxe:block_synchronizer:${loggerOrSuffix}` : `pxe:block_synchronizer`)
|
|
32
|
-
: loggerOrSuffix;
|
|
36
|
+
this.log = createLogger('pxe:block_synchronizer', bindings);
|
|
33
37
|
this.blockStream = this.createBlockStream(config);
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
protected createBlockStream(config: Partial<
|
|
37
|
-
return new L2BlockStream(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
protected createBlockStream(config: Partial<BlockSynchronizerConfig>): L2BlockStream {
|
|
41
|
+
return new L2BlockStream(
|
|
42
|
+
this.node,
|
|
43
|
+
this.l2TipsStore,
|
|
44
|
+
this,
|
|
45
|
+
createLogger('pxe:block_stream', this.log.getBindings()),
|
|
46
|
+
{
|
|
47
|
+
batchSize: config.l2BlockBatchSize,
|
|
48
|
+
// Skipping finalized blocks makes us sync much faster - we only need to download blocks other than the latest one
|
|
49
|
+
// in order to detect reorgs, and there can be no reorgs on finalized block, making this safe.
|
|
50
|
+
skipFinalized: true,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
/** Handle events emitted by the block stream. */
|
|
@@ -48,32 +58,83 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
48
58
|
|
|
49
59
|
switch (event.type) {
|
|
50
60
|
case 'blocks-added': {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
if (this.config.syncChainTip === undefined || this.config.syncChainTip === 'proposed') {
|
|
62
|
+
const lastBlock = event.blocks.at(-1)!;
|
|
63
|
+
await this.updateAnchorBlockHeader(lastBlock.header);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'chain-checkpointed': {
|
|
68
|
+
if (this.config.syncChainTip === 'checkpointed') {
|
|
69
|
+
// Get the last block header from the checkpoint
|
|
70
|
+
const lastBlock = event.checkpoint.checkpoint.blocks.at(-1)!;
|
|
71
|
+
await this.updateAnchorBlockHeader(lastBlock.header);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'chain-proven': {
|
|
76
|
+
if (this.config.syncChainTip === 'proven') {
|
|
77
|
+
const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
|
|
78
|
+
if (blockHeader) {
|
|
79
|
+
await this.updateAnchorBlockHeader(blockHeader);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'chain-finalized': {
|
|
85
|
+
if (this.config.syncChainTip === 'finalized') {
|
|
86
|
+
const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
|
|
87
|
+
if (blockHeader) {
|
|
88
|
+
await this.updateAnchorBlockHeader(blockHeader);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
58
91
|
break;
|
|
59
92
|
}
|
|
60
93
|
case 'chain-pruned': {
|
|
94
|
+
const currentAnchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
95
|
+
const currentAnchorBlockNumber = currentAnchorBlockHeader.getBlockNumber();
|
|
96
|
+
if (currentAnchorBlockNumber <= event.block.number) {
|
|
97
|
+
this.log.verbose(
|
|
98
|
+
`Ignoring prune event to block ${event.block.number} greater than current anchor block ${currentAnchorBlockNumber}`,
|
|
99
|
+
{ pruneEvent: event, currentAnchorBlockHeader: currentAnchorBlockHeader.toInspect() },
|
|
100
|
+
);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
61
104
|
this.log.warn(`Pruning data after block ${event.block.number} due to reorg`);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
105
|
+
|
|
106
|
+
// Note that the following is not necessarily the anchor block that will be used in the transaction - if
|
|
107
|
+
// the chain has already moved past the reorg, we'll also see blocks-added events that will push the anchor
|
|
108
|
+
// forward.
|
|
109
|
+
const newAnchorBlockHeader = await this.node.getBlockHeader(BlockHash.fromString(event.block.hash));
|
|
110
|
+
|
|
111
|
+
if (!newAnchorBlockHeader) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Block header for block number ${event.block.number} and hash ${event.block.hash} not found during chain prune. This likely indicates a bug in the node, as we receive block stream events and fetch block headers from the same node.`,
|
|
114
|
+
);
|
|
71
115
|
}
|
|
116
|
+
|
|
117
|
+
// Operations are wrapped in a single transaction to ensure atomicity.
|
|
118
|
+
await this.store.transactionAsync(async () => {
|
|
119
|
+
await this.noteStore.rollback(event.block.number, currentAnchorBlockNumber);
|
|
120
|
+
await this.privateEventStore.rollback(event.block.number, currentAnchorBlockNumber);
|
|
121
|
+
await this.updateAnchorBlockHeader(newAnchorBlockHeader);
|
|
122
|
+
});
|
|
72
123
|
break;
|
|
73
124
|
}
|
|
74
125
|
}
|
|
75
126
|
}
|
|
76
127
|
|
|
128
|
+
/** Updates the anchor block header to the target block */
|
|
129
|
+
private async updateAnchorBlockHeader(blockHeader: BlockHeader) {
|
|
130
|
+
// Whenever the anchor block header is updated, we need to synchronize the private state of contracts again.
|
|
131
|
+
// Therefore, we clear the contract synchronization cache here such that the sync is re-triggered upon new
|
|
132
|
+
// execution.
|
|
133
|
+
this.contractSyncService.wipe();
|
|
134
|
+
this.log.verbose(`Updated pxe last block to ${blockHeader.getBlockNumber()}`, blockHeader.toInspect());
|
|
135
|
+
await this.anchorBlockStore.setHeader(blockHeader);
|
|
136
|
+
}
|
|
137
|
+
|
|
77
138
|
/**
|
|
78
139
|
* Syncs PXE and the node by downloading the metadata of the latest blocks, allowing simulations to use
|
|
79
140
|
* recent data (e.g. notes), and handling any reorgs that might have occurred.
|