@aztec/p2p 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1
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/README.md +129 -3
- package/dest/client/factory.d.ts +3 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +19 -10
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +3 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +40 -14
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +21 -7
- package/dest/config.d.ts +107 -97
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +20 -5
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +11 -8
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +10 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +13 -3
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +20 -7
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- 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 +13 -5
- 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 +20 -11
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
- package/dest/msg_validators/clock_tolerance.d.ts +12 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +54 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
- 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 +2 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +19 -11
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +10 -2
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +26 -7
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +36 -4
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +50 -33
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +28 -1
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/dummy_service.d.ts +6 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +6 -1
- package/dest/services/encoding.d.ts +5 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -1
- package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +21 -4
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +19 -27
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +141 -130
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +37 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -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 +69 -65
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +14 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -11
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
- package/dest/services/reqresp/reqresp.d.ts +4 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +28 -11
- package/dest/services/service.d.ts +5 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +57 -73
- package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +3 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- 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 +4 -1
- package/dest/test-helpers/mock-pubsub.d.ts +11 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +36 -11
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +5 -3
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +21 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +73 -17
- package/dest/testbench/worker_client_manager.d.ts +8 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +49 -1
- package/package.json +14 -14
- package/src/client/factory.ts +31 -4
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +47 -15
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -8
- package/src/config.ts +35 -6
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +12 -8
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +9 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +31 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +14 -4
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
- package/src/msg_validators/clock_tolerance.ts +72 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +17 -10
- package/src/msg_validators/tx_validator/README.md +15 -3
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/factory.ts +31 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +82 -33
- package/src/msg_validators/tx_validator/phases_validator.ts +31 -1
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +8 -2
- package/src/services/encoding.ts +9 -1
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +141 -141
- package/src/services/peer-manager/peer_manager.ts +43 -10
- package/src/services/peer-manager/peer_scoring.ts +27 -5
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
- package/src/services/reqresp/config.ts +2 -2
- package/src/services/reqresp/interface.ts +21 -11
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +37 -12
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +3 -5
- package/src/services/tx_collection/tx_source.ts +8 -7
- package/src/test-helpers/make-test-p2p-clients.ts +2 -0
- package/src/test-helpers/mock-pubsub.ts +34 -5
- package/src/test-helpers/reqresp-nodes.ts +4 -2
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +73 -14
- package/src/testbench/worker_client_manager.ts +55 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -16
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -402
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -23
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -321
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tracks which transactions are still missing and need to be fetched.
|
|
8
|
+
* Manages the request deadline and serves as the sole source of cancellation signal.
|
|
9
|
+
* The request is cancelled when all txs are fetched or the deadline expires.
|
|
10
|
+
*/
|
|
11
|
+
export interface IRequestTracker {
|
|
12
|
+
/** Returns the set of transaction hashes that are still missing. */
|
|
13
|
+
get missingTxHashes(): Set<string>;
|
|
14
|
+
/** Size of this.missingTxHashes */
|
|
15
|
+
get numberOfMissingTxs(): number;
|
|
16
|
+
/** Are all requested txs fetched */
|
|
17
|
+
allFetched(): boolean;
|
|
18
|
+
/** Checks that transaction is still missing */
|
|
19
|
+
isMissing(txHash: string): boolean;
|
|
20
|
+
/** Marks a transaction as fetched. Returns true if it was previously missing. */
|
|
21
|
+
markFetched(tx: Tx): boolean;
|
|
22
|
+
/** Get list of collected txs */
|
|
23
|
+
get collectedTxs(): Tx[];
|
|
24
|
+
/** The deadline for this request. */
|
|
25
|
+
get deadline(): Date;
|
|
26
|
+
/** Remaining time in milliseconds until deadline. Returns 0 if already past. */
|
|
27
|
+
get timeoutMs(): number;
|
|
28
|
+
/** Checks whether the request is cancelled (deadline expired or all fetched). May trigger cancellation if deadline has passed. */
|
|
29
|
+
checkCancelled(): boolean;
|
|
30
|
+
/** Resolves when deadline expires or all txs are fetched. */
|
|
31
|
+
get cancellationToken(): Promise<void>;
|
|
32
|
+
/** Externally cancel the request. */
|
|
33
|
+
cancel(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class RequestTracker implements IRequestTracker {
|
|
37
|
+
public readonly collectedTxs: Tx[] = [];
|
|
38
|
+
private done = false;
|
|
39
|
+
private readonly cancellationTokenPromise: PromiseWithResolvers<void>;
|
|
40
|
+
private readonly deadlineTimer: ReturnType<typeof setTimeout> | undefined;
|
|
41
|
+
|
|
42
|
+
private constructor(
|
|
43
|
+
public readonly missingTxHashes: Set<string>,
|
|
44
|
+
public readonly deadline: Date,
|
|
45
|
+
private readonly dateProvider?: DateProvider,
|
|
46
|
+
) {
|
|
47
|
+
this.cancellationTokenPromise = promiseWithResolvers<void>();
|
|
48
|
+
|
|
49
|
+
if (missingTxHashes.size === 0) {
|
|
50
|
+
this.finish();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const now = this.dateProvider?.now() ?? Date.now();
|
|
55
|
+
const remaining = deadline.getTime() - now;
|
|
56
|
+
if (remaining <= 0) {
|
|
57
|
+
this.finish();
|
|
58
|
+
} else {
|
|
59
|
+
this.deadlineTimer = setTimeout(() => this.finish(), remaining);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public static create(hashes: TxHash[] | string[], deadline: Date, dateProvider?: DateProvider) {
|
|
64
|
+
return new RequestTracker(new Set(hashes.map(hash => hash.toString())), deadline, dateProvider);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
markFetched(tx: Tx): boolean {
|
|
68
|
+
if (this.missingTxHashes.delete(tx.txHash.toString())) {
|
|
69
|
+
this.collectedTxs.push(tx);
|
|
70
|
+
if (this.allFetched()) {
|
|
71
|
+
this.finish();
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get numberOfMissingTxs(): number {
|
|
79
|
+
return this.missingTxHashes.size;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
allFetched(): boolean {
|
|
83
|
+
return this.numberOfMissingTxs === 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
isMissing(txHash: string): boolean {
|
|
87
|
+
return this.missingTxHashes.has(txHash.toString());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get timeoutMs(): number {
|
|
91
|
+
const now = this.dateProvider?.now() ?? Date.now();
|
|
92
|
+
return Math.max(0, this.deadline.getTime() - now);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
checkCancelled(): boolean {
|
|
96
|
+
if (this.done) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// Synchronous fallback: check deadline even if setTimeout hasn't fired yet.
|
|
100
|
+
// This prevents macrotask starvation in tight async loops from blocking cancellation.
|
|
101
|
+
const now = this.dateProvider?.now() ?? Date.now();
|
|
102
|
+
if (now >= this.deadline.getTime()) {
|
|
103
|
+
this.finish();
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get cancellationToken(): Promise<void> {
|
|
110
|
+
return this.cancellationTokenPromise.promise;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
cancel(): void {
|
|
114
|
+
this.finish();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private finish() {
|
|
118
|
+
if (this.done) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.done = true;
|
|
122
|
+
if (this.deadlineTimer) {
|
|
123
|
+
clearTimeout(this.deadlineTimer);
|
|
124
|
+
}
|
|
125
|
+
this.cancellationTokenPromise.resolve();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -196,7 +196,7 @@ export class SlowTxCollection {
|
|
|
196
196
|
// from mined unproven blocks it has seen in the past.
|
|
197
197
|
const fastRequests = this.fastCollection.getFastCollectionRequests();
|
|
198
198
|
const fastCollectionTxs: Set<string> = new Set(
|
|
199
|
-
fastRequests.values().flatMap(r => Array.from(r.
|
|
199
|
+
fastRequests.values().flatMap(r => Array.from(r.requestTracker.missingTxHashes)),
|
|
200
200
|
);
|
|
201
201
|
|
|
202
202
|
// Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { compactArray } from '@aztec/foundation/collection';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import { RunningPromise } from '@aztec/foundation/promise';
|
|
5
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
7
7
|
import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
|
|
@@ -19,7 +19,7 @@ import type { TxCollectionConfig } from './config.js';
|
|
|
19
19
|
import { FastTxCollection } from './fast_tx_collection.js';
|
|
20
20
|
import { FileStoreTxCollection } from './file_store_tx_collection.js';
|
|
21
21
|
import type { FileStoreTxSource } from './file_store_tx_source.js';
|
|
22
|
-
import type {
|
|
22
|
+
import type { IRequestTracker } from './request_tracker.js';
|
|
23
23
|
import { SlowTxCollection, getProofDeadlineForSlot } from './slow_tx_collection.js';
|
|
24
24
|
import { type TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
25
25
|
import type { TxSource } from './tx_source.js';
|
|
@@ -33,10 +33,8 @@ export type FastCollectionRequestInput =
|
|
|
33
33
|
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
|
|
34
34
|
|
|
35
35
|
export type FastCollectionRequest = FastCollectionRequestInput & {
|
|
36
|
-
|
|
37
|
-
deadline: Date;
|
|
36
|
+
requestTracker: IRequestTracker;
|
|
38
37
|
blockInfo: L2BlockInfo;
|
|
39
|
-
promise: PromiseWithResolvers<void>;
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
/**
|
|
@@ -2,7 +2,7 @@ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
|
2
2
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
3
3
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
4
4
|
import { type AztecNode, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
|
|
5
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
|
|
6
6
|
import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
|
|
7
7
|
import { makeTracedFetch } from '@aztec/telemetry-client';
|
|
8
8
|
|
|
@@ -16,12 +16,13 @@ export interface TxSource {
|
|
|
16
16
|
export class NodeRpcTxSource implements TxSource {
|
|
17
17
|
constructor(
|
|
18
18
|
private readonly client: Pick<AztecNode, 'getTxsByHash'>,
|
|
19
|
+
private readonly txValidator: TxValidator,
|
|
19
20
|
private readonly info: string,
|
|
20
21
|
) {}
|
|
21
22
|
|
|
22
|
-
public static fromUrl(nodeUrl: string, versions: ComponentsVersions): NodeRpcTxSource {
|
|
23
|
+
public static fromUrl(nodeUrl: string, txValidator: TxValidator, versions: ComponentsVersions): NodeRpcTxSource {
|
|
23
24
|
const client = createAztecNodeClient(nodeUrl, versions, makeTracedFetch([1, 2, 3], false));
|
|
24
|
-
return new NodeRpcTxSource(client, nodeUrl);
|
|
25
|
+
return new NodeRpcTxSource(client, txValidator, nodeUrl);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
public getInfo() {
|
|
@@ -38,8 +39,8 @@ export class NodeRpcTxSource implements TxSource {
|
|
|
38
39
|
const invalidTxHashes: string[] = [];
|
|
39
40
|
await Promise.all(
|
|
40
41
|
txs.map(async tx => {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
42
|
+
const validation = await this.txValidator.validateTx(tx);
|
|
43
|
+
if (validation.result === 'valid') {
|
|
43
44
|
validTxs.push(tx);
|
|
44
45
|
} else {
|
|
45
46
|
invalidTxHashes.push(tx.getTxHash().toString());
|
|
@@ -50,7 +51,7 @@ export class NodeRpcTxSource implements TxSource {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
export function createNodeRpcTxSources(urls: string[], chainConfig: ChainConfig) {
|
|
54
|
+
export function createNodeRpcTxSources(urls: string[], txValidator: TxValidator, chainConfig: ChainConfig) {
|
|
54
55
|
const versions = getComponentsVersionsFromConfig(chainConfig, protocolContractsHash, getVKTreeRoot());
|
|
55
|
-
return urls.map(url => NodeRpcTxSource.fromUrl(url, versions));
|
|
56
|
+
return urls.map(url => NodeRpcTxSource.fromUrl(url, txValidator, versions));
|
|
56
57
|
}
|
|
@@ -5,6 +5,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
5
5
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
6
6
|
import { sleep } from '@aztec/foundation/sleep';
|
|
7
7
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
8
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
8
9
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
10
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
10
11
|
|
|
@@ -102,6 +103,7 @@ export async function makeTestP2PClient(
|
|
|
102
103
|
proofVerifier,
|
|
103
104
|
mockWorldState,
|
|
104
105
|
mockEpochCache,
|
|
106
|
+
{ getCurrentMinFees: () => Promise.resolve(GasFees.empty()) },
|
|
105
107
|
'test-p2p-client',
|
|
106
108
|
undefined,
|
|
107
109
|
undefined,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
3
4
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
5
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
5
6
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
7
|
+
import type { BlockMinFeesProvider } from '@aztec/stdlib/gas';
|
|
6
8
|
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
9
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
8
10
|
|
|
@@ -55,6 +57,7 @@ export function getMockPubSubP2PServiceFactory(
|
|
|
55
57
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
56
58
|
worldStateSynchronizer: WorldStateSynchronizer;
|
|
57
59
|
peerStore: AztecAsyncKVStore;
|
|
60
|
+
blockMinFeesProvider: BlockMinFeesProvider;
|
|
58
61
|
telemetry: TelemetryClient;
|
|
59
62
|
logger: Logger;
|
|
60
63
|
},
|
|
@@ -75,6 +78,7 @@ export function getMockPubSubP2PServiceFactory(
|
|
|
75
78
|
deps.epochCache,
|
|
76
79
|
deps.proofVerifier,
|
|
77
80
|
deps.worldStateSynchronizer,
|
|
81
|
+
deps.blockMinFeesProvider,
|
|
78
82
|
deps.telemetry,
|
|
79
83
|
deps.logger,
|
|
80
84
|
);
|
|
@@ -100,6 +104,7 @@ class MockReqResp implements ReqRespInterface {
|
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
updateConfig(_config: Partial<P2PReqRespConfig>): void {}
|
|
107
|
+
setShouldRejectPeer(): void {}
|
|
103
108
|
|
|
104
109
|
start(
|
|
105
110
|
subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
|
|
@@ -138,6 +143,11 @@ class MockReqResp implements ReqRespInterface {
|
|
|
138
143
|
const responses: InstanceType<SubProtocolMap[SubProtocol]['response']>[] = [];
|
|
139
144
|
const peers = this.network.getReqRespPeers().filter(p => !p.peerId.equals(this.peerId));
|
|
140
145
|
const targetPeers = pinnedPeer ? peers.filter(p => p.peerId.equals(pinnedPeer)) : peers;
|
|
146
|
+
const delayMs = this.network.getPropagationDelayMs();
|
|
147
|
+
|
|
148
|
+
if (delayMs > 0) {
|
|
149
|
+
await sleep(delayMs);
|
|
150
|
+
}
|
|
141
151
|
|
|
142
152
|
for (const request of requests) {
|
|
143
153
|
const requestBuffer = request.toBuffer();
|
|
@@ -174,7 +184,12 @@ class MockReqResp implements ReqRespInterface {
|
|
|
174
184
|
return { status: ReqRespStatus.SUCCESS, data: Buffer.from([]) };
|
|
175
185
|
}
|
|
176
186
|
try {
|
|
187
|
+
const delayMs = this.network.getPropagationDelayMs();
|
|
188
|
+
if (delayMs > 0) {
|
|
189
|
+
await sleep(delayMs);
|
|
190
|
+
}
|
|
177
191
|
const data = await handler(this.peerId, payload);
|
|
192
|
+
|
|
178
193
|
return { status: ReqRespStatus.SUCCESS, data };
|
|
179
194
|
} catch {
|
|
180
195
|
return { status: ReqRespStatus.FAILURE };
|
|
@@ -242,10 +257,10 @@ class MockGossipSubService extends TypedEventEmitter<GossipsubEvents> implements
|
|
|
242
257
|
score: (_peerId: PeerIdStr) => 0,
|
|
243
258
|
};
|
|
244
259
|
|
|
245
|
-
publish(topic: TopicStr, data: Uint8Array, _opts?: PublishOpts): Promise<PublishResult> {
|
|
260
|
+
async publish(topic: TopicStr, data: Uint8Array, _opts?: PublishOpts): Promise<PublishResult> {
|
|
246
261
|
this.logger.debug(`Publishing message on topic ${topic}`, { topic, sender: this.peerId.toString() });
|
|
247
|
-
this.network.publishToPeers(topic, data, this.peerId);
|
|
248
|
-
return
|
|
262
|
+
await this.network.publishToPeers(topic, data, this.peerId);
|
|
263
|
+
return { recipients: this.network.getPeers().filter(peer => !this.peerId.equals(peer)) };
|
|
249
264
|
}
|
|
250
265
|
|
|
251
266
|
receive(msg: GossipsubMessage) {
|
|
@@ -281,7 +296,8 @@ class MockGossipSubService extends TypedEventEmitter<GossipsubEvents> implements
|
|
|
281
296
|
|
|
282
297
|
/**
|
|
283
298
|
* Mock gossip sub network used for testing.
|
|
284
|
-
* All instances of MockGossipSubService connected to the same network
|
|
299
|
+
* All instances of MockGossipSubService connected to the same network receive the same messages,
|
|
300
|
+
* optionally delayed by a configurable propagation time.
|
|
285
301
|
*/
|
|
286
302
|
export class MockGossipSubNetwork {
|
|
287
303
|
private peers: MockGossipSubService[] = [];
|
|
@@ -290,6 +306,15 @@ export class MockGossipSubNetwork {
|
|
|
290
306
|
|
|
291
307
|
private logger = createLogger('p2p:test:mock-gossipsub-network');
|
|
292
308
|
|
|
309
|
+
constructor(
|
|
310
|
+
/** Artificial propagation delay in milliseconds applied to each message delivery. */
|
|
311
|
+
private propagationDelayMs: number = 0,
|
|
312
|
+
) {}
|
|
313
|
+
|
|
314
|
+
public getPropagationDelayMs(): number {
|
|
315
|
+
return this.propagationDelayMs;
|
|
316
|
+
}
|
|
317
|
+
|
|
293
318
|
public getPeers(): PeerId[] {
|
|
294
319
|
return this.peers.map(peer => peer.peerId);
|
|
295
320
|
}
|
|
@@ -306,7 +331,7 @@ export class MockGossipSubNetwork {
|
|
|
306
331
|
return this.reqRespPeers;
|
|
307
332
|
}
|
|
308
333
|
|
|
309
|
-
public publishToPeers(topic: TopicStr, data: Uint8Array, sender: PeerId): void {
|
|
334
|
+
public async publishToPeers(topic: TopicStr, data: Uint8Array, sender: PeerId): Promise<void> {
|
|
310
335
|
const msgId = (this.nextMsgId++).toString();
|
|
311
336
|
this.logger.debug(`Network is distributing message on topic ${topic}`, {
|
|
312
337
|
topic,
|
|
@@ -315,6 +340,10 @@ export class MockGossipSubNetwork {
|
|
|
315
340
|
msgId,
|
|
316
341
|
});
|
|
317
342
|
|
|
343
|
+
if (this.propagationDelayMs > 0) {
|
|
344
|
+
await sleep(this.propagationDelayMs);
|
|
345
|
+
}
|
|
346
|
+
|
|
318
347
|
const gossipSubMsg: GossipsubMessage = { msgId, msg: { type: 'unsigned', topic, data }, propagationSource: sender };
|
|
319
348
|
for (const peer of this.peers) {
|
|
320
349
|
if (peer.subscribedTopics.has(topic)) {
|
|
@@ -6,6 +6,7 @@ import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
|
6
6
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
7
7
|
import { type ChainConfig, emptyChainConfig } from '@aztec/stdlib/config';
|
|
8
8
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
9
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
9
10
|
import type {
|
|
10
11
|
ClientProtocolCircuitVerifier,
|
|
11
12
|
IVCProofVerificationResult,
|
|
@@ -153,6 +154,8 @@ export async function createTestLibP2PService(
|
|
|
153
154
|
epochCache,
|
|
154
155
|
);
|
|
155
156
|
|
|
157
|
+
reqresp.setShouldRejectPeer(peerId => peerManager.shouldDisableP2PGossip(peerId));
|
|
158
|
+
|
|
156
159
|
p2pNode.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
|
|
157
160
|
p2pNode.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
|
|
158
161
|
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
@@ -168,6 +171,7 @@ export async function createTestLibP2PService(
|
|
|
168
171
|
epochCache,
|
|
169
172
|
proofVerifier,
|
|
170
173
|
worldStateSynchronizer,
|
|
174
|
+
{ getCurrentMinFees: () => Promise.resolve(GasFees.empty()) },
|
|
171
175
|
telemetry,
|
|
172
176
|
);
|
|
173
177
|
}
|
|
@@ -187,7 +191,6 @@ export const MOCK_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
|
|
|
187
191
|
[ReqRespSubProtocol.STATUS]: (_msg: any) => Promise.resolve(Buffer.from('status')),
|
|
188
192
|
[ReqRespSubProtocol.TX]: (_msg: any) => Promise.resolve(Buffer.from('tx')),
|
|
189
193
|
[ReqRespSubProtocol.GOODBYE]: (_msg: any) => Promise.resolve(Buffer.from('goodbye')),
|
|
190
|
-
[ReqRespSubProtocol.BLOCK]: (_msg: any) => Promise.resolve(Buffer.from('block')),
|
|
191
194
|
[ReqRespSubProtocol.AUTH]: (_msg: any) => Promise.resolve(Buffer.from('auth')),
|
|
192
195
|
[ReqRespSubProtocol.BLOCK_TXS]: (_msg: any) => Promise.resolve(Buffer.from('block_txs')),
|
|
193
196
|
};
|
|
@@ -199,7 +202,6 @@ export const MOCK_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
|
|
|
199
202
|
[ReqRespSubProtocol.STATUS]: noopValidator,
|
|
200
203
|
[ReqRespSubProtocol.TX]: noopValidator,
|
|
201
204
|
[ReqRespSubProtocol.GOODBYE]: noopValidator,
|
|
202
|
-
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
203
205
|
[ReqRespSubProtocol.AUTH]: noopValidator,
|
|
204
206
|
[ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
|
|
205
207
|
};
|
|
@@ -273,17 +273,42 @@ export class InMemoryAttestationPool {
|
|
|
273
273
|
* Creates a mock EpochCache for testing.
|
|
274
274
|
*/
|
|
275
275
|
export function createMockEpochCache(): EpochCacheInterface {
|
|
276
|
-
|
|
276
|
+
const cache: EpochCacheInterface = {
|
|
277
277
|
getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: EpochNumber.ZERO, isEscapeHatchOpen: false }),
|
|
278
278
|
getProposerIndexEncoding: () => '0x' as `0x${string}`,
|
|
279
|
-
|
|
279
|
+
getSlotNow: () => SlotNumber.ZERO,
|
|
280
|
+
getTargetSlot: () => SlotNumber.ZERO,
|
|
281
|
+
getEpochNow: () => EpochNumber.ZERO,
|
|
282
|
+
getTargetEpoch: () => EpochNumber.ZERO,
|
|
283
|
+
getEpochAndSlotNow: () => ({
|
|
284
|
+
epoch: EpochNumber.ZERO,
|
|
285
|
+
slot: SlotNumber.ZERO,
|
|
286
|
+
ts: 0n,
|
|
287
|
+
nowMs: 0n,
|
|
288
|
+
}),
|
|
289
|
+
isProposerPipeliningEnabled: () => false,
|
|
290
|
+
pipeliningOffset: () => 0,
|
|
280
291
|
computeProposerIndex: () => 0n,
|
|
281
292
|
getCurrentAndNextSlot: () => ({ currentSlot: SlotNumber.ZERO, nextSlot: SlotNumber.ZERO }),
|
|
293
|
+
getTargetAndNextSlot: () => ({ targetSlot: SlotNumber.ZERO, nextSlot: SlotNumber.ZERO }),
|
|
282
294
|
getProposerAttesterAddressInSlot: () => Promise.resolve(undefined),
|
|
283
|
-
getEpochAndSlotInNextL1Slot: () => ({
|
|
295
|
+
getEpochAndSlotInNextL1Slot: () => ({
|
|
296
|
+
epoch: EpochNumber.ZERO,
|
|
297
|
+
slot: SlotNumber.ZERO,
|
|
298
|
+
ts: 0n,
|
|
299
|
+
nowSeconds: 0n,
|
|
300
|
+
}),
|
|
301
|
+
getTargetEpochAndSlotInNextL1Slot: () => ({
|
|
302
|
+
epoch: EpochNumber.ZERO,
|
|
303
|
+
slot: SlotNumber.ZERO,
|
|
304
|
+
ts: 0n,
|
|
305
|
+
nowSeconds: 0n,
|
|
306
|
+
}),
|
|
284
307
|
isInCommittee: () => Promise.resolve(false),
|
|
285
308
|
getRegisteredValidators: () => Promise.resolve([]),
|
|
286
309
|
filterInCommittee: () => Promise.resolve([]),
|
|
310
|
+
isEscapeHatchOpen: () => Promise.resolve(false),
|
|
311
|
+
isEscapeHatchOpenAtSlot: () => Promise.resolve(false),
|
|
287
312
|
getL1Constants: () => ({
|
|
288
313
|
l1StartBlock: 0n,
|
|
289
314
|
l1GenesisTime: 0n,
|
|
@@ -295,6 +320,7 @@ export function createMockEpochCache(): EpochCacheInterface {
|
|
|
295
320
|
rollupManaLimit: Number.MAX_SAFE_INTEGER,
|
|
296
321
|
}),
|
|
297
322
|
};
|
|
323
|
+
return cache;
|
|
298
324
|
}
|
|
299
325
|
|
|
300
326
|
/**
|
|
@@ -17,6 +17,7 @@ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
|
17
17
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
18
18
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
19
19
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
20
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
20
21
|
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
21
22
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
22
23
|
import { type BlockProposal, P2PMessage } from '@aztec/stdlib/p2p';
|
|
@@ -40,7 +41,7 @@ import type { IBatchRequestTxValidator } from '../services/reqresp/batch-tx-requ
|
|
|
40
41
|
import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.js';
|
|
41
42
|
import type { ReqResp } from '../services/reqresp/reqresp.js';
|
|
42
43
|
import type { PeerDiscoveryService } from '../services/service.js';
|
|
43
|
-
import {
|
|
44
|
+
import { RequestTracker } from '../services/tx_collection/request_tracker.js';
|
|
44
45
|
import { AlwaysTrueCircuitVerifier } from '../test-helpers/index.js';
|
|
45
46
|
import {
|
|
46
47
|
BENCHMARK_CONSTANTS,
|
|
@@ -116,6 +117,7 @@ class TestLibP2PService extends LibP2PService {
|
|
|
116
117
|
epochCache,
|
|
117
118
|
proofVerifier,
|
|
118
119
|
worldStateSynchronizer,
|
|
120
|
+
{ getCurrentMinFees: () => Promise.resolve(GasFees.empty()) },
|
|
119
121
|
telemetry,
|
|
120
122
|
logger,
|
|
121
123
|
);
|
|
@@ -204,6 +206,25 @@ function installUnlimitedRateLimits(client: P2PClient): void {
|
|
|
204
206
|
rateLimiter.allow = () => RateLimitStatus.Allowed;
|
|
205
207
|
}
|
|
206
208
|
|
|
209
|
+
/** Resets peer scores to prevent cross-case contamination in benchmarks. */
|
|
210
|
+
function resetPeerScores(client: P2PClient): void {
|
|
211
|
+
const peerManager = (client as any).p2pService.peerManager;
|
|
212
|
+
const peerScoring = peerManager?.peerScoring;
|
|
213
|
+
if (peerScoring?.resetAllScores) {
|
|
214
|
+
peerScoring.resetAllScores();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Returns the number of connected peers for connectivity checks. */
|
|
219
|
+
function getConnectedPeerCount(client: P2PClient): number {
|
|
220
|
+
const p2pService = (client as any).p2pService;
|
|
221
|
+
const connectionSampler = p2pService?.reqresp?.getConnectionSampler?.();
|
|
222
|
+
if (connectionSampler?.getPeerListSortedByConnectionCountAsc) {
|
|
223
|
+
return connectionSampler.getPeerListSortedByConnectionCountAsc().length;
|
|
224
|
+
}
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
207
228
|
async function runAggregatorBenchmark(
|
|
208
229
|
client: P2PClient,
|
|
209
230
|
blockProposal: BlockProposal,
|
|
@@ -273,10 +294,9 @@ async function runAggregatorBenchmark(
|
|
|
273
294
|
noopTxValidator,
|
|
274
295
|
);
|
|
275
296
|
const fetchedTxs = await collector.collectTxs(
|
|
276
|
-
|
|
297
|
+
RequestTracker.create(txHashes, new Date(Date.now() + timeoutMs)),
|
|
277
298
|
blockProposal,
|
|
278
299
|
pinnedPeer,
|
|
279
|
-
timeoutMs,
|
|
280
300
|
);
|
|
281
301
|
const durationMs = timer.ms();
|
|
282
302
|
return {
|
|
@@ -293,10 +313,9 @@ async function runAggregatorBenchmark(
|
|
|
293
313
|
BENCHMARK_CONSTANTS.FIXED_MAX_RETRY_ATTEMPTS,
|
|
294
314
|
);
|
|
295
315
|
const fetchedTxs = await collector.collectTxs(
|
|
296
|
-
|
|
316
|
+
RequestTracker.create(txHashes, new Date(Date.now() + timeoutMs)),
|
|
297
317
|
blockProposal,
|
|
298
318
|
pinnedPeer,
|
|
299
|
-
timeoutMs,
|
|
300
319
|
);
|
|
301
320
|
const durationMs = timer.ms();
|
|
302
321
|
return {
|
|
@@ -323,6 +342,37 @@ let workerConfig: P2PConfig | null = null;
|
|
|
323
342
|
let workerLogger: Logger | null = null;
|
|
324
343
|
let kvStore: Awaited<ReturnType<typeof openTmpStore>> | null = null;
|
|
325
344
|
|
|
345
|
+
async function stopWorker() {
|
|
346
|
+
try {
|
|
347
|
+
if (workerClient) {
|
|
348
|
+
await workerClient.stop();
|
|
349
|
+
workerClient = null;
|
|
350
|
+
}
|
|
351
|
+
} catch (e) {
|
|
352
|
+
workerLogger?.error('Error stopping worker client', e);
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
if (kvStore?.close) {
|
|
356
|
+
await kvStore.close();
|
|
357
|
+
kvStore = null;
|
|
358
|
+
}
|
|
359
|
+
} catch (e) {
|
|
360
|
+
workerLogger?.error('Error closing kv store', e);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function gracefulExit(code: number = 0) {
|
|
365
|
+
try {
|
|
366
|
+
if (process.connected) {
|
|
367
|
+
process.disconnect();
|
|
368
|
+
}
|
|
369
|
+
} catch {
|
|
370
|
+
// IPC channel already closed
|
|
371
|
+
}
|
|
372
|
+
// Safety fallback if lingering handles prevent the event loop from draining
|
|
373
|
+
setTimeout(() => process.exit(code), 5000).unref();
|
|
374
|
+
}
|
|
375
|
+
|
|
326
376
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
327
377
|
process.on('message', async msg => {
|
|
328
378
|
const {
|
|
@@ -369,6 +419,7 @@ process.on('message', async msg => {
|
|
|
369
419
|
proofVerifier as ClientProtocolCircuitVerifier,
|
|
370
420
|
worldState,
|
|
371
421
|
epochCache,
|
|
422
|
+
{ getCurrentMinFees: () => Promise.resolve(GasFees.empty()) },
|
|
372
423
|
'test-p2p-bench-worker',
|
|
373
424
|
undefined,
|
|
374
425
|
telemetry as TelemetryClient,
|
|
@@ -412,13 +463,8 @@ process.on('message', async msg => {
|
|
|
412
463
|
const cmd = msg as any;
|
|
413
464
|
switch (cmd.type) {
|
|
414
465
|
case 'STOP':
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
if (kvStore?.close) {
|
|
419
|
-
await kvStore.close();
|
|
420
|
-
}
|
|
421
|
-
process.exit(0);
|
|
466
|
+
await stopWorker();
|
|
467
|
+
gracefulExit(0);
|
|
422
468
|
break;
|
|
423
469
|
|
|
424
470
|
case 'SEND_TX':
|
|
@@ -428,6 +474,13 @@ process.on('message', async msg => {
|
|
|
428
474
|
}
|
|
429
475
|
break;
|
|
430
476
|
|
|
477
|
+
case 'GET_PEER_COUNT':
|
|
478
|
+
process.send!({
|
|
479
|
+
type: 'PEER_COUNT',
|
|
480
|
+
count: workerClient ? getConnectedPeerCount(workerClient) : 0,
|
|
481
|
+
});
|
|
482
|
+
break;
|
|
483
|
+
|
|
431
484
|
case 'BENCH_REQRESP': {
|
|
432
485
|
const benchCmd = cmd as BenchReqRespCommand;
|
|
433
486
|
if (!workerClient || !workerTxPool || !workerAttestationPool || !workerConfig || !workerLogger) {
|
|
@@ -444,6 +497,7 @@ process.on('message', async msg => {
|
|
|
444
497
|
// Reset state before each benchmark run to avoid cross-run contamination
|
|
445
498
|
workerTxPool.resetState();
|
|
446
499
|
workerAttestationPool.resetState();
|
|
500
|
+
resetPeerScores(workerClient);
|
|
447
501
|
|
|
448
502
|
installUnlimitedRateLimits(workerClient);
|
|
449
503
|
|
|
@@ -495,7 +549,12 @@ process.on('message', async msg => {
|
|
|
495
549
|
}
|
|
496
550
|
}
|
|
497
551
|
} catch (err: any) {
|
|
498
|
-
|
|
499
|
-
|
|
552
|
+
try {
|
|
553
|
+
process.send!({ type: 'ERROR', error: err.message });
|
|
554
|
+
} catch {
|
|
555
|
+
// IPC channel may be closed
|
|
556
|
+
}
|
|
557
|
+
await stopWorker();
|
|
558
|
+
gracefulExit(1);
|
|
500
559
|
}
|
|
501
560
|
});
|
|
@@ -72,7 +72,6 @@ class WorkerClientManager {
|
|
|
72
72
|
destroy() {
|
|
73
73
|
this.cleanup().catch((error: Error) => {
|
|
74
74
|
this.logger.error('Failed to cleanup worker client manager', error);
|
|
75
|
-
process.exit(1);
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
|
|
@@ -425,6 +424,61 @@ class WorkerClientManager {
|
|
|
425
424
|
this.logger.info('All worker processes cleaned up');
|
|
426
425
|
}
|
|
427
426
|
|
|
427
|
+
/**
|
|
428
|
+
* Checks that the aggregator (client 0) has sufficient peer connections before running a benchmark.
|
|
429
|
+
* This prevents benchmark cases from starting with degraded connectivity after a previous case
|
|
430
|
+
* caused connection failures.
|
|
431
|
+
*/
|
|
432
|
+
async waitForConnectivity(minPeers: number, timeoutMs: number = 15_000): Promise<number> {
|
|
433
|
+
const waitInterval = 1000;
|
|
434
|
+
let waited = 0;
|
|
435
|
+
|
|
436
|
+
while (waited < timeoutMs) {
|
|
437
|
+
const count = await this.getPeerCount(0, 5000);
|
|
438
|
+
if (count >= minPeers) {
|
|
439
|
+
this.logger.info(`Connectivity check passed: ${count}/${minPeers} peers connected`);
|
|
440
|
+
return count;
|
|
441
|
+
}
|
|
442
|
+
this.logger.debug(`Waiting for connectivity: ${count}/${minPeers} (waited ${waited}ms)`);
|
|
443
|
+
await sleep(waitInterval);
|
|
444
|
+
waited += waitInterval;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const finalCount = await this.getPeerCount(0, 5000);
|
|
448
|
+
this.logger.warn(`Connectivity check: only ${finalCount}/${minPeers} peers after ${timeoutMs}ms`);
|
|
449
|
+
return finalCount;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private getPeerCount(clientIndex: number, timeoutMs: number): Promise<number> {
|
|
453
|
+
return new Promise<number>(resolve => {
|
|
454
|
+
let resolved = false;
|
|
455
|
+
|
|
456
|
+
const handler = (msg: any) => {
|
|
457
|
+
if (resolved) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (msg.type === 'PEER_COUNT') {
|
|
461
|
+
resolved = true;
|
|
462
|
+
clearTimeout(timeout);
|
|
463
|
+
this.processes[clientIndex].off('message', handler);
|
|
464
|
+
resolve(msg.count as number);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const timeout = setTimeout(() => {
|
|
469
|
+
if (resolved) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
resolved = true;
|
|
473
|
+
this.processes[clientIndex].off('message', handler);
|
|
474
|
+
resolve(0);
|
|
475
|
+
}, timeoutMs);
|
|
476
|
+
|
|
477
|
+
this.processes[clientIndex].on('message', handler);
|
|
478
|
+
this.processes[clientIndex].send({ type: 'GET_PEER_COUNT' });
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
428
482
|
/**
|
|
429
483
|
* Run a req/resp benchmark across all worker clients.
|
|
430
484
|
*
|