@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.24de95ac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -9
- package/dest/client/factory.d.ts +13 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -24
- package/dest/client/index.d.ts +1 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +155 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +72 -169
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +365 -174
- package/dest/config.d.ts +123 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +173 -34
- package/dest/enr/generate-enr.d.ts +10 -2
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/index.d.ts +3 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +42 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +204 -54
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +93 -15
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +86 -18
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +9 -15
- package/dest/mem_pools/instrumentation.d.ts +7 -11
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +25 -37
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +93 -9
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +469 -97
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +33 -9
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +64 -8
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +5 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +61 -12
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +56 -86
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
- package/dest/msg_validators/tx_validator/factory.d.ts +15 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +74 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +11 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +115 -0
- package/dest/msg_validators/tx_validator/index.d.ts +7 -0
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +7 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +7 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +91 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +12 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
- package/dest/services/discv5/discV5_service.d.ts +9 -8
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +63 -36
- package/dest/services/dummy_service.d.ts +49 -10
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +25 -6
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +73 -5
- package/dest/services/index.d.ts +4 -0
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +18 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +157 -0
- package/dest/services/libp2p/libp2p_service.d.ts +87 -42
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +500 -218
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +11 -2
- package/dest/services/peer-manager/peer_manager.d.ts +126 -15
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +547 -72
- package/dest/services/reqresp/config.d.ts +10 -8
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +30 -13
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
- package/dest/services/reqresp/index.d.ts +2 -1
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +72 -23
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +45 -26
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +5 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +28 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +2 -4
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +2 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +0 -2
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +38 -6
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +72 -5
- package/dest/services/reqresp/protocols/tx.d.ts +12 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +4 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +45 -47
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +298 -207
- package/dest/services/reqresp/status.d.ts +9 -3
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +22 -18
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +58 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +300 -0
- package/dest/services/tx_collection/index.d.ts +3 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +2 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +34 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +176 -0
- package/dest/services/tx_collection/tx_collection.d.ts +110 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +128 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +111 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +49 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +210 -0
- package/dest/services/tx_provider_instrumentation.d.ts +13 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +1 -0
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +1 -0
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +32 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -16
- package/dest/test-helpers/mock-pubsub.d.ts +59 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +130 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +14 -10
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +62 -28
- package/dest/testbench/p2p_client_testbench_worker.js +96 -25
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +0 -5
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +11 -19
- package/dest/types/index.d.ts +3 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +22 -15
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +64 -67
- package/dest/versioning.d.ts +3 -3
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +28 -24
- package/src/bootstrap/bootstrap.ts +27 -11
- package/src/client/factory.ts +136 -45
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +195 -0
- package/src/client/p2p_client.ts +460 -327
- package/src/config.ts +288 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +48 -4
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -55
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +117 -20
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +114 -22
- package/src/mem_pools/attestation_pool/mocks.ts +11 -10
- package/src/mem_pools/instrumentation.ts +32 -46
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
- package/src/msg_validators/attestation_validator/attestation_validator.ts +55 -10
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +66 -14
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +4 -4
- package/src/msg_validators/tx_validator/data_validator.ts +81 -69
- package/src/msg_validators/tx_validator/double_spend_validator.ts +19 -17
- package/src/msg_validators/tx_validator/factory.ts +109 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +134 -0
- package/src/msg_validators/tx_validator/index.ts +7 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +58 -21
- package/src/msg_validators/tx_validator/phases_validator.ts +114 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +17 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +6 -5
- package/src/services/discv5/discV5_service.ts +84 -38
- package/src/services/dummy_service.ts +147 -9
- package/src/services/encoding.ts +80 -5
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +158 -0
- package/src/services/libp2p/libp2p_service.ts +646 -263
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +16 -1
- package/src/services/peer-manager/peer_manager.ts +652 -78
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +91 -36
- package/src/services/reqresp/metrics.ts +4 -1
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +24 -3
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +9 -7
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +117 -5
- package/src/services/reqresp/protocols/tx.ts +35 -6
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +387 -256
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +45 -21
- package/src/services/tx_collection/config.ts +84 -0
- package/src/services/tx_collection/fast_tx_collection.ts +340 -0
- package/src/services/tx_collection/index.ts +2 -0
- package/src/services/tx_collection/instrumentation.ts +43 -0
- package/src/services/tx_collection/slow_tx_collection.ts +232 -0
- package/src/services/tx_collection/tx_collection.ts +215 -0
- package/src/services/tx_collection/tx_collection_sink.ts +129 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +216 -0
- package/src/services/tx_provider_instrumentation.ts +44 -0
- package/src/test-helpers/index.ts +1 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +111 -21
- package/src/test-helpers/mock-pubsub.ts +188 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +86 -35
- package/src/testbench/p2p_client_testbench_worker.ts +145 -22
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +17 -23
- package/src/types/index.ts +2 -0
- package/src/util.ts +93 -89
- package/src/versioning.ts +11 -4
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
try {
|
|
30
|
+
// TODO(@spalladino): We add this just to handle public authwit-check calls during setup
|
|
31
|
+
// which are needed for public FPC flows, but fail if the account contract hasnt been deployed yet,
|
|
32
|
+
// which is what we're trying to do as part of the current txs.
|
|
33
|
+
await this.contractsDB.addNewContracts(tx);
|
|
34
|
+
|
|
35
|
+
if (!tx.data.forPublic) {
|
|
36
|
+
this.#log.debug(
|
|
37
|
+
`Tx ${tx.getTxHash().toString()} does not contain enqueued public functions. Skipping phases validation.`,
|
|
38
|
+
);
|
|
39
|
+
return { result: 'valid' };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const setupFns = getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP);
|
|
43
|
+
for (const setupFn of setupFns) {
|
|
44
|
+
if (!(await this.isOnAllowList(setupFn, this.setupAllowList))) {
|
|
45
|
+
this.#log.verbose(
|
|
46
|
+
`Rejecting tx ${tx.getTxHash().toString()} because it calls setup function not on allow list: ${
|
|
47
|
+
setupFn.request.contractAddress
|
|
48
|
+
}:${setupFn.functionSelector}`,
|
|
49
|
+
{ allowList: this.setupAllowList },
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return { result: 'invalid', reason: [TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED] };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { result: 'valid' };
|
|
57
|
+
} catch (err) {
|
|
58
|
+
this.#log.error(`Error validating phases for tx`, err);
|
|
59
|
+
return { result: 'invalid', reason: [TX_ERROR_DURING_VALIDATION] };
|
|
60
|
+
} finally {
|
|
61
|
+
this.contractsDB.clearContractsForTx();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async isOnAllowList(
|
|
66
|
+
publicCall: PublicCallRequestWithCalldata,
|
|
67
|
+
allowList: AllowedElement[],
|
|
68
|
+
): Promise<boolean> {
|
|
69
|
+
if (publicCall.isEmpty()) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const contractAddress = publicCall.request.contractAddress;
|
|
74
|
+
const functionSelector = publicCall.functionSelector;
|
|
75
|
+
|
|
76
|
+
// do these checks first since they don't require the contract class
|
|
77
|
+
for (const entry of allowList) {
|
|
78
|
+
if ('address' in entry && !('selector' in entry)) {
|
|
79
|
+
if (contractAddress.equals(entry.address)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ('address' in entry && 'selector' in entry) {
|
|
85
|
+
if (contractAddress.equals(entry.address) && entry.selector.equals(functionSelector)) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const contractClass = await this.contractsDB.getContractInstance(contractAddress, this.timestamp);
|
|
91
|
+
|
|
92
|
+
if (!contractClass) {
|
|
93
|
+
throw new Error(`Contract not found: ${contractAddress}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ('classId' in entry && !('selector' in entry)) {
|
|
97
|
+
if (contractClass.currentContractClassId.equals(entry.classId)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if ('classId' in entry && 'selector' in entry) {
|
|
103
|
+
if (
|
|
104
|
+
contractClass.currentContractClassId.equals(entry.classId) &&
|
|
105
|
+
(entry.selector === undefined || entry.selector.equals(functionSelector))
|
|
106
|
+
) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -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
|
|
|
@@ -1,17 +1,39 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
1
2
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import type {
|
|
3
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
import type { Gossipable, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
4
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
5
|
|
|
5
6
|
import type { PeerId } from '@libp2p/interface';
|
|
7
|
+
import type { ENR } from '@nethermindeth/enr';
|
|
6
8
|
import EventEmitter from 'events';
|
|
7
9
|
|
|
8
|
-
import type {
|
|
9
|
-
import
|
|
10
|
+
import type { PeerManagerInterface } from './peer-manager/interface.js';
|
|
11
|
+
import type { P2PReqRespConfig } from './reqresp/config.js';
|
|
12
|
+
import { type AuthRequest, StatusMessage } from './reqresp/index.js';
|
|
13
|
+
import type {
|
|
14
|
+
ReqRespInterface,
|
|
15
|
+
ReqRespResponse,
|
|
16
|
+
ReqRespSubProtocol,
|
|
17
|
+
ReqRespSubProtocolHandler,
|
|
18
|
+
ReqRespSubProtocolHandlers,
|
|
19
|
+
ReqRespSubProtocolValidators,
|
|
20
|
+
SubProtocolMap,
|
|
21
|
+
} from './reqresp/interface.js';
|
|
22
|
+
import type { GoodByeReason } from './reqresp/protocols/goodbye.js';
|
|
23
|
+
import { ReqRespStatus } from './reqresp/status.js';
|
|
24
|
+
import {
|
|
25
|
+
type P2PBlockReceivedCallback,
|
|
26
|
+
type P2PService,
|
|
27
|
+
type PeerDiscoveryService,
|
|
28
|
+
PeerDiscoveryState,
|
|
29
|
+
} from './service.js';
|
|
10
30
|
|
|
11
31
|
/**
|
|
12
32
|
* A dummy implementation of the P2P Service.
|
|
13
33
|
*/
|
|
14
34
|
export class DummyP2PService implements P2PService {
|
|
35
|
+
updateConfig(_config: Partial<P2PReqRespConfig>): void {}
|
|
36
|
+
|
|
15
37
|
/** Returns an empty array for peers. */
|
|
16
38
|
getPeers(): PeerInfo[] {
|
|
17
39
|
return [];
|
|
@@ -37,7 +59,9 @@ export class DummyP2PService implements P2PService {
|
|
|
37
59
|
* Called to have the given message propagated through the P2P network.
|
|
38
60
|
* @param _ - The message to be propagated.
|
|
39
61
|
*/
|
|
40
|
-
public propagate<T extends Gossipable>(_: T) {
|
|
62
|
+
public propagate<T extends Gossipable>(_: T) {
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
}
|
|
41
65
|
|
|
42
66
|
/**
|
|
43
67
|
* Called upon receipt of settled transactions.
|
|
@@ -48,7 +72,7 @@ export class DummyP2PService implements P2PService {
|
|
|
48
72
|
/**
|
|
49
73
|
* Register a callback into the validator client for when a block proposal is received
|
|
50
74
|
*/
|
|
51
|
-
public registerBlockReceivedCallback(
|
|
75
|
+
public registerBlockReceivedCallback(_callback: P2PBlockReceivedCallback) {}
|
|
52
76
|
|
|
53
77
|
/**
|
|
54
78
|
* Sends a request to a peer.
|
|
@@ -83,6 +107,25 @@ export class DummyP2PService implements P2PService {
|
|
|
83
107
|
public getEnr(): undefined {
|
|
84
108
|
return undefined;
|
|
85
109
|
}
|
|
110
|
+
|
|
111
|
+
validate(_txs: Tx[]): Promise<void> {
|
|
112
|
+
return Promise.resolve();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
addReqRespSubProtocol(
|
|
116
|
+
_subProtocol: ReqRespSubProtocol,
|
|
117
|
+
_handler: ReqRespSubProtocolHandler,
|
|
118
|
+
_validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
119
|
+
): Promise<void> {
|
|
120
|
+
return Promise.resolve();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
handleAuthRequestFromPeer(_authRequest: AuthRequest, _peerId: PeerId): Promise<StatusMessage> {
|
|
124
|
+
return Promise.resolve(StatusMessage.random());
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//this is no-op
|
|
128
|
+
registerThisValidatorAddresses(_address: EthAddress[]): void {}
|
|
86
129
|
}
|
|
87
130
|
|
|
88
131
|
/**
|
|
@@ -90,7 +133,7 @@ export class DummyP2PService implements P2PService {
|
|
|
90
133
|
*/
|
|
91
134
|
export class DummyPeerDiscoveryService extends EventEmitter implements PeerDiscoveryService {
|
|
92
135
|
private currentState = PeerDiscoveryState.STOPPED;
|
|
93
|
-
public
|
|
136
|
+
public bootstrapNodeEnrs: ENR[] = [];
|
|
94
137
|
|
|
95
138
|
/**
|
|
96
139
|
* Starts the dummy implementation.
|
|
@@ -110,9 +153,9 @@ export class DummyPeerDiscoveryService extends EventEmitter implements PeerDisco
|
|
|
110
153
|
}
|
|
111
154
|
/**
|
|
112
155
|
* Called to discover peers in the network.
|
|
113
|
-
* @returns An array of
|
|
156
|
+
* @returns An array of Enrs.
|
|
114
157
|
*/
|
|
115
|
-
public
|
|
158
|
+
public getKadValues() {
|
|
116
159
|
return [];
|
|
117
160
|
}
|
|
118
161
|
|
|
@@ -132,3 +175,98 @@ export class DummyPeerDiscoveryService extends EventEmitter implements PeerDisco
|
|
|
132
175
|
return undefined;
|
|
133
176
|
}
|
|
134
177
|
}
|
|
178
|
+
|
|
179
|
+
export class DummyPeerManager implements PeerManagerInterface {
|
|
180
|
+
constructor(
|
|
181
|
+
public peerId: PeerId,
|
|
182
|
+
private peersProvider?: { getPeers: () => PeerId[] },
|
|
183
|
+
) {}
|
|
184
|
+
|
|
185
|
+
public getPeers(_includePending?: boolean): PeerInfo[] {
|
|
186
|
+
if (!this.peersProvider) {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
return this.peersProvider
|
|
190
|
+
.getPeers()
|
|
191
|
+
.filter(peer => !peer.equals(this.peerId))
|
|
192
|
+
.map(id => ({
|
|
193
|
+
id: id.toString(),
|
|
194
|
+
status: 'connected',
|
|
195
|
+
score: 0,
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public initializePeers(): Promise<void> {
|
|
200
|
+
return Promise.resolve();
|
|
201
|
+
}
|
|
202
|
+
public getPeerScore(_peerId: string): number {
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public shouldDisableP2PGossip(_peerId: string): boolean {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public stop(): Promise<void> {
|
|
211
|
+
return Promise.resolve();
|
|
212
|
+
}
|
|
213
|
+
public heartbeat(): Promise<void> {
|
|
214
|
+
return Promise.resolve();
|
|
215
|
+
}
|
|
216
|
+
public addTrustedPeer(_peerId: PeerId): void {}
|
|
217
|
+
public addPrivatePeer(_peerId: PeerId): void {}
|
|
218
|
+
public goodbyeReceived(_peerId: PeerId, _reason: GoodByeReason): void {}
|
|
219
|
+
public penalizePeer(_peerId: PeerId, _penalty: PeerErrorSeverity): void {}
|
|
220
|
+
public addPreferredPeer(_peerId: PeerId): void {}
|
|
221
|
+
public handleAuthRequestFromPeer(_authRequest: AuthRequest, _peerId: PeerId): Promise<StatusMessage> {
|
|
222
|
+
return Promise.resolve(StatusMessage.random());
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
//this is no-op
|
|
226
|
+
registerThisValidatorAddresses(_address: EthAddress[]): void {}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export class DummyReqResp implements ReqRespInterface {
|
|
230
|
+
updateConfig(_config: Partial<P2PReqRespConfig>): void {}
|
|
231
|
+
start(
|
|
232
|
+
_subProtocolHandlers: ReqRespSubProtocolHandlers,
|
|
233
|
+
_subProtocolValidators: ReqRespSubProtocolValidators,
|
|
234
|
+
): Promise<void> {
|
|
235
|
+
return Promise.resolve();
|
|
236
|
+
}
|
|
237
|
+
stop(): Promise<void> {
|
|
238
|
+
return Promise.resolve();
|
|
239
|
+
}
|
|
240
|
+
sendRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
241
|
+
_subProtocol: SubProtocol,
|
|
242
|
+
_request: InstanceType<SubProtocolMap[SubProtocol]['request']>,
|
|
243
|
+
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']> | undefined> {
|
|
244
|
+
return Promise.resolve(undefined);
|
|
245
|
+
}
|
|
246
|
+
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
247
|
+
_subProtocol: SubProtocol,
|
|
248
|
+
_requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
249
|
+
_pinnedPeer: PeerId | undefined,
|
|
250
|
+
_timeoutMs?: number,
|
|
251
|
+
_maxPeers?: number,
|
|
252
|
+
_maxRetryAttempts?: number,
|
|
253
|
+
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
|
|
254
|
+
return Promise.resolve([]);
|
|
255
|
+
}
|
|
256
|
+
public sendRequestToPeer(
|
|
257
|
+
_peerId: PeerId,
|
|
258
|
+
_subProtocol: ReqRespSubProtocol,
|
|
259
|
+
_payload: Buffer,
|
|
260
|
+
_dialTimeout?: number,
|
|
261
|
+
): Promise<ReqRespResponse> {
|
|
262
|
+
return Promise.resolve({ status: ReqRespStatus.SUCCESS, data: Buffer.from([]) });
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
addSubProtocol(
|
|
266
|
+
_subProtocol: ReqRespSubProtocol,
|
|
267
|
+
_handler: ReqRespSubProtocolHandler,
|
|
268
|
+
_validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
269
|
+
): Promise<void> {
|
|
270
|
+
return Promise.resolve();
|
|
271
|
+
}
|
|
272
|
+
}
|