@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.24de95ac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -9
- package/dest/client/factory.d.ts +13 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -24
- package/dest/client/index.d.ts +1 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +155 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +72 -169
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +365 -174
- package/dest/config.d.ts +123 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +173 -34
- package/dest/enr/generate-enr.d.ts +10 -2
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/index.d.ts +3 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +42 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +204 -54
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +93 -15
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +86 -18
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +9 -15
- package/dest/mem_pools/instrumentation.d.ts +7 -11
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +25 -37
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +93 -9
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +33 -9
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +64 -8
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +61 -12
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +56 -86
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
- package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +74 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
- package/dest/msg_validators/tx_validator/index.d.ts +7 -0
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +7 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +7 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +91 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
- package/dest/services/discv5/discV5_service.d.ts +9 -8
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +63 -36
- package/dest/services/dummy_service.d.ts +49 -10
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +25 -6
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +73 -5
- package/dest/services/index.d.ts +4 -0
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +18 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +157 -0
- package/dest/services/libp2p/libp2p_service.d.ts +87 -42
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +500 -218
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +11 -2
- package/dest/services/peer-manager/peer_manager.d.ts +126 -15
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +547 -72
- package/dest/services/reqresp/config.d.ts +10 -8
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +30 -13
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
- package/dest/services/reqresp/index.d.ts +2 -1
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +72 -23
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +45 -26
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +5 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +28 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +2 -4
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +2 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +0 -2
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +38 -6
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +72 -5
- package/dest/services/reqresp/protocols/tx.d.ts +12 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +4 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +45 -47
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +298 -207
- package/dest/services/reqresp/status.d.ts +9 -3
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +22 -18
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +58 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +300 -0
- package/dest/services/tx_collection/index.d.ts +3 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +2 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +34 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +176 -0
- package/dest/services/tx_collection/tx_collection.d.ts +110 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +128 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +111 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +49 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +210 -0
- package/dest/services/tx_provider_instrumentation.d.ts +13 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +1 -0
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +1 -0
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +32 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -16
- package/dest/test-helpers/mock-pubsub.d.ts +59 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +130 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +14 -10
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +62 -28
- package/dest/testbench/p2p_client_testbench_worker.js +96 -25
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +0 -5
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +11 -19
- package/dest/types/index.d.ts +3 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +22 -15
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +64 -67
- package/dest/versioning.d.ts +3 -3
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +28 -24
- package/src/bootstrap/bootstrap.ts +27 -11
- package/src/client/factory.ts +136 -45
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +195 -0
- package/src/client/p2p_client.ts +460 -327
- package/src/config.ts +288 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +48 -4
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -55
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +117 -20
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +114 -22
- package/src/mem_pools/attestation_pool/mocks.ts +11 -10
- package/src/mem_pools/instrumentation.ts +32 -46
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
- package/src/msg_validators/attestation_validator/attestation_validator.ts +55 -10
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +66 -14
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
- package/src/msg_validators/tx_validator/data_validator.ts +81 -69
- package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
- package/src/msg_validators/tx_validator/factory.ts +109 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
- package/src/msg_validators/tx_validator/index.ts +7 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
- package/src/msg_validators/tx_validator/phases_validator.ts +114 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
- package/src/services/discv5/discV5_service.ts +84 -38
- package/src/services/dummy_service.ts +147 -9
- package/src/services/encoding.ts +80 -5
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +158 -0
- package/src/services/libp2p/libp2p_service.ts +646 -263
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +16 -1
- package/src/services/peer-manager/peer_manager.ts +652 -78
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +91 -36
- package/src/services/reqresp/metrics.ts +4 -1
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +24 -3
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +9 -7
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +117 -5
- package/src/services/reqresp/protocols/tx.ts +35 -6
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +387 -256
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +45 -21
- package/src/services/tx_collection/config.ts +84 -0
- package/src/services/tx_collection/fast_tx_collection.ts +340 -0
- package/src/services/tx_collection/index.ts +2 -0
- package/src/services/tx_collection/instrumentation.ts +43 -0
- package/src/services/tx_collection/slow_tx_collection.ts +232 -0
- package/src/services/tx_collection/tx_collection.ts +215 -0
- package/src/services/tx_collection/tx_collection_sink.ts +129 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +216 -0
- package/src/services/tx_provider_instrumentation.ts +44 -0
- package/src/test-helpers/index.ts +1 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +111 -21
- package/src/test-helpers/mock-pubsub.ts +188 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +86 -35
- package/src/testbench/p2p_client_testbench_worker.ts +145 -22
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +17 -23
- package/src/types/index.ts +2 -0
- package/src/util.ts +93 -89
- package/src/versioning.ts +11 -4
|
@@ -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
|
}
|
|
@@ -1,8 +1,120 @@
|
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
import { bufferToHex } from '@aztec/foundation/string';
|
|
5
|
+
import type { WorldStateSyncStatus, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
|
|
7
|
+
import type { PeerId } from '@libp2p/interface';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* P2P Status Message
|
|
11
|
+
* It is used to establish Status handshake between to peers
|
|
12
|
+
* By validating Status handshake we ensure peers are on the same Blockchain fork
|
|
13
|
+
* And get peer sync status
|
|
14
|
+
*/
|
|
15
|
+
export class StatusMessage {
|
|
16
|
+
constructor(
|
|
17
|
+
readonly compressedComponentsVersion: string,
|
|
18
|
+
readonly latestBlockNumber: number,
|
|
19
|
+
readonly latestBlockHash: string,
|
|
20
|
+
readonly finalizedBlockNumber: number,
|
|
21
|
+
//TODO: add finalizedBlockHash
|
|
22
|
+
//readonly finalizedBlockHash: string,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Deserializes the StatusMessage object from a Buffer.
|
|
27
|
+
* @param buffer - Buffer or BufferReader object to deserialize.
|
|
28
|
+
* @returns An instance of StatusMessage.
|
|
29
|
+
*/
|
|
30
|
+
static fromBuffer(buffer: Buffer | BufferReader): StatusMessage {
|
|
31
|
+
const reader = BufferReader.asReader(buffer);
|
|
32
|
+
return new StatusMessage(
|
|
33
|
+
reader.readString(), // compressedComponentsVersion
|
|
34
|
+
reader.readNumber(), // latestBlockNumber
|
|
35
|
+
reader.readString(), // latestBlockHash
|
|
36
|
+
reader.readNumber(), // finalizedBlockNumber
|
|
37
|
+
//TODO: add finalizedBlockHash
|
|
38
|
+
//reader.readString(), // finalizedBlockHash
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Serializes the StatusMessage object into a Buffer.
|
|
44
|
+
* @returns Buffer representation of the StatusMessage object.
|
|
45
|
+
*/
|
|
46
|
+
toBuffer() {
|
|
47
|
+
return serializeToBuffer([
|
|
48
|
+
this.compressedComponentsVersion,
|
|
49
|
+
this.latestBlockNumber,
|
|
50
|
+
this.latestBlockHash,
|
|
51
|
+
this.finalizedBlockNumber,
|
|
52
|
+
//TODO: add finalizedBlockHash
|
|
53
|
+
// this.finalizedBlockHash,
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Builds Status message
|
|
59
|
+
* @param version - Compressed Components Version
|
|
60
|
+
* @param worldStateSyncStatus - Info about the current sync status
|
|
61
|
+
* @returns StatusMessage instance
|
|
62
|
+
*/
|
|
63
|
+
static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage {
|
|
64
|
+
return new StatusMessage(
|
|
65
|
+
version,
|
|
66
|
+
syncStatus.latestBlockNumber,
|
|
67
|
+
syncStatus.latestBlockHash,
|
|
68
|
+
syncStatus.finalizedBlockNumber,
|
|
69
|
+
//TODO: add finalizedBlockHash
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static random(): StatusMessage {
|
|
74
|
+
return new StatusMessage(
|
|
75
|
+
'1.0.0',
|
|
76
|
+
Math.floor(Math.random() * 100),
|
|
77
|
+
Buffer32.random().toString(),
|
|
78
|
+
Math.floor(Math.random() * 100),
|
|
79
|
+
//TODO: add finalizedBlockHash
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
validate(peerStatus: StatusMessage): boolean {
|
|
84
|
+
// TODO: Validate other fields as well
|
|
85
|
+
return this.compressedComponentsVersion === peerStatus.compressedComponentsVersion;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
equals(other: StatusMessage): boolean {
|
|
89
|
+
return (
|
|
90
|
+
this.compressedComponentsVersion === other.compressedComponentsVersion &&
|
|
91
|
+
this.latestBlockNumber === other.latestBlockNumber &&
|
|
92
|
+
this.latestBlockHash === other.latestBlockHash &&
|
|
93
|
+
this.finalizedBlockNumber === other.finalizedBlockNumber
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
1
98
|
/**
|
|
2
|
-
* Handles the status request.
|
|
3
|
-
* @param
|
|
4
|
-
* @
|
|
99
|
+
* Handles the status request. By immediately responding with the current node status.
|
|
100
|
+
* @param compressedComponentsVersion - Compressed Components Version
|
|
101
|
+
* @param worldStateSynchronizer - World State Synchronizer to fetch the sync status from.
|
|
102
|
+
* Note the WorldStateSynchronizer must be injected to fetch the fresh sync status, we cannot pass in pre-built StatusMessage.
|
|
103
|
+
* @returns Status message handler
|
|
5
104
|
*/
|
|
6
|
-
export function
|
|
7
|
-
|
|
105
|
+
export function reqRespStatusHandler(
|
|
106
|
+
compressedComponentsVersion: string,
|
|
107
|
+
worldStateSynchronizer: WorldStateSynchronizer,
|
|
108
|
+
logger?: Logger,
|
|
109
|
+
) {
|
|
110
|
+
return async (peerId: PeerId, _msg: Buffer) => {
|
|
111
|
+
logger?.trace(`Received status handshake request from ${peerId}`);
|
|
112
|
+
const status = StatusMessage.fromWorldStateSyncStatus(
|
|
113
|
+
compressedComponentsVersion,
|
|
114
|
+
(await worldStateSynchronizer.status()).syncSummary,
|
|
115
|
+
);
|
|
116
|
+
const response = status.toBuffer();
|
|
117
|
+
logger?.trace(`Responding status handshake from ${peerId}`, { data: bufferToHex(response) });
|
|
118
|
+
return response;
|
|
119
|
+
};
|
|
8
120
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { chunk } from '@aztec/foundation/collection';
|
|
1
2
|
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
2
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
3
4
|
|
|
4
5
|
import type { PeerId } from '@libp2p/interface';
|
|
5
6
|
|
|
6
7
|
import type { MemPools } from '../../../mem_pools/interface.js';
|
|
7
8
|
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
9
|
+
import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* We want to keep the logic of the req resp handler in this file, but we do not have a reference to the mempools here
|
|
@@ -12,18 +14,45 @@ import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
|
12
14
|
*
|
|
13
15
|
* Handler for tx requests
|
|
14
16
|
* @param mempools - the mempools
|
|
15
|
-
* @returns the
|
|
17
|
+
* @returns the Tx request handler
|
|
16
18
|
*/
|
|
17
19
|
export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>): ReqRespSubProtocolHandler {
|
|
18
20
|
/**
|
|
19
21
|
* Handler for tx requests
|
|
20
22
|
* @param msg - the tx request message
|
|
21
23
|
* @returns the tx response message
|
|
24
|
+
* @throws if msg is not a valid tx hash
|
|
22
25
|
*/
|
|
23
26
|
return async (_peerId: PeerId, msg: Buffer) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
let txHashes: TxHashArray;
|
|
28
|
+
try {
|
|
29
|
+
txHashes = TxHashArray.fromBuffer(msg);
|
|
30
|
+
} catch (err: any) {
|
|
31
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const txs = new TxArray(
|
|
36
|
+
...(await Promise.all(txHashes.map(txHash => mempools.txPool.getTxByHash(txHash)))).filter(t => !!t),
|
|
37
|
+
);
|
|
38
|
+
return txs.toBuffer();
|
|
39
|
+
} catch (err: any) {
|
|
40
|
+
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
|
|
41
|
+
}
|
|
28
42
|
};
|
|
29
43
|
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Helper function to chunk an array of transaction hashes into chunks of a specified size.
|
|
47
|
+
* This is mainly used in ReqResp in order not to request too many transactions at once from the single peer.
|
|
48
|
+
*
|
|
49
|
+
* @param hashes - The array of transaction hashes to chunk.
|
|
50
|
+
* @param chunkSize - The size of each chunk. Default is 8. Reasoning:
|
|
51
|
+
* Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
|
|
52
|
+
* we define Q as max number of transactions per batch, the comment explains why we use 8.
|
|
53
|
+
*/
|
|
54
|
+
//TODO: (mralj) chunk size should by default be 8, this is just temporary until the protocol is implemented correctly
|
|
55
|
+
//more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
|
|
56
|
+
export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
|
|
57
|
+
return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
|
|
58
|
+
}
|
|
@@ -8,7 +8,7 @@ import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
|
8
8
|
import type { PeerId } from '@libp2p/interface';
|
|
9
9
|
|
|
10
10
|
import type { PeerScoring } from '../../peer-manager/peer_scoring.js';
|
|
11
|
-
import type { ReqRespSubProtocol, ReqRespSubProtocolRateLimits } from '../interface.js';
|
|
11
|
+
import type { ProtocolRateLimitQuota, ReqRespSubProtocol, ReqRespSubProtocolRateLimits } from '../interface.js';
|
|
12
12
|
import { DEFAULT_RATE_LIMITS } from './rate_limits.js';
|
|
13
13
|
|
|
14
14
|
// Check for disconnected peers every 10 minutes
|
|
@@ -177,13 +177,18 @@ export class SubProtocolRateLimiter {
|
|
|
177
177
|
*/
|
|
178
178
|
export class RequestResponseRateLimiter {
|
|
179
179
|
private subProtocolRateLimiters: Map<ReqRespSubProtocol, SubProtocolRateLimiter>;
|
|
180
|
+
private rateLimits: ReqRespSubProtocolRateLimits;
|
|
180
181
|
|
|
181
182
|
private cleanupInterval: NodeJS.Timeout | undefined = undefined;
|
|
182
183
|
|
|
183
|
-
constructor(
|
|
184
|
+
constructor(
|
|
185
|
+
private peerScoring: PeerScoring,
|
|
186
|
+
rateLimits: Partial<ReqRespSubProtocolRateLimits> = {},
|
|
187
|
+
) {
|
|
184
188
|
this.subProtocolRateLimiters = new Map();
|
|
185
189
|
|
|
186
|
-
|
|
190
|
+
this.rateLimits = { ...DEFAULT_RATE_LIMITS, ...rateLimits };
|
|
191
|
+
for (const [subProtocol, protocolLimits] of Object.entries(this.rateLimits)) {
|
|
187
192
|
this.subProtocolRateLimiters.set(
|
|
188
193
|
subProtocol as ReqRespSubProtocol,
|
|
189
194
|
new SubProtocolRateLimiter(
|
|
@@ -225,4 +230,8 @@ export class RequestResponseRateLimiter {
|
|
|
225
230
|
stop() {
|
|
226
231
|
clearInterval(this.cleanupInterval);
|
|
227
232
|
}
|
|
233
|
+
|
|
234
|
+
getRateLimits(protocol: ReqRespSubProtocol): ProtocolRateLimitQuota {
|
|
235
|
+
return this.rateLimits[protocol];
|
|
236
|
+
}
|
|
228
237
|
}
|
|
@@ -22,6 +22,16 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
22
22
|
quotaCount: 10,
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
+
[ReqRespSubProtocol.AUTH]: {
|
|
26
|
+
peerLimit: {
|
|
27
|
+
quotaTimeMs: 1000,
|
|
28
|
+
quotaCount: 5,
|
|
29
|
+
},
|
|
30
|
+
globalLimit: {
|
|
31
|
+
quotaTimeMs: 1000,
|
|
32
|
+
quotaCount: 10,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
25
35
|
[ReqRespSubProtocol.TX]: {
|
|
26
36
|
peerLimit: {
|
|
27
37
|
quotaTimeMs: 1000,
|
|
@@ -29,7 +39,7 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
29
39
|
},
|
|
30
40
|
globalLimit: {
|
|
31
41
|
quotaTimeMs: 1000,
|
|
32
|
-
quotaCount:
|
|
42
|
+
quotaCount: 200,
|
|
33
43
|
},
|
|
34
44
|
},
|
|
35
45
|
[ReqRespSubProtocol.BLOCK]: {
|
|
@@ -52,4 +62,14 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
52
62
|
quotaCount: 10,
|
|
53
63
|
},
|
|
54
64
|
},
|
|
65
|
+
[ReqRespSubProtocol.BLOCK_TXS]: {
|
|
66
|
+
peerLimit: {
|
|
67
|
+
quotaTimeMs: 1000,
|
|
68
|
+
quotaCount: 10,
|
|
69
|
+
},
|
|
70
|
+
globalLimit: {
|
|
71
|
+
quotaTimeMs: 1000,
|
|
72
|
+
quotaCount: 200,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
55
75
|
};
|