@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.5476d83
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 +14 -4
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -24
- 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 +72 -187
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +373 -177
- 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 +214 -63
- 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 +126 -25
- 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 +225 -5
- 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/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +10 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +35 -38
- package/dest/mem_pools/interface.d.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +62 -13
- 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/index.d.ts +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +34 -10
- 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.d.ts +1 -1
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +65 -9
- 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 +264 -39
- 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 +1 -1
- 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 +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 +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 +8 -4
- 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 +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 +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 +73 -5
- 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 +698 -246
- 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 +45 -26
- 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 +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 +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 +39 -7
- 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 +13 -2
- 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 +50 -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 +52 -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 +109 -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/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 +136 -45
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +198 -0
- package/src/client/p2p_client.ts +469 -330
- 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 +264 -65
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +173 -34
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
- package/src/mem_pools/attestation_pool/mocks.ts +11 -10
- package/src/mem_pools/instrumentation.ts +43 -44
- 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 +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 +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 +116 -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 +167 -0
- package/src/services/libp2p/libp2p_service.ts +866 -294
- 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 +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 +233 -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 +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
|
@@ -5,17 +5,22 @@ export enum ReqRespStatus {
|
|
|
5
5
|
SUCCESS = 0,
|
|
6
6
|
RATE_LIMIT_EXCEEDED = 1,
|
|
7
7
|
BADLY_FORMED_REQUEST = 2,
|
|
8
|
+
INTERNAL_ERROR = 3,
|
|
9
|
+
NOT_FOUND = 4,
|
|
10
|
+
FAILURE = 126,
|
|
8
11
|
UNKNOWN = 127,
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
export type UnsuccessfulReqRespStatus = Exclude<ReqRespStatus, ReqRespStatus.SUCCESS>;
|
|
15
|
+
|
|
11
16
|
export class ReqRespStatusError extends Error {
|
|
12
17
|
/**
|
|
13
18
|
* The status code
|
|
14
19
|
*/
|
|
15
|
-
status:
|
|
20
|
+
readonly status: UnsuccessfulReqRespStatus;
|
|
16
21
|
|
|
17
|
-
constructor(status:
|
|
18
|
-
super(`ReqResp Error: ${prettyPrintReqRespStatus(status)}
|
|
22
|
+
constructor(status: UnsuccessfulReqRespStatus, cause?: { cause?: Error }) {
|
|
23
|
+
super(`ReqResp Error: ${prettyPrintReqRespStatus(status)}`, cause);
|
|
19
24
|
this.status = status;
|
|
20
25
|
}
|
|
21
26
|
}
|
|
@@ -53,6 +58,10 @@ export function prettyPrintReqRespStatus(status: ReqRespStatus) {
|
|
|
53
58
|
return 'RATE_LIMIT_EXCEEDED';
|
|
54
59
|
case ReqRespStatus.BADLY_FORMED_REQUEST:
|
|
55
60
|
return 'BADLY_FORMED_REQUEST';
|
|
61
|
+
case ReqRespStatus.FAILURE:
|
|
62
|
+
return 'FAILURE';
|
|
63
|
+
case ReqRespStatus.INTERNAL_ERROR:
|
|
64
|
+
return 'INTERNAL_ERROR';
|
|
56
65
|
case ReqRespStatus.UNKNOWN:
|
|
57
66
|
return 'UNKNOWN';
|
|
58
67
|
}
|
package/src/services/service.ts
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
1
2
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
2
3
|
import type { BlockAttestation, BlockProposal, Gossipable } from '@aztec/stdlib/p2p';
|
|
4
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
3
5
|
|
|
4
|
-
import type { ENR } from '@chainsafe/enr';
|
|
5
6
|
import type { PeerId } from '@libp2p/interface';
|
|
7
|
+
import type { ENR } from '@nethermindeth/enr';
|
|
6
8
|
import type EventEmitter from 'events';
|
|
7
9
|
|
|
8
|
-
import type {
|
|
10
|
+
import type { P2PReqRespConfig } from './reqresp/config.js';
|
|
11
|
+
import type { StatusMessage } from './reqresp/index.js';
|
|
12
|
+
import type {
|
|
13
|
+
ReqRespSubProtocol,
|
|
14
|
+
ReqRespSubProtocolHandler,
|
|
15
|
+
ReqRespSubProtocolValidators,
|
|
16
|
+
SubProtocolMap,
|
|
17
|
+
} from './reqresp/interface.js';
|
|
18
|
+
import type { AuthRequest, AuthResponse } from './reqresp/protocols/auth.js';
|
|
9
19
|
|
|
10
20
|
export enum PeerDiscoveryState {
|
|
11
21
|
RUNNING = 'running',
|
|
12
22
|
STOPPED = 'stopped',
|
|
13
23
|
}
|
|
14
24
|
|
|
25
|
+
export type P2PBlockReceivedCallback = (
|
|
26
|
+
block: BlockProposal,
|
|
27
|
+
sender: PeerId,
|
|
28
|
+
) => Promise<BlockAttestation[] | undefined>;
|
|
29
|
+
|
|
30
|
+
export type AuthReceivedCallback = (peerId: PeerId, authRequest: AuthRequest) => Promise<AuthResponse | undefined>;
|
|
31
|
+
|
|
15
32
|
/**
|
|
16
33
|
* The interface for a P2P service implementation.
|
|
17
34
|
*/
|
|
@@ -32,19 +49,7 @@ export interface P2PService {
|
|
|
32
49
|
* Called to have the given transaction propagated through the P2P network.
|
|
33
50
|
* @param message - The message to be propagated.
|
|
34
51
|
*/
|
|
35
|
-
propagate<T extends Gossipable>(message: T): void
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Request information from peers via the request response protocol.
|
|
39
|
-
*
|
|
40
|
-
* @param protocol - The request response protocol to use
|
|
41
|
-
* @param request - The request type, corresponding to the protocol
|
|
42
|
-
* @returns The response type, corresponding to the protocol
|
|
43
|
-
*/
|
|
44
|
-
sendRequest<Protocol extends ReqRespSubProtocol>(
|
|
45
|
-
protocol: Protocol,
|
|
46
|
-
request: InstanceType<SubProtocolMap[Protocol]['request']>,
|
|
47
|
-
): Promise<InstanceType<SubProtocolMap[Protocol]['response']> | undefined>;
|
|
52
|
+
propagate<T extends Gossipable>(message: T): Promise<void>;
|
|
48
53
|
|
|
49
54
|
/**
|
|
50
55
|
* Send a batch of requests to peers, and return the responses
|
|
@@ -56,14 +61,33 @@ export interface P2PService {
|
|
|
56
61
|
sendBatchRequest<Protocol extends ReqRespSubProtocol>(
|
|
57
62
|
protocol: Protocol,
|
|
58
63
|
requests: InstanceType<SubProtocolMap[Protocol]['request']>[],
|
|
59
|
-
|
|
64
|
+
pinnedPeerId?: PeerId,
|
|
65
|
+
timeoutMs?: number,
|
|
66
|
+
maxPeers?: number,
|
|
67
|
+
maxRetryAttempts?: number,
|
|
68
|
+
): Promise<InstanceType<SubProtocolMap[Protocol]['response']>[]>;
|
|
60
69
|
|
|
61
70
|
// Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
62
|
-
registerBlockReceivedCallback(callback:
|
|
71
|
+
registerBlockReceivedCallback(callback: P2PBlockReceivedCallback): void;
|
|
63
72
|
|
|
64
73
|
getEnr(): ENR | undefined;
|
|
65
74
|
|
|
66
75
|
getPeers(includePending?: boolean): PeerInfo[];
|
|
76
|
+
|
|
77
|
+
validate(txs: Tx[]): Promise<void>;
|
|
78
|
+
|
|
79
|
+
addReqRespSubProtocol(
|
|
80
|
+
subProtocol: ReqRespSubProtocol,
|
|
81
|
+
handler: ReqRespSubProtocolHandler,
|
|
82
|
+
validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
83
|
+
): Promise<void>;
|
|
84
|
+
|
|
85
|
+
handleAuthRequestFromPeer(authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage>;
|
|
86
|
+
|
|
87
|
+
updateConfig(config: Partial<P2PReqRespConfig>): void;
|
|
88
|
+
|
|
89
|
+
/** If node running this P2P stack is validator, passes in validator address to P2P layer */
|
|
90
|
+
registerThisValidatorAddresses(address: EthAddress[]): void;
|
|
67
91
|
}
|
|
68
92
|
|
|
69
93
|
/**
|
|
@@ -81,10 +105,10 @@ export interface PeerDiscoveryService extends EventEmitter {
|
|
|
81
105
|
stop(): Promise<void>;
|
|
82
106
|
|
|
83
107
|
/**
|
|
84
|
-
* Gets all
|
|
85
|
-
* @returns An array of
|
|
108
|
+
* Gets all KadValues.
|
|
109
|
+
* @returns An array of ENRs.
|
|
86
110
|
*/
|
|
87
|
-
|
|
111
|
+
getKadValues(): ENR[];
|
|
88
112
|
|
|
89
113
|
/**
|
|
90
114
|
* Runs findRandomNode query.
|
|
@@ -108,5 +132,5 @@ export interface PeerDiscoveryService extends EventEmitter {
|
|
|
108
132
|
|
|
109
133
|
getEnr(): ENR | undefined;
|
|
110
134
|
|
|
111
|
-
|
|
135
|
+
bootstrapNodeEnrs: ENR[];
|
|
112
136
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
+
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
|
|
4
|
+
export type TxCollectionConfig = {
|
|
5
|
+
/** How long to wait before starting reqresp for fast collection */
|
|
6
|
+
txCollectionFastNodesTimeoutBeforeReqRespMs: number;
|
|
7
|
+
/** How often to collect from configured nodes */
|
|
8
|
+
txCollectionSlowNodesIntervalMs: number;
|
|
9
|
+
/** How ofter to collect from peers */
|
|
10
|
+
txCollectionSlowReqRespIntervalMs: number;
|
|
11
|
+
/** How long to wait for a reqresp response during slow collection */
|
|
12
|
+
txCollectionSlowReqRespTimeoutMs: number;
|
|
13
|
+
/** How often to reconcile found txs with the tx pool */
|
|
14
|
+
txCollectionReconcileIntervalMs: number;
|
|
15
|
+
/** Whether to disable the slow collection loop if we are dealing with any immediate requests */
|
|
16
|
+
txCollectionDisableSlowDuringFastRequests: boolean;
|
|
17
|
+
/** How many ms to wait between retried request to a node via RPC during fast collection */
|
|
18
|
+
txCollectionFastNodeIntervalMs: number;
|
|
19
|
+
/** A comma-separated list of Aztec node RPC URLs to use for tx collection */
|
|
20
|
+
txCollectionNodeRpcUrls: string[];
|
|
21
|
+
/** Maximum number of parallel requests to make to a node during fast collection */
|
|
22
|
+
txCollectionFastMaxParallelRequestsPerNode: number;
|
|
23
|
+
/** Maximum number of transactions to request from a node in a single batch */
|
|
24
|
+
txCollectionNodeRpcMaxBatchSize: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig> = {
|
|
28
|
+
txCollectionFastNodesTimeoutBeforeReqRespMs: {
|
|
29
|
+
env: 'TX_COLLECTION_FAST_NODES_TIMEOUT_BEFORE_REQ_RESP_MS',
|
|
30
|
+
description: 'How long to wait before starting reqresp for fast collection',
|
|
31
|
+
...numberConfigHelper(200),
|
|
32
|
+
},
|
|
33
|
+
txCollectionSlowNodesIntervalMs: {
|
|
34
|
+
env: 'TX_COLLECTION_SLOW_NODES_INTERVAL_MS',
|
|
35
|
+
description: 'How often to collect from configured nodes in the slow collection loop',
|
|
36
|
+
...numberConfigHelper(12_000),
|
|
37
|
+
},
|
|
38
|
+
txCollectionSlowReqRespIntervalMs: {
|
|
39
|
+
env: 'TX_COLLECTION_SLOW_REQ_RESP_INTERVAL_MS',
|
|
40
|
+
description: 'How often to collect from peers via reqresp in the slow collection loop',
|
|
41
|
+
...numberConfigHelper(12_000),
|
|
42
|
+
},
|
|
43
|
+
txCollectionSlowReqRespTimeoutMs: {
|
|
44
|
+
env: 'TX_COLLECTION_SLOW_REQ_RESP_TIMEOUT_MS',
|
|
45
|
+
description: 'How long to wait for a reqresp response during slow collection',
|
|
46
|
+
...numberConfigHelper(20_000),
|
|
47
|
+
},
|
|
48
|
+
txCollectionReconcileIntervalMs: {
|
|
49
|
+
env: 'TX_COLLECTION_RECONCILE_INTERVAL_MS',
|
|
50
|
+
description: 'How often to reconcile found txs from the tx pool',
|
|
51
|
+
...numberConfigHelper(60_000),
|
|
52
|
+
},
|
|
53
|
+
txCollectionDisableSlowDuringFastRequests: {
|
|
54
|
+
env: 'TX_COLLECTION_DISABLE_SLOW_DURING_FAST_REQUESTS',
|
|
55
|
+
description: 'Whether to disable the slow collection loop if we are dealing with any immediate requests',
|
|
56
|
+
...booleanConfigHelper(true),
|
|
57
|
+
},
|
|
58
|
+
txCollectionFastNodeIntervalMs: {
|
|
59
|
+
env: 'TX_COLLECTION_FAST_NODE_INTERVAL_MS',
|
|
60
|
+
description: 'How many ms to wait between retried request to a node via RPC during fast collection',
|
|
61
|
+
...numberConfigHelper(500),
|
|
62
|
+
},
|
|
63
|
+
txCollectionNodeRpcUrls: {
|
|
64
|
+
env: 'TX_COLLECTION_NODE_RPC_URLS',
|
|
65
|
+
fallback: ['PROVER_COORDINATION_NODE_URLS'],
|
|
66
|
+
description: 'A comma-separated list of Aztec node RPC URLs to use for tx collection',
|
|
67
|
+
parseEnv: (val: string) =>
|
|
68
|
+
val
|
|
69
|
+
.split(',')
|
|
70
|
+
.map(url => url.trim().replace(/\/$/, ''))
|
|
71
|
+
.filter(url => url.length > 0),
|
|
72
|
+
defaultValue: [],
|
|
73
|
+
},
|
|
74
|
+
txCollectionFastMaxParallelRequestsPerNode: {
|
|
75
|
+
env: 'TX_COLLECTION_FAST_MAX_PARALLEL_REQUESTS_PER_NODE',
|
|
76
|
+
description: 'Maximum number of parallel requests to make to a node during fast collection',
|
|
77
|
+
...numberConfigHelper(4),
|
|
78
|
+
},
|
|
79
|
+
txCollectionNodeRpcMaxBatchSize: {
|
|
80
|
+
env: 'TX_COLLECTION_NODE_RPC_MAX_BATCH_SIZE',
|
|
81
|
+
description: 'Maximum number of transactions to request from a node in a single batch',
|
|
82
|
+
...numberConfigHelper(MAX_RPC_TXS_LEN),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { times } from '@aztec/foundation/collection';
|
|
2
|
+
import { AbortError, TimeoutError } from '@aztec/foundation/error';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { boundInclusive } from '@aztec/foundation/number';
|
|
5
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
6
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
7
|
+
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
8
|
+
import type { L2BlockInfo } from '@aztec/stdlib/block';
|
|
9
|
+
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
10
|
+
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
11
|
+
|
|
12
|
+
import type { PeerId } from '@libp2p/interface';
|
|
13
|
+
|
|
14
|
+
import { type ReqRespInterface, ReqRespSubProtocol } from '../reqresp/interface.js';
|
|
15
|
+
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
16
|
+
import type { TxCollectionConfig } from './config.js';
|
|
17
|
+
import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
|
|
18
|
+
import type { TxCollectionSink } from './tx_collection_sink.js';
|
|
19
|
+
import type { TxSource } from './tx_source.js';
|
|
20
|
+
|
|
21
|
+
export class FastTxCollection {
|
|
22
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
23
|
+
protected requests: Set<FastCollectionRequest> = new Set();
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private reqResp: Pick<ReqRespInterface, 'sendBatchRequest'>,
|
|
27
|
+
private nodes: TxSource[],
|
|
28
|
+
private txCollectionSink: TxCollectionSink,
|
|
29
|
+
private config: TxCollectionConfig,
|
|
30
|
+
private dateProvider: DateProvider = new DateProvider(),
|
|
31
|
+
private log: Logger = createLogger('p2p:tx_collection_service'),
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
public async stop() {
|
|
35
|
+
this.requests.forEach(request => request.promise.reject(new AbortError(`Stopped collection service`)));
|
|
36
|
+
await Promise.resolve();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public getFastCollectionRequests() {
|
|
40
|
+
return this.requests;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async collectFastFor(
|
|
44
|
+
input: FastCollectionRequestInput,
|
|
45
|
+
txHashes: TxHash[] | string[],
|
|
46
|
+
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
47
|
+
) {
|
|
48
|
+
const timeout = opts.deadline.getTime() - this.dateProvider.now();
|
|
49
|
+
if (timeout <= 0) {
|
|
50
|
+
this.log.warn(`Deadline for fast tx collection is in the past (${timeout}ms)`, {
|
|
51
|
+
deadline: opts.deadline.getTime(),
|
|
52
|
+
now: this.dateProvider.now(),
|
|
53
|
+
});
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const blockInfo: L2BlockInfo =
|
|
58
|
+
input.type === 'proposal'
|
|
59
|
+
? { ...input.blockProposal.toBlockInfo(), blockNumber: input.blockNumber }
|
|
60
|
+
: { ...input.block.toBlockInfo() };
|
|
61
|
+
|
|
62
|
+
// This promise is used to await for the collection to finish during the main collectFast method.
|
|
63
|
+
// It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
|
|
64
|
+
const promise = promiseWithResolvers<void>();
|
|
65
|
+
setTimeout(() => promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
|
|
66
|
+
|
|
67
|
+
const request: FastCollectionRequest = {
|
|
68
|
+
...input,
|
|
69
|
+
blockInfo,
|
|
70
|
+
promise,
|
|
71
|
+
foundTxs: new Map<string, Tx>(),
|
|
72
|
+
missingTxHashes: new Set(txHashes.map(t => t.toString())),
|
|
73
|
+
deadline: opts.deadline,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const [duration] = await elapsed(() => this.collectFast(request, { ...opts }));
|
|
77
|
+
|
|
78
|
+
this.log.verbose(
|
|
79
|
+
`Collected ${request.foundTxs.size} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
|
|
80
|
+
{
|
|
81
|
+
...blockInfo,
|
|
82
|
+
duration,
|
|
83
|
+
requestType: input.type,
|
|
84
|
+
missingTxs: [...request.missingTxHashes],
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
return [...request.foundTxs.values()];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected async collectFast(
|
|
91
|
+
request: FastCollectionRequest,
|
|
92
|
+
opts: { proposal?: BlockProposal; deadline: Date; pinnedPeer?: PeerId },
|
|
93
|
+
) {
|
|
94
|
+
this.requests.add(request);
|
|
95
|
+
const { blockInfo } = request;
|
|
96
|
+
|
|
97
|
+
this.log.debug(
|
|
98
|
+
`Starting fast collection of ${request.missingTxHashes.size} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
99
|
+
{ ...blockInfo, requestType: request.type, deadline: opts.deadline },
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
// Start blasting all nodes for the txs. We give them a little time to respond before we start reqresp.
|
|
104
|
+
// And keep an eye on the request promise to ensure we don't wait longer than the deadline or return as soon
|
|
105
|
+
// as we have collected all txs, whatever the source.
|
|
106
|
+
const nodeCollectionPromise = this.collectFastFromNodes(request, opts);
|
|
107
|
+
const waitBeforeReqResp = sleep(this.config.txCollectionFastNodesTimeoutBeforeReqRespMs);
|
|
108
|
+
await Promise.race([request.promise.promise, waitBeforeReqResp]);
|
|
109
|
+
|
|
110
|
+
// If we have collected all txs, we can stop here
|
|
111
|
+
if (request.missingTxHashes.size === 0) {
|
|
112
|
+
this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Start blasting reqresp for the remaining txs. Note that node collection keeps running in parallel.
|
|
117
|
+
// We stop when we have collected all txs, timed out, or both node collection and reqresp have given up.
|
|
118
|
+
const collectionPromise = Promise.allSettled([this.collectFastViaReqResp(request, opts), nodeCollectionPromise]);
|
|
119
|
+
await Promise.race([collectionPromise, request.promise.promise]);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
// Log and swallow all errors
|
|
122
|
+
const logCtx = {
|
|
123
|
+
...blockInfo,
|
|
124
|
+
errorMessage: err instanceof Error ? err.message : undefined,
|
|
125
|
+
missingTxs: [...request.missingTxHashes].map(txHash => txHash.toString()),
|
|
126
|
+
};
|
|
127
|
+
if (err instanceof Error && err.name === 'TimeoutError') {
|
|
128
|
+
this.log.warn(`Timed out collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
|
|
129
|
+
} else if (err instanceof Error && err.name === 'AbortError') {
|
|
130
|
+
this.log.warn(`Aborted collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
|
|
131
|
+
} else {
|
|
132
|
+
this.log.error(`Error collecting txs for ${request.type} for slot ${blockInfo.slotNumber}`, err, logCtx);
|
|
133
|
+
}
|
|
134
|
+
} finally {
|
|
135
|
+
// Ensure no unresolved promises and remove the request from the set
|
|
136
|
+
request.promise.resolve();
|
|
137
|
+
this.requests.delete(request);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Starts collecting txs from all configured nodes. We send `txCollectionFastMaxParallelRequestsPerNode` requests
|
|
143
|
+
* in parallel to each node. We keep track of the number of attempts made to collect each tx, so we can prioritize
|
|
144
|
+
* the txs that have been requested less often whenever we need to send a new batch of requests. We ensure that no
|
|
145
|
+
* tx is requested more than once at the same time to the same node.
|
|
146
|
+
*/
|
|
147
|
+
private async collectFastFromNodes(request: FastCollectionRequest, opts: { deadline: Date }): Promise<void> {
|
|
148
|
+
if (this.nodes.length === 0) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Keep a shared priority queue of all txs pending to be requested, sorted by the number of attempts made to collect them.
|
|
153
|
+
const attemptsPerTx = [...request.missingTxHashes].map(txHash => ({ txHash, attempts: 0, found: false }));
|
|
154
|
+
|
|
155
|
+
// Returns once we have finished all node loops. Each loop finishes when the deadline is hit, or all txs have been collected.
|
|
156
|
+
await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx, opts)));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private async collectFastFromNode(
|
|
160
|
+
request: FastCollectionRequest,
|
|
161
|
+
node: TxSource,
|
|
162
|
+
attemptsPerTx: { txHash: string; attempts: number; found: boolean }[],
|
|
163
|
+
opts: { deadline: Date },
|
|
164
|
+
) {
|
|
165
|
+
const notFinished = () =>
|
|
166
|
+
this.dateProvider.now() <= +opts.deadline && request.missingTxHashes.size > 0 && this.requests.has(request);
|
|
167
|
+
|
|
168
|
+
const maxParallelRequests = this.config.txCollectionFastMaxParallelRequestsPerNode;
|
|
169
|
+
const maxBatchSize = this.config.txCollectionNodeRpcMaxBatchSize;
|
|
170
|
+
const activeRequestsToThisNode = new Set<string>(); // Track the txs being actively requested to this node
|
|
171
|
+
|
|
172
|
+
const processBatch = async () => {
|
|
173
|
+
while (notFinished()) {
|
|
174
|
+
// Pull tx hashes from the attemptsPerTx array, which is sorted by attempts,
|
|
175
|
+
// so we prioritize txs that have been requested less often.
|
|
176
|
+
const batch = [];
|
|
177
|
+
let index = 0;
|
|
178
|
+
while (batch.length < maxBatchSize) {
|
|
179
|
+
const txToRequest = attemptsPerTx[index++];
|
|
180
|
+
if (!txToRequest) {
|
|
181
|
+
// No more txs to process
|
|
182
|
+
break;
|
|
183
|
+
} else if (!request.missingTxHashes.has(txToRequest.txHash)) {
|
|
184
|
+
// Mark as found if it was found somewhere else, we'll then remove it from the array.
|
|
185
|
+
// We don't delete it now since 'array.splice' is pretty expensive, so we do it after sorting.
|
|
186
|
+
txToRequest.found = true;
|
|
187
|
+
} else if (!activeRequestsToThisNode.has(txToRequest.txHash)) {
|
|
188
|
+
// If the tx is not alredy being requested to this node, add it to the current batch and increase attempts.
|
|
189
|
+
// Note that we increase the attempts *before* making the request, so the next `collectFastFromNode` that
|
|
190
|
+
// needs to grab txs to send, will pick txs that have been requested less often, instead of all requesting
|
|
191
|
+
// the same txs at the same time.
|
|
192
|
+
batch.push(txToRequest);
|
|
193
|
+
activeRequestsToThisNode.add(txToRequest.txHash);
|
|
194
|
+
txToRequest.attempts++;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// After modifying the array by removing txs or updating attempts, re-sort it and trim the found txs from the end.
|
|
199
|
+
attemptsPerTx.sort((a, b) =>
|
|
200
|
+
a.found === b.found ? a.attempts - b.attempts : Number(a.found) - Number(b.found),
|
|
201
|
+
);
|
|
202
|
+
const firstFoundTxIndex = attemptsPerTx.findIndex(tx => tx.found);
|
|
203
|
+
if (firstFoundTxIndex !== -1) {
|
|
204
|
+
attemptsPerTx.length = firstFoundTxIndex;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// If we see no more txs to request, we can stop this "process" loop
|
|
208
|
+
if (batch.length === 0) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Collect this batch from the node
|
|
213
|
+
await this.txCollectionSink.collect(
|
|
214
|
+
txHashes => node.getTxsByHash(txHashes),
|
|
215
|
+
batch.map(({ txHash }) => TxHash.fromString(txHash)),
|
|
216
|
+
{
|
|
217
|
+
description: `fast ${node.getInfo()}`,
|
|
218
|
+
node: node.getInfo(),
|
|
219
|
+
method: 'fast-node-rpc',
|
|
220
|
+
...request.blockInfo,
|
|
221
|
+
},
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
// Clear from the active requests the txs we just requested
|
|
225
|
+
for (const requestedTx of batch) {
|
|
226
|
+
activeRequestsToThisNode.delete(requestedTx.txHash);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Sleep a bit until hitting the node again (or not, depending on config)
|
|
230
|
+
if (notFinished()) {
|
|
231
|
+
await sleep(this.config.txCollectionFastNodeIntervalMs);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// Kick off N parallel requests to the node, up to the maxParallelRequests limit
|
|
237
|
+
await Promise.all(times(maxParallelRequests, processBatch));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private async collectFastViaReqResp(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
|
|
241
|
+
const timeoutMs = +request.deadline - this.dateProvider.now();
|
|
242
|
+
const pinnedPeer = opts.pinnedPeer;
|
|
243
|
+
const maxPeers = boundInclusive(Math.ceil(request.missingTxHashes.size / 2), 8, 32);
|
|
244
|
+
const maxRetryAttempts = 5;
|
|
245
|
+
const blockInfo = request.blockInfo;
|
|
246
|
+
const slotNumber = blockInfo.slotNumber;
|
|
247
|
+
if (timeoutMs < 100) {
|
|
248
|
+
this.log.warn(
|
|
249
|
+
`Not initiating fast reqresp for txs for ${request.type} at slot ${blockInfo.slotNumber} due to timeout`,
|
|
250
|
+
{ timeoutMs, ...blockInfo },
|
|
251
|
+
);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
this.log.debug(
|
|
256
|
+
`Starting fast reqresp for ${request.missingTxHashes.size} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
257
|
+
{ ...blockInfo, timeoutMs, pinnedPeer },
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
await this.txCollectionSink.collect(
|
|
262
|
+
async txHashes => {
|
|
263
|
+
const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
264
|
+
ReqRespSubProtocol.TX,
|
|
265
|
+
chunkTxHashesRequest(txHashes),
|
|
266
|
+
pinnedPeer,
|
|
267
|
+
timeoutMs,
|
|
268
|
+
maxPeers,
|
|
269
|
+
maxRetryAttempts,
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
return txs.flat();
|
|
273
|
+
},
|
|
274
|
+
Array.from(request.missingTxHashes).map(txHash => TxHash.fromString(txHash)),
|
|
275
|
+
{ description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
|
|
276
|
+
);
|
|
277
|
+
} catch (err) {
|
|
278
|
+
this.log.error(`Error sending fast reqresp request for txs`, err, {
|
|
279
|
+
txs: [...request.missingTxHashes],
|
|
280
|
+
...blockInfo,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Handle txs by marking them as found for the requests that are waiting for them, and resolves the request if all its txs have been found.
|
|
287
|
+
* Called internally and from the main tx collection manager whenever the tx pool emits a tx-added event.
|
|
288
|
+
*/
|
|
289
|
+
public foundTxs(txs: Tx[]) {
|
|
290
|
+
for (const request of this.requests) {
|
|
291
|
+
for (const tx of txs) {
|
|
292
|
+
const txHash = tx.txHash.toString();
|
|
293
|
+
// Remove the tx hash from the missing set, and add it to the found set.
|
|
294
|
+
if (request.missingTxHashes.has(txHash)) {
|
|
295
|
+
request.missingTxHashes.delete(txHash);
|
|
296
|
+
request.foundTxs.set(txHash, tx);
|
|
297
|
+
this.log.trace(`Found tx ${txHash} for fast collection request`, {
|
|
298
|
+
...request.blockInfo,
|
|
299
|
+
txHash: tx.txHash.toString(),
|
|
300
|
+
type: request.type,
|
|
301
|
+
});
|
|
302
|
+
// If we found all txs for this request, we resolve the promise
|
|
303
|
+
if (request.missingTxHashes.size === 0) {
|
|
304
|
+
this.log.trace(`All txs found for fast collection request`, {
|
|
305
|
+
...request.blockInfo,
|
|
306
|
+
type: request.type,
|
|
307
|
+
});
|
|
308
|
+
request.promise.resolve();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
317
|
+
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
318
|
+
*/
|
|
319
|
+
public stopCollectingForBlocksUpTo(blockNumber: number): void {
|
|
320
|
+
for (const request of this.requests) {
|
|
321
|
+
if (request.blockInfo.blockNumber <= blockNumber) {
|
|
322
|
+
request.promise.reject(new AbortError(`Stopped collecting txs up to block ${blockNumber}`));
|
|
323
|
+
this.requests.delete(request);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Stop collecting all txs for blocks greater than the block number specified.
|
|
330
|
+
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
331
|
+
*/
|
|
332
|
+
public stopCollectingForBlocksAfter(blockNumber: number): void {
|
|
333
|
+
for (const request of this.requests) {
|
|
334
|
+
if (request.blockInfo.blockNumber > blockNumber) {
|
|
335
|
+
request.promise.reject(new AbortError(`Stopped collecting txs after block ${blockNumber}`));
|
|
336
|
+
this.requests.delete(request);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Attributes,
|
|
3
|
+
type Histogram,
|
|
4
|
+
Metrics,
|
|
5
|
+
type TelemetryClient,
|
|
6
|
+
type UpDownCounter,
|
|
7
|
+
ValueType,
|
|
8
|
+
} from '@aztec/telemetry-client';
|
|
9
|
+
|
|
10
|
+
import type { CollectionMethod } from './tx_collection.js';
|
|
11
|
+
|
|
12
|
+
export class TxCollectionInstrumentation {
|
|
13
|
+
private txsCollected: UpDownCounter;
|
|
14
|
+
private collectionDurationPerTx: Histogram;
|
|
15
|
+
private collectionDurationPerRequest: Histogram;
|
|
16
|
+
|
|
17
|
+
constructor(client: TelemetryClient, name: string) {
|
|
18
|
+
const meter = client.getMeter(name);
|
|
19
|
+
|
|
20
|
+
this.txsCollected = meter.createUpDownCounter(Metrics.TX_COLLECTOR_COUNT, {
|
|
21
|
+
description: 'The number of txs collected',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX, {
|
|
25
|
+
unit: 'ms',
|
|
26
|
+
description: 'Average duration per tx of an individual tx collection request',
|
|
27
|
+
valueType: ValueType.INT,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
this.collectionDurationPerRequest = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_REQUEST, {
|
|
31
|
+
unit: 'ms',
|
|
32
|
+
description: 'Total duration of an individual tx collection request',
|
|
33
|
+
valueType: ValueType.INT,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
increaseTxsFor(what: CollectionMethod, count: number, duration: number) {
|
|
38
|
+
const durationPerTx = Math.ceil(duration / count);
|
|
39
|
+
this.collectionDurationPerTx.record(durationPerTx, { [Attributes.TX_COLLECTION_METHOD]: what });
|
|
40
|
+
this.collectionDurationPerRequest.record(Math.ceil(duration), { [Attributes.TX_COLLECTION_METHOD]: what });
|
|
41
|
+
this.txsCollected.add(count, { [Attributes.TX_COLLECTION_METHOD]: what });
|
|
42
|
+
}
|
|
43
|
+
}
|