@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.5476d83
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,7 +1,7 @@
|
|
|
1
1
|
import { unfreeze } from '@aztec/foundation/types';
|
|
2
2
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
3
3
|
import { mockTx } from '@aztec/stdlib/testing';
|
|
4
|
-
import type
|
|
4
|
+
import { BlockHeader, GlobalVariables, type Tx } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { TxPool } from './tx_pool.js';
|
|
7
7
|
|
|
@@ -12,79 +12,121 @@ import type { TxPool } from './tx_pool.js';
|
|
|
12
12
|
export function describeTxPool(getTxPool: () => TxPool) {
|
|
13
13
|
let pool: TxPool;
|
|
14
14
|
|
|
15
|
+
const minedBlockHeader = BlockHeader.empty({
|
|
16
|
+
globalVariables: GlobalVariables.empty({ blockNumber: 1, timestamp: 0n }),
|
|
17
|
+
});
|
|
18
|
+
|
|
15
19
|
beforeEach(() => {
|
|
16
20
|
pool = getTxPool();
|
|
17
21
|
});
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
pool.removeAllListeners('txs-added');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('adds txs to the pool as pending', async () => {
|
|
20
28
|
const tx1 = await mockTx();
|
|
21
29
|
|
|
22
30
|
await pool.addTxs([tx1]);
|
|
23
|
-
const poolTx = await pool.getTxByHash(
|
|
24
|
-
expect(
|
|
25
|
-
await expect(pool.getTxStatus(
|
|
26
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
31
|
+
const poolTx = await pool.getTxByHash(tx1.getTxHash());
|
|
32
|
+
expect(poolTx!.getTxHash()).toEqual(tx1.getTxHash());
|
|
33
|
+
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('pending');
|
|
34
|
+
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]);
|
|
35
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
27
36
|
});
|
|
28
37
|
|
|
29
|
-
it('
|
|
30
|
-
const tx1 = await mockTx();
|
|
38
|
+
it('emits txs-added event with new txs', async () => {
|
|
39
|
+
const tx1 = await mockTx(); // existing and pending
|
|
40
|
+
const tx2 = await mockTx(); // mined but not known
|
|
41
|
+
const tx3 = await mockTx(); // brand new
|
|
31
42
|
|
|
32
43
|
await pool.addTxs([tx1]);
|
|
33
|
-
await pool.
|
|
44
|
+
await pool.markAsMined([tx2.getTxHash()], minedBlockHeader);
|
|
45
|
+
|
|
46
|
+
let txsFromEvent: Tx[] | undefined = undefined;
|
|
47
|
+
pool.once('txs-added', ({ txs }) => {
|
|
48
|
+
txsFromEvent = txs;
|
|
49
|
+
});
|
|
34
50
|
|
|
35
|
-
await
|
|
36
|
-
|
|
51
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
52
|
+
expect(txsFromEvent).toBeDefined();
|
|
53
|
+
expect(txsFromEvent).toHaveLength(2);
|
|
54
|
+
expect(txsFromEvent).toEqual(expect.arrayContaining([tx2, tx3]));
|
|
37
55
|
});
|
|
38
56
|
|
|
39
|
-
it('
|
|
57
|
+
it('permanently deletes pending txs and soft-deletes mined txs', async () => {
|
|
58
|
+
const pendingTx = await mockTx(1);
|
|
59
|
+
const minedTx = await mockTx(2);
|
|
60
|
+
|
|
61
|
+
await pool.addTxs([pendingTx, minedTx]);
|
|
62
|
+
await pool.markAsMined([minedTx.getTxHash()], minedBlockHeader);
|
|
63
|
+
|
|
64
|
+
// Delete a pending tx - should be permanently deleted
|
|
65
|
+
await pool.deleteTxs([pendingTx.getTxHash()]);
|
|
66
|
+
await expect(pool.getTxByHash(pendingTx.getTxHash())).resolves.toBeUndefined();
|
|
67
|
+
await expect(pool.getTxStatus(pendingTx.getTxHash())).resolves.toBeUndefined();
|
|
68
|
+
|
|
69
|
+
// Delete a mined tx - should be soft-deleted (still in storage)
|
|
70
|
+
await pool.deleteTxs([minedTx.getTxHash()]);
|
|
71
|
+
await expect(pool.getTxByHash(minedTx.getTxHash())).resolves.toBeDefined();
|
|
72
|
+
await expect(pool.getTxStatus(minedTx.getTxHash())).resolves.toEqual('deleted');
|
|
73
|
+
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
74
|
+
|
|
75
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(0);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('marks txs as mined', async () => {
|
|
40
79
|
const tx1 = await mockTx(1);
|
|
41
80
|
const tx2 = await mockTx(2);
|
|
42
81
|
|
|
43
82
|
await pool.addTxs([tx1, tx2]);
|
|
44
|
-
await pool.markAsMined([
|
|
83
|
+
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
45
84
|
|
|
46
|
-
await expect(pool.getTxByHash(
|
|
47
|
-
await expect(pool.getTxStatus(
|
|
48
|
-
await expect(pool.getMinedTxHashes()).resolves.toEqual([[
|
|
49
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
85
|
+
await expect(pool.getTxByHash(tx1.getTxHash())).resolves.toEqual(tx1);
|
|
86
|
+
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('mined');
|
|
87
|
+
await expect(pool.getMinedTxHashes()).resolves.toEqual([[tx1.getTxHash(), 1]]);
|
|
88
|
+
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx2.getTxHash()]);
|
|
89
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
50
90
|
});
|
|
51
91
|
|
|
52
|
-
it('
|
|
92
|
+
it('marks txs as pending after being mined', async () => {
|
|
53
93
|
const tx1 = await mockTx(1);
|
|
54
94
|
const tx2 = await mockTx(2);
|
|
55
95
|
|
|
56
96
|
await pool.addTxs([tx1, tx2]);
|
|
57
|
-
await pool.markAsMined([
|
|
97
|
+
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
58
98
|
|
|
59
|
-
await pool.markMinedAsPending([
|
|
99
|
+
await pool.markMinedAsPending([tx1.getTxHash()]);
|
|
60
100
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
61
101
|
const pending = await pool.getPendingTxHashes();
|
|
62
102
|
expect(pending).toHaveLength(2);
|
|
63
|
-
expect(pending).toEqual(expect.arrayContaining([
|
|
103
|
+
expect(pending).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash()]));
|
|
104
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(2);
|
|
64
105
|
});
|
|
65
106
|
|
|
66
|
-
it('
|
|
107
|
+
it('only marks txs as pending if they are known', async () => {
|
|
67
108
|
const tx1 = await mockTx(1);
|
|
68
109
|
// simulate a situation where not all peers have all the txs
|
|
69
110
|
const tx2 = await mockTx(2);
|
|
70
|
-
const someTxHashThatThisPeerDidNotSee =
|
|
111
|
+
const someTxHashThatThisPeerDidNotSee = tx2.getTxHash();
|
|
71
112
|
await pool.addTxs([tx1]);
|
|
72
113
|
// this peer knows that tx2 was mined, but it does not have the tx object
|
|
73
|
-
await pool.markAsMined([
|
|
114
|
+
await pool.markAsMined([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], minedBlockHeader);
|
|
74
115
|
expect(await pool.getMinedTxHashes()).toEqual(
|
|
75
116
|
expect.arrayContaining([
|
|
76
|
-
[
|
|
117
|
+
[tx1.getTxHash(), 1],
|
|
77
118
|
[someTxHashThatThisPeerDidNotSee, 1],
|
|
78
119
|
]),
|
|
79
120
|
);
|
|
80
121
|
|
|
81
122
|
// reorg: both txs should now become available again
|
|
82
|
-
await pool.markMinedAsPending([
|
|
123
|
+
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee]);
|
|
83
124
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
84
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
125
|
+
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]); // tx2 is not in the pool
|
|
126
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
85
127
|
});
|
|
86
128
|
|
|
87
|
-
it('
|
|
129
|
+
it('returns all transactions in the pool', async () => {
|
|
88
130
|
const tx1 = await mockTx(1);
|
|
89
131
|
const tx2 = await mockTx(2);
|
|
90
132
|
const tx3 = await mockTx(3);
|
|
@@ -94,9 +136,10 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
94
136
|
const poolTxs = await pool.getAllTxs();
|
|
95
137
|
expect(poolTxs).toHaveLength(3);
|
|
96
138
|
expect(poolTxs).toEqual(expect.arrayContaining([tx1, tx2, tx3]));
|
|
139
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
97
140
|
});
|
|
98
141
|
|
|
99
|
-
it('
|
|
142
|
+
it('returns all txHashes in the pool', async () => {
|
|
100
143
|
const tx1 = await mockTx(1);
|
|
101
144
|
const tx2 = await mockTx(2);
|
|
102
145
|
const tx3 = await mockTx(3);
|
|
@@ -104,13 +147,56 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
104
147
|
await pool.addTxs([tx1, tx2, tx3]);
|
|
105
148
|
|
|
106
149
|
const poolTxHashes = await pool.getAllTxHashes();
|
|
150
|
+
const expectedHashes = [tx1, tx2, tx3].map(tx => tx.getTxHash());
|
|
107
151
|
expect(poolTxHashes).toHaveLength(3);
|
|
108
|
-
expect(poolTxHashes).toEqual(
|
|
109
|
-
|
|
110
|
-
);
|
|
152
|
+
expect(poolTxHashes).toEqual(expect.arrayContaining(expectedHashes));
|
|
153
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
111
154
|
});
|
|
112
155
|
|
|
113
|
-
it('
|
|
156
|
+
it('returns txs by their hash', async () => {
|
|
157
|
+
const tx1 = await mockTx(1);
|
|
158
|
+
const tx2 = await mockTx(2);
|
|
159
|
+
const tx3 = await mockTx(3);
|
|
160
|
+
|
|
161
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
162
|
+
|
|
163
|
+
const requestedTxs = await pool.getTxsByHash([tx1.getTxHash(), tx3.getTxHash()]);
|
|
164
|
+
expect(requestedTxs).toHaveLength(2);
|
|
165
|
+
expect(requestedTxs).toEqual(expect.arrayContaining([tx1, tx3]));
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('returns a large number of transactions by their hash', async () => {
|
|
169
|
+
const numTxs = 1000;
|
|
170
|
+
const txs = await Promise.all(Array.from({ length: numTxs }, (_, i) => mockTx(i)));
|
|
171
|
+
const hashes = txs.map(tx => tx.getTxHash());
|
|
172
|
+
await pool.addTxs(txs);
|
|
173
|
+
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
174
|
+
expect(requestedTxs).toHaveLength(numTxs);
|
|
175
|
+
expect(requestedTxs).toEqual(expect.arrayContaining(txs));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('returns whether or not txs exist', async () => {
|
|
179
|
+
const tx1 = await mockTx(1);
|
|
180
|
+
const tx2 = await mockTx(2);
|
|
181
|
+
const tx3 = await mockTx(3);
|
|
182
|
+
|
|
183
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
184
|
+
|
|
185
|
+
const tx4 = await mockTx(4);
|
|
186
|
+
const tx5 = await mockTx(5);
|
|
187
|
+
|
|
188
|
+
const availability = await pool.hasTxs([
|
|
189
|
+
tx1.getTxHash(),
|
|
190
|
+
tx2.getTxHash(),
|
|
191
|
+
tx3.getTxHash(),
|
|
192
|
+
tx4.getTxHash(),
|
|
193
|
+
tx5.getTxHash(),
|
|
194
|
+
]);
|
|
195
|
+
expect(availability).toHaveLength(5);
|
|
196
|
+
expect(availability).toEqual(expect.arrayContaining([true, true, true, false, false]));
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('returns pending tx hashes sorted by priority', async () => {
|
|
114
200
|
const withPriorityFee = (tx: Tx, fee: number) => {
|
|
115
201
|
unfreeze(tx.data.constants.txContext.gasSettings).maxPriorityFeesPerGas = new GasFees(fee, fee);
|
|
116
202
|
return tx;
|
|
@@ -125,6 +211,103 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
125
211
|
|
|
126
212
|
const poolTxHashes = await pool.getPendingTxHashes();
|
|
127
213
|
expect(poolTxHashes).toHaveLength(4);
|
|
128
|
-
expect(poolTxHashes).toEqual(
|
|
214
|
+
expect(poolTxHashes).toEqual([tx4, tx1, tx3, tx2].map(tx => tx.getTxHash()));
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('soft-delete', () => {
|
|
218
|
+
it('soft-deletes mined txs and keeps them in storage', async () => {
|
|
219
|
+
const txs = await Promise.all([mockTx(1), mockTx(2), mockTx(3)]);
|
|
220
|
+
await pool.addTxs(txs);
|
|
221
|
+
|
|
222
|
+
// Mark first tx as mined
|
|
223
|
+
await pool.markAsMined([txs[0].getTxHash()], minedBlockHeader);
|
|
224
|
+
|
|
225
|
+
// Verify initial state
|
|
226
|
+
await expect(pool.getPendingTxCount()).resolves.toBe(2);
|
|
227
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
228
|
+
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeDefined();
|
|
229
|
+
|
|
230
|
+
// Delete mined tx - should be soft-deleted
|
|
231
|
+
await pool.deleteTxs([txs[0].getTxHash()]);
|
|
232
|
+
|
|
233
|
+
// Delete pending tx - should be permanently deleted
|
|
234
|
+
await pool.deleteTxs([txs[1].getTxHash()]);
|
|
235
|
+
|
|
236
|
+
// Verify mined tx still exists in storage but has 'deleted' status
|
|
237
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
238
|
+
await expect(pool.getTxStatus(txs[0].getTxHash())).resolves.toEqual('deleted');
|
|
239
|
+
|
|
240
|
+
// Verify pending tx is permanently deleted
|
|
241
|
+
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
242
|
+
await expect(pool.getTxStatus(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
243
|
+
|
|
244
|
+
// Verify remaining pending count
|
|
245
|
+
await expect(pool.getPendingTxCount()).resolves.toBe(1);
|
|
246
|
+
|
|
247
|
+
// Verify pending hashes don't include deleted txs
|
|
248
|
+
const pendingHashes = await pool.getPendingTxHashes();
|
|
249
|
+
expect(pendingHashes).toHaveLength(1);
|
|
250
|
+
expect(pendingHashes.map(h => h.toString())).toContain(txs[2].getTxHash().toString());
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('cleans up old deleted mined transactions', async () => {
|
|
254
|
+
const txs = await Promise.all([mockTx(1), mockTx(2), mockTx(3)]);
|
|
255
|
+
await pool.addTxs(txs);
|
|
256
|
+
|
|
257
|
+
// Mark first two as mined in block 1
|
|
258
|
+
await pool.markAsMined([txs[0].getTxHash(), txs[1].getTxHash()], minedBlockHeader);
|
|
259
|
+
|
|
260
|
+
// Soft-delete mined transactions
|
|
261
|
+
await pool.deleteTxs([txs[0].getTxHash(), txs[1].getTxHash()]);
|
|
262
|
+
|
|
263
|
+
// Clean up deleted mined txs from block 1 and earlier
|
|
264
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(1);
|
|
265
|
+
|
|
266
|
+
// Verify old transactions are permanently deleted
|
|
267
|
+
expect(deletedCount).toBe(2);
|
|
268
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeUndefined();
|
|
269
|
+
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
270
|
+
await expect(pool.getTxByHash(txs[2].getTxHash())).resolves.toBeDefined();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('does not clean up recent deleted mined transactions', async () => {
|
|
274
|
+
const txs = await Promise.all([mockTx(1), mockTx(2)]);
|
|
275
|
+
await pool.addTxs(txs);
|
|
276
|
+
|
|
277
|
+
// Mark as mined in block 2
|
|
278
|
+
const laterBlockHeader = BlockHeader.empty({
|
|
279
|
+
globalVariables: GlobalVariables.empty({ blockNumber: 2, timestamp: 0n }),
|
|
280
|
+
});
|
|
281
|
+
await pool.markAsMined([txs[0].getTxHash()], laterBlockHeader);
|
|
282
|
+
|
|
283
|
+
// Soft-delete a mined transaction
|
|
284
|
+
await pool.deleteTxs([txs[0].getTxHash()]);
|
|
285
|
+
|
|
286
|
+
// Try to clean up with block 1 (before the mined block)
|
|
287
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(1);
|
|
288
|
+
|
|
289
|
+
// Verify no transactions were cleaned up
|
|
290
|
+
expect(deletedCount).toBe(0);
|
|
291
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('restores deleted mined tx when it is mined again', async () => {
|
|
295
|
+
const tx = await mockTx(1);
|
|
296
|
+
await pool.addTxs([tx]);
|
|
297
|
+
|
|
298
|
+
// Mark as mined
|
|
299
|
+
await pool.markAsMined([tx.getTxHash()], minedBlockHeader);
|
|
300
|
+
|
|
301
|
+
// Soft-delete it
|
|
302
|
+
await pool.deleteTxs([tx.getTxHash()]);
|
|
303
|
+
await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('deleted');
|
|
304
|
+
|
|
305
|
+
// Mark as mined again (e.g., after a reorg)
|
|
306
|
+
await pool.markAsMined([tx.getTxHash()], minedBlockHeader);
|
|
307
|
+
|
|
308
|
+
// Should be back to mined status
|
|
309
|
+
await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('mined');
|
|
310
|
+
await expect(pool.getTxByHash(tx.getTxHash())).resolves.toBeDefined();
|
|
311
|
+
});
|
|
129
312
|
});
|
|
130
313
|
}
|
|
@@ -1,26 +1,69 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { NoCommitteeError } from '@aztec/ethereum';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
4
|
import { type BlockAttestation, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
3
5
|
|
|
4
6
|
export class AttestationValidator implements P2PValidator<BlockAttestation> {
|
|
5
|
-
|
|
7
|
+
protected epochCache: EpochCacheInterface;
|
|
8
|
+
protected logger: Logger;
|
|
6
9
|
|
|
7
10
|
constructor(epochCache: EpochCacheInterface) {
|
|
8
11
|
this.epochCache = epochCache;
|
|
12
|
+
this.logger = createLogger('p2p:attestation-validator');
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
async validate(message: BlockAttestation): Promise<PeerErrorSeverity | undefined> {
|
|
12
|
-
const
|
|
16
|
+
const slotNumber = message.payload.header.slotNumber;
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
+
try {
|
|
19
|
+
const { currentProposer, nextProposer, currentSlot, nextSlot } =
|
|
20
|
+
await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
|
|
23
|
+
this.logger.warn(`Attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`);
|
|
24
|
+
return PeerErrorSeverity.HighToleranceError;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Verify the signature is valid
|
|
28
|
+
const attester = message.getSender();
|
|
29
|
+
if (attester === undefined) {
|
|
30
|
+
this.logger.warn(`Invalid signature in attestation for slot ${slotNumber}`);
|
|
31
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
32
|
+
}
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
// Verify the attester is in the committee for this slot
|
|
35
|
+
if (!(await this.epochCache.isInCommittee(slotNumber, attester))) {
|
|
36
|
+
this.logger.warn(`Attester ${attester.toString()} is not in committee for slot ${slotNumber}`);
|
|
37
|
+
return PeerErrorSeverity.HighToleranceError;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Verify the proposer signature matches the expected proposer for this slot
|
|
41
|
+
const proposer = message.getProposer();
|
|
42
|
+
const expectedProposer = slotNumber === currentSlot ? currentProposer : nextProposer;
|
|
43
|
+
if (!expectedProposer) {
|
|
44
|
+
this.logger.warn(`No proposer defined for slot ${slotNumber}`);
|
|
45
|
+
return PeerErrorSeverity.HighToleranceError;
|
|
46
|
+
}
|
|
47
|
+
if (!proposer) {
|
|
48
|
+
this.logger.warn(`Invalid proposer signature in attestation for slot ${slotNumber}`);
|
|
49
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
50
|
+
}
|
|
51
|
+
if (!proposer.equals(expectedProposer)) {
|
|
52
|
+
this.logger.warn(
|
|
53
|
+
`Proposer signature mismatch in attestation. ` +
|
|
54
|
+
`Expected ${expectedProposer?.toString() ?? 'none'} but got ${proposer.toString()} for slot ${slotNumber}`,
|
|
55
|
+
);
|
|
56
|
+
return PeerErrorSeverity.HighToleranceError;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return undefined;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// People shouldn't be sending us attestations if the committee doesn't exist
|
|
62
|
+
if (e instanceof NoCommitteeError) {
|
|
63
|
+
this.logger.warn(`No committee exists for attestation for slot ${slotNumber}`);
|
|
64
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
65
|
+
}
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
25
68
|
}
|
|
26
69
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { type BlockAttestation, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
3
|
+
import { Attributes, Metrics, type TelemetryClient, ValueType } from '@aztec/telemetry-client';
|
|
4
|
+
|
|
5
|
+
import type { AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js';
|
|
6
|
+
import { AttestationValidator } from './attestation_validator.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* FishermanAttestationValidator extends the base AttestationValidator to add
|
|
10
|
+
* additional validation for fisherman nodes: verifying that attestations sign
|
|
11
|
+
* the same payload as the original proposal.
|
|
12
|
+
* Invalid attestations are rejected (not propagated), but peer penalization is
|
|
13
|
+
* handled by LibP2PService based on the fishermanMode config to ensure a better
|
|
14
|
+
* view of the network.
|
|
15
|
+
*/
|
|
16
|
+
export class FishermanAttestationValidator extends AttestationValidator {
|
|
17
|
+
private invalidAttestationCounter;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
epochCache: EpochCacheInterface,
|
|
21
|
+
private attestationPool: AttestationPool,
|
|
22
|
+
telemetryClient: TelemetryClient,
|
|
23
|
+
) {
|
|
24
|
+
super(epochCache);
|
|
25
|
+
this.logger = this.logger.createChild('[FISHERMAN]');
|
|
26
|
+
|
|
27
|
+
const meter = telemetryClient.getMeter('FishermanAttestationValidator');
|
|
28
|
+
this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT, {
|
|
29
|
+
description: 'The number of invalid attestations received',
|
|
30
|
+
valueType: ValueType.INT,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override async validate(message: BlockAttestation): Promise<PeerErrorSeverity | undefined> {
|
|
35
|
+
// First run the standard validation
|
|
36
|
+
const baseValidationResult = await super.validate(message);
|
|
37
|
+
if (baseValidationResult !== undefined) {
|
|
38
|
+
// Track base validation failures (invalid signature, wrong committee, etc.)
|
|
39
|
+
this.invalidAttestationCounter.add(1, {
|
|
40
|
+
[Attributes.ERROR_TYPE]: 'base_validation_failed',
|
|
41
|
+
});
|
|
42
|
+
return baseValidationResult;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// fisherman validation: verify attestation payload matches proposal payload
|
|
46
|
+
const slotNumberBigInt = message.payload.header.slotNumber;
|
|
47
|
+
const attester = message.getSender();
|
|
48
|
+
const proposer = message.getProposer();
|
|
49
|
+
|
|
50
|
+
if (!attester || !proposer) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const proposalId = message.archive.toString();
|
|
55
|
+
const proposal = await this.attestationPool.getBlockProposal(proposalId);
|
|
56
|
+
|
|
57
|
+
if (proposal) {
|
|
58
|
+
// Compare the attestation payload with the proposal payload
|
|
59
|
+
if (!message.payload.equals(proposal.payload)) {
|
|
60
|
+
this.logger.error(
|
|
61
|
+
`Attestation payload mismatch for slot ${slotNumberBigInt}! ` +
|
|
62
|
+
`Attester ${attester.toString()} signed different data than the proposal.`,
|
|
63
|
+
{
|
|
64
|
+
slot: slotNumberBigInt.toString(),
|
|
65
|
+
attester: attester.toString(),
|
|
66
|
+
proposer: proposer.toString(),
|
|
67
|
+
proposalArchive: proposal.archive.toString(),
|
|
68
|
+
attestationArchive: message.archive.toString(),
|
|
69
|
+
proposalHeader: proposal.payload.header.hash().toString(),
|
|
70
|
+
attestationHeader: message.payload.header.hash().toString(),
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// Track invalid attestation metric
|
|
75
|
+
this.invalidAttestationCounter.add(1, {
|
|
76
|
+
[Attributes.ERROR_TYPE]: 'payload_mismatch',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Return error to reject the message, but LibP2PService won't penalize in fisherman mode
|
|
80
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
// We might receive attestations before proposals in some cases
|
|
84
|
+
this.logger.debug(
|
|
85
|
+
`Received attestation for slot ${slotNumberBigInt} but proposal not found yet. ` + `Proposal ID: ${proposalId}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,29 +1,97 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { NoCommitteeError } from '@aztec/ethereum';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
4
|
import { type BlockProposal, type P2PValidator, PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
3
5
|
|
|
4
6
|
export class BlockProposalValidator implements P2PValidator<BlockProposal> {
|
|
5
7
|
private epochCache: EpochCacheInterface;
|
|
8
|
+
private logger: Logger;
|
|
9
|
+
private txsPermitted: boolean;
|
|
6
10
|
|
|
7
|
-
constructor(epochCache: EpochCacheInterface) {
|
|
11
|
+
constructor(epochCache: EpochCacheInterface, opts: { txsPermitted: boolean }) {
|
|
8
12
|
this.epochCache = epochCache;
|
|
13
|
+
this.txsPermitted = opts.txsPermitted;
|
|
14
|
+
this.logger = createLogger('p2p:block_proposal_validator');
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
async validate(block: BlockProposal): Promise<PeerErrorSeverity | undefined> {
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
try {
|
|
19
|
+
// Check signature validity first - invalid signatures are a high-severity issue
|
|
20
|
+
const proposer = block.getSender();
|
|
21
|
+
if (!proposer) {
|
|
22
|
+
this.logger.debug(`Penalizing peer for block proposal with invalid signature`);
|
|
23
|
+
return PeerErrorSeverity.MidToleranceError;
|
|
24
|
+
}
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
// Check if transactions are permitted when the proposal contains transaction hashes
|
|
27
|
+
const embeddedTxCount = block.txs?.length ?? 0;
|
|
28
|
+
if (!this.txsPermitted && (block.txHashes.length > 0 || embeddedTxCount > 0)) {
|
|
29
|
+
this.logger.debug(
|
|
30
|
+
`Penalizing peer for block proposal with ${block.txHashes.length} transaction(s) when transactions are not permitted`,
|
|
31
|
+
);
|
|
32
|
+
return PeerErrorSeverity.MidToleranceError;
|
|
33
|
+
}
|
|
20
34
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
// If there are embedded txs, they must be listed in txHashes; if there are no txHashes, there must be no txs
|
|
36
|
+
const hashSet = new Set(block.txHashes.map(h => h.toString()));
|
|
37
|
+
const missingTxHashes =
|
|
38
|
+
embeddedTxCount > 0
|
|
39
|
+
? block.txs!.filter(tx => !hashSet.has(tx.getTxHash().toString())).map(tx => tx.getTxHash().toString())
|
|
40
|
+
: [];
|
|
41
|
+
if (embeddedTxCount > 0 && missingTxHashes.length > 0) {
|
|
42
|
+
this.logger.warn('Penalizing peer for embedded transaction(s) not included in txHashes', {
|
|
43
|
+
embeddedTxCount,
|
|
44
|
+
txHashesLength: block.txHashes.length,
|
|
45
|
+
missingTxHashes,
|
|
46
|
+
});
|
|
47
|
+
return PeerErrorSeverity.MidToleranceError;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const { currentProposer, nextProposer, currentSlot, nextSlot } =
|
|
51
|
+
await this.epochCache.getProposerAttesterAddressInCurrentOrNextSlot();
|
|
52
|
+
|
|
53
|
+
// Check that the attestation is for the current or next slot
|
|
54
|
+
const slotNumber = block.payload.header.slotNumber;
|
|
55
|
+
if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
|
|
56
|
+
this.logger.debug(`Penalizing peer for invalid slot number ${slotNumber}`, { currentSlot, nextSlot });
|
|
57
|
+
return PeerErrorSeverity.HighToleranceError;
|
|
58
|
+
}
|
|
26
59
|
|
|
27
|
-
|
|
60
|
+
// Check that the block proposal is from the current or next proposer
|
|
61
|
+
if (slotNumber === currentSlot && currentProposer !== undefined && !proposer.equals(currentProposer)) {
|
|
62
|
+
this.logger.debug(`Penalizing peer for invalid proposer for current slot ${slotNumber}`, {
|
|
63
|
+
currentProposer,
|
|
64
|
+
nextProposer,
|
|
65
|
+
proposer: proposer.toString(),
|
|
66
|
+
});
|
|
67
|
+
return PeerErrorSeverity.MidToleranceError;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (slotNumber === nextSlot && nextProposer !== undefined && !proposer.equals(nextProposer)) {
|
|
71
|
+
this.logger.debug(`Penalizing peer for invalid proposer for next slot ${slotNumber}`, {
|
|
72
|
+
currentProposer,
|
|
73
|
+
nextProposer,
|
|
74
|
+
proposer: proposer.toString(),
|
|
75
|
+
});
|
|
76
|
+
return PeerErrorSeverity.MidToleranceError;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Validate tx hashes for all txs embedded in the proposal
|
|
80
|
+
if (!(await Promise.all(block.txs?.map(tx => tx.validateTxHash()) ?? [])).every(v => v)) {
|
|
81
|
+
this.logger.warn(`Penalizing peer for invalid tx hashes in block proposal`, {
|
|
82
|
+
proposer,
|
|
83
|
+
slotNumber,
|
|
84
|
+
});
|
|
85
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return undefined;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
// People shouldn't be sending us block proposals if the committee doesn't exist
|
|
91
|
+
if (e instanceof NoCommitteeError) {
|
|
92
|
+
return PeerErrorSeverity.LowToleranceError;
|
|
93
|
+
}
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
28
96
|
}
|
|
29
97
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Implements a queue of message IDs
|
|
2
|
+
export class MessageSeenValidator {
|
|
3
|
+
private queue: Array<string>;
|
|
4
|
+
private writePointer = 0;
|
|
5
|
+
private seenMessages: Set<string> = new Set();
|
|
6
|
+
|
|
7
|
+
constructor(private queueLength: number) {
|
|
8
|
+
if (this.queueLength <= 0) {
|
|
9
|
+
throw new Error('Queue length must be greater than 0');
|
|
10
|
+
}
|
|
11
|
+
this.queue = new Array<string>(this.queueLength);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Adds a message if not seen before. Returns true if added, false if already seen.
|
|
15
|
+
public addMessage(msgId: string): boolean {
|
|
16
|
+
// Check if the message is already in the cache
|
|
17
|
+
if (this.seenMessages.has(msgId)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// If we are at the cache limit, remove the oldest msg ID
|
|
21
|
+
if (this.seenMessages.size >= this.queueLength) {
|
|
22
|
+
const msgToRemove = this.queue[this.writePointer];
|
|
23
|
+
this.seenMessages.delete(msgToRemove);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Insert the message into the cache and the queue
|
|
27
|
+
this.seenMessages.add(msgId);
|
|
28
|
+
this.queue[this.writePointer] = msgId;
|
|
29
|
+
this.writePointer = this.writePointer === this.queueLength - 1 ? 0 : this.writePointer + 1;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public size() {
|
|
34
|
+
return this.seenMessages.size;
|
|
35
|
+
}
|
|
36
|
+
}
|