@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.21caa21
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
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { L2Block } from '@aztec/stdlib/block';
|
|
3
|
-
import {
|
|
3
|
+
import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { PeerId } from '@libp2p/interface';
|
|
6
6
|
|
|
7
|
+
import type { P2PReqRespConfig } from './config.js';
|
|
8
|
+
import { AuthRequest, AuthResponse } from './protocols/auth.js';
|
|
9
|
+
import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
|
|
10
|
+
import { StatusMessage } from './protocols/status.js';
|
|
7
11
|
import type { ReqRespStatus } from './status.js';
|
|
8
12
|
|
|
9
13
|
/*
|
|
10
14
|
* Request Response Sub Protocols
|
|
11
15
|
*/
|
|
12
|
-
export const PING_PROTOCOL = '/aztec/req/ping/
|
|
13
|
-
export const STATUS_PROTOCOL = '/aztec/req/status/
|
|
14
|
-
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/
|
|
15
|
-
export const TX_REQ_PROTOCOL = '/aztec/req/tx/
|
|
16
|
-
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/
|
|
16
|
+
export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
|
|
17
|
+
export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
|
|
18
|
+
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
|
|
19
|
+
export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
|
|
20
|
+
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
|
|
21
|
+
export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
|
|
22
|
+
export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
|
|
17
23
|
|
|
18
24
|
export enum ReqRespSubProtocol {
|
|
19
25
|
PING = PING_PROTOCOL,
|
|
@@ -21,6 +27,8 @@ export enum ReqRespSubProtocol {
|
|
|
21
27
|
GOODBYE = GOODBYE_PROTOCOL,
|
|
22
28
|
TX = TX_REQ_PROTOCOL,
|
|
23
29
|
BLOCK = BLOCK_REQ_PROTOCOL,
|
|
30
|
+
AUTH = AUTH_PROTOCOL,
|
|
31
|
+
BLOCK_TXS = BLOCK_TXS_REQ_PROTOCOL,
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/**
|
|
@@ -36,12 +44,12 @@ export type ReqRespSubProtocolRateLimits = Record<ReqRespSubProtocol, ProtocolRa
|
|
|
36
44
|
|
|
37
45
|
/**
|
|
38
46
|
* The response from the ReqResp protocol
|
|
39
|
-
* Consists of a status
|
|
47
|
+
* Consists of a status
|
|
48
|
+
* And, optionally, a data buffer (in case status is SUCCESS)
|
|
40
49
|
*/
|
|
41
|
-
export
|
|
42
|
-
status: ReqRespStatus;
|
|
43
|
-
|
|
44
|
-
}
|
|
50
|
+
export type ReqRespResponse =
|
|
51
|
+
| { status: ReqRespStatus.SUCCESS; data: Buffer }
|
|
52
|
+
| { status: Exclude<ReqRespStatus, ReqRespStatus.SUCCESS> };
|
|
45
53
|
|
|
46
54
|
/**
|
|
47
55
|
* A rate limit quota
|
|
@@ -91,33 +99,27 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
|
|
|
91
99
|
[ReqRespSubProtocol.TX]: noopValidator,
|
|
92
100
|
[ReqRespSubProtocol.GOODBYE]: noopValidator,
|
|
93
101
|
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
102
|
+
[ReqRespSubProtocol.AUTH]: noopValidator,
|
|
103
|
+
[ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
|
|
94
104
|
};
|
|
95
105
|
|
|
106
|
+
/*
|
|
107
|
+
* Helper class to sub-protocol validation error*/
|
|
108
|
+
export class ValidationError extends Error {
|
|
109
|
+
constructor(message: string) {
|
|
110
|
+
super(message);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
96
114
|
/**
|
|
97
115
|
* Sub protocol map determines the request and response types for each
|
|
98
116
|
* Req Resp protocol
|
|
99
117
|
*/
|
|
100
118
|
export type SubProtocolMap = {
|
|
101
|
-
[S in ReqRespSubProtocol]: RequestResponsePair<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* Default handler for unimplemented sub protocols, this SHOULD be overwritten
|
|
106
|
-
* by the service, but is provided as a fallback
|
|
107
|
-
*/
|
|
108
|
-
const defaultHandler = (_msg: any): Promise<Buffer> => {
|
|
109
|
-
return Promise.resolve(Buffer.from('unimplemented'));
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Default sub protocol handlers - this SHOULD be overwritten by the service,
|
|
114
|
-
*/
|
|
115
|
-
export const DEFAULT_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
|
|
116
|
-
[ReqRespSubProtocol.PING]: defaultHandler,
|
|
117
|
-
[ReqRespSubProtocol.STATUS]: defaultHandler,
|
|
118
|
-
[ReqRespSubProtocol.TX]: defaultHandler,
|
|
119
|
-
[ReqRespSubProtocol.GOODBYE]: defaultHandler,
|
|
120
|
-
[ReqRespSubProtocol.BLOCK]: defaultHandler,
|
|
119
|
+
[S in ReqRespSubProtocol]: RequestResponsePair<
|
|
120
|
+
InstanceType<(typeof subProtocolMap)[S]['request']>,
|
|
121
|
+
InstanceType<(typeof subProtocolMap)[S]['response']>
|
|
122
|
+
>;
|
|
121
123
|
};
|
|
122
124
|
|
|
123
125
|
/**
|
|
@@ -138,6 +140,22 @@ interface RequestResponsePair<Req extends { toBuffer(): Buffer }, Res> {
|
|
|
138
140
|
};
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
/*
|
|
144
|
+
* Small helper function which parses buffer into specific response type
|
|
145
|
+
* It is needed to make TypeScript happy, as it cannot infer the type from the buffer
|
|
146
|
+
*
|
|
147
|
+
* @param proto - The sub protocol to parse the response for
|
|
148
|
+
* @param buffer - The buffer to parse
|
|
149
|
+
*
|
|
150
|
+
* @returns - The parsed response object
|
|
151
|
+
* */
|
|
152
|
+
export function responseFromBuffer<P extends ReqRespSubProtocol>(
|
|
153
|
+
proto: P,
|
|
154
|
+
buffer: Buffer,
|
|
155
|
+
): InstanceType<(typeof subProtocolMap)[P]['response']> {
|
|
156
|
+
return subProtocolMap[proto].response.fromBuffer(buffer) as InstanceType<(typeof subProtocolMap)[P]['response']>;
|
|
157
|
+
}
|
|
158
|
+
|
|
141
159
|
/**
|
|
142
160
|
* RequestableBuffer is a wrapper around a buffer that allows it to be
|
|
143
161
|
* used in generic request response protocols
|
|
@@ -161,18 +179,18 @@ export class RequestableBuffer {
|
|
|
161
179
|
* This defines the request and response types for each sub protocol, used primarily
|
|
162
180
|
* as a type rather than an object
|
|
163
181
|
*/
|
|
164
|
-
export const subProtocolMap
|
|
182
|
+
export const subProtocolMap = {
|
|
165
183
|
[ReqRespSubProtocol.PING]: {
|
|
166
184
|
request: RequestableBuffer,
|
|
167
185
|
response: RequestableBuffer,
|
|
168
186
|
},
|
|
169
187
|
[ReqRespSubProtocol.STATUS]: {
|
|
170
|
-
request:
|
|
171
|
-
response:
|
|
188
|
+
request: StatusMessage,
|
|
189
|
+
response: StatusMessage,
|
|
172
190
|
},
|
|
173
191
|
[ReqRespSubProtocol.TX]: {
|
|
174
|
-
request:
|
|
175
|
-
response:
|
|
192
|
+
request: TxHashArray,
|
|
193
|
+
response: TxArray,
|
|
176
194
|
},
|
|
177
195
|
[ReqRespSubProtocol.GOODBYE]: {
|
|
178
196
|
request: RequestableBuffer,
|
|
@@ -182,4 +200,41 @@ export const subProtocolMap: SubProtocolMap = {
|
|
|
182
200
|
request: Fr, // block number
|
|
183
201
|
response: L2Block,
|
|
184
202
|
},
|
|
203
|
+
[ReqRespSubProtocol.AUTH]: {
|
|
204
|
+
request: AuthRequest,
|
|
205
|
+
response: AuthResponse,
|
|
206
|
+
},
|
|
207
|
+
[ReqRespSubProtocol.BLOCK_TXS]: {
|
|
208
|
+
request: BlockTxsRequest,
|
|
209
|
+
response: BlockTxsResponse,
|
|
210
|
+
},
|
|
185
211
|
};
|
|
212
|
+
|
|
213
|
+
export interface ReqRespInterface {
|
|
214
|
+
start(
|
|
215
|
+
subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>,
|
|
216
|
+
subProtocolValidators: ReqRespSubProtocolValidators,
|
|
217
|
+
): Promise<void>;
|
|
218
|
+
addSubProtocol(
|
|
219
|
+
subProtocol: ReqRespSubProtocol,
|
|
220
|
+
handler: ReqRespSubProtocolHandler,
|
|
221
|
+
validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
222
|
+
): Promise<void>;
|
|
223
|
+
stop(): Promise<void>;
|
|
224
|
+
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
225
|
+
subProtocol: SubProtocol,
|
|
226
|
+
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
227
|
+
pinnedPeer: PeerId | undefined,
|
|
228
|
+
timeoutMs?: number,
|
|
229
|
+
maxPeers?: number,
|
|
230
|
+
maxRetryAttempts?: number,
|
|
231
|
+
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
|
|
232
|
+
sendRequestToPeer(
|
|
233
|
+
peerId: PeerId,
|
|
234
|
+
subProtocol: ReqRespSubProtocol,
|
|
235
|
+
payload: Buffer,
|
|
236
|
+
dialTimeout?: number,
|
|
237
|
+
): Promise<ReqRespResponse>;
|
|
238
|
+
|
|
239
|
+
updateConfig(config: Partial<P2PReqRespConfig>): void;
|
|
240
|
+
}
|
|
@@ -11,7 +11,10 @@ export class ReqRespMetrics {
|
|
|
11
11
|
private readonly failedOutboundRequests: UpDownCounter;
|
|
12
12
|
private readonly failedInboundRequests: UpDownCounter;
|
|
13
13
|
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
readonly telemetryClient: TelemetryClient,
|
|
16
|
+
name = 'ReqResp',
|
|
17
|
+
) {
|
|
15
18
|
this.tracer = telemetryClient.getTracer(name);
|
|
16
19
|
|
|
17
20
|
const meter = telemetryClient.getMeter(name);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto';
|
|
3
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
4
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
6
|
+
|
|
7
|
+
import { StatusMessage } from './status.js';
|
|
8
|
+
|
|
9
|
+
export const VALIDATOR_AUTH_DOMAIN_SEPARATOR = 'Aztec Validator Challenge:';
|
|
10
|
+
export const VALIDATOR_AUTH_FULL_CHALLENGE_ENCODED_LENGTH =
|
|
11
|
+
VALIDATOR_AUTH_DOMAIN_SEPARATOR.length + Fr.random().toString().length;
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* P2P Auth Message
|
|
15
|
+
* Superset of the StatusMessage, used to establish a handshake between peers and authenticate them.
|
|
16
|
+
*/
|
|
17
|
+
export class AuthRequest {
|
|
18
|
+
constructor(
|
|
19
|
+
readonly status: StatusMessage,
|
|
20
|
+
readonly challenge: Fr,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Deserializes the AuthRequest object from a Buffer.
|
|
25
|
+
* @param buffer - Buffer or BufferReader object to deserialize.
|
|
26
|
+
* @returns An instance of StatusMessage.
|
|
27
|
+
*/
|
|
28
|
+
static fromBuffer(buffer: Buffer | BufferReader): AuthRequest {
|
|
29
|
+
const reader = BufferReader.asReader(buffer);
|
|
30
|
+
return new AuthRequest(
|
|
31
|
+
StatusMessage.fromBuffer(reader), // Deserialize StatusMessage
|
|
32
|
+
Fr.fromBuffer(reader), // challenge
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Serializes the AuthRequest object into a Buffer.
|
|
38
|
+
* @returns Buffer representation of the StatusMessage object.
|
|
39
|
+
*/
|
|
40
|
+
toBuffer() {
|
|
41
|
+
return serializeToBuffer([this.status, this.challenge]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getPayloadToSign(): Buffer32 {
|
|
45
|
+
const fullChallenge = VALIDATOR_AUTH_DOMAIN_SEPARATOR + this.challenge.toString();
|
|
46
|
+
return Buffer32.fromBuffer(keccak256(Buffer.from(fullChallenge, 'utf-8')));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static random(): AuthRequest {
|
|
50
|
+
return new AuthRequest(StatusMessage.random(), Fr.random());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class AuthResponse {
|
|
55
|
+
constructor(
|
|
56
|
+
readonly status: StatusMessage,
|
|
57
|
+
readonly signature: Signature,
|
|
58
|
+
) {}
|
|
59
|
+
/**
|
|
60
|
+
* Deserializes the AuthResponse object from a Buffer.
|
|
61
|
+
* @param buffer - Buffer or BufferReader object to deserialize.
|
|
62
|
+
* @returns An instance of StatusMessage.
|
|
63
|
+
*/
|
|
64
|
+
static fromBuffer(buffer: Buffer | BufferReader): AuthResponse {
|
|
65
|
+
const reader = BufferReader.asReader(buffer);
|
|
66
|
+
return new AuthResponse(
|
|
67
|
+
StatusMessage.fromBuffer(reader), // Deserialize StatusMessage
|
|
68
|
+
Signature.fromBuffer(reader), // response
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Serializes the AuthRequest object into a Buffer.
|
|
74
|
+
* @returns Buffer representation of the StatusMessage object.
|
|
75
|
+
*/
|
|
76
|
+
toBuffer() {
|
|
77
|
+
return serializeToBuffer([this.status, this.signature]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static random(): AuthResponse {
|
|
81
|
+
return new AuthResponse(StatusMessage.random(), Signature.random());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -4,12 +4,33 @@ import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
|
4
4
|
import type { PeerId } from '@libp2p/interface';
|
|
5
5
|
|
|
6
6
|
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
7
|
+
import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Handler for L2 Block requests
|
|
11
|
+
* @param l2BlockSource - source for L2 blocks
|
|
12
|
+
* @returns the Block request handler
|
|
13
|
+
* */
|
|
8
14
|
export function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubProtocolHandler {
|
|
15
|
+
/**
|
|
16
|
+
* @param peerId - the peer ID of the requester
|
|
17
|
+
* @param msg - the block request message, which is expected to contain valid block number as a Buffer
|
|
18
|
+
* @returns a Buffer containing the requested block data, or an empty Buffer if the block is not found
|
|
19
|
+
* @throws ReqRespStatusError if the input msg is not a valid block number
|
|
20
|
+
* */
|
|
9
21
|
return async (_peerId: PeerId, msg: Buffer) => {
|
|
10
|
-
|
|
22
|
+
let blockNumber: Fr;
|
|
23
|
+
try {
|
|
24
|
+
blockNumber = Fr.fromBuffer(msg);
|
|
25
|
+
} catch (err: any) {
|
|
26
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
27
|
+
}
|
|
11
28
|
|
|
12
|
-
|
|
13
|
-
|
|
29
|
+
try {
|
|
30
|
+
const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
|
|
31
|
+
return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
|
|
32
|
+
} catch (err: any) {
|
|
33
|
+
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
|
|
34
|
+
}
|
|
14
35
|
};
|
|
15
36
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BitVector helper class for representing and serializing bit vectors
|
|
5
|
+
*/
|
|
6
|
+
export class BitVector {
|
|
7
|
+
private buffer: Buffer;
|
|
8
|
+
private length: number;
|
|
9
|
+
|
|
10
|
+
constructor(buffer: Buffer, length: number) {
|
|
11
|
+
this.buffer = buffer;
|
|
12
|
+
this.length = length;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Creates new BitVector instance
|
|
17
|
+
* @param length - Length of the bit vector
|
|
18
|
+
* @param indices - Array of indices to set to 1 in the bit vector
|
|
19
|
+
*
|
|
20
|
+
* @returns A new BitVector instance with specified length and set indices
|
|
21
|
+
* */
|
|
22
|
+
static init(length: number, indices: number[]): BitVector {
|
|
23
|
+
if (indices.length > length) {
|
|
24
|
+
throw new Error('Indices length exceeds specified length');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const buffer = Buffer.alloc(BitVector.byteLength(length));
|
|
28
|
+
|
|
29
|
+
indices.forEach(idx => {
|
|
30
|
+
const invalidIndex = idx < 0 || idx >= length;
|
|
31
|
+
if (invalidIndex) {
|
|
32
|
+
throw new Error(`Index ${idx} is out of bounds for BitVector of length ${length}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const byteIndex = Math.floor(idx / 8);
|
|
36
|
+
const bitIndex = idx % 8;
|
|
37
|
+
buffer[byteIndex] |= 1 << bitIndex;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return new BitVector(buffer, length);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getLength(): number {
|
|
44
|
+
return this.length;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* Checks if element at index is set to true
|
|
49
|
+
*
|
|
50
|
+
* @param index - Index of the bit to check
|
|
51
|
+
*
|
|
52
|
+
* @returns True if the bit at index is set, false otherwise
|
|
53
|
+
* */
|
|
54
|
+
isSet(index: number): boolean {
|
|
55
|
+
return index >= 0 && index < this.length && !!(this.buffer[Math.floor(index / 8)] & (1 << index % 8));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns all indices which are set to true
|
|
60
|
+
* */
|
|
61
|
+
getTrueIndices(): number[] {
|
|
62
|
+
return Array.from({ length: this.length }, (_, i) => i).filter(i => this.isSet(i));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Serializes the BitVector object into a Buffer
|
|
67
|
+
*
|
|
68
|
+
* @returns Buffer representation of the BitVector object
|
|
69
|
+
* */
|
|
70
|
+
toBuffer(): Buffer {
|
|
71
|
+
return serializeToBuffer([this.length, this.buffer]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Deserializes buffer into new BitVector
|
|
76
|
+
*
|
|
77
|
+
* @returns A new BitVector instance
|
|
78
|
+
* */
|
|
79
|
+
static fromBuffer(buffer: Buffer | BufferReader): BitVector {
|
|
80
|
+
const reader = BufferReader.asReader(buffer);
|
|
81
|
+
const length = reader.readNumber();
|
|
82
|
+
|
|
83
|
+
const bitBuffer = reader.readBytes(BitVector.byteLength(length));
|
|
84
|
+
return new BitVector(bitBuffer, length);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static byteLength(length: number) {
|
|
88
|
+
return Math.ceil(length / 8);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TxArray } from '@aztec/stdlib/tx';
|
|
2
|
+
|
|
3
|
+
import type { PeerId } from '@libp2p/interface';
|
|
4
|
+
|
|
5
|
+
import type { AttestationPool } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
|
|
6
|
+
import type { TxPool } from '../../../../mem_pools/index.js';
|
|
7
|
+
import type { ReqRespSubProtocolHandler } from '../../interface.js';
|
|
8
|
+
import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
|
|
9
|
+
import { BitVector } from './bitvector.js';
|
|
10
|
+
import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Handler for block txs requests
|
|
14
|
+
* @param attestationPool - the attestation pool to check for block proposals
|
|
15
|
+
* @param mempools - the mempools containing the tx pool
|
|
16
|
+
* @returns the BlockTxs request handler
|
|
17
|
+
*/
|
|
18
|
+
export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool: TxPool): ReqRespSubProtocolHandler {
|
|
19
|
+
/**
|
|
20
|
+
* Handler for block txs requests
|
|
21
|
+
* @param msg - the block txs request message
|
|
22
|
+
* @returns the block txs response message
|
|
23
|
+
* @throws if msg is not a valid block txs request
|
|
24
|
+
*/
|
|
25
|
+
return async (_peerId: PeerId, msg: Buffer) => {
|
|
26
|
+
let request: BlockTxsRequest;
|
|
27
|
+
try {
|
|
28
|
+
request = BlockTxsRequest.fromBuffer(msg);
|
|
29
|
+
} catch (err: any) {
|
|
30
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const blockProposal = await attestationPool.getBlockProposal(request.blockHash.toString());
|
|
34
|
+
|
|
35
|
+
if (!blockProposal) {
|
|
36
|
+
throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const txsAvailableInPool = await txPool.hasTxs(blockProposal.txHashes);
|
|
40
|
+
//Map txs in the pool to their indices in the block proposal
|
|
41
|
+
const availableIndices = txsAvailableInPool.map((hasTx, idx) => (hasTx ? idx : -1)).filter(idx => idx !== -1);
|
|
42
|
+
const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
|
|
43
|
+
|
|
44
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
45
|
+
const requestedTxsHashes = blockProposal.txHashes.filter((_, idx) => requestedIndices.has(idx));
|
|
46
|
+
|
|
47
|
+
const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
|
|
48
|
+
|
|
49
|
+
const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
|
|
50
|
+
|
|
51
|
+
return response.toBuffer();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
+
import { TxArray } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
import { BitVector } from './bitvector.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Request message for requesting specific transactions from a block
|
|
9
|
+
*/
|
|
10
|
+
export class BlockTxsRequest {
|
|
11
|
+
constructor(
|
|
12
|
+
readonly blockHash: Fr, // 32 byte hash of the proposed block header
|
|
13
|
+
// BitVector indicating which txs from the proposal we are requesting
|
|
14
|
+
// 1 means we want the tx, 0 means we don't
|
|
15
|
+
readonly txIndices: BitVector,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Deserializes the BlockTxRequest object from a Buffer
|
|
20
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
21
|
+
* @returns An instance of BlockTxRequest
|
|
22
|
+
*/
|
|
23
|
+
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
|
|
24
|
+
const reader = BufferReader.asReader(buffer);
|
|
25
|
+
const blockHash = Fr.fromBuffer(reader);
|
|
26
|
+
const txIndices = BitVector.fromBuffer(reader);
|
|
27
|
+
|
|
28
|
+
return new BlockTxsRequest(blockHash, txIndices);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Serializes the BlockTxRequest object into a Buffer
|
|
33
|
+
* @returns Buffer representation of the BlockTxRequest object
|
|
34
|
+
*/
|
|
35
|
+
toBuffer(): Buffer {
|
|
36
|
+
return serializeToBuffer([this.blockHash, this.txIndices.toBuffer()]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Response message containing requested transactions from a block
|
|
42
|
+
*/
|
|
43
|
+
export class BlockTxsResponse {
|
|
44
|
+
constructor(
|
|
45
|
+
readonly blockHash: Fr,
|
|
46
|
+
readonly txs: TxArray, // List of transactions we requested and peer has
|
|
47
|
+
// BitVector indicating which txs from the proposal are available at the peer
|
|
48
|
+
// 1 means the tx is available, 0 means it is not
|
|
49
|
+
readonly txIndices: BitVector,
|
|
50
|
+
) {}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Deserializes the BlockTxResponse object from a Buffer
|
|
54
|
+
* @param buffer - Buffer or BufferReader object to deserialize
|
|
55
|
+
* @returns An instance of BlockTxResponse
|
|
56
|
+
*/
|
|
57
|
+
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
|
|
58
|
+
const reader = BufferReader.asReader(buffer);
|
|
59
|
+
const blockHash = Fr.fromBuffer(reader);
|
|
60
|
+
const txs = TxArray.fromBuffer(reader);
|
|
61
|
+
const txIndices = BitVector.fromBuffer(reader);
|
|
62
|
+
|
|
63
|
+
return new BlockTxsResponse(blockHash, txs, txIndices);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Serializes the BlockTxResponse object into a Buffer
|
|
68
|
+
* @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
|
|
69
|
+
* thus we serialize it last
|
|
70
|
+
* @returns Buffer representation of the BlockTxResponse object
|
|
71
|
+
*/
|
|
72
|
+
toBuffer(): Buffer {
|
|
73
|
+
return serializeToBuffer([this.blockHash, this.txs.toBuffer(), this.txIndices.toBuffer()]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static empty(): BlockTxsResponse {
|
|
77
|
+
return new BlockTxsResponse(Fr.ZERO, new TxArray(), BitVector.init(0, []));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -2,7 +2,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
|
|
3
3
|
import type { PeerId } from '@libp2p/interface';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { PeerManagerInterface } from '../../peer-manager/interface.js';
|
|
6
6
|
import { ReqRespSubProtocol, type ReqRespSubProtocolHandler } from '../interface.js';
|
|
7
7
|
import type { ReqResp } from '../reqresp.js';
|
|
8
8
|
|
|
@@ -34,7 +34,7 @@ export function decodeGoodbyeReason(buffer: Buffer): GoodByeReason {
|
|
|
34
34
|
throw new Error('Invalid goodbye reason buffer length');
|
|
35
35
|
}
|
|
36
36
|
return buffer[0] as GoodByeReason;
|
|
37
|
-
} catch
|
|
37
|
+
} catch {
|
|
38
38
|
return GoodByeReason.UNKNOWN;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -89,13 +89,15 @@ export class GoodbyeProtocolHandler {
|
|
|
89
89
|
* @param peerManager - The peer manager.
|
|
90
90
|
* @returns A resolved promise with the goodbye response.
|
|
91
91
|
*/
|
|
92
|
-
export function reqGoodbyeHandler(peerManager:
|
|
93
|
-
return (peerId: PeerId,
|
|
94
|
-
const reason = decodeGoodbyeReason(
|
|
92
|
+
export function reqGoodbyeHandler(peerManager: PeerManagerInterface): ReqRespSubProtocolHandler {
|
|
93
|
+
return (peerId: PeerId, msg: Buffer) => {
|
|
94
|
+
const reason = decodeGoodbyeReason(msg);
|
|
95
95
|
|
|
96
96
|
peerManager.goodbyeReceived(peerId, reason);
|
|
97
97
|
|
|
98
|
-
//
|
|
99
|
-
|
|
98
|
+
// NOTE: In the current implementation this won't be sent to peer,
|
|
99
|
+
// as the connection to peer has been already closed by peerManager.goodbyeReceived
|
|
100
|
+
// We have this just to satisfy interface
|
|
101
|
+
return Promise.resolve(Buffer.alloc(0));
|
|
100
102
|
};
|
|
101
103
|
}
|