@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.24de95ac
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.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -9
- package/dest/client/factory.d.ts +13 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -24
- package/dest/client/index.d.ts +1 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +155 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +72 -169
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +365 -174
- package/dest/config.d.ts +123 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +173 -34
- package/dest/enr/generate-enr.d.ts +10 -2
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/index.d.ts +3 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +42 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +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 +204 -54
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +93 -15
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +86 -18
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +9 -15
- package/dest/mem_pools/instrumentation.d.ts +7 -11
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +25 -37
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +93 -9
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +33 -9
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +64 -8
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +61 -12
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +56 -86
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
- package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +74 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
- package/dest/msg_validators/tx_validator/index.d.ts +7 -0
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +7 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +7 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +91 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
- package/dest/services/discv5/discV5_service.d.ts +9 -8
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +63 -36
- package/dest/services/dummy_service.d.ts +49 -10
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +25 -6
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +73 -5
- package/dest/services/index.d.ts +4 -0
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +18 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +157 -0
- package/dest/services/libp2p/libp2p_service.d.ts +87 -42
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +500 -218
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +11 -2
- package/dest/services/peer-manager/peer_manager.d.ts +126 -15
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +547 -72
- package/dest/services/reqresp/config.d.ts +10 -8
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +30 -13
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
- package/dest/services/reqresp/index.d.ts +2 -1
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +72 -23
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +45 -26
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +5 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +28 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +2 -4
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +2 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +0 -2
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +38 -6
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +72 -5
- package/dest/services/reqresp/protocols/tx.d.ts +12 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +4 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +45 -47
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +298 -207
- package/dest/services/reqresp/status.d.ts +9 -3
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +22 -18
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +58 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +300 -0
- package/dest/services/tx_collection/index.d.ts +3 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +2 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +34 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +176 -0
- package/dest/services/tx_collection/tx_collection.d.ts +110 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +128 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +111 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +49 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +210 -0
- package/dest/services/tx_provider_instrumentation.d.ts +13 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +1 -0
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +1 -0
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +32 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -16
- package/dest/test-helpers/mock-pubsub.d.ts +59 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +130 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +14 -10
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +62 -28
- package/dest/testbench/p2p_client_testbench_worker.js +96 -25
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +0 -5
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +11 -19
- package/dest/types/index.d.ts +3 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +22 -15
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +64 -67
- package/dest/versioning.d.ts +3 -3
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +28 -24
- package/src/bootstrap/bootstrap.ts +27 -11
- package/src/client/factory.ts +136 -45
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +195 -0
- package/src/client/p2p_client.ts +460 -327
- package/src/config.ts +288 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +48 -4
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -55
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +117 -20
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +114 -22
- package/src/mem_pools/attestation_pool/mocks.ts +11 -10
- package/src/mem_pools/instrumentation.ts +32 -46
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
- package/src/msg_validators/attestation_validator/attestation_validator.ts +55 -10
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +66 -14
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
- package/src/msg_validators/tx_validator/data_validator.ts +81 -69
- package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
- package/src/msg_validators/tx_validator/factory.ts +109 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
- package/src/msg_validators/tx_validator/index.ts +7 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
- package/src/msg_validators/tx_validator/phases_validator.ts +114 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
- package/src/services/discv5/discV5_service.ts +84 -38
- package/src/services/dummy_service.ts +147 -9
- package/src/services/encoding.ts +80 -5
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +158 -0
- package/src/services/libp2p/libp2p_service.ts +646 -263
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +16 -1
- package/src/services/peer-manager/peer_manager.ts +652 -78
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +91 -36
- package/src/services/reqresp/metrics.ts +4 -1
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +24 -3
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +9 -7
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +117 -5
- package/src/services/reqresp/protocols/tx.ts +35 -6
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +387 -256
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +45 -21
- package/src/services/tx_collection/config.ts +84 -0
- package/src/services/tx_collection/fast_tx_collection.ts +340 -0
- package/src/services/tx_collection/index.ts +2 -0
- package/src/services/tx_collection/instrumentation.ts +43 -0
- package/src/services/tx_collection/slow_tx_collection.ts +232 -0
- package/src/services/tx_collection/tx_collection.ts +215 -0
- package/src/services/tx_collection/tx_collection_sink.ts +129 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +216 -0
- package/src/services/tx_provider_instrumentation.ts +44 -0
- package/src/test-helpers/index.ts +1 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +111 -21
- package/src/test-helpers/mock-pubsub.ts +188 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +86 -35
- package/src/testbench/p2p_client_testbench_worker.ts +145 -22
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +17 -23
- package/src/types/index.ts +2 -0
- package/src/util.ts +93 -89
- package/src/versioning.ts +11 -4
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { type ConfigMapping } from '@aztec/foundation/config';
|
|
2
|
-
export declare const DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS =
|
|
3
|
-
export declare const DEFAULT_OVERALL_REQUEST_TIMEOUT_MS =
|
|
2
|
+
export declare const DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS = 10000;
|
|
3
|
+
export declare const DEFAULT_OVERALL_REQUEST_TIMEOUT_MS = 10000;
|
|
4
|
+
export declare const DEFAULT_REQRESP_DIAL_TIMEOUT_MS = 5000;
|
|
5
|
+
export declare const DEFAULT_OPTIMISTIC_NEGOTIATION = false;
|
|
4
6
|
export declare const DEFAULT_P2P_REQRESP_CONFIG: P2PReqRespConfig;
|
|
5
7
|
export interface P2PReqRespConfig {
|
|
6
|
-
/**
|
|
7
|
-
* The overall timeout for a request response operation.
|
|
8
|
-
*/
|
|
8
|
+
/** The overall timeout for a request response operation. */
|
|
9
9
|
overallRequestTimeoutMs: number;
|
|
10
|
-
/**
|
|
11
|
-
* The timeout for an individual request response peer interaction.
|
|
12
|
-
*/
|
|
10
|
+
/** The timeout for an individual request response peer interaction. */
|
|
13
11
|
individualRequestTimeoutMs: number;
|
|
12
|
+
/** Whether to use optimistic protocol negotiation when dialing to another peer (opposite of `negotiateFully`). */
|
|
13
|
+
p2pOptimisticNegotiation: boolean;
|
|
14
|
+
/** How long to wait for the dial protocol to establish a connection */
|
|
15
|
+
dialTimeoutMs: number;
|
|
14
16
|
}
|
|
15
17
|
export declare const p2pReqRespConfigMappings: Record<keyof P2PReqRespConfig, ConfigMapping>;
|
|
16
18
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAA2C,MAAM,0BAA0B,CAAC;AAEvG,eAAO,MAAM,qCAAqC,QAAS,CAAC;AAC5D,eAAO,MAAM,kCAAkC,QAAS,CAAC;AACzD,eAAO,MAAM,+BAA+B,OAAQ,CAAC;AACrD,eAAO,MAAM,8BAA8B,QAAQ,CAAC;AAGpD,eAAO,MAAM,0BAA0B,EAAE,gBAKxC,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,uBAAuB,EAAE,MAAM,CAAC;IAEhC,uEAAuE;IACvE,0BAA0B,EAAE,MAAM,CAAC;IAEnC,kHAAkH;IAClH,wBAAwB,EAAE,OAAO,CAAC;IAElC,uEAAuE;IACvE,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,gBAAgB,EAAE,aAAa,CAsBlF,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
-
export const DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS =
|
|
3
|
-
export const DEFAULT_OVERALL_REQUEST_TIMEOUT_MS =
|
|
1
|
+
import { booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
+
export const DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS = 10_000;
|
|
3
|
+
export const DEFAULT_OVERALL_REQUEST_TIMEOUT_MS = 10_000; // Not currently used
|
|
4
|
+
export const DEFAULT_REQRESP_DIAL_TIMEOUT_MS = 5_000;
|
|
5
|
+
export const DEFAULT_OPTIMISTIC_NEGOTIATION = false;
|
|
4
6
|
// For use in tests.
|
|
5
7
|
export const DEFAULT_P2P_REQRESP_CONFIG = {
|
|
6
8
|
overallRequestTimeoutMs: DEFAULT_OVERALL_REQUEST_TIMEOUT_MS,
|
|
7
|
-
individualRequestTimeoutMs: DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS
|
|
9
|
+
individualRequestTimeoutMs: DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS,
|
|
10
|
+
dialTimeoutMs: DEFAULT_REQRESP_DIAL_TIMEOUT_MS,
|
|
11
|
+
p2pOptimisticNegotiation: DEFAULT_OPTIMISTIC_NEGOTIATION
|
|
8
12
|
};
|
|
9
13
|
export const p2pReqRespConfigMappings = {
|
|
10
14
|
overallRequestTimeoutMs: {
|
|
@@ -16,5 +20,15 @@ export const p2pReqRespConfigMappings = {
|
|
|
16
20
|
env: 'P2P_REQRESP_INDIVIDUAL_REQUEST_TIMEOUT_MS',
|
|
17
21
|
description: 'The timeout for an individual request response peer interaction.',
|
|
18
22
|
...numberConfigHelper(DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS)
|
|
23
|
+
},
|
|
24
|
+
dialTimeoutMs: {
|
|
25
|
+
env: 'P2P_REQRESP_DIAL_TIMEOUT_MS',
|
|
26
|
+
description: 'How long to wait for the dial protocol to establish a connection',
|
|
27
|
+
...numberConfigHelper(DEFAULT_REQRESP_DIAL_TIMEOUT_MS)
|
|
28
|
+
},
|
|
29
|
+
p2pOptimisticNegotiation: {
|
|
30
|
+
env: 'P2P_REQRESP_OPTIMISTIC_NEGOTIATION',
|
|
31
|
+
description: 'Whether to use optimistic protocol negotiation when dialing to another peer (opposite of `negotiateFully`).',
|
|
32
|
+
...booleanConfigHelper(DEFAULT_OPTIMISTIC_NEGOTIATION)
|
|
19
33
|
}
|
|
20
34
|
};
|
|
@@ -18,7 +18,7 @@ export declare class BatchConnectionSampler {
|
|
|
18
18
|
private readonly logger;
|
|
19
19
|
private readonly batch;
|
|
20
20
|
private readonly requestsPerPeer;
|
|
21
|
-
constructor(connectionSampler: ConnectionSampler, batchSize: number, maxPeers: number);
|
|
21
|
+
constructor(connectionSampler: ConnectionSampler, batchSize: number, maxPeers: number, exclude?: PeerId[], logger?: import("@aztec/foundation/log").Logger);
|
|
22
22
|
/**
|
|
23
23
|
* Gets the peer responsible for handling a specific request index
|
|
24
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch_connection_sampler.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/connection-sampler/batch_connection_sampler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAsB;
|
|
1
|
+
{"version":3,"file":"batch_connection_sampler.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/connection-sampler/batch_connection_sampler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAsB;IAK/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAIlC,OAAO,CAAC,QAAQ,CAAC,MAAM;IARzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAGtB,iBAAiB,EAAE,iBAAiB,EACrD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAAE,EACD,MAAM,yCAAuD;IAiBhF;;;;;OAKG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAUpD;;;;;OAKG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAmB1C;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;OAEG;IACH,IAAI,iBAAiB,IAAI,MAAM,CAE9B;CACF"}
|
|
@@ -16,9 +16,9 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
16
16
|
logger;
|
|
17
17
|
batch;
|
|
18
18
|
requestsPerPeer;
|
|
19
|
-
constructor(connectionSampler, batchSize, maxPeers){
|
|
19
|
+
constructor(connectionSampler, batchSize, maxPeers, exclude, logger = createLogger('p2p:reqresp:batch-connection-sampler')){
|
|
20
20
|
this.connectionSampler = connectionSampler;
|
|
21
|
-
this.logger =
|
|
21
|
+
this.logger = logger;
|
|
22
22
|
this.batch = [];
|
|
23
23
|
if (maxPeers <= 0) {
|
|
24
24
|
throw new Error('Max peers cannot be 0');
|
|
@@ -29,7 +29,11 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
29
29
|
// Calculate how many requests each peer should handle, cannot be 0
|
|
30
30
|
this.requestsPerPeer = Math.max(1, Math.floor(batchSize / maxPeers));
|
|
31
31
|
// Sample initial peers
|
|
32
|
-
|
|
32
|
+
const excluding = exclude && new Map(exclude.map((peerId)=>[
|
|
33
|
+
peerId.toString(),
|
|
34
|
+
true
|
|
35
|
+
]));
|
|
36
|
+
this.batch = this.connectionSampler.samplePeersBatch(maxPeers, excluding);
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* Gets the peer responsible for handling a specific request index
|
|
@@ -60,17 +64,17 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
60
64
|
true
|
|
61
65
|
]
|
|
62
66
|
]);
|
|
63
|
-
const newPeer = this.connectionSampler.getPeer(excluding);
|
|
67
|
+
const newPeer = this.connectionSampler.getPeer(excluding); // Q: Shouldn't we accumulate all excluded peers? Otherwise the sampler could return us a previously excluded peer?
|
|
64
68
|
if (newPeer) {
|
|
65
69
|
this.batch[index] = newPeer;
|
|
66
|
-
this.logger.trace(
|
|
70
|
+
this.logger.trace('Replaced peer', {
|
|
67
71
|
peerId,
|
|
68
72
|
newPeer
|
|
69
73
|
});
|
|
70
74
|
} else {
|
|
71
75
|
// If we couldn't get a replacement, remove the peer and compact the array
|
|
72
76
|
this.batch.splice(index, 1);
|
|
73
|
-
this.logger.trace(
|
|
77
|
+
this.logger.trace('Removed peer', {
|
|
74
78
|
peerId
|
|
75
79
|
});
|
|
76
80
|
}
|
|
@@ -3,7 +3,7 @@ export declare class RandomSampler {
|
|
|
3
3
|
random(max: number): number;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
|
-
* A class that samples peers from the libp2p node and returns a peer that we don't already have a connection open to.
|
|
6
|
+
* A class that samples peers from the libp2p node and returns a peer that we don't already have a reqresp connection open to.
|
|
7
7
|
* If we already have a connection open, we try to sample a different peer.
|
|
8
8
|
* We do this MAX_SAMPLE_ATTEMPTS times, if we still don't find a peer we just go for it.
|
|
9
9
|
*
|
|
@@ -11,16 +11,17 @@ export declare class RandomSampler {
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class ConnectionSampler {
|
|
13
13
|
private readonly libp2p;
|
|
14
|
-
private readonly cleanupIntervalMs;
|
|
15
14
|
private readonly sampler;
|
|
16
15
|
private readonly logger;
|
|
16
|
+
private readonly opts;
|
|
17
17
|
private cleanupInterval;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
protected readonly activeConnectionsCount: Map<string, number>;
|
|
19
|
+
protected readonly streams: Set<Stream>;
|
|
20
|
+
private abortOnStop;
|
|
21
|
+
constructor(libp2p: Libp2p, sampler: RandomSampler, logger?: import("@aztec/foundation/log").Logger, opts?: {
|
|
22
|
+
cleanupIntervalMs?: number;
|
|
23
|
+
p2pOptimisticNegotiation?: boolean;
|
|
24
|
+
});
|
|
24
25
|
/**
|
|
25
26
|
* Stops the cleanup job and closes all active connections
|
|
26
27
|
*/
|
|
@@ -32,27 +33,43 @@ export declare class ConnectionSampler {
|
|
|
32
33
|
* @returns
|
|
33
34
|
*/
|
|
34
35
|
getPeer(excluding?: Map<string, boolean>): PeerId | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Samples a peer from a list of peers, excluding those that have active (reqresp) connections or are in the exclusion list
|
|
38
|
+
*
|
|
39
|
+
* @param peers - The list of peers to sample from
|
|
40
|
+
* @param excluding - The peers to exclude from the sampling
|
|
41
|
+
* @returns - A peer from the list, or undefined if no peers are available,
|
|
42
|
+
* - a boolean indicating if the peer has active connections, and
|
|
43
|
+
* - all sampled peers - to enable optional resampling
|
|
44
|
+
*
|
|
45
|
+
* @dev The provided list peers, should be mutated by this function. This allows batch sampling
|
|
46
|
+
* to be performed without making extra copies of the list.
|
|
47
|
+
*/
|
|
48
|
+
getPeerFromList(peers: PeerId[], excluding?: Map<string, boolean>): {
|
|
49
|
+
peer: PeerId | undefined;
|
|
50
|
+
sampledPeers: PeerId[];
|
|
51
|
+
};
|
|
35
52
|
/**
|
|
36
53
|
* Samples a batch of unique peers from the libp2p node, prioritizing peers without active connections
|
|
37
54
|
*
|
|
38
55
|
* @param numberToSample - The number of peers to sample
|
|
56
|
+
* @param excluding - The peers to exclude from the sampling
|
|
39
57
|
* @returns Array of unique sampled peers, prioritizing those without active connections
|
|
40
58
|
*/
|
|
41
|
-
samplePeersBatch(numberToSample: number): PeerId[];
|
|
59
|
+
samplePeersBatch(numberToSample: number, excluding?: Map<string, boolean>): PeerId[];
|
|
42
60
|
/**
|
|
43
61
|
* Dials a protocol and returns the stream
|
|
44
62
|
*
|
|
45
63
|
* @param peerId - The peer id
|
|
46
64
|
* @param protocol - The protocol
|
|
65
|
+
* @param timeout - Abort connection if it takes too long
|
|
47
66
|
* @returns The stream
|
|
48
67
|
*/
|
|
49
|
-
dialProtocol(peerId: PeerId, protocol: string): Promise<Stream>;
|
|
68
|
+
dialProtocol(peerId: PeerId, protocol: string, timeout?: number): Promise<Stream>;
|
|
50
69
|
/**
|
|
51
70
|
* Closes a stream and updates the active connections count
|
|
52
|
-
*
|
|
53
|
-
* @param streamId - The stream id
|
|
54
71
|
*/
|
|
55
|
-
close(
|
|
72
|
+
close(stream: Stream): Promise<void>;
|
|
56
73
|
/**
|
|
57
74
|
* Cleans up stale connections that we have lost accounting for
|
|
58
75
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection_sampler.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/connection-sampler/connection_sampler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"connection_sampler.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/connection-sampler/connection_sampler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhE,qBAAa,aAAa;IACxB,MAAM,CAAC,GAAG,EAAE,MAAM;CAGnB;AAED;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAY1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAdvB,OAAO,CAAC,eAAe,CAAiB;IAGxC,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAG3E,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAEpD,OAAO,CAAC,WAAW,CAA0C;gBAG1C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,EACtB,MAAM,yCAAiD,EACvD,IAAI,GAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAAC,wBAAwB,CAAC,EAAE,OAAO,CAAA;KAAO;IAQhG;;OAEG;IACG,IAAI;IAWV;;;;;OAKG;IACH,OAAO,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS;IAO7D;;;;;;;;;;;OAWG;IACH,eAAe,CACb,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B;QACD,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB;IAuCD;;;;;;OAMG;IACH,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE;IA0CpF;;;;;;;OAOG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBvF;;OAEG;IACG,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC1C;;OAEG;YACW,uBAAuB;CAqBtC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { AbortError } from '@aztec/foundation/error';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { SerialQueue } from '@aztec/foundation/queue';
|
|
3
3
|
const MAX_SAMPLE_ATTEMPTS = 4;
|
|
4
4
|
export class RandomSampler {
|
|
5
5
|
random(max) {
|
|
@@ -7,43 +7,40 @@ export class RandomSampler {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* A class that samples peers from the libp2p node and returns a peer that we don't already have a connection open to.
|
|
10
|
+
* A class that samples peers from the libp2p node and returns a peer that we don't already have a reqresp connection open to.
|
|
11
11
|
* If we already have a connection open, we try to sample a different peer.
|
|
12
12
|
* We do this MAX_SAMPLE_ATTEMPTS times, if we still don't find a peer we just go for it.
|
|
13
13
|
*
|
|
14
14
|
* @dev Close must always be called on connections, else memory leak
|
|
15
15
|
*/ export class ConnectionSampler {
|
|
16
16
|
libp2p;
|
|
17
|
-
cleanupIntervalMs;
|
|
18
17
|
sampler;
|
|
19
18
|
logger;
|
|
19
|
+
opts;
|
|
20
20
|
cleanupInterval;
|
|
21
|
-
|
|
21
|
+
// Map from stringified peer id to number of active connections
|
|
22
22
|
activeConnectionsCount;
|
|
23
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
23
24
|
streams;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
constructor(libp2p, cleanupIntervalMs = 60000, sampler = new RandomSampler()){
|
|
25
|
+
abortOnStop;
|
|
26
|
+
constructor(libp2p, sampler, logger = createLogger('p2p:reqresp:connection-sampler'), opts = {}){
|
|
27
27
|
this.libp2p = libp2p;
|
|
28
|
-
this.cleanupIntervalMs = cleanupIntervalMs;
|
|
29
28
|
this.sampler = sampler;
|
|
30
|
-
this.logger =
|
|
31
|
-
this.
|
|
29
|
+
this.logger = logger;
|
|
30
|
+
this.opts = opts;
|
|
32
31
|
this.activeConnectionsCount = new Map();
|
|
33
|
-
this.streams = new
|
|
34
|
-
this.
|
|
35
|
-
this.cleanupInterval = setInterval(()=>void this.cleanupStaleConnections(), this.cleanupIntervalMs);
|
|
36
|
-
this.dialQueue.start();
|
|
32
|
+
this.streams = new Set();
|
|
33
|
+
this.abortOnStop = new AbortController();
|
|
34
|
+
this.cleanupInterval = setInterval(()=>void this.cleanupStaleConnections(), this.opts.cleanupIntervalMs ?? 60_000);
|
|
37
35
|
}
|
|
38
36
|
/**
|
|
39
37
|
* Stops the cleanup job and closes all active connections
|
|
40
38
|
*/ async stop() {
|
|
41
39
|
this.logger.info('Stopping connection sampler');
|
|
40
|
+
this.abortOnStop.abort(new AbortError('Connection sampler stopped'));
|
|
42
41
|
clearInterval(this.cleanupInterval);
|
|
43
|
-
this.abortController.abort();
|
|
44
|
-
await this.dialQueue.end();
|
|
45
42
|
// Close all active streams
|
|
46
|
-
const closePromises = Array.from(this.streams.
|
|
43
|
+
const closePromises = Array.from(this.streams.values()).map((stream)=>this.close(stream));
|
|
47
44
|
await Promise.all(closePromises);
|
|
48
45
|
this.logger.info('Connection sampler stopped');
|
|
49
46
|
}
|
|
@@ -55,56 +52,102 @@ export class RandomSampler {
|
|
|
55
52
|
*/ getPeer(excluding) {
|
|
56
53
|
// In libp2p getPeers performs a shallow copy, so this array can be sliced from safetly
|
|
57
54
|
const peers = this.libp2p.getPeers();
|
|
55
|
+
const { peer } = this.getPeerFromList(peers, excluding);
|
|
56
|
+
return peer;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Samples a peer from a list of peers, excluding those that have active (reqresp) connections or are in the exclusion list
|
|
60
|
+
*
|
|
61
|
+
* @param peers - The list of peers to sample from
|
|
62
|
+
* @param excluding - The peers to exclude from the sampling
|
|
63
|
+
* @returns - A peer from the list, or undefined if no peers are available,
|
|
64
|
+
* - a boolean indicating if the peer has active connections, and
|
|
65
|
+
* - all sampled peers - to enable optional resampling
|
|
66
|
+
*
|
|
67
|
+
* @dev The provided list peers, should be mutated by this function. This allows batch sampling
|
|
68
|
+
* to be performed without making extra copies of the list.
|
|
69
|
+
*/ getPeerFromList(peers, excluding) {
|
|
58
70
|
if (peers.length === 0) {
|
|
59
|
-
return
|
|
71
|
+
return {
|
|
72
|
+
peer: undefined,
|
|
73
|
+
sampledPeers: []
|
|
74
|
+
};
|
|
60
75
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
const sampledPeers = [];
|
|
77
|
+
// Try to find a peer that has no active connections and is not in the exclusion list
|
|
78
|
+
for(let attempts = 0; attempts < MAX_SAMPLE_ATTEMPTS && peers.length > 0; attempts++){
|
|
79
|
+
const randomIndex = this.sampler.random(peers.length);
|
|
80
|
+
const peer = peers[randomIndex];
|
|
81
|
+
const hasActiveConnections = (this.activeConnectionsCount.get(peer.toString()) ?? 0) > 0;
|
|
82
|
+
const isExcluded = excluding?.get(peer.toString()) ?? false;
|
|
83
|
+
// Remove this peer from consideration
|
|
67
84
|
peers.splice(randomIndex, 1);
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
// If peer is suitable (no active connections and not excluded), return it
|
|
86
|
+
if (!hasActiveConnections && !isExcluded) {
|
|
87
|
+
this.logger.trace('Sampled peer', {
|
|
88
|
+
attempts,
|
|
89
|
+
peer
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
peer,
|
|
93
|
+
sampledPeers
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// Keep track of peers that have active reqresp channels, batch sampling will use these to resample
|
|
97
|
+
sampledPeers.push(peer);
|
|
70
98
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
99
|
+
// If we've exhausted our attempts or peers list is empty, return the last peer if available
|
|
100
|
+
const lastPeer = peers.length > 0 ? peers[this.sampler.random(peers.length)] : undefined;
|
|
101
|
+
this.logger.trace('Sampled peer', {
|
|
102
|
+
attempts: MAX_SAMPLE_ATTEMPTS,
|
|
103
|
+
peer: lastPeer?.toString()
|
|
74
104
|
});
|
|
75
|
-
return
|
|
105
|
+
return {
|
|
106
|
+
peer: lastPeer,
|
|
107
|
+
sampledPeers
|
|
108
|
+
};
|
|
76
109
|
}
|
|
77
110
|
/**
|
|
78
111
|
* Samples a batch of unique peers from the libp2p node, prioritizing peers without active connections
|
|
79
112
|
*
|
|
80
113
|
* @param numberToSample - The number of peers to sample
|
|
114
|
+
* @param excluding - The peers to exclude from the sampling
|
|
81
115
|
* @returns Array of unique sampled peers, prioritizing those without active connections
|
|
82
|
-
*/ samplePeersBatch(numberToSample) {
|
|
116
|
+
*/ samplePeersBatch(numberToSample, excluding) {
|
|
83
117
|
const peers = this.libp2p.getPeers();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
118
|
+
this.logger.debug('Sampling peers batch', {
|
|
119
|
+
numberToSample,
|
|
120
|
+
peers
|
|
121
|
+
});
|
|
122
|
+
// Only sample as many peers as we have available
|
|
123
|
+
numberToSample = Math.min(numberToSample, peers.length);
|
|
124
|
+
const batch = [];
|
|
125
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
126
|
+
const withActiveConnections = new Set();
|
|
127
|
+
for(let i = 0; i < numberToSample; i++){
|
|
128
|
+
const { peer, sampledPeers } = this.getPeerFromList(peers, excluding);
|
|
129
|
+
if (peer) {
|
|
130
|
+
batch.push(peer);
|
|
131
|
+
}
|
|
132
|
+
if (sampledPeers.length > 0) {
|
|
133
|
+
sampledPeers.forEach((peer)=>withActiveConnections.add(peer));
|
|
94
134
|
}
|
|
95
135
|
}
|
|
136
|
+
const lengthWithoutConnections = batch.length;
|
|
96
137
|
// If we still need more peers, sample from those with connections
|
|
97
|
-
while(
|
|
98
|
-
const randomIndex = this.sampler.random(
|
|
99
|
-
const
|
|
100
|
-
|
|
138
|
+
while(batch.length < numberToSample && withActiveConnections.size > 0){
|
|
139
|
+
const randomIndex = this.sampler.random(withActiveConnections.size);
|
|
140
|
+
const peer = Array.from(withActiveConnections)[randomIndex];
|
|
141
|
+
withActiveConnections.delete(peer);
|
|
142
|
+
batch.push(peer);
|
|
101
143
|
}
|
|
102
|
-
this.logger.trace(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
144
|
+
this.logger.trace('Batch sampled peers', {
|
|
145
|
+
length: batch.length,
|
|
146
|
+
peers: batch,
|
|
147
|
+
withoutConnections: lengthWithoutConnections,
|
|
148
|
+
withConnections: numberToSample - lengthWithoutConnections
|
|
106
149
|
});
|
|
107
|
-
return
|
|
150
|
+
return batch;
|
|
108
151
|
}
|
|
109
152
|
// Set of passthrough functions to keep track of active connections
|
|
110
153
|
/**
|
|
@@ -112,51 +155,60 @@ export class RandomSampler {
|
|
|
112
155
|
*
|
|
113
156
|
* @param peerId - The peer id
|
|
114
157
|
* @param protocol - The protocol
|
|
158
|
+
* @param timeout - Abort connection if it takes too long
|
|
115
159
|
* @returns The stream
|
|
116
|
-
*/ async dialProtocol(peerId, protocol) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
160
|
+
*/ async dialProtocol(peerId, protocol, timeout) {
|
|
161
|
+
const stream = await this.libp2p.dialProtocol(peerId, protocol, {
|
|
162
|
+
signal: AbortSignal.any(timeout ? [
|
|
163
|
+
this.abortOnStop.signal,
|
|
164
|
+
AbortSignal.timeout(timeout)
|
|
165
|
+
] : [
|
|
166
|
+
this.abortOnStop.signal
|
|
167
|
+
]),
|
|
168
|
+
negotiateFully: !this.opts.p2pOptimisticNegotiation
|
|
125
169
|
});
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
|
|
170
|
+
stream.metadata.peerId = peerId;
|
|
171
|
+
this.streams.add(stream);
|
|
172
|
+
const peerIdString = peerId.toString();
|
|
173
|
+
const updatedActiveConnectionsCount = (this.activeConnectionsCount.get(peerIdString) ?? 0) + 1;
|
|
174
|
+
this.activeConnectionsCount.set(peerIdString, updatedActiveConnectionsCount);
|
|
175
|
+
this.logger.trace('Dialed protocol', {
|
|
129
176
|
streamId: stream.id,
|
|
130
|
-
|
|
177
|
+
protocol,
|
|
178
|
+
peerId: peerIdString,
|
|
131
179
|
activeConnectionsCount: updatedActiveConnectionsCount
|
|
132
180
|
});
|
|
133
181
|
return stream;
|
|
134
182
|
}
|
|
135
183
|
/**
|
|
136
184
|
* Closes a stream and updates the active connections count
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*/ async close(streamId) {
|
|
185
|
+
*/ async close(stream) {
|
|
186
|
+
let peerId = undefined;
|
|
140
187
|
try {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
188
|
+
peerId = stream.metadata.peerId;
|
|
189
|
+
let updatedActiveConnectionsCount = undefined;
|
|
190
|
+
if (!peerId) {
|
|
191
|
+
this.logger.warn(`Stream ${stream.id} does not have a peerId set`);
|
|
192
|
+
} else {
|
|
193
|
+
updatedActiveConnectionsCount = (this.activeConnectionsCount.get(peerId.toString()) ?? 1) - 1;
|
|
194
|
+
this.activeConnectionsCount.set(peerId.toString(), updatedActiveConnectionsCount);
|
|
145
195
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
this.logger.trace(`Closing connection to peer ${peerId.toString()}`, {
|
|
150
|
-
streamId,
|
|
151
|
-
peerId: peerId.toString(),
|
|
196
|
+
this.logger.trace('Closing connection', {
|
|
197
|
+
streamId: stream.id,
|
|
198
|
+
peerId: peerId?.toString(),
|
|
152
199
|
protocol: stream.protocol,
|
|
153
200
|
activeConnectionsCount: updatedActiveConnectionsCount
|
|
154
201
|
});
|
|
155
|
-
|
|
202
|
+
if (!this.streams.has(stream)) {
|
|
203
|
+
this.logger.debug(`Stream ${stream.id} is not in the active streams set`);
|
|
204
|
+
}
|
|
205
|
+
await stream.close();
|
|
156
206
|
} catch (error) {
|
|
157
|
-
this.logger.error(`Failed to close connection to peer with stream id ${
|
|
207
|
+
this.logger.error(`Failed to close connection to peer ${peerId ?? 'unknown'} with stream id ${stream.id}`, error);
|
|
208
|
+
// graceful close failed, abort the stream
|
|
209
|
+
stream.abort(new AbortError('Failed to close stream gracefully'));
|
|
158
210
|
} finally{
|
|
159
|
-
this.streams.delete(
|
|
211
|
+
this.streams.delete(stream);
|
|
160
212
|
}
|
|
161
213
|
}
|
|
162
214
|
/**
|
|
@@ -164,15 +216,21 @@ export class RandomSampler {
|
|
|
164
216
|
*/ async cleanupStaleConnections() {
|
|
165
217
|
// Look for streams without anything in the activeConnectionsCount
|
|
166
218
|
// If we find anything, close the stream
|
|
167
|
-
for (const
|
|
219
|
+
for (const stream of this.streams.values()){
|
|
168
220
|
try {
|
|
169
221
|
// Check if we have lost track of accounting
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this.logger.
|
|
222
|
+
const peerId = stream.metadata.peerId;
|
|
223
|
+
if (!peerId) {
|
|
224
|
+
this.logger.warn(`Stream ${stream.id} does not have a peerId set`);
|
|
225
|
+
} else if (this.activeConnectionsCount.get(peerId.toString()) === 0) {
|
|
226
|
+
await this.close(stream);
|
|
227
|
+
this.logger.debug('Cleaned up stale connection', {
|
|
228
|
+
streamId: stream.id,
|
|
229
|
+
peerId: peerId.toString()
|
|
230
|
+
});
|
|
173
231
|
}
|
|
174
232
|
} catch (error) {
|
|
175
|
-
this.logger.error(`Error cleaning up stale connection ${
|
|
233
|
+
this.logger.error(`Error cleaning up stale connection to peer ${stream.metadata.peerId?.toString() ?? 'unknown'} stream ${stream.id}`, {
|
|
176
234
|
error
|
|
177
235
|
});
|
|
178
236
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
|