@aztec/p2p 0.0.0-test.0 → 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,24 +1,30 @@
|
|
|
1
|
-
import { type ConfigMapping, numberConfigHelper } from '@aztec/foundation/config';
|
|
1
|
+
import { type ConfigMapping, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
2
|
|
|
3
|
-
export const DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS =
|
|
4
|
-
export const DEFAULT_OVERALL_REQUEST_TIMEOUT_MS =
|
|
3
|
+
export const DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS = 10_000;
|
|
4
|
+
export const DEFAULT_OVERALL_REQUEST_TIMEOUT_MS = 10_000; // Not currently used
|
|
5
|
+
export const DEFAULT_REQRESP_DIAL_TIMEOUT_MS = 5_000;
|
|
6
|
+
export const DEFAULT_OPTIMISTIC_NEGOTIATION = false;
|
|
5
7
|
|
|
6
8
|
// For use in tests.
|
|
7
9
|
export const DEFAULT_P2P_REQRESP_CONFIG: P2PReqRespConfig = {
|
|
8
10
|
overallRequestTimeoutMs: DEFAULT_OVERALL_REQUEST_TIMEOUT_MS,
|
|
9
11
|
individualRequestTimeoutMs: DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS,
|
|
12
|
+
dialTimeoutMs: DEFAULT_REQRESP_DIAL_TIMEOUT_MS,
|
|
13
|
+
p2pOptimisticNegotiation: DEFAULT_OPTIMISTIC_NEGOTIATION,
|
|
10
14
|
};
|
|
11
15
|
|
|
12
16
|
export interface P2PReqRespConfig {
|
|
13
|
-
/**
|
|
14
|
-
* The overall timeout for a request response operation.
|
|
15
|
-
*/
|
|
17
|
+
/** The overall timeout for a request response operation. */
|
|
16
18
|
overallRequestTimeoutMs: number;
|
|
17
19
|
|
|
18
|
-
/**
|
|
19
|
-
* The timeout for an individual request response peer interaction.
|
|
20
|
-
*/
|
|
20
|
+
/** The timeout for an individual request response peer interaction. */
|
|
21
21
|
individualRequestTimeoutMs: number;
|
|
22
|
+
|
|
23
|
+
/** Whether to use optimistic protocol negotiation when dialing to another peer (opposite of `negotiateFully`). */
|
|
24
|
+
p2pOptimisticNegotiation: boolean;
|
|
25
|
+
|
|
26
|
+
/** How long to wait for the dial protocol to establish a connection */
|
|
27
|
+
dialTimeoutMs: number;
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export const p2pReqRespConfigMappings: Record<keyof P2PReqRespConfig, ConfigMapping> = {
|
|
@@ -32,4 +38,15 @@ export const p2pReqRespConfigMappings: Record<keyof P2PReqRespConfig, ConfigMapp
|
|
|
32
38
|
description: 'The timeout for an individual request response peer interaction.',
|
|
33
39
|
...numberConfigHelper(DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS),
|
|
34
40
|
},
|
|
41
|
+
dialTimeoutMs: {
|
|
42
|
+
env: 'P2P_REQRESP_DIAL_TIMEOUT_MS',
|
|
43
|
+
description: 'How long to wait for the dial protocol to establish a connection',
|
|
44
|
+
...numberConfigHelper(DEFAULT_REQRESP_DIAL_TIMEOUT_MS),
|
|
45
|
+
},
|
|
46
|
+
p2pOptimisticNegotiation: {
|
|
47
|
+
env: 'P2P_REQRESP_OPTIMISTIC_NEGOTIATION',
|
|
48
|
+
description:
|
|
49
|
+
'Whether to use optimistic protocol negotiation when dialing to another peer (opposite of `negotiateFully`).',
|
|
50
|
+
...booleanConfigHelper(DEFAULT_OPTIMISTIC_NEGOTIATION),
|
|
51
|
+
},
|
|
35
52
|
};
|
|
@@ -18,11 +18,16 @@ import type { ConnectionSampler } from './connection_sampler.js';
|
|
|
18
18
|
* If a peer fails, it is replaced while maintaining the same bucket.
|
|
19
19
|
*/
|
|
20
20
|
export class BatchConnectionSampler {
|
|
21
|
-
private readonly logger = createLogger('p2p:reqresp:batch-connection-sampler');
|
|
22
21
|
private readonly batch: PeerId[] = [];
|
|
23
22
|
private readonly requestsPerPeer: number;
|
|
24
23
|
|
|
25
|
-
constructor(
|
|
24
|
+
constructor(
|
|
25
|
+
private readonly connectionSampler: ConnectionSampler,
|
|
26
|
+
batchSize: number,
|
|
27
|
+
maxPeers: number,
|
|
28
|
+
exclude?: PeerId[],
|
|
29
|
+
private readonly logger = createLogger('p2p:reqresp:batch-connection-sampler'),
|
|
30
|
+
) {
|
|
26
31
|
if (maxPeers <= 0) {
|
|
27
32
|
throw new Error('Max peers cannot be 0');
|
|
28
33
|
}
|
|
@@ -34,7 +39,8 @@ export class BatchConnectionSampler {
|
|
|
34
39
|
this.requestsPerPeer = Math.max(1, Math.floor(batchSize / maxPeers));
|
|
35
40
|
|
|
36
41
|
// Sample initial peers
|
|
37
|
-
|
|
42
|
+
const excluding = exclude && new Map(exclude.map(peerId => [peerId.toString(), true] as const));
|
|
43
|
+
this.batch = this.connectionSampler.samplePeersBatch(maxPeers, excluding);
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
/**
|
|
@@ -66,15 +72,15 @@ export class BatchConnectionSampler {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
const excluding = new Map([[peerId.toString(), true]]);
|
|
69
|
-
const newPeer = this.connectionSampler.getPeer(excluding);
|
|
75
|
+
const newPeer = this.connectionSampler.getPeer(excluding); // Q: Shouldn't we accumulate all excluded peers? Otherwise the sampler could return us a previously excluded peer?
|
|
70
76
|
|
|
71
77
|
if (newPeer) {
|
|
72
78
|
this.batch[index] = newPeer;
|
|
73
|
-
this.logger.trace(
|
|
79
|
+
this.logger.trace('Replaced peer', { peerId, newPeer });
|
|
74
80
|
} else {
|
|
75
81
|
// If we couldn't get a replacement, remove the peer and compact the array
|
|
76
82
|
this.batch.splice(index, 1);
|
|
77
|
-
this.logger.trace(
|
|
83
|
+
this.logger.trace('Removed peer', { peerId });
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
+
import { AbortError } from '@aztec/foundation/error';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { SerialQueue } from '@aztec/foundation/queue';
|
|
3
3
|
|
|
4
4
|
import type { Libp2p, PeerId, Stream } from '@libp2p/interface';
|
|
5
5
|
|
|
6
6
|
const MAX_SAMPLE_ATTEMPTS = 4;
|
|
7
7
|
|
|
8
|
-
interface StreamAndPeerId {
|
|
9
|
-
stream: Stream;
|
|
10
|
-
peerId: PeerId;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
8
|
export class RandomSampler {
|
|
14
9
|
random(max: number) {
|
|
15
10
|
return Math.floor(Math.random() * max);
|
|
@@ -17,31 +12,33 @@ export class RandomSampler {
|
|
|
17
12
|
}
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
|
-
* A class that samples peers from the libp2p node and returns a peer that we don't already have a connection open to.
|
|
15
|
+
* A class that samples peers from the libp2p node and returns a peer that we don't already have a reqresp connection open to.
|
|
21
16
|
* If we already have a connection open, we try to sample a different peer.
|
|
22
17
|
* We do this MAX_SAMPLE_ATTEMPTS times, if we still don't find a peer we just go for it.
|
|
23
18
|
*
|
|
24
19
|
* @dev Close must always be called on connections, else memory leak
|
|
25
20
|
*/
|
|
26
21
|
export class ConnectionSampler {
|
|
27
|
-
private readonly logger = createLogger('p2p:reqresp:connection-sampler');
|
|
28
22
|
private cleanupInterval: NodeJS.Timeout;
|
|
29
|
-
private abortController: AbortController = new AbortController();
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
// Map from stringified peer id to number of active connections
|
|
25
|
+
protected readonly activeConnectionsCount: Map<string, number> = new Map();
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
28
|
+
protected readonly streams: Set<Stream> = new Set();
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
private dialQueue: SerialQueue = new SerialQueue();
|
|
30
|
+
private abortOnStop: AbortController = new AbortController();
|
|
36
31
|
|
|
37
32
|
constructor(
|
|
38
33
|
private readonly libp2p: Libp2p,
|
|
39
|
-
private readonly
|
|
40
|
-
private readonly
|
|
34
|
+
private readonly sampler: RandomSampler,
|
|
35
|
+
private readonly logger = createLogger('p2p:reqresp:connection-sampler'),
|
|
36
|
+
private readonly opts: { cleanupIntervalMs?: number; p2pOptimisticNegotiation?: boolean } = {},
|
|
41
37
|
) {
|
|
42
|
-
this.cleanupInterval = setInterval(
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
this.cleanupInterval = setInterval(
|
|
39
|
+
() => void this.cleanupStaleConnections(),
|
|
40
|
+
this.opts.cleanupIntervalMs ?? 60_000,
|
|
41
|
+
);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
/**
|
|
@@ -49,13 +46,11 @@ export class ConnectionSampler {
|
|
|
49
46
|
*/
|
|
50
47
|
async stop() {
|
|
51
48
|
this.logger.info('Stopping connection sampler');
|
|
49
|
+
this.abortOnStop.abort(new AbortError('Connection sampler stopped'));
|
|
52
50
|
clearInterval(this.cleanupInterval);
|
|
53
51
|
|
|
54
|
-
this.abortController.abort();
|
|
55
|
-
await this.dialQueue.end();
|
|
56
|
-
|
|
57
52
|
// Close all active streams
|
|
58
|
-
const closePromises = Array.from(this.streams.
|
|
53
|
+
const closePromises = Array.from(this.streams.values()).map(stream => this.close(stream));
|
|
59
54
|
await Promise.all(closePromises);
|
|
60
55
|
this.logger.info('Connection sampler stopped');
|
|
61
56
|
}
|
|
@@ -69,70 +64,112 @@ export class ConnectionSampler {
|
|
|
69
64
|
getPeer(excluding?: Map<string, boolean>): PeerId | undefined {
|
|
70
65
|
// In libp2p getPeers performs a shallow copy, so this array can be sliced from safetly
|
|
71
66
|
const peers = this.libp2p.getPeers();
|
|
67
|
+
const { peer } = this.getPeerFromList(peers, excluding);
|
|
68
|
+
return peer;
|
|
69
|
+
}
|
|
72
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Samples a peer from a list of peers, excluding those that have active (reqresp) connections or are in the exclusion list
|
|
73
|
+
*
|
|
74
|
+
* @param peers - The list of peers to sample from
|
|
75
|
+
* @param excluding - The peers to exclude from the sampling
|
|
76
|
+
* @returns - A peer from the list, or undefined if no peers are available,
|
|
77
|
+
* - a boolean indicating if the peer has active connections, and
|
|
78
|
+
* - all sampled peers - to enable optional resampling
|
|
79
|
+
*
|
|
80
|
+
* @dev The provided list peers, should be mutated by this function. This allows batch sampling
|
|
81
|
+
* to be performed without making extra copies of the list.
|
|
82
|
+
*/
|
|
83
|
+
getPeerFromList(
|
|
84
|
+
peers: PeerId[],
|
|
85
|
+
excluding?: Map<string, boolean>,
|
|
86
|
+
): {
|
|
87
|
+
peer: PeerId | undefined;
|
|
88
|
+
sampledPeers: PeerId[];
|
|
89
|
+
} {
|
|
73
90
|
if (peers.length === 0) {
|
|
74
|
-
return undefined;
|
|
91
|
+
return { peer: undefined, sampledPeers: [] };
|
|
75
92
|
}
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
(excluding?.get(peers[randomIndex]?.toString()) ?? false))
|
|
87
|
-
) {
|
|
94
|
+
const sampledPeers: PeerId[] = [];
|
|
95
|
+
// Try to find a peer that has no active connections and is not in the exclusion list
|
|
96
|
+
for (let attempts = 0; attempts < MAX_SAMPLE_ATTEMPTS && peers.length > 0; attempts++) {
|
|
97
|
+
const randomIndex = this.sampler.random(peers.length);
|
|
98
|
+
const peer = peers[randomIndex];
|
|
99
|
+
const hasActiveConnections = (this.activeConnectionsCount.get(peer.toString()) ?? 0) > 0;
|
|
100
|
+
const isExcluded = excluding?.get(peer.toString()) ?? false;
|
|
101
|
+
|
|
102
|
+
// Remove this peer from consideration
|
|
88
103
|
peers.splice(randomIndex, 1);
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
|
|
105
|
+
// If peer is suitable (no active connections and not excluded), return it
|
|
106
|
+
if (!hasActiveConnections && !isExcluded) {
|
|
107
|
+
this.logger.trace('Sampled peer', {
|
|
108
|
+
attempts,
|
|
109
|
+
peer,
|
|
110
|
+
});
|
|
111
|
+
return { peer, sampledPeers };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Keep track of peers that have active reqresp channels, batch sampling will use these to resample
|
|
115
|
+
sampledPeers.push(peer);
|
|
91
116
|
}
|
|
92
117
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
118
|
+
// If we've exhausted our attempts or peers list is empty, return the last peer if available
|
|
119
|
+
const lastPeer = peers.length > 0 ? peers[this.sampler.random(peers.length)] : undefined;
|
|
120
|
+
|
|
121
|
+
this.logger.trace('Sampled peer', {
|
|
122
|
+
attempts: MAX_SAMPLE_ATTEMPTS,
|
|
123
|
+
peer: lastPeer?.toString(),
|
|
96
124
|
});
|
|
97
|
-
return
|
|
125
|
+
return { peer: lastPeer, sampledPeers };
|
|
98
126
|
}
|
|
99
127
|
|
|
100
128
|
/**
|
|
101
129
|
* Samples a batch of unique peers from the libp2p node, prioritizing peers without active connections
|
|
102
130
|
*
|
|
103
131
|
* @param numberToSample - The number of peers to sample
|
|
132
|
+
* @param excluding - The peers to exclude from the sampling
|
|
104
133
|
* @returns Array of unique sampled peers, prioritizing those without active connections
|
|
105
134
|
*/
|
|
106
|
-
samplePeersBatch(numberToSample: number): PeerId[] {
|
|
135
|
+
samplePeersBatch(numberToSample: number, excluding?: Map<string, boolean>): PeerId[] {
|
|
107
136
|
const peers = this.libp2p.getPeers();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
137
|
+
this.logger.debug('Sampling peers batch', { numberToSample, peers });
|
|
138
|
+
|
|
139
|
+
// Only sample as many peers as we have available
|
|
140
|
+
numberToSample = Math.min(numberToSample, peers.length);
|
|
141
|
+
|
|
142
|
+
const batch: PeerId[] = [];
|
|
143
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
144
|
+
const withActiveConnections: Set<PeerId> = new Set();
|
|
145
|
+
for (let i = 0; i < numberToSample; i++) {
|
|
146
|
+
const { peer, sampledPeers } = this.getPeerFromList(peers, excluding);
|
|
147
|
+
if (peer) {
|
|
148
|
+
batch.push(peer);
|
|
149
|
+
}
|
|
150
|
+
if (sampledPeers.length > 0) {
|
|
151
|
+
sampledPeers.forEach(peer => withActiveConnections.add(peer));
|
|
119
152
|
}
|
|
120
153
|
}
|
|
154
|
+
const lengthWithoutConnections = batch.length;
|
|
121
155
|
|
|
122
156
|
// If we still need more peers, sample from those with connections
|
|
123
|
-
while (
|
|
124
|
-
const randomIndex = this.sampler.random(
|
|
125
|
-
|
|
126
|
-
|
|
157
|
+
while (batch.length < numberToSample && withActiveConnections.size > 0) {
|
|
158
|
+
const randomIndex = this.sampler.random(withActiveConnections.size);
|
|
159
|
+
|
|
160
|
+
const peer = Array.from(withActiveConnections)[randomIndex];
|
|
161
|
+
withActiveConnections.delete(peer);
|
|
162
|
+
batch.push(peer);
|
|
127
163
|
}
|
|
128
164
|
|
|
129
|
-
this.logger.trace(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
165
|
+
this.logger.trace('Batch sampled peers', {
|
|
166
|
+
length: batch.length,
|
|
167
|
+
peers: batch,
|
|
168
|
+
withoutConnections: lengthWithoutConnections,
|
|
169
|
+
withConnections: numberToSample - lengthWithoutConnections,
|
|
133
170
|
});
|
|
134
171
|
|
|
135
|
-
return
|
|
172
|
+
return batch;
|
|
136
173
|
}
|
|
137
174
|
|
|
138
175
|
// Set of passthrough functions to keep track of active connections
|
|
@@ -142,22 +179,27 @@ export class ConnectionSampler {
|
|
|
142
179
|
*
|
|
143
180
|
* @param peerId - The peer id
|
|
144
181
|
* @param protocol - The protocol
|
|
182
|
+
* @param timeout - Abort connection if it takes too long
|
|
145
183
|
* @returns The stream
|
|
146
184
|
*/
|
|
147
|
-
async dialProtocol(peerId: PeerId, protocol: string): Promise<Stream> {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
185
|
+
async dialProtocol(peerId: PeerId, protocol: string, timeout?: number): Promise<Stream> {
|
|
186
|
+
const stream = await this.libp2p.dialProtocol(peerId, protocol, {
|
|
187
|
+
signal: AbortSignal.any(
|
|
188
|
+
timeout ? [this.abortOnStop.signal, AbortSignal.timeout(timeout!)] : [this.abortOnStop.signal],
|
|
189
|
+
),
|
|
190
|
+
negotiateFully: !this.opts.p2pOptimisticNegotiation,
|
|
191
|
+
});
|
|
192
|
+
stream.metadata.peerId = peerId;
|
|
193
|
+
this.streams.add(stream);
|
|
153
194
|
|
|
154
|
-
|
|
155
|
-
const updatedActiveConnectionsCount = (this.activeConnectionsCount.get(
|
|
156
|
-
this.activeConnectionsCount.set(
|
|
195
|
+
const peerIdString = peerId.toString();
|
|
196
|
+
const updatedActiveConnectionsCount = (this.activeConnectionsCount.get(peerIdString) ?? 0) + 1;
|
|
197
|
+
this.activeConnectionsCount.set(peerIdString, updatedActiveConnectionsCount);
|
|
157
198
|
|
|
158
|
-
this.logger.trace(
|
|
199
|
+
this.logger.trace('Dialed protocol', {
|
|
159
200
|
streamId: stream.id,
|
|
160
|
-
|
|
201
|
+
protocol,
|
|
202
|
+
peerId: peerIdString,
|
|
161
203
|
activeConnectionsCount: updatedActiveConnectionsCount,
|
|
162
204
|
});
|
|
163
205
|
return stream;
|
|
@@ -165,34 +207,39 @@ export class ConnectionSampler {
|
|
|
165
207
|
|
|
166
208
|
/**
|
|
167
209
|
* Closes a stream and updates the active connections count
|
|
168
|
-
*
|
|
169
|
-
* @param streamId - The stream id
|
|
170
210
|
*/
|
|
171
|
-
async close(
|
|
172
|
-
|
|
173
|
-
const streamAndPeerId = this.streams.get(streamId);
|
|
174
|
-
if (!streamAndPeerId) {
|
|
175
|
-
this.logger.warn(`Stream ${streamId} not found`);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
211
|
+
async close(stream: Stream): Promise<void> {
|
|
212
|
+
let peerId: PeerId | undefined = undefined;
|
|
178
213
|
|
|
179
|
-
|
|
214
|
+
try {
|
|
215
|
+
peerId = stream.metadata.peerId;
|
|
216
|
+
let updatedActiveConnectionsCount = undefined;
|
|
180
217
|
|
|
181
|
-
|
|
182
|
-
|
|
218
|
+
if (!peerId) {
|
|
219
|
+
this.logger.warn(`Stream ${stream.id} does not have a peerId set`);
|
|
220
|
+
} else {
|
|
221
|
+
updatedActiveConnectionsCount = (this.activeConnectionsCount.get(peerId.toString()) ?? 1) - 1;
|
|
222
|
+
this.activeConnectionsCount.set(peerId.toString(), updatedActiveConnectionsCount);
|
|
223
|
+
}
|
|
183
224
|
|
|
184
|
-
this.logger.trace(
|
|
185
|
-
streamId,
|
|
186
|
-
peerId: peerId
|
|
225
|
+
this.logger.trace('Closing connection', {
|
|
226
|
+
streamId: stream.id,
|
|
227
|
+
peerId: peerId?.toString(),
|
|
187
228
|
protocol: stream.protocol,
|
|
188
229
|
activeConnectionsCount: updatedActiveConnectionsCount,
|
|
189
230
|
});
|
|
190
231
|
|
|
191
|
-
|
|
232
|
+
if (!this.streams.has(stream)) {
|
|
233
|
+
this.logger.debug(`Stream ${stream.id} is not in the active streams set`);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
await stream.close();
|
|
192
237
|
} catch (error) {
|
|
193
|
-
this.logger.error(`Failed to close connection to peer with stream id ${
|
|
238
|
+
this.logger.error(`Failed to close connection to peer ${peerId ?? 'unknown'} with stream id ${stream.id}`, error);
|
|
239
|
+
// graceful close failed, abort the stream
|
|
240
|
+
stream.abort(new AbortError('Failed to close stream gracefully'));
|
|
194
241
|
} finally {
|
|
195
|
-
this.streams.delete(
|
|
242
|
+
this.streams.delete(stream);
|
|
196
243
|
}
|
|
197
244
|
}
|
|
198
245
|
|
|
@@ -202,15 +249,21 @@ export class ConnectionSampler {
|
|
|
202
249
|
private async cleanupStaleConnections() {
|
|
203
250
|
// Look for streams without anything in the activeConnectionsCount
|
|
204
251
|
// If we find anything, close the stream
|
|
205
|
-
for (const
|
|
252
|
+
for (const stream of this.streams.values()) {
|
|
206
253
|
try {
|
|
207
254
|
// Check if we have lost track of accounting
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.logger.
|
|
255
|
+
const peerId: PeerId = stream.metadata.peerId;
|
|
256
|
+
if (!peerId) {
|
|
257
|
+
this.logger.warn(`Stream ${stream.id} does not have a peerId set`);
|
|
258
|
+
} else if (this.activeConnectionsCount.get(peerId.toString()) === 0) {
|
|
259
|
+
await this.close(stream);
|
|
260
|
+
this.logger.debug('Cleaned up stale connection', { streamId: stream.id, peerId: peerId.toString() });
|
|
211
261
|
}
|
|
212
262
|
} catch (error) {
|
|
213
|
-
this.logger.error(
|
|
263
|
+
this.logger.error(
|
|
264
|
+
`Error cleaning up stale connection to peer ${stream.metadata.peerId?.toString() ?? 'unknown'} stream ${stream.id}`,
|
|
265
|
+
{ error },
|
|
266
|
+
);
|
|
214
267
|
}
|
|
215
268
|
}
|
|
216
269
|
}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { L2Block } from '@aztec/stdlib/block';
|
|
3
|
-
import {
|
|
3
|
+
import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { PeerId } from '@libp2p/interface';
|
|
6
6
|
|
|
7
|
+
import type { P2PReqRespConfig } from './config.js';
|
|
8
|
+
import { AuthRequest, AuthResponse } from './protocols/auth.js';
|
|
9
|
+
import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
|
|
10
|
+
import { StatusMessage } from './protocols/status.js';
|
|
7
11
|
import type { ReqRespStatus } from './status.js';
|
|
8
12
|
|
|
9
13
|
/*
|
|
10
14
|
* Request Response Sub Protocols
|
|
11
15
|
*/
|
|
12
|
-
export const PING_PROTOCOL = '/aztec/req/ping/
|
|
13
|
-
export const STATUS_PROTOCOL = '/aztec/req/status/
|
|
14
|
-
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/
|
|
15
|
-
export const TX_REQ_PROTOCOL = '/aztec/req/tx/
|
|
16
|
-
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/
|
|
16
|
+
export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
|
|
17
|
+
export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
|
|
18
|
+
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
|
|
19
|
+
export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
|
|
20
|
+
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
|
|
21
|
+
export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
|
|
22
|
+
export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
|
|
17
23
|
|
|
18
24
|
export enum ReqRespSubProtocol {
|
|
19
25
|
PING = PING_PROTOCOL,
|
|
@@ -21,6 +27,8 @@ export enum ReqRespSubProtocol {
|
|
|
21
27
|
GOODBYE = GOODBYE_PROTOCOL,
|
|
22
28
|
TX = TX_REQ_PROTOCOL,
|
|
23
29
|
BLOCK = BLOCK_REQ_PROTOCOL,
|
|
30
|
+
AUTH = AUTH_PROTOCOL,
|
|
31
|
+
BLOCK_TXS = BLOCK_TXS_REQ_PROTOCOL,
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/**
|
|
@@ -36,12 +44,12 @@ export type ReqRespSubProtocolRateLimits = Record<ReqRespSubProtocol, ProtocolRa
|
|
|
36
44
|
|
|
37
45
|
/**
|
|
38
46
|
* The response from the ReqResp protocol
|
|
39
|
-
* Consists of a status
|
|
47
|
+
* Consists of a status
|
|
48
|
+
* And, optionally, a data buffer (in case status is SUCCESS)
|
|
40
49
|
*/
|
|
41
|
-
export
|
|
42
|
-
status: ReqRespStatus;
|
|
43
|
-
|
|
44
|
-
}
|
|
50
|
+
export type ReqRespResponse =
|
|
51
|
+
| { status: ReqRespStatus.SUCCESS; data: Buffer }
|
|
52
|
+
| { status: Exclude<ReqRespStatus, ReqRespStatus.SUCCESS> };
|
|
45
53
|
|
|
46
54
|
/**
|
|
47
55
|
* A rate limit quota
|
|
@@ -91,33 +99,27 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
|
|
|
91
99
|
[ReqRespSubProtocol.TX]: noopValidator,
|
|
92
100
|
[ReqRespSubProtocol.GOODBYE]: noopValidator,
|
|
93
101
|
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
102
|
+
[ReqRespSubProtocol.AUTH]: noopValidator,
|
|
103
|
+
[ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
|
|
94
104
|
};
|
|
95
105
|
|
|
106
|
+
/*
|
|
107
|
+
* Helper class to sub-protocol validation error*/
|
|
108
|
+
export class ValidationError extends Error {
|
|
109
|
+
constructor(message: string) {
|
|
110
|
+
super(message);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
96
114
|
/**
|
|
97
115
|
* Sub protocol map determines the request and response types for each
|
|
98
116
|
* Req Resp protocol
|
|
99
117
|
*/
|
|
100
118
|
export type SubProtocolMap = {
|
|
101
|
-
[S in ReqRespSubProtocol]: RequestResponsePair<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* Default handler for unimplemented sub protocols, this SHOULD be overwritten
|
|
106
|
-
* by the service, but is provided as a fallback
|
|
107
|
-
*/
|
|
108
|
-
const defaultHandler = (_msg: any): Promise<Buffer> => {
|
|
109
|
-
return Promise.resolve(Buffer.from('unimplemented'));
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Default sub protocol handlers - this SHOULD be overwritten by the service,
|
|
114
|
-
*/
|
|
115
|
-
export const DEFAULT_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
|
|
116
|
-
[ReqRespSubProtocol.PING]: defaultHandler,
|
|
117
|
-
[ReqRespSubProtocol.STATUS]: defaultHandler,
|
|
118
|
-
[ReqRespSubProtocol.TX]: defaultHandler,
|
|
119
|
-
[ReqRespSubProtocol.GOODBYE]: defaultHandler,
|
|
120
|
-
[ReqRespSubProtocol.BLOCK]: defaultHandler,
|
|
119
|
+
[S in ReqRespSubProtocol]: RequestResponsePair<
|
|
120
|
+
InstanceType<(typeof subProtocolMap)[S]['request']>,
|
|
121
|
+
InstanceType<(typeof subProtocolMap)[S]['response']>
|
|
122
|
+
>;
|
|
121
123
|
};
|
|
122
124
|
|
|
123
125
|
/**
|
|
@@ -138,6 +140,22 @@ interface RequestResponsePair<Req extends { toBuffer(): Buffer }, Res> {
|
|
|
138
140
|
};
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
/*
|
|
144
|
+
* Small helper function which parses buffer into specific response type
|
|
145
|
+
* It is needed to make TypeScript happy, as it cannot infer the type from the buffer
|
|
146
|
+
*
|
|
147
|
+
* @param proto - The sub protocol to parse the response for
|
|
148
|
+
* @param buffer - The buffer to parse
|
|
149
|
+
*
|
|
150
|
+
* @returns - The parsed response object
|
|
151
|
+
* */
|
|
152
|
+
export function responseFromBuffer<P extends ReqRespSubProtocol>(
|
|
153
|
+
proto: P,
|
|
154
|
+
buffer: Buffer,
|
|
155
|
+
): InstanceType<(typeof subProtocolMap)[P]['response']> {
|
|
156
|
+
return subProtocolMap[proto].response.fromBuffer(buffer) as InstanceType<(typeof subProtocolMap)[P]['response']>;
|
|
157
|
+
}
|
|
158
|
+
|
|
141
159
|
/**
|
|
142
160
|
* RequestableBuffer is a wrapper around a buffer that allows it to be
|
|
143
161
|
* used in generic request response protocols
|
|
@@ -161,18 +179,18 @@ export class RequestableBuffer {
|
|
|
161
179
|
* This defines the request and response types for each sub protocol, used primarily
|
|
162
180
|
* as a type rather than an object
|
|
163
181
|
*/
|
|
164
|
-
export const subProtocolMap
|
|
182
|
+
export const subProtocolMap = {
|
|
165
183
|
[ReqRespSubProtocol.PING]: {
|
|
166
184
|
request: RequestableBuffer,
|
|
167
185
|
response: RequestableBuffer,
|
|
168
186
|
},
|
|
169
187
|
[ReqRespSubProtocol.STATUS]: {
|
|
170
|
-
request:
|
|
171
|
-
response:
|
|
188
|
+
request: StatusMessage,
|
|
189
|
+
response: StatusMessage,
|
|
172
190
|
},
|
|
173
191
|
[ReqRespSubProtocol.TX]: {
|
|
174
|
-
request:
|
|
175
|
-
response:
|
|
192
|
+
request: TxHashArray,
|
|
193
|
+
response: TxArray,
|
|
176
194
|
},
|
|
177
195
|
[ReqRespSubProtocol.GOODBYE]: {
|
|
178
196
|
request: RequestableBuffer,
|
|
@@ -182,4 +200,41 @@ export const subProtocolMap: SubProtocolMap = {
|
|
|
182
200
|
request: Fr, // block number
|
|
183
201
|
response: L2Block,
|
|
184
202
|
},
|
|
203
|
+
[ReqRespSubProtocol.AUTH]: {
|
|
204
|
+
request: AuthRequest,
|
|
205
|
+
response: AuthResponse,
|
|
206
|
+
},
|
|
207
|
+
[ReqRespSubProtocol.BLOCK_TXS]: {
|
|
208
|
+
request: BlockTxsRequest,
|
|
209
|
+
response: BlockTxsResponse,
|
|
210
|
+
},
|
|
185
211
|
};
|
|
212
|
+
|
|
213
|
+
export interface ReqRespInterface {
|
|
214
|
+
start(
|
|
215
|
+
subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
|
|
216
|
+
subProtocolValidators: ReqRespSubProtocolValidators,
|
|
217
|
+
): Promise<void>;
|
|
218
|
+
addSubProtocol(
|
|
219
|
+
subProtocol: ReqRespSubProtocol,
|
|
220
|
+
handler: ReqRespSubProtocolHandler,
|
|
221
|
+
validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
222
|
+
): Promise<void>;
|
|
223
|
+
stop(): Promise<void>;
|
|
224
|
+
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
225
|
+
subProtocol: SubProtocol,
|
|
226
|
+
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
227
|
+
pinnedPeer: PeerId | undefined,
|
|
228
|
+
timeoutMs?: number,
|
|
229
|
+
maxPeers?: number,
|
|
230
|
+
maxRetryAttempts?: number,
|
|
231
|
+
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
|
|
232
|
+
sendRequestToPeer(
|
|
233
|
+
peerId: PeerId,
|
|
234
|
+
subProtocol: ReqRespSubProtocol,
|
|
235
|
+
payload: Buffer,
|
|
236
|
+
dialTimeout?: number,
|
|
237
|
+
): Promise<ReqRespResponse>;
|
|
238
|
+
|
|
239
|
+
updateConfig(config: Partial<P2PReqRespConfig>): void;
|
|
240
|
+
}
|
|
@@ -11,7 +11,10 @@ export class ReqRespMetrics {
|
|
|
11
11
|
private readonly failedOutboundRequests: UpDownCounter;
|
|
12
12
|
private readonly failedInboundRequests: UpDownCounter;
|
|
13
13
|
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
readonly telemetryClient: TelemetryClient,
|
|
16
|
+
name = 'ReqResp',
|
|
17
|
+
) {
|
|
15
18
|
this.tracer = telemetryClient.getTracer(name);
|
|
16
19
|
|
|
17
20
|
const meter = telemetryClient.getMeter(name);
|