@aztec/stdlib 5.0.0-rc.1 → 5.0.0
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/abi/buffer.d.ts +6 -2
- package/dest/abi/buffer.d.ts.map +1 -1
- package/dest/abi/buffer.js +13 -1
- package/dest/avm/avm.js +1 -1
- package/dest/aztec-address/index.d.ts +35 -5
- package/dest/aztec-address/index.d.ts.map +1 -1
- package/dest/aztec-address/index.js +32 -8
- package/dest/block/attestation_info.d.ts +1 -1
- package/dest/block/attestation_info.d.ts.map +1 -1
- package/dest/block/attestation_info.js +7 -4
- package/dest/block/l2_block_source.d.ts +44 -27
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/l2_block_source.js +15 -1
- package/dest/block/l2_block_stream/event_driven_l2_block_stream.d.ts +39 -0
- package/dest/block/l2_block_stream/event_driven_l2_block_stream.d.ts.map +1 -0
- package/dest/block/l2_block_stream/event_driven_l2_block_stream.js +165 -0
- package/dest/block/l2_block_stream/index.d.ts +2 -1
- package/dest/block/l2_block_stream/index.d.ts.map +1 -1
- package/dest/block/l2_block_stream/index.js +1 -0
- package/dest/block/l2_block_stream/interfaces.d.ts +40 -6
- package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
- package/dest/block/l2_block_stream/interfaces.js +25 -1
- package/dest/block/l2_block_stream/l2_block_stream.d.ts +23 -15
- package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.js +140 -152
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +10 -2
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_tips_store_base.js +33 -15
- package/dest/block/proposal/attestations_and_signers.d.ts +19 -1
- package/dest/block/proposal/attestations_and_signers.d.ts.map +1 -1
- package/dest/block/proposal/attestations_and_signers.js +47 -7
- package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
- package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
- package/dest/block/test/l2_tips_store_test_suite.js +94 -3
- package/dest/block/validate_block_result.d.ts +16 -1
- package/dest/block/validate_block_result.d.ts.map +1 -1
- package/dest/block/validate_block_result.js +18 -3
- package/dest/checkpoint/index.d.ts +2 -1
- package/dest/checkpoint/index.d.ts.map +1 -1
- package/dest/checkpoint/index.js +1 -0
- package/dest/checkpoint/simulation_overrides.d.ts +61 -0
- package/dest/checkpoint/simulation_overrides.d.ts.map +1 -0
- package/dest/checkpoint/simulation_overrides.js +98 -0
- package/dest/config/network-consensus-config.d.ts +1 -1
- package/dest/config/network-consensus-config.d.ts.map +1 -1
- package/dest/config/network-consensus-config.js +2 -10
- package/dest/contract/contract_address.d.ts +5 -4
- package/dest/contract/contract_address.d.ts.map +1 -1
- package/dest/contract/contract_instance.d.ts +16 -2
- package/dest/contract/contract_instance.d.ts.map +1 -1
- package/dest/contract/contract_instance.js +45 -0
- package/dest/contract/interfaces/contract_data_source.d.ts +3 -5
- package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_instance.d.ts +71 -10
- package/dest/contract/interfaces/contract_instance.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_instance.js +7 -2
- package/dest/contract/partial_address.d.ts +9 -3
- package/dest/contract/partial_address.d.ts.map +1 -1
- package/dest/contract/partial_address.js +8 -2
- package/dest/database-version/version_manager.d.ts +18 -4
- package/dest/database-version/version_manager.d.ts.map +1 -1
- package/dest/database-version/version_manager.js +76 -6
- package/dest/file-store/factory.d.ts +1 -1
- package/dest/file-store/factory.d.ts.map +1 -1
- package/dest/file-store/factory.js +7 -0
- package/dest/file-store/index.d.ts +2 -1
- package/dest/file-store/index.d.ts.map +1 -1
- package/dest/file-store/index.js +1 -0
- package/dest/file-store/memory.d.ts +24 -0
- package/dest/file-store/memory.d.ts.map +1 -0
- package/dest/file-store/memory.js +80 -0
- package/dest/ha-signing/config.d.ts +19 -5
- package/dest/ha-signing/config.d.ts.map +1 -1
- package/dest/ha-signing/config.js +9 -3
- package/dest/ha-signing/local_config.d.ts +10 -2
- package/dest/ha-signing/local_config.d.ts.map +1 -1
- package/dest/ha-signing/local_config.js +8 -2
- package/dest/hash/hash.d.ts +1 -2
- package/dest/hash/hash.d.ts.map +1 -1
- package/dest/hash/hash.js +0 -7
- package/dest/interfaces/archiver.d.ts +8 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +3 -2
- package/dest/interfaces/aztec-node-admin.d.ts +5 -2
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-debug.d.ts +26 -1
- package/dest/interfaces/aztec-node-debug.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-debug.js +20 -0
- package/dest/interfaces/aztec-node.d.ts +20 -20
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +8 -15
- package/dest/interfaces/chain_tips.d.ts +8 -47
- package/dest/interfaces/chain_tips.d.ts.map +1 -1
- package/dest/interfaces/chain_tips.js +1 -6
- package/dest/interfaces/checkpoint_parameter.d.ts +3 -3
- package/dest/interfaces/checkpoint_parameter.d.ts.map +1 -1
- package/dest/interfaces/checkpoint_parameter.js +3 -3
- package/dest/interfaces/configs.d.ts +4 -1
- package/dest/interfaces/configs.d.ts.map +1 -1
- package/dest/interfaces/configs.js +1 -0
- package/dest/interfaces/private_kernel_prover.d.ts +9 -11
- package/dest/interfaces/private_kernel_prover.d.ts.map +1 -1
- package/dest/interfaces/prover-node.d.ts +6 -7
- package/dest/interfaces/prover-node.d.ts.map +1 -1
- package/dest/interfaces/prover-node.js +15 -10
- package/dest/interfaces/proving-job.d.ts +87 -74
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/proving-job.js +13 -4
- package/dest/interfaces/server_circuit_prover.d.ts +3 -3
- package/dest/interfaces/server_circuit_prover.d.ts.map +1 -1
- package/dest/interfaces/validator.d.ts +7 -3
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/world_state.d.ts +14 -1
- package/dest/interfaces/world_state.d.ts.map +1 -1
- package/dest/kernel/hints/find_private_kernel_reset_dimensions.d.ts +8 -2
- package/dest/kernel/hints/find_private_kernel_reset_dimensions.d.ts.map +1 -1
- package/dest/kernel/hints/find_private_kernel_reset_dimensions.js +12 -74
- package/dest/kernel/hints/read_request.js +1 -1
- package/dest/kernel/index.d.ts +2 -2
- package/dest/kernel/index.d.ts.map +1 -1
- package/dest/kernel/index.js +1 -1
- package/dest/kernel/log_hash.d.ts +1 -1
- package/dest/kernel/log_hash.d.ts.map +1 -1
- package/dest/kernel/log_hash.js +2 -2
- package/dest/kernel/note_hash.js +1 -1
- package/dest/kernel/nullifier.js +1 -1
- package/dest/kernel/private_circuit_public_inputs.d.ts +13 -3
- package/dest/kernel/private_circuit_public_inputs.d.ts.map +1 -1
- package/dest/kernel/private_circuit_public_inputs.js +14 -7
- package/dest/kernel/private_context_inputs.d.ts +4 -3
- package/dest/kernel/private_context_inputs.d.ts.map +1 -1
- package/dest/kernel/private_context_inputs.js +7 -3
- package/dest/kernel/private_kernel_circuit_public_inputs.d.ts +7 -1
- package/dest/kernel/private_kernel_circuit_public_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_circuit_public_inputs.js +7 -0
- package/dest/kernel/private_kernel_init_2_circuit_private_inputs.d.ts +2 -3
- package/dest/kernel/private_kernel_init_2_circuit_private_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_init_2_circuit_private_inputs.js +3 -5
- package/dest/kernel/private_kernel_init_3_circuit_private_inputs.d.ts +2 -3
- package/dest/kernel/private_kernel_init_3_circuit_private_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_init_3_circuit_private_inputs.js +3 -5
- package/dest/kernel/private_kernel_init_circuit_private_inputs.d.ts +1 -9
- package/dest/kernel/private_kernel_init_circuit_private_inputs.d.ts.map +1 -1
- package/dest/kernel/private_kernel_init_circuit_private_inputs.js +2 -6
- package/dest/kernel/private_kernel_reset_dimensions.d.ts +7 -8
- package/dest/kernel/private_kernel_reset_dimensions.d.ts.map +1 -1
- package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.d.ts +29 -0
- package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.d.ts.map +1 -0
- package/dest/kernel/private_kernel_reset_tail_circuit_private_inputs.js +36 -0
- package/dest/kernel/private_log_data.d.ts +1 -1
- package/dest/kernel/private_log_data.d.ts.map +1 -1
- package/dest/kernel/private_log_data.js +1 -1
- package/dest/keys/derivation.d.ts +41 -6
- package/dest/keys/derivation.d.ts.map +1 -1
- package/dest/keys/derivation.js +49 -26
- package/dest/logs/app_tagging_secret.d.ts +30 -7
- package/dest/logs/app_tagging_secret.d.ts.map +1 -1
- package/dest/logs/app_tagging_secret.js +46 -39
- package/dest/logs/contract_class_log.d.ts +1 -2
- package/dest/logs/contract_class_log.d.ts.map +1 -1
- package/dest/logs/contract_class_log.js +0 -4
- package/dest/logs/index.d.ts +1 -3
- package/dest/logs/index.d.ts.map +1 -1
- package/dest/logs/index.js +0 -2
- package/dest/logs/shared_secret_derivation.d.ts +19 -6
- package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
- package/dest/logs/shared_secret_derivation.js +26 -11
- package/dest/messaging/l1_to_l2_message.d.ts +23 -2
- package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
- package/dest/messaging/l1_to_l2_message.js +36 -11
- package/dest/p2p/attestation_utils.d.ts +1 -1
- package/dest/p2p/attestation_utils.d.ts.map +1 -1
- package/dest/p2p/attestation_utils.js +8 -1
- package/dest/p2p/checkpoint_attestation.d.ts +10 -1
- package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
- package/dest/p2p/checkpoint_attestation.js +10 -0
- package/dest/p2p/checkpoint_proposal.d.ts +2 -1
- package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
- package/dest/p2p/consensus_payload.d.ts +2 -1
- package/dest/p2p/consensus_payload.d.ts.map +1 -1
- package/dest/p2p/signature_utils.d.ts +10 -1
- package/dest/p2p/signature_utils.d.ts.map +1 -1
- package/dest/p2p/signature_utils.js +9 -1
- package/dest/rollup/avm_proof_data.d.ts +3 -3
- package/dest/rollup/avm_proof_data.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.d.ts +8 -3
- package/dest/rollup/checkpoint_header.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.js +20 -10
- package/dest/stats/stats.d.ts +2 -2
- package/dest/stats/stats.d.ts.map +1 -1
- package/dest/tests/factories.d.ts +1 -1
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +7 -15
- package/dest/trees/nullifier_membership_witness.d.ts +5 -8
- package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
- package/dest/trees/nullifier_membership_witness.js +0 -9
- package/dest/trees/public_data_witness.d.ts +7 -17
- package/dest/trees/public_data_witness.d.ts.map +1 -1
- package/dest/trees/public_data_witness.js +0 -27
- package/dest/tx/execution_payload.d.ts +1 -1
- package/dest/tx/execution_payload.d.ts.map +1 -1
- package/dest/tx/execution_payload.js +1 -1
- package/dest/tx/global_variable_builder.d.ts +2 -12
- package/dest/tx/global_variable_builder.d.ts.map +1 -1
- package/dest/tx/global_variables.js +2 -2
- package/dest/tx/private_tx_constant_data.d.ts +18 -2
- package/dest/tx/private_tx_constant_data.d.ts.map +1 -1
- package/dest/tx/private_tx_constant_data.js +13 -4
- package/dest/tx/simulated_tx.d.ts +10 -6
- package/dest/tx/simulated_tx.d.ts.map +1 -1
- package/dest/world-state/genesis_data.d.ts +9 -1
- package/dest/world-state/genesis_data.d.ts.map +1 -1
- package/dest/world-state/genesis_data.js +1 -0
- package/package.json +8 -8
- package/src/abi/buffer.ts +13 -1
- package/src/avm/avm.ts +1 -1
- package/src/aztec-address/index.ts +36 -6
- package/src/block/attestation_info.ts +7 -2
- package/src/block/l2_block_source.ts +64 -17
- package/src/block/l2_block_stream/event_driven_l2_block_stream.ts +207 -0
- package/src/block/l2_block_stream/index.ts +1 -0
- package/src/block/l2_block_stream/interfaces.ts +60 -6
- package/src/block/l2_block_stream/l2_block_stream.ts +201 -178
- package/src/block/l2_block_stream/l2_tips_store_base.ts +36 -15
- package/src/block/proposal/attestations_and_signers.ts +53 -7
- package/src/block/test/l2_tips_store_test_suite.ts +73 -4
- package/src/block/validate_block_result.ts +48 -2
- package/src/checkpoint/index.ts +1 -0
- package/src/checkpoint/simulation_overrides.ts +171 -0
- package/src/config/network-consensus-config.ts +2 -13
- package/src/contract/contract_address.ts +4 -3
- package/src/contract/contract_instance.ts +62 -1
- package/src/contract/interfaces/contract_data_source.ts +2 -4
- package/src/contract/interfaces/contract_instance.ts +26 -8
- package/src/contract/partial_address.ts +8 -2
- package/src/database-version/version_manager.ts +96 -6
- package/src/file-store/factory.ts +7 -0
- package/src/file-store/index.ts +1 -0
- package/src/file-store/memory.ts +94 -0
- package/src/ha-signing/config.ts +23 -5
- package/src/ha-signing/local_config.ts +20 -1
- package/src/hash/hash.ts +0 -8
- package/src/interfaces/archiver.ts +9 -1
- package/src/interfaces/aztec-node-debug.ts +37 -0
- package/src/interfaces/aztec-node.ts +30 -33
- package/src/interfaces/chain_tips.ts +8 -16
- package/src/interfaces/checkpoint_parameter.ts +3 -3
- package/src/interfaces/configs.ts +3 -0
- package/src/interfaces/private_kernel_prover.ts +10 -12
- package/src/interfaces/prover-node.ts +19 -11
- package/src/interfaces/proving-job.ts +15 -3
- package/src/interfaces/server_circuit_prover.ts +2 -2
- package/src/interfaces/world_state.ts +14 -0
- package/src/kernel/hints/find_private_kernel_reset_dimensions.ts +22 -112
- package/src/kernel/hints/read_request.ts +1 -1
- package/src/kernel/index.ts +1 -1
- package/src/kernel/log_hash.ts +5 -2
- package/src/kernel/note_hash.ts +1 -1
- package/src/kernel/nullifier.ts +1 -1
- package/src/kernel/private_circuit_public_inputs.ts +12 -1
- package/src/kernel/private_context_inputs.ts +10 -3
- package/src/kernel/private_kernel_circuit_public_inputs.ts +9 -0
- package/src/kernel/private_kernel_init_2_circuit_private_inputs.ts +0 -3
- package/src/kernel/private_kernel_init_3_circuit_private_inputs.ts +0 -3
- package/src/kernel/private_kernel_init_circuit_private_inputs.ts +0 -6
- package/src/kernel/private_kernel_reset_dimensions.ts +15 -5
- package/src/kernel/private_kernel_reset_tail_circuit_private_inputs.ts +69 -0
- package/src/kernel/private_log_data.ts +4 -1
- package/src/keys/derivation.ts +69 -24
- package/src/logs/app_tagging_secret.ts +62 -39
- package/src/logs/contract_class_log.ts +0 -9
- package/src/logs/index.ts +0 -2
- package/src/logs/shared_secret_derivation.ts +31 -15
- package/src/messaging/l1_to_l2_message.ts +51 -13
- package/src/p2p/attestation_utils.ts +8 -1
- package/src/p2p/checkpoint_attestation.ts +12 -0
- package/src/p2p/signature_utils.ts +9 -0
- package/src/rollup/avm_proof_data.ts +2 -2
- package/src/rollup/checkpoint_header.ts +16 -2
- package/src/stats/stats.ts +2 -2
- package/src/tests/factories.ts +6 -12
- package/src/trees/nullifier_membership_witness.ts +0 -11
- package/src/trees/public_data_witness.ts +0 -31
- package/src/tx/execution_payload.ts +2 -1
- package/src/tx/global_variable_builder.ts +1 -17
- package/src/tx/global_variables.ts +2 -2
- package/src/tx/private_tx_constant_data.ts +25 -2
- package/src/world-state/genesis_data.ts +10 -0
- package/dest/kernel/private_kernel_tail_circuit_private_inputs.d.ts +0 -47
- package/dest/kernel/private_kernel_tail_circuit_private_inputs.d.ts.map +0 -1
- package/dest/kernel/private_kernel_tail_circuit_private_inputs.js +0 -38
- package/dest/logs/message_context.d.ts +0 -27
- package/dest/logs/message_context.d.ts.map +0 -1
- package/dest/logs/message_context.js +0 -74
- package/dest/logs/pending_tagged_log.d.ts +0 -13
- package/dest/logs/pending_tagged_log.d.ts.map +0 -1
- package/dest/logs/pending_tagged_log.js +0 -34
- package/src/kernel/private_kernel_tail_circuit_private_inputs.ts +0 -58
- package/src/logs/message_context.ts +0 -76
- package/src/logs/pending_tagged_log.ts +0 -39
|
@@ -43,34 +43,64 @@ export class AztecAddress {
|
|
|
43
43
|
static ZERO = new AztecAddress(Buffer.alloc(32, 0));
|
|
44
44
|
|
|
45
45
|
/** Null msg sender address. Not part of the protocol contracts tree. */
|
|
46
|
-
static NULL_MSG_SENDER = AztecAddress.
|
|
46
|
+
static NULL_MSG_SENDER = AztecAddress.fromBigIntUnsafe(NULL_MSG_SENDER_CONTRACT_ADDRESS);
|
|
47
47
|
|
|
48
48
|
static zero(): AztecAddress {
|
|
49
49
|
return AztecAddress.ZERO;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Builds an `AztecAddress` from a field **without checking it is a valid address** (the x-coordinate of a point on
|
|
54
|
+
* the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to validate an
|
|
55
|
+
* untrusted one, or {@link AztecAddress.random} for valid test addresses.
|
|
56
|
+
*/
|
|
57
|
+
static fromFieldUnsafe(fr: Fr) {
|
|
53
58
|
return new AztecAddress(fr);
|
|
54
59
|
}
|
|
55
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Deserializes an `AztecAddress` from a buffer. It does **not** check the value is a valid Grumpkin-curve address
|
|
63
|
+
* (see {@link AztecAddress.isValid}); it is meant for reading addresses from already-validated serialized data. Use
|
|
64
|
+
* {@link AztecAddress.random} for valid test addresses.
|
|
65
|
+
*/
|
|
56
66
|
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
57
67
|
return new AztecAddress(fromBuffer(buffer, Fr));
|
|
58
68
|
}
|
|
59
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Deserializes an `AztecAddress` from a field reader. It does **not** check the value is a valid Grumpkin-curve
|
|
72
|
+
* address (see {@link AztecAddress.isValid}); it is meant for reading addresses from already-validated serialized
|
|
73
|
+
* data. Use {@link AztecAddress.random} for valid test addresses.
|
|
74
|
+
*/
|
|
60
75
|
static fromFields(fields: Fr[] | FieldReader) {
|
|
61
76
|
const reader = FieldReader.asReader(fields);
|
|
62
77
|
return new AztecAddress(reader.readField());
|
|
63
78
|
}
|
|
64
79
|
|
|
65
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Builds an `AztecAddress` from a bigint **without checking it is a valid address** (the x-coordinate of a point on
|
|
82
|
+
* the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to validate an
|
|
83
|
+
* untrusted one, or {@link AztecAddress.random} for valid test addresses.
|
|
84
|
+
*/
|
|
85
|
+
static fromBigIntUnsafe(value: bigint) {
|
|
66
86
|
return new AztecAddress(new Fr(value));
|
|
67
87
|
}
|
|
68
88
|
|
|
69
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Builds an `AztecAddress` from a number **without checking it is a valid address** (the x-coordinate of a point on
|
|
91
|
+
* the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to validate an
|
|
92
|
+
* untrusted one, or {@link AztecAddress.random} for valid test addresses.
|
|
93
|
+
*/
|
|
94
|
+
static fromNumberUnsafe(value: number) {
|
|
70
95
|
return new AztecAddress(new Fr(value));
|
|
71
96
|
}
|
|
72
97
|
|
|
73
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Builds an `AztecAddress` from a hex string **without checking it is a valid address** (the x-coordinate of a
|
|
100
|
+
* point on the Grumpkin curve, which is what lets it be encrypted to). Use {@link AztecAddress.isValid} to
|
|
101
|
+
* validate an untrusted one, or {@link AztecAddress.random} for valid test addresses.
|
|
102
|
+
*/
|
|
103
|
+
static fromStringUnsafe(buf: string) {
|
|
74
104
|
return new AztecAddress(hexToBuffer(buf));
|
|
75
105
|
}
|
|
76
106
|
|
|
@@ -89,7 +119,7 @@ export class AztecAddress {
|
|
|
89
119
|
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
90
120
|
return new AztecAddress(obj);
|
|
91
121
|
}
|
|
92
|
-
return AztecAddress.
|
|
122
|
+
return AztecAddress.fromStringUnsafe(obj);
|
|
93
123
|
}
|
|
94
124
|
|
|
95
125
|
/**
|
|
@@ -60,9 +60,14 @@ export function getAttestationInfoFromPayload(
|
|
|
60
60
|
return { address: attestation.address, status: 'provided-as-address' as const };
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// Try to recover address from signature
|
|
63
|
+
// Try to recover address from signature. Recover with default opts (no allowYParityAsV): a slot
|
|
64
|
+
// whose recovery byte is in yParity form (v ∈ {0, 1}) is judged invalid here, matching L1 proving
|
|
65
|
+
// (ValidatorSelectionLib.verifyAttestations → ECDSA.recover only accepts v ∈ {27, 28}). A malicious
|
|
66
|
+
// proposer that lands such a slot cannot have it silently treated as valid off-chain; it is routed to
|
|
67
|
+
// invalid-attestation and invalidated. The gossip receipt path (recoverCoordinationSigner) stays
|
|
68
|
+
// lenient with allowYParityAsV; A-1351 normalizes on pool ingress and before the L1 bundle.
|
|
64
69
|
try {
|
|
65
|
-
const recoveredAddress = recoverAddress(hashedPayload, attestation.signature
|
|
70
|
+
const recoveredAddress = recoverAddress(hashedPayload, attestation.signature);
|
|
66
71
|
return { address: recoveredAddress, status: 'recovered-from-signature' as const };
|
|
67
72
|
} catch {
|
|
68
73
|
// Signature present but recovery failed
|
|
@@ -63,8 +63,18 @@ export type CheckpointQuery =
|
|
|
63
63
|
| { slot: SlotNumber }
|
|
64
64
|
| { tag: 'checkpointed' | 'proven' | 'finalized' };
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Query a range of confirmed checkpoints by start/limit, by slot anchor, or by epoch.
|
|
68
|
+
*
|
|
69
|
+
* The `fromSlot` variant walks the slot index: it returns up to `limit` checkpoints anchored at
|
|
70
|
+
* `fromSlot`, ordered nearest-first. With `reverse` it takes the checkpoints at or before the slot
|
|
71
|
+
* (descending); otherwise the checkpoints at or after it (ascending). Use `limit: 1, reverse: true`
|
|
72
|
+
* to find the latest checkpoint at or before a slot in a single range scan.
|
|
73
|
+
*/
|
|
74
|
+
export type CheckpointsQuery =
|
|
75
|
+
| { from: CheckpointNumber; limit: number }
|
|
76
|
+
| { fromSlot: SlotNumber; limit: number; reverse?: boolean }
|
|
77
|
+
| { epoch: EpochNumber };
|
|
68
78
|
|
|
69
79
|
/**
|
|
70
80
|
* Lookup a proposed (archiver-internal, not-yet-L1-confirmed) checkpoint.
|
|
@@ -81,6 +91,7 @@ export const CheckpointQuerySchema: z.ZodType<CheckpointQuery, unknown> = z.unio
|
|
|
81
91
|
|
|
82
92
|
export const CheckpointsQuerySchema: z.ZodType<CheckpointsQuery, unknown> = z.union([
|
|
83
93
|
z.object({ from: CheckpointNumberSchema, limit: z.number().int().min(1) }).strict(),
|
|
94
|
+
z.object({ fromSlot: SlotNumberSchema, limit: z.number().int().min(1), reverse: z.boolean().optional() }).strict(),
|
|
84
95
|
z.object({ epoch: EpochNumberSchema }).strict(),
|
|
85
96
|
]);
|
|
86
97
|
|
|
@@ -241,7 +252,10 @@ export interface L2BlockSource {
|
|
|
241
252
|
|
|
242
253
|
/**
|
|
243
254
|
* Looks up a proposed (archiver-internal, not-yet-L1-confirmed) checkpoint.
|
|
244
|
-
* Returns the latest proposed entry when called with no args or `{ tag: 'proposed' }
|
|
255
|
+
* Returns the latest proposed entry when called with no args or `{ tag: 'proposed' }`; since a
|
|
256
|
+
* proposed entry can only be stored with a checkpoint number beyond the confirmed frontier (and is
|
|
257
|
+
* deleted on confirmation), the latest entry is always the leading one. Callers derive the proposed
|
|
258
|
+
* tip from the payload (checkpoint number, and last block `startBlock + blockCount - 1`).
|
|
245
259
|
* With `{ number }` or `{ slot }`, returns the matching entry or undefined.
|
|
246
260
|
* Never falls back to confirmed checkpoints.
|
|
247
261
|
*/
|
|
@@ -321,42 +335,36 @@ export type ArchiverEmitter = TypedEventEmitter<{
|
|
|
321
335
|
[L2BlockSourceEvents.DescendentOfInvalidAttestationsCheckpointDetected]: (
|
|
322
336
|
args: DescendentOfInvalidAttestationsCheckpointEvent,
|
|
323
337
|
) => void;
|
|
338
|
+
[L2BlockSourceEvents.L2BlockSourceUpdated]: (args: L2BlockSourceUpdatedEvent) => void;
|
|
324
339
|
}>;
|
|
325
340
|
export interface L2BlockSourceEventEmitter extends L2BlockSource {
|
|
326
341
|
events: ArchiverEmitter;
|
|
327
342
|
}
|
|
328
343
|
|
|
329
344
|
/**
|
|
330
|
-
* Identifier for L2 block tags. Internal counterpart to {@link BlockTag} that
|
|
331
|
-
*
|
|
332
|
-
* archiver side) and omits `latest` (which is an alias for `proposed` accepted only at
|
|
333
|
-
* the public RPC surface).
|
|
345
|
+
* Identifier for L2 block tags. Internal counterpart to {@link BlockTag} that omits `latest`
|
|
346
|
+
* (which is an alias for `proposed` accepted only at the public RPC surface).
|
|
334
347
|
*
|
|
335
348
|
* - proposed: Latest block proposed on L2.
|
|
336
|
-
* - proposedCheckpoint: Latest block in the most recent proposed checkpoint (archiver-internal).
|
|
337
349
|
* - checkpointed: Latest block whose enclosing checkpoint has been published on L1.
|
|
338
350
|
* - proven: Latest block whose enclosing checkpoint has been proven on L1.
|
|
339
351
|
* - finalized: Latest block whose proving L1 transaction has reached L1 finality.
|
|
340
|
-
*
|
|
341
|
-
* TODO(palla): Remove `proposedCheckpoint` and unify with `proposed`.
|
|
342
352
|
*/
|
|
343
|
-
export type L2BlockTag = 'proposed' | '
|
|
353
|
+
export type L2BlockTag = 'proposed' | 'checkpointed' | 'proven' | 'finalized';
|
|
344
354
|
|
|
345
355
|
/** Tips of the L2 chain. */
|
|
346
356
|
export type L2Tips = {
|
|
347
357
|
proposed: L2BlockId;
|
|
348
358
|
checkpointed: L2TipId;
|
|
349
|
-
proposedCheckpoint: L2TipId;
|
|
350
359
|
proven: L2TipId;
|
|
351
360
|
finalized: L2TipId;
|
|
352
361
|
};
|
|
353
362
|
|
|
354
363
|
/**
|
|
355
|
-
* Tips of the L2 chain as tracked by a local provider (world-state, l2-tips-store).
|
|
356
|
-
*
|
|
357
|
-
* is only meaningful on the archiver side via {@link L2BlockSource}.
|
|
364
|
+
* Tips of the L2 chain as tracked by a local provider (world-state, l2-tips-store). Identical to
|
|
365
|
+
* {@link L2Tips}; the alias is retained for call sites that document a local-only provenance.
|
|
358
366
|
*/
|
|
359
|
-
export type LocalL2Tips =
|
|
367
|
+
export type LocalL2Tips = L2Tips;
|
|
360
368
|
|
|
361
369
|
export const GENESIS_CHECKPOINT_HEADER_HASH = CheckpointHeader.empty().hash();
|
|
362
370
|
|
|
@@ -380,6 +388,28 @@ export function makeL2CheckpointId(number: CheckpointNumber, hash: string): Chec
|
|
|
380
388
|
return { number, hash };
|
|
381
389
|
}
|
|
382
390
|
|
|
391
|
+
function l2BlockIdEquals(a: L2BlockId, b: L2BlockId): boolean {
|
|
392
|
+
return a.number === b.number && a.hash === b.hash;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function l2TipIdEquals(a: L2TipId, b: L2TipId): boolean {
|
|
396
|
+
return (
|
|
397
|
+
l2BlockIdEquals(a.block, b.block) &&
|
|
398
|
+
a.checkpoint.number === b.checkpoint.number &&
|
|
399
|
+
a.checkpoint.hash === b.checkpoint.hash
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Returns whether two {@link L2Tips} snapshots agree on every tier (proposed, checkpointed, proven, finalized). */
|
|
404
|
+
export function l2TipsEqual(a: L2Tips, b: L2Tips): boolean {
|
|
405
|
+
return (
|
|
406
|
+
l2BlockIdEquals(a.proposed, b.proposed) &&
|
|
407
|
+
l2TipIdEquals(a.checkpointed, b.checkpointed) &&
|
|
408
|
+
l2TipIdEquals(a.proven, b.proven) &&
|
|
409
|
+
l2TipIdEquals(a.finalized, b.finalized)
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
383
413
|
const L2BlockIdSchema = z.object({
|
|
384
414
|
number: BlockNumberSchema,
|
|
385
415
|
hash: z.string(),
|
|
@@ -398,7 +428,6 @@ const L2TipIdSchema = z.object({
|
|
|
398
428
|
export const L2TipsSchema = z.object({
|
|
399
429
|
proposed: L2BlockIdSchema,
|
|
400
430
|
checkpointed: L2TipIdSchema,
|
|
401
|
-
proposedCheckpoint: L2TipIdSchema,
|
|
402
431
|
proven: L2TipIdSchema,
|
|
403
432
|
finalized: L2TipIdSchema,
|
|
404
433
|
});
|
|
@@ -411,8 +440,26 @@ export enum L2BlockSourceEvents {
|
|
|
411
440
|
InvalidAttestationsCheckpointDetected = 'invalidCheckpointDetected',
|
|
412
441
|
CheckpointEquivocationDetected = 'checkpointEquivocationDetected',
|
|
413
442
|
DescendentOfInvalidAttestationsCheckpointDetected = 'descendentOfInvalidAttestationsCheckpointDetected',
|
|
443
|
+
L2BlockSourceUpdated = 'l2BlockSourceUpdated',
|
|
414
444
|
}
|
|
415
445
|
|
|
446
|
+
/**
|
|
447
|
+
* Aggregate event emitted once per committed archiver sync pass that mutated local state. Carries the chain tips
|
|
448
|
+
* before and after the pass, and the blocks added during it. Consumers compare `fromTips` and `toTips` to learn what
|
|
449
|
+
* moved; there is no separate `changed` section.
|
|
450
|
+
*
|
|
451
|
+
* This is an optimization signal that lets a block stream reconcile immediately on an archiver update rather than
|
|
452
|
+
* waiting for its next poll. Polling remains the correctness fallback, so a missed event only affects latency.
|
|
453
|
+
* `blocksAdded` are hydrated blocks already in hand from the sync pass, so a triggered sync that is caught up to
|
|
454
|
+
* `fromTips` can reuse them (and `toTips`) instead of re-reading the store.
|
|
455
|
+
*/
|
|
456
|
+
export type L2BlockSourceUpdatedEvent = {
|
|
457
|
+
type: 'l2BlockSourceUpdated';
|
|
458
|
+
fromTips: L2Tips;
|
|
459
|
+
toTips: L2Tips;
|
|
460
|
+
blocksAdded: readonly L2Block[];
|
|
461
|
+
};
|
|
462
|
+
|
|
416
463
|
export type L2BlockProvenEvent = {
|
|
417
464
|
type: 'l2BlockProven';
|
|
418
465
|
blockNumber: BlockNumber;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
3
|
+
|
|
4
|
+
import type { BlockData } from '../block_data.js';
|
|
5
|
+
import type { L2Block } from '../l2_block.js';
|
|
6
|
+
import {
|
|
7
|
+
type ArchiverEmitter,
|
|
8
|
+
type BlockQuery,
|
|
9
|
+
type BlocksQuery,
|
|
10
|
+
type L2BlockSource,
|
|
11
|
+
type L2BlockSourceEventEmitter,
|
|
12
|
+
L2BlockSourceEvents,
|
|
13
|
+
type L2BlockSourceUpdatedEvent,
|
|
14
|
+
type L2Tips,
|
|
15
|
+
} from '../l2_block_source.js';
|
|
16
|
+
import { type L2BlockStreamEventHandler, type L2BlockStreamLocalDataProvider, localTipsMatch } from './interfaces.js';
|
|
17
|
+
import { L2BlockStream, type L2BlockStreamOptions, type L2BlockStreamSource } from './l2_block_stream.js';
|
|
18
|
+
|
|
19
|
+
/** Derives the metadata-only {@link BlockData} view of a hydrated {@link L2Block}. */
|
|
20
|
+
async function l2BlockToBlockData(block: L2Block): Promise<BlockData> {
|
|
21
|
+
return {
|
|
22
|
+
header: block.header,
|
|
23
|
+
archive: block.archive,
|
|
24
|
+
blockHash: await block.hash(),
|
|
25
|
+
checkpointNumber: block.checkpointNumber,
|
|
26
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Returns the event emitter of a source that exposes one, or undefined for plain (e.g. RPC-backed) sources. */
|
|
31
|
+
function getEmitter(source: L2BlockSource | L2BlockSourceEventEmitter): ArchiverEmitter | undefined {
|
|
32
|
+
return 'events' in source ? source.events : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Fast-path context for a single sync pass: blocks to serve by number, plus the tips to report as the source's. */
|
|
36
|
+
type ActiveUpdate = { byNumber: Map<number, L2Block>; toTips: L2Tips };
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Wraps a block source so a single sync pass can be served from blocks delivered by an aggregate update event,
|
|
40
|
+
* avoiding round-trips to archiver storage. The fast path is only armed (via {@link activate}) for a pass that is
|
|
41
|
+
* confirmed caught up to the event's pre-pass tips: in that case the event's `blocksAdded` contiguously cover the
|
|
42
|
+
* pass's download range and `toTips` is the exact post-pass tip, so `getL2Tips` can report it without querying the
|
|
43
|
+
* source. When the fast path is not armed, every read delegates to the source, so a stale or partial cache never
|
|
44
|
+
* changes the sync outcome.
|
|
45
|
+
*/
|
|
46
|
+
class HotBlockSourceAdapter implements L2BlockStreamSource {
|
|
47
|
+
/** Set for the duration of one fast-path pass; undefined when reads must delegate to the source. */
|
|
48
|
+
private active: ActiveUpdate | undefined;
|
|
49
|
+
|
|
50
|
+
constructor(
|
|
51
|
+
private readonly source: L2BlockStreamSource,
|
|
52
|
+
private readonly log: Logger,
|
|
53
|
+
) {}
|
|
54
|
+
|
|
55
|
+
/** Arms the fast path for the current pass: serve these blocks and report `toTips` as the source tips. */
|
|
56
|
+
public activate(blocks: readonly L2Block[], toTips: L2Tips): void {
|
|
57
|
+
const byNumber = new Map<number, L2Block>();
|
|
58
|
+
for (const block of blocks) {
|
|
59
|
+
byNumber.set(block.number, block);
|
|
60
|
+
}
|
|
61
|
+
this.active = { byNumber, toTips };
|
|
62
|
+
this.log.trace(`Armed hot-block fast path`, { blocks: byNumber.size, toTips });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Disarms the fast path so subsequent reads delegate to the source again. */
|
|
66
|
+
public deactivate(): void {
|
|
67
|
+
this.active = undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
71
|
+
return this.active ? Promise.resolve(this.active.toTips) : this.source.getL2Tips();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public getBlocks(query: BlocksQuery): Promise<L2Block[]> {
|
|
75
|
+
const served = this.active ? this.tryServeBlocksFromCache(query) : undefined;
|
|
76
|
+
return served ? Promise.resolve(served) : this.source.getBlocks(query);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public getBlockData(query: BlockQuery): Promise<BlockData | undefined> {
|
|
80
|
+
if (this.active && 'number' in query) {
|
|
81
|
+
const block = this.active.byNumber.get(query.number);
|
|
82
|
+
if (block) {
|
|
83
|
+
return l2BlockToBlockData(block);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return this.source.getBlockData(query);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Serves a block range from the cache only when it is fully covered by contiguous cached blocks. */
|
|
90
|
+
private tryServeBlocksFromCache(query: BlocksQuery): L2Block[] | undefined {
|
|
91
|
+
// Only the by-range form is cacheable, and only for the full (not checkpointed-only) chain: the cache may hold
|
|
92
|
+
// uncheckpointed blocks that an onlyCheckpointed query must not receive.
|
|
93
|
+
if (!this.active || !('from' in query) || query.onlyCheckpointed) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const from = query.from;
|
|
97
|
+
const to = from + query.limit - 1;
|
|
98
|
+
const blocks: L2Block[] = [];
|
|
99
|
+
for (let n = from; n <= to; n++) {
|
|
100
|
+
const block = this.active.byNumber.get(n);
|
|
101
|
+
if (!block) {
|
|
102
|
+
// A gap inside the requested range: bail out and let the source serve the whole range.
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
blocks.push(block);
|
|
106
|
+
}
|
|
107
|
+
return blocks;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Event-driven wrapper around {@link L2BlockStream}. Subscribes to the source's aggregate `l2BlockSourceUpdated`
|
|
113
|
+
* event (when the source exposes one) to trigger an immediate reconciliation, while keeping the periodic poll as
|
|
114
|
+
* the correctness fallback. Subsystems keep consuming the same {@link L2BlockStreamEvent}s; the archiver aggregate
|
|
115
|
+
* event is handled entirely here.
|
|
116
|
+
*
|
|
117
|
+
* The event is passed through to the sync pass via {@link RunningPromise.trigger}. If, at the time the pass runs,
|
|
118
|
+
* the stream's local tips match the event's `fromTips` (it is caught up to where the event began), the event's
|
|
119
|
+
* hydrated blocks are served back through a hot-block cache and the event's `toTips` is reported as the source tips
|
|
120
|
+
* — so the triggered sync re-reads neither block bodies nor tips from the archiver. Otherwise the pass delegates
|
|
121
|
+
* entirely to the source, and the periodic poll guarantees eventual catch-up.
|
|
122
|
+
*/
|
|
123
|
+
export class EventDrivenL2BlockStream {
|
|
124
|
+
private readonly adapter: HotBlockSourceAdapter;
|
|
125
|
+
private readonly blockStream: L2BlockStream;
|
|
126
|
+
private readonly runningPromise: RunningPromise<L2BlockSourceUpdatedEvent>;
|
|
127
|
+
private readonly emitter: ArchiverEmitter | undefined;
|
|
128
|
+
private started = false;
|
|
129
|
+
|
|
130
|
+
private readonly onSourceUpdated = (event: L2BlockSourceUpdatedEvent) => {
|
|
131
|
+
// Fire-and-forget: trigger coalesces with any in-flight or periodic pass (see RunningPromise.trigger), so a
|
|
132
|
+
// burst of events does not run passes concurrently. Errors are swallowed by the inner stream's own handler.
|
|
133
|
+
void this.runningPromise
|
|
134
|
+
.trigger(event)
|
|
135
|
+
.catch(err => this.log.error(`Error in event-triggered block stream sync`, err));
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
constructor(
|
|
139
|
+
source: L2BlockSource | L2BlockSourceEventEmitter,
|
|
140
|
+
private readonly localData: L2BlockStreamLocalDataProvider,
|
|
141
|
+
handler: L2BlockStreamEventHandler,
|
|
142
|
+
private readonly log = createLogger('types:event_driven_block_stream'),
|
|
143
|
+
opts: L2BlockStreamOptions = {},
|
|
144
|
+
) {
|
|
145
|
+
this.adapter = new HotBlockSourceAdapter(source, log);
|
|
146
|
+
// The inner stream's own RunningPromise is never started; this wrapper owns the polling loop and drives the
|
|
147
|
+
// stream through `sync()` (which runs `work()` directly when the inner loop is stopped).
|
|
148
|
+
this.blockStream = new L2BlockStream(this.adapter, localData, handler, log, opts);
|
|
149
|
+
this.runningPromise = new RunningPromise<L2BlockSourceUpdatedEvent>(
|
|
150
|
+
this.runPass.bind(this),
|
|
151
|
+
log,
|
|
152
|
+
opts.pollIntervalMS ?? 1000,
|
|
153
|
+
);
|
|
154
|
+
this.emitter = getEmitter(source);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public start(): void {
|
|
158
|
+
if (this.started) {
|
|
159
|
+
this.log.warn(`Attempted to start an already-started event-driven block stream`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.started = true;
|
|
163
|
+
this.emitter?.on(L2BlockSourceEvents.L2BlockSourceUpdated, this.onSourceUpdated);
|
|
164
|
+
this.runningPromise.start();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public async stop(): Promise<void> {
|
|
168
|
+
this.started = false;
|
|
169
|
+
this.emitter?.off(L2BlockSourceEvents.L2BlockSourceUpdated, this.onSourceUpdated);
|
|
170
|
+
await this.runningPromise.stop();
|
|
171
|
+
await this.blockStream.stop();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public isRunning(): boolean {
|
|
175
|
+
return this.runningPromise.isRunning();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Runs a synchronization pass now, bypassing the poll interval, and resolves once that pass completes. Concurrent
|
|
180
|
+
* callers and periodic ticks coalesce onto a single pass; a caller that coalesces onto an already in-flight pass
|
|
181
|
+
* can resolve against a pass that began just before it, so this guarantees freshness only up to that coalescing
|
|
182
|
+
* window. The periodic poll and per-pass reorg handling make the gap a latency effect, never a correctness one.
|
|
183
|
+
*/
|
|
184
|
+
public sync(): Promise<void> {
|
|
185
|
+
return this.runningPromise.trigger();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Runs a single pass over the underlying block stream. When triggered by an aggregate event and the stream is
|
|
190
|
+
* caught up to the event's pre-pass tips, the event's blocks and tips serve the pass directly; the fast path is
|
|
191
|
+
* always disarmed afterwards so a subsequent poll-driven pass reads from the source.
|
|
192
|
+
*/
|
|
193
|
+
private async runPass(event?: L2BlockSourceUpdatedEvent): Promise<void> {
|
|
194
|
+
if (event) {
|
|
195
|
+
const localTips = await this.localData.getL2Tips();
|
|
196
|
+
if (localTipsMatch(localTips, event.fromTips)) {
|
|
197
|
+
this.adapter.activate(event.blocksAdded, event.toTips);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
await this.blockStream.sync();
|
|
203
|
+
} finally {
|
|
204
|
+
this.adapter.deactivate();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
|
|
3
|
-
import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
|
|
4
3
|
import type { L2Block } from '../l2_block.js';
|
|
5
|
-
import type { CheckpointId, L2BlockId, L2TipId, LocalL2Tips } from '../l2_block_source.js';
|
|
4
|
+
import type { CheckpointId, L2BlockId, L2TipId, L2Tips, LocalL2Tips } from '../l2_block_source.js';
|
|
6
5
|
|
|
7
6
|
/** Provides the current chain tips. Implemented by world-state, l2-tips-store, and AztecNode. */
|
|
8
7
|
export interface L2TipsProvider {
|
|
@@ -21,7 +20,7 @@ export type LocalL2BlockId = { number: BlockNumber; hash?: string };
|
|
|
21
20
|
*/
|
|
22
21
|
export type LocalChainTips = {
|
|
23
22
|
proposed: LocalL2BlockId;
|
|
24
|
-
checkpointed?: { checkpoint: CheckpointId };
|
|
23
|
+
checkpointed?: { block: LocalL2BlockId; checkpoint: CheckpointId };
|
|
25
24
|
proven: { block: LocalL2BlockId };
|
|
26
25
|
finalized: { block: LocalL2BlockId };
|
|
27
26
|
};
|
|
@@ -36,6 +35,40 @@ export interface L2BlockStreamLocalDataProvider {
|
|
|
36
35
|
getL2BlockHash(number: number): Promise<string | undefined>;
|
|
37
36
|
}
|
|
38
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Returns whether a local block id differs from a source block id. Compares block number and, when the local hash is
|
|
40
|
+
* known, block hash. The hash comparison is skipped when the local hash is undefined: world-state legitimately
|
|
41
|
+
* reports `undefined` hashes for tips ahead of its synced range, and comparing against an undefined hash would treat
|
|
42
|
+
* such a tip as different on every poll. An `undefined` local block (no local tip yet) always counts as differing.
|
|
43
|
+
*/
|
|
44
|
+
export function localBlockIdDiffers(localBlock: LocalL2BlockId | undefined, sourceBlock: L2BlockId): boolean {
|
|
45
|
+
if (localBlock === undefined) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (sourceBlock.number !== localBlock.number) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (localBlock.hash === undefined) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return sourceBlock.hash !== localBlock.hash;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns whether the local chain tips agree with the given source tips on every tier the local provider exposes.
|
|
59
|
+
* Each tier is compared at the block level via {@link localBlockIdDiffers} (so an unresolved local hash matches on
|
|
60
|
+
* number alone); checkpoint ids are not compared, mirroring the stream's own tier reconciliation. The optional
|
|
61
|
+
* `checkpointed` tier is only compared when present (it is absent when the stream ignores checkpoints).
|
|
62
|
+
*/
|
|
63
|
+
export function localTipsMatch(local: LocalChainTips, source: L2Tips): boolean {
|
|
64
|
+
return (
|
|
65
|
+
!localBlockIdDiffers(local.proposed, source.proposed) &&
|
|
66
|
+
(local.checkpointed === undefined || !localBlockIdDiffers(local.checkpointed.block, source.checkpointed.block)) &&
|
|
67
|
+
!localBlockIdDiffers(local.proven.block, source.proven.block) &&
|
|
68
|
+
!localBlockIdDiffers(local.finalized.block, source.finalized.block)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
39
72
|
/** Interface to a handler of events emitted. */
|
|
40
73
|
export interface L2BlockStreamEventHandler {
|
|
41
74
|
handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
|
|
@@ -46,10 +79,24 @@ export type L2BlockStreamEvent =
|
|
|
46
79
|
type: 'blocks-added';
|
|
47
80
|
blocks: L2Block[];
|
|
48
81
|
}
|
|
49
|
-
| /**
|
|
82
|
+
| /**
|
|
83
|
+
* Reports the new proposed tip of the chain. Emitted once per sync pass when the source's proposed tip differs
|
|
84
|
+
* from the pre-pass local one (downloads, a prune, or a thin tip movement). Carries only the block id; in block
|
|
85
|
+
* mode the corresponding payloads arrive via preceding `blocks-added` events, while in tips-only mode this is the
|
|
86
|
+
* sole signal that the proposed tip moved. Consumers that only track the proposed tip can ignore `blocks-added`
|
|
87
|
+
* entirely and anchor on this event instead.
|
|
88
|
+
*/ {
|
|
89
|
+
type: 'chain-proposed';
|
|
90
|
+
block: L2BlockId;
|
|
91
|
+
}
|
|
92
|
+
| /**
|
|
93
|
+
* Reports a new checkpointed tip. Emitted at most once per sync pass when the source's checkpointed tip
|
|
94
|
+
* leads the local one. Carries only the block + checkpoint ids; consumers that need the full checkpoint
|
|
95
|
+
* payload fetch it on demand from the block source.
|
|
96
|
+
*/ {
|
|
50
97
|
type: 'chain-checkpointed';
|
|
51
|
-
checkpoint: PublishedCheckpoint;
|
|
52
98
|
block: L2BlockId;
|
|
99
|
+
checkpoint: CheckpointId;
|
|
53
100
|
}
|
|
54
101
|
| /**
|
|
55
102
|
* Reports last correct block (new tip of the proposed chain). Note that this is not necessarily the anchor block
|
|
@@ -77,4 +124,11 @@ export type L2BlockStreamEvent =
|
|
|
77
124
|
|
|
78
125
|
export type L2TipsStore = L2BlockStreamEventHandler &
|
|
79
126
|
L2TipsProvider &
|
|
80
|
-
Pick<L2BlockStreamLocalDataProvider, 'getL2BlockHash'
|
|
127
|
+
Pick<L2BlockStreamLocalDataProvider, 'getL2BlockHash'> & {
|
|
128
|
+
/**
|
|
129
|
+
* Records `(number → hash)` witnesses into the walk-back hash index without moving any tip cursor. Consumers that
|
|
130
|
+
* materialize per-height state should record a witness for each height they materialize, so a reorg below the
|
|
131
|
+
* nearest sparse anchor does not produce an over-deep prune event. See {@link L2TipsStoreBase.recordBlockHashes}.
|
|
132
|
+
*/
|
|
133
|
+
recordBlockHashes(blocks: L2BlockId[]): Promise<void>;
|
|
134
|
+
};
|