@aztec/p2p 0.0.0-test.0 → 0.0.1-commit.03f7ef2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -9
- package/dest/client/factory.d.ts +15 -5
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -25
- package/dest/client/index.d.ts +2 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +157 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +75 -190
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +381 -183
- package/dest/config.d.ts +151 -125
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +183 -34
- package/dest/enr/generate-enr.d.ts +11 -3
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +4 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +68 -8
- 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 +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 +216 -65
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -6
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +127 -26
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +19 -6
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +111 -21
- package/dest/mem_pools/attestation_pool/mocks.d.ts +227 -7
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +10 -16
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +16 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +57 -35
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +64 -14
- 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 +472 -97
- package/dest/mem_pools/tx_pool/index.d.ts +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +36 -11
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +137 -36
- package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +67 -10
- 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 +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 +273 -42
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
- 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/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
- 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 +73 -12
- package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
- package/dest/msg_validators/index.d.ts +1 -1
- 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/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/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 +2 -2
- 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 +1 -1
- 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 +1 -3
- 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 +16 -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 +8 -1
- 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 +9 -5
- 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 +93 -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 +13 -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 +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.d.ts +10 -9
- 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 +50 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +74 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +5 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +20 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +164 -0
- package/dest/services/libp2p/libp2p_service.d.ts +78 -89
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +695 -248
- 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 +6 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +22 -2
- package/dest/services/peer-manager/peer_manager.d.ts +102 -22
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +549 -72
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +40 -2
- package/dest/services/reqresp/config.d.ts +11 -9
- 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 +2 -2
- 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 +31 -17
- 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 +3 -2
- 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 +73 -24
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +46 -27
- package/dest/services/reqresp/metrics.d.ts +1 -1
- 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 +6 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +30 -6
- 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 +47 -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 +3 -5
- 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 +3 -1
- 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 +1 -3
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +40 -7
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +73 -5
- package/dest/services/reqresp/protocols/tx.d.ts +14 -4
- 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/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
- 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 +1 -1
- 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 +24 -66
- 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 +10 -4
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +23 -19
- 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 +51 -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 +53 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +177 -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 +51 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +217 -0
- package/dest/services/tx_provider_instrumentation.d.ts +16 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +47 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +2 -1
- 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 +1 -1
- 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 +33 -5
- 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 +15 -11
- 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.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +103 -29
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +1 -6
- 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 +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +24 -16
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +75 -69
- package/dest/versioning.d.ts +4 -4
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +32 -27
- package/src/bootstrap/bootstrap.ts +27 -11
- package/src/client/factory.ts +139 -53
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +198 -0
- package/src/client/p2p_client.ts +484 -348
- package/src/config.ts +305 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +266 -67
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +174 -35
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
- package/src/mem_pools/attestation_pool/mocks.ts +13 -12
- package/src/mem_pools/instrumentation.ts +70 -40
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +555 -110
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +160 -46
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +69 -9
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +224 -35
- package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -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 +5 -5
- 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 +110 -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 +59 -22
- package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -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 +81 -6
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +167 -0
- package/src/services/libp2p/libp2p_service.ts +865 -298
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +26 -1
- package/src/services/peer-manager/peer_manager.ts +654 -78
- package/src/services/peer-manager/peer_scoring.ts +46 -3
- 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 +92 -37
- package/src/services/reqresp/metrics.ts +4 -1
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +26 -4
- 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 +118 -5
- package/src/services/reqresp/protocols/tx.ts +36 -8
- 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 +341 -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 +233 -0
- package/src/services/tx_collection/tx_collection.ts +216 -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 +229 -0
- package/src/services/tx_provider_instrumentation.ts +61 -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 +87 -36
- package/src/testbench/p2p_client_testbench_worker.ts +151 -25
- 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 +105 -91
- package/src/versioning.ts +11 -4
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { compactArray } from '@aztec/foundation/collection';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { elapsed } from '@aztec/foundation/timer';
|
|
5
|
+
import type { L2BlockInfo, L2BlockNew } from '@aztec/stdlib/block';
|
|
6
|
+
import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
|
|
7
|
+
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
8
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
9
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
10
|
+
|
|
11
|
+
import type { PeerId } from '@libp2p/interface';
|
|
12
|
+
|
|
13
|
+
import type { P2PClient } from '../client/p2p_client.js';
|
|
14
|
+
import type { TxPool } from '../mem_pools/index.js';
|
|
15
|
+
import type { FastCollectionRequestInput, TxCollection } from './tx_collection/tx_collection.js';
|
|
16
|
+
import { TxProviderInstrumentation } from './tx_provider_instrumentation.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gathers and returns txs given a block proposal, block, or their hashes.
|
|
20
|
+
* Loads available txs from the tx pool, and relies on a TxCollection service to collect txs from the network and other nodes.
|
|
21
|
+
*/
|
|
22
|
+
export class TxProvider implements ITxProvider {
|
|
23
|
+
protected instrumentation: TxProviderInstrumentation;
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private txCollection: TxCollection,
|
|
27
|
+
private txPool: TxPool,
|
|
28
|
+
private txValidator: Pick<P2PClient, 'validate'>,
|
|
29
|
+
private log: Logger = createLogger('p2p:tx-collector'),
|
|
30
|
+
client: TelemetryClient = getTelemetryClient(),
|
|
31
|
+
) {
|
|
32
|
+
this.instrumentation = new TxProviderInstrumentation(client, 'TxProvider');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Returns txs from the tx pool given their hashes.*/
|
|
36
|
+
public async getAvailableTxs(txHashes: TxHash[]): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
|
|
37
|
+
const response = await this.txPool.getTxsByHash(txHashes);
|
|
38
|
+
if (response.length !== txHashes.length) {
|
|
39
|
+
throw new Error(`Unexpected response size from tx pool: expected ${txHashes.length} but got ${response.length}`);
|
|
40
|
+
}
|
|
41
|
+
const txs: Tx[] = [];
|
|
42
|
+
const missingTxs: TxHash[] = [];
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < txHashes.length; i++) {
|
|
45
|
+
const tx = response[i];
|
|
46
|
+
if (tx === undefined) {
|
|
47
|
+
missingTxs.push(txHashes[i]);
|
|
48
|
+
} else {
|
|
49
|
+
txs.push(tx);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { txs, missingTxs };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Gathers txs from the tx pool, proposal body, remote rpc nodes, and reqresp. */
|
|
57
|
+
public getTxsForBlockProposal(
|
|
58
|
+
blockProposal: BlockProposal,
|
|
59
|
+
blockNumber: BlockNumber,
|
|
60
|
+
opts: { pinnedPeer: PeerId | undefined; deadline: Date },
|
|
61
|
+
): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
|
|
62
|
+
return this.getOrderedTxsFromAllSources(
|
|
63
|
+
{ type: 'proposal', blockProposal, blockNumber },
|
|
64
|
+
{ ...blockProposal.toBlockInfo(), blockNumber },
|
|
65
|
+
blockProposal.txHashes,
|
|
66
|
+
{ ...opts, pinnedPeer: opts.pinnedPeer },
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Gathers txs from the tx pool, remote rpc nodes, and reqresp. */
|
|
71
|
+
public getTxsForBlock(block: L2BlockNew, opts: { deadline: Date }): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
|
|
72
|
+
return this.getOrderedTxsFromAllSources(
|
|
73
|
+
{ type: 'block', block },
|
|
74
|
+
block.toBlockInfo(),
|
|
75
|
+
block.body.txEffects.map(tx => tx.txHash),
|
|
76
|
+
{ ...opts, pinnedPeer: undefined },
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private async getOrderedTxsFromAllSources(
|
|
81
|
+
request: FastCollectionRequestInput,
|
|
82
|
+
blockInfo: L2BlockInfo,
|
|
83
|
+
txHashes: TxHash[],
|
|
84
|
+
opts: { pinnedPeer: PeerId | undefined; deadline: Date },
|
|
85
|
+
) {
|
|
86
|
+
const [durationMs, result] = await elapsed(() => this.getTxsFromAllSources(request, blockInfo, txHashes, opts));
|
|
87
|
+
const { missingTxHashes, txsFromMempool, txsFromNetwork, txsFromProposal } = result;
|
|
88
|
+
|
|
89
|
+
const txs = [...(txsFromMempool ?? []), ...(txsFromProposal ?? []), ...(txsFromNetwork ?? [])];
|
|
90
|
+
const missingTxs = missingTxHashes?.length ?? 0;
|
|
91
|
+
|
|
92
|
+
const level = missingTxs === 0 ? 'verbose' : 'warn';
|
|
93
|
+
this.log[level](`Retrieved ${txs.length} out of ${blockInfo.txCount} txs for ${request.type}`, {
|
|
94
|
+
...blockInfo,
|
|
95
|
+
txsFromProposal: txsFromProposal?.length,
|
|
96
|
+
txsFromMempool: txsFromMempool?.length,
|
|
97
|
+
txsFromNetwork: txsFromNetwork?.length,
|
|
98
|
+
missingTxs,
|
|
99
|
+
durationMs,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const orderedTxs = this.orderTxs(txs, txHashes);
|
|
103
|
+
if (orderedTxs.length + missingTxs !== txHashes.length) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Error collecting txs for ${request.type} with ${txHashes.length} txs: found ${orderedTxs.length} and flagged ${missingTxs} as missing`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { txs: orderedTxs, missingTxs: (missingTxHashes ?? []).map(TxHash.fromString), durationMs };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private orderTxs(txs: Tx[], order: TxHash[]): Tx[] {
|
|
113
|
+
const txsMap = new Map(txs.map(tx => [tx.txHash.toString(), tx]));
|
|
114
|
+
return order.map(hash => txsMap.get(hash.toString())!).filter(tx => tx !== undefined);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private async getTxsFromAllSources(
|
|
118
|
+
request: FastCollectionRequestInput,
|
|
119
|
+
blockInfo: L2BlockInfo,
|
|
120
|
+
txHashes: TxHash[],
|
|
121
|
+
opts: { pinnedPeer: PeerId | undefined; deadline: Date },
|
|
122
|
+
) {
|
|
123
|
+
const missingTxHashes = new Set(txHashes.map(txHash => txHash.toString()));
|
|
124
|
+
if (missingTxHashes.size === 0) {
|
|
125
|
+
this.log.debug(`Received request with no transactions`, blockInfo);
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// First go to our tx pool and fetch whatever txs we have there
|
|
130
|
+
// We go to the mempool first since those txs are already validated
|
|
131
|
+
const txsFromMempool = compactArray(await this.txPool.getTxsByHash(txHashes));
|
|
132
|
+
txsFromMempool.forEach(tx => missingTxHashes.delete(tx.getTxHash().toString()));
|
|
133
|
+
this.instrumentation.incTxsFromMempool(txsFromMempool.length);
|
|
134
|
+
this.log.debug(
|
|
135
|
+
`Retrieved ${txsFromMempool.length} txs from mempool for block proposal (${missingTxHashes.size} pending)`,
|
|
136
|
+
{ ...blockInfo, missingTxHashes: [...missingTxHashes] },
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
if (missingTxHashes.size === 0) {
|
|
140
|
+
return { txsFromMempool };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Take txs from the proposal body if there are any
|
|
144
|
+
// Note that we still have to validate these txs, but we do it in parallel with tx collection
|
|
145
|
+
const proposal = request.type === 'proposal' ? request.blockProposal : undefined;
|
|
146
|
+
const txsFromProposal = this.extractFromProposal(proposal, [...missingTxHashes]);
|
|
147
|
+
if (txsFromProposal.length > 0) {
|
|
148
|
+
this.instrumentation.incTxsFromProposals(txsFromProposal.length);
|
|
149
|
+
txsFromProposal.forEach(tx => missingTxHashes.delete(tx.txHash.toString()));
|
|
150
|
+
this.log.debug(`Retrieved ${txsFromProposal.length} txs from proposal body (${missingTxHashes.size} pending)`, {
|
|
151
|
+
...blockInfo,
|
|
152
|
+
missingTxHashes: [...missingTxHashes],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (missingTxHashes.size === 0) {
|
|
157
|
+
await this.processProposalTxs(txsFromProposal);
|
|
158
|
+
return { txsFromMempool, txsFromProposal };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Start tx collection from the network if needed, while we validate the txs taken from the proposal in parallel
|
|
162
|
+
const [txsFromNetwork] = await Promise.all([
|
|
163
|
+
this.collectFromP2P(request, [...missingTxHashes], opts),
|
|
164
|
+
this.processProposalTxs(txsFromProposal),
|
|
165
|
+
] as const);
|
|
166
|
+
|
|
167
|
+
if (txsFromNetwork.length > 0) {
|
|
168
|
+
txsFromNetwork.forEach(tx => missingTxHashes.delete(tx.txHash.toString()));
|
|
169
|
+
this.instrumentation.incTxsFromP2P(txsFromNetwork.length, txHashes.length);
|
|
170
|
+
this.log.debug(
|
|
171
|
+
`Retrieved ${txsFromNetwork.length} txs from network for block proposal (${missingTxHashes.size} pending)`,
|
|
172
|
+
{ ...blockInfo, missingTxHashes: [...missingTxHashes] },
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (missingTxHashes.size === 0) {
|
|
177
|
+
return { txsFromNetwork, txsFromMempool, txsFromProposal };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// We are still missing txs, make one last attempt to collect them from our pool, in case they showed up somehow else
|
|
181
|
+
const moreTxsFromPool = compactArray(await this.txPool.getTxsByHash([...missingTxHashes].map(TxHash.fromString)));
|
|
182
|
+
|
|
183
|
+
if (moreTxsFromPool.length > 0) {
|
|
184
|
+
this.instrumentation.incTxsFromMempool(moreTxsFromPool.length);
|
|
185
|
+
this.log.debug(
|
|
186
|
+
`Retrieved ${moreTxsFromPool.length} txs from pool retry for block proposal (${missingTxHashes.size} pending)`,
|
|
187
|
+
{ ...blockInfo, missingTxHashes: [...missingTxHashes] },
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (missingTxHashes.size > 0) {
|
|
192
|
+
this.instrumentation.incMissingTxs(missingTxHashes.size);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
txsFromNetwork,
|
|
197
|
+
txsFromMempool: [...txsFromMempool, ...moreTxsFromPool],
|
|
198
|
+
txsFromProposal,
|
|
199
|
+
missingTxHashes: [...missingTxHashes],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private async collectFromP2P(
|
|
204
|
+
input: FastCollectionRequestInput,
|
|
205
|
+
txHashes: TxHash[] | string[],
|
|
206
|
+
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
207
|
+
): Promise<Tx[]> {
|
|
208
|
+
const requestedAt = Date.now();
|
|
209
|
+
const result = await this.txCollection.collectFastFor(input, txHashes, opts);
|
|
210
|
+
const requestProcessedAt = Date.now();
|
|
211
|
+
this.instrumentation.recordTxsRequestDelay(requestProcessedAt - requestedAt);
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private extractFromProposal(proposal: BlockProposal | undefined, missingTxHashes: string[]): Tx[] {
|
|
216
|
+
if (!proposal) {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
return compactArray(proposal.txs ?? []).filter(tx => missingTxHashes.includes(tx.getTxHash().toString()));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private async processProposalTxs(txs: Tx[]): Promise<void> {
|
|
223
|
+
if (txs.length === 0) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
await this.txValidator.validate(txs);
|
|
227
|
+
await this.txPool.addTxs(txs);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Histogram, Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
|
|
2
|
+
|
|
3
|
+
export class TxProviderInstrumentation {
|
|
4
|
+
private txFromProposalCount: UpDownCounter;
|
|
5
|
+
private txFromMempoolCount: UpDownCounter;
|
|
6
|
+
private txFromP2PCount: UpDownCounter;
|
|
7
|
+
private missingTxsCount: UpDownCounter;
|
|
8
|
+
|
|
9
|
+
private fractionOfTxsRequestedFromP2P: Histogram;
|
|
10
|
+
private txsRequestDelay: Histogram;
|
|
11
|
+
|
|
12
|
+
constructor(client: TelemetryClient, name: string) {
|
|
13
|
+
const meter = client.getMeter(name);
|
|
14
|
+
|
|
15
|
+
this.txFromProposalCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_PROPOSALS_COUNT, {
|
|
16
|
+
description: 'The number of txs taken from block proposals',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this.txFromMempoolCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_MEMPOOL_COUNT, {
|
|
20
|
+
description: 'The number of txs taken from the local mempool',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
this.txFromP2PCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_P2P_COUNT, {
|
|
24
|
+
description: 'The number of txs taken from the p2p network',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
this.missingTxsCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_MISSING_TXS_COUNT, {
|
|
28
|
+
description: 'The number of txs not found anywhere',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
this.fractionOfTxsRequestedFromP2P = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUESTED_FRACTION, {
|
|
32
|
+
description: 'The fraction of transaction requested from peers',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.txsRequestDelay = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUEST_DELAY, {
|
|
36
|
+
unit: 'ms',
|
|
37
|
+
description: 'The time it took to request missing transactions from p2p',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
incTxsFromProposals(count: number) {
|
|
42
|
+
this.txFromProposalCount.add(count);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
incTxsFromMempool(count: number) {
|
|
46
|
+
this.txFromMempoolCount.add(count);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
incTxsFromP2P(count: number, total: number) {
|
|
50
|
+
this.txFromP2PCount.add(count);
|
|
51
|
+
this.fractionOfTxsRequestedFromP2P.record(count / total);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
recordTxsRequestDelay(delay: number) {
|
|
55
|
+
this.txsRequestDelay.record(delay);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
incMissingTxs(count: number) {
|
|
59
|
+
this.missingTxsCount.add(count);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
2
2
|
|
|
3
|
-
import { SignableENR } from '@chainsafe/enr';
|
|
4
3
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
4
|
+
import { SignableENR } from '@nethermindeth/enr';
|
|
5
5
|
|
|
6
6
|
import { convertToMultiaddr, createLibP2PPeerIdFromPrivateKey } from '../util.js';
|
|
7
7
|
import { setAztecEnrKey } from '../versioning.js';
|
|
@@ -30,10 +30,9 @@ export async function makeEnr(p2pPrivateKey: string, port: number, config: Chain
|
|
|
30
30
|
const peerId = await createLibP2PPeerIdFromPrivateKey(p2pPrivateKey);
|
|
31
31
|
const enr = SignableENR.createFromPeerId(peerId);
|
|
32
32
|
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const tcpPublicAddr = multiaddr(convertToMultiaddr(tcpAnnounceAddress, 'tcp'));
|
|
33
|
+
const p2pIp = `127.0.0.1`;
|
|
34
|
+
const udpPublicAddr = multiaddr(convertToMultiaddr(p2pIp, port, 'udp'));
|
|
35
|
+
const tcpPublicAddr = multiaddr(convertToMultiaddr(p2pIp, port, 'tcp'));
|
|
37
36
|
|
|
38
37
|
// ENRS must include the network and a discoverable address (udp for discv5)
|
|
39
38
|
setAztecEnrKey(enr, config);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { MockL2BlockSource } from '@aztec/archiver/test';
|
|
2
2
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
6
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
7
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
5
8
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
9
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
@@ -14,9 +17,10 @@ import type { TxPool } from '../mem_pools/tx_pool/index.js';
|
|
|
14
17
|
import { generatePeerIdPrivateKeys } from '../test-helpers/generate-peer-id-private-keys.js';
|
|
15
18
|
import { getPorts } from './get-ports.js';
|
|
16
19
|
import { makeEnrs } from './make-enrs.js';
|
|
20
|
+
import { type MockGossipSubNetwork, getMockPubSubP2PServiceFactory } from './mock-pubsub.js';
|
|
17
21
|
import { AlwaysFalseCircuitVerifier, AlwaysTrueCircuitVerifier } from './reqresp-nodes.js';
|
|
18
22
|
|
|
19
|
-
interface MakeTestP2PClientOptions {
|
|
23
|
+
export interface MakeTestP2PClientOptions {
|
|
20
24
|
mockAttestationPool: AttestationPool;
|
|
21
25
|
mockTxPool: TxPool;
|
|
22
26
|
mockEpochCache: EpochCache;
|
|
@@ -25,6 +29,27 @@ interface MakeTestP2PClientOptions {
|
|
|
25
29
|
p2pBaseConfig: P2PConfig;
|
|
26
30
|
p2pConfigOverrides?: Partial<P2PConfig>;
|
|
27
31
|
logger?: Logger;
|
|
32
|
+
mockGossipSubNetwork?: MockGossipSubNetwork;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates a single P2P client and immediately starts it for testing purposes.
|
|
37
|
+
* @param peerIdPrivateKey - The private key of the peer.
|
|
38
|
+
* @param port - The port to run the client on.
|
|
39
|
+
* @param peers - The peers to connect to.
|
|
40
|
+
* @param options - The options for the client.
|
|
41
|
+
* @returns The created and already started client.
|
|
42
|
+
*/
|
|
43
|
+
export async function makeAndStartTestP2PClient(
|
|
44
|
+
peerIdPrivateKey: string,
|
|
45
|
+
port: number,
|
|
46
|
+
peers: string[],
|
|
47
|
+
options: MakeTestP2PClientOptions,
|
|
48
|
+
) {
|
|
49
|
+
const client = await makeTestP2PClient(peerIdPrivateKey, port, peers, options);
|
|
50
|
+
|
|
51
|
+
await client.start();
|
|
52
|
+
return client;
|
|
28
53
|
}
|
|
29
54
|
|
|
30
55
|
/**
|
|
@@ -47,22 +72,18 @@ export async function makeTestP2PClient(
|
|
|
47
72
|
mockTxPool,
|
|
48
73
|
mockEpochCache,
|
|
49
74
|
mockWorldState,
|
|
75
|
+
mockGossipSubNetwork,
|
|
50
76
|
logger = createLogger('p2p-test-client'),
|
|
51
77
|
}: MakeTestP2PClientOptions,
|
|
52
78
|
) {
|
|
53
|
-
const addr = `127.0.0.1:${port}`;
|
|
54
|
-
const listenAddr = `0.0.0.0:${port}`;
|
|
55
|
-
|
|
56
79
|
// Filter nodes so that we only dial active peers
|
|
57
|
-
|
|
58
80
|
const config: P2PConfig & DataStoreConfig = {
|
|
59
81
|
...p2pBaseConfig,
|
|
60
82
|
p2pEnabled: true,
|
|
61
|
-
peerIdPrivateKey,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
udpAnnounceAddress: addr,
|
|
83
|
+
peerIdPrivateKey: new SecretValue(peerIdPrivateKey),
|
|
84
|
+
p2pIp: `127.0.0.1`,
|
|
85
|
+
listenAddress: `127.0.0.1`,
|
|
86
|
+
p2pPort: port,
|
|
66
87
|
bootstrapNodes: peers,
|
|
67
88
|
peerCheckIntervalMS: 1000,
|
|
68
89
|
maxPeerCount: 10,
|
|
@@ -75,12 +96,7 @@ export async function makeTestP2PClient(
|
|
|
75
96
|
|
|
76
97
|
const proofVerifier = alwaysTrueVerifier ? new AlwaysTrueCircuitVerifier() : new AlwaysFalseCircuitVerifier();
|
|
77
98
|
const kvStore = await openTmpStore('test');
|
|
78
|
-
|
|
79
|
-
txPool: mockTxPool as unknown as TxPool,
|
|
80
|
-
attestationPool: mockAttestationPool as unknown as AttestationPool,
|
|
81
|
-
store: kvStore,
|
|
82
|
-
logger,
|
|
83
|
-
};
|
|
99
|
+
|
|
84
100
|
const client = await createP2PClient(
|
|
85
101
|
P2PClientType.Full,
|
|
86
102
|
config,
|
|
@@ -88,14 +104,68 @@ export async function makeTestP2PClient(
|
|
|
88
104
|
proofVerifier,
|
|
89
105
|
mockWorldState,
|
|
90
106
|
mockEpochCache,
|
|
107
|
+
'test-p2p-client',
|
|
91
108
|
undefined,
|
|
92
|
-
|
|
109
|
+
undefined,
|
|
110
|
+
{
|
|
111
|
+
txPool: mockTxPool as unknown as TxPool,
|
|
112
|
+
attestationPool: mockAttestationPool as unknown as AttestationPool,
|
|
113
|
+
store: kvStore,
|
|
114
|
+
logger,
|
|
115
|
+
p2pServiceFactory: mockGossipSubNetwork && getMockPubSubP2PServiceFactory(mockGossipSubNetwork),
|
|
116
|
+
},
|
|
93
117
|
);
|
|
94
|
-
await client.start();
|
|
95
118
|
|
|
96
119
|
return client;
|
|
97
120
|
}
|
|
98
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Creates a number of P2P clients and immediately starts them for testing purposes.
|
|
124
|
+
* @param numberOfPeers - The number of clients to create.
|
|
125
|
+
* @param options - The options for the clients.
|
|
126
|
+
* @returns The created and started clients.
|
|
127
|
+
*/
|
|
128
|
+
export async function makeAndStartTestP2PClients(numberOfPeers: number, testConfig: MakeTestP2PClientOptions) {
|
|
129
|
+
const clients: P2PClient[] = [];
|
|
130
|
+
const peerIdPrivateKeys = generatePeerIdPrivateKeys(numberOfPeers);
|
|
131
|
+
|
|
132
|
+
let ports = [];
|
|
133
|
+
while (true) {
|
|
134
|
+
try {
|
|
135
|
+
ports = await getPorts(numberOfPeers);
|
|
136
|
+
break;
|
|
137
|
+
} catch {
|
|
138
|
+
await sleep(1000);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const peerEnrs = await makeEnrs(peerIdPrivateKeys, ports, testConfig.p2pBaseConfig);
|
|
143
|
+
|
|
144
|
+
for (let i = 0; i < numberOfPeers; i++) {
|
|
145
|
+
const client = await makeAndStartTestP2PClient(peerIdPrivateKeys[i], ports[i], peerEnrs, {
|
|
146
|
+
...testConfig,
|
|
147
|
+
logger: createLogger(`p2p:${i}`),
|
|
148
|
+
});
|
|
149
|
+
clients.push(client);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
await retryUntil(() => clients.every(c => c.isReady()), 'p2p clients started', 10, 0.5);
|
|
153
|
+
testConfig.logger?.info(`Created and started ${clients.length} P2P clients at ports ${ports.join(',')}`, {
|
|
154
|
+
ports,
|
|
155
|
+
peerEnrs,
|
|
156
|
+
peerIdPrivateKeys,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return clients.map((client, index) => {
|
|
160
|
+
return {
|
|
161
|
+
client,
|
|
162
|
+
peerPrivateKey: peerIdPrivateKeys[index],
|
|
163
|
+
port: ports[index],
|
|
164
|
+
enr: peerEnrs[index],
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
99
169
|
/**
|
|
100
170
|
* Creates a number of P2P clients for testing purposes.
|
|
101
171
|
* @param numberOfPeers - The number of clients to create.
|
|
@@ -106,7 +176,16 @@ export async function makeTestP2PClients(numberOfPeers: number, testConfig: Make
|
|
|
106
176
|
const clients: P2PClient[] = [];
|
|
107
177
|
const peerIdPrivateKeys = generatePeerIdPrivateKeys(numberOfPeers);
|
|
108
178
|
|
|
109
|
-
|
|
179
|
+
let ports = [];
|
|
180
|
+
while (true) {
|
|
181
|
+
try {
|
|
182
|
+
ports = await getPorts(numberOfPeers);
|
|
183
|
+
break;
|
|
184
|
+
} catch {
|
|
185
|
+
await sleep(1000);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
110
189
|
const peerEnrs = await makeEnrs(peerIdPrivateKeys, ports, testConfig.p2pBaseConfig);
|
|
111
190
|
|
|
112
191
|
for (let i = 0; i < numberOfPeers; i++) {
|
|
@@ -117,6 +196,17 @@ export async function makeTestP2PClients(numberOfPeers: number, testConfig: Make
|
|
|
117
196
|
clients.push(client);
|
|
118
197
|
}
|
|
119
198
|
|
|
120
|
-
|
|
121
|
-
|
|
199
|
+
return clients.map((client, index) => {
|
|
200
|
+
return {
|
|
201
|
+
client,
|
|
202
|
+
peerPrivateKey: peerIdPrivateKeys[index],
|
|
203
|
+
port: ports[index],
|
|
204
|
+
enr: peerEnrs[index],
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export async function startTestP2PClients(clients: P2PClient[]) {
|
|
210
|
+
await Promise.all(clients.map(c => c.start()));
|
|
211
|
+
await retryUntil(() => clients.every(c => c.isReady()), 'p2p clients started', 10, 0.5);
|
|
122
212
|
}
|