@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.21caa21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -9
- package/dest/client/factory.d.ts +14 -4
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -24
- package/dest/client/index.d.ts +2 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +157 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +72 -187
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +373 -177
- package/dest/config.d.ts +151 -125
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +183 -34
- package/dest/enr/generate-enr.d.ts +11 -3
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +4 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +68 -8
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +214 -63
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -6
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +126 -25
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +19 -6
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +111 -21
- package/dest/mem_pools/attestation_pool/mocks.d.ts +225 -5
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +9 -15
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +10 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +35 -38
- package/dest/mem_pools/interface.d.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +62 -13
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
- package/dest/mem_pools/tx_pool/index.d.ts +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +34 -10
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
- package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +65 -9
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
- package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
- package/dest/msg_validators/index.d.ts +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +56 -86
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
- package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +74 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
- package/dest/msg_validators/tx_validator/index.d.ts +8 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +7 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +8 -4
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.d.ts +10 -9
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +63 -36
- package/dest/services/dummy_service.d.ts +50 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +73 -5
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +5 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +20 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +164 -0
- package/dest/services/libp2p/libp2p_service.d.ts +78 -89
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +698 -246
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +6 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +22 -2
- package/dest/services/peer-manager/peer_manager.d.ts +102 -22
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +549 -72
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +40 -2
- package/dest/services/reqresp/config.d.ts +11 -9
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
- package/dest/services/reqresp/index.d.ts +3 -2
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +73 -24
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +45 -26
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +6 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +28 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +47 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +3 -1
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +1 -3
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +39 -7
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +72 -5
- package/dest/services/reqresp/protocols/tx.d.ts +13 -2
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +24 -66
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +298 -207
- package/dest/services/reqresp/status.d.ts +10 -4
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +23 -19
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +58 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +50 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +300 -0
- package/dest/services/tx_collection/index.d.ts +3 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +2 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +34 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +52 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +177 -0
- package/dest/services/tx_collection/tx_collection.d.ts +109 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +128 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +111 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +49 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +210 -0
- package/dest/services/tx_provider_instrumentation.d.ts +13 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +2 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +1 -0
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -16
- package/dest/test-helpers/mock-pubsub.d.ts +59 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +130 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +62 -28
- package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +103 -29
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +1 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +11 -19
- package/dest/types/index.d.ts +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +24 -16
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +75 -69
- package/dest/versioning.d.ts +4 -4
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +32 -27
- package/src/bootstrap/bootstrap.ts +27 -11
- package/src/client/factory.ts +136 -45
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +198 -0
- package/src/client/p2p_client.ts +469 -330
- package/src/config.ts +305 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +264 -65
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +173 -34
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
- package/src/mem_pools/attestation_pool/mocks.ts +11 -10
- package/src/mem_pools/instrumentation.ts +43 -44
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
- package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
- package/src/msg_validators/tx_validator/data_validator.ts +81 -69
- package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
- package/src/msg_validators/tx_validator/factory.ts +109 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
- package/src/msg_validators/tx_validator/index.ts +7 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
- package/src/msg_validators/tx_validator/phases_validator.ts +116 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
- package/src/services/discv5/discV5_service.ts +84 -38
- package/src/services/dummy_service.ts +147 -9
- package/src/services/encoding.ts +80 -5
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +167 -0
- package/src/services/libp2p/libp2p_service.ts +866 -294
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +26 -1
- package/src/services/peer-manager/peer_manager.ts +654 -78
- package/src/services/peer-manager/peer_scoring.ts +46 -3
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +91 -36
- package/src/services/reqresp/metrics.ts +4 -1
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +24 -3
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +9 -7
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +117 -5
- package/src/services/reqresp/protocols/tx.ts +35 -6
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +387 -256
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +45 -21
- package/src/services/tx_collection/config.ts +84 -0
- package/src/services/tx_collection/fast_tx_collection.ts +340 -0
- package/src/services/tx_collection/index.ts +2 -0
- package/src/services/tx_collection/instrumentation.ts +43 -0
- package/src/services/tx_collection/slow_tx_collection.ts +233 -0
- package/src/services/tx_collection/tx_collection.ts +215 -0
- package/src/services/tx_collection/tx_collection_sink.ts +129 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +216 -0
- package/src/services/tx_provider_instrumentation.ts +44 -0
- package/src/test-helpers/index.ts +1 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +111 -21
- package/src/test-helpers/mock-pubsub.ts +188 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +86 -35
- package/src/testbench/p2p_client_testbench_worker.ts +151 -25
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +17 -23
- package/src/types/index.ts +2 -0
- package/src/util.ts +105 -91
- package/src/versioning.ts +11 -4
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type AnyTx,
|
|
5
|
+
TX_ERROR_INCORRECT_L1_CHAIN_ID,
|
|
6
|
+
TX_ERROR_INCORRECT_PROTOCOL_CONTRACTS_HASH,
|
|
7
|
+
TX_ERROR_INCORRECT_ROLLUP_VERSION,
|
|
8
|
+
TX_ERROR_INCORRECT_VK_TREE_ROOT,
|
|
9
|
+
type TxValidationResult,
|
|
10
|
+
type TxValidator,
|
|
11
|
+
} from '@aztec/stdlib/tx';
|
|
4
12
|
|
|
5
13
|
export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
6
14
|
#log = createLogger('p2p:tx_validator:tx_metadata');
|
|
7
15
|
|
|
8
|
-
constructor(
|
|
16
|
+
constructor(
|
|
17
|
+
private values: {
|
|
18
|
+
l1ChainId: Fr;
|
|
19
|
+
rollupVersion: Fr;
|
|
20
|
+
vkTreeRoot: Fr;
|
|
21
|
+
protocolContractsHash: Fr;
|
|
22
|
+
},
|
|
23
|
+
) {}
|
|
9
24
|
|
|
10
|
-
|
|
25
|
+
validateTx(tx: T): Promise<TxValidationResult> {
|
|
11
26
|
const errors = [];
|
|
12
|
-
if (!
|
|
13
|
-
errors.push(
|
|
27
|
+
if (!this.#hasCorrectL1ChainId(tx)) {
|
|
28
|
+
errors.push(TX_ERROR_INCORRECT_L1_CHAIN_ID);
|
|
14
29
|
}
|
|
15
|
-
if (!
|
|
16
|
-
errors.push(
|
|
30
|
+
if (!this.#hasCorrectRollupVersion(tx)) {
|
|
31
|
+
errors.push(TX_ERROR_INCORRECT_ROLLUP_VERSION);
|
|
17
32
|
}
|
|
18
|
-
|
|
33
|
+
if (!this.#hasCorrectVkTreeRoot(tx)) {
|
|
34
|
+
errors.push(TX_ERROR_INCORRECT_VK_TREE_ROOT);
|
|
35
|
+
}
|
|
36
|
+
if (!this.#hasCorrectprotocolContractsHash(tx)) {
|
|
37
|
+
errors.push(TX_ERROR_INCORRECT_PROTOCOL_CONTRACTS_HASH);
|
|
38
|
+
}
|
|
39
|
+
return Promise.resolve(errors.length > 0 ? { result: 'invalid', reason: errors } : { result: 'valid' });
|
|
19
40
|
}
|
|
20
41
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)} because of incorrect chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.chainId.toNumber()}`,
|
|
42
|
+
#hasCorrectVkTreeRoot(tx: T): boolean {
|
|
43
|
+
// This gets implicitly tested in the proof validator, but we can get a much cheaper check here by looking early at the vk.
|
|
44
|
+
if (!tx.data.constants.vkTreeRoot.equals(this.values.vkTreeRoot)) {
|
|
45
|
+
this.#log.verbose(
|
|
46
|
+
`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect vk tree root ${tx.data.constants.vkTreeRoot.toString()} != ${this.values.vkTreeRoot.toString()}`,
|
|
27
47
|
);
|
|
28
48
|
return false;
|
|
29
49
|
} else {
|
|
@@ -31,14 +51,31 @@ export class MetadataTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
31
51
|
}
|
|
32
52
|
}
|
|
33
53
|
|
|
34
|
-
|
|
35
|
-
|
|
54
|
+
#hasCorrectprotocolContractsHash(tx: T): boolean {
|
|
55
|
+
if (!tx.data.constants.protocolContractsHash.equals(this.values.protocolContractsHash)) {
|
|
56
|
+
this.#log.verbose(
|
|
57
|
+
`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect protocol contracts hash ${tx.data.constants.protocolContractsHash.toString()} != ${this.values.protocolContractsHash.toString()}`,
|
|
58
|
+
);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#hasCorrectL1ChainId(tx: T): boolean {
|
|
65
|
+
if (!tx.data.constants.txContext.chainId.equals(this.values.l1ChainId)) {
|
|
66
|
+
this.#log.verbose(
|
|
67
|
+
`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect L1 chain ${tx.data.constants.txContext.chainId.toNumber()} != ${this.values.l1ChainId.toNumber()}`,
|
|
68
|
+
);
|
|
69
|
+
return false;
|
|
70
|
+
} else {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
36
74
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}, current block number: ${this.blockNumber}.`,
|
|
75
|
+
#hasCorrectRollupVersion(tx: T): boolean {
|
|
76
|
+
if (!tx.data.constants.txContext.version.equals(this.values.rollupVersion)) {
|
|
77
|
+
this.#log.verbose(
|
|
78
|
+
`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} because of incorrect rollup version ${tx.data.constants.txContext.version.toNumber()} != ${this.values.rollupVersion.toNumber()}`,
|
|
42
79
|
);
|
|
43
80
|
return false;
|
|
44
81
|
} else {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { PublicContractsDB, getCallRequestsWithCalldataByPhase } from '@aztec/simulator/server';
|
|
3
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
4
|
+
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
|
|
5
|
+
import {
|
|
6
|
+
type PublicCallRequestWithCalldata,
|
|
7
|
+
TX_ERROR_DURING_VALIDATION,
|
|
8
|
+
TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED,
|
|
9
|
+
Tx,
|
|
10
|
+
TxExecutionPhase,
|
|
11
|
+
type TxValidationResult,
|
|
12
|
+
type TxValidator,
|
|
13
|
+
} from '@aztec/stdlib/tx';
|
|
14
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
15
|
+
|
|
16
|
+
export class PhasesTxValidator implements TxValidator<Tx> {
|
|
17
|
+
#log = createLogger('sequencer:tx_validator:tx_phases');
|
|
18
|
+
private contractsDB: PublicContractsDB;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
contracts: ContractDataSource,
|
|
22
|
+
private setupAllowList: AllowedElement[],
|
|
23
|
+
private timestamp: UInt64,
|
|
24
|
+
) {
|
|
25
|
+
this.contractsDB = new PublicContractsDB(contracts);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
29
|
+
this.contractsDB.createCheckpoint();
|
|
30
|
+
try {
|
|
31
|
+
// TODO(@spalladino): We add this just to handle public authwit-check calls during setup
|
|
32
|
+
// which are needed for public FPC flows, but fail if the account contract hasnt been deployed yet,
|
|
33
|
+
// which is what we're trying to do as part of the current txs.
|
|
34
|
+
// We only need to create/revert checkpoint here because of this addNewContracts call.
|
|
35
|
+
await this.contractsDB.addNewContracts(tx);
|
|
36
|
+
|
|
37
|
+
if (!tx.data.forPublic) {
|
|
38
|
+
this.#log.debug(
|
|
39
|
+
`Tx ${tx.getTxHash().toString()} does not contain enqueued public functions. Skipping phases validation.`,
|
|
40
|
+
);
|
|
41
|
+
return { result: 'valid' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const setupFns = getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP);
|
|
45
|
+
for (const setupFn of setupFns) {
|
|
46
|
+
if (!(await this.isOnAllowList(setupFn, this.setupAllowList))) {
|
|
47
|
+
this.#log.verbose(
|
|
48
|
+
`Rejecting tx ${tx.getTxHash().toString()} because it calls setup function not on allow list: ${
|
|
49
|
+
setupFn.request.contractAddress
|
|
50
|
+
}:${setupFn.functionSelector}`,
|
|
51
|
+
{ allowList: this.setupAllowList },
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return { result: 'invalid', reason: [TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED] };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return { result: 'valid' };
|
|
59
|
+
} catch (err) {
|
|
60
|
+
this.#log.error(`Error validating phases for tx`, err);
|
|
61
|
+
return { result: 'invalid', reason: [TX_ERROR_DURING_VALIDATION] };
|
|
62
|
+
} finally {
|
|
63
|
+
this.contractsDB.revertCheckpoint();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private async isOnAllowList(
|
|
68
|
+
publicCall: PublicCallRequestWithCalldata,
|
|
69
|
+
allowList: AllowedElement[],
|
|
70
|
+
): Promise<boolean> {
|
|
71
|
+
if (publicCall.isEmpty()) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const contractAddress = publicCall.request.contractAddress;
|
|
76
|
+
const functionSelector = publicCall.functionSelector;
|
|
77
|
+
|
|
78
|
+
// do these checks first since they don't require the contract class
|
|
79
|
+
for (const entry of allowList) {
|
|
80
|
+
if ('address' in entry && !('selector' in entry)) {
|
|
81
|
+
if (contractAddress.equals(entry.address)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ('address' in entry && 'selector' in entry) {
|
|
87
|
+
if (contractAddress.equals(entry.address) && entry.selector.equals(functionSelector)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const contractClass = await this.contractsDB.getContractInstance(contractAddress, this.timestamp);
|
|
93
|
+
|
|
94
|
+
if (!contractClass) {
|
|
95
|
+
throw new Error(`Contract not found: ${contractAddress}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if ('classId' in entry && !('selector' in entry)) {
|
|
99
|
+
if (contractClass.currentContractClassId.equals(entry.classId)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ('classId' in entry && 'selector' in entry) {
|
|
105
|
+
if (
|
|
106
|
+
contractClass.currentContractClassId.equals(entry.classId) &&
|
|
107
|
+
(entry.selector === undefined || entry.selector.equals(functionSelector))
|
|
108
|
+
) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { HashedValues, type Tx } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
export function patchNonRevertibleFn(
|
|
7
|
+
tx: Tx,
|
|
8
|
+
index: number,
|
|
9
|
+
overrides: { address?: AztecAddress; selector: FunctionSelector; args?: Fr[]; msgSender?: AztecAddress },
|
|
10
|
+
): Promise<AztecAddress> {
|
|
11
|
+
return patchFn('nonRevertibleAccumulatedData', tx, index, overrides);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function patchRevertibleFn(
|
|
15
|
+
tx: Tx,
|
|
16
|
+
index: number,
|
|
17
|
+
overrides: { address?: AztecAddress; selector: FunctionSelector; args?: Fr[]; msgSender?: AztecAddress },
|
|
18
|
+
): Promise<AztecAddress> {
|
|
19
|
+
return patchFn('revertibleAccumulatedData', tx, index, overrides);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function patchFn(
|
|
23
|
+
where: 'revertibleAccumulatedData' | 'nonRevertibleAccumulatedData',
|
|
24
|
+
tx: Tx,
|
|
25
|
+
index: number,
|
|
26
|
+
overrides: { address?: AztecAddress; selector: FunctionSelector; args?: Fr[]; msgSender?: AztecAddress },
|
|
27
|
+
): Promise<AztecAddress> {
|
|
28
|
+
const calldataIndex =
|
|
29
|
+
where === 'nonRevertibleAccumulatedData'
|
|
30
|
+
? index
|
|
31
|
+
: index + tx.data.forPublic!.nonRevertibleAccumulatedData.publicCallRequests.length;
|
|
32
|
+
const calldata = [overrides.selector.toField(), ...(overrides.args ?? [])];
|
|
33
|
+
const hashedCalldata = await HashedValues.fromCalldata(calldata);
|
|
34
|
+
tx.publicFunctionCalldata[calldataIndex] = hashedCalldata;
|
|
35
|
+
|
|
36
|
+
const request = tx.data.forPublic![where].publicCallRequests[index];
|
|
37
|
+
request.contractAddress = overrides.address ?? request.contractAddress;
|
|
38
|
+
request.msgSender = overrides.msgSender ?? request.msgSender;
|
|
39
|
+
request.calldataHash = hashedCalldata.hash;
|
|
40
|
+
tx.data.forPublic![where].publicCallRequests[index] = request;
|
|
41
|
+
|
|
42
|
+
return request.contractAddress;
|
|
43
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import {
|
|
3
|
+
type AnyTx,
|
|
4
|
+
TX_ERROR_INVALID_INCLUDE_BY_TIMESTAMP,
|
|
5
|
+
type TxValidationResult,
|
|
6
|
+
type TxValidator,
|
|
7
|
+
getTxHash,
|
|
8
|
+
} from '@aztec/stdlib/tx';
|
|
9
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
10
|
+
|
|
11
|
+
export class TimestampTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
12
|
+
#log = createLogger('p2p:tx_validator:timestamp');
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
private values: {
|
|
16
|
+
// Timestamp at which we will validate that the tx is not expired. This is typically the timestamp of the block
|
|
17
|
+
// being built.
|
|
18
|
+
timestamp: UInt64;
|
|
19
|
+
// Block number in which the tx is considered to be included.
|
|
20
|
+
blockNumber: number;
|
|
21
|
+
},
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
validateTx(tx: T): Promise<TxValidationResult> {
|
|
25
|
+
const includeByTimestamp = tx.data.includeByTimestamp;
|
|
26
|
+
// If building block 1, we skip the expiration check. For details on why see the `validate_include_by_timestamp`
|
|
27
|
+
// function in `noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/validation_requests.nr`.
|
|
28
|
+
const buildingBlock1 = this.values.blockNumber === 1;
|
|
29
|
+
|
|
30
|
+
if (!buildingBlock1 && includeByTimestamp < this.values.timestamp) {
|
|
31
|
+
if (tx.data.constants.anchorBlockHeader.globalVariables.blockNumber === 0) {
|
|
32
|
+
this.#log.warn(
|
|
33
|
+
`A tx built against a genesis block failed to be included in block 1 which is the only block in which txs built against a genesis block are allowed to be included.`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
this.#log.verbose(
|
|
37
|
+
`Rejecting tx ${getTxHash(tx)} for low expiration timestamp. Tx expiration timestamp: ${includeByTimestamp}, timestamp: ${
|
|
38
|
+
this.values.timestamp
|
|
39
|
+
}.`,
|
|
40
|
+
);
|
|
41
|
+
return Promise.resolve({ result: 'invalid', reason: [TX_ERROR_INVALID_INCLUDE_BY_TIMESTAMP] });
|
|
42
|
+
} else {
|
|
43
|
+
return Promise.resolve({ result: 'valid' });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { Tx, TxValidationResult, TxValidator } from '@aztec/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
export class TxPermittedValidator implements TxValidator<Tx> {
|
|
5
|
+
#log = createLogger('p2p:tx_validator:tx_permitted');
|
|
6
|
+
|
|
7
|
+
constructor(private permitted: boolean) {}
|
|
8
|
+
|
|
9
|
+
validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
10
|
+
if (!this.permitted) {
|
|
11
|
+
const txHash = tx.getTxHash();
|
|
12
|
+
this.#log.verbose(`Rejecting tx ${txHash.toString()}. Reason: Transactions are not permitted`);
|
|
13
|
+
return Promise.resolve({ result: 'invalid', reason: ['Transactions are not permitted'] });
|
|
14
|
+
}
|
|
15
|
+
return Promise.resolve({ result: 'valid' });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import { Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
3
|
+
import { TX_ERROR_INVALID_PROOF, Tx, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
export class TxProofValidator implements TxValidator<Tx> {
|
|
6
6
|
#log = createLogger('p2p:tx_validator:private_proof');
|
|
@@ -8,11 +8,12 @@ export class TxProofValidator implements TxValidator<Tx> {
|
|
|
8
8
|
constructor(private verifier: ClientProtocolCircuitVerifier) {}
|
|
9
9
|
|
|
10
10
|
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const result = await this.verifier.verifyProof(tx);
|
|
12
|
+
if (!result.valid) {
|
|
13
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()} for invalid proof`);
|
|
14
|
+
return { result: 'invalid', reason: [TX_ERROR_INVALID_PROOF] };
|
|
14
15
|
}
|
|
15
|
-
this.#log.trace(`Accepted ${
|
|
16
|
+
this.#log.trace(`Accepted ${tx.getTxHash().toString()} with valid proof`);
|
|
16
17
|
return { result: 'valid' };
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -3,16 +3,16 @@ import { sleep } from '@aztec/foundation/sleep';
|
|
|
3
3
|
import { type ComponentsVersions, checkCompressedComponentVersion } from '@aztec/stdlib/versioning';
|
|
4
4
|
import { OtelMetricsAdapter, type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
5
5
|
|
|
6
|
-
import { Discv5, type Discv5EventEmitter } from '@chainsafe/discv5';
|
|
7
|
-
import { ENR, SignableENR } from '@chainsafe/enr';
|
|
8
6
|
import type { PeerId } from '@libp2p/interface';
|
|
9
7
|
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr';
|
|
8
|
+
import { Discv5, type Discv5EventEmitter, type IDiscv5CreateOptions } from '@nethermindeth/discv5';
|
|
9
|
+
import { ENR, SignableENR } from '@nethermindeth/enr';
|
|
10
10
|
import EventEmitter from 'events';
|
|
11
11
|
|
|
12
12
|
import type { P2PConfig } from '../../config.js';
|
|
13
|
+
import { createNodeENR } from '../../enr/generate-enr.js';
|
|
13
14
|
import { AZTEC_ENR_KEY, Discv5Event, PeerEvent } from '../../types/index.js';
|
|
14
15
|
import { convertToMultiaddr } from '../../util.js';
|
|
15
|
-
import { setAztecEnrKey } from '../../versioning.js';
|
|
16
16
|
import { type PeerDiscoveryService, PeerDiscoveryState } from '../service.js';
|
|
17
17
|
|
|
18
18
|
const delayBeforeStart = 2000; // 2sec
|
|
@@ -22,7 +22,7 @@ const delayBeforeStart = 2000; // 2sec
|
|
|
22
22
|
*/
|
|
23
23
|
export class DiscV5Service extends EventEmitter implements PeerDiscoveryService {
|
|
24
24
|
/** The Discv5 instance */
|
|
25
|
-
private discv5:
|
|
25
|
+
private discv5: Discv5EventEmitter;
|
|
26
26
|
|
|
27
27
|
/** This instance's ENR */
|
|
28
28
|
private enr: SignableENR;
|
|
@@ -30,57 +30,74 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
30
30
|
/** Version identifiers. */
|
|
31
31
|
private versions: ComponentsVersions;
|
|
32
32
|
|
|
33
|
-
/** UDP listen addr */
|
|
34
|
-
private listenMultiAddrUdp: Multiaddr;
|
|
35
|
-
|
|
36
33
|
private currentState = PeerDiscoveryState.STOPPED;
|
|
37
34
|
|
|
38
|
-
public readonly bootstrapNodes: string[] = [];
|
|
39
35
|
private bootstrapNodePeerIds: PeerId[] = [];
|
|
40
|
-
|
|
36
|
+
public bootstrapNodeEnrs: ENR[] = [];
|
|
37
|
+
private trustedPeerEnrs: ENR[] = [];
|
|
41
38
|
|
|
42
39
|
private startTime = 0;
|
|
43
40
|
|
|
41
|
+
private handlers = {
|
|
42
|
+
onMultiaddrUpdated: this.onMultiaddrUpdated.bind(this),
|
|
43
|
+
onDiscovered: this.onDiscovered.bind(this),
|
|
44
|
+
onEnrAdded: this.onEnrAdded.bind(this),
|
|
45
|
+
};
|
|
46
|
+
|
|
44
47
|
constructor(
|
|
45
48
|
private peerId: PeerId,
|
|
46
49
|
private config: P2PConfig,
|
|
50
|
+
private readonly packageVersion: string,
|
|
47
51
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
48
52
|
private logger = createLogger('p2p:discv5_service'),
|
|
53
|
+
configOverrides: Partial<IDiscv5CreateOptions> = {},
|
|
49
54
|
) {
|
|
50
55
|
super();
|
|
51
|
-
const {
|
|
52
|
-
|
|
53
|
-
this.bootstrapNodeEnrs =
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
const { p2pIp, p2pPort, p2pBroadcastPort, bootstrapNodes, trustedPeers, privatePeers } = config;
|
|
57
|
+
|
|
58
|
+
this.bootstrapNodeEnrs = bootstrapNodes.map(x => ENR.decodeTxt(x));
|
|
59
|
+
const privatePeerEnrs = new Set(privatePeers);
|
|
60
|
+
this.trustedPeerEnrs = trustedPeers.filter(x => !privatePeerEnrs.has(x)).map(x => ENR.decodeTxt(x));
|
|
61
|
+
|
|
62
|
+
// If no overridden broadcast port is provided, use the p2p port as the broadcast port
|
|
63
|
+
if (!p2pBroadcastPort) {
|
|
64
|
+
this.logger.warn('No p2pBroadcastPort provided, using p2pPort as broadcast port');
|
|
65
|
+
config.p2pBroadcastPort = p2pPort;
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
`${convertToMultiaddr(udpAnnounceAddress || tcpAnnounceAddress, 'udp')}/p2p/${peerId.toString()}`,
|
|
67
|
-
);
|
|
68
|
+
const bindAddrs: any = {
|
|
69
|
+
ip4: multiaddr(convertToMultiaddr(config.listenAddress, p2pPort, 'udp')),
|
|
70
|
+
};
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
let multiAddrUdp, multiAddrTcp;
|
|
73
|
+
if (p2pIp) {
|
|
74
|
+
multiAddrTcp = multiaddr(
|
|
75
|
+
`${convertToMultiaddr(p2pIp!, config.p2pBroadcastPort!, 'tcp')}/p2p/${peerId.toString()}`,
|
|
76
|
+
);
|
|
77
|
+
multiAddrUdp = multiaddr(
|
|
78
|
+
`${convertToMultiaddr(p2pIp!, config.p2pBroadcastPort!, 'udp')}/p2p/${peerId.toString()}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
70
81
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
({ enr: this.enr, versions: this.versions } = createNodeENR(
|
|
83
|
+
peerId,
|
|
84
|
+
multiAddrUdp,
|
|
85
|
+
multiAddrTcp,
|
|
86
|
+
config,
|
|
87
|
+
this.packageVersion,
|
|
88
|
+
));
|
|
74
89
|
|
|
75
90
|
const metricsRegistry = new OtelMetricsAdapter(telemetry);
|
|
76
91
|
this.discv5 = Discv5.create({
|
|
77
92
|
enr: this.enr,
|
|
78
93
|
peerId,
|
|
79
|
-
bindAddrs
|
|
94
|
+
bindAddrs,
|
|
80
95
|
config: {
|
|
81
96
|
lookupTimeout: 2000,
|
|
82
97
|
requestTimeout: 2000,
|
|
83
98
|
allowUnverifiedSessions: true,
|
|
99
|
+
enrUpdate: !p2pIp ? true : false, // If no p2p IP is set, enrUpdate can automatically resolve it
|
|
100
|
+
...configOverrides.config,
|
|
84
101
|
},
|
|
85
102
|
metricsRegistry,
|
|
86
103
|
});
|
|
@@ -104,8 +121,17 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
104
121
|
}
|
|
105
122
|
};
|
|
106
123
|
|
|
107
|
-
this.discv5.on(Discv5Event.DISCOVERED, this.onDiscovered
|
|
108
|
-
this.discv5.on(Discv5Event.ENR_ADDED, this.onEnrAdded
|
|
124
|
+
this.discv5.on(Discv5Event.DISCOVERED, this.handlers.onDiscovered);
|
|
125
|
+
this.discv5.on(Discv5Event.ENR_ADDED, this.handlers.onEnrAdded);
|
|
126
|
+
this.discv5.on(Discv5Event.MULTIADDR_UPDATED, this.handlers.onMultiaddrUpdated);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private onMultiaddrUpdated(m: Multiaddr) {
|
|
130
|
+
// We want to update our tcp port to match the udp port
|
|
131
|
+
// p2pBroadcastPort is optional on config, however it is set to default within the p2p client factory
|
|
132
|
+
const multiAddrTcp = multiaddr(convertToMultiaddr(m.nodeAddress().address, this.config.p2pBroadcastPort!, 'tcp'));
|
|
133
|
+
this.enr.setLocationMultiaddr(multiAddrTcp);
|
|
134
|
+
this.logger.info('Multiaddr updated', { multiaddr: multiAddrTcp.toString() });
|
|
109
135
|
}
|
|
110
136
|
|
|
111
137
|
public async start(): Promise<void> {
|
|
@@ -126,10 +152,14 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
126
152
|
this.currentState = PeerDiscoveryState.RUNNING;
|
|
127
153
|
|
|
128
154
|
// Add bootnode ENR if provided
|
|
129
|
-
if (this.
|
|
155
|
+
if (this.bootstrapNodeEnrs?.length) {
|
|
130
156
|
// Do this conversion once since it involves an async function call
|
|
131
157
|
this.bootstrapNodePeerIds = await Promise.all(this.bootstrapNodeEnrs.map(enr => enr.peerId()));
|
|
132
|
-
this.logger.info(
|
|
158
|
+
this.logger.info(
|
|
159
|
+
`Adding ${this.bootstrapNodeEnrs.length} bootstrap nodes ENRs: ${this.bootstrapNodeEnrs
|
|
160
|
+
.map(enr => enr.encodeTxt())
|
|
161
|
+
.join(', ')}`,
|
|
162
|
+
);
|
|
133
163
|
for (const enr of this.bootstrapNodeEnrs) {
|
|
134
164
|
try {
|
|
135
165
|
if (this.config.bootstrapNodeEnrVersionCheck) {
|
|
@@ -145,11 +175,23 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
145
175
|
}
|
|
146
176
|
}
|
|
147
177
|
}
|
|
178
|
+
|
|
179
|
+
// Add trusted peer ENRs if provided
|
|
180
|
+
if (this.trustedPeerEnrs?.length) {
|
|
181
|
+
this.logger.info(
|
|
182
|
+
`Adding ${this.trustedPeerEnrs.length} trusted peer ENRs: ${this.trustedPeerEnrs
|
|
183
|
+
.map(enr => enr.encodeTxt())
|
|
184
|
+
.join(', ')}`,
|
|
185
|
+
);
|
|
186
|
+
for (const enr of this.trustedPeerEnrs) {
|
|
187
|
+
this.discv5.addEnr(enr);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
148
190
|
}
|
|
149
191
|
|
|
150
192
|
public async runRandomNodesQuery(): Promise<void> {
|
|
151
193
|
if (this.currentState !== PeerDiscoveryState.RUNNING) {
|
|
152
|
-
|
|
194
|
+
return;
|
|
153
195
|
}
|
|
154
196
|
|
|
155
197
|
// First, wait some time before starting the peer discovery
|
|
@@ -166,7 +208,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
166
208
|
}
|
|
167
209
|
}
|
|
168
210
|
|
|
169
|
-
public
|
|
211
|
+
public getKadValues(): ENR[] {
|
|
170
212
|
return this.discv5.kadValues();
|
|
171
213
|
}
|
|
172
214
|
|
|
@@ -187,8 +229,12 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
187
229
|
}
|
|
188
230
|
|
|
189
231
|
public async stop(): Promise<void> {
|
|
190
|
-
|
|
191
|
-
|
|
232
|
+
if (this.currentState !== PeerDiscoveryState.RUNNING) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
await this.discv5.off(Discv5Event.DISCOVERED, this.handlers.onDiscovered);
|
|
236
|
+
await this.discv5.off(Discv5Event.ENR_ADDED, this.handlers.onEnrAdded);
|
|
237
|
+
await this.discv5.off(Discv5Event.MULTIADDR_UPDATED, this.handlers.onMultiaddrUpdated);
|
|
192
238
|
|
|
193
239
|
await this.discv5.stop();
|
|
194
240
|
|
|
@@ -231,7 +277,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
231
277
|
// Check the peer is an aztec peer
|
|
232
278
|
const value = enr.kvs.get(AZTEC_ENR_KEY);
|
|
233
279
|
if (!value) {
|
|
234
|
-
this.logger.
|
|
280
|
+
this.logger.debug(`Peer node ${enr.nodeId} does not have aztec key in ENR`);
|
|
235
281
|
return false;
|
|
236
282
|
}
|
|
237
283
|
|