@aztec/p2p 0.0.1-commit.b655e406 → 0.0.1-commit.c31f2472
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 +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +4 -4
- package/dest/client/factory.d.ts +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +8 -8
- package/dest/client/index.d.ts +1 -1
- package/dest/client/interface.d.ts +18 -3
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +16 -37
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +464 -126
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +69 -60
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -14
- package/dest/enr/generate-enr.d.ts +1 -1
- 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 +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +77 -36
- 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 +241 -266
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +24 -14
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +123 -95
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +18 -12
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +91 -108
- package/dest/mem_pools/attestation_pool/mocks.d.ts +234 -10
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +17 -13
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +9 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +37 -10
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +33 -58
- 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 +314 -335
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -6
- 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 +30 -24
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +7 -6
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +57 -24
- 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 +76 -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/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -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 +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +4 -3
- 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 -3
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +4 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -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 +3 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +10 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +22 -12
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +4 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +6 -4
- package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +5 -3
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
- 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 +1 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/dummy_service.d.ts +18 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +42 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +36 -71
- package/dest/services/libp2p/libp2p_service.d.ts +48 -81
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +926 -193
- package/dest/services/peer-manager/interface.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts +9 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +39 -16
- package/dest/services/peer-manager/peer_manager.d.ts +2 -33
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +6 -12
- 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 +43 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/config.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/index.d.ts +1 -1
- package/dest/services/reqresp/interface.d.ts +4 -2
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +1 -1
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -21
- package/dest/services/reqresp/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +14 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +17 -7
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +34 -4
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/ping.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +6 -5
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -3
- package/dest/services/reqresp/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts +6 -41
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +460 -46
- package/dest/services/reqresp/status.d.ts +2 -2
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/service.d.ts +19 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +4 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +10 -2
- package/dest/services/tx_collection/fast_tx_collection.d.ts +9 -12
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +16 -5
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +10 -13
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +4 -5
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +2 -1
- package/dest/services/tx_collection/tx_collection.d.ts +10 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +5 -5
- package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.d.ts +1 -1
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +4 -2
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +11 -2
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +14 -14
- 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 +3 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +2 -0
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-tx-helpers.d.ts +2 -2
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -1
- package/dest/test-helpers/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +156 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +296 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +218 -120
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts +51 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +226 -39
- package/dest/types/index.d.ts +1 -1
- package/dest/util.d.ts +2 -1
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +11 -2
- package/dest/versioning.d.ts +1 -1
- package/package.json +19 -18
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +11 -20
- package/src/client/interface.ts +20 -2
- package/src/client/p2p_client.ts +108 -155
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +36 -20
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +86 -35
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +243 -278
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +175 -111
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +147 -136
- package/src/mem_pools/attestation_pool/mocks.ts +21 -15
- package/src/mem_pools/instrumentation.ts +48 -10
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +367 -371
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
- package/src/msg_validators/attestation_validator/attestation_validator.ts +45 -32
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +94 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +8 -5
- package/src/msg_validators/tx_validator/data_validator.ts +18 -6
- package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
- package/src/msg_validators/tx_validator/factory.ts +67 -25
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +19 -8
- package/src/msg_validators/tx_validator/phases_validator.ts +8 -4
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +11 -5
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +51 -0
- package/src/services/encoding.ts +6 -5
- package/src/services/libp2p/instrumentation.ts +39 -71
- package/src/services/libp2p/libp2p_service.ts +628 -194
- package/src/services/peer-manager/metrics.ts +44 -16
- package/src/services/peer-manager/peer_manager.ts +7 -4
- package/src/services/peer-manager/peer_scoring.ts +45 -3
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +4 -1
- package/src/services/reqresp/metrics.ts +36 -27
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +16 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -5
- package/src/services/reqresp/protocols/status.ts +16 -12
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/reqresp/reqresp.ts +66 -19
- package/src/services/service.ts +23 -4
- package/src/services/tx_collection/config.ts +16 -2
- package/src/services/tx_collection/fast_tx_collection.ts +39 -15
- package/src/services/tx_collection/index.ts +5 -0
- package/src/services/tx_collection/instrumentation.ts +5 -13
- package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
- package/src/services/tx_collection/slow_tx_collection.ts +5 -4
- package/src/services/tx_collection/tx_collection.ts +10 -9
- package/src/services/tx_provider.ts +19 -3
- package/src/services/tx_provider_instrumentation.ts +24 -14
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/mock-pubsub.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +372 -0
- package/src/testbench/p2p_client_testbench_worker.ts +338 -116
- package/src/testbench/worker_client_manager.ts +304 -42
- package/src/util.ts +12 -2
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -70
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -81
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { SerialQueue } from '@aztec/foundation/queue';
|
|
6
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
7
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
8
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
9
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
10
9
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
11
|
-
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
10
|
+
import type { EthAddress, L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
11
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
13
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
14
13
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
15
14
|
import {
|
|
16
|
-
BlockAttestation,
|
|
17
15
|
BlockProposal,
|
|
16
|
+
CheckpointAttestation,
|
|
17
|
+
CheckpointProposal,
|
|
18
|
+
type CheckpointProposalCore,
|
|
18
19
|
type Gossipable,
|
|
19
20
|
P2PClientType,
|
|
20
21
|
P2PMessage,
|
|
22
|
+
type ValidationResult as P2PValidationResult,
|
|
21
23
|
PeerErrorSeverity,
|
|
22
24
|
TopicType,
|
|
23
25
|
createTopicString,
|
|
@@ -28,7 +30,14 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
28
30
|
import { Tx, type TxHash, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
29
31
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
30
32
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
31
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
Attributes,
|
|
35
|
+
OtelMetricsAdapter,
|
|
36
|
+
SpanStatusCode,
|
|
37
|
+
type TelemetryClient,
|
|
38
|
+
WithTracer,
|
|
39
|
+
trackSpan,
|
|
40
|
+
} from '@aztec/telemetry-client';
|
|
32
41
|
|
|
33
42
|
import {
|
|
34
43
|
type GossipSub,
|
|
@@ -50,18 +59,22 @@ import { ENR } from '@nethermindeth/enr';
|
|
|
50
59
|
import { createLibp2p } from 'libp2p';
|
|
51
60
|
|
|
52
61
|
import type { P2PConfig } from '../../config.js';
|
|
62
|
+
import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
|
|
53
63
|
import type { MemPools } from '../../mem_pools/interface.js';
|
|
54
|
-
import {
|
|
64
|
+
import {
|
|
65
|
+
BlockProposalValidator,
|
|
66
|
+
CheckpointAttestationValidator,
|
|
67
|
+
CheckpointProposalValidator,
|
|
68
|
+
FishermanAttestationValidator,
|
|
69
|
+
} from '../../msg_validators/index.js';
|
|
55
70
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
56
71
|
import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
|
|
57
|
-
import { type MessageValidator, createTxMessageValidators } from '../../msg_validators/tx_validator/factory.js';
|
|
58
72
|
import {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} from '../../msg_validators/tx_validator/index.js';
|
|
73
|
+
type MessageValidator,
|
|
74
|
+
createTxMessageValidators,
|
|
75
|
+
createTxReqRespValidator,
|
|
76
|
+
} from '../../msg_validators/tx_validator/factory.js';
|
|
77
|
+
import { DoubleSpendTxValidator } from '../../msg_validators/tx_validator/index.js';
|
|
65
78
|
import { GossipSubEvent } from '../../types/index.js';
|
|
66
79
|
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
67
80
|
import { getVersions } from '../../versioning.js';
|
|
@@ -72,10 +85,12 @@ import { gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
|
72
85
|
import type { PeerManagerInterface } from '../peer-manager/interface.js';
|
|
73
86
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
74
87
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
88
|
+
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
75
89
|
import type { P2PReqRespConfig } from '../reqresp/config.js';
|
|
76
90
|
import {
|
|
77
91
|
DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
78
92
|
type ReqRespInterface,
|
|
93
|
+
type ReqRespResponse,
|
|
79
94
|
ReqRespSubProtocol,
|
|
80
95
|
type ReqRespSubProtocolHandler,
|
|
81
96
|
type ReqRespSubProtocolHandlers,
|
|
@@ -96,7 +111,12 @@ import {
|
|
|
96
111
|
reqRespTxHandler,
|
|
97
112
|
} from '../reqresp/protocols/index.js';
|
|
98
113
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
99
|
-
import type {
|
|
114
|
+
import type {
|
|
115
|
+
P2PBlockReceivedCallback,
|
|
116
|
+
P2PCheckpointReceivedCallback,
|
|
117
|
+
P2PService,
|
|
118
|
+
PeerDiscoveryService,
|
|
119
|
+
} from '../service.js';
|
|
100
120
|
import { P2PInstrumentation } from './instrumentation.js';
|
|
101
121
|
|
|
102
122
|
interface ValidationResult {
|
|
@@ -116,18 +136,18 @@ type ReceivedMessageValidationResult<T> =
|
|
|
116
136
|
* Lib P2P implementation of the P2PService interface.
|
|
117
137
|
*/
|
|
118
138
|
export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends WithTracer implements P2PService {
|
|
119
|
-
private jobQueue: SerialQueue = new SerialQueue();
|
|
120
139
|
private discoveryRunningPromise?: RunningPromise;
|
|
121
140
|
private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
|
|
122
141
|
|
|
123
142
|
// Message validators
|
|
124
|
-
private attestationValidator: AttestationValidator;
|
|
125
143
|
private blockProposalValidator: BlockProposalValidator;
|
|
144
|
+
private checkpointProposalValidator: CheckpointProposalValidator;
|
|
145
|
+
private checkpointAttestationValidator: CheckpointAttestationValidator;
|
|
126
146
|
|
|
127
147
|
private protocolVersion = '';
|
|
128
148
|
private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
|
|
129
149
|
|
|
130
|
-
private feesCache: { blockNumber:
|
|
150
|
+
private feesCache: { blockNumber: BlockNumber; gasFees: GasFees } | undefined;
|
|
131
151
|
|
|
132
152
|
/**
|
|
133
153
|
* Callback for when a block is received from a peer.
|
|
@@ -136,10 +156,21 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
136
156
|
*/
|
|
137
157
|
private blockReceivedCallback: P2PBlockReceivedCallback;
|
|
138
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Callback for when a checkpoint proposal is received from a peer.
|
|
161
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
162
|
+
* @returns The attestations for the checkpoint, if any.
|
|
163
|
+
*/
|
|
164
|
+
private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
165
|
+
|
|
139
166
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
140
167
|
|
|
141
168
|
private instrumentation: P2PInstrumentation;
|
|
142
169
|
|
|
170
|
+
private telemetry: TelemetryClient;
|
|
171
|
+
|
|
172
|
+
protected logger: Logger;
|
|
173
|
+
|
|
143
174
|
constructor(
|
|
144
175
|
private clientType: T,
|
|
145
176
|
private config: P2PConfig,
|
|
@@ -147,21 +178,26 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
147
178
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
148
179
|
private reqresp: ReqRespInterface,
|
|
149
180
|
private peerManager: PeerManagerInterface,
|
|
150
|
-
protected mempools: MemPools
|
|
181
|
+
protected mempools: MemPools,
|
|
151
182
|
private archiver: L2BlockSource & ContractDataSource,
|
|
152
183
|
private epochCache: EpochCacheInterface,
|
|
153
184
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
154
185
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
155
186
|
telemetry: TelemetryClient,
|
|
156
|
-
|
|
187
|
+
logger: Logger = createLogger('p2p:libp2p_service'),
|
|
157
188
|
) {
|
|
158
189
|
super(telemetry, 'LibP2PService');
|
|
190
|
+
this.telemetry = telemetry;
|
|
191
|
+
|
|
192
|
+
// Create child logger with fisherman prefix if in fisherman mode
|
|
193
|
+
this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
|
|
159
194
|
|
|
160
195
|
this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
|
|
161
196
|
|
|
162
197
|
this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
163
198
|
this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
164
|
-
this.msgIdSeenValidators[TopicType.
|
|
199
|
+
this.msgIdSeenValidators[TopicType.checkpoint_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
200
|
+
this.msgIdSeenValidators[TopicType.checkpoint_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
165
201
|
|
|
166
202
|
const versions = getVersions(config);
|
|
167
203
|
this.protocolVersion = compressComponentVersions(versions);
|
|
@@ -169,22 +205,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
169
205
|
|
|
170
206
|
this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
|
|
171
207
|
this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
|
|
172
|
-
this.topicStrings[TopicType.
|
|
173
|
-
TopicType.
|
|
208
|
+
this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(
|
|
209
|
+
TopicType.checkpoint_proposal,
|
|
210
|
+
this.protocolVersion,
|
|
211
|
+
);
|
|
212
|
+
this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(
|
|
213
|
+
TopicType.checkpoint_attestation,
|
|
174
214
|
this.protocolVersion,
|
|
175
215
|
);
|
|
176
216
|
|
|
177
|
-
this.attestationValidator = new AttestationValidator(epochCache);
|
|
178
217
|
this.blockProposalValidator = new BlockProposalValidator(epochCache, { txsPermitted: !config.disableTransactions });
|
|
218
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
|
|
219
|
+
txsPermitted: !config.disableTransactions,
|
|
220
|
+
});
|
|
221
|
+
this.checkpointAttestationValidator = config.fishermanMode
|
|
222
|
+
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
223
|
+
: new CheckpointAttestationValidator(epochCache);
|
|
179
224
|
|
|
180
225
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
181
226
|
|
|
182
|
-
this.blockReceivedCallback = async (block: BlockProposal): Promise<
|
|
227
|
+
this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
|
|
183
228
|
this.logger.debug(
|
|
184
|
-
`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber
|
|
185
|
-
{ p2pMessageIdentifier: await block.
|
|
229
|
+
`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`,
|
|
230
|
+
{ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
|
|
186
231
|
);
|
|
187
|
-
return
|
|
232
|
+
return false;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
this.checkpointReceivedCallback = (
|
|
236
|
+
checkpoint: CheckpointProposalCore,
|
|
237
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
238
|
+
this.logger.debug(
|
|
239
|
+
`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
|
|
240
|
+
);
|
|
241
|
+
return Promise.resolve(undefined);
|
|
188
242
|
};
|
|
189
243
|
}
|
|
190
244
|
|
|
@@ -203,7 +257,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
203
257
|
config: P2PConfig,
|
|
204
258
|
peerId: PeerId,
|
|
205
259
|
deps: {
|
|
206
|
-
mempools: MemPools
|
|
260
|
+
mempools: MemPools;
|
|
207
261
|
l2BlockSource: L2BlockSource & ContractDataSource;
|
|
208
262
|
epochCache: EpochCacheInterface;
|
|
209
263
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
@@ -230,14 +284,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
230
284
|
|
|
231
285
|
const datastore = new AztecDatastore(peerStore);
|
|
232
286
|
|
|
233
|
-
const otelMetricsAdapter = new OtelMetricsAdapter(telemetry);
|
|
287
|
+
const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
|
|
234
288
|
|
|
235
289
|
const peerDiscoveryService = new DiscV5Service(
|
|
236
290
|
peerId,
|
|
237
291
|
config,
|
|
238
292
|
packageVersion,
|
|
239
293
|
telemetry,
|
|
240
|
-
createLogger(`${logger.module}:discv5_service
|
|
294
|
+
createLogger(`${logger.module}:discv5_service`, logger.getBindings()),
|
|
241
295
|
);
|
|
242
296
|
|
|
243
297
|
// Seed libp2p's bootstrap discovery with private and trusted peers
|
|
@@ -253,7 +307,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
253
307
|
|
|
254
308
|
const txTopic = createTopicString(TopicType.tx, protocolVersion);
|
|
255
309
|
const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
|
|
256
|
-
const
|
|
310
|
+
const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
|
|
311
|
+
const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
|
|
257
312
|
|
|
258
313
|
const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
|
|
259
314
|
const directPeers = (
|
|
@@ -375,12 +430,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
375
430
|
invalidMessageDeliveriesWeight: -20,
|
|
376
431
|
invalidMessageDeliveriesDecay: 0.5,
|
|
377
432
|
}),
|
|
378
|
-
[
|
|
433
|
+
[blockProposalTopic]: createTopicScoreParams({
|
|
379
434
|
topicWeight: 1,
|
|
380
435
|
invalidMessageDeliveriesWeight: -20,
|
|
381
436
|
invalidMessageDeliveriesDecay: 0.5,
|
|
382
437
|
}),
|
|
383
|
-
[
|
|
438
|
+
[checkpointProposalTopic]: createTopicScoreParams({
|
|
439
|
+
topicWeight: 1,
|
|
440
|
+
invalidMessageDeliveriesWeight: -20,
|
|
441
|
+
invalidMessageDeliveriesDecay: 0.5,
|
|
442
|
+
}),
|
|
443
|
+
[checkpointAttestationTopic]: createTopicScoreParams({
|
|
384
444
|
topicWeight: 1,
|
|
385
445
|
invalidMessageDeliveriesWeight: -20,
|
|
386
446
|
invalidMessageDeliveriesDecay: 0.5,
|
|
@@ -392,10 +452,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
392
452
|
connectionManager: components.connectionManager,
|
|
393
453
|
}),
|
|
394
454
|
},
|
|
395
|
-
logger: createLibp2pComponentLogger(logger.module),
|
|
455
|
+
logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
|
|
396
456
|
});
|
|
397
457
|
|
|
398
|
-
const peerScoring = new PeerScoring(config);
|
|
458
|
+
const peerScoring = new PeerScoring(config, telemetry);
|
|
399
459
|
const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
|
|
400
460
|
|
|
401
461
|
const peerManager = new PeerManager(
|
|
@@ -450,20 +510,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
450
510
|
}
|
|
451
511
|
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
452
512
|
|
|
453
|
-
// Start job queue, peer discovery service and libp2p node
|
|
454
|
-
this.jobQueue.start();
|
|
455
|
-
|
|
456
|
-
await this.peerManager.initializePeers();
|
|
457
|
-
if (!this.config.p2pDiscoveryDisabled) {
|
|
458
|
-
await this.peerDiscoveryService.start();
|
|
459
|
-
}
|
|
460
|
-
await this.node.start();
|
|
461
|
-
|
|
462
|
-
// Subscribe to standard GossipSub topics by default
|
|
463
|
-
for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
|
|
464
|
-
this.subscribeToTopic(this.topicStrings[topic]);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
513
|
// Create request response protocol handlers
|
|
468
514
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
469
515
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
@@ -477,8 +523,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
477
523
|
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
478
524
|
};
|
|
479
525
|
|
|
480
|
-
|
|
481
|
-
if (this.mempools.attestationPool && !this.config.disableTransactions) {
|
|
526
|
+
if (!this.config.disableTransactions) {
|
|
482
527
|
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
|
|
483
528
|
requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
|
|
484
529
|
}
|
|
@@ -487,25 +532,41 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
487
532
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
488
533
|
}
|
|
489
534
|
|
|
535
|
+
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
536
|
+
const reqrespSubProtocolValidators = {
|
|
537
|
+
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
538
|
+
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
539
|
+
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
540
|
+
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
await this.peerManager.initializePeers();
|
|
544
|
+
|
|
545
|
+
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
546
|
+
|
|
547
|
+
await this.node.start();
|
|
548
|
+
|
|
549
|
+
// Subscribe to standard GossipSub topics by default
|
|
550
|
+
for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
|
|
551
|
+
this.subscribeToTopic(this.topicStrings[topic]);
|
|
552
|
+
}
|
|
553
|
+
|
|
490
554
|
// add GossipSub listener
|
|
491
555
|
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
492
556
|
|
|
493
|
-
// Start running promise for peer discovery
|
|
557
|
+
// Start running promise for peer discovery and metrics collection
|
|
558
|
+
if (!this.config.p2pDiscoveryDisabled) {
|
|
559
|
+
await this.peerDiscoveryService.start();
|
|
560
|
+
}
|
|
494
561
|
this.discoveryRunningPromise = new RunningPromise(
|
|
495
|
-
() =>
|
|
562
|
+
async () => {
|
|
563
|
+
await this.peerManager.heartbeat();
|
|
564
|
+
},
|
|
496
565
|
this.logger,
|
|
497
566
|
this.config.peerCheckIntervalMS,
|
|
498
567
|
);
|
|
499
568
|
this.discoveryRunningPromise.start();
|
|
500
569
|
|
|
501
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
502
|
-
const reqrespSubProtocolValidators = {
|
|
503
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
504
|
-
// TODO(#11336): A request validator for blocks
|
|
505
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
506
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
507
|
-
};
|
|
508
|
-
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
509
570
|
this.logger.info(`Started P2P service`, {
|
|
510
571
|
listen: this.config.listenAddress,
|
|
511
572
|
port: this.config.p2pPort,
|
|
@@ -525,9 +586,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
525
586
|
// Stop peer manager
|
|
526
587
|
this.logger.debug('Stopping peer manager...');
|
|
527
588
|
await this.peerManager.stop();
|
|
528
|
-
|
|
529
|
-
this.logger.debug('Stopping job queue...');
|
|
530
|
-
await this.jobQueue.end();
|
|
531
589
|
this.logger.debug('Stopping running promise...');
|
|
532
590
|
await this.discoveryRunningPromise?.stop();
|
|
533
591
|
this.logger.debug('Stopping peer discovery service...');
|
|
@@ -582,6 +640,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
582
640
|
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
583
641
|
}
|
|
584
642
|
|
|
643
|
+
public sendRequestToPeer(
|
|
644
|
+
peerId: PeerId,
|
|
645
|
+
subProtocol: ReqRespSubProtocol,
|
|
646
|
+
payload: Buffer,
|
|
647
|
+
dialTimeout?: number,
|
|
648
|
+
): Promise<ReqRespResponse> {
|
|
649
|
+
return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
|
|
650
|
+
}
|
|
651
|
+
|
|
585
652
|
/**
|
|
586
653
|
* Get the ENR of the node
|
|
587
654
|
* @returns The ENR of the node
|
|
@@ -594,6 +661,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
594
661
|
this.blockReceivedCallback = callback;
|
|
595
662
|
}
|
|
596
663
|
|
|
664
|
+
public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
665
|
+
this.checkpointReceivedCallback = callback;
|
|
666
|
+
}
|
|
667
|
+
|
|
597
668
|
/**
|
|
598
669
|
* Subscribes to a topic.
|
|
599
670
|
* @param topic - The topic to subscribe to.
|
|
@@ -615,7 +686,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
615
686
|
if (!this.node.services.pubsub) {
|
|
616
687
|
throw new Error('Pubsub service not available.');
|
|
617
688
|
}
|
|
618
|
-
const
|
|
689
|
+
const isBlockProposal = topic === this.topicStrings[TopicType.block_proposal];
|
|
690
|
+
const traceContext =
|
|
691
|
+
this.config.debugP2PInstrumentMessages && isBlockProposal ? this.telemetry.getTraceContext() : undefined;
|
|
692
|
+
const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages, traceContext);
|
|
619
693
|
const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
|
|
620
694
|
return result.recipients.length;
|
|
621
695
|
}
|
|
@@ -636,12 +710,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
636
710
|
case this.topicStrings[TopicType.tx]:
|
|
637
711
|
topicType = TopicType.tx;
|
|
638
712
|
break;
|
|
639
|
-
case this.topicStrings[TopicType.block_attestation]:
|
|
640
|
-
topicType = TopicType.block_attestation;
|
|
641
|
-
break;
|
|
642
713
|
case this.topicStrings[TopicType.block_proposal]:
|
|
643
714
|
topicType = TopicType.block_proposal;
|
|
644
715
|
break;
|
|
716
|
+
case this.topicStrings[TopicType.checkpoint_proposal]:
|
|
717
|
+
topicType = TopicType.checkpoint_proposal;
|
|
718
|
+
break;
|
|
719
|
+
case this.topicStrings[TopicType.checkpoint_attestation]:
|
|
720
|
+
topicType = TopicType.checkpoint_attestation;
|
|
721
|
+
break;
|
|
645
722
|
default:
|
|
646
723
|
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
647
724
|
break;
|
|
@@ -660,13 +737,39 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
660
737
|
return { result: true, topicType };
|
|
661
738
|
}
|
|
662
739
|
|
|
740
|
+
/**
|
|
741
|
+
* Safely deserializes a P2PMessage from raw message data.
|
|
742
|
+
* @param msgId - The message ID.
|
|
743
|
+
* @param source - The peer ID of the message source.
|
|
744
|
+
* @param data - The raw message data.
|
|
745
|
+
* @returns The deserialized P2PMessage or undefined if deserialization fails.
|
|
746
|
+
*/
|
|
747
|
+
private safelyDeserializeP2PMessage(msgId: string, source: PeerId, data: Uint8Array): P2PMessage | undefined {
|
|
748
|
+
try {
|
|
749
|
+
return P2PMessage.fromMessageData(Buffer.from(data), this.config.debugP2PInstrumentMessages);
|
|
750
|
+
} catch (err) {
|
|
751
|
+
this.logger.error(`Error deserializing P2PMessage`, err, {
|
|
752
|
+
msgId,
|
|
753
|
+
source: source.toString(),
|
|
754
|
+
});
|
|
755
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Reject);
|
|
756
|
+
this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
|
|
757
|
+
return undefined;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
663
761
|
/**
|
|
664
762
|
* Handles a new gossip message that was received by the client.
|
|
665
763
|
* @param topic - The message's topic.
|
|
666
764
|
* @param data - The message data
|
|
667
765
|
*/
|
|
668
766
|
protected async handleNewGossipMessage(msg: Message, msgId: string, source: PeerId) {
|
|
669
|
-
const
|
|
767
|
+
const msgReceivedTime = Date.now();
|
|
768
|
+
let topicType: TopicType | undefined;
|
|
769
|
+
const p2pMessage = this.safelyDeserializeP2PMessage(msgId, source, msg.data);
|
|
770
|
+
if (!p2pMessage) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
670
773
|
|
|
671
774
|
const preValidationResult = this.preValidateReceivedMessage(msg, msgId, source);
|
|
672
775
|
|
|
@@ -674,14 +777,75 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
674
777
|
return;
|
|
675
778
|
}
|
|
676
779
|
|
|
780
|
+
// Determine topic type for attributes
|
|
677
781
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
678
|
-
|
|
782
|
+
topicType = TopicType.tx;
|
|
783
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
784
|
+
topicType = TopicType.checkpoint_attestation;
|
|
785
|
+
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
786
|
+
topicType = TopicType.block_proposal;
|
|
787
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
788
|
+
topicType = TopicType.checkpoint_proposal;
|
|
679
789
|
}
|
|
680
|
-
|
|
681
|
-
|
|
790
|
+
|
|
791
|
+
// Process the message, optionally within a linked span for trace propagation
|
|
792
|
+
const processMessage = async () => {
|
|
793
|
+
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
794
|
+
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
795
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
796
|
+
if (this.clientType === P2PClientType.Full) {
|
|
797
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
798
|
+
}
|
|
799
|
+
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
800
|
+
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
801
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
802
|
+
await this.handleGossipedCheckpointProposal(p2pMessage.payload, msgId, source);
|
|
803
|
+
} else {
|
|
804
|
+
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
const latency = p2pMessage.timestamp !== undefined ? msgReceivedTime - p2pMessage.timestamp.getTime() : undefined;
|
|
809
|
+
const propagatedContext = p2pMessage.traceContext
|
|
810
|
+
? this.telemetry.extractPropagatedContext(p2pMessage.traceContext)
|
|
811
|
+
: undefined;
|
|
812
|
+
|
|
813
|
+
if (propagatedContext) {
|
|
814
|
+
await this.tracer.startActiveSpan(
|
|
815
|
+
'LibP2PService.processMessage',
|
|
816
|
+
{
|
|
817
|
+
attributes: {
|
|
818
|
+
[Attributes.TOPIC_NAME]: topicType!,
|
|
819
|
+
[Attributes.PEER_ID]: source.toString(),
|
|
820
|
+
},
|
|
821
|
+
},
|
|
822
|
+
propagatedContext,
|
|
823
|
+
async span => {
|
|
824
|
+
try {
|
|
825
|
+
await processMessage();
|
|
826
|
+
span.setStatus({
|
|
827
|
+
code: SpanStatusCode.OK,
|
|
828
|
+
});
|
|
829
|
+
} catch (err) {
|
|
830
|
+
span.setStatus({
|
|
831
|
+
code: SpanStatusCode.ERROR,
|
|
832
|
+
message: String(err),
|
|
833
|
+
});
|
|
834
|
+
if (typeof err === 'string' || (err && err instanceof Error)) {
|
|
835
|
+
span.recordException(err);
|
|
836
|
+
}
|
|
837
|
+
throw err;
|
|
838
|
+
} finally {
|
|
839
|
+
span.end();
|
|
840
|
+
}
|
|
841
|
+
},
|
|
842
|
+
);
|
|
843
|
+
} else {
|
|
844
|
+
await processMessage();
|
|
682
845
|
}
|
|
683
|
-
|
|
684
|
-
|
|
846
|
+
|
|
847
|
+
if (latency !== undefined && topicType !== undefined) {
|
|
848
|
+
this.instrumentation.recordMessageLatency(topicType, latency);
|
|
685
849
|
}
|
|
686
850
|
|
|
687
851
|
return;
|
|
@@ -698,6 +862,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
698
862
|
try {
|
|
699
863
|
resultAndObj = await validationFunc();
|
|
700
864
|
} catch (err) {
|
|
865
|
+
this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
|
|
701
866
|
this.logger.error(`Error deserializing and validating gossipsub message`, err, {
|
|
702
867
|
msgId,
|
|
703
868
|
source: source.toString(),
|
|
@@ -751,42 +916,63 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
751
916
|
return;
|
|
752
917
|
}
|
|
753
918
|
|
|
919
|
+
this.instrumentation.incrementTxReceived(1);
|
|
754
920
|
await this.mempools.txPool.addTxs([tx]);
|
|
755
921
|
}
|
|
756
922
|
|
|
757
923
|
/**
|
|
758
|
-
* Process
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
* @param attestation - The attestation to process.
|
|
924
|
+
* Process a checkpoint attestation from a peer.
|
|
925
|
+
* Validates the attestation and adds it to the pool.
|
|
762
926
|
*/
|
|
763
|
-
private async
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
927
|
+
private async processCheckpointAttestationFromPeer(
|
|
928
|
+
payloadData: Buffer,
|
|
929
|
+
msgId: string,
|
|
930
|
+
source: PeerId,
|
|
931
|
+
): Promise<void> {
|
|
932
|
+
const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointAttestation>> = async () => {
|
|
933
|
+
const attestation = CheckpointAttestation.fromBuffer(payloadData);
|
|
934
|
+
const pool = this.mempools.attestationPool;
|
|
935
|
+
const validationResult = await this.validateCheckpointAttestation(source, attestation);
|
|
936
|
+
const isValid = validationResult.result === 'accept';
|
|
937
|
+
const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
|
|
938
|
+
|
|
939
|
+
let canAdd = true;
|
|
940
|
+
if (isValid && !exists) {
|
|
941
|
+
const slot = attestation.payload.header.slotNumber;
|
|
942
|
+
const { committee } = await this.epochCache.getCommittee(slot);
|
|
943
|
+
const committeeSize = committee?.length ?? 0;
|
|
944
|
+
canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
|
|
945
|
+
}
|
|
768
946
|
|
|
769
|
-
this.logger.trace(`Validate propagated
|
|
947
|
+
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
770
948
|
isValid,
|
|
771
949
|
exists,
|
|
950
|
+
canAdd,
|
|
772
951
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
|
|
773
952
|
[Attributes.P2P_ID]: source.toString(),
|
|
774
953
|
});
|
|
775
954
|
|
|
776
|
-
if (
|
|
955
|
+
if (validationResult.result === 'reject') {
|
|
777
956
|
return { result: TopicValidatorResult.Reject };
|
|
778
|
-
} else if (exists) {
|
|
957
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
958
|
+
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
959
|
+
} else if (!canAdd) {
|
|
960
|
+
this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
|
|
961
|
+
slot: attestation.payload.header.slotNumber.toString(),
|
|
962
|
+
archive: attestation.archive.toString(),
|
|
963
|
+
source: source.toString(),
|
|
964
|
+
});
|
|
779
965
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
780
966
|
} else {
|
|
781
967
|
return { result: TopicValidatorResult.Accept, obj: attestation };
|
|
782
968
|
}
|
|
783
969
|
};
|
|
784
970
|
|
|
785
|
-
const { result, obj: attestation } = await this.validateReceivedMessage<
|
|
971
|
+
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
786
972
|
validationFunc,
|
|
787
973
|
msgId,
|
|
788
974
|
source,
|
|
789
|
-
TopicType.
|
|
975
|
+
TopicType.checkpoint_attestation,
|
|
790
976
|
);
|
|
791
977
|
|
|
792
978
|
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
@@ -794,38 +980,48 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
794
980
|
}
|
|
795
981
|
|
|
796
982
|
this.logger.debug(
|
|
797
|
-
`Received attestation for slot ${attestation.slotNumber
|
|
983
|
+
`Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
798
984
|
{
|
|
799
|
-
p2pMessageIdentifier: await attestation.
|
|
800
|
-
slot: attestation.slotNumber
|
|
985
|
+
p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
|
|
986
|
+
slot: attestation.slotNumber,
|
|
801
987
|
archive: attestation.archive.toString(),
|
|
802
988
|
source: source.toString(),
|
|
803
989
|
},
|
|
804
990
|
);
|
|
805
991
|
|
|
806
|
-
await this.mempools.attestationPool
|
|
992
|
+
await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
|
|
807
993
|
}
|
|
808
994
|
|
|
809
995
|
private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
810
996
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockProposal>> = async () => {
|
|
811
997
|
const block = BlockProposal.fromBuffer(payloadData);
|
|
812
|
-
const
|
|
998
|
+
const validationResult = await this.validateBlockProposal(source, block);
|
|
999
|
+
const isValid = validationResult.result === 'accept';
|
|
1000
|
+
const pool = this.mempools.attestationPool;
|
|
813
1001
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
const exists = isValid && (await this.mempools.attestationPool?.hasBlockProposal(block));
|
|
1002
|
+
const exists = isValid && (await pool.hasBlockProposal(block));
|
|
1003
|
+
const canAdd = isValid && (await pool.canAddProposal(block));
|
|
817
1004
|
|
|
818
1005
|
this.logger.trace(`Validate propagated block proposal`, {
|
|
819
1006
|
isValid,
|
|
820
1007
|
exists,
|
|
821
|
-
|
|
1008
|
+
canAdd,
|
|
1009
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
822
1010
|
[Attributes.P2P_ID]: source.toString(),
|
|
823
1011
|
});
|
|
824
1012
|
|
|
825
|
-
if (
|
|
1013
|
+
if (validationResult.result === 'reject') {
|
|
826
1014
|
return { result: TopicValidatorResult.Reject };
|
|
827
|
-
} else if (exists) {
|
|
1015
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
828
1016
|
return { result: TopicValidatorResult.Ignore, obj: block };
|
|
1017
|
+
} else if (!canAdd) {
|
|
1018
|
+
this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
|
|
1019
|
+
this.logger.warn(`Penalizing peer for block proposal exceeding per-slot cap`, {
|
|
1020
|
+
slot: block.slotNumber.toString(),
|
|
1021
|
+
archive: block.archive.toString(),
|
|
1022
|
+
source: source.toString(),
|
|
1023
|
+
});
|
|
1024
|
+
return { result: TopicValidatorResult.Reject };
|
|
829
1025
|
} else {
|
|
830
1026
|
return { result: TopicValidatorResult.Accept, obj: block };
|
|
831
1027
|
}
|
|
@@ -846,55 +1042,156 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
846
1042
|
}
|
|
847
1043
|
|
|
848
1044
|
// REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
1045
|
+
// REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
|
|
1046
|
+
// should not be here as it does not deal with p2p networking.
|
|
849
1047
|
@trackSpan('Libp2pService.processValidBlockProposal', async block => ({
|
|
850
|
-
[Attributes.SLOT_NUMBER]: block.slotNumber
|
|
1048
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber,
|
|
851
1049
|
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
852
|
-
[Attributes.P2P_ID]: await block.
|
|
1050
|
+
[Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
853
1051
|
}))
|
|
854
1052
|
private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
|
|
855
|
-
const slot = block.slotNumber
|
|
856
|
-
const previousSlot = slot - 1n;
|
|
1053
|
+
const slot = block.slotNumber;
|
|
857
1054
|
this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
858
|
-
p2pMessageIdentifier: await block.
|
|
859
|
-
slot: block.slotNumber.toNumber(),
|
|
860
|
-
archive: block.archive.toString(),
|
|
1055
|
+
p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
|
|
861
1056
|
source: sender.toString(),
|
|
1057
|
+
...block.toBlockInfo(),
|
|
862
1058
|
});
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1059
|
+
|
|
1060
|
+
// Attempt to add proposal
|
|
1061
|
+
try {
|
|
1062
|
+
await this.mempools.attestationPool.addBlockProposal(block);
|
|
1063
|
+
} catch (err: unknown) {
|
|
1064
|
+
// Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
|
|
1065
|
+
if (err instanceof ProposalSlotCapExceededError) {
|
|
1066
|
+
this.logger.warn(`Dropping block proposal due to per-slot proposal cap`, {
|
|
1067
|
+
slot: String(slot),
|
|
1068
|
+
archive: block.archive.toString(),
|
|
1069
|
+
error: (err as Error).message,
|
|
1070
|
+
});
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
throw err;
|
|
866
1074
|
}
|
|
867
1075
|
|
|
868
1076
|
// Mark the txs in this proposal as non-evictable
|
|
869
1077
|
await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
|
|
870
|
-
await this.mempools.attestationPool?.addBlockProposal(block);
|
|
871
|
-
const attestations = await this.blockReceivedCallback(block, sender);
|
|
872
1078
|
|
|
873
|
-
//
|
|
874
|
-
//
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1079
|
+
// Call the block received callback to validate the proposal.
|
|
1080
|
+
// Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1081
|
+
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1082
|
+
if (!isValid) {
|
|
1083
|
+
this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Handle a gossiped checkpoint proposal.
|
|
1089
|
+
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1090
|
+
*/
|
|
1091
|
+
private async handleGossipedCheckpointProposal(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
1092
|
+
// TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
|
|
1093
|
+
const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointProposal>> = async () => {
|
|
1094
|
+
const checkpoint = CheckpointProposal.fromBuffer(payloadData);
|
|
1095
|
+
const validationResult = await this.validateCheckpointProposal(source, checkpoint);
|
|
1096
|
+
const isValid = validationResult.result === 'accept';
|
|
1097
|
+
const pool = this.mempools.attestationPool;
|
|
1098
|
+
|
|
1099
|
+
const exists = isValid && (await pool.hasCheckpointProposal(checkpoint));
|
|
1100
|
+
const canAdd = isValid && (await pool.canAddCheckpointProposal(checkpoint));
|
|
1101
|
+
|
|
1102
|
+
this.logger.trace(`Validate propagated checkpoint proposal`, {
|
|
1103
|
+
isValid,
|
|
1104
|
+
exists,
|
|
1105
|
+
canAdd,
|
|
1106
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1107
|
+
[Attributes.P2P_ID]: source.toString(),
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
if (validationResult.result === 'reject') {
|
|
1111
|
+
return { result: TopicValidatorResult.Reject };
|
|
1112
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
1113
|
+
return { result: TopicValidatorResult.Ignore, obj: checkpoint };
|
|
1114
|
+
} else if (!canAdd) {
|
|
1115
|
+
this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
|
|
1116
|
+
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1117
|
+
slot: checkpoint.slotNumber.toString(),
|
|
1118
|
+
archive: checkpoint.archive.toString(),
|
|
1119
|
+
source: source.toString(),
|
|
881
1120
|
});
|
|
882
|
-
|
|
1121
|
+
return { result: TopicValidatorResult.Reject };
|
|
1122
|
+
} else {
|
|
1123
|
+
return { result: TopicValidatorResult.Accept, obj: checkpoint };
|
|
883
1124
|
}
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
const { result, obj: checkpoint } = await this.validateReceivedMessage<CheckpointProposal>(
|
|
1128
|
+
validationFunc,
|
|
1129
|
+
msgId,
|
|
1130
|
+
source,
|
|
1131
|
+
TopicType.checkpoint_proposal,
|
|
1132
|
+
);
|
|
1133
|
+
|
|
1134
|
+
if (result !== TopicValidatorResult.Accept || !checkpoint) {
|
|
1135
|
+
return;
|
|
884
1136
|
}
|
|
1137
|
+
|
|
1138
|
+
await this.processValidCheckpointProposal(checkpoint, source);
|
|
885
1139
|
}
|
|
886
1140
|
|
|
887
1141
|
/**
|
|
888
|
-
*
|
|
889
|
-
*
|
|
1142
|
+
* Process a validated checkpoint proposal.
|
|
1143
|
+
* Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
|
|
1144
|
+
* The block callback is invoked before the checkpoint callback.
|
|
890
1145
|
*/
|
|
891
|
-
@trackSpan('Libp2pService.
|
|
892
|
-
[Attributes.SLOT_NUMBER]:
|
|
893
|
-
[Attributes.BLOCK_ARCHIVE]:
|
|
894
|
-
[Attributes.P2P_ID]: await
|
|
1146
|
+
@trackSpan('Libp2pService.processValidCheckpointProposal', async checkpoint => ({
|
|
1147
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
1148
|
+
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
1149
|
+
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
895
1150
|
}))
|
|
896
|
-
private async
|
|
897
|
-
|
|
1151
|
+
private async processValidCheckpointProposal(checkpoint: CheckpointProposal, sender: PeerId) {
|
|
1152
|
+
const slot = checkpoint.slotNumber;
|
|
1153
|
+
this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
1154
|
+
p2pMessageIdentifier: await checkpoint.p2pMessageLoggingIdentifier(),
|
|
1155
|
+
slot: checkpoint.slotNumber,
|
|
1156
|
+
archive: checkpoint.archive.toString(),
|
|
1157
|
+
source: sender.toString(),
|
|
1158
|
+
});
|
|
1159
|
+
|
|
1160
|
+
// Extract block proposal before adding to pool (pool stores them separately)
|
|
1161
|
+
const blockProposal = checkpoint.getBlockProposal();
|
|
1162
|
+
|
|
1163
|
+
// Add proposal to the pool (this extracts and stores block proposal separately)
|
|
1164
|
+
await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
|
|
1165
|
+
|
|
1166
|
+
// Mark txs as non-evictable if present (from the last block)
|
|
1167
|
+
if (checkpoint.txHashes.length > 0) {
|
|
1168
|
+
await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// If there was a last block proposal, invoke the block callback first for validation.
|
|
1172
|
+
// Note: The block proposal is already stored in the pool by addCheckpointProposal.
|
|
1173
|
+
if (blockProposal) {
|
|
1174
|
+
const isValid = await this.blockReceivedCallback(blockProposal, sender);
|
|
1175
|
+
if (!isValid) {
|
|
1176
|
+
this.logger.warn(`Block proposal from checkpoint failed validation`, {
|
|
1177
|
+
slot: slot.toString(),
|
|
1178
|
+
archive: checkpoint.archive.toString(),
|
|
1179
|
+
blockNumber: blockProposal.blockNumber.toString(),
|
|
1180
|
+
});
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1186
|
+
// to validate and potentially generate attestations
|
|
1187
|
+
const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
|
|
1188
|
+
if (attestations && attestations.length > 0) {
|
|
1189
|
+
// If the callback returned attestations, add them to the pool and propagate them
|
|
1190
|
+
await this.mempools.attestationPool.addCheckpointAttestations(attestations);
|
|
1191
|
+
for (const attestation of attestations) {
|
|
1192
|
+
await this.propagate(attestation);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
898
1195
|
}
|
|
899
1196
|
|
|
900
1197
|
/**
|
|
@@ -902,19 +1199,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
902
1199
|
* @param message - The message to propagate.
|
|
903
1200
|
*/
|
|
904
1201
|
public async propagate<T extends Gossipable>(message: T) {
|
|
905
|
-
const p2pMessageIdentifier = await message.
|
|
1202
|
+
const p2pMessageIdentifier = await message.p2pMessageLoggingIdentifier();
|
|
906
1203
|
this.logger.trace(`Message ${p2pMessageIdentifier} queued`, { p2pMessageIdentifier });
|
|
907
|
-
void this.
|
|
908
|
-
.
|
|
909
|
-
|
|
910
|
-
})
|
|
911
|
-
.catch(error => {
|
|
912
|
-
this.logger.error(`Error propagating message ${p2pMessageIdentifier}`, { error });
|
|
913
|
-
});
|
|
1204
|
+
void this.sendToPeers(message).catch(error => {
|
|
1205
|
+
this.logger.error(`Error propagating message ${p2pMessageIdentifier}`, { error });
|
|
1206
|
+
});
|
|
914
1207
|
}
|
|
915
1208
|
|
|
916
1209
|
/**
|
|
917
|
-
* Validate the requested block transactions.
|
|
1210
|
+
* Validate the requested block transactions. Allow partial returns.
|
|
918
1211
|
* @param request - The block transactions request.
|
|
919
1212
|
* @param response - The block transactions response.
|
|
920
1213
|
* @param peerId - The ID of the peer that made the request.
|
|
@@ -924,14 +1217,71 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
924
1217
|
[Attributes.BLOCK_HASH]: request.blockHash.toString(),
|
|
925
1218
|
}))
|
|
926
1219
|
private async validateRequestedBlockTxs(
|
|
927
|
-
|
|
1220
|
+
request: BlockTxsRequest,
|
|
928
1221
|
response: BlockTxsResponse,
|
|
929
1222
|
peerId: PeerId,
|
|
930
1223
|
): Promise<boolean> {
|
|
931
1224
|
const requestedTxValidator = this.createRequestedTxValidator();
|
|
932
1225
|
|
|
933
1226
|
try {
|
|
934
|
-
|
|
1227
|
+
if (!response.blockHash.equals(request.blockHash)) {
|
|
1228
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1229
|
+
throw new ValidationError(
|
|
1230
|
+
`Received block txs for unexpected block: expected ${request.blockHash.toString()}, got ${response.blockHash.toString()}`,
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
if (response.txIndices.getLength() !== request.txIndices.getLength()) {
|
|
1235
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1236
|
+
throw new ValidationError(
|
|
1237
|
+
`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`,
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// Check no duplicates and not exceeding returnable count
|
|
1242
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
1243
|
+
const availableIndices = new Set(response.txIndices.getTrueIndices());
|
|
1244
|
+
const maxReturnable = [...requestedIndices].filter(i => availableIndices.has(i)).length;
|
|
1245
|
+
|
|
1246
|
+
const returnedHashes = await Promise.all(response.txs.map(tx => tx.getTxHash().toString()));
|
|
1247
|
+
const uniqueReturned = new Set(returnedHashes.map(h => h.toString()));
|
|
1248
|
+
if (uniqueReturned.size !== returnedHashes.length) {
|
|
1249
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1250
|
+
throw new ValidationError(`Received duplicate txs in block txs response`);
|
|
1251
|
+
}
|
|
1252
|
+
if (response.txs.length > maxReturnable) {
|
|
1253
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1254
|
+
throw new ValidationError(
|
|
1255
|
+
`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`,
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// Given proposal (should have locally), ensure returned txs are valid subset and match request indices
|
|
1260
|
+
const proposal = await this.mempools.attestationPool.getBlockProposal(request.blockHash.toString());
|
|
1261
|
+
if (proposal) {
|
|
1262
|
+
// Build intersected indices
|
|
1263
|
+
const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
|
|
1264
|
+
|
|
1265
|
+
// Enforce subset membership and preserve increasing order by index.
|
|
1266
|
+
const hashToIndexInProposal = new Map<string, number>(
|
|
1267
|
+
proposal.txHashes.map((h, i) => [h.toString(), i] as [string, number]),
|
|
1268
|
+
);
|
|
1269
|
+
const allowedIndexSet = new Set(intersectIdx);
|
|
1270
|
+
const indices = returnedHashes.map(h => hashToIndexInProposal.get(h));
|
|
1271
|
+
const allAllowed = indices.every(idx => idx !== undefined && allowedIndexSet.has(idx));
|
|
1272
|
+
const strictlyIncreasing = indices.every((idx, i) => (i === 0 ? idx !== undefined : idx! > indices[i - 1]!));
|
|
1273
|
+
if (!allAllowed || !strictlyIncreasing) {
|
|
1274
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1275
|
+
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
1276
|
+
}
|
|
1277
|
+
} else {
|
|
1278
|
+
// No local proposal, cannot check the membership/order of the returned txs
|
|
1279
|
+
this.logger.warn(
|
|
1280
|
+
`Block proposal not found for block hash ${request.blockHash.toString()}; cannot validate membership/order of returned txs`,
|
|
1281
|
+
);
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
935
1285
|
await Promise.all(response.txs.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
936
1286
|
return true;
|
|
937
1287
|
} catch (e: any) {
|
|
@@ -955,7 +1305,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
955
1305
|
* ReqRespSubProtocol.TX subprotocol validation.
|
|
956
1306
|
*
|
|
957
1307
|
* @param requestedTxHash - The collection of the txs that was requested.
|
|
958
|
-
* @param responseTx - The
|
|
1308
|
+
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
959
1309
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
960
1310
|
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
961
1311
|
*/
|
|
@@ -966,7 +1316,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
966
1316
|
const requested = new Set(requestedTxHash.map(h => h.toString()));
|
|
967
1317
|
const requestedTxValidator = this.createRequestedTxValidator();
|
|
968
1318
|
|
|
969
|
-
//TODO: (mralj) - this is somewhat naive implementation, if single tx is
|
|
1319
|
+
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
970
1320
|
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
971
1321
|
try {
|
|
972
1322
|
await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
@@ -982,37 +1332,74 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
982
1332
|
}
|
|
983
1333
|
}
|
|
984
1334
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1335
|
+
/**
|
|
1336
|
+
* Validates a BLOCK response.
|
|
1337
|
+
*
|
|
1338
|
+
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1339
|
+
* Penalizes on block number mismatch or hash mismatch.
|
|
1340
|
+
*
|
|
1341
|
+
* @param requestedBlockNumber - The requested block number.
|
|
1342
|
+
* @param responseBlock - The block returned by the peer.
|
|
1343
|
+
* @param peerId - The peer that returned the block.
|
|
1344
|
+
* @returns True if the response is valid, false otherwise.
|
|
1345
|
+
*/
|
|
1346
|
+
@trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock) => ({
|
|
1347
|
+
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString(),
|
|
1348
|
+
}))
|
|
1349
|
+
private async validateRequestedBlock(
|
|
1350
|
+
requestedBlockNumber: Fr,
|
|
1351
|
+
responseBlock: L2Block,
|
|
1352
|
+
peerId: PeerId,
|
|
1353
|
+
): Promise<boolean> {
|
|
1354
|
+
try {
|
|
1355
|
+
const reqNum = Number(requestedBlockNumber.toString());
|
|
1356
|
+
if (responseBlock.number !== reqNum) {
|
|
1357
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1358
|
+
return false;
|
|
1359
|
+
}
|
|
997
1360
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1361
|
+
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1362
|
+
if (!local) {
|
|
1363
|
+
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1364
|
+
// TODO: Consider extending this validator to accept an expected hash or
|
|
1365
|
+
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1366
|
+
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
const [localHash, respHash] = await Promise.all([local.hash(), responseBlock.hash()]);
|
|
1370
|
+
if (!localHash.equals(respHash)) {
|
|
1371
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1372
|
+
return false;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
return true;
|
|
1376
|
+
} catch (e) {
|
|
1377
|
+
this.logger.warn(`Error validating requested block`, e);
|
|
1378
|
+
return false;
|
|
1002
1379
|
}
|
|
1380
|
+
}
|
|
1003
1381
|
|
|
1382
|
+
private async validateRequestedTx(tx: Tx, peerId: PeerId, txValidator: TxValidator, requested?: Set<`0x${string}`>) {
|
|
1383
|
+
const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
|
|
1004
1384
|
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1005
|
-
|
|
1385
|
+
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1006
1386
|
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
1007
1387
|
}
|
|
1008
1388
|
|
|
1009
1389
|
const { result } = await txValidator.validateTx(tx);
|
|
1010
1390
|
if (result === 'invalid') {
|
|
1011
|
-
|
|
1391
|
+
penalize(PeerErrorSeverity.LowToleranceError);
|
|
1012
1392
|
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
|
|
1013
1393
|
}
|
|
1014
1394
|
}
|
|
1015
1395
|
|
|
1396
|
+
private createRequestedTxValidator(): TxValidator {
|
|
1397
|
+
return createTxReqRespValidator(this.proofVerifier, {
|
|
1398
|
+
l1ChainId: this.config.l1ChainId,
|
|
1399
|
+
rollupVersion: this.config.rollupVersion,
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1016
1403
|
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
1017
1404
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1018
1405
|
}))
|
|
@@ -1034,7 +1421,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1034
1421
|
|
|
1035
1422
|
// Double spend validator has a special case handler
|
|
1036
1423
|
if (name === 'doubleSpendValidator') {
|
|
1037
|
-
const txBlockNumber = currentBlockNumber + 1; // tx is expected to be in the next block
|
|
1424
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
|
|
1038
1425
|
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1039
1426
|
}
|
|
1040
1427
|
|
|
@@ -1044,7 +1431,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1044
1431
|
return true;
|
|
1045
1432
|
}
|
|
1046
1433
|
|
|
1047
|
-
private async getGasFees(blockNumber:
|
|
1434
|
+
private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
|
|
1048
1435
|
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1049
1436
|
return this.feesCache.gasFees;
|
|
1050
1437
|
}
|
|
@@ -1055,6 +1442,22 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1055
1442
|
return gasFees;
|
|
1056
1443
|
}
|
|
1057
1444
|
|
|
1445
|
+
/**
|
|
1446
|
+
* Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
|
|
1447
|
+
*/
|
|
1448
|
+
public getBatchTxRequesterService(): BatchTxRequesterLibP2PService {
|
|
1449
|
+
return {
|
|
1450
|
+
reqResp: this.reqresp,
|
|
1451
|
+
connectionSampler: this.reqresp.getConnectionSampler(),
|
|
1452
|
+
txValidatorConfig: {
|
|
1453
|
+
l1ChainId: this.config.l1ChainId,
|
|
1454
|
+
rollupVersion: this.config.rollupVersion,
|
|
1455
|
+
proofVerifier: this.proofVerifier,
|
|
1456
|
+
},
|
|
1457
|
+
peerScoring: this.peerManager,
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1058
1461
|
public async validate(txs: Tx[]): Promise<void> {
|
|
1059
1462
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1060
1463
|
|
|
@@ -1085,13 +1488,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1085
1488
|
* @returns The message validators.
|
|
1086
1489
|
*/
|
|
1087
1490
|
private async createMessageValidators(
|
|
1088
|
-
currentBlockNumber:
|
|
1491
|
+
currentBlockNumber: BlockNumber,
|
|
1089
1492
|
nextSlotTimestamp: UInt64,
|
|
1090
1493
|
): Promise<Record<string, MessageValidator>[]> {
|
|
1091
1494
|
const gasFees = await this.getGasFees(currentBlockNumber);
|
|
1092
1495
|
const allowedInSetup = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
1093
1496
|
|
|
1094
|
-
const blockNumberInWhichTheTxIsConsideredToBeIncluded = currentBlockNumber + 1;
|
|
1497
|
+
const blockNumberInWhichTheTxIsConsideredToBeIncluded = BlockNumber(currentBlockNumber + 1);
|
|
1095
1498
|
|
|
1096
1499
|
return createTxMessageValidators(
|
|
1097
1500
|
nextSlotTimestamp,
|
|
@@ -1105,6 +1508,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1105
1508
|
this.proofVerifier,
|
|
1106
1509
|
!this.config.disableTransactions,
|
|
1107
1510
|
allowedInSetup,
|
|
1511
|
+
this.logger.getBindings(),
|
|
1108
1512
|
);
|
|
1109
1513
|
}
|
|
1110
1514
|
|
|
@@ -1153,20 +1557,23 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1153
1557
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1154
1558
|
* @returns Severity
|
|
1155
1559
|
*/
|
|
1156
|
-
private async handleDoubleSpendFailure(tx: Tx, blockNumber:
|
|
1560
|
+
private async handleDoubleSpendFailure(tx: Tx, blockNumber: BlockNumber): Promise<PeerErrorSeverity> {
|
|
1157
1561
|
if (blockNumber <= this.config.doubleSpendSeverePeerPenaltyWindow) {
|
|
1158
1562
|
return PeerErrorSeverity.HighToleranceError;
|
|
1159
1563
|
}
|
|
1160
1564
|
|
|
1161
|
-
const snapshotValidator = new DoubleSpendTxValidator(
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1565
|
+
const snapshotValidator = new DoubleSpendTxValidator(
|
|
1566
|
+
{
|
|
1567
|
+
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
1568
|
+
const merkleTree = this.worldStateSynchronizer.getSnapshot(
|
|
1569
|
+
BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow),
|
|
1570
|
+
);
|
|
1571
|
+
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
1572
|
+
return indices.map(index => index !== undefined);
|
|
1573
|
+
},
|
|
1168
1574
|
},
|
|
1169
|
-
|
|
1575
|
+
this.logger.getBindings(),
|
|
1576
|
+
);
|
|
1170
1577
|
|
|
1171
1578
|
const validSnapshot = await snapshotValidator.validateTx(tx);
|
|
1172
1579
|
if (validSnapshot.result !== 'valid') {
|
|
@@ -1177,24 +1584,28 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1177
1584
|
}
|
|
1178
1585
|
|
|
1179
1586
|
/**
|
|
1180
|
-
* Validate
|
|
1587
|
+
* Validate a checkpoint attestation.
|
|
1181
1588
|
*
|
|
1182
|
-
* @param attestation - The attestation to validate.
|
|
1183
|
-
* @returns True if the attestation is valid, false otherwise.
|
|
1589
|
+
* @param attestation - The checkpoint attestation to validate.
|
|
1590
|
+
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1184
1591
|
*/
|
|
1185
|
-
@trackSpan('Libp2pService.
|
|
1186
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber
|
|
1592
|
+
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1593
|
+
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1187
1594
|
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1188
|
-
[Attributes.P2P_ID]: await attestation.
|
|
1595
|
+
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1189
1596
|
}))
|
|
1190
|
-
public async
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1597
|
+
public async validateCheckpointAttestation(
|
|
1598
|
+
peerId: PeerId,
|
|
1599
|
+
attestation: CheckpointAttestation,
|
|
1600
|
+
): Promise<P2PValidationResult> {
|
|
1601
|
+
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1602
|
+
|
|
1603
|
+
if (result.result === 'reject') {
|
|
1604
|
+
this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1605
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1195
1606
|
}
|
|
1196
1607
|
|
|
1197
|
-
return
|
|
1608
|
+
return result;
|
|
1198
1609
|
}
|
|
1199
1610
|
|
|
1200
1611
|
/**
|
|
@@ -1204,17 +1615,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1204
1615
|
* @returns True if the block proposal is valid, false otherwise.
|
|
1205
1616
|
*/
|
|
1206
1617
|
@trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
|
|
1207
|
-
[Attributes.SLOT_NUMBER]: block.
|
|
1618
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
1208
1619
|
}))
|
|
1209
|
-
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1620
|
+
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<P2PValidationResult> {
|
|
1621
|
+
const result = await this.blockProposalValidator.validate(block);
|
|
1622
|
+
|
|
1623
|
+
if (result.result === 'reject') {
|
|
1212
1624
|
this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1213
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1214
|
-
return false;
|
|
1625
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1215
1626
|
}
|
|
1216
1627
|
|
|
1217
|
-
return
|
|
1628
|
+
return result;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* Validate a checkpoint proposal.
|
|
1633
|
+
*
|
|
1634
|
+
* @param checkpoint - The checkpoint proposal to validate.
|
|
1635
|
+
* @returns True if the checkpoint proposal is valid, false otherwise.
|
|
1636
|
+
*/
|
|
1637
|
+
@trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint) => ({
|
|
1638
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1639
|
+
}))
|
|
1640
|
+
public async validateCheckpointProposal(
|
|
1641
|
+
peerId: PeerId,
|
|
1642
|
+
checkpoint: CheckpointProposal,
|
|
1643
|
+
): Promise<P2PValidationResult> {
|
|
1644
|
+
const result = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1645
|
+
|
|
1646
|
+
if (result.result === 'reject') {
|
|
1647
|
+
this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1648
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
return result;
|
|
1218
1652
|
}
|
|
1219
1653
|
|
|
1220
1654
|
public getPeerScore(peerId: PeerId): number {
|
|
@@ -1228,7 +1662,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1228
1662
|
private async sendToPeers<T extends Gossipable>(message: T) {
|
|
1229
1663
|
const parent = message.constructor as typeof Gossipable;
|
|
1230
1664
|
|
|
1231
|
-
const identifier = await message.
|
|
1665
|
+
const identifier = await message.p2pMessageLoggingIdentifier().then(i => i.toString());
|
|
1232
1666
|
this.logger.trace(`Sending message ${identifier}`, { p2pMessageIdentifier: identifier });
|
|
1233
1667
|
|
|
1234
1668
|
const recipientsNum = await this.publishToTopic(this.topicStrings[parent.p2pTopic], message);
|