@aztec/p2p 0.0.1-commit.c31f2472 → 0.0.1-commit.c52d6e7
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/README.md +130 -3
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -6
- package/dest/client/factory.d.ts +13 -12
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +67 -18
- package/dest/client/interface.d.ts +93 -40
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +69 -64
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +247 -244
- package/dest/config.d.ts +168 -89
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +157 -45
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/reqresp.error.d.ts +9 -16
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +10 -17
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +164 -106
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +518 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- 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 +550 -125
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +7 -5
- package/dest/mem_pools/index.d.ts +3 -3
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/instrumentation.d.ts +12 -5
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +38 -17
- package/dest/mem_pools/interface.d.ts +5 -5
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +39 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +97 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +99 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +12 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +64 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/{tx_pool → tx_pool_v2}/eviction/invalid_txs_after_mining_rule.js +15 -35
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +92 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +79 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +5 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +243 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +11 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +137 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +223 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +122 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +368 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +68 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +178 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +91 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +1013 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +8 -4
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +18 -5
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +2 -2
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +36 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/factory.d.ts +133 -7
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +261 -61
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +104 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
- package/dest/msg_validators/tx_validator/index.d.ts +5 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +4 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +7 -7
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +14 -10
- package/dest/services/discv5/discV5_service.d.ts +13 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +119 -23
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +26 -18
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +25 -20
- package/dest/services/encoding.d.ts +24 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +43 -26
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +167 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +336 -0
- package/dest/services/index.d.ts +2 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +1 -0
- 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 +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +112 -61
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +808 -583
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +20 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +83 -26
- package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +127 -15
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +7 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +100 -132
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
- package/dest/services/reqresp/config.d.ts +15 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +11 -0
- package/dest/services/reqresp/interface.d.ts +25 -18
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +23 -19
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
- 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 +34 -26
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +33 -17
- 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 +72 -38
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +21 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
- package/dest/services/reqresp/reqresp.d.ts +7 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +85 -219
- package/dest/services/service.d.ts +66 -13
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +11 -14
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +26 -33
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +100 -0
- package/dest/services/tx_collection/index.d.ts +3 -3
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -1
- package/dest/services/tx_collection/instrumentation.js +1 -2
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/tx_collection.d.ts +45 -51
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +296 -68
- package/dest/services/tx_collection/tx_collection_sink.d.ts +19 -9
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +28 -31
- package/dest/services/tx_collection/tx_source.d.ts +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +29 -7
- package/dest/services/tx_file_store/config.d.ts +16 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +22 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +46 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +142 -0
- package/dest/services/tx_provider.d.ts +6 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +12 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +5 -3
- package/dest/test-helpers/mock-pubsub.d.ts +46 -6
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +115 -14
- package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +19 -20
- package/dest/test-helpers/test_tx_provider.d.ts +3 -1
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
- package/dest/test-helpers/test_tx_provider.js +3 -0
- package/dest/test-helpers/testbench-utils.d.ts +58 -50
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +181 -76
- package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +114 -51
- package/dest/testbench/worker_client_manager.d.ts +12 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +57 -11
- package/dest/util.d.ts +13 -8
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +15 -16
- package/src/bootstrap/bootstrap.ts +17 -3
- package/src/client/factory.ts +135 -31
- package/src/client/interface.ts +100 -48
- package/src/client/p2p_client.ts +289 -310
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +282 -49
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +13 -19
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +585 -94
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +656 -141
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +14 -8
- package/src/mem_pools/index.ts +2 -2
- package/src/mem_pools/instrumentation.ts +27 -17
- package/src/mem_pools/interface.ts +4 -4
- package/src/mem_pools/tx_pool_v2/README.md +283 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +112 -0
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +120 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +126 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +28 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +67 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +72 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +99 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +90 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
- package/src/mem_pools/tx_pool_v2/index.ts +12 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +274 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +349 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +465 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +252 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1215 -0
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +17 -9
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
- package/src/msg_validators/tx_validator/README.md +129 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +2 -2
- package/src/msg_validators/tx_validator/block_header_validator.ts +18 -8
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +44 -1
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +413 -80
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
- package/src/msg_validators/tx_validator/index.ts +4 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/msg_validators/tx_validator/timestamp_validator.ts +24 -19
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/data_store.ts +14 -19
- package/src/services/discv5/discV5_service.ts +126 -14
- package/src/services/discv5/persisted_enr_store.ts +158 -0
- package/src/services/dummy_service.ts +38 -45
- package/src/services/encoding.ts +42 -26
- package/src/services/gossipsub/README.md +663 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +478 -0
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +880 -641
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +91 -25
- package/src/services/peer-manager/peer_scoring.ts +127 -8
- package/src/services/reqresp/README.md +194 -0
- package/src/services/reqresp/batch-tx-requester/README.md +60 -21
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +101 -147
- package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
- package/src/services/reqresp/config.ts +19 -2
- package/src/services/reqresp/interface.ts +45 -46
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +43 -30
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +86 -36
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +23 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
- package/src/services/reqresp/reqresp.ts +100 -263
- package/src/services/service.ts +85 -29
- package/src/services/tx_collection/config.ts +40 -49
- package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +2 -6
- package/src/services/tx_collection/instrumentation.ts +1 -1
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/tx_collection.ts +362 -110
- package/src/services/tx_collection/tx_collection_sink.ts +32 -36
- package/src/services/tx_collection/tx_source.ts +29 -8
- package/src/services/tx_file_store/config.ts +37 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +163 -0
- package/src/services/tx_provider.ts +15 -9
- package/src/test-helpers/make-test-p2p-clients.ts +7 -6
- package/src/test-helpers/mock-pubsub.ts +137 -14
- package/src/test-helpers/reqresp-nodes.ts +17 -29
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +188 -94
- package/src/testbench/p2p_client_testbench_worker.ts +123 -66
- package/src/testbench/worker_client_manager.ts +72 -25
- package/src/util.ts +40 -19
- package/src/versioning.ts +3 -33
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/clock_tolerance.d.ts +0 -21
- package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
- package/dest/msg_validators/clock_tolerance.js +0 -37
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -53
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -311
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -53
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -177
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/clock_tolerance.ts +0 -51
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/fast_tx_collection.ts +0 -364
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -114
- package/src/services/tx_collection/slow_tx_collection.ts +0 -233
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import {
|
|
4
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { compactArray, maxBy, merge } from '@aztec/foundation/collection';
|
|
5
4
|
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
6
5
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
7
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
9
8
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
10
|
-
import type { EthAddress,
|
|
9
|
+
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
10
|
+
import { DEFAULT_MAX_BLOCKS_PER_CHECKPOINT } from '@aztec/stdlib/config';
|
|
11
11
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
12
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
12
|
+
import { type BlockMinFeesProvider, GasFees, getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
13
13
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
14
14
|
import {
|
|
15
15
|
BlockProposal,
|
|
@@ -17,18 +17,19 @@ import {
|
|
|
17
17
|
CheckpointProposal,
|
|
18
18
|
type CheckpointProposalCore,
|
|
19
19
|
type Gossipable,
|
|
20
|
-
P2PClientType,
|
|
21
20
|
P2PMessage,
|
|
22
|
-
type ValidationResult as P2PValidationResult,
|
|
23
21
|
PeerErrorSeverity,
|
|
22
|
+
PeerErrorSeverityByHarshness,
|
|
24
23
|
TopicType,
|
|
25
24
|
createTopicString,
|
|
26
|
-
|
|
25
|
+
getTopicsForConfig,
|
|
27
26
|
metricsTopicStrToLabels,
|
|
28
27
|
} from '@aztec/stdlib/p2p';
|
|
28
|
+
import { ConsensusTimetable, getDefaultCheckpointProposalSyncGrace } from '@aztec/stdlib/timetable';
|
|
29
29
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
30
|
-
import { Tx, type
|
|
30
|
+
import { Tx, type TxValidationResult } from '@aztec/stdlib/tx';
|
|
31
31
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
32
|
+
import { InvalidBlockProposalTxsError } from '@aztec/stdlib/validators';
|
|
32
33
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
33
34
|
import {
|
|
34
35
|
Attributes,
|
|
@@ -45,80 +46,99 @@ import {
|
|
|
45
46
|
type GossipsubMessage,
|
|
46
47
|
gossipsub,
|
|
47
48
|
} from '@chainsafe/libp2p-gossipsub';
|
|
48
|
-
import { createPeerScoreParams
|
|
49
|
+
import { createPeerScoreParams } from '@chainsafe/libp2p-gossipsub/score';
|
|
49
50
|
import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
|
|
50
51
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
51
52
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
52
53
|
import { bootstrap } from '@libp2p/bootstrap';
|
|
53
54
|
import { identify } from '@libp2p/identify';
|
|
54
55
|
import { type Message, type MultiaddrConnection, type PeerId, TopicValidatorResult } from '@libp2p/interface';
|
|
55
|
-
import type { ConnectionManager } from '@libp2p/interface-internal';
|
|
56
|
+
import type { AddressManager, ConnectionManager } from '@libp2p/interface-internal';
|
|
56
57
|
import { mplex } from '@libp2p/mplex';
|
|
57
58
|
import { tcp } from '@libp2p/tcp';
|
|
59
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
58
60
|
import { ENR } from '@nethermindeth/enr';
|
|
59
61
|
import { createLibp2p } from 'libp2p';
|
|
60
62
|
|
|
61
63
|
import type { P2PConfig } from '../../config.js';
|
|
62
|
-
import {
|
|
64
|
+
import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
|
|
63
65
|
import type { MemPools } from '../../mem_pools/interface.js';
|
|
64
66
|
import {
|
|
65
67
|
BlockProposalValidator,
|
|
66
68
|
CheckpointAttestationValidator,
|
|
67
69
|
CheckpointProposalValidator,
|
|
70
|
+
DoubleSpendTxValidator,
|
|
68
71
|
FishermanAttestationValidator,
|
|
72
|
+
getDefaultAllowedSetupFunctions,
|
|
69
73
|
} from '../../msg_validators/index.js';
|
|
70
74
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
71
|
-
import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
|
|
72
75
|
import {
|
|
73
|
-
type
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
type TransactionValidator,
|
|
77
|
+
createFirstStageTxValidationsForGossipedTransactions,
|
|
78
|
+
createSecondStageTxValidationsForGossipedTransactions,
|
|
79
|
+
createTxValidatorForBlockProposalReceivedTxs,
|
|
76
80
|
} from '../../msg_validators/tx_validator/factory.js';
|
|
77
|
-
import {
|
|
81
|
+
import { TxValidationCache } from '../../msg_validators/tx_validator/tx_validation_cache.js';
|
|
78
82
|
import { GossipSubEvent } from '../../types/index.js';
|
|
79
83
|
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
80
84
|
import { getVersions } from '../../versioning.js';
|
|
81
85
|
import { AztecDatastore } from '../data_store.js';
|
|
82
86
|
import { DiscV5Service } from '../discv5/discV5_service.js';
|
|
83
|
-
import { SnappyTransform,
|
|
84
|
-
import { gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
87
|
+
import { SnappyTransform, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
88
|
+
import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
89
|
+
import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
|
|
85
90
|
import type { PeerManagerInterface } from '../peer-manager/interface.js';
|
|
86
91
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
87
92
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
88
93
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
89
|
-
import type
|
|
94
|
+
import { type P2PReqRespConfig, YAMUX_MAX_MESSAGE_SIZE_BYTES } from '../reqresp/config.js';
|
|
90
95
|
import {
|
|
91
|
-
|
|
96
|
+
AuthRequest,
|
|
97
|
+
BlockTxsRequest,
|
|
98
|
+
BlockTxsResponse,
|
|
92
99
|
type ReqRespInterface,
|
|
93
100
|
type ReqRespResponse,
|
|
94
101
|
ReqRespSubProtocol,
|
|
95
102
|
type ReqRespSubProtocolHandler,
|
|
96
103
|
type ReqRespSubProtocolHandlers,
|
|
97
|
-
type ReqRespSubProtocolValidators,
|
|
98
|
-
type SubProtocolMap,
|
|
99
|
-
ValidationError,
|
|
100
|
-
} from '../reqresp/interface.js';
|
|
101
|
-
import { reqRespBlockTxsHandler } from '../reqresp/protocols/block_txs/block_txs_handler.js';
|
|
102
|
-
import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
|
|
103
|
-
import {
|
|
104
|
-
AuthRequest,
|
|
105
|
-
BlockTxsRequest,
|
|
106
|
-
BlockTxsResponse,
|
|
107
104
|
StatusMessage,
|
|
105
|
+
ValidationError,
|
|
108
106
|
pingHandler,
|
|
109
|
-
|
|
107
|
+
reqGoodbyeHandler,
|
|
108
|
+
reqRespBlockTxsHandler,
|
|
110
109
|
reqRespStatusHandler,
|
|
111
110
|
reqRespTxHandler,
|
|
112
|
-
} from '../reqresp/
|
|
111
|
+
} from '../reqresp/index.js';
|
|
113
112
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
114
113
|
import type {
|
|
115
114
|
P2PBlockReceivedCallback,
|
|
115
|
+
P2PCheckpointAttestationCallback,
|
|
116
116
|
P2PCheckpointReceivedCallback,
|
|
117
|
+
P2PDuplicateAttestationCallback,
|
|
118
|
+
P2POversizedProposalCallback,
|
|
117
119
|
P2PService,
|
|
118
120
|
PeerDiscoveryService,
|
|
119
121
|
} from '../service.js';
|
|
120
122
|
import { P2PInstrumentation } from './instrumentation.js';
|
|
121
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Builds the {@link ConsensusTimetable} shared by the gossip validators for proposal/attestation receive-window
|
|
126
|
+
* bounds. Derived purely from protocol slot-timing constants plus the block sub-slot duration and the consensus
|
|
127
|
+
* materialization grace, so every node agrees on these bounds without depending on proposer operational budgets.
|
|
128
|
+
*/
|
|
129
|
+
function buildConsensusTimetable(
|
|
130
|
+
config: P2PConfig,
|
|
131
|
+
l1Constants: ReturnType<EpochCacheInterface['getL1Constants']>,
|
|
132
|
+
): ConsensusTimetable {
|
|
133
|
+
const blockDuration = config.blockDurationMs / 1000;
|
|
134
|
+
return new ConsensusTimetable({
|
|
135
|
+
l1Constants,
|
|
136
|
+
blockDuration,
|
|
137
|
+
checkpointProposalSyncGrace:
|
|
138
|
+
config.checkpointProposalSyncGraceSeconds ?? getDefaultCheckpointProposalSyncGrace(blockDuration),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
122
142
|
interface ValidationResult {
|
|
123
143
|
name: string;
|
|
124
144
|
isValid: TxValidationResult;
|
|
@@ -128,14 +148,14 @@ interface ValidationResult {
|
|
|
128
148
|
type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: ValidationResult };
|
|
129
149
|
|
|
130
150
|
// REFACTOR: Unify with the type above
|
|
131
|
-
type ReceivedMessageValidationResult<T> =
|
|
132
|
-
| { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject
|
|
133
|
-
| { obj?:
|
|
151
|
+
type ReceivedMessageValidationResult<T, M = undefined> =
|
|
152
|
+
| { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject>; metadata?: M }
|
|
153
|
+
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M; severity: PeerErrorSeverity };
|
|
134
154
|
|
|
135
155
|
/**
|
|
136
156
|
* Lib P2P implementation of the P2PService interface.
|
|
137
157
|
*/
|
|
138
|
-
export class LibP2PService
|
|
158
|
+
export class LibP2PService extends WithTracer implements P2PService {
|
|
139
159
|
private discoveryRunningPromise?: RunningPromise;
|
|
140
160
|
private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
|
|
141
161
|
|
|
@@ -147,7 +167,21 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
147
167
|
private protocolVersion = '';
|
|
148
168
|
private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
|
|
149
169
|
|
|
150
|
-
|
|
170
|
+
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */
|
|
171
|
+
private duplicateProposalCallback?: (info: {
|
|
172
|
+
slot: SlotNumber;
|
|
173
|
+
proposer: EthAddress;
|
|
174
|
+
type: 'checkpoint' | 'block';
|
|
175
|
+
}) => void;
|
|
176
|
+
|
|
177
|
+
/** Callback invoked when an oversized block proposal is stored as slashing evidence (triggers slashing). */
|
|
178
|
+
private oversizedProposalCallback?: P2POversizedProposalCallback;
|
|
179
|
+
|
|
180
|
+
/** Callback invoked when a duplicate attestation is detected (triggers slashing). */
|
|
181
|
+
private duplicateAttestationCallback?: P2PDuplicateAttestationCallback;
|
|
182
|
+
|
|
183
|
+
/** Callback invoked when a valid checkpoint attestation is accepted into the pool. */
|
|
184
|
+
private checkpointAttestationCallback?: P2PCheckpointAttestationCallback;
|
|
151
185
|
|
|
152
186
|
/**
|
|
153
187
|
* Callback for when a block is received from a peer.
|
|
@@ -161,10 +195,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
161
195
|
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
162
196
|
* @returns The attestations for the checkpoint, if any.
|
|
163
197
|
*/
|
|
164
|
-
private
|
|
198
|
+
private allNodesCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
199
|
+
/**
|
|
200
|
+
* Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
|
|
201
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
202
|
+
* @returns The attestations for the checkpoint, if any.
|
|
203
|
+
*/
|
|
204
|
+
private validatorCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
165
205
|
|
|
166
206
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
167
207
|
|
|
208
|
+
private ipChangedHandler?: (ip: string) => void;
|
|
209
|
+
private discoveredP2pIp?: string;
|
|
210
|
+
|
|
168
211
|
private instrumentation: P2PInstrumentation;
|
|
169
212
|
|
|
170
213
|
private telemetry: TelemetryClient;
|
|
@@ -172,19 +215,20 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
172
215
|
protected logger: Logger;
|
|
173
216
|
|
|
174
217
|
constructor(
|
|
175
|
-
private clientType: T,
|
|
176
218
|
private config: P2PConfig,
|
|
177
219
|
protected node: PubSubLibp2p,
|
|
178
220
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
179
221
|
private reqresp: ReqRespInterface,
|
|
180
|
-
|
|
222
|
+
protected peerManager: PeerManagerInterface,
|
|
181
223
|
protected mempools: MemPools,
|
|
182
|
-
|
|
224
|
+
protected archiver: L2BlockSource & ContractDataSource,
|
|
183
225
|
private epochCache: EpochCacheInterface,
|
|
184
226
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
185
227
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
228
|
+
private blockMinFeesProvider: BlockMinFeesProvider,
|
|
186
229
|
telemetry: TelemetryClient,
|
|
187
230
|
logger: Logger = createLogger('p2p:libp2p_service'),
|
|
231
|
+
private txValidationCache?: TxValidationCache,
|
|
188
232
|
) {
|
|
189
233
|
super(telemetry, 'LibP2PService');
|
|
190
234
|
this.telemetry = telemetry;
|
|
@@ -214,36 +258,66 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
214
258
|
this.protocolVersion,
|
|
215
259
|
);
|
|
216
260
|
|
|
217
|
-
|
|
218
|
-
|
|
261
|
+
// Build the consensus timetable once from protocol slot-timing constants and inject it into every
|
|
262
|
+
// validator so they share one set of receive-window bounds, independent of proposer operational budgets.
|
|
263
|
+
const consensusTimetable = buildConsensusTimetable(config, epochCache.getL1Constants());
|
|
264
|
+
const proposalValidatorOpts = {
|
|
219
265
|
txsPermitted: !config.disableTransactions,
|
|
220
|
-
|
|
266
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
267
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
268
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
269
|
+
signatureContext: {
|
|
270
|
+
chainId: config.l1ChainId,
|
|
271
|
+
rollupAddress: config.rollupAddress,
|
|
272
|
+
},
|
|
273
|
+
clockDisparityMs: config.maxGossipClockDisparityMs,
|
|
274
|
+
};
|
|
275
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, proposalValidatorOpts);
|
|
276
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(
|
|
277
|
+
epochCache,
|
|
278
|
+
consensusTimetable,
|
|
279
|
+
proposalValidatorOpts,
|
|
280
|
+
);
|
|
281
|
+
const attestationValidatorOpts = {
|
|
282
|
+
signatureContext: proposalValidatorOpts.signatureContext,
|
|
283
|
+
clockDisparityMs: config.maxGossipClockDisparityMs,
|
|
284
|
+
};
|
|
221
285
|
this.checkpointAttestationValidator = config.fishermanMode
|
|
222
|
-
? new FishermanAttestationValidator(
|
|
223
|
-
|
|
286
|
+
? new FishermanAttestationValidator(
|
|
287
|
+
epochCache,
|
|
288
|
+
consensusTimetable,
|
|
289
|
+
mempools.attestationPool,
|
|
290
|
+
telemetry,
|
|
291
|
+
attestationValidatorOpts,
|
|
292
|
+
)
|
|
293
|
+
: new CheckpointAttestationValidator(epochCache, consensusTimetable, attestationValidatorOpts);
|
|
224
294
|
|
|
225
295
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
226
296
|
|
|
227
297
|
this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
|
|
228
|
-
this.logger.
|
|
229
|
-
`Handler not yet registered
|
|
298
|
+
this.logger.warn(
|
|
299
|
+
`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
|
|
230
300
|
{ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
|
|
231
301
|
);
|
|
232
|
-
return
|
|
302
|
+
return true;
|
|
233
303
|
};
|
|
234
304
|
|
|
235
|
-
this.
|
|
236
|
-
|
|
305
|
+
this.allNodesCheckpointReceivedCallback = (
|
|
306
|
+
_checkpoint: CheckpointProposalCore,
|
|
307
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
308
|
+
throw new CheckpointProposalReceivedCallbackNotRegisteredError();
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
this.validatorCheckpointReceivedCallback = (
|
|
312
|
+
_checkpoint: CheckpointProposalCore,
|
|
237
313
|
): 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
314
|
return Promise.resolve(undefined);
|
|
242
315
|
};
|
|
243
316
|
}
|
|
244
317
|
|
|
245
|
-
public updateConfig(config: Partial<P2PReqRespConfig
|
|
318
|
+
public updateConfig(config: Partial<P2PReqRespConfig & Pick<P2PConfig, 'skipIncomingProposals'>>) {
|
|
246
319
|
this.reqresp.updateConfig(config);
|
|
320
|
+
this.config = merge(this.config, config);
|
|
247
321
|
}
|
|
248
322
|
|
|
249
323
|
/**
|
|
@@ -252,8 +326,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
252
326
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
253
327
|
* @returns The new service.
|
|
254
328
|
*/
|
|
255
|
-
public static async new
|
|
256
|
-
clientType: T,
|
|
329
|
+
public static async new(
|
|
257
330
|
config: P2PConfig,
|
|
258
331
|
peerId: PeerId,
|
|
259
332
|
deps: {
|
|
@@ -263,9 +336,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
263
336
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
264
337
|
worldStateSynchronizer: WorldStateSynchronizer;
|
|
265
338
|
peerStore: AztecAsyncKVStore;
|
|
339
|
+
blockMinFeesProvider: BlockMinFeesProvider;
|
|
266
340
|
telemetry: TelemetryClient;
|
|
267
341
|
logger: Logger;
|
|
268
342
|
packageVersion: string;
|
|
343
|
+
txValidationCache?: TxValidationCache;
|
|
269
344
|
},
|
|
270
345
|
) {
|
|
271
346
|
const {
|
|
@@ -275,9 +350,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
275
350
|
mempools,
|
|
276
351
|
proofVerifier,
|
|
277
352
|
peerStore,
|
|
353
|
+
blockMinFeesProvider,
|
|
278
354
|
telemetry,
|
|
279
355
|
logger,
|
|
280
356
|
packageVersion,
|
|
357
|
+
txValidationCache,
|
|
281
358
|
} = deps;
|
|
282
359
|
const { p2pPort, maxPeerCount, listenAddress } = config;
|
|
283
360
|
const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
|
|
@@ -292,6 +369,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
292
369
|
packageVersion,
|
|
293
370
|
telemetry,
|
|
294
371
|
createLogger(`${logger.module}:discv5_service`, logger.getBindings()),
|
|
372
|
+
peerStore,
|
|
295
373
|
);
|
|
296
374
|
|
|
297
375
|
// Seed libp2p's bootstrap discovery with private and trusted peers
|
|
@@ -305,30 +383,50 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
305
383
|
const versions = getVersions(config);
|
|
306
384
|
const protocolVersion = compressComponentVersions(versions);
|
|
307
385
|
|
|
308
|
-
const txTopic = createTopicString(TopicType.tx, protocolVersion);
|
|
309
|
-
const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
|
|
310
|
-
const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
|
|
311
|
-
const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
|
|
312
|
-
|
|
313
386
|
const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
|
|
314
|
-
const directPeers = (
|
|
387
|
+
const directPeers = compactArray(
|
|
315
388
|
await Promise.all(
|
|
316
389
|
preferredPeersEnrs.map(async enr => {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
390
|
+
try {
|
|
391
|
+
const peerId = await enr.peerId();
|
|
392
|
+
const address = enr.getLocationMultiaddr('tcp');
|
|
393
|
+
if (address === undefined) {
|
|
394
|
+
throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
id: peerId,
|
|
398
|
+
addrs: [address],
|
|
399
|
+
};
|
|
400
|
+
} catch (err) {
|
|
401
|
+
// A malformed configured ENR shouldn't abort node setup — skip it and log.
|
|
402
|
+
logger.warn(`Skipping preferred peer with invalid ENR`, { err });
|
|
403
|
+
return undefined;
|
|
321
404
|
}
|
|
322
|
-
return {
|
|
323
|
-
id: peerId,
|
|
324
|
-
addrs: [address],
|
|
325
|
-
};
|
|
326
405
|
}),
|
|
327
|
-
)
|
|
328
|
-
)
|
|
406
|
+
),
|
|
407
|
+
);
|
|
329
408
|
|
|
330
409
|
const announceTcpMultiaddr = config.p2pIp ? [convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')] : [];
|
|
331
410
|
|
|
411
|
+
// Create dynamic topic score params based on network configuration. Scoring uses the network-wide
|
|
412
|
+
// max-blocks-per-checkpoint config value directly to size expected per-slot message rates; these are
|
|
413
|
+
// peer-rate thresholds, not consensus deadlines, so they need no proposer operational budgets.
|
|
414
|
+
const l1Constants = epochCache.getL1Constants();
|
|
415
|
+
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
416
|
+
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
417
|
+
heartbeatIntervalMs: config.gossipsubInterval,
|
|
418
|
+
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
419
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint ?? DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
|
|
420
|
+
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// Restrict gossipsub to exactly the topics we subscribe to. Without this, an arbitrary-topic
|
|
424
|
+
// message is transformed, msg-id'd and inserted into the seenCache before the subscription check,
|
|
425
|
+
// so a crafted topic colliding on msg id can suppress a real message as a duplicate.
|
|
426
|
+
const allowedTopics = getTopicsForConfig(config.disableTransactions).map(topic =>
|
|
427
|
+
createTopicString(topic, protocolVersion),
|
|
428
|
+
);
|
|
429
|
+
|
|
332
430
|
const node = await createLibp2p({
|
|
333
431
|
start: false,
|
|
334
432
|
peerId,
|
|
@@ -360,7 +458,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
360
458
|
],
|
|
361
459
|
datastore,
|
|
362
460
|
peerDiscovery,
|
|
363
|
-
|
|
461
|
+
// Pin the yamux frame size: MAX_REQRESP_REQUEST_SIZE_BYTES relies on a reqresp request fitting in one frame.
|
|
462
|
+
streamMuxers: [yamux({ maxMessageSize: YAMUX_MAX_MESSAGE_SIZE_BYTES }), mplex()],
|
|
364
463
|
connectionEncryption: [noise()],
|
|
365
464
|
connectionManager: {
|
|
366
465
|
minConnections: 0, // Disable libp2p peer dialing, we do it manually
|
|
@@ -374,7 +473,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
374
473
|
},
|
|
375
474
|
connectionGater: {
|
|
376
475
|
denyInboundConnection: (maConn: MultiaddrConnection) => {
|
|
377
|
-
const allowed = peerManager.
|
|
476
|
+
const allowed = peerManager.isAddressAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
|
|
378
477
|
if (allowed) {
|
|
379
478
|
return false;
|
|
380
479
|
}
|
|
@@ -385,7 +484,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
385
484
|
denyInboundEncryptedConnection: (peerId: PeerId, _maConn: MultiaddrConnection) => {
|
|
386
485
|
//NOTE: it is not necessary to check address here because this was already done by
|
|
387
486
|
// denyInboundConnection
|
|
388
|
-
const allowed = peerManager.
|
|
487
|
+
const allowed = peerManager.isPeerAllowedToConnect(peerId);
|
|
389
488
|
if (allowed) {
|
|
390
489
|
return false;
|
|
391
490
|
}
|
|
@@ -413,9 +512,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
413
512
|
mcacheLength: config.gossipsubMcacheLength,
|
|
414
513
|
mcacheGossip: config.gossipsubMcacheGossip,
|
|
415
514
|
seenTTL: config.gossipsubSeenTTL,
|
|
515
|
+
allowedTopics,
|
|
516
|
+
// No fastMsgIdFn: the fast-path dedup cache keys on a non-cryptographic 64-bit hash of the
|
|
517
|
+
// raw data only (no topic), so a collision — accidental or engineered via a weak seed — drops
|
|
518
|
+
// a different message with no fallback to the full id. Dedup instead rests solely on the
|
|
519
|
+
// cryptographic, topic-framed msgIdFn below.
|
|
416
520
|
msgIdFn: getMsgIdFn,
|
|
417
521
|
msgIdToStrFn: msgIdToStrFn,
|
|
418
|
-
fastMsgIdFn: fastMsgIdFn,
|
|
419
522
|
dataTransform: new SnappyTransform(),
|
|
420
523
|
metricsRegister: otelMetricsAdapter,
|
|
421
524
|
metricsTopicStrToLabel: metricsTopicStrToLabels(protocolVersion),
|
|
@@ -424,32 +527,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
424
527
|
scoreParams: createPeerScoreParams({
|
|
425
528
|
// IPColocation factor can be disabled for local testing - default to -5
|
|
426
529
|
IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
|
|
427
|
-
topics:
|
|
428
|
-
[txTopic]: createTopicScoreParams({
|
|
429
|
-
topicWeight: 1,
|
|
430
|
-
invalidMessageDeliveriesWeight: -20,
|
|
431
|
-
invalidMessageDeliveriesDecay: 0.5,
|
|
432
|
-
}),
|
|
433
|
-
[blockProposalTopic]: createTopicScoreParams({
|
|
434
|
-
topicWeight: 1,
|
|
435
|
-
invalidMessageDeliveriesWeight: -20,
|
|
436
|
-
invalidMessageDeliveriesDecay: 0.5,
|
|
437
|
-
}),
|
|
438
|
-
[checkpointProposalTopic]: createTopicScoreParams({
|
|
439
|
-
topicWeight: 1,
|
|
440
|
-
invalidMessageDeliveriesWeight: -20,
|
|
441
|
-
invalidMessageDeliveriesDecay: 0.5,
|
|
442
|
-
}),
|
|
443
|
-
[checkpointAttestationTopic]: createTopicScoreParams({
|
|
444
|
-
topicWeight: 1,
|
|
445
|
-
invalidMessageDeliveriesWeight: -20,
|
|
446
|
-
invalidMessageDeliveriesDecay: 0.5,
|
|
447
|
-
}),
|
|
448
|
-
},
|
|
530
|
+
topics: topicScoreParams,
|
|
449
531
|
}),
|
|
450
532
|
}) as (components: GossipSubComponents) => GossipSub,
|
|
451
|
-
components: (components: { connectionManager: ConnectionManager }) => ({
|
|
533
|
+
components: (components: { connectionManager: ConnectionManager; addressManager: AddressManager }) => ({
|
|
452
534
|
connectionManager: components.connectionManager,
|
|
535
|
+
addressManager: components.addressManager,
|
|
453
536
|
}),
|
|
454
537
|
},
|
|
455
538
|
logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
|
|
@@ -471,13 +554,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
471
554
|
epochCache,
|
|
472
555
|
);
|
|
473
556
|
|
|
474
|
-
//
|
|
475
|
-
|
|
557
|
+
// Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
|
|
558
|
+
reqresp.setShouldRejectPeer(peerId => peerManager.shouldDisableP2PGossip(peerId));
|
|
559
|
+
|
|
560
|
+
// Configure application-specific scoring for gossipsub.
|
|
561
|
+
// The weight scales app score to align with gossipsub thresholds:
|
|
562
|
+
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
563
|
+
// - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
|
|
564
|
+
// Note: positive topic scores can offset penalties, so alignment is best-effort.
|
|
565
|
+
node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
|
|
476
566
|
node.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
|
|
477
567
|
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
478
568
|
|
|
479
569
|
return new LibP2PService(
|
|
480
|
-
clientType,
|
|
481
570
|
config,
|
|
482
571
|
node,
|
|
483
572
|
peerDiscoveryService,
|
|
@@ -488,8 +577,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
488
577
|
epochCache,
|
|
489
578
|
proofVerifier,
|
|
490
579
|
worldStateSynchronizer,
|
|
580
|
+
blockMinFeesProvider,
|
|
491
581
|
telemetry,
|
|
492
582
|
logger,
|
|
583
|
+
txValidationCache,
|
|
493
584
|
);
|
|
494
585
|
}
|
|
495
586
|
|
|
@@ -503,28 +594,29 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
503
594
|
throw new Error('P2P service already started');
|
|
504
595
|
}
|
|
505
596
|
|
|
506
|
-
// Get listen & announce addresses for logging
|
|
507
597
|
const { p2pIp, p2pPort } = this.config;
|
|
508
|
-
if (!p2pIp) {
|
|
509
|
-
throw new Error('Announce address not provided.');
|
|
598
|
+
if (!p2pIp && !this.config.queryForIp) {
|
|
599
|
+
throw new Error('Announce address not provided and queryForIp is not enabled.');
|
|
510
600
|
}
|
|
511
|
-
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
601
|
+
const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
|
|
512
602
|
|
|
513
603
|
// Create request response protocol handlers
|
|
514
604
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
515
605
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
516
|
-
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
517
606
|
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
518
607
|
|
|
519
608
|
const requestResponseHandlers: Partial<ReqRespSubProtocolHandlers> = {
|
|
520
609
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
521
610
|
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
522
611
|
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
|
|
523
|
-
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
524
612
|
};
|
|
525
613
|
|
|
526
614
|
if (!this.config.disableTransactions) {
|
|
527
|
-
const blockTxsHandler = reqRespBlockTxsHandler(
|
|
615
|
+
const blockTxsHandler = reqRespBlockTxsHandler(
|
|
616
|
+
this.mempools.attestationPool,
|
|
617
|
+
this.archiver,
|
|
618
|
+
this.mempools.txPool,
|
|
619
|
+
);
|
|
528
620
|
requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
|
|
529
621
|
}
|
|
530
622
|
|
|
@@ -532,22 +624,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
532
624
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
533
625
|
}
|
|
534
626
|
|
|
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
627
|
await this.peerManager.initializePeers();
|
|
544
628
|
|
|
545
|
-
await this.reqresp.start(requestResponseHandlers
|
|
629
|
+
await this.reqresp.start(requestResponseHandlers);
|
|
546
630
|
|
|
547
631
|
await this.node.start();
|
|
548
632
|
|
|
549
633
|
// Subscribe to standard GossipSub topics by default
|
|
550
|
-
for (const topic of
|
|
634
|
+
for (const topic of getTopicsForConfig(this.config.disableTransactions)) {
|
|
551
635
|
this.subscribeToTopic(this.topicStrings[topic]);
|
|
552
636
|
}
|
|
553
637
|
|
|
@@ -558,6 +642,38 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
558
642
|
if (!this.config.p2pDiscoveryDisabled) {
|
|
559
643
|
await this.peerDiscoveryService.start();
|
|
560
644
|
}
|
|
645
|
+
|
|
646
|
+
// Bridge discv5 IP changes to libp2p's AddressManager so peers see the updated address
|
|
647
|
+
if (this.config.queryForIp) {
|
|
648
|
+
this.discoveredP2pIp = this.config.p2pIp;
|
|
649
|
+
this.logger.info('IP change tracking enabled, bridging discv5 IP updates to libp2p AddressManager');
|
|
650
|
+
this.ipChangedHandler = (ip: string) => {
|
|
651
|
+
const addressManager = this.node.services.components.addressManager;
|
|
652
|
+
const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
|
|
653
|
+
const previousIp = this.discoveredP2pIp;
|
|
654
|
+
|
|
655
|
+
if (previousIp) {
|
|
656
|
+
const oldAddr = multiaddr(convertToMultiaddr(previousIp, this.config.p2pPort, 'tcp'));
|
|
657
|
+
addressManager.removeObservedAddr(oldAddr);
|
|
658
|
+
this.logger.info('Libp2p announce address updated due to IP change', {
|
|
659
|
+
previousIp,
|
|
660
|
+
newIp: ip,
|
|
661
|
+
newMultiaddr: newAddr.toString(),
|
|
662
|
+
});
|
|
663
|
+
} else {
|
|
664
|
+
this.logger.info('Libp2p announce address set from initial discv5 IP discovery', {
|
|
665
|
+
ip,
|
|
666
|
+
multiaddr: newAddr.toString(),
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
addressManager.addObservedAddr(newAddr);
|
|
671
|
+
addressManager.confirmObservedAddr(newAddr);
|
|
672
|
+
this.discoveredP2pIp = ip;
|
|
673
|
+
};
|
|
674
|
+
this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
|
|
675
|
+
}
|
|
676
|
+
|
|
561
677
|
this.discoveryRunningPromise = new RunningPromise(
|
|
562
678
|
async () => {
|
|
563
679
|
await this.peerManager.heartbeat();
|
|
@@ -583,6 +699,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
583
699
|
// Remove gossip sub listener
|
|
584
700
|
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
585
701
|
|
|
702
|
+
if (this.ipChangedHandler) {
|
|
703
|
+
this.peerDiscoveryService.removeListener('ip:changed', this.ipChangedHandler);
|
|
704
|
+
this.ipChangedHandler = undefined;
|
|
705
|
+
}
|
|
706
|
+
|
|
586
707
|
// Stop peer manager
|
|
587
708
|
this.logger.debug('Stopping peer manager...');
|
|
588
709
|
await this.peerManager.stop();
|
|
@@ -597,12 +718,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
597
718
|
this.logger.info('LibP2P service stopped');
|
|
598
719
|
}
|
|
599
720
|
|
|
600
|
-
addReqRespSubProtocol(
|
|
601
|
-
subProtocol
|
|
602
|
-
handler: ReqRespSubProtocolHandler,
|
|
603
|
-
validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
604
|
-
): Promise<void> {
|
|
605
|
-
return this.reqresp.addSubProtocol(subProtocol, handler, validator);
|
|
721
|
+
addReqRespSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void> {
|
|
722
|
+
return this.reqresp.addSubProtocol(subProtocol, handler);
|
|
606
723
|
}
|
|
607
724
|
|
|
608
725
|
public registerThisValidatorAddresses(address: EthAddress[]): void {
|
|
@@ -613,6 +730,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
613
730
|
return this.peerManager.getPeers(includePending);
|
|
614
731
|
}
|
|
615
732
|
|
|
733
|
+
public getGossipMeshPeerCount(topicType: TopicType): number {
|
|
734
|
+
return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
|
|
735
|
+
}
|
|
736
|
+
|
|
616
737
|
private handleGossipSubEvent(e: CustomEvent<GossipsubMessage>) {
|
|
617
738
|
this.logger.trace(`Received PUBSUB message.`);
|
|
618
739
|
|
|
@@ -626,20 +747,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
626
747
|
setImmediate(() => void safeJob());
|
|
627
748
|
}
|
|
628
749
|
|
|
629
|
-
/**
|
|
630
|
-
* Send a batch of requests to peers, and return the responses
|
|
631
|
-
* @param protocol - The request response protocol to use
|
|
632
|
-
* @param requests - The requests to send to the peers
|
|
633
|
-
* @returns The responses to the requests
|
|
634
|
-
*/
|
|
635
|
-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
636
|
-
protocol: SubProtocol,
|
|
637
|
-
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
638
|
-
pinnedPeerId: PeerId | undefined,
|
|
639
|
-
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
|
|
640
|
-
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
641
|
-
}
|
|
642
|
-
|
|
643
750
|
public sendRequestToPeer(
|
|
644
751
|
peerId: PeerId,
|
|
645
752
|
subProtocol: ReqRespSubProtocol,
|
|
@@ -661,8 +768,42 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
661
768
|
this.blockReceivedCallback = callback;
|
|
662
769
|
}
|
|
663
770
|
|
|
664
|
-
public
|
|
665
|
-
this.
|
|
771
|
+
public registerValidatorCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
772
|
+
this.validatorCheckpointReceivedCallback = callback;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
public registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
776
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Registers a callback to be invoked when a duplicate proposal is detected.
|
|
781
|
+
* This callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
782
|
+
*/
|
|
783
|
+
public registerDuplicateProposalCallback(
|
|
784
|
+
callback: (info: { slot: SlotNumber; proposer: EthAddress; type: 'checkpoint' | 'block' }) => void,
|
|
785
|
+
): void {
|
|
786
|
+
this.duplicateProposalCallback = callback;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Registers a callback to be invoked when an oversized block proposal is stored as slashing evidence.
|
|
791
|
+
*/
|
|
792
|
+
public registerOversizedProposalCallback(callback: P2POversizedProposalCallback): void {
|
|
793
|
+
this.oversizedProposalCallback = callback;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Registers a callback to be invoked when a duplicate attestation is detected.
|
|
798
|
+
* A validator signing attestations for different proposals at the same slot.
|
|
799
|
+
* This callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
800
|
+
*/
|
|
801
|
+
public registerDuplicateAttestationCallback(callback: P2PDuplicateAttestationCallback): void {
|
|
802
|
+
this.duplicateAttestationCallback = callback;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
public registerCheckpointAttestationCallback(callback: P2PCheckpointAttestationCallback): void {
|
|
806
|
+
this.checkpointAttestationCallback = callback;
|
|
666
807
|
}
|
|
667
808
|
|
|
668
809
|
/**
|
|
@@ -729,6 +870,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
729
870
|
if (!validator || !validator.addMessage(msgId)) {
|
|
730
871
|
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
731
872
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
873
|
+
if (topicType === TopicType.tx) {
|
|
874
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
|
|
875
|
+
}
|
|
732
876
|
return { result: false, topicType };
|
|
733
877
|
}
|
|
734
878
|
|
|
@@ -790,12 +934,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
790
934
|
|
|
791
935
|
// Process the message, optionally within a linked span for trace propagation
|
|
792
936
|
const processMessage = async () => {
|
|
937
|
+
if (
|
|
938
|
+
this.config.skipIncomingProposals &&
|
|
939
|
+
(msg.topic === this.topicStrings[TopicType.block_proposal] ||
|
|
940
|
+
msg.topic === this.topicStrings[TopicType.checkpoint_proposal])
|
|
941
|
+
) {
|
|
942
|
+
this.logger.warn(`Ignoring incoming proposal (skipIncomingProposals is set)`, { topic: msg.topic });
|
|
943
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
793
946
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
794
947
|
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
795
948
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
796
|
-
|
|
797
|
-
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
798
|
-
}
|
|
949
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
799
950
|
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
800
951
|
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
801
952
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
@@ -851,51 +1002,145 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
851
1002
|
return;
|
|
852
1003
|
}
|
|
853
1004
|
|
|
854
|
-
protected async validateReceivedMessage<T>(
|
|
855
|
-
validationFunc: () => Promise<ReceivedMessageValidationResult<T>>,
|
|
1005
|
+
protected async validateReceivedMessage<T, M = undefined>(
|
|
1006
|
+
validationFunc: () => Promise<ReceivedMessageValidationResult<T, M>>,
|
|
856
1007
|
msgId: string,
|
|
857
1008
|
source: PeerId,
|
|
858
1009
|
topicType: TopicType,
|
|
859
|
-
): Promise<ReceivedMessageValidationResult<T>> {
|
|
860
|
-
|
|
1010
|
+
): Promise<ReceivedMessageValidationResult<T, M>> {
|
|
1011
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
1012
|
+
let resultAndObj: ReceivedMessageValidationResult<T, M> = {
|
|
1013
|
+
result: TopicValidatorResult.Reject,
|
|
1014
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
1015
|
+
};
|
|
861
1016
|
const timer = new Timer();
|
|
862
1017
|
try {
|
|
863
1018
|
resultAndObj = await validationFunc();
|
|
864
1019
|
} catch (err) {
|
|
865
|
-
this.
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
1020
|
+
this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
const validationTimeMs = timer.ms();
|
|
1024
|
+
const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
|
|
1025
|
+
if (validationTimeMs > mcacheWindowMs * 0.75) {
|
|
1026
|
+
this.instrumentation.incSlowValidation(topicType);
|
|
1027
|
+
this.logger.warn(
|
|
1028
|
+
`Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` +
|
|
1029
|
+
`Message forwarding may be skipped if validation exceeds the window.`,
|
|
1030
|
+
{ msgId, source: source.toString(), topicType, validationTimeMs, mcacheWindowMs },
|
|
1031
|
+
);
|
|
871
1032
|
}
|
|
872
1033
|
|
|
873
1034
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
1035
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
|
|
874
1036
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
1037
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
1038
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
1039
|
+
msgId,
|
|
1040
|
+
source: source.toString(),
|
|
1041
|
+
topicType,
|
|
1042
|
+
severity: resultAndObj.severity,
|
|
1043
|
+
});
|
|
1044
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
1045
|
+
} else {
|
|
1046
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
|
|
875
1047
|
}
|
|
876
1048
|
|
|
877
1049
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
878
1050
|
return resultAndObj;
|
|
879
1051
|
}
|
|
880
1052
|
|
|
1053
|
+
private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
|
|
1054
|
+
try {
|
|
1055
|
+
return deserializeFunc();
|
|
1056
|
+
} catch (err) {
|
|
1057
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
1058
|
+
err,
|
|
1059
|
+
msgId,
|
|
1060
|
+
source: source.toString(),
|
|
1061
|
+
});
|
|
1062
|
+
return undefined;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
|
|
881
1066
|
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
882
1067
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
883
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
884
|
-
|
|
885
|
-
|
|
1068
|
+
const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
|
|
1069
|
+
if (!tx) {
|
|
1070
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1074
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1075
|
+
|
|
1076
|
+
// Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
|
|
1077
|
+
const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1078
|
+
const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
|
|
1079
|
+
if (!firstStageOutcome.allPassed) {
|
|
1080
|
+
const { name } = firstStageOutcome.failure;
|
|
1081
|
+
let { severity } = firstStageOutcome.failure;
|
|
1082
|
+
|
|
1083
|
+
// Double spend validator has a special case handler. We perform more detailed examination
|
|
1084
|
+
// as to how recently the nullifier was entered into the tree and if the transaction should
|
|
1085
|
+
// have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
|
|
1086
|
+
if (name === 'doubleSpendValidator') {
|
|
1087
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1088
|
+
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
1092
|
+
validator: name,
|
|
1093
|
+
severity,
|
|
1094
|
+
source: source.toString(),
|
|
1095
|
+
});
|
|
1096
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
1100
|
+
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
1101
|
+
if (canAdd === 'ignored') {
|
|
1102
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
1103
|
+
source: source.toString(),
|
|
1104
|
+
});
|
|
1105
|
+
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// Stage 2: expensive proof verification
|
|
1109
|
+
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
1110
|
+
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
1111
|
+
if (!secondStageOutcome.allPassed) {
|
|
1112
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
1113
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1114
|
+
validator: name,
|
|
1115
|
+
severity,
|
|
1116
|
+
source: source.toString(),
|
|
1117
|
+
});
|
|
1118
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// Pool add: persist the tx
|
|
1122
|
+
const txHash = tx.getTxHash();
|
|
1123
|
+
const addResult = await this.mempools.txPool.addPendingTxs([tx], { source: 'gossip' });
|
|
886
1124
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1125
|
+
const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
|
|
1126
|
+
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
1127
|
+
|
|
1128
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
1129
|
+
wasAccepted,
|
|
1130
|
+
wasIgnored,
|
|
890
1131
|
[Attributes.P2P_ID]: source.toString(),
|
|
891
1132
|
});
|
|
892
1133
|
|
|
893
|
-
if (
|
|
894
|
-
return { result: TopicValidatorResult.
|
|
895
|
-
} else if (
|
|
1134
|
+
if (wasAccepted) {
|
|
1135
|
+
return { result: TopicValidatorResult.Accept, obj: tx };
|
|
1136
|
+
} else if (wasIgnored) {
|
|
896
1137
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
897
1138
|
} else {
|
|
898
|
-
|
|
1139
|
+
this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
|
|
1140
|
+
source: source.toString(),
|
|
1141
|
+
txHash: txHash.toString(),
|
|
1142
|
+
});
|
|
1143
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
899
1144
|
}
|
|
900
1145
|
};
|
|
901
1146
|
|
|
@@ -904,6 +1149,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
904
1149
|
return;
|
|
905
1150
|
}
|
|
906
1151
|
|
|
1152
|
+
// Tx was accepted into pool and will be propagated - just log and record metrics
|
|
907
1153
|
const txHash = tx.getTxHash();
|
|
908
1154
|
const txHashString = txHash.toString();
|
|
909
1155
|
this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
|
|
@@ -911,13 +1157,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
911
1157
|
txHash: txHashString,
|
|
912
1158
|
});
|
|
913
1159
|
|
|
914
|
-
if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
|
|
915
|
-
this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
1160
|
this.instrumentation.incrementTxReceived(1);
|
|
920
|
-
await this.mempools.txPool.addTxs([tx]);
|
|
921
1161
|
}
|
|
922
1162
|
|
|
923
1163
|
/**
|
|
@@ -929,47 +1169,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
929
1169
|
msgId: string,
|
|
930
1170
|
source: PeerId,
|
|
931
1171
|
): 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
|
-
}
|
|
946
|
-
|
|
947
|
-
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
948
|
-
isValid,
|
|
949
|
-
exists,
|
|
950
|
-
canAdd,
|
|
951
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
|
|
952
|
-
[Attributes.P2P_ID]: source.toString(),
|
|
953
|
-
});
|
|
954
|
-
|
|
955
|
-
if (validationResult.result === 'reject') {
|
|
956
|
-
return { result: TopicValidatorResult.Reject };
|
|
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
|
-
});
|
|
965
|
-
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
966
|
-
} else {
|
|
967
|
-
return { result: TopicValidatorResult.Accept, obj: attestation };
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
|
|
971
1172
|
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
972
|
-
|
|
1173
|
+
() => {
|
|
1174
|
+
const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1175
|
+
if (!attestation) {
|
|
1176
|
+
return Promise.resolve({
|
|
1177
|
+
result: TopicValidatorResult.Reject,
|
|
1178
|
+
severity: PeerErrorSeverity.LowToleranceError,
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1182
|
+
},
|
|
973
1183
|
msgId,
|
|
974
1184
|
source,
|
|
975
1185
|
TopicType.checkpoint_attestation,
|
|
@@ -979,8 +1189,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
979
1189
|
return;
|
|
980
1190
|
}
|
|
981
1191
|
|
|
982
|
-
this.logger.
|
|
983
|
-
`Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
1192
|
+
this.logger.verbose(
|
|
1193
|
+
`Received valid checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
984
1194
|
{
|
|
985
1195
|
p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
|
|
986
1196
|
slot: attestation.slotNumber,
|
|
@@ -988,60 +1198,192 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
988
1198
|
source: source.toString(),
|
|
989
1199
|
},
|
|
990
1200
|
);
|
|
991
|
-
|
|
992
|
-
await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
|
|
993
1201
|
}
|
|
994
1202
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1203
|
+
/** Validates a checkpoint attestation and adds it to the pool. Penalizes the peer if validation fails. */
|
|
1204
|
+
@trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation) => ({
|
|
1205
|
+
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
|
|
1206
|
+
}))
|
|
1207
|
+
protected async validateAndStoreCheckpointAttestation(
|
|
1208
|
+
peerId: PeerId,
|
|
1209
|
+
attestation: CheckpointAttestation,
|
|
1210
|
+
): Promise<ReceivedMessageValidationResult<CheckpointAttestation>> {
|
|
1211
|
+
const validationResult = await this.checkpointAttestationValidator.validate(attestation);
|
|
1212
|
+
|
|
1213
|
+
if (validationResult.result === 'reject') {
|
|
1214
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1215
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
if (validationResult.result === 'ignore') {
|
|
1219
|
+
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
// Try to add the attestation: this handles existence check, cap check, and adding in one call
|
|
1223
|
+
// count is the number of attestations by this signer for this slot (for duplicate detection)
|
|
1224
|
+
const slot = attestation.payload.header.slotNumber;
|
|
1225
|
+
const { added, alreadyExists, count } =
|
|
1226
|
+
await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation);
|
|
1227
|
+
|
|
1228
|
+
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
1229
|
+
added,
|
|
1230
|
+
alreadyExists,
|
|
1231
|
+
count,
|
|
1232
|
+
[Attributes.SLOT_NUMBER]: slot.toString(),
|
|
1233
|
+
[Attributes.P2P_ID]: peerId.toString(),
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
// Exact same attestation received, no need to re-broadcast
|
|
1237
|
+
if (alreadyExists) {
|
|
1238
|
+
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1242
|
+
if (!added) {
|
|
1243
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1244
|
+
slot: slot.toString(),
|
|
1245
|
+
archive: attestation.archive.toString(),
|
|
1246
|
+
source: peerId.toString(),
|
|
1247
|
+
attester: attestation.getSender()?.toString(),
|
|
1248
|
+
count,
|
|
1011
1249
|
});
|
|
1250
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
1251
|
+
}
|
|
1012
1252
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
this.
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1253
|
+
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
1254
|
+
// count is the number of attestations by this signer for this slot
|
|
1255
|
+
if (count === 2) {
|
|
1256
|
+
const attester = attestation.getSender();
|
|
1257
|
+
if (attester) {
|
|
1258
|
+
this.logger.warn(`Detected duplicate attestation (equivocation) at slot ${slot}`, {
|
|
1259
|
+
slot: slot.toString(),
|
|
1260
|
+
archive: attestation.archive.toString(),
|
|
1261
|
+
source: peerId.toString(),
|
|
1262
|
+
attester: attester.toString(),
|
|
1023
1263
|
});
|
|
1024
|
-
|
|
1025
|
-
} else {
|
|
1026
|
-
return { result: TopicValidatorResult.Accept, obj: block };
|
|
1264
|
+
this.duplicateAttestationCallback?.({ slot, attester });
|
|
1027
1265
|
}
|
|
1028
|
-
}
|
|
1266
|
+
}
|
|
1029
1267
|
|
|
1030
|
-
|
|
1031
|
-
|
|
1268
|
+
// Attestation was added successfully - accept it so other nodes can also detect the equivocation
|
|
1269
|
+
this.checkpointAttestationCallback?.(attestation);
|
|
1270
|
+
return { result: TopicValidatorResult.Accept, obj: attestation };
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
protected async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
1274
|
+
const {
|
|
1275
|
+
result,
|
|
1276
|
+
obj: block,
|
|
1277
|
+
metadata: { isEquivocated, isOversized } = {},
|
|
1278
|
+
} = await this.validateReceivedMessage<BlockProposal, { isEquivocated: boolean; isOversized: boolean }>(
|
|
1279
|
+
() => this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)),
|
|
1032
1280
|
msgId,
|
|
1033
1281
|
source,
|
|
1034
1282
|
TopicType.block_proposal,
|
|
1035
1283
|
);
|
|
1036
1284
|
|
|
1037
|
-
|
|
1285
|
+
// If not accepted, equivocated, or oversized, return. Oversized proposals are re-broadcast as
|
|
1286
|
+
// slashing evidence but never attested or processed.
|
|
1287
|
+
if (result !== TopicValidatorResult.Accept || !block || isEquivocated || isOversized) {
|
|
1038
1288
|
return;
|
|
1039
1289
|
}
|
|
1040
1290
|
|
|
1041
1291
|
await this.processValidBlockProposal(block, source);
|
|
1042
1292
|
}
|
|
1043
1293
|
|
|
1044
|
-
|
|
1294
|
+
/** Validates a block proposal. Triggers a penalization to the peer that sent it if invalid. Adds to the mempool if valid. */
|
|
1295
|
+
@trackSpan('Libp2pService.validateAndStoreBlockProposal', (_peerId, block) => ({
|
|
1296
|
+
[Attributes.BLOCK_NUMBER]: block.blockNumber.toString(),
|
|
1297
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
1298
|
+
}))
|
|
1299
|
+
protected async validateAndStoreBlockProposal(
|
|
1300
|
+
peerId: PeerId,
|
|
1301
|
+
block: BlockProposal,
|
|
1302
|
+
): Promise<ReceivedMessageValidationResult<BlockProposal, { isEquivocated: boolean; isOversized: boolean }>> {
|
|
1303
|
+
const validationResult = await this.blockProposalValidator.validate(block);
|
|
1304
|
+
|
|
1305
|
+
if (validationResult.result === 'reject') {
|
|
1306
|
+
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1307
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
if (validationResult.result === 'ignore') {
|
|
1311
|
+
return { result: TopicValidatorResult.Ignore, obj: block };
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// Try to add the proposal: this handles existence check, cap check, and adding in one call
|
|
1315
|
+
const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
|
|
1316
|
+
const isEquivocated = count !== undefined && count > 1;
|
|
1317
|
+
// An oversized proposal (index at or beyond the consensus per-checkpoint limit) is structurally valid
|
|
1318
|
+
// proposer misbehavior: it is stored and re-broadcast as slashing evidence but never processed or
|
|
1319
|
+
// attested to. No-ops when maxBlocksPerCheckpoint is unset (local/test).
|
|
1320
|
+
const isOversized =
|
|
1321
|
+
this.config.maxBlocksPerCheckpoint !== undefined &&
|
|
1322
|
+
block.indexWithinCheckpoint >= this.config.maxBlocksPerCheckpoint;
|
|
1323
|
+
|
|
1324
|
+
// Duplicate proposal received, no need to re-broadcast
|
|
1325
|
+
if (alreadyExists) {
|
|
1326
|
+
this.logger.debug(`Ignoring duplicate block proposal received`, {
|
|
1327
|
+
...block.toBlockInfo(),
|
|
1328
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1329
|
+
proposer: block.getSender()?.toString(),
|
|
1330
|
+
source: peerId.toString(),
|
|
1331
|
+
});
|
|
1332
|
+
return { result: TopicValidatorResult.Ignore, obj: block, metadata: { isEquivocated, isOversized } };
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1336
|
+
if (!added) {
|
|
1337
|
+
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1338
|
+
...block.toBlockInfo(),
|
|
1339
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1340
|
+
count,
|
|
1341
|
+
proposer: block.getSender()?.toString(),
|
|
1342
|
+
source: peerId.toString(),
|
|
1343
|
+
});
|
|
1344
|
+
return {
|
|
1345
|
+
result: TopicValidatorResult.Reject,
|
|
1346
|
+
metadata: { isEquivocated, isOversized },
|
|
1347
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
// The proposal was stored: if oversized, invoke the oversized callback so the proposer can be
|
|
1352
|
+
// slashed. Fired alongside (not instead of) equivocation detection below.
|
|
1353
|
+
if (isOversized) {
|
|
1354
|
+
const proposer = block.getSender();
|
|
1355
|
+
if (proposer) {
|
|
1356
|
+
this.logger.warn(`Detected oversized block proposal at slot ${block.slotNumber}`, {
|
|
1357
|
+
...block.toBlockInfo(),
|
|
1358
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1359
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint,
|
|
1360
|
+
source: peerId.toString(),
|
|
1361
|
+
proposer: proposer.toString(),
|
|
1362
|
+
});
|
|
1363
|
+
this.oversizedProposalCallback?.({ slot: block.slotNumber, proposer });
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1368
|
+
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1369
|
+
if (isEquivocated) {
|
|
1370
|
+
const proposer = block.getSender();
|
|
1371
|
+
this.logger.warn(`Detected duplicate block proposal (equivocation) at slot ${block.slotNumber}`, {
|
|
1372
|
+
...block.toBlockInfo(),
|
|
1373
|
+
source: peerId.toString(),
|
|
1374
|
+
proposer: proposer?.toString(),
|
|
1375
|
+
});
|
|
1376
|
+
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1377
|
+
if (proposer && count === 2) {
|
|
1378
|
+
this.duplicateProposalCallback?.({ slot: block.slotNumber, proposer, type: 'block' });
|
|
1379
|
+
}
|
|
1380
|
+
return { result: TopicValidatorResult.Accept, obj: block, metadata: { isEquivocated, isOversized } };
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
// Otherwise, we're good to go!
|
|
1384
|
+
return { result: TopicValidatorResult.Accept, obj: block, metadata: { isEquivocated: false, isOversized } };
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1045
1387
|
// REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
|
|
1046
1388
|
// should not be here as it does not deal with p2p networking.
|
|
1047
1389
|
@trackSpan('Libp2pService.processValidBlockProposal', async block => ({
|
|
@@ -1049,7 +1391,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1049
1391
|
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
1050
1392
|
[Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1051
1393
|
}))
|
|
1052
|
-
|
|
1394
|
+
protected async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
|
|
1053
1395
|
const slot = block.slotNumber;
|
|
1054
1396
|
this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
1055
1397
|
p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
|
|
@@ -1057,98 +1399,215 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1057
1399
|
...block.toBlockInfo(),
|
|
1058
1400
|
});
|
|
1059
1401
|
|
|
1060
|
-
//
|
|
1402
|
+
// Mark the txs in this proposal as protected
|
|
1403
|
+
await this.mempools.txPool.protectTxs(block.txHashes, block.blockHeader);
|
|
1404
|
+
|
|
1405
|
+
if (!(await this.tryBlockReceivedCallback(block, sender))) {
|
|
1406
|
+
// Release the protections this proposal created so its txs return to pending. Only entries still
|
|
1407
|
+
// keyed to this slot are cleared, so a tx referenced by a live proposal at another slot stays protected.
|
|
1408
|
+
await this.mempools.txPool.unprotectTxs(block.txHashes, slot);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
/**
|
|
1413
|
+
* Runs the block received callback to validate a proposal, and returns whether it was accepted.
|
|
1414
|
+
* A callback that throws is reported as a rejection: the proposal is no more usable than one explicitly
|
|
1415
|
+
* rejected, and letting the error escape would leave the proposal's tx protections in place.
|
|
1416
|
+
* Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1417
|
+
*/
|
|
1418
|
+
private async tryBlockReceivedCallback(block: BlockProposal, sender: PeerId): Promise<boolean> {
|
|
1061
1419
|
try {
|
|
1062
|
-
await this.
|
|
1063
|
-
|
|
1064
|
-
|
|
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;
|
|
1420
|
+
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1421
|
+
if (!isValid) {
|
|
1422
|
+
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1072
1423
|
}
|
|
1073
|
-
|
|
1424
|
+
return isValid;
|
|
1425
|
+
} catch (err) {
|
|
1426
|
+
this.logger.error(`Error validating block proposal for block ${block.blockNumber}`, err, block.toBlockInfo());
|
|
1427
|
+
return false;
|
|
1074
1428
|
}
|
|
1429
|
+
}
|
|
1075
1430
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1431
|
+
/**
|
|
1432
|
+
* Handle a gossiped checkpoint proposal.
|
|
1433
|
+
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1434
|
+
*/
|
|
1435
|
+
protected async handleGossipedCheckpointProposal(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
1436
|
+
const {
|
|
1437
|
+
result,
|
|
1438
|
+
obj: checkpoint,
|
|
1439
|
+
metadata: { isEquivocated, processBlock, isOversized } = {},
|
|
1440
|
+
} = await this.validateReceivedMessage<
|
|
1441
|
+
CheckpointProposal,
|
|
1442
|
+
{ isEquivocated: boolean; processBlock: boolean; isOversized: boolean }
|
|
1443
|
+
>(
|
|
1444
|
+
() => this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)),
|
|
1445
|
+
msgId,
|
|
1446
|
+
source,
|
|
1447
|
+
TopicType.checkpoint_proposal,
|
|
1448
|
+
);
|
|
1078
1449
|
|
|
1079
|
-
//
|
|
1080
|
-
//
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1450
|
+
// An oversized checkpoint is re-broadcast as slashing evidence but never attested or processed.
|
|
1451
|
+
// Process checkpoint proposal if valid and neither equivocated nor oversized.
|
|
1452
|
+
const processCheckpointFn = () =>
|
|
1453
|
+
result === TopicValidatorResult.Accept && checkpoint && !isEquivocated && !isOversized
|
|
1454
|
+
? this.processValidCheckpointProposal(checkpoint.toCore(), source)
|
|
1455
|
+
: Promise.resolve();
|
|
1456
|
+
|
|
1457
|
+
// If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
|
|
1458
|
+
// TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
|
|
1459
|
+
const processBlockFn = () =>
|
|
1460
|
+
processBlock && checkpoint && checkpoint.getBlockProposal()
|
|
1461
|
+
? this.processValidBlockProposal(checkpoint.getBlockProposal()!, source)
|
|
1462
|
+
: Promise.resolve();
|
|
1463
|
+
|
|
1464
|
+
// A node that skips checkpoint validation attests without re-executing the embedded last block, so run
|
|
1465
|
+
// the checkpoint callback first: this creates and broadcasts the attestation before the block is
|
|
1466
|
+
// processed. Otherwise the block's re-execution — which can stall until the re-execution deadline
|
|
1467
|
+
// waiting for a parent that may never arrive — would delay the attestation past the slot's attestation
|
|
1468
|
+
// window, after which peers reject it as stale.
|
|
1469
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
1470
|
+
await processCheckpointFn();
|
|
1471
|
+
await processBlockFn();
|
|
1472
|
+
return;
|
|
1084
1473
|
}
|
|
1474
|
+
|
|
1475
|
+
// Process the block first, since it's required for the checkpoint proposal validation.
|
|
1476
|
+
await processBlockFn();
|
|
1477
|
+
await processCheckpointFn();
|
|
1085
1478
|
}
|
|
1086
1479
|
|
|
1087
1480
|
/**
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1481
|
+
* Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
|
|
1482
|
+
* its last block (if present) to the mempool if valid. Triggers equivocation detection on both.
|
|
1090
1483
|
*/
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1484
|
+
@trackSpan('Libp2pService.validateAndStoreCheckpointProposal', (_peerId, checkpoint) => ({
|
|
1485
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1486
|
+
}))
|
|
1487
|
+
protected async validateAndStoreCheckpointProposal(
|
|
1488
|
+
peerId: PeerId,
|
|
1489
|
+
checkpoint: CheckpointProposal,
|
|
1490
|
+
): Promise<
|
|
1491
|
+
ReceivedMessageValidationResult<
|
|
1492
|
+
CheckpointProposal,
|
|
1493
|
+
{ isEquivocated: boolean; processBlock: boolean; isOversized: boolean }
|
|
1494
|
+
>
|
|
1495
|
+
> {
|
|
1496
|
+
const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1497
|
+
|
|
1498
|
+
if (validationResult.result === 'reject') {
|
|
1499
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1500
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
if (validationResult.result === 'ignore') {
|
|
1504
|
+
return { result: TopicValidatorResult.Ignore, obj: checkpoint };
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
// Extract and try to add the block proposal first if present
|
|
1508
|
+
const blockProposal = checkpoint.getBlockProposal();
|
|
1509
|
+
let processBlock = false;
|
|
1510
|
+
let isOversized = false;
|
|
1511
|
+
if (blockProposal) {
|
|
1512
|
+
this.logger.debug(`Validating block proposal from propagated checkpoint`, {
|
|
1106
1513
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1107
|
-
[Attributes.P2P_ID]:
|
|
1514
|
+
[Attributes.P2P_ID]: peerId.toString(),
|
|
1108
1515
|
});
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
source: source.toString(),
|
|
1516
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1517
|
+
const { obj, metadata: { isEquivocated, isOversized: blockIsOversized } = {} } = blockProposalResult;
|
|
1518
|
+
isOversized = blockIsOversized ?? false;
|
|
1519
|
+
|
|
1520
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1521
|
+
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1522
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1523
|
+
[Attributes.P2P_ID]: peerId.toString(),
|
|
1524
|
+
isEquivocated,
|
|
1525
|
+
result: blockProposalResult.result,
|
|
1120
1526
|
});
|
|
1121
|
-
return {
|
|
1122
|
-
|
|
1123
|
-
|
|
1527
|
+
return {
|
|
1528
|
+
result: TopicValidatorResult.Reject,
|
|
1529
|
+
severity:
|
|
1530
|
+
'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
|
|
1531
|
+
};
|
|
1532
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated && !isOversized) {
|
|
1533
|
+
// An oversized terminal block is re-broadcast as slashing evidence but never processed.
|
|
1534
|
+
processBlock = true;
|
|
1124
1535
|
}
|
|
1125
|
-
}
|
|
1536
|
+
}
|
|
1126
1537
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1538
|
+
// Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
|
|
1539
|
+
const checkpointCore = checkpoint.toCore();
|
|
1540
|
+
const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
|
|
1541
|
+
const { added, alreadyExists, count } = tryAddResult;
|
|
1542
|
+
const isEquivocated = count !== undefined && count > 1;
|
|
1543
|
+
|
|
1544
|
+
// Duplicate proposal received, do not re-broadcast
|
|
1545
|
+
if (alreadyExists) {
|
|
1546
|
+
this.logger.debug(`Ignoring duplicate checkpoint proposal received`, {
|
|
1547
|
+
...checkpoint.toCheckpointInfo(),
|
|
1548
|
+
source: peerId.toString(),
|
|
1549
|
+
});
|
|
1550
|
+
return {
|
|
1551
|
+
result: TopicValidatorResult.Ignore,
|
|
1552
|
+
obj: checkpoint,
|
|
1553
|
+
metadata: { isEquivocated, processBlock, isOversized },
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1133
1556
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1557
|
+
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast.
|
|
1558
|
+
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1559
|
+
if (!added) {
|
|
1560
|
+
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1561
|
+
...checkpoint.toCheckpointInfo(),
|
|
1562
|
+
count,
|
|
1563
|
+
source: peerId.toString(),
|
|
1564
|
+
});
|
|
1565
|
+
return {
|
|
1566
|
+
result: TopicValidatorResult.Reject,
|
|
1567
|
+
obj: checkpoint,
|
|
1568
|
+
metadata: { isEquivocated, processBlock, isOversized },
|
|
1569
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1570
|
+
};
|
|
1136
1571
|
}
|
|
1137
1572
|
|
|
1138
|
-
|
|
1573
|
+
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1574
|
+
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1575
|
+
if (isEquivocated) {
|
|
1576
|
+
const proposer = checkpoint.getSender();
|
|
1577
|
+
this.logger.warn(`Detected duplicate checkpoint proposal (equivocation) at slot ${checkpoint.slotNumber}`, {
|
|
1578
|
+
...checkpoint.toCheckpointInfo(),
|
|
1579
|
+
source: peerId.toString(),
|
|
1580
|
+
proposer: proposer?.toString(),
|
|
1581
|
+
});
|
|
1582
|
+
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1583
|
+
if (proposer && count === 2) {
|
|
1584
|
+
this.duplicateProposalCallback?.({ slot: checkpoint.slotNumber, proposer, type: 'checkpoint' });
|
|
1585
|
+
}
|
|
1586
|
+
return {
|
|
1587
|
+
result: TopicValidatorResult.Accept,
|
|
1588
|
+
obj: checkpoint,
|
|
1589
|
+
metadata: { isEquivocated, processBlock, isOversized },
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// Otherwise, we're good to go!
|
|
1594
|
+
return {
|
|
1595
|
+
result: TopicValidatorResult.Accept,
|
|
1596
|
+
obj: checkpoint,
|
|
1597
|
+
metadata: { processBlock, isEquivocated, isOversized },
|
|
1598
|
+
};
|
|
1139
1599
|
}
|
|
1140
1600
|
|
|
1141
1601
|
/**
|
|
1142
1602
|
* Process a validated checkpoint proposal.
|
|
1143
|
-
*
|
|
1144
|
-
* The block callback is invoked before the checkpoint callback.
|
|
1603
|
+
* Note: The proposal was already added to the pool by tryAddCheckpointProposal in handleGossipedCheckpointProposal.
|
|
1145
1604
|
*/
|
|
1146
1605
|
@trackSpan('Libp2pService.processValidCheckpointProposal', async checkpoint => ({
|
|
1147
1606
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
1148
1607
|
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
1149
1608
|
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1150
1609
|
}))
|
|
1151
|
-
|
|
1610
|
+
protected async processValidCheckpointProposal(checkpoint: CheckpointProposalCore, sender: PeerId) {
|
|
1152
1611
|
const slot = checkpoint.slotNumber;
|
|
1153
1612
|
this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
1154
1613
|
p2pMessageIdentifier: await checkpoint.p2pMessageLoggingIdentifier(),
|
|
@@ -1157,37 +1616,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1157
1616
|
source: sender.toString(),
|
|
1158
1617
|
});
|
|
1159
1618
|
|
|
1160
|
-
|
|
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
|
-
}
|
|
1619
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1184
1620
|
|
|
1185
1621
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1186
1622
|
// to validate and potentially generate attestations
|
|
1187
|
-
const attestations = await this.
|
|
1623
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1188
1624
|
if (attestations && attestations.length > 0) {
|
|
1189
1625
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1190
|
-
await this.mempools.attestationPool.
|
|
1626
|
+
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
1191
1627
|
for (const attestation of attestations) {
|
|
1192
1628
|
await this.propagate(attestation);
|
|
1193
1629
|
}
|
|
@@ -1207,82 +1643,87 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1207
1643
|
}
|
|
1208
1644
|
|
|
1209
1645
|
/**
|
|
1210
|
-
* Validate the requested block transactions
|
|
1646
|
+
* Validate the requested block transactions request-response consistency.
|
|
1647
|
+
* It does NOT validate the transactions themselves.
|
|
1211
1648
|
* @param request - The block transactions request.
|
|
1212
1649
|
* @param response - The block transactions response.
|
|
1213
1650
|
* @param peerId - The ID of the peer that made the request.
|
|
1214
|
-
* @returns True if the
|
|
1651
|
+
* @returns True if the request-response is consistent, false otherwise.
|
|
1215
1652
|
*/
|
|
1216
|
-
@trackSpan('Libp2pService.
|
|
1217
|
-
[Attributes.
|
|
1653
|
+
@trackSpan('Libp2pService.validateRequestedBlockTxsConsistency', request => ({
|
|
1654
|
+
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
|
|
1218
1655
|
}))
|
|
1219
|
-
|
|
1656
|
+
protected async validateRequestedBlockTxsConsistency(
|
|
1220
1657
|
request: BlockTxsRequest,
|
|
1221
1658
|
response: BlockTxsResponse,
|
|
1222
1659
|
peerId: PeerId,
|
|
1223
1660
|
): Promise<boolean> {
|
|
1224
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1225
|
-
|
|
1226
1661
|
try {
|
|
1227
|
-
|
|
1662
|
+
// Check for duplicates txs (or hashes) in the response.
|
|
1663
|
+
const returnedHashes = response.txs.map(tx => tx.getTxHash().toString());
|
|
1664
|
+
const uniqueReturned = new Set(returnedHashes.map(h => h.toString()));
|
|
1665
|
+
if (uniqueReturned.size !== returnedHashes.length) {
|
|
1228
1666
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1229
|
-
throw new ValidationError(
|
|
1230
|
-
|
|
1667
|
+
throw new ValidationError(`Received duplicate txs in block txs response`);
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
// We get the block tx hashes from the proposal or the archiver.
|
|
1671
|
+
const proposal = await this.mempools.attestationPool.getBlockProposalByArchive(request.archiveRoot.toString());
|
|
1672
|
+
const blockTxHashes =
|
|
1673
|
+
proposal?.txHashes ??
|
|
1674
|
+
(await this.archiver.getBlock({ archive: request.archiveRoot }))?.body.txEffects.map(e => e.txHash);
|
|
1675
|
+
|
|
1676
|
+
// If we don't have the block, we can't verify membership/order of the returned txs.
|
|
1677
|
+
if (!blockTxHashes) {
|
|
1678
|
+
// This shouldn't happen, since we asked for the block (proposal).
|
|
1679
|
+
// Neither a local proposal nor an archived block: we cannot verify membership/order of the
|
|
1680
|
+
// returned txs. This is a local-state gap, not a peer fault, so we do not penalize.
|
|
1681
|
+
this.logger.warn(
|
|
1682
|
+
`Block ${request.archiveRoot.toString()} not found in attestation pool or archiver; cannot validate membership/order of returned txs`,
|
|
1231
1683
|
);
|
|
1684
|
+
// NOTE: We mark the response as invalid, given the limitations of a true/false return value.
|
|
1685
|
+
return false;
|
|
1232
1686
|
}
|
|
1233
1687
|
|
|
1234
|
-
|
|
1235
|
-
|
|
1688
|
+
// Verify that the returned tx hashes are a subset of (tx hashes by index) U (explicitly requested tx hashes).
|
|
1689
|
+
const uniqueRequestedHashes = new Set([
|
|
1690
|
+
// tx hashes requested by index.
|
|
1691
|
+
...request.txIndices.getTrueIndices().map(i => blockTxHashes[i].toString()),
|
|
1692
|
+
// explicitly requested tx hashes.
|
|
1693
|
+
...request.txHashes.map(h => h.toString()),
|
|
1694
|
+
]);
|
|
1695
|
+
if (!returnedHashes.every(h => uniqueRequestedHashes.has(h))) {
|
|
1696
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1236
1697
|
throw new ValidationError(
|
|
1237
|
-
|
|
1698
|
+
'Returned txs should be a subset of (tx hashes by index) U (explicitly requested tx hashes)',
|
|
1238
1699
|
);
|
|
1239
1700
|
}
|
|
1240
1701
|
|
|
1241
|
-
//
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
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`);
|
|
1702
|
+
// Tx indices information is optional, but if present, we need to verify a few things.
|
|
1703
|
+
if (!response.peerHasBlock()) {
|
|
1704
|
+
this.logger.debug(`Peer ${peerId.toString()} signalled missing block`);
|
|
1705
|
+
return true;
|
|
1251
1706
|
}
|
|
1252
|
-
|
|
1707
|
+
|
|
1708
|
+
// If the response has a non-empty bitvector, it needs to be consistent with the number of txs in the block.
|
|
1709
|
+
if (response.txIndices.getLength() !== blockTxHashes.length) {
|
|
1253
1710
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1254
1711
|
throw new ValidationError(
|
|
1255
|
-
`Received
|
|
1712
|
+
`Received block txs with mismatched bitvector length: expected ${blockTxHashes.length}, got ${response.txIndices.getLength()}`,
|
|
1256
1713
|
);
|
|
1257
1714
|
}
|
|
1258
1715
|
|
|
1259
|
-
//
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
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;
|
|
1716
|
+
// For every index we requested that the peer claims to have (per its bitvector), the
|
|
1717
|
+
// corresponding tx must be present in the response. A peer advertising availability but
|
|
1718
|
+
// withholding the tx is inconsistent.
|
|
1719
|
+
const returnedHashSet = new Set(returnedHashes);
|
|
1720
|
+
const expectedIndices = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
|
|
1721
|
+
const missingExpected = expectedIndices.some(i => !returnedHashSet.has(blockTxHashes[i].toString()));
|
|
1722
|
+
if (missingExpected) {
|
|
1723
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1724
|
+
throw new ValidationError('Peer advertised requested txs via indices but did not return them');
|
|
1283
1725
|
}
|
|
1284
1726
|
|
|
1285
|
-
await Promise.all(response.txs.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
1286
1727
|
return true;
|
|
1287
1728
|
} catch (e: any) {
|
|
1288
1729
|
if (e instanceof ValidationError) {
|
|
@@ -1295,151 +1736,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1295
1736
|
}
|
|
1296
1737
|
}
|
|
1297
1738
|
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
*
|
|
1301
|
-
* The core component of this validator is that each tx hash MUST match the requested tx hash,
|
|
1302
|
-
* In order to perform this check, the tx proof must be verified.
|
|
1303
|
-
*
|
|
1304
|
-
* Note: This function is called from within `ReqResp.sendRequest` as part of the
|
|
1305
|
-
* ReqRespSubProtocol.TX subprotocol validation.
|
|
1306
|
-
*
|
|
1307
|
-
* @param requestedTxHash - The collection of the txs that was requested.
|
|
1308
|
-
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
1309
|
-
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1310
|
-
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
1311
|
-
*/
|
|
1312
|
-
@trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx) => ({
|
|
1313
|
-
[Attributes.TX_HASH]: requestedTxHash.toString(),
|
|
1314
|
-
}))
|
|
1315
|
-
private async validateRequestedTxs(requestedTxHash: TxHash[], responseTx: Tx[], peerId: PeerId): Promise<boolean> {
|
|
1316
|
-
const requested = new Set(requestedTxHash.map(h => h.toString()));
|
|
1317
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1318
|
-
|
|
1319
|
-
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
1320
|
-
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1321
|
-
try {
|
|
1322
|
-
await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
1323
|
-
return true;
|
|
1324
|
-
} catch (e: any) {
|
|
1325
|
-
if (e instanceof ValidationError) {
|
|
1326
|
-
this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
|
|
1327
|
-
} else {
|
|
1328
|
-
this.logger.error(`Error during validation of requested txs`, e);
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
return false;
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
|
|
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
|
-
}
|
|
1360
|
-
|
|
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;
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
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);
|
|
1384
|
-
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1385
|
-
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1386
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
const { result } = await txValidator.validateTx(tx);
|
|
1390
|
-
if (result === 'invalid') {
|
|
1391
|
-
penalize(PeerErrorSeverity.LowToleranceError);
|
|
1392
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
private createRequestedTxValidator(): TxValidator {
|
|
1397
|
-
return createTxReqRespValidator(this.proofVerifier, {
|
|
1398
|
-
l1ChainId: this.config.l1ChainId,
|
|
1399
|
-
rollupVersion: this.config.rollupVersion,
|
|
1400
|
-
});
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
1404
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1405
|
-
}))
|
|
1406
|
-
private async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
|
|
1407
|
-
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1408
|
-
|
|
1409
|
-
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1410
|
-
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1411
|
-
const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1412
|
-
|
|
1413
|
-
for (const validator of messageValidators) {
|
|
1414
|
-
const outcome = await this.runValidations(tx, validator);
|
|
1415
|
-
|
|
1416
|
-
if (outcome.allPassed) {
|
|
1417
|
-
continue;
|
|
1418
|
-
}
|
|
1419
|
-
const { name } = outcome.failure;
|
|
1420
|
-
let { severity } = outcome.failure;
|
|
1421
|
-
|
|
1422
|
-
// Double spend validator has a special case handler
|
|
1423
|
-
if (name === 'doubleSpendValidator') {
|
|
1424
|
-
const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
|
|
1425
|
-
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1429
|
-
return false;
|
|
1430
|
-
}
|
|
1431
|
-
return true;
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
|
|
1435
|
-
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1436
|
-
return this.feesCache.gasFees;
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
1440
|
-
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
1441
|
-
this.feesCache = { blockNumber, gasFees };
|
|
1442
|
-
return gasFees;
|
|
1739
|
+
private getGasFees(): Promise<GasFees> {
|
|
1740
|
+
return this.blockMinFeesProvider.getCurrentMinFees();
|
|
1443
1741
|
}
|
|
1444
1742
|
|
|
1445
1743
|
/**
|
|
@@ -1453,65 +1751,72 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1453
1751
|
l1ChainId: this.config.l1ChainId,
|
|
1454
1752
|
rollupVersion: this.config.rollupVersion,
|
|
1455
1753
|
proofVerifier: this.proofVerifier,
|
|
1754
|
+
txValidationCache: this.txValidationCache,
|
|
1456
1755
|
},
|
|
1457
1756
|
peerScoring: this.peerManager,
|
|
1757
|
+
validateRequestedBlockTxsConsistency: this.validateRequestedBlockTxsConsistency.bind(this),
|
|
1458
1758
|
};
|
|
1459
1759
|
}
|
|
1460
1760
|
|
|
1461
|
-
public async
|
|
1462
|
-
const
|
|
1761
|
+
public async validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
1762
|
+
const validator = createTxValidatorForBlockProposalReceivedTxs(
|
|
1763
|
+
this.proofVerifier,
|
|
1764
|
+
{ l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
|
|
1765
|
+
this.logger.getBindings(),
|
|
1766
|
+
this.txValidationCache,
|
|
1767
|
+
);
|
|
1463
1768
|
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1769
|
+
const results = await Promise.all(
|
|
1770
|
+
txs.map(async tx => ({ txHash: tx.getTxHash(), result: await validator.validateTx(tx) })),
|
|
1771
|
+
);
|
|
1467
1772
|
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
for (const validator of messageValidators) {
|
|
1471
|
-
const outcome = await this.runValidations(tx, validator);
|
|
1472
|
-
if (!outcome.allPassed) {
|
|
1473
|
-
throw new Error('Invalid tx detected', { cause: { outcome } });
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
}),
|
|
1773
|
+
const invalidTxs = results.flatMap(({ txHash, result }) =>
|
|
1774
|
+
result.result === 'invalid' ? [{ txHash, reasons: result.reason }] : [],
|
|
1477
1775
|
);
|
|
1776
|
+
|
|
1777
|
+
if (invalidTxs.length > 0) {
|
|
1778
|
+
throw new InvalidBlockProposalTxsError(invalidTxs);
|
|
1779
|
+
}
|
|
1478
1780
|
}
|
|
1479
1781
|
|
|
1480
|
-
/**
|
|
1481
|
-
|
|
1482
|
-
*
|
|
1483
|
-
* Each validator is a pair of a validator and a severity.
|
|
1484
|
-
* If a validator fails, the peer is penalized with the severity of the validator.
|
|
1485
|
-
*
|
|
1486
|
-
* @param currentBlockNumber - The current synced block number.
|
|
1487
|
-
* @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
|
|
1488
|
-
* @returns The message validators.
|
|
1489
|
-
*/
|
|
1490
|
-
private async createMessageValidators(
|
|
1782
|
+
/** Creates the first stage (fast) validators for gossiped transactions. */
|
|
1783
|
+
protected async createFirstStageMessageValidators(
|
|
1491
1784
|
currentBlockNumber: BlockNumber,
|
|
1492
1785
|
nextSlotTimestamp: UInt64,
|
|
1493
|
-
): Promise<Record<string,
|
|
1494
|
-
const gasFees = await this.getGasFees(
|
|
1495
|
-
const allowedInSetup =
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1786
|
+
): Promise<Record<string, TransactionValidator>> {
|
|
1787
|
+
const gasFees = await this.getGasFees();
|
|
1788
|
+
const allowedInSetup = [
|
|
1789
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1790
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1791
|
+
];
|
|
1792
|
+
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1793
|
+
const l1Constants = await this.archiver.getL1Constants();
|
|
1794
|
+
const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
|
|
1795
|
+
|
|
1796
|
+
return createFirstStageTxValidationsForGossipedTransactions(
|
|
1500
1797
|
nextSlotTimestamp,
|
|
1501
|
-
|
|
1798
|
+
blockNumber,
|
|
1502
1799
|
this.worldStateSynchronizer,
|
|
1503
1800
|
gasFees,
|
|
1504
1801
|
this.config.l1ChainId,
|
|
1505
1802
|
this.config.rollupVersion,
|
|
1506
1803
|
protocolContractsHash,
|
|
1507
1804
|
this.archiver,
|
|
1508
|
-
this.proofVerifier,
|
|
1509
1805
|
!this.config.disableTransactions,
|
|
1510
1806
|
allowedInSetup,
|
|
1511
1807
|
this.logger.getBindings(),
|
|
1808
|
+
{
|
|
1809
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
1810
|
+
maxTxDAGas: networkTxGasLimits.daGas,
|
|
1811
|
+
},
|
|
1512
1812
|
);
|
|
1513
1813
|
}
|
|
1514
1814
|
|
|
1815
|
+
/** Creates the second stage (expensive proof verification) validators for gossiped transactions. */
|
|
1816
|
+
protected createSecondStageMessageValidators(): Record<string, TransactionValidator> {
|
|
1817
|
+
return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1515
1820
|
/**
|
|
1516
1821
|
* Run validations on a tx.
|
|
1517
1822
|
* @param tx - The tx to validate.
|
|
@@ -1520,7 +1825,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1520
1825
|
*/
|
|
1521
1826
|
private async runValidations(
|
|
1522
1827
|
tx: Tx,
|
|
1523
|
-
messageValidators: Record<string,
|
|
1828
|
+
messageValidators: Record<string, TransactionValidator>,
|
|
1524
1829
|
): Promise<ValidationOutcome> {
|
|
1525
1830
|
const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
|
|
1526
1831
|
const { result } = await validator.validateTx(tx);
|
|
@@ -1529,8 +1834,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1529
1834
|
|
|
1530
1835
|
// A promise that resolves when all validations have been run
|
|
1531
1836
|
const allValidations = await Promise.all(validationPromises);
|
|
1532
|
-
const
|
|
1533
|
-
if (
|
|
1837
|
+
const failures = allValidations.filter(x => !x.isValid);
|
|
1838
|
+
if (failures.length > 0) {
|
|
1839
|
+
// Pick the most severe failure (lowest tolerance = harshest penalty)
|
|
1840
|
+
const failed = maxBy(failures, f => PeerErrorSeverityByHarshness.indexOf(f.severity))!;
|
|
1534
1841
|
return {
|
|
1535
1842
|
allPassed: false,
|
|
1536
1843
|
failure: {
|
|
@@ -1583,74 +1890,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1583
1890
|
return PeerErrorSeverity.HighToleranceError;
|
|
1584
1891
|
}
|
|
1585
1892
|
|
|
1586
|
-
/**
|
|
1587
|
-
* Validate a checkpoint attestation.
|
|
1588
|
-
*
|
|
1589
|
-
* @param attestation - The checkpoint attestation to validate.
|
|
1590
|
-
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1591
|
-
*/
|
|
1592
|
-
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1593
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1594
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1595
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1596
|
-
}))
|
|
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);
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
return result;
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
/**
|
|
1612
|
-
* Validate a block proposal.
|
|
1613
|
-
*
|
|
1614
|
-
* @param block - The block proposal to validate.
|
|
1615
|
-
* @returns True if the block proposal is valid, false otherwise.
|
|
1616
|
-
*/
|
|
1617
|
-
@trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
|
|
1618
|
-
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
1619
|
-
}))
|
|
1620
|
-
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<P2PValidationResult> {
|
|
1621
|
-
const result = await this.blockProposalValidator.validate(block);
|
|
1622
|
-
|
|
1623
|
-
if (result.result === 'reject') {
|
|
1624
|
-
this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1625
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1626
|
-
}
|
|
1627
|
-
|
|
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;
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
1893
|
public getPeerScore(peerId: PeerId): number {
|
|
1655
1894
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1656
1895
|
}
|