@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
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
3
|
+
import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
|
|
3
4
|
import type { PeerId } from '@libp2p/interface';
|
|
5
|
+
import type { P2PReqRespConfig } from './config.js';
|
|
6
|
+
import { AuthRequest, AuthResponse } from './protocols/auth.js';
|
|
7
|
+
import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
|
|
8
|
+
import { StatusMessage } from './protocols/status.js';
|
|
4
9
|
import type { ReqRespStatus } from './status.js';
|
|
5
|
-
export declare const PING_PROTOCOL = "/aztec/req/ping/
|
|
6
|
-
export declare const STATUS_PROTOCOL = "/aztec/req/status/
|
|
7
|
-
export declare const GOODBYE_PROTOCOL = "/aztec/req/goodbye/
|
|
8
|
-
export declare const TX_REQ_PROTOCOL = "/aztec/req/tx/
|
|
9
|
-
export declare const BLOCK_REQ_PROTOCOL = "/aztec/req/block/
|
|
10
|
+
export declare const PING_PROTOCOL = "/aztec/req/ping/1.0.0";
|
|
11
|
+
export declare const STATUS_PROTOCOL = "/aztec/req/status/1.0.0";
|
|
12
|
+
export declare const GOODBYE_PROTOCOL = "/aztec/req/goodbye/1.0.0";
|
|
13
|
+
export declare const TX_REQ_PROTOCOL = "/aztec/req/tx/1.0.0";
|
|
14
|
+
export declare const BLOCK_REQ_PROTOCOL = "/aztec/req/block/1.0.0";
|
|
15
|
+
export declare const AUTH_PROTOCOL = "/aztec/req/auth/1.0.0";
|
|
16
|
+
export declare const BLOCK_TXS_REQ_PROTOCOL = "/aztec/req/block_txs/1.0.0";
|
|
10
17
|
export declare enum ReqRespSubProtocol {
|
|
11
|
-
PING = "/aztec/req/ping/
|
|
12
|
-
STATUS = "/aztec/req/status/
|
|
13
|
-
GOODBYE = "/aztec/req/goodbye/
|
|
14
|
-
TX = "/aztec/req/tx/
|
|
15
|
-
BLOCK = "/aztec/req/block/
|
|
18
|
+
PING = "/aztec/req/ping/1.0.0",
|
|
19
|
+
STATUS = "/aztec/req/status/1.0.0",
|
|
20
|
+
GOODBYE = "/aztec/req/goodbye/1.0.0",
|
|
21
|
+
TX = "/aztec/req/tx/1.0.0",
|
|
22
|
+
BLOCK = "/aztec/req/block/1.0.0",
|
|
23
|
+
AUTH = "/aztec/req/auth/1.0.0",
|
|
24
|
+
BLOCK_TXS = "/aztec/req/block_txs/1.0.0"
|
|
16
25
|
}
|
|
17
26
|
/**
|
|
18
27
|
* A handler for a sub protocol
|
|
@@ -25,12 +34,15 @@ export type ReqRespSubProtocolHandler = (peerId: PeerId, msg: Buffer) => Promise
|
|
|
25
34
|
export type ReqRespSubProtocolRateLimits = Record<ReqRespSubProtocol, ProtocolRateLimitQuota>;
|
|
26
35
|
/**
|
|
27
36
|
* The response from the ReqResp protocol
|
|
28
|
-
* Consists of a status
|
|
37
|
+
* Consists of a status
|
|
38
|
+
* And, optionally, a data buffer (in case status is SUCCESS)
|
|
29
39
|
*/
|
|
30
|
-
export
|
|
31
|
-
status: ReqRespStatus;
|
|
40
|
+
export type ReqRespResponse = {
|
|
41
|
+
status: ReqRespStatus.SUCCESS;
|
|
32
42
|
data: Buffer;
|
|
33
|
-
}
|
|
43
|
+
} | {
|
|
44
|
+
status: Exclude<ReqRespStatus, ReqRespStatus.SUCCESS>;
|
|
45
|
+
};
|
|
34
46
|
/**
|
|
35
47
|
* A rate limit quota
|
|
36
48
|
*/
|
|
@@ -64,17 +76,16 @@ export type ReqRespSubProtocolValidators = {
|
|
|
64
76
|
[S in ReqRespSubProtocol]: ResponseValidator<any, any>;
|
|
65
77
|
};
|
|
66
78
|
export declare const DEFAULT_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators;
|
|
79
|
+
export declare class ValidationError extends Error {
|
|
80
|
+
constructor(message: string);
|
|
81
|
+
}
|
|
67
82
|
/**
|
|
68
83
|
* Sub protocol map determines the request and response types for each
|
|
69
84
|
* Req Resp protocol
|
|
70
85
|
*/
|
|
71
86
|
export type SubProtocolMap = {
|
|
72
|
-
[S in ReqRespSubProtocol]: RequestResponsePair<
|
|
87
|
+
[S in ReqRespSubProtocol]: RequestResponsePair<InstanceType<(typeof subProtocolMap)[S]['request']>, InstanceType<(typeof subProtocolMap)[S]['response']>>;
|
|
73
88
|
};
|
|
74
|
-
/**
|
|
75
|
-
* Default sub protocol handlers - this SHOULD be overwritten by the service,
|
|
76
|
-
*/
|
|
77
|
-
export declare const DEFAULT_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers;
|
|
78
89
|
/**
|
|
79
90
|
* The Request Response Pair interface defines the methods that each
|
|
80
91
|
* request response pair must implement
|
|
@@ -94,6 +105,7 @@ interface RequestResponsePair<Req extends {
|
|
|
94
105
|
fromBuffer(buffer: Buffer): Res;
|
|
95
106
|
};
|
|
96
107
|
}
|
|
108
|
+
export declare function responseFromBuffer<P extends ReqRespSubProtocol>(proto: P, buffer: Buffer): InstanceType<(typeof subProtocolMap)[P]['response']>;
|
|
97
109
|
/**
|
|
98
110
|
* RequestableBuffer is a wrapper around a buffer that allows it to be
|
|
99
111
|
* used in generic request response protocols
|
|
@@ -103,7 +115,7 @@ interface RequestResponsePair<Req extends {
|
|
|
103
115
|
export declare class RequestableBuffer {
|
|
104
116
|
buffer: Buffer;
|
|
105
117
|
constructor(buffer: Buffer);
|
|
106
|
-
toBuffer(): Buffer
|
|
118
|
+
toBuffer(): Buffer<ArrayBufferLike>;
|
|
107
119
|
static fromBuffer(buffer: Buffer): RequestableBuffer;
|
|
108
120
|
}
|
|
109
121
|
/**
|
|
@@ -111,6 +123,43 @@ export declare class RequestableBuffer {
|
|
|
111
123
|
* This defines the request and response types for each sub protocol, used primarily
|
|
112
124
|
* as a type rather than an object
|
|
113
125
|
*/
|
|
114
|
-
export declare const subProtocolMap:
|
|
126
|
+
export declare const subProtocolMap: {
|
|
127
|
+
"/aztec/req/ping/1.0.0": {
|
|
128
|
+
request: typeof RequestableBuffer;
|
|
129
|
+
response: typeof RequestableBuffer;
|
|
130
|
+
};
|
|
131
|
+
"/aztec/req/status/1.0.0": {
|
|
132
|
+
request: typeof StatusMessage;
|
|
133
|
+
response: typeof StatusMessage;
|
|
134
|
+
};
|
|
135
|
+
"/aztec/req/tx/1.0.0": {
|
|
136
|
+
request: typeof TxHashArray;
|
|
137
|
+
response: typeof TxArray;
|
|
138
|
+
};
|
|
139
|
+
"/aztec/req/goodbye/1.0.0": {
|
|
140
|
+
request: typeof RequestableBuffer;
|
|
141
|
+
response: typeof RequestableBuffer;
|
|
142
|
+
};
|
|
143
|
+
"/aztec/req/block/1.0.0": {
|
|
144
|
+
request: typeof Fr;
|
|
145
|
+
response: typeof L2Block;
|
|
146
|
+
};
|
|
147
|
+
"/aztec/req/auth/1.0.0": {
|
|
148
|
+
request: typeof AuthRequest;
|
|
149
|
+
response: typeof AuthResponse;
|
|
150
|
+
};
|
|
151
|
+
"/aztec/req/block_txs/1.0.0": {
|
|
152
|
+
request: typeof BlockTxsRequest;
|
|
153
|
+
response: typeof BlockTxsResponse;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
export interface ReqRespInterface {
|
|
157
|
+
start(subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>, subProtocolValidators: ReqRespSubProtocolValidators): Promise<void>;
|
|
158
|
+
addSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler, validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol]): Promise<void>;
|
|
159
|
+
stop(): Promise<void>;
|
|
160
|
+
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(subProtocol: SubProtocol, requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[], pinnedPeer: PeerId | undefined, timeoutMs?: number, maxPeers?: number, maxRetryAttempts?: number): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
|
|
161
|
+
sendRequestToPeer(peerId: PeerId, subProtocol: ReqRespSubProtocol, payload: Buffer, dialTimeout?: number): Promise<ReqRespResponse>;
|
|
162
|
+
updateConfig(config: Partial<P2PReqRespConfig>): void;
|
|
163
|
+
}
|
|
115
164
|
export {};
|
|
116
165
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/interface.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,19 +1,26 @@
|
|
|
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
|
+
import { AuthRequest, AuthResponse } from './protocols/auth.js';
|
|
5
|
+
import { BlockTxsRequest, BlockTxsResponse } from './protocols/block_txs/block_txs_reqresp.js';
|
|
6
|
+
import { StatusMessage } from './protocols/status.js';
|
|
4
7
|
/*
|
|
5
8
|
* Request Response Sub Protocols
|
|
6
|
-
*/ export const PING_PROTOCOL = '/aztec/req/ping/
|
|
7
|
-
export const STATUS_PROTOCOL = '/aztec/req/status/
|
|
8
|
-
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/
|
|
9
|
-
export const TX_REQ_PROTOCOL = '/aztec/req/tx/
|
|
10
|
-
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/
|
|
9
|
+
*/ export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
|
|
10
|
+
export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
|
|
11
|
+
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
|
|
12
|
+
export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
|
|
13
|
+
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
|
|
14
|
+
export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
|
|
15
|
+
export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
|
|
11
16
|
export var ReqRespSubProtocol = /*#__PURE__*/ function(ReqRespSubProtocol) {
|
|
12
17
|
ReqRespSubProtocol[ReqRespSubProtocol["PING"] = PING_PROTOCOL] = "PING";
|
|
13
18
|
ReqRespSubProtocol[ReqRespSubProtocol["STATUS"] = STATUS_PROTOCOL] = "STATUS";
|
|
14
19
|
ReqRespSubProtocol[ReqRespSubProtocol["GOODBYE"] = GOODBYE_PROTOCOL] = "GOODBYE";
|
|
15
20
|
ReqRespSubProtocol[ReqRespSubProtocol["TX"] = TX_REQ_PROTOCOL] = "TX";
|
|
16
21
|
ReqRespSubProtocol[ReqRespSubProtocol["BLOCK"] = BLOCK_REQ_PROTOCOL] = "BLOCK";
|
|
22
|
+
ReqRespSubProtocol[ReqRespSubProtocol["AUTH"] = AUTH_PROTOCOL] = "AUTH";
|
|
23
|
+
ReqRespSubProtocol[ReqRespSubProtocol["BLOCK_TXS"] = BLOCK_TXS_REQ_PROTOCOL] = "BLOCK_TXS";
|
|
17
24
|
return ReqRespSubProtocol;
|
|
18
25
|
}({});
|
|
19
26
|
export const noopValidator = ()=>Promise.resolve(true);
|
|
@@ -22,23 +29,27 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS = {
|
|
|
22
29
|
[ReqRespSubProtocol.STATUS]: noopValidator,
|
|
23
30
|
[ReqRespSubProtocol.TX]: noopValidator,
|
|
24
31
|
[ReqRespSubProtocol.GOODBYE]: noopValidator,
|
|
25
|
-
[ReqRespSubProtocol.BLOCK]: noopValidator
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* Default handler for unimplemented sub protocols, this SHOULD be overwritten
|
|
29
|
-
* by the service, but is provided as a fallback
|
|
30
|
-
*/ const defaultHandler = (_msg)=>{
|
|
31
|
-
return Promise.resolve(Buffer.from('unimplemented'));
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Default sub protocol handlers - this SHOULD be overwritten by the service,
|
|
35
|
-
*/ export const DEFAULT_SUB_PROTOCOL_HANDLERS = {
|
|
36
|
-
[ReqRespSubProtocol.PING]: defaultHandler,
|
|
37
|
-
[ReqRespSubProtocol.STATUS]: defaultHandler,
|
|
38
|
-
[ReqRespSubProtocol.TX]: defaultHandler,
|
|
39
|
-
[ReqRespSubProtocol.GOODBYE]: defaultHandler,
|
|
40
|
-
[ReqRespSubProtocol.BLOCK]: defaultHandler
|
|
32
|
+
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
33
|
+
[ReqRespSubProtocol.AUTH]: noopValidator,
|
|
34
|
+
[ReqRespSubProtocol.BLOCK_TXS]: noopValidator
|
|
41
35
|
};
|
|
36
|
+
/*
|
|
37
|
+
* Helper class to sub-protocol validation error*/ export class ValidationError extends Error {
|
|
38
|
+
constructor(message){
|
|
39
|
+
super(message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/*
|
|
43
|
+
* Small helper function which parses buffer into specific response type
|
|
44
|
+
* It is needed to make TypeScript happy, as it cannot infer the type from the buffer
|
|
45
|
+
*
|
|
46
|
+
* @param proto - The sub protocol to parse the response for
|
|
47
|
+
* @param buffer - The buffer to parse
|
|
48
|
+
*
|
|
49
|
+
* @returns - The parsed response object
|
|
50
|
+
* */ export function responseFromBuffer(proto, buffer) {
|
|
51
|
+
return subProtocolMap[proto].response.fromBuffer(buffer);
|
|
52
|
+
}
|
|
42
53
|
/**
|
|
43
54
|
* RequestableBuffer is a wrapper around a buffer that allows it to be
|
|
44
55
|
* used in generic request response protocols
|
|
@@ -66,12 +77,12 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS = {
|
|
|
66
77
|
response: RequestableBuffer
|
|
67
78
|
},
|
|
68
79
|
[ReqRespSubProtocol.STATUS]: {
|
|
69
|
-
request:
|
|
70
|
-
response:
|
|
80
|
+
request: StatusMessage,
|
|
81
|
+
response: StatusMessage
|
|
71
82
|
},
|
|
72
83
|
[ReqRespSubProtocol.TX]: {
|
|
73
|
-
request:
|
|
74
|
-
response:
|
|
84
|
+
request: TxHashArray,
|
|
85
|
+
response: TxArray
|
|
75
86
|
},
|
|
76
87
|
[ReqRespSubProtocol.GOODBYE]: {
|
|
77
88
|
request: RequestableBuffer,
|
|
@@ -80,5 +91,13 @@ export const DEFAULT_SUB_PROTOCOL_VALIDATORS = {
|
|
|
80
91
|
[ReqRespSubProtocol.BLOCK]: {
|
|
81
92
|
request: Fr,
|
|
82
93
|
response: L2Block
|
|
94
|
+
},
|
|
95
|
+
[ReqRespSubProtocol.AUTH]: {
|
|
96
|
+
request: AuthRequest,
|
|
97
|
+
response: AuthResponse
|
|
98
|
+
},
|
|
99
|
+
[ReqRespSubProtocol.BLOCK_TXS]: {
|
|
100
|
+
request: BlockTxsRequest,
|
|
101
|
+
response: BlockTxsResponse
|
|
83
102
|
}
|
|
84
103
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAiB,MAAM,yBAAyB,CAAC;AAEtF,qBAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAiB,MAAM,yBAAyB,CAAC;AAEtF,qBAAa,cAAc;IAUvB,QAAQ,CAAC,eAAe,EAAE,eAAe;IAT3C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAC7C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IAEjD,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAgB;IACvD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAgB;gBAG3C,eAAe,EAAE,eAAe,EACzC,IAAI,SAAY;IA6BX,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAIlC,qBAAqB,CAAC,QAAQ,EAAE,MAAM;IAItC,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAInC,mBAAmB,CAAC,QAAQ,EAAE,MAAM;CAG5C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
5
|
+
import { StatusMessage } from './status.js';
|
|
6
|
+
export declare const VALIDATOR_AUTH_DOMAIN_SEPARATOR = "Aztec Validator Challenge:";
|
|
7
|
+
export declare const VALIDATOR_AUTH_FULL_CHALLENGE_ENCODED_LENGTH: number;
|
|
8
|
+
export declare class AuthRequest {
|
|
9
|
+
readonly status: StatusMessage;
|
|
10
|
+
readonly challenge: Fr;
|
|
11
|
+
constructor(status: StatusMessage, challenge: Fr);
|
|
12
|
+
/**
|
|
13
|
+
* Deserializes the AuthRequest object from a Buffer.
|
|
14
|
+
* @param buffer - Buffer or BufferReader object to deserialize.
|
|
15
|
+
* @returns An instance of StatusMessage.
|
|
16
|
+
*/
|
|
17
|
+
static fromBuffer(buffer: Buffer | BufferReader): AuthRequest;
|
|
18
|
+
/**
|
|
19
|
+
* Serializes the AuthRequest object into a Buffer.
|
|
20
|
+
* @returns Buffer representation of the StatusMessage object.
|
|
21
|
+
*/
|
|
22
|
+
toBuffer(): Buffer<ArrayBufferLike>;
|
|
23
|
+
getPayloadToSign(): Buffer32;
|
|
24
|
+
static random(): AuthRequest;
|
|
25
|
+
}
|
|
26
|
+
export declare class AuthResponse {
|
|
27
|
+
readonly status: StatusMessage;
|
|
28
|
+
readonly signature: Signature;
|
|
29
|
+
constructor(status: StatusMessage, signature: Signature);
|
|
30
|
+
/**
|
|
31
|
+
* Deserializes the AuthResponse object from a Buffer.
|
|
32
|
+
* @param buffer - Buffer or BufferReader object to deserialize.
|
|
33
|
+
* @returns An instance of StatusMessage.
|
|
34
|
+
*/
|
|
35
|
+
static fromBuffer(buffer: Buffer | BufferReader): AuthResponse;
|
|
36
|
+
/**
|
|
37
|
+
* Serializes the AuthRequest object into a Buffer.
|
|
38
|
+
* @returns Buffer representation of the StatusMessage object.
|
|
39
|
+
*/
|
|
40
|
+
toBuffer(): Buffer<ArrayBufferLike>;
|
|
41
|
+
static random(): AuthResponse;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,eAAO,MAAM,+BAA+B,+BAA+B,CAAC;AAC5E,eAAO,MAAM,4CAA4C,QACe,CAAC;AAMzE,qBAAa,WAAW;IAEpB,QAAQ,CAAC,MAAM,EAAE,aAAa;IAC9B,QAAQ,CAAC,SAAS,EAAE,EAAE;gBADb,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,EAAE;IAGxB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,WAAW;IAQ7D;;;OAGG;IACH,QAAQ;IAIR,gBAAgB,IAAI,QAAQ;IAK5B,MAAM,CAAC,MAAM,IAAI,WAAW;CAG7B;AAED,qBAAa,YAAY;IAErB,QAAQ,CAAC,MAAM,EAAE,aAAa;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS;gBADpB,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,SAAS;IAE/B;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,YAAY;IAQ9D;;;OAGG;IACH,QAAQ;IAIR,MAAM,CAAC,MAAM,IAAI,YAAY;CAG9B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
import { StatusMessage } from './status.js';
|
|
7
|
+
export const VALIDATOR_AUTH_DOMAIN_SEPARATOR = 'Aztec Validator Challenge:';
|
|
8
|
+
export const VALIDATOR_AUTH_FULL_CHALLENGE_ENCODED_LENGTH = VALIDATOR_AUTH_DOMAIN_SEPARATOR.length + Fr.random().toString().length;
|
|
9
|
+
/*
|
|
10
|
+
* P2P Auth Message
|
|
11
|
+
* Superset of the StatusMessage, used to establish a handshake between peers and authenticate them.
|
|
12
|
+
*/ export class AuthRequest {
|
|
13
|
+
status;
|
|
14
|
+
challenge;
|
|
15
|
+
constructor(status, challenge){
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.challenge = challenge;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Deserializes the AuthRequest object from a Buffer.
|
|
21
|
+
* @param buffer - Buffer or BufferReader object to deserialize.
|
|
22
|
+
* @returns An instance of StatusMessage.
|
|
23
|
+
*/ static fromBuffer(buffer) {
|
|
24
|
+
const reader = BufferReader.asReader(buffer);
|
|
25
|
+
return new AuthRequest(StatusMessage.fromBuffer(reader), Fr.fromBuffer(reader));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Serializes the AuthRequest object into a Buffer.
|
|
29
|
+
* @returns Buffer representation of the StatusMessage object.
|
|
30
|
+
*/ toBuffer() {
|
|
31
|
+
return serializeToBuffer([
|
|
32
|
+
this.status,
|
|
33
|
+
this.challenge
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
getPayloadToSign() {
|
|
37
|
+
const fullChallenge = VALIDATOR_AUTH_DOMAIN_SEPARATOR + this.challenge.toString();
|
|
38
|
+
return Buffer32.fromBuffer(keccak256(Buffer.from(fullChallenge, 'utf-8')));
|
|
39
|
+
}
|
|
40
|
+
static random() {
|
|
41
|
+
return new AuthRequest(StatusMessage.random(), Fr.random());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class AuthResponse {
|
|
45
|
+
status;
|
|
46
|
+
signature;
|
|
47
|
+
constructor(status, signature){
|
|
48
|
+
this.status = status;
|
|
49
|
+
this.signature = signature;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Deserializes the AuthResponse object from a Buffer.
|
|
53
|
+
* @param buffer - Buffer or BufferReader object to deserialize.
|
|
54
|
+
* @returns An instance of StatusMessage.
|
|
55
|
+
*/ static fromBuffer(buffer) {
|
|
56
|
+
const reader = BufferReader.asReader(buffer);
|
|
57
|
+
return new AuthResponse(StatusMessage.fromBuffer(reader), Signature.fromBuffer(reader));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Serializes the AuthRequest object into a Buffer.
|
|
61
|
+
* @returns Buffer representation of the StatusMessage object.
|
|
62
|
+
*/ toBuffer() {
|
|
63
|
+
return serializeToBuffer([
|
|
64
|
+
this.status,
|
|
65
|
+
this.signature
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
static random() {
|
|
69
|
+
return new AuthResponse(StatusMessage.random(), Signature.random());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
2
2
|
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handler for L2 Block requests
|
|
5
|
+
* @param l2BlockSource - source for L2 blocks
|
|
6
|
+
* @returns the Block request handler
|
|
7
|
+
* */
|
|
3
8
|
export declare function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubProtocolHandler;
|
|
4
9
|
//# sourceMappingURL=block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/block.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/block.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGjE;;;;KAIK;AACL,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,yBAAyB,CAsB3F"}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handler for L2 Block requests
|
|
5
|
+
* @param l2BlockSource - source for L2 blocks
|
|
6
|
+
* @returns the Block request handler
|
|
7
|
+
* */ export function reqRespBlockHandler(l2BlockSource) {
|
|
8
|
+
/**
|
|
9
|
+
* @param peerId - the peer ID of the requester
|
|
10
|
+
* @param msg - the block request message, which is expected to contain valid block number as a Buffer
|
|
11
|
+
* @returns a Buffer containing the requested block data, or an empty Buffer if the block is not found
|
|
12
|
+
* @throws ReqRespStatusError if the input msg is not a valid block number
|
|
13
|
+
* */ return async (_peerId, msg)=>{
|
|
14
|
+
let blockNumber;
|
|
15
|
+
try {
|
|
16
|
+
blockNumber = Fr.fromBuffer(msg);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, {
|
|
19
|
+
cause: err
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
|
|
24
|
+
return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, {
|
|
27
|
+
cause: err
|
|
28
|
+
});
|
|
29
|
+
}
|
|
7
30
|
};
|
|
8
31
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
2
|
+
/**
|
|
3
|
+
* BitVector helper class for representing and serializing bit vectors
|
|
4
|
+
*/
|
|
5
|
+
export declare class BitVector {
|
|
6
|
+
private buffer;
|
|
7
|
+
private length;
|
|
8
|
+
constructor(buffer: Buffer, length: number);
|
|
9
|
+
static init(length: number, indices: number[]): BitVector;
|
|
10
|
+
getLength(): number;
|
|
11
|
+
isSet(index: number): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Returns all indices which are set to true
|
|
14
|
+
* */
|
|
15
|
+
getTrueIndices(): number[];
|
|
16
|
+
/**
|
|
17
|
+
* Serializes the BitVector object into a Buffer
|
|
18
|
+
*
|
|
19
|
+
* @returns Buffer representation of the BitVector object
|
|
20
|
+
* */
|
|
21
|
+
toBuffer(): Buffer;
|
|
22
|
+
/**
|
|
23
|
+
* Deserializes buffer into new BitVector
|
|
24
|
+
*
|
|
25
|
+
* @returns A new BitVector instance
|
|
26
|
+
* */
|
|
27
|
+
static fromBuffer(buffer: Buffer | BufferReader): BitVector;
|
|
28
|
+
static byteLength(length: number): number;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=bitvector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitvector.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/bitvector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAY1C,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS;IAqBzD,SAAS,IAAI,MAAM;IAWnB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI7B;;SAEK;IACL,cAAc,IAAI,MAAM,EAAE;IAI1B;;;;SAIK;IACL,QAAQ,IAAI,MAAM;IAIlB;;;;SAIK;IACL,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAQ3D,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM;CAGjC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
|
+
/**
|
|
3
|
+
* BitVector helper class for representing and serializing bit vectors
|
|
4
|
+
*/ export class BitVector {
|
|
5
|
+
buffer;
|
|
6
|
+
length;
|
|
7
|
+
constructor(buffer, length){
|
|
8
|
+
this.buffer = buffer;
|
|
9
|
+
this.length = length;
|
|
10
|
+
}
|
|
11
|
+
/*
|
|
12
|
+
* Creates new BitVector instance
|
|
13
|
+
* @param length - Length of the bit vector
|
|
14
|
+
* @param indices - Array of indices to set to 1 in the bit vector
|
|
15
|
+
*
|
|
16
|
+
* @returns A new BitVector instance with specified length and set indices
|
|
17
|
+
* */ static init(length, indices) {
|
|
18
|
+
if (indices.length > length) {
|
|
19
|
+
throw new Error('Indices length exceeds specified length');
|
|
20
|
+
}
|
|
21
|
+
const buffer = Buffer.alloc(BitVector.byteLength(length));
|
|
22
|
+
indices.forEach((idx)=>{
|
|
23
|
+
const invalidIndex = idx < 0 || idx >= length;
|
|
24
|
+
if (invalidIndex) {
|
|
25
|
+
throw new Error(`Index ${idx} is out of bounds for BitVector of length ${length}`);
|
|
26
|
+
}
|
|
27
|
+
const byteIndex = Math.floor(idx / 8);
|
|
28
|
+
const bitIndex = idx % 8;
|
|
29
|
+
buffer[byteIndex] |= 1 << bitIndex;
|
|
30
|
+
});
|
|
31
|
+
return new BitVector(buffer, length);
|
|
32
|
+
}
|
|
33
|
+
getLength() {
|
|
34
|
+
return this.length;
|
|
35
|
+
}
|
|
36
|
+
/*
|
|
37
|
+
* Checks if element at index is set to true
|
|
38
|
+
*
|
|
39
|
+
* @param index - Index of the bit to check
|
|
40
|
+
*
|
|
41
|
+
* @returns True if the bit at index is set, false otherwise
|
|
42
|
+
* */ isSet(index) {
|
|
43
|
+
return index >= 0 && index < this.length && !!(this.buffer[Math.floor(index / 8)] & 1 << index % 8);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns all indices which are set to true
|
|
47
|
+
* */ getTrueIndices() {
|
|
48
|
+
return Array.from({
|
|
49
|
+
length: this.length
|
|
50
|
+
}, (_, i)=>i).filter((i)=>this.isSet(i));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Serializes the BitVector object into a Buffer
|
|
54
|
+
*
|
|
55
|
+
* @returns Buffer representation of the BitVector object
|
|
56
|
+
* */ toBuffer() {
|
|
57
|
+
return serializeToBuffer([
|
|
58
|
+
this.length,
|
|
59
|
+
this.buffer
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Deserializes buffer into new BitVector
|
|
64
|
+
*
|
|
65
|
+
* @returns A new BitVector instance
|
|
66
|
+
* */ static fromBuffer(buffer) {
|
|
67
|
+
const reader = BufferReader.asReader(buffer);
|
|
68
|
+
const length = reader.readNumber();
|
|
69
|
+
const bitBuffer = reader.readBytes(BitVector.byteLength(length));
|
|
70
|
+
return new BitVector(bitBuffer, length);
|
|
71
|
+
}
|
|
72
|
+
static byteLength(length) {
|
|
73
|
+
return Math.ceil(length / 8);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AttestationPool } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
|
|
2
|
+
import type { TxPool } from '../../../../mem_pools/index.js';
|
|
3
|
+
import type { ReqRespSubProtocolHandler } from '../../interface.js';
|
|
4
|
+
/**
|
|
5
|
+
* Handler for block txs requests
|
|
6
|
+
* @param attestationPool - the attestation pool to check for block proposals
|
|
7
|
+
* @param mempools - the mempools containing the tx pool
|
|
8
|
+
* @returns the BlockTxs request handler
|
|
9
|
+
*/
|
|
10
|
+
export declare function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool: TxPool): ReqRespSubProtocolHandler;
|
|
11
|
+
//# sourceMappingURL=block_txs_handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_txs_handler.d.ts","sourceRoot":"","sources":["../../../../../src/services/reqresp/protocols/block_txs/block_txs_handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4DAA4D,CAAC;AAClG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAKpE;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,yBAAyB,CAmClH"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TxArray } from '@aztec/stdlib/tx';
|
|
2
|
+
import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
|
|
3
|
+
import { BitVector } from './bitvector.js';
|
|
4
|
+
import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
|
|
5
|
+
/**
|
|
6
|
+
* Handler for block txs requests
|
|
7
|
+
* @param attestationPool - the attestation pool to check for block proposals
|
|
8
|
+
* @param mempools - the mempools containing the tx pool
|
|
9
|
+
* @returns the BlockTxs request handler
|
|
10
|
+
*/ export function reqRespBlockTxsHandler(attestationPool, txPool) {
|
|
11
|
+
/**
|
|
12
|
+
* Handler for block txs requests
|
|
13
|
+
* @param msg - the block txs request message
|
|
14
|
+
* @returns the block txs response message
|
|
15
|
+
* @throws if msg is not a valid block txs request
|
|
16
|
+
*/ return async (_peerId, msg)=>{
|
|
17
|
+
let request;
|
|
18
|
+
try {
|
|
19
|
+
request = BlockTxsRequest.fromBuffer(msg);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, {
|
|
22
|
+
cause: err
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const blockProposal = await attestationPool.getBlockProposal(request.blockHash.toString());
|
|
26
|
+
if (!blockProposal) {
|
|
27
|
+
throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
|
|
28
|
+
}
|
|
29
|
+
const txsAvailableInPool = await txPool.hasTxs(blockProposal.txHashes);
|
|
30
|
+
//Map txs in the pool to their indices in the block proposal
|
|
31
|
+
const availableIndices = txsAvailableInPool.map((hasTx, idx)=>hasTx ? idx : -1).filter((idx)=>idx !== -1);
|
|
32
|
+
const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
|
|
33
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
34
|
+
const requestedTxsHashes = blockProposal.txHashes.filter((_, idx)=>requestedIndices.has(idx));
|
|
35
|
+
const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter((tx)=>!!tx);
|
|
36
|
+
const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
|
|
37
|
+
return response.toBuffer();
|
|
38
|
+
};
|
|
39
|
+
}
|