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