@aztec/p2p 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a
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/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +9 -1
- package/dest/client/factory.d.ts +3 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +12 -9
- package/dest/client/interface.d.ts +6 -4
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +11 -8
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +53 -17
- package/dest/config.d.ts +43 -17
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +48 -8
- package/dest/errors/reqresp.error.d.ts +1 -20
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +0 -21
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +93 -55
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +258 -195
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +175 -59
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +6 -4
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +17 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +73 -83
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +18 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +3 -4
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +13 -11
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +5 -2
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +5 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +8 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +28 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +8 -15
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +3 -3
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +1 -0
- package/dest/msg_validators/tx_validator/factory.d.ts +5 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +11 -7
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/discv5/discV5_service.d.ts +2 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +35 -8
- package/dest/services/dummy_service.d.ts +10 -17
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +9 -18
- package/dest/services/libp2p/libp2p_service.d.ts +19 -21
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +147 -148
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +35 -44
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +8 -5
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
- package/dest/services/reqresp/interface.d.ts +3 -10
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +0 -9
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
- package/dest/services/reqresp/reqresp.d.ts +5 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +16 -206
- package/dest/services/service.d.ts +7 -13
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +2 -23
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +2 -55
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +12 -28
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +43 -83
- package/dest/services/tx_collection/index.d.ts +2 -3
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +0 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +0 -2
- package/dest/services/tx_collection/tx_collection.d.ts +35 -51
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +275 -119
- package/dest/services/tx_collection/tx_collection_sink.d.ts +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +2 -2
- package/dest/services/tx_file_store/tx_file_store.d.ts +1 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +4 -14
- package/dest/services/tx_provider.d.ts +3 -1
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +3 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +13 -7
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +12 -37
- package/dest/test-helpers/reqresp-nodes.d.ts +4 -5
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +11 -15
- package/dest/test-helpers/test_tx_provider.d.ts +3 -1
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
- package/dest/test-helpers/test_tx_provider.js +3 -0
- package/dest/test-helpers/testbench-utils.d.ts +12 -14
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +19 -14
- package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +13 -24
- package/dest/testbench/worker_client_manager.d.ts +3 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +2 -8
- package/dest/util.d.ts +11 -6
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +15 -14
- package/src/bootstrap/bootstrap.ts +9 -1
- package/src/client/factory.ts +20 -5
- package/src/client/interface.ts +6 -10
- package/src/client/p2p_client.ts +61 -36
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +94 -6
- package/src/errors/reqresp.error.ts +0 -25
- package/src/mem_pools/attestation_pool/attestation_pool.ts +309 -238
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +198 -62
- package/src/mem_pools/attestation_pool/mocks.ts +13 -8
- package/src/mem_pools/instrumentation.ts +5 -1
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +73 -90
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -1
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +11 -7
- package/src/msg_validators/clock_tolerance.ts +13 -12
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +9 -2
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +14 -2
- package/src/msg_validators/proposal_validator/proposal_validator.ts +39 -2
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -12
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +3 -3
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/data_validator.ts +2 -0
- package/src/msg_validators/tx_validator/factory.ts +15 -6
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/discv5/discV5_service.ts +38 -5
- package/src/services/dummy_service.ts +12 -43
- package/src/services/libp2p/libp2p_service.ts +169 -167
- package/src/services/peer-manager/peer_manager.ts +1 -0
- package/src/services/reqresp/README.md +0 -14
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +39 -52
- package/src/services/reqresp/batch-tx-requester/interface.ts +11 -4
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
- package/src/services/reqresp/interface.ts +2 -38
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
- package/src/services/reqresp/reqresp.ts +11 -251
- package/src/services/service.ts +9 -30
- package/src/services/tx_collection/config.ts +3 -80
- package/src/services/tx_collection/file_store_tx_collection.ts +54 -103
- package/src/services/tx_collection/index.ts +1 -6
- package/src/services/tx_collection/instrumentation.ts +1 -7
- package/src/services/tx_collection/tx_collection.ts +330 -173
- package/src/services/tx_collection/tx_collection_sink.ts +2 -2
- package/src/services/tx_file_store/tx_file_store.ts +5 -17
- package/src/services/tx_provider.ts +5 -0
- package/src/test-helpers/make-test-p2p-clients.ts +1 -0
- package/src/test-helpers/mock-pubsub.ts +17 -60
- package/src/test-helpers/reqresp-nodes.ts +8 -20
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +23 -27
- package/src/testbench/p2p_client_testbench_worker.ts +16 -42
- package/src/testbench/worker_client_manager.ts +4 -19
- package/src/util.ts +32 -17
- package/src/versioning.ts +3 -33
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -318
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
- package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -51
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -311
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -57
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -211
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -357
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
- package/src/services/tx_collection/fast_tx_collection.ts +0 -361
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -108
- package/src/services/tx_collection/slow_tx_collection.ts +0 -266
|
@@ -53,6 +53,7 @@ import type { TxMetaData } from '../../mem_pools/tx_pool_v2/tx_metadata.js';
|
|
|
53
53
|
import { AggregateTxValidator } from './aggregate_tx_validator.js';
|
|
54
54
|
import { ArchiveCache } from './archive_cache.js';
|
|
55
55
|
import { type ArchiveSource, BlockHeaderTxValidator } from './block_header_validator.js';
|
|
56
|
+
import { CachedTxValidator } from './cached_tx_validator.js';
|
|
56
57
|
import { ContractInstanceTxValidator } from './contract_instance_validator.js';
|
|
57
58
|
import { DataTxValidator } from './data_validator.js';
|
|
58
59
|
import { DoubleSpendTxValidator, type NullifierSource } from './double_spend_validator.js';
|
|
@@ -64,6 +65,7 @@ import { SizeTxValidator } from './size_validator.js';
|
|
|
64
65
|
import { TimestampTxValidator } from './timestamp_validator.js';
|
|
65
66
|
import { TxPermittedValidator } from './tx_permitted_validator.js';
|
|
66
67
|
import { TxProofValidator } from './tx_proof_validator.js';
|
|
68
|
+
import { TxValidationCache } from './tx_validation_cache.js';
|
|
67
69
|
|
|
68
70
|
/**
|
|
69
71
|
* A validator paired with a peer penalty severity.
|
|
@@ -210,8 +212,9 @@ function createTxValidatorForMinimumTxIntegrityChecks(
|
|
|
210
212
|
rollupVersion: number;
|
|
211
213
|
},
|
|
212
214
|
bindings?: LoggerBindings,
|
|
215
|
+
cache?: TxValidationCache,
|
|
213
216
|
): TxValidator {
|
|
214
|
-
|
|
217
|
+
const aggregate = new AggregateTxValidator(
|
|
215
218
|
new MetadataTxValidator(
|
|
216
219
|
{
|
|
217
220
|
l1ChainId: new Fr(l1ChainId),
|
|
@@ -222,10 +225,14 @@ function createTxValidatorForMinimumTxIntegrityChecks(
|
|
|
222
225
|
bindings,
|
|
223
226
|
),
|
|
224
227
|
new SizeTxValidator(bindings),
|
|
225
|
-
new DataTxValidator(bindings),
|
|
228
|
+
CachedTxValidator.new(new DataTxValidator(bindings), cache),
|
|
226
229
|
new ContractInstanceTxValidator(bindings),
|
|
227
|
-
new TxProofValidator(verifier, bindings),
|
|
230
|
+
CachedTxValidator.new(new TxProofValidator(verifier, bindings), cache),
|
|
228
231
|
);
|
|
232
|
+
|
|
233
|
+
// This validator is not state-dependent so we can cache it.
|
|
234
|
+
const identifier = Symbol('TxValidatorForMinimumTxIntegrityChecks');
|
|
235
|
+
return CachedTxValidator.newWithIdentifier(aggregate, identifier, cache);
|
|
229
236
|
}
|
|
230
237
|
|
|
231
238
|
/**
|
|
@@ -234,7 +241,7 @@ function createTxValidatorForMinimumTxIntegrityChecks(
|
|
|
234
241
|
* are invalid against current state. State-dependent checks happen when the tx
|
|
235
242
|
* enters the pending pool or during block building.
|
|
236
243
|
*/
|
|
237
|
-
export function
|
|
244
|
+
export function createTxValidatorForOnDemandReceivedTxs(
|
|
238
245
|
verifier: ClientProtocolCircuitVerifier,
|
|
239
246
|
{
|
|
240
247
|
l1ChainId,
|
|
@@ -244,8 +251,9 @@ export function createTxValidatorForReqResponseReceivedTxs(
|
|
|
244
251
|
rollupVersion: number;
|
|
245
252
|
},
|
|
246
253
|
bindings?: LoggerBindings,
|
|
254
|
+
cache?: TxValidationCache,
|
|
247
255
|
): TxValidator {
|
|
248
|
-
return createTxValidatorForMinimumTxIntegrityChecks(verifier, { l1ChainId, rollupVersion }, bindings);
|
|
256
|
+
return createTxValidatorForMinimumTxIntegrityChecks(verifier, { l1ChainId, rollupVersion }, bindings, cache);
|
|
249
257
|
}
|
|
250
258
|
|
|
251
259
|
/**
|
|
@@ -263,8 +271,9 @@ export function createTxValidatorForBlockProposalReceivedTxs(
|
|
|
263
271
|
rollupVersion: number;
|
|
264
272
|
},
|
|
265
273
|
bindings?: LoggerBindings,
|
|
274
|
+
cache?: TxValidationCache,
|
|
266
275
|
): TxValidator {
|
|
267
|
-
return createTxValidatorForMinimumTxIntegrityChecks(verifier, { l1ChainId, rollupVersion }, bindings);
|
|
276
|
+
return createTxValidatorForMinimumTxIntegrityChecks(verifier, { l1ChainId, rollupVersion }, bindings, cache);
|
|
268
277
|
}
|
|
269
278
|
|
|
270
279
|
/**
|
|
@@ -3,6 +3,8 @@ import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/ser
|
|
|
3
3
|
import { TX_ERROR_INVALID_PROOF, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
export class TxProofValidator implements TxValidator<Tx> {
|
|
6
|
+
public readonly identifier: symbol = Symbol('TxProofValidator');
|
|
7
|
+
|
|
6
8
|
#log: Logger;
|
|
7
9
|
|
|
8
10
|
constructor(
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { LruMap } from '@aztec/foundation/collection';
|
|
2
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { Tx, TxValidationResult } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Minimal interface consumed by {@link CachedTxValidator}.
|
|
9
|
+
* Keeping the dependency on an interface lets callers (and tests) substitute any cache implementation.
|
|
10
|
+
*/
|
|
11
|
+
export interface ITxValidationCache {
|
|
12
|
+
/** Returns the cached promise if present, otherwise calls `validate`, caches its promise, and returns it. */
|
|
13
|
+
getOrValidate(
|
|
14
|
+
validatorSymbol: symbol,
|
|
15
|
+
tx: Tx,
|
|
16
|
+
validate: () => Promise<TxValidationResult>,
|
|
17
|
+
): Promise<TxValidationResult>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Caches per-validator tx validation results to avoid redundant work across repeated validation calls.
|
|
22
|
+
*
|
|
23
|
+
* The cache key is composed from the validator symbol and tx hash, ensuring results are
|
|
24
|
+
* scoped to the specific validator that produced them.
|
|
25
|
+
*
|
|
26
|
+
* Promises are stored before they are awaited, so concurrent calls for the same pair share
|
|
27
|
+
* a single in-flight validation rather than launching duplicate work.
|
|
28
|
+
*
|
|
29
|
+
* Entries are evicted in least-recently-used order once the cache reaches `maxSize`.
|
|
30
|
+
*/
|
|
31
|
+
export class TxValidationCache implements ITxValidationCache {
|
|
32
|
+
#log: Logger;
|
|
33
|
+
|
|
34
|
+
private readonly entries: LruMap<string, Promise<TxValidationResult>>;
|
|
35
|
+
// Remember hashes for known Tx object references to skip rehashing on subsequent lookups.
|
|
36
|
+
// WeakMap holds keys weakly, so an entry doesn't keep the Tx alive once nothing else references it.
|
|
37
|
+
private readonly txHashesCache: WeakMap<Tx, string> = new WeakMap();
|
|
38
|
+
|
|
39
|
+
constructor(maxSize: number) {
|
|
40
|
+
this.entries = new LruMap(maxSize);
|
|
41
|
+
this.#log = createLogger('p2p:tx_validation_cache');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Computes the cache key scoping a validation result to a specific validator and tx.
|
|
46
|
+
*
|
|
47
|
+
* @param validatorSymbol - The symbol of the validator.
|
|
48
|
+
* @param tx - The tx to compute the key for.
|
|
49
|
+
* @returns The cache key.
|
|
50
|
+
*
|
|
51
|
+
* Note: the key should NOT use the tx.hash because it can't be trusted at this point.
|
|
52
|
+
*/
|
|
53
|
+
public key(validatorSymbol: symbol, tx: Tx): string {
|
|
54
|
+
// Serializing the tx dominates cost (~5 ms). If we have already hashed this object, skip toBuffer + hash.
|
|
55
|
+
let hash = this.txHashesCache.get(tx);
|
|
56
|
+
if (hash === undefined) {
|
|
57
|
+
hash = createHash('sha256').update(tx.toBuffer()).digest('hex');
|
|
58
|
+
this.txHashesCache.set(tx, hash);
|
|
59
|
+
}
|
|
60
|
+
return `${Symbol.keyFor(validatorSymbol) ?? validatorSymbol.toString()}:${hash}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Returns the cached promise for the given key, or undefined if not cached. Refreshes recency. */
|
|
64
|
+
public get(key: string): Promise<TxValidationResult> | undefined {
|
|
65
|
+
return this.entries.get(key);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Stores a validation promise under the given key, evicting the LRU entry if at capacity. */
|
|
69
|
+
public set(key: string, result: Promise<TxValidationResult>): void {
|
|
70
|
+
this.entries.set(key, result);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Removes the cached validation promise for the given key. */
|
|
74
|
+
public delete(key: string): void {
|
|
75
|
+
this.entries.delete(key);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns the cached promise if present, otherwise calls `validate`, stores its promise
|
|
80
|
+
* immediately (before awaiting), and returns it.
|
|
81
|
+
*/
|
|
82
|
+
public getOrValidate(
|
|
83
|
+
validatorSymbol: symbol,
|
|
84
|
+
tx: Tx,
|
|
85
|
+
validate: () => Promise<TxValidationResult>,
|
|
86
|
+
): Promise<TxValidationResult> {
|
|
87
|
+
const key = this.key(validatorSymbol, tx);
|
|
88
|
+
const cached = this.get(key);
|
|
89
|
+
if (cached !== undefined) {
|
|
90
|
+
this.#log.debug('Returning cached tx validation result', {
|
|
91
|
+
validator: validatorSymbol.toString(),
|
|
92
|
+
txHash: tx.txHash.toString(),
|
|
93
|
+
key: key,
|
|
94
|
+
});
|
|
95
|
+
return cached;
|
|
96
|
+
}
|
|
97
|
+
const promise = validate();
|
|
98
|
+
this.set(key, promise);
|
|
99
|
+
return promise;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -38,6 +38,8 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
38
38
|
|
|
39
39
|
private startTime = 0;
|
|
40
40
|
|
|
41
|
+
private currentIp: string | undefined;
|
|
42
|
+
|
|
41
43
|
private handlers = {
|
|
42
44
|
onMultiaddrUpdated: this.onMultiaddrUpdated.bind(this),
|
|
43
45
|
onDiscovered: this.onDiscovered.bind(this),
|
|
@@ -53,8 +55,10 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
53
55
|
configOverrides: Partial<IDiscv5CreateOptions> = {},
|
|
54
56
|
) {
|
|
55
57
|
super();
|
|
58
|
+
|
|
56
59
|
const { p2pIp, p2pPort, p2pBroadcastPort, bootstrapNodes, trustedPeers, privatePeers } = config;
|
|
57
60
|
|
|
61
|
+
this.currentIp = p2pIp;
|
|
58
62
|
this.bootstrapNodeEnrs = bootstrapNodes.map(x => ENR.decodeTxt(x));
|
|
59
63
|
const privatePeerEnrs = new Set(privatePeers);
|
|
60
64
|
this.trustedPeerEnrs = trustedPeers.filter(x => !privatePeerEnrs.has(x)).map(x => ENR.decodeTxt(x));
|
|
@@ -96,7 +100,8 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
96
100
|
lookupTimeout: 2000,
|
|
97
101
|
requestTimeout: 2000,
|
|
98
102
|
allowUnverifiedSessions: true,
|
|
99
|
-
enrUpdate: !p2pIp
|
|
103
|
+
enrUpdate: config.queryForIp || !p2pIp,
|
|
104
|
+
pingInterval: config.queryForIp ? 10_000 : 300_000,
|
|
100
105
|
...configOverrides.config,
|
|
101
106
|
},
|
|
102
107
|
metricsRegistry,
|
|
@@ -127,11 +132,34 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
private onMultiaddrUpdated(m: Multiaddr) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
const newIp = m.nodeAddress().address;
|
|
136
|
+
const previousIp = this.currentIp;
|
|
137
|
+
|
|
138
|
+
if (newIp === previousIp) {
|
|
139
|
+
this.logger.debug('Discv5 confirmed current IP (no change)', { ip: newIp });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const multiAddrTcp = multiaddr(convertToMultiaddr(newIp, this.config.p2pBroadcastPort!, 'tcp'));
|
|
133
144
|
this.enr.setLocationMultiaddr(multiAddrTcp);
|
|
134
|
-
this.
|
|
145
|
+
this.currentIp = newIp;
|
|
146
|
+
|
|
147
|
+
if (previousIp) {
|
|
148
|
+
this.logger.info('IP address changed, ENR updated', {
|
|
149
|
+
previousIp,
|
|
150
|
+
newIp,
|
|
151
|
+
multiaddr: multiAddrTcp.toString(),
|
|
152
|
+
enr: this.enr.encodeTxt(),
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
this.logger.info('Initial IP discovered via discv5, ENR updated', {
|
|
156
|
+
ip: newIp,
|
|
157
|
+
multiaddr: multiAddrTcp.toString(),
|
|
158
|
+
enr: this.enr.encodeTxt(),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.emit('ip:changed', newIp);
|
|
135
163
|
}
|
|
136
164
|
|
|
137
165
|
public async start(): Promise<void> {
|
|
@@ -142,12 +170,17 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
142
170
|
await this.discv5.start();
|
|
143
171
|
this.startTime = Date.now();
|
|
144
172
|
|
|
173
|
+
const enrUpdateEnabled = this.config.queryForIp || !this.config.p2pIp;
|
|
145
174
|
this.logger.info(`DiscV5 service started`, {
|
|
146
175
|
nodeId: this.enr.nodeId,
|
|
147
176
|
peerId: this.peerId,
|
|
148
177
|
enrUdp: await this.enr.getFullMultiaddr('udp'),
|
|
149
178
|
enrTcp: await this.enr.getFullMultiaddr('tcp'),
|
|
150
179
|
versions: this.versions,
|
|
180
|
+
enrUpdateEnabled,
|
|
181
|
+
queryForIp: this.config.queryForIp,
|
|
182
|
+
configuredIp: this.config.p2pIp ?? 'none',
|
|
183
|
+
pingIntervalMs: this.config.queryForIp ? 10_000 : 300_000,
|
|
151
184
|
});
|
|
152
185
|
this.currentState = PeerDiscoveryState.RUNNING;
|
|
153
186
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Gossipable, PeerErrorSeverity, TopicType } from '@aztec/stdlib/p2p';
|
|
4
4
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -18,13 +18,13 @@ import type {
|
|
|
18
18
|
ReqRespSubProtocol,
|
|
19
19
|
ReqRespSubProtocolHandler,
|
|
20
20
|
ReqRespSubProtocolHandlers,
|
|
21
|
-
ReqRespSubProtocolValidators,
|
|
22
21
|
SubProtocolMap,
|
|
23
22
|
} from './reqresp/interface.js';
|
|
24
23
|
import type { GoodByeReason } from './reqresp/protocols/goodbye.js';
|
|
25
24
|
import { ReqRespStatus } from './reqresp/status.js';
|
|
26
25
|
import {
|
|
27
26
|
type P2PBlockReceivedCallback,
|
|
27
|
+
type P2PCheckpointAttestationCallback,
|
|
28
28
|
type P2PCheckpointReceivedCallback,
|
|
29
29
|
type P2PDuplicateAttestationCallback,
|
|
30
30
|
type P2PDuplicateProposalCallback,
|
|
@@ -37,6 +37,8 @@ import {
|
|
|
37
37
|
* A dummy implementation of the P2P Service.
|
|
38
38
|
*/
|
|
39
39
|
export class DummyP2PService implements P2PService {
|
|
40
|
+
private allNodesCheckpointReceivedCallback?: P2PCheckpointReceivedCallback;
|
|
41
|
+
|
|
40
42
|
updateConfig(_config: Partial<P2PReqRespConfig>): void {}
|
|
41
43
|
|
|
42
44
|
/** Returns an empty array for peers. */
|
|
@@ -87,10 +89,8 @@ export class DummyP2PService implements P2PService {
|
|
|
87
89
|
* Register a callback into the validator client for when a checkpoint proposal is received
|
|
88
90
|
*/
|
|
89
91
|
public registerValidatorCheckpointReceivedCallback(_callback: P2PCheckpointReceivedCallback) {}
|
|
90
|
-
public registerAllNodesCheckpointReceivedCallback(
|
|
91
|
-
|
|
92
|
-
public notifyOwnCheckpointProposal(_checkpoint: CheckpointProposalCore): Promise<void> {
|
|
93
|
-
return Promise.resolve();
|
|
92
|
+
public registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
93
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -103,6 +103,8 @@ export class DummyP2PService implements P2PService {
|
|
|
103
103
|
*/
|
|
104
104
|
public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {}
|
|
105
105
|
|
|
106
|
+
public registerCheckpointAttestationCallback(_callback: P2PCheckpointAttestationCallback): void {}
|
|
107
|
+
|
|
106
108
|
/**
|
|
107
109
|
* Sends a request to a peer.
|
|
108
110
|
* @param _protocol - The protocol to send the request on.
|
|
@@ -116,19 +118,6 @@ export class DummyP2PService implements P2PService {
|
|
|
116
118
|
return Promise.resolve(undefined);
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
/**
|
|
120
|
-
* Sends a batch request to a peer.
|
|
121
|
-
* @param _protocol - The protocol to send the request on.
|
|
122
|
-
* @param _requests - The requests to send.
|
|
123
|
-
* @returns The responses from the peer, otherwise undefined.
|
|
124
|
-
*/
|
|
125
|
-
public sendBatchRequest<Protocol extends ReqRespSubProtocol>(
|
|
126
|
-
_protocol: Protocol,
|
|
127
|
-
_requests: InstanceType<SubProtocolMap[Protocol]['request']>[],
|
|
128
|
-
): Promise<InstanceType<SubProtocolMap[Protocol]['response']>[]> {
|
|
129
|
-
return Promise.resolve([]);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
121
|
public sendRequestToPeer(
|
|
133
122
|
_peerId: PeerId,
|
|
134
123
|
_subProtocol: ReqRespSubProtocol,
|
|
@@ -150,11 +139,7 @@ export class DummyP2PService implements P2PService {
|
|
|
150
139
|
return Promise.resolve();
|
|
151
140
|
}
|
|
152
141
|
|
|
153
|
-
addReqRespSubProtocol(
|
|
154
|
-
_subProtocol: ReqRespSubProtocol,
|
|
155
|
-
_handler: ReqRespSubProtocolHandler,
|
|
156
|
-
_validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
157
|
-
): Promise<void> {
|
|
142
|
+
addReqRespSubProtocol(_subProtocol: ReqRespSubProtocol, _handler: ReqRespSubProtocolHandler): Promise<void> {
|
|
158
143
|
return Promise.resolve();
|
|
159
144
|
}
|
|
160
145
|
|
|
@@ -183,6 +168,7 @@ export class DummyP2PService implements P2PService {
|
|
|
183
168
|
peerScoring: {
|
|
184
169
|
penalizePeer: (_peerId, _penalty) => {},
|
|
185
170
|
},
|
|
171
|
+
validateRequestedBlockTxsConsistency: () => Promise.resolve(true),
|
|
186
172
|
};
|
|
187
173
|
}
|
|
188
174
|
}
|
|
@@ -288,10 +274,7 @@ export class DummyPeerManager implements PeerManagerInterface {
|
|
|
288
274
|
export class DummyReqResp implements ReqRespInterface {
|
|
289
275
|
updateConfig(_config: Partial<P2PReqRespConfig>): void {}
|
|
290
276
|
setShouldRejectPeer(): void {}
|
|
291
|
-
start(
|
|
292
|
-
_subProtocolHandlers: ReqRespSubProtocolHandlers,
|
|
293
|
-
_subProtocolValidators: ReqRespSubProtocolValidators,
|
|
294
|
-
): Promise<void> {
|
|
277
|
+
start(_subProtocolHandlers: ReqRespSubProtocolHandlers): Promise<void> {
|
|
295
278
|
return Promise.resolve();
|
|
296
279
|
}
|
|
297
280
|
stop(): Promise<void> {
|
|
@@ -303,16 +286,6 @@ export class DummyReqResp implements ReqRespInterface {
|
|
|
303
286
|
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']> | undefined> {
|
|
304
287
|
return Promise.resolve(undefined);
|
|
305
288
|
}
|
|
306
|
-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
307
|
-
_subProtocol: SubProtocol,
|
|
308
|
-
_requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
309
|
-
_pinnedPeer: PeerId | undefined,
|
|
310
|
-
_timeoutMs?: number,
|
|
311
|
-
_maxPeers?: number,
|
|
312
|
-
_maxRetryAttempts?: number,
|
|
313
|
-
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
|
|
314
|
-
return Promise.resolve([]);
|
|
315
|
-
}
|
|
316
289
|
public sendRequestToPeer(
|
|
317
290
|
_peerId: PeerId,
|
|
318
291
|
_subProtocol: ReqRespSubProtocol,
|
|
@@ -331,11 +304,7 @@ export class DummyReqResp implements ReqRespInterface {
|
|
|
331
304
|
};
|
|
332
305
|
}
|
|
333
306
|
|
|
334
|
-
addSubProtocol(
|
|
335
|
-
_subProtocol: ReqRespSubProtocol,
|
|
336
|
-
_handler: ReqRespSubProtocolHandler,
|
|
337
|
-
_validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
338
|
-
): Promise<void> {
|
|
307
|
+
addSubProtocol(_subProtocol: ReqRespSubProtocol, _handler: ReqRespSubProtocolHandler): Promise<void> {
|
|
339
308
|
return Promise.resolve();
|
|
340
309
|
}
|
|
341
310
|
}
|