@aztec/p2p 0.0.0-test.0 → 0.0.1-commit.001888fc
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 +129 -3
- package/dest/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +26 -13
- package/dest/client/factory.d.ts +21 -11
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +101 -26
- package/dest/client/index.d.ts +2 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +183 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +93 -221
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +760 -289
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +304 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +192 -126
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +240 -36
- package/dest/enr/generate-enr.d.ts +11 -3
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/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 +5 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +125 -30
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +445 -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 +564 -173
- 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 +234 -11
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +19 -21
- package/dest/mem_pools/index.d.ts +3 -2
- 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 +18 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +58 -41
- package/dest/mem_pools/interface.d.ts +6 -7
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +75 -16
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +493 -142
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +123 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +8 -3
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +72 -11
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +279 -46
- 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 +43 -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 +103 -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 +10 -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 +11 -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_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
- 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 +215 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +10 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +134 -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 +216 -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 +108 -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 +337 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +62 -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 +167 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +78 -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 +923 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +7 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +79 -10
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +76 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +11 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +14 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +11 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +20 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +18 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +116 -0
- 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 +3 -3
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +4 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +31 -0
- 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 +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +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 +7 -6
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +60 -87
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -6
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +24 -29
- package/dest/msg_validators/tx_validator/factory.d.ts +148 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +265 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +24 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +76 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +177 -0
- package/dest/msg_validators/tx_validator/index.d.ts +11 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +10 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +10 -5
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +40 -21
- 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 +35 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +141 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +30 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +8 -7
- 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 +10 -6
- package/dest/services/discv5/discV5_service.d.ts +10 -9
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +64 -37
- package/dest/services/dummy_service.d.ts +74 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +136 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +82 -12
- 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 +173 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +346 -0
- package/dest/services/index.d.ts +6 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +5 -0
- package/dest/services/libp2p/instrumentation.d.ts +20 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +122 -0
- package/dest/services/libp2p/libp2p_service.d.ts +165 -101
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +1478 -350
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +14 -3
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +50 -12
- package/dest/services/peer-manager/peer_manager.d.ts +103 -23
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +552 -82
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +68 -4
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +54 -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 +556 -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 +48 -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 +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/config.d.ts +11 -9
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +23 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +73 -10
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +32 -17
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +154 -84
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/index.d.ts +3 -2
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +84 -24
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +60 -27
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -21
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +6 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +30 -6
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +34 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +87 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +13 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +57 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +70 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +121 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +3 -1
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +1 -3
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +40 -7
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +76 -5
- package/dest/services/reqresp/protocols/tx.d.ts +20 -4
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +54 -6
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +29 -66
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +762 -249
- package/dest/services/reqresp/status.d.ts +10 -4
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +76 -20
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +46 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +112 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +54 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +327 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -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 +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -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 +90 -0
- package/dest/services/tx_collection/index.d.ts +5 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +4 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +49 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +57 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +211 -0
- package/dest/services/tx_collection/tx_collection.d.ts +123 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +200 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +40 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +108 -0
- package/dest/services/tx_collection/tx_source.d.ts +23 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +48 -0
- 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 +48 -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 +152 -0
- package/dest/services/tx_provider.d.ts +51 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +220 -0
- package/dest/services/tx_provider_instrumentation.d.ts +16 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +4 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +3 -0
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +35 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -17
- package/dest/test-helpers/mock-pubsub.d.ts +85 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +231 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +15 -12
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +63 -28
- package/dest/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +163 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +367 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +261 -91
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +53 -11
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +237 -54
- package/dest/types/index.d.ts +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +25 -17
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +75 -69
- package/dest/versioning.d.ts +4 -4
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +32 -27
- package/src/bootstrap/bootstrap.ts +34 -15
- package/src/client/factory.ts +215 -58
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +235 -0
- package/src/client/p2p_client.ts +474 -457
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +345 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +409 -135
- package/src/enr/generate-enr.ts +39 -6
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +5 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +530 -29
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +692 -201
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +25 -17
- package/src/mem_pools/index.ts +4 -1
- package/src/mem_pools/instrumentation.ts +75 -47
- package/src/mem_pools/interface.ts +5 -7
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +580 -143
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +163 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +10 -3
- package/src/mem_pools/tx_pool/tx_pool.ts +75 -10
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +228 -37
- 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 +120 -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 +27 -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 +247 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +337 -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 +430 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +238 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1105 -0
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +72 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +94 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +20 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +26 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +115 -0
- package/src/msg_validators/tx_validator/README.md +119 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +30 -0
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +23 -10
- package/src/msg_validators/tx_validator/data_validator.ts +95 -71
- package/src/msg_validators/tx_validator/double_spend_validator.ts +31 -23
- package/src/msg_validators/tx_validator/factory.ts +460 -0
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +44 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +219 -0
- package/src/msg_validators/tx_validator/index.ts +10 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +80 -24
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +173 -0
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +57 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +22 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +14 -8
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +85 -39
- package/src/services/dummy_service.ts +210 -9
- package/src/services/encoding.ts +87 -11
- package/src/services/gossipsub/README.md +641 -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 +487 -0
- package/src/services/index.ts +5 -0
- package/src/services/libp2p/instrumentation.ts +126 -0
- package/src/services/libp2p/libp2p_service.ts +1335 -402
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +62 -12
- package/src/services/peer-manager/peer_manager.ts +658 -80
- package/src/services/peer-manager/peer_scoring.ts +70 -3
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +698 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +55 -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 +37 -0
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +77 -10
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +166 -95
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +120 -37
- package/src/services/reqresp/metrics.ts +40 -28
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +26 -4
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +106 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +76 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +144 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +9 -7
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +121 -5
- package/src/services/reqresp/protocols/tx.ts +58 -8
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +462 -272
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +114 -22
- package/src/services/tx_collection/config.ts +166 -0
- package/src/services/tx_collection/fast_tx_collection.ts +387 -0
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +8 -0
- package/src/services/tx_collection/instrumentation.ts +41 -0
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +113 -0
- package/src/services/tx_collection/slow_tx_collection.ts +266 -0
- package/src/services/tx_collection/tx_collection.ts +313 -0
- package/src/services/tx_collection/tx_collection_sink.ts +125 -0
- package/src/services/tx_collection/tx_source.ts +56 -0
- 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 +175 -0
- package/src/services/tx_provider.ts +233 -0
- package/src/services/tx_provider_instrumentation.ts +54 -0
- package/src/test-helpers/index.ts +3 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +114 -26
- package/src/test-helpers/mock-pubsub.ts +325 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +91 -42
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +431 -0
- package/src/testbench/p2p_client_testbench_worker.ts +442 -93
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +323 -59
- package/src/types/index.ts +2 -0
- package/src/util.ts +112 -92
- package/src/versioning.ts +11 -4
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -22
- 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 -112
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -17
- 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 -129
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -56
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -141
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -8
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -21
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -159
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -161
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -174
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -29
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -1,73 +1,124 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { maxBy } from '@aztec/foundation/collection';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
+
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
6
8
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
7
|
-
import
|
|
9
|
+
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
10
|
+
import type { EthAddress, L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
11
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
12
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
8
13
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
14
|
import {
|
|
10
|
-
BlockAttestation,
|
|
11
15
|
BlockProposal,
|
|
16
|
+
CheckpointAttestation,
|
|
17
|
+
CheckpointProposal,
|
|
18
|
+
type CheckpointProposalCore,
|
|
12
19
|
type Gossipable,
|
|
13
|
-
|
|
20
|
+
P2PMessage,
|
|
21
|
+
type ValidationResult as P2PValidationResult,
|
|
14
22
|
PeerErrorSeverity,
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
PeerErrorSeverityByHarshness,
|
|
24
|
+
TopicType,
|
|
25
|
+
createTopicString,
|
|
26
|
+
getTopicsForConfig,
|
|
17
27
|
metricsTopicStrToLabels,
|
|
18
28
|
} from '@aztec/stdlib/p2p';
|
|
19
29
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
20
|
-
import { Tx, type TxHash, type TxValidationResult } from '@aztec/stdlib/tx';
|
|
21
|
-
import
|
|
30
|
+
import { Tx, type TxHash, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
31
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
32
|
+
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
33
|
+
import {
|
|
34
|
+
Attributes,
|
|
35
|
+
OtelMetricsAdapter,
|
|
36
|
+
SpanStatusCode,
|
|
37
|
+
type TelemetryClient,
|
|
38
|
+
WithTracer,
|
|
39
|
+
trackSpan,
|
|
40
|
+
} from '@aztec/telemetry-client';
|
|
22
41
|
|
|
23
|
-
import type { ENR } from '@chainsafe/enr';
|
|
24
42
|
import {
|
|
25
43
|
type GossipSub,
|
|
26
44
|
type GossipSubComponents,
|
|
27
45
|
type GossipsubMessage,
|
|
28
46
|
gossipsub,
|
|
29
47
|
} from '@chainsafe/libp2p-gossipsub';
|
|
30
|
-
import { createPeerScoreParams
|
|
48
|
+
import { createPeerScoreParams } from '@chainsafe/libp2p-gossipsub/score';
|
|
31
49
|
import { SignaturePolicy } from '@chainsafe/libp2p-gossipsub/types';
|
|
32
50
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
33
51
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
34
52
|
import { bootstrap } from '@libp2p/bootstrap';
|
|
35
53
|
import { identify } from '@libp2p/identify';
|
|
36
|
-
import { type Message, type PeerId, TopicValidatorResult } from '@libp2p/interface';
|
|
54
|
+
import { type Message, type MultiaddrConnection, type PeerId, TopicValidatorResult } from '@libp2p/interface';
|
|
37
55
|
import type { ConnectionManager } from '@libp2p/interface-internal';
|
|
38
|
-
import '@libp2p/kad-dht';
|
|
39
56
|
import { mplex } from '@libp2p/mplex';
|
|
40
57
|
import { tcp } from '@libp2p/tcp';
|
|
58
|
+
import { ENR } from '@nethermindeth/enr';
|
|
41
59
|
import { createLibp2p } from 'libp2p';
|
|
42
60
|
|
|
43
61
|
import type { P2PConfig } from '../../config.js';
|
|
44
62
|
import type { MemPools } from '../../mem_pools/interface.js';
|
|
45
|
-
import { AttestationValidator, BlockProposalValidator } from '../../msg_validators/index.js';
|
|
46
63
|
import {
|
|
47
|
-
|
|
64
|
+
BlockProposalValidator,
|
|
65
|
+
CheckpointAttestationValidator,
|
|
66
|
+
CheckpointProposalValidator,
|
|
48
67
|
DoubleSpendTxValidator,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} from '../../msg_validators/
|
|
68
|
+
FishermanAttestationValidator,
|
|
69
|
+
getDefaultAllowedSetupFunctions,
|
|
70
|
+
} from '../../msg_validators/index.js';
|
|
71
|
+
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
72
|
+
import {
|
|
73
|
+
type TransactionValidator,
|
|
74
|
+
createFirstStageTxValidationsForGossipedTransactions,
|
|
75
|
+
createSecondStageTxValidationsForGossipedTransactions,
|
|
76
|
+
createTxValidatorForBlockProposalReceivedTxs,
|
|
77
|
+
createTxValidatorForReqResponseReceivedTxs,
|
|
78
|
+
} from '../../msg_validators/tx_validator/factory.js';
|
|
52
79
|
import { GossipSubEvent } from '../../types/index.js';
|
|
53
80
|
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
81
|
+
import { getVersions } from '../../versioning.js';
|
|
54
82
|
import { AztecDatastore } from '../data_store.js';
|
|
83
|
+
import { DiscV5Service } from '../discv5/discV5_service.js';
|
|
55
84
|
import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
56
|
-
import { gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
85
|
+
import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
86
|
+
import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
|
|
87
|
+
import type { PeerManagerInterface } from '../peer-manager/interface.js';
|
|
57
88
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
58
89
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
59
|
-
import {
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
90
|
+
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
91
|
+
import type { P2PReqRespConfig } from '../reqresp/config.js';
|
|
92
|
+
import {
|
|
93
|
+
AuthRequest,
|
|
94
|
+
BlockTxsRequest,
|
|
95
|
+
BlockTxsResponse,
|
|
96
|
+
DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
97
|
+
type ReqRespInterface,
|
|
98
|
+
type ReqRespResponse,
|
|
99
|
+
ReqRespSubProtocol,
|
|
100
|
+
type ReqRespSubProtocolHandler,
|
|
101
|
+
type ReqRespSubProtocolHandlers,
|
|
102
|
+
type ReqRespSubProtocolValidators,
|
|
103
|
+
StatusMessage,
|
|
104
|
+
type SubProtocolMap,
|
|
105
|
+
ValidationError,
|
|
106
|
+
pingHandler,
|
|
107
|
+
reqGoodbyeHandler,
|
|
108
|
+
reqRespBlockHandler,
|
|
109
|
+
reqRespBlockTxsHandler,
|
|
110
|
+
reqRespStatusHandler,
|
|
111
|
+
reqRespTxHandler,
|
|
112
|
+
} from '../reqresp/index.js';
|
|
62
113
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
63
|
-
import type {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
114
|
+
import type {
|
|
115
|
+
P2PBlockReceivedCallback,
|
|
116
|
+
P2PCheckpointReceivedCallback,
|
|
117
|
+
P2PDuplicateAttestationCallback,
|
|
118
|
+
P2PService,
|
|
119
|
+
PeerDiscoveryService,
|
|
120
|
+
} from '../service.js';
|
|
121
|
+
import { P2PInstrumentation } from './instrumentation.js';
|
|
71
122
|
|
|
72
123
|
interface ValidationResult {
|
|
73
124
|
name: string;
|
|
@@ -77,146 +128,295 @@ interface ValidationResult {
|
|
|
77
128
|
|
|
78
129
|
type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: ValidationResult };
|
|
79
130
|
|
|
131
|
+
// REFACTOR: Unify with the type above
|
|
132
|
+
type ReceivedMessageValidationResult<T, M = undefined> =
|
|
133
|
+
| { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject>; metadata?: M }
|
|
134
|
+
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M };
|
|
135
|
+
|
|
80
136
|
/**
|
|
81
137
|
* Lib P2P implementation of the P2PService interface.
|
|
82
138
|
*/
|
|
83
|
-
export class LibP2PService
|
|
84
|
-
private jobQueue: SerialQueue = new SerialQueue();
|
|
85
|
-
private peerManager: PeerManager;
|
|
139
|
+
export class LibP2PService extends WithTracer implements P2PService {
|
|
86
140
|
private discoveryRunningPromise?: RunningPromise;
|
|
141
|
+
private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
|
|
87
142
|
|
|
88
143
|
// Message validators
|
|
89
|
-
private attestationValidator: AttestationValidator;
|
|
90
144
|
private blockProposalValidator: BlockProposalValidator;
|
|
145
|
+
private checkpointProposalValidator: CheckpointProposalValidator;
|
|
146
|
+
private checkpointAttestationValidator: CheckpointAttestationValidator;
|
|
91
147
|
|
|
92
|
-
|
|
93
|
-
|
|
148
|
+
private protocolVersion = '';
|
|
149
|
+
private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
|
|
150
|
+
|
|
151
|
+
private feesCache: { blockNumber: BlockNumber; gasFees: GasFees } | undefined;
|
|
152
|
+
|
|
153
|
+
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */
|
|
154
|
+
private duplicateProposalCallback?: (info: {
|
|
155
|
+
slot: SlotNumber;
|
|
156
|
+
proposer: EthAddress;
|
|
157
|
+
type: 'checkpoint' | 'block';
|
|
158
|
+
}) => void;
|
|
159
|
+
|
|
160
|
+
/** Callback invoked when a duplicate attestation is detected (triggers slashing). */
|
|
161
|
+
private duplicateAttestationCallback?: P2PDuplicateAttestationCallback;
|
|
94
162
|
|
|
95
163
|
/**
|
|
96
164
|
* Callback for when a block is received from a peer.
|
|
97
165
|
* @param block - The block received from the peer.
|
|
98
166
|
* @returns The attestation for the block, if any.
|
|
99
167
|
*/
|
|
100
|
-
private blockReceivedCallback:
|
|
168
|
+
private blockReceivedCallback: P2PBlockReceivedCallback;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Callback for when a checkpoint proposal is received from a peer.
|
|
172
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
173
|
+
* @returns The attestations for the checkpoint, if any.
|
|
174
|
+
*/
|
|
175
|
+
private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
176
|
+
|
|
177
|
+
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
178
|
+
|
|
179
|
+
private instrumentation: P2PInstrumentation;
|
|
180
|
+
|
|
181
|
+
private telemetry: TelemetryClient;
|
|
182
|
+
|
|
183
|
+
protected logger: Logger;
|
|
101
184
|
|
|
102
185
|
constructor(
|
|
103
|
-
private clientType: T,
|
|
104
186
|
private config: P2PConfig,
|
|
105
|
-
|
|
187
|
+
protected node: PubSubLibp2p,
|
|
106
188
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
107
|
-
private
|
|
108
|
-
|
|
109
|
-
|
|
189
|
+
private reqresp: ReqRespInterface,
|
|
190
|
+
protected peerManager: PeerManagerInterface,
|
|
191
|
+
protected mempools: MemPools,
|
|
192
|
+
protected archiver: L2BlockSource & ContractDataSource,
|
|
193
|
+
private epochCache: EpochCacheInterface,
|
|
110
194
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
111
195
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
112
196
|
telemetry: TelemetryClient,
|
|
113
|
-
|
|
197
|
+
logger: Logger = createLogger('p2p:libp2p_service'),
|
|
114
198
|
) {
|
|
115
199
|
super(telemetry, 'LibP2PService');
|
|
200
|
+
this.telemetry = telemetry;
|
|
116
201
|
|
|
117
|
-
|
|
118
|
-
this.
|
|
202
|
+
// Create child logger with fisherman prefix if in fisherman mode
|
|
203
|
+
this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
|
|
119
204
|
|
|
120
|
-
this.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
205
|
+
this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
|
|
206
|
+
|
|
207
|
+
this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
208
|
+
this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
209
|
+
this.msgIdSeenValidators[TopicType.checkpoint_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
210
|
+
this.msgIdSeenValidators[TopicType.checkpoint_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
211
|
+
|
|
212
|
+
const versions = getVersions(config);
|
|
213
|
+
this.protocolVersion = compressComponentVersions(versions);
|
|
214
|
+
logger.info(`Started libp2p service with protocol version ${this.protocolVersion}`);
|
|
215
|
+
|
|
216
|
+
this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
|
|
217
|
+
this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
|
|
218
|
+
this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(
|
|
219
|
+
TopicType.checkpoint_proposal,
|
|
220
|
+
this.protocolVersion,
|
|
221
|
+
);
|
|
222
|
+
this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(
|
|
223
|
+
TopicType.checkpoint_attestation,
|
|
224
|
+
this.protocolVersion,
|
|
128
225
|
);
|
|
129
226
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
227
|
+
const proposalValidatorOpts = {
|
|
228
|
+
txsPermitted: !config.disableTransactions,
|
|
229
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
230
|
+
};
|
|
231
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
|
|
232
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
|
|
233
|
+
this.checkpointAttestationValidator = config.fishermanMode
|
|
234
|
+
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
235
|
+
: new CheckpointAttestationValidator(epochCache);
|
|
236
|
+
|
|
237
|
+
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
238
|
+
|
|
239
|
+
this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
|
|
240
|
+
this.logger.warn(
|
|
241
|
+
`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
|
|
242
|
+
{ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
|
|
243
|
+
);
|
|
244
|
+
return true;
|
|
133
245
|
};
|
|
134
|
-
this.node.services.pubsub.score.params.appSpecificWeight = 10;
|
|
135
|
-
|
|
136
|
-
this.attestationValidator = new AttestationValidator(epochCache);
|
|
137
|
-
this.blockProposalValidator = new BlockProposalValidator(epochCache);
|
|
138
246
|
|
|
139
|
-
this.
|
|
247
|
+
this.checkpointReceivedCallback = (
|
|
248
|
+
checkpoint: CheckpointProposalCore,
|
|
249
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
140
250
|
this.logger.debug(
|
|
141
|
-
`Handler not yet registered:
|
|
142
|
-
{ p2pMessageIdentifier: await block.p2pMessageIdentifier() },
|
|
251
|
+
`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
|
|
143
252
|
);
|
|
144
|
-
return undefined;
|
|
253
|
+
return Promise.resolve(undefined);
|
|
145
254
|
};
|
|
146
255
|
}
|
|
147
256
|
|
|
257
|
+
public updateConfig(config: Partial<P2PReqRespConfig>) {
|
|
258
|
+
this.reqresp.updateConfig(config);
|
|
259
|
+
}
|
|
260
|
+
|
|
148
261
|
/**
|
|
149
262
|
* Creates an instance of the LibP2P service.
|
|
150
263
|
* @param config - The configuration to use when creating the service.
|
|
151
264
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
152
265
|
* @returns The new service.
|
|
153
266
|
*/
|
|
154
|
-
public static async new
|
|
155
|
-
clientType: T,
|
|
267
|
+
public static async new(
|
|
156
268
|
config: P2PConfig,
|
|
157
|
-
peerDiscoveryService: PeerDiscoveryService,
|
|
158
269
|
peerId: PeerId,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
270
|
+
deps: {
|
|
271
|
+
mempools: MemPools;
|
|
272
|
+
l2BlockSource: L2BlockSource & ContractDataSource;
|
|
273
|
+
epochCache: EpochCacheInterface;
|
|
274
|
+
proofVerifier: ClientProtocolCircuitVerifier;
|
|
275
|
+
worldStateSynchronizer: WorldStateSynchronizer;
|
|
276
|
+
peerStore: AztecAsyncKVStore;
|
|
277
|
+
telemetry: TelemetryClient;
|
|
278
|
+
logger: Logger;
|
|
279
|
+
packageVersion: string;
|
|
280
|
+
},
|
|
167
281
|
) {
|
|
168
|
-
const {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
282
|
+
const {
|
|
283
|
+
worldStateSynchronizer,
|
|
284
|
+
epochCache,
|
|
285
|
+
l2BlockSource,
|
|
286
|
+
mempools,
|
|
287
|
+
proofVerifier,
|
|
288
|
+
peerStore,
|
|
289
|
+
telemetry,
|
|
290
|
+
logger,
|
|
291
|
+
packageVersion,
|
|
292
|
+
} = deps;
|
|
293
|
+
const { p2pPort, maxPeerCount, listenAddress } = config;
|
|
294
|
+
const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
|
|
295
|
+
|
|
296
|
+
const datastore = new AztecDatastore(peerStore);
|
|
297
|
+
|
|
298
|
+
const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
|
|
172
299
|
|
|
173
|
-
const
|
|
300
|
+
const peerDiscoveryService = new DiscV5Service(
|
|
301
|
+
peerId,
|
|
302
|
+
config,
|
|
303
|
+
packageVersion,
|
|
304
|
+
telemetry,
|
|
305
|
+
createLogger(`${logger.module}:discv5_service`, logger.getBindings()),
|
|
306
|
+
);
|
|
174
307
|
|
|
175
|
-
|
|
308
|
+
// Seed libp2p's bootstrap discovery with private and trusted peers
|
|
309
|
+
const bootstrapNodes = [...config.privatePeers, ...config.trustedPeers];
|
|
176
310
|
|
|
177
|
-
// If bootstrap nodes are provided, also provide them to the p2p service
|
|
178
311
|
const peerDiscovery = [];
|
|
179
|
-
if (
|
|
180
|
-
peerDiscovery.push(bootstrap({ list:
|
|
312
|
+
if (bootstrapNodes.length > 0) {
|
|
313
|
+
peerDiscovery.push(bootstrap({ list: bootstrapNodes }));
|
|
181
314
|
}
|
|
182
315
|
|
|
316
|
+
const versions = getVersions(config);
|
|
317
|
+
const protocolVersion = compressComponentVersions(versions);
|
|
318
|
+
|
|
319
|
+
const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
|
|
320
|
+
const directPeers = (
|
|
321
|
+
await Promise.all(
|
|
322
|
+
preferredPeersEnrs.map(async enr => {
|
|
323
|
+
const peerId = await enr.peerId();
|
|
324
|
+
const address = enr.getLocationMultiaddr('tcp');
|
|
325
|
+
if (address === undefined) {
|
|
326
|
+
throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
id: peerId,
|
|
330
|
+
addrs: [address],
|
|
331
|
+
};
|
|
332
|
+
}),
|
|
333
|
+
)
|
|
334
|
+
).filter(peer => peer !== undefined);
|
|
335
|
+
|
|
336
|
+
const announceTcpMultiaddr = config.p2pIp ? [convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')] : [];
|
|
337
|
+
|
|
338
|
+
// Create dynamic topic score params based on network configuration
|
|
339
|
+
const l1Constants = epochCache.getL1Constants();
|
|
340
|
+
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
341
|
+
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
342
|
+
heartbeatIntervalMs: config.gossipsubInterval,
|
|
343
|
+
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
344
|
+
blockDurationMs: config.blockDurationMs,
|
|
345
|
+
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
|
|
346
|
+
});
|
|
347
|
+
|
|
183
348
|
const node = await createLibp2p({
|
|
184
349
|
start: false,
|
|
185
350
|
peerId,
|
|
186
351
|
addresses: {
|
|
187
352
|
listen: [bindAddrTcp],
|
|
188
|
-
announce:
|
|
353
|
+
announce: announceTcpMultiaddr,
|
|
189
354
|
},
|
|
190
355
|
transports: [
|
|
191
356
|
tcp({
|
|
192
|
-
|
|
357
|
+
// It's better to have this number a bit higher than our maxPeerCount because it's sets the limit on transport (TCP) layer
|
|
358
|
+
// The connection attempts to the node on TCP layer are not necessarily valid Aztec peers so we want to have a bit of leeway here
|
|
359
|
+
// If we hit the limit, the connection will be temporarily accepted and immediately dropped.
|
|
360
|
+
// Docs: https://nodejs.org/api/net.html#servermaxconnections
|
|
361
|
+
maxConnections: maxPeerCount * 2,
|
|
193
362
|
// socket option: the maximum length of the queue of pending connections
|
|
194
|
-
// https://nodejs.org/dist/latest-
|
|
363
|
+
// https://nodejs.org/dist/latest-v22.x/docs/api/net.html#serverlisten
|
|
195
364
|
// it's not safe if we increase this number
|
|
196
365
|
backlog: 5,
|
|
197
366
|
closeServerOnMaxConnections: {
|
|
198
|
-
|
|
199
|
-
|
|
367
|
+
// The property `maxConnections` will protect us against the most DDOS attack
|
|
368
|
+
// This property protects us in case of burst of new connections where server is not able to close them quickly enough
|
|
369
|
+
// In case closeAbove is reached, the server stops listening altogether
|
|
370
|
+
// It's important that there is enough difference between closeAbove and listenAbove,
|
|
371
|
+
// otherwise the server.listener will flap between being closed and open potentially degrading perf even more
|
|
372
|
+
closeAbove: maxPeerCount * 3,
|
|
373
|
+
listenBelow: Math.floor(maxPeerCount * 0.9),
|
|
200
374
|
},
|
|
201
375
|
}),
|
|
202
376
|
],
|
|
203
377
|
datastore,
|
|
204
378
|
peerDiscovery,
|
|
205
|
-
streamMuxers: [
|
|
379
|
+
streamMuxers: [yamux(), mplex()],
|
|
206
380
|
connectionEncryption: [noise()],
|
|
207
381
|
connectionManager: {
|
|
208
|
-
minConnections: 0,
|
|
209
|
-
|
|
382
|
+
minConnections: 0, // Disable libp2p peer dialing, we do it manually
|
|
383
|
+
// We set maxConnections above maxPeerCount because if we hit limit of maxPeerCount
|
|
384
|
+
// libp2p will start aggressively rejecting all new connections, preventing network discovery and crawling.
|
|
385
|
+
maxConnections: maxPeerCount * 2,
|
|
210
386
|
maxParallelDials: 100,
|
|
211
387
|
dialTimeout: 30_000,
|
|
212
388
|
maxPeerAddrsToDial: 5,
|
|
213
389
|
maxIncomingPendingConnections: 5,
|
|
214
390
|
},
|
|
391
|
+
connectionGater: {
|
|
392
|
+
denyInboundConnection: (maConn: MultiaddrConnection) => {
|
|
393
|
+
const allowed = peerManager.isNodeAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
|
|
394
|
+
if (allowed) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
logger.debug(`Connection gater: Denying inbound connection from ${maConn.remoteAddr.toString()}`);
|
|
399
|
+
return true;
|
|
400
|
+
},
|
|
401
|
+
denyInboundEncryptedConnection: (peerId: PeerId, _maConn: MultiaddrConnection) => {
|
|
402
|
+
//NOTE: it is not necessary to check address here because this was already done by
|
|
403
|
+
// denyInboundConnection
|
|
404
|
+
const allowed = peerManager.isNodeAllowedToConnect(peerId);
|
|
405
|
+
if (allowed) {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
logger.debug(`Connection gater: Denying inbound encrypted connection from ${peerId.toString()}`);
|
|
410
|
+
return true;
|
|
411
|
+
},
|
|
412
|
+
},
|
|
215
413
|
services: {
|
|
216
414
|
identify: identify({
|
|
217
415
|
protocolPrefix: 'aztec',
|
|
416
|
+
runOnConnectionOpen: true,
|
|
218
417
|
}),
|
|
219
418
|
pubsub: gossipsub({
|
|
419
|
+
directPeers,
|
|
220
420
|
debugName: 'gossipsub',
|
|
221
421
|
globalSignaturePolicy: SignaturePolicy.StrictNoSign,
|
|
222
422
|
allowPublishToZeroTopicPeers: true,
|
|
@@ -228,48 +428,59 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
228
428
|
heartbeatInterval: config.gossipsubInterval,
|
|
229
429
|
mcacheLength: config.gossipsubMcacheLength,
|
|
230
430
|
mcacheGossip: config.gossipsubMcacheGossip,
|
|
431
|
+
seenTTL: config.gossipsubSeenTTL,
|
|
231
432
|
msgIdFn: getMsgIdFn,
|
|
232
433
|
msgIdToStrFn: msgIdToStrFn,
|
|
233
434
|
fastMsgIdFn: fastMsgIdFn,
|
|
234
435
|
dataTransform: new SnappyTransform(),
|
|
235
436
|
metricsRegister: otelMetricsAdapter,
|
|
236
|
-
metricsTopicStrToLabel: metricsTopicStrToLabels(),
|
|
437
|
+
metricsTopicStrToLabel: metricsTopicStrToLabels(protocolVersion),
|
|
237
438
|
asyncValidation: true,
|
|
238
439
|
scoreThresholds: gossipScoreThresholds,
|
|
239
440
|
scoreParams: createPeerScoreParams({
|
|
240
441
|
// IPColocation factor can be disabled for local testing - default to -5
|
|
241
442
|
IPColocationFactorWeight: config.debugDisableColocationPenalty ? 0 : -5.0,
|
|
242
|
-
topics:
|
|
243
|
-
[Tx.p2pTopic]: createTopicScoreParams({
|
|
244
|
-
topicWeight: 1,
|
|
245
|
-
invalidMessageDeliveriesWeight: -20,
|
|
246
|
-
invalidMessageDeliveriesDecay: 0.5,
|
|
247
|
-
}),
|
|
248
|
-
[BlockAttestation.p2pTopic]: createTopicScoreParams({
|
|
249
|
-
topicWeight: 1,
|
|
250
|
-
invalidMessageDeliveriesWeight: -20,
|
|
251
|
-
invalidMessageDeliveriesDecay: 0.5,
|
|
252
|
-
}),
|
|
253
|
-
[BlockProposal.p2pTopic]: createTopicScoreParams({
|
|
254
|
-
topicWeight: 1,
|
|
255
|
-
invalidMessageDeliveriesWeight: -20,
|
|
256
|
-
invalidMessageDeliveriesDecay: 0.5,
|
|
257
|
-
}),
|
|
258
|
-
},
|
|
443
|
+
topics: topicScoreParams,
|
|
259
444
|
}),
|
|
260
445
|
}) as (components: GossipSubComponents) => GossipSub,
|
|
261
446
|
components: (components: { connectionManager: ConnectionManager }) => ({
|
|
262
447
|
connectionManager: components.connectionManager,
|
|
263
448
|
}),
|
|
264
449
|
},
|
|
265
|
-
logger: createLibp2pComponentLogger(logger.module),
|
|
450
|
+
logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
|
|
266
451
|
});
|
|
267
452
|
|
|
453
|
+
const peerScoring = new PeerScoring(config, telemetry);
|
|
454
|
+
const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
|
|
455
|
+
|
|
456
|
+
const peerManager = new PeerManager(
|
|
457
|
+
node,
|
|
458
|
+
peerDiscoveryService,
|
|
459
|
+
config,
|
|
460
|
+
telemetry,
|
|
461
|
+
createLogger(`${logger.module}:peer_manager`),
|
|
462
|
+
peerScoring,
|
|
463
|
+
reqresp,
|
|
464
|
+
worldStateSynchronizer,
|
|
465
|
+
protocolVersion,
|
|
466
|
+
epochCache,
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
// Configure application-specific scoring for gossipsub.
|
|
470
|
+
// The weight scales app score to align with gossipsub thresholds:
|
|
471
|
+
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
472
|
+
// - Ban (-100) × 10 = -1000 = publishThreshold (cannot publish)
|
|
473
|
+
// Note: positive topic scores can offset penalties, so alignment is best-effort.
|
|
474
|
+
node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
|
|
475
|
+
node.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
|
|
476
|
+
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
477
|
+
|
|
268
478
|
return new LibP2PService(
|
|
269
|
-
clientType,
|
|
270
479
|
config,
|
|
271
480
|
node,
|
|
272
481
|
peerDiscoveryService,
|
|
482
|
+
reqresp,
|
|
483
|
+
peerManager,
|
|
273
484
|
mempools,
|
|
274
485
|
l2BlockSource,
|
|
275
486
|
epochCache,
|
|
@@ -291,55 +502,76 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
291
502
|
}
|
|
292
503
|
|
|
293
504
|
// Get listen & announce addresses for logging
|
|
294
|
-
const {
|
|
295
|
-
if (!
|
|
505
|
+
const { p2pIp, p2pPort } = this.config;
|
|
506
|
+
if (!p2pIp) {
|
|
296
507
|
throw new Error('Announce address not provided.');
|
|
297
508
|
}
|
|
298
|
-
const announceTcpMultiaddr = convertToMultiaddr(
|
|
299
|
-
|
|
300
|
-
// Start job queue, peer discovery service and libp2p node
|
|
301
|
-
this.jobQueue.start();
|
|
302
|
-
await this.peerDiscoveryService.start();
|
|
303
|
-
await this.node.start();
|
|
304
|
-
|
|
305
|
-
// Subscribe to standard GossipSub topics by default
|
|
306
|
-
for (const topic of getTopicTypeForClientType(this.clientType)) {
|
|
307
|
-
this.subscribeToTopic(TopicTypeMap[topic].p2pTopic);
|
|
308
|
-
}
|
|
509
|
+
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
309
510
|
|
|
310
511
|
// Create request response protocol handlers
|
|
311
512
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
312
513
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
313
|
-
const blockHandler = reqRespBlockHandler(this.
|
|
514
|
+
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
515
|
+
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
314
516
|
|
|
315
|
-
const requestResponseHandlers = {
|
|
517
|
+
const requestResponseHandlers: Partial<ReqRespSubProtocolHandlers> = {
|
|
316
518
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
317
|
-
[ReqRespSubProtocol.STATUS]: statusHandler,
|
|
318
|
-
[ReqRespSubProtocol.TX]: txHandler.bind(this),
|
|
519
|
+
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
319
520
|
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
|
|
320
521
|
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
321
522
|
};
|
|
322
523
|
|
|
524
|
+
if (!this.config.disableTransactions) {
|
|
525
|
+
const blockTxsHandler = reqRespBlockTxsHandler(
|
|
526
|
+
this.mempools.attestationPool,
|
|
527
|
+
this.archiver,
|
|
528
|
+
this.mempools.txPool,
|
|
529
|
+
);
|
|
530
|
+
requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (!this.config.disableTransactions) {
|
|
534
|
+
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
538
|
+
const reqrespSubProtocolValidators = {
|
|
539
|
+
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
540
|
+
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
541
|
+
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
542
|
+
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
await this.peerManager.initializePeers();
|
|
546
|
+
|
|
547
|
+
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
548
|
+
|
|
549
|
+
await this.node.start();
|
|
550
|
+
|
|
551
|
+
// Subscribe to standard GossipSub topics by default
|
|
552
|
+
for (const topic of getTopicsForConfig(this.config.disableTransactions)) {
|
|
553
|
+
this.subscribeToTopic(this.topicStrings[topic]);
|
|
554
|
+
}
|
|
555
|
+
|
|
323
556
|
// add GossipSub listener
|
|
324
|
-
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.
|
|
557
|
+
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
325
558
|
|
|
326
|
-
// Start running promise for peer discovery
|
|
559
|
+
// Start running promise for peer discovery and metrics collection
|
|
560
|
+
if (!this.config.p2pDiscoveryDisabled) {
|
|
561
|
+
await this.peerDiscoveryService.start();
|
|
562
|
+
}
|
|
327
563
|
this.discoveryRunningPromise = new RunningPromise(
|
|
328
|
-
() =>
|
|
564
|
+
async () => {
|
|
565
|
+
await this.peerManager.heartbeat();
|
|
566
|
+
},
|
|
329
567
|
this.logger,
|
|
330
568
|
this.config.peerCheckIntervalMS,
|
|
331
569
|
);
|
|
332
570
|
this.discoveryRunningPromise.start();
|
|
333
571
|
|
|
334
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
335
|
-
const reqrespSubProtocolValidators = {
|
|
336
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
337
|
-
// TODO(#11336): A request validator for blocks
|
|
338
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTx.bind(this),
|
|
339
|
-
};
|
|
340
|
-
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
341
572
|
this.logger.info(`Started P2P service`, {
|
|
342
|
-
listen:
|
|
573
|
+
listen: this.config.listenAddress,
|
|
574
|
+
port: this.config.p2pPort,
|
|
343
575
|
announce: announceTcpMultiaddr,
|
|
344
576
|
peerId: this.node.peerId.toString(),
|
|
345
577
|
});
|
|
@@ -351,14 +583,11 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
351
583
|
*/
|
|
352
584
|
public async stop() {
|
|
353
585
|
// Remove gossip sub listener
|
|
354
|
-
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.
|
|
586
|
+
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
355
587
|
|
|
356
588
|
// Stop peer manager
|
|
357
589
|
this.logger.debug('Stopping peer manager...');
|
|
358
590
|
await this.peerManager.stop();
|
|
359
|
-
|
|
360
|
-
this.logger.debug('Stopping job queue...');
|
|
361
|
-
await this.jobQueue.end();
|
|
362
591
|
this.logger.debug('Stopping running promise...');
|
|
363
592
|
await this.discoveryRunningPromise?.stop();
|
|
364
593
|
this.logger.debug('Stopping peer discovery service...');
|
|
@@ -370,10 +599,26 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
370
599
|
this.logger.info('LibP2P service stopped');
|
|
371
600
|
}
|
|
372
601
|
|
|
602
|
+
addReqRespSubProtocol(
|
|
603
|
+
subProtocol: ReqRespSubProtocol,
|
|
604
|
+
handler: ReqRespSubProtocolHandler,
|
|
605
|
+
validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
606
|
+
): Promise<void> {
|
|
607
|
+
return this.reqresp.addSubProtocol(subProtocol, handler, validator);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
public registerThisValidatorAddresses(address: EthAddress[]): void {
|
|
611
|
+
this.peerManager.registerThisValidatorAddresses(address);
|
|
612
|
+
}
|
|
613
|
+
|
|
373
614
|
public getPeers(includePending?: boolean): PeerInfo[] {
|
|
374
615
|
return this.peerManager.getPeers(includePending);
|
|
375
616
|
}
|
|
376
617
|
|
|
618
|
+
public getGossipMeshPeerCount(topicType: TopicType): number {
|
|
619
|
+
return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
|
|
620
|
+
}
|
|
621
|
+
|
|
377
622
|
private handleGossipSubEvent(e: CustomEvent<GossipsubMessage>) {
|
|
378
623
|
this.logger.trace(`Received PUBSUB message.`);
|
|
379
624
|
|
|
@@ -387,23 +632,6 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
387
632
|
setImmediate(() => void safeJob());
|
|
388
633
|
}
|
|
389
634
|
|
|
390
|
-
/**
|
|
391
|
-
* Send Request via the ReqResp service
|
|
392
|
-
* The subprotocol defined will determine the request and response types
|
|
393
|
-
*
|
|
394
|
-
* See the subProtocolMap for the mapping of subprotocols to request/response types in `interface.ts`
|
|
395
|
-
*
|
|
396
|
-
* @param protocol The request response protocol to use
|
|
397
|
-
* @param request The request type to send
|
|
398
|
-
* @returns
|
|
399
|
-
*/
|
|
400
|
-
sendRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
401
|
-
protocol: SubProtocol,
|
|
402
|
-
request: InstanceType<SubProtocolMap[SubProtocol]['request']>,
|
|
403
|
-
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']> | undefined> {
|
|
404
|
-
return this.reqresp.sendRequest(protocol, request);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
635
|
/**
|
|
408
636
|
* Send a batch of requests to peers, and return the responses
|
|
409
637
|
* @param protocol - The request response protocol to use
|
|
@@ -413,8 +641,18 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
413
641
|
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
414
642
|
protocol: SubProtocol,
|
|
415
643
|
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
416
|
-
|
|
417
|
-
|
|
644
|
+
pinnedPeerId: PeerId | undefined,
|
|
645
|
+
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
|
|
646
|
+
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
public sendRequestToPeer(
|
|
650
|
+
peerId: PeerId,
|
|
651
|
+
subProtocol: ReqRespSubProtocol,
|
|
652
|
+
payload: Buffer,
|
|
653
|
+
dialTimeout?: number,
|
|
654
|
+
): Promise<ReqRespResponse> {
|
|
655
|
+
return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
|
|
418
656
|
}
|
|
419
657
|
|
|
420
658
|
/**
|
|
@@ -425,9 +663,31 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
425
663
|
return this.peerDiscoveryService.getEnr();
|
|
426
664
|
}
|
|
427
665
|
|
|
428
|
-
public registerBlockReceivedCallback(callback:
|
|
666
|
+
public registerBlockReceivedCallback(callback: P2PBlockReceivedCallback) {
|
|
429
667
|
this.blockReceivedCallback = callback;
|
|
430
|
-
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
671
|
+
this.checkpointReceivedCallback = callback;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Registers a callback to be invoked when a duplicate proposal is detected.
|
|
676
|
+
* This callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
677
|
+
*/
|
|
678
|
+
public registerDuplicateProposalCallback(
|
|
679
|
+
callback: (info: { slot: SlotNumber; proposer: EthAddress; type: 'checkpoint' | 'block' }) => void,
|
|
680
|
+
): void {
|
|
681
|
+
this.duplicateProposalCallback = callback;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Registers a callback to be invoked when a duplicate attestation is detected.
|
|
686
|
+
* A validator signing attestations for different proposals at the same slot.
|
|
687
|
+
* This callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
688
|
+
*/
|
|
689
|
+
public registerDuplicateAttestationCallback(callback: P2PDuplicateAttestationCallback): void {
|
|
690
|
+
this.duplicateAttestationCallback = callback;
|
|
431
691
|
}
|
|
432
692
|
|
|
433
693
|
/**
|
|
@@ -444,175 +704,675 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
444
704
|
/**
|
|
445
705
|
* Publishes data to a topic.
|
|
446
706
|
* @param topic - The topic to publish to.
|
|
447
|
-
* @param data - The
|
|
707
|
+
* @param data - The message to publish.
|
|
448
708
|
* @returns The number of recipients the data was sent to.
|
|
449
709
|
*/
|
|
450
|
-
private async publishToTopic(topic: string,
|
|
710
|
+
private async publishToTopic(topic: string, message: Gossipable) {
|
|
451
711
|
if (!this.node.services.pubsub) {
|
|
452
712
|
throw new Error('Pubsub service not available.');
|
|
453
713
|
}
|
|
454
|
-
const
|
|
455
|
-
|
|
714
|
+
const isBlockProposal = topic === this.topicStrings[TopicType.block_proposal];
|
|
715
|
+
const traceContext =
|
|
716
|
+
this.config.debugP2PInstrumentMessages && isBlockProposal ? this.telemetry.getTraceContext() : undefined;
|
|
717
|
+
const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages, traceContext);
|
|
718
|
+
const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
|
|
456
719
|
return result.recipients.length;
|
|
457
720
|
}
|
|
458
721
|
|
|
722
|
+
/**
|
|
723
|
+
* Checks if this message has already been seen, based on its msgId computed from hashing the message data.
|
|
724
|
+
* Note that we do not rely on the seenCache from gossipsub since we want to keep a longer history of seen
|
|
725
|
+
* messages to avoid tx echoes across the network.
|
|
726
|
+
*/
|
|
727
|
+
protected preValidateReceivedMessage(
|
|
728
|
+
msg: Message,
|
|
729
|
+
msgId: string,
|
|
730
|
+
source: PeerId,
|
|
731
|
+
): { result: boolean; topicType?: TopicType } {
|
|
732
|
+
let topicType: TopicType | undefined;
|
|
733
|
+
|
|
734
|
+
switch (msg.topic) {
|
|
735
|
+
case this.topicStrings[TopicType.tx]:
|
|
736
|
+
topicType = TopicType.tx;
|
|
737
|
+
break;
|
|
738
|
+
case this.topicStrings[TopicType.block_proposal]:
|
|
739
|
+
topicType = TopicType.block_proposal;
|
|
740
|
+
break;
|
|
741
|
+
case this.topicStrings[TopicType.checkpoint_proposal]:
|
|
742
|
+
topicType = TopicType.checkpoint_proposal;
|
|
743
|
+
break;
|
|
744
|
+
case this.topicStrings[TopicType.checkpoint_attestation]:
|
|
745
|
+
topicType = TopicType.checkpoint_attestation;
|
|
746
|
+
break;
|
|
747
|
+
default:
|
|
748
|
+
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const validator = topicType ? this.msgIdSeenValidators[topicType] : undefined;
|
|
753
|
+
|
|
754
|
+
if (!validator || !validator.addMessage(msgId)) {
|
|
755
|
+
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
756
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
757
|
+
if (topicType === TopicType.tx) {
|
|
758
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
|
|
759
|
+
}
|
|
760
|
+
return { result: false, topicType };
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
this.instrumentation.incMessagePrevalidationStatus(true, topicType);
|
|
764
|
+
|
|
765
|
+
return { result: true, topicType };
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Safely deserializes a P2PMessage from raw message data.
|
|
770
|
+
* @param msgId - The message ID.
|
|
771
|
+
* @param source - The peer ID of the message source.
|
|
772
|
+
* @param data - The raw message data.
|
|
773
|
+
* @returns The deserialized P2PMessage or undefined if deserialization fails.
|
|
774
|
+
*/
|
|
775
|
+
private safelyDeserializeP2PMessage(msgId: string, source: PeerId, data: Uint8Array): P2PMessage | undefined {
|
|
776
|
+
try {
|
|
777
|
+
return P2PMessage.fromMessageData(Buffer.from(data), this.config.debugP2PInstrumentMessages);
|
|
778
|
+
} catch (err) {
|
|
779
|
+
this.logger.error(`Error deserializing P2PMessage`, err, {
|
|
780
|
+
msgId,
|
|
781
|
+
source: source.toString(),
|
|
782
|
+
});
|
|
783
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Reject);
|
|
784
|
+
this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
|
|
785
|
+
return undefined;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
459
789
|
/**
|
|
460
790
|
* Handles a new gossip message that was received by the client.
|
|
461
791
|
* @param topic - The message's topic.
|
|
462
792
|
* @param data - The message data
|
|
463
793
|
*/
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
794
|
+
protected async handleNewGossipMessage(msg: Message, msgId: string, source: PeerId) {
|
|
795
|
+
const msgReceivedTime = Date.now();
|
|
796
|
+
let topicType: TopicType | undefined;
|
|
797
|
+
const p2pMessage = this.safelyDeserializeP2PMessage(msgId, source, msg.data);
|
|
798
|
+
if (!p2pMessage) {
|
|
799
|
+
return;
|
|
467
800
|
}
|
|
468
|
-
|
|
469
|
-
|
|
801
|
+
|
|
802
|
+
const preValidationResult = this.preValidateReceivedMessage(msg, msgId, source);
|
|
803
|
+
|
|
804
|
+
if (!preValidationResult.result) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// Determine topic type for attributes
|
|
809
|
+
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
810
|
+
topicType = TopicType.tx;
|
|
811
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
812
|
+
topicType = TopicType.checkpoint_attestation;
|
|
813
|
+
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
814
|
+
topicType = TopicType.block_proposal;
|
|
815
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
816
|
+
topicType = TopicType.checkpoint_proposal;
|
|
470
817
|
}
|
|
471
|
-
|
|
472
|
-
|
|
818
|
+
|
|
819
|
+
// Process the message, optionally within a linked span for trace propagation
|
|
820
|
+
const processMessage = async () => {
|
|
821
|
+
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
822
|
+
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
823
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
824
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
825
|
+
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
826
|
+
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
827
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
828
|
+
await this.handleGossipedCheckpointProposal(p2pMessage.payload, msgId, source);
|
|
829
|
+
} else {
|
|
830
|
+
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
const latency = p2pMessage.timestamp !== undefined ? msgReceivedTime - p2pMessage.timestamp.getTime() : undefined;
|
|
835
|
+
const propagatedContext = p2pMessage.traceContext
|
|
836
|
+
? this.telemetry.extractPropagatedContext(p2pMessage.traceContext)
|
|
837
|
+
: undefined;
|
|
838
|
+
|
|
839
|
+
if (propagatedContext) {
|
|
840
|
+
await this.tracer.startActiveSpan(
|
|
841
|
+
'LibP2PService.processMessage',
|
|
842
|
+
{
|
|
843
|
+
attributes: {
|
|
844
|
+
[Attributes.TOPIC_NAME]: topicType!,
|
|
845
|
+
[Attributes.PEER_ID]: source.toString(),
|
|
846
|
+
},
|
|
847
|
+
},
|
|
848
|
+
propagatedContext,
|
|
849
|
+
async span => {
|
|
850
|
+
try {
|
|
851
|
+
await processMessage();
|
|
852
|
+
span.setStatus({
|
|
853
|
+
code: SpanStatusCode.OK,
|
|
854
|
+
});
|
|
855
|
+
} catch (err) {
|
|
856
|
+
span.setStatus({
|
|
857
|
+
code: SpanStatusCode.ERROR,
|
|
858
|
+
message: String(err),
|
|
859
|
+
});
|
|
860
|
+
if (typeof err === 'string' || (err && err instanceof Error)) {
|
|
861
|
+
span.recordException(err);
|
|
862
|
+
}
|
|
863
|
+
throw err;
|
|
864
|
+
} finally {
|
|
865
|
+
span.end();
|
|
866
|
+
}
|
|
867
|
+
},
|
|
868
|
+
);
|
|
869
|
+
} else {
|
|
870
|
+
await processMessage();
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
if (latency !== undefined && topicType !== undefined) {
|
|
874
|
+
this.instrumentation.recordMessageLatency(topicType, latency);
|
|
473
875
|
}
|
|
474
876
|
|
|
475
877
|
return;
|
|
476
878
|
}
|
|
477
879
|
|
|
478
|
-
|
|
479
|
-
validationFunc: () => Promise<
|
|
880
|
+
protected async validateReceivedMessage<T, M = undefined>(
|
|
881
|
+
validationFunc: () => Promise<ReceivedMessageValidationResult<T, M>>,
|
|
480
882
|
msgId: string,
|
|
481
883
|
source: PeerId,
|
|
482
|
-
|
|
483
|
-
|
|
884
|
+
topicType: TopicType,
|
|
885
|
+
): Promise<ReceivedMessageValidationResult<T, M>> {
|
|
886
|
+
let resultAndObj: ReceivedMessageValidationResult<T, M> = { result: TopicValidatorResult.Reject };
|
|
887
|
+
const timer = new Timer();
|
|
484
888
|
try {
|
|
485
889
|
resultAndObj = await validationFunc();
|
|
486
890
|
} catch (err) {
|
|
487
|
-
this.
|
|
891
|
+
this.peerManager.penalizePeer(source, PeerErrorSeverity.LowToleranceError);
|
|
892
|
+
this.logger.error(`Error deserializing and validating gossipsub message`, err, {
|
|
893
|
+
msgId,
|
|
894
|
+
source: source.toString(),
|
|
895
|
+
topicType,
|
|
896
|
+
});
|
|
488
897
|
}
|
|
489
898
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
);
|
|
899
|
+
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
900
|
+
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
495
904
|
return resultAndObj;
|
|
496
905
|
}
|
|
497
906
|
|
|
498
|
-
|
|
499
|
-
const validationFunc = async () => {
|
|
500
|
-
const tx = Tx.fromBuffer(
|
|
501
|
-
|
|
502
|
-
|
|
907
|
+
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
908
|
+
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
909
|
+
const tx = Tx.fromBuffer(payloadData);
|
|
910
|
+
|
|
911
|
+
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
912
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
913
|
+
|
|
914
|
+
// Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
|
|
915
|
+
const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
916
|
+
const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
|
|
917
|
+
if (!firstStageOutcome.allPassed) {
|
|
918
|
+
const { name } = firstStageOutcome.failure;
|
|
919
|
+
let { severity } = firstStageOutcome.failure;
|
|
920
|
+
|
|
921
|
+
// Double spend validator has a special case handler. We perform more detailed examination
|
|
922
|
+
// as to how recently the nullifier was entered into the tree and if the transaction should
|
|
923
|
+
// have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
|
|
924
|
+
if (name === 'doubleSpendValidator') {
|
|
925
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1);
|
|
926
|
+
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
930
|
+
validator: name,
|
|
931
|
+
severity,
|
|
932
|
+
source: source.toString(),
|
|
933
|
+
});
|
|
934
|
+
this.peerManager.penalizePeer(source, severity);
|
|
935
|
+
return { result: TopicValidatorResult.Reject };
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
939
|
+
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
940
|
+
if (canAdd === 'ignored') {
|
|
941
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
942
|
+
source: source.toString(),
|
|
943
|
+
});
|
|
944
|
+
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// Stage 2: expensive proof verification
|
|
948
|
+
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
949
|
+
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
950
|
+
if (!secondStageOutcome.allPassed) {
|
|
951
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
952
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
953
|
+
validator: name,
|
|
954
|
+
severity,
|
|
955
|
+
source: source.toString(),
|
|
956
|
+
});
|
|
957
|
+
this.peerManager.penalizePeer(source, severity);
|
|
958
|
+
return { result: TopicValidatorResult.Reject };
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// Pool add: persist the tx
|
|
962
|
+
const txHash = tx.getTxHash();
|
|
963
|
+
const addResult = await this.mempools.txPool.addPendingTxs([tx], { source: 'gossip' });
|
|
964
|
+
|
|
965
|
+
const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
|
|
966
|
+
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
967
|
+
|
|
968
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
969
|
+
wasAccepted,
|
|
970
|
+
wasIgnored,
|
|
971
|
+
[Attributes.P2P_ID]: source.toString(),
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
if (wasAccepted) {
|
|
975
|
+
return { result: TopicValidatorResult.Accept, obj: tx };
|
|
976
|
+
} else if (wasIgnored) {
|
|
977
|
+
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
978
|
+
} else {
|
|
979
|
+
return { result: TopicValidatorResult.Reject };
|
|
980
|
+
}
|
|
503
981
|
};
|
|
504
982
|
|
|
505
|
-
const { result, obj: tx } = await this.validateReceivedMessage<Tx>(validationFunc, msgId, source);
|
|
506
|
-
if (
|
|
983
|
+
const { result, obj: tx } = await this.validateReceivedMessage<Tx>(validationFunc, msgId, source, TopicType.tx);
|
|
984
|
+
if (result !== TopicValidatorResult.Accept || !tx) {
|
|
507
985
|
return;
|
|
508
986
|
}
|
|
509
|
-
|
|
987
|
+
|
|
988
|
+
// Tx was accepted into pool and will be propagated - just log and record metrics
|
|
989
|
+
const txHash = tx.getTxHash();
|
|
510
990
|
const txHashString = txHash.toString();
|
|
511
|
-
this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()}
|
|
512
|
-
|
|
991
|
+
this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
|
|
992
|
+
source: source.toString(),
|
|
993
|
+
txHash: txHashString,
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
this.instrumentation.incrementTxReceived(1);
|
|
513
997
|
}
|
|
514
998
|
|
|
515
|
-
/**
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
* @param attestation - The attestation to process.
|
|
999
|
+
/**
|
|
1000
|
+
* Process a checkpoint attestation from a peer.
|
|
1001
|
+
* Validates the attestation and adds it to the pool.
|
|
519
1002
|
*/
|
|
520
|
-
private async
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
});
|
|
528
|
-
return { result, obj: attestation };
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
const { result, obj: attestation } = await this.validateReceivedMessage<BlockAttestation>(
|
|
532
|
-
validationFunc,
|
|
1003
|
+
private async processCheckpointAttestationFromPeer(
|
|
1004
|
+
payloadData: Buffer,
|
|
1005
|
+
msgId: string,
|
|
1006
|
+
source: PeerId,
|
|
1007
|
+
): Promise<void> {
|
|
1008
|
+
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
1009
|
+
() => this.validateAndStoreCheckpointAttestation(source, CheckpointAttestation.fromBuffer(payloadData)),
|
|
533
1010
|
msgId,
|
|
534
1011
|
source,
|
|
1012
|
+
TopicType.checkpoint_attestation,
|
|
535
1013
|
);
|
|
536
|
-
|
|
1014
|
+
|
|
1015
|
+
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
537
1016
|
return;
|
|
538
1017
|
}
|
|
539
|
-
|
|
540
|
-
|
|
1018
|
+
|
|
1019
|
+
this.logger.verbose(
|
|
1020
|
+
`Received valid checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
541
1021
|
{
|
|
542
|
-
p2pMessageIdentifier: await attestation.
|
|
543
|
-
slot: attestation.slotNumber
|
|
1022
|
+
p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
|
|
1023
|
+
slot: attestation.slotNumber,
|
|
544
1024
|
archive: attestation.archive.toString(),
|
|
545
|
-
|
|
1025
|
+
source: source.toString(),
|
|
546
1026
|
},
|
|
547
1027
|
);
|
|
548
|
-
await this.mempools.attestationPool!.addAttestations([attestation]);
|
|
549
1028
|
}
|
|
550
1029
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
1030
|
+
/** Validates a checkpoint attestation and adds it to the pool. Penalizes the peer if validation fails. */
|
|
1031
|
+
@trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation) => ({
|
|
1032
|
+
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString(),
|
|
1033
|
+
}))
|
|
1034
|
+
protected async validateAndStoreCheckpointAttestation(
|
|
1035
|
+
peerId: PeerId,
|
|
1036
|
+
attestation: CheckpointAttestation,
|
|
1037
|
+
): Promise<ReceivedMessageValidationResult<CheckpointAttestation>> {
|
|
1038
|
+
const validationResult = await this.checkpointAttestationValidator.validate(attestation);
|
|
1039
|
+
|
|
1040
|
+
if (validationResult.result === 'reject') {
|
|
1041
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1042
|
+
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1043
|
+
return { result: TopicValidatorResult.Reject };
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if (validationResult.result === 'ignore') {
|
|
1047
|
+
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// Try to add the attestation: this handles existence check, cap check, and adding in one call
|
|
1051
|
+
// count is the number of attestations by this signer for this slot (for duplicate detection)
|
|
1052
|
+
const slot = attestation.payload.header.slotNumber;
|
|
1053
|
+
const { added, alreadyExists, count } =
|
|
1054
|
+
await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation);
|
|
1055
|
+
|
|
1056
|
+
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
1057
|
+
added,
|
|
1058
|
+
alreadyExists,
|
|
1059
|
+
count,
|
|
1060
|
+
[Attributes.SLOT_NUMBER]: slot.toString(),
|
|
1061
|
+
[Attributes.P2P_ID]: peerId.toString(),
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
// Exact same attestation received, no need to re-broadcast
|
|
1065
|
+
if (alreadyExists) {
|
|
1066
|
+
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// Could not add (cap reached for signer), no need to re-broadcast
|
|
1070
|
+
if (!added) {
|
|
1071
|
+
this.logger.warn(`Dropping checkpoint attestation due to cap`, {
|
|
1072
|
+
slot: slot.toString(),
|
|
1073
|
+
archive: attestation.archive.toString(),
|
|
1074
|
+
source: peerId.toString(),
|
|
1075
|
+
attester: attestation.getSender()?.toString(),
|
|
1076
|
+
count,
|
|
558
1077
|
});
|
|
559
|
-
return { result, obj:
|
|
560
|
-
}
|
|
1078
|
+
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1079
|
+
}
|
|
561
1080
|
|
|
562
|
-
|
|
563
|
-
|
|
1081
|
+
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
1082
|
+
// count is the number of attestations by this signer for this slot
|
|
1083
|
+
if (count === 2) {
|
|
1084
|
+
const attester = attestation.getSender();
|
|
1085
|
+
if (attester) {
|
|
1086
|
+
this.logger.warn(`Detected duplicate attestation (equivocation) at slot ${slot}`, {
|
|
1087
|
+
slot: slot.toString(),
|
|
1088
|
+
archive: attestation.archive.toString(),
|
|
1089
|
+
source: peerId.toString(),
|
|
1090
|
+
attester: attester.toString(),
|
|
1091
|
+
});
|
|
1092
|
+
this.duplicateAttestationCallback?.({ slot, attester });
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// Attestation was added successfully - accept it so other nodes can also detect the equivocation
|
|
1097
|
+
return { result: TopicValidatorResult.Accept, obj: attestation };
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
protected async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
1101
|
+
const {
|
|
1102
|
+
result,
|
|
1103
|
+
obj: block,
|
|
1104
|
+
metadata: { isEquivocated } = {},
|
|
1105
|
+
} = await this.validateReceivedMessage<BlockProposal, { isEquivocated: boolean }>(
|
|
1106
|
+
() => this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)),
|
|
1107
|
+
msgId,
|
|
1108
|
+
source,
|
|
1109
|
+
TopicType.block_proposal,
|
|
1110
|
+
);
|
|
1111
|
+
|
|
1112
|
+
// If not accepted or equivocated, return
|
|
1113
|
+
if (result !== TopicValidatorResult.Accept || !block || isEquivocated) {
|
|
564
1114
|
return;
|
|
565
1115
|
}
|
|
566
|
-
|
|
1116
|
+
|
|
1117
|
+
await this.processValidBlockProposal(block, source);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/** Validates a block proposal. Triggers a penalization to the peer that sent it if invalid. Adds to the mempool if valid. */
|
|
1121
|
+
@trackSpan('Libp2pService.validateAndStoreBlockProposal', (_peerId, block) => ({
|
|
1122
|
+
[Attributes.BLOCK_NUMBER]: block.blockNumber.toString(),
|
|
1123
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
1124
|
+
}))
|
|
1125
|
+
protected async validateAndStoreBlockProposal(
|
|
1126
|
+
peerId: PeerId,
|
|
1127
|
+
block: BlockProposal,
|
|
1128
|
+
): Promise<ReceivedMessageValidationResult<BlockProposal, { isEquivocated: boolean }>> {
|
|
1129
|
+
const validationResult = await this.blockProposalValidator.validate(block);
|
|
1130
|
+
|
|
1131
|
+
if (validationResult.result === 'reject') {
|
|
1132
|
+
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1133
|
+
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1134
|
+
return { result: TopicValidatorResult.Reject };
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
if (validationResult.result === 'ignore') {
|
|
1138
|
+
return { result: TopicValidatorResult.Ignore, obj: block };
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// Try to add the proposal: this handles existence check, cap check, and adding in one call
|
|
1142
|
+
const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
|
|
1143
|
+
const isEquivocated = count !== undefined && count > 1;
|
|
1144
|
+
|
|
1145
|
+
// Duplicate proposal received, no need to re-broadcast
|
|
1146
|
+
if (alreadyExists) {
|
|
1147
|
+
this.logger.debug(`Ignoring duplicate block proposal received`, {
|
|
1148
|
+
...block.toBlockInfo(),
|
|
1149
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1150
|
+
proposer: block.getSender()?.toString(),
|
|
1151
|
+
source: peerId.toString(),
|
|
1152
|
+
});
|
|
1153
|
+
return { result: TopicValidatorResult.Ignore, obj: block, metadata: { isEquivocated } };
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1157
|
+
if (!added) {
|
|
1158
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1159
|
+
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1160
|
+
...block.toBlockInfo(),
|
|
1161
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1162
|
+
count,
|
|
1163
|
+
proposer: block.getSender()?.toString(),
|
|
1164
|
+
source: peerId.toString(),
|
|
1165
|
+
});
|
|
1166
|
+
return { result: TopicValidatorResult.Reject, metadata: { isEquivocated } };
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1170
|
+
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1171
|
+
if (isEquivocated) {
|
|
1172
|
+
const proposer = block.getSender();
|
|
1173
|
+
this.logger.warn(`Detected duplicate block proposal (equivocation) at slot ${block.slotNumber}`, {
|
|
1174
|
+
...block.toBlockInfo(),
|
|
1175
|
+
source: peerId.toString(),
|
|
1176
|
+
proposer: proposer?.toString(),
|
|
1177
|
+
});
|
|
1178
|
+
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1179
|
+
if (proposer && count === 2) {
|
|
1180
|
+
this.duplicateProposalCallback?.({ slot: block.slotNumber, proposer, type: 'block' });
|
|
1181
|
+
}
|
|
1182
|
+
return { result: TopicValidatorResult.Accept, obj: block, metadata: { isEquivocated } };
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// Otherwise, we're good to go!
|
|
1186
|
+
return { result: TopicValidatorResult.Accept, obj: block };
|
|
567
1187
|
}
|
|
568
1188
|
|
|
569
|
-
//
|
|
1189
|
+
// REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
|
|
1190
|
+
// should not be here as it does not deal with p2p networking.
|
|
570
1191
|
@trackSpan('Libp2pService.processValidBlockProposal', async block => ({
|
|
571
|
-
[Attributes.
|
|
572
|
-
[Attributes.SLOT_NUMBER]: block.slotNumber.toNumber(),
|
|
1192
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber,
|
|
573
1193
|
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
574
|
-
[Attributes.P2P_ID]: await block.
|
|
1194
|
+
[Attributes.P2P_ID]: await block.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
575
1195
|
}))
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
1196
|
+
protected async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
|
|
1197
|
+
const slot = block.slotNumber;
|
|
1198
|
+
this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
1199
|
+
p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
|
|
1200
|
+
source: sender.toString(),
|
|
1201
|
+
...block.toBlockInfo(),
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1204
|
+
// Mark the txs in this proposal as protected
|
|
1205
|
+
await this.mempools.txPool.protectTxs(block.txHashes, block.blockHeader);
|
|
1206
|
+
|
|
1207
|
+
// Call the block received callback to validate the proposal.
|
|
1208
|
+
// Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1209
|
+
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1210
|
+
if (!isValid) {
|
|
1211
|
+
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* Handle a gossiped checkpoint proposal.
|
|
1217
|
+
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1218
|
+
*/
|
|
1219
|
+
protected async handleGossipedCheckpointProposal(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
1220
|
+
const {
|
|
1221
|
+
result,
|
|
1222
|
+
obj: checkpoint,
|
|
1223
|
+
metadata: { isEquivocated, processBlock } = {},
|
|
1224
|
+
} = await this.validateReceivedMessage<CheckpointProposal, { isEquivocated: boolean; processBlock: boolean }>(
|
|
1225
|
+
() => this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)),
|
|
1226
|
+
msgId,
|
|
1227
|
+
source,
|
|
1228
|
+
TopicType.checkpoint_proposal,
|
|
585
1229
|
);
|
|
586
|
-
const attestation = await this.blockReceivedCallback(block);
|
|
587
1230
|
|
|
588
|
-
//
|
|
589
|
-
//
|
|
590
|
-
if (
|
|
591
|
-
this.
|
|
592
|
-
`Broadcasting attestation for block ${attestation.blockNumber.toNumber()} slot ${attestation.slotNumber.toNumber()}`,
|
|
593
|
-
{
|
|
594
|
-
p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
|
|
595
|
-
slot: attestation.slotNumber.toNumber(),
|
|
596
|
-
archive: attestation.archive.toString(),
|
|
597
|
-
block: attestation.blockNumber.toNumber(),
|
|
598
|
-
},
|
|
599
|
-
);
|
|
600
|
-
await this.broadcastAttestation(attestation);
|
|
1231
|
+
// If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
|
|
1232
|
+
// TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
|
|
1233
|
+
if (processBlock && checkpoint?.getBlockProposal()) {
|
|
1234
|
+
await this.processValidBlockProposal(checkpoint.getBlockProposal()!, source);
|
|
601
1235
|
}
|
|
1236
|
+
|
|
1237
|
+
if (result !== TopicValidatorResult.Accept || !checkpoint || isEquivocated) {
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
await this.processValidCheckpointProposal(checkpoint.toCore(), source);
|
|
602
1242
|
}
|
|
603
1243
|
|
|
604
1244
|
/**
|
|
605
|
-
*
|
|
606
|
-
*
|
|
1245
|
+
* Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
|
|
1246
|
+
* its last block (if present) to the mempool if valid. Triggers equivocation detection on both.
|
|
607
1247
|
*/
|
|
608
|
-
@trackSpan('Libp2pService.
|
|
609
|
-
[Attributes.
|
|
610
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toNumber(),
|
|
611
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
612
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then(i => i.toString()),
|
|
1248
|
+
@trackSpan('Libp2pService.validateAndStoreCheckpointProposal', (_peerId, checkpoint) => ({
|
|
1249
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
613
1250
|
}))
|
|
614
|
-
|
|
615
|
-
|
|
1251
|
+
protected async validateAndStoreCheckpointProposal(
|
|
1252
|
+
peerId: PeerId,
|
|
1253
|
+
checkpoint: CheckpointProposal,
|
|
1254
|
+
): Promise<ReceivedMessageValidationResult<CheckpointProposal, { isEquivocated: boolean; processBlock: boolean }>> {
|
|
1255
|
+
const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1256
|
+
|
|
1257
|
+
if (validationResult.result === 'reject') {
|
|
1258
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1259
|
+
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1260
|
+
return { result: TopicValidatorResult.Reject };
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
if (validationResult.result === 'ignore') {
|
|
1264
|
+
return { result: TopicValidatorResult.Ignore, obj: checkpoint };
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
// Extract and try to add the block proposal first if present
|
|
1268
|
+
const blockProposal = checkpoint.getBlockProposal();
|
|
1269
|
+
let processBlock = false;
|
|
1270
|
+
if (blockProposal) {
|
|
1271
|
+
this.logger.debug(`Validating block proposal from propagated checkpoint`, {
|
|
1272
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1273
|
+
[Attributes.P2P_ID]: peerId.toString(),
|
|
1274
|
+
});
|
|
1275
|
+
const {
|
|
1276
|
+
result,
|
|
1277
|
+
obj,
|
|
1278
|
+
metadata: { isEquivocated } = {},
|
|
1279
|
+
} = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1280
|
+
if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1281
|
+
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1282
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1283
|
+
[Attributes.P2P_ID]: peerId.toString(),
|
|
1284
|
+
isEquivocated,
|
|
1285
|
+
result,
|
|
1286
|
+
});
|
|
1287
|
+
return { result: TopicValidatorResult.Reject };
|
|
1288
|
+
} else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1289
|
+
processBlock = true;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
|
|
1294
|
+
const checkpointCore = checkpoint.toCore();
|
|
1295
|
+
const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
|
|
1296
|
+
const { added, alreadyExists, count } = tryAddResult;
|
|
1297
|
+
const isEquivocated = count !== undefined && count > 1;
|
|
1298
|
+
|
|
1299
|
+
// Duplicate proposal received, do not re-broadcast
|
|
1300
|
+
if (alreadyExists) {
|
|
1301
|
+
this.logger.debug(`Ignoring duplicate checkpoint proposal received`, {
|
|
1302
|
+
...checkpoint.toCheckpointInfo(),
|
|
1303
|
+
source: peerId.toString(),
|
|
1304
|
+
});
|
|
1305
|
+
return {
|
|
1306
|
+
result: TopicValidatorResult.Ignore,
|
|
1307
|
+
obj: checkpoint,
|
|
1308
|
+
metadata: { isEquivocated, processBlock },
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1313
|
+
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1314
|
+
if (!added) {
|
|
1315
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1316
|
+
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1317
|
+
...checkpoint.toCheckpointInfo(),
|
|
1318
|
+
count,
|
|
1319
|
+
source: peerId.toString(),
|
|
1320
|
+
});
|
|
1321
|
+
return { result: TopicValidatorResult.Reject, obj: checkpoint, metadata: { isEquivocated, processBlock } };
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1325
|
+
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1326
|
+
if (isEquivocated) {
|
|
1327
|
+
const proposer = checkpoint.getSender();
|
|
1328
|
+
this.logger.warn(`Detected duplicate checkpoint proposal (equivocation) at slot ${checkpoint.slotNumber}`, {
|
|
1329
|
+
...checkpoint.toCheckpointInfo(),
|
|
1330
|
+
source: peerId.toString(),
|
|
1331
|
+
proposer: proposer?.toString(),
|
|
1332
|
+
});
|
|
1333
|
+
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1334
|
+
if (proposer && count === 2) {
|
|
1335
|
+
this.duplicateProposalCallback?.({ slot: checkpoint.slotNumber, proposer, type: 'checkpoint' });
|
|
1336
|
+
}
|
|
1337
|
+
return {
|
|
1338
|
+
result: TopicValidatorResult.Accept,
|
|
1339
|
+
obj: checkpoint,
|
|
1340
|
+
metadata: { isEquivocated, processBlock },
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
// Otherwise, we're good to go!
|
|
1345
|
+
return { result: TopicValidatorResult.Accept, obj: checkpoint, metadata: { processBlock, isEquivocated } };
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Process a validated checkpoint proposal.
|
|
1350
|
+
* Note: The proposal was already added to the pool by tryAddCheckpointProposal in handleGossipedCheckpointProposal.
|
|
1351
|
+
*/
|
|
1352
|
+
@trackSpan('Libp2pService.processValidCheckpointProposal', async checkpoint => ({
|
|
1353
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
1354
|
+
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
1355
|
+
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1356
|
+
}))
|
|
1357
|
+
protected async processValidCheckpointProposal(checkpoint: CheckpointProposalCore, sender: PeerId) {
|
|
1358
|
+
const slot = checkpoint.slotNumber;
|
|
1359
|
+
this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
1360
|
+
p2pMessageIdentifier: await checkpoint.p2pMessageLoggingIdentifier(),
|
|
1361
|
+
slot: checkpoint.slotNumber,
|
|
1362
|
+
archive: checkpoint.archive.toString(),
|
|
1363
|
+
source: sender.toString(),
|
|
1364
|
+
});
|
|
1365
|
+
|
|
1366
|
+
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1367
|
+
// to validate and potentially generate attestations
|
|
1368
|
+
const attestations = await this.checkpointReceivedCallback(checkpoint, sender);
|
|
1369
|
+
if (attestations && attestations.length > 0) {
|
|
1370
|
+
// If the callback returned attestations, add them to the pool and propagate them
|
|
1371
|
+
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
1372
|
+
for (const attestation of attestations) {
|
|
1373
|
+
await this.propagate(attestation);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
616
1376
|
}
|
|
617
1377
|
|
|
618
1378
|
/**
|
|
@@ -620,113 +1380,295 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
620
1380
|
* @param message - The message to propagate.
|
|
621
1381
|
*/
|
|
622
1382
|
public async propagate<T extends Gossipable>(message: T) {
|
|
623
|
-
const p2pMessageIdentifier = await message.
|
|
1383
|
+
const p2pMessageIdentifier = await message.p2pMessageLoggingIdentifier();
|
|
624
1384
|
this.logger.trace(`Message ${p2pMessageIdentifier} queued`, { p2pMessageIdentifier });
|
|
625
|
-
void this.
|
|
626
|
-
.
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
1385
|
+
void this.sendToPeers(message).catch(error => {
|
|
1386
|
+
this.logger.error(`Error propagating message ${p2pMessageIdentifier}`, { error });
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
/**
|
|
1391
|
+
* Validate the requested block transactions. Allow partial returns.
|
|
1392
|
+
* @param request - The block transactions request.
|
|
1393
|
+
* @param response - The block transactions response.
|
|
1394
|
+
* @param peerId - The ID of the peer that made the request.
|
|
1395
|
+
* @returns True if the requested block transactions are valid, false otherwise.
|
|
1396
|
+
*/
|
|
1397
|
+
@trackSpan('Libp2pService.validateRequestedBlockTxs', request => ({
|
|
1398
|
+
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
|
|
1399
|
+
}))
|
|
1400
|
+
protected async validateRequestedBlockTxs(
|
|
1401
|
+
request: BlockTxsRequest,
|
|
1402
|
+
response: BlockTxsResponse,
|
|
1403
|
+
peerId: PeerId,
|
|
1404
|
+
): Promise<boolean> {
|
|
1405
|
+
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1406
|
+
|
|
1407
|
+
try {
|
|
1408
|
+
if (!response.archiveRoot.equals(request.archiveRoot)) {
|
|
1409
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1410
|
+
throw new ValidationError(
|
|
1411
|
+
`Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`,
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
if (response.txIndices.getLength() !== request.txIndices.getLength()) {
|
|
1416
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1417
|
+
throw new ValidationError(
|
|
1418
|
+
`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`,
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// Check no duplicates and not exceeding returnable count
|
|
1423
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
1424
|
+
const availableIndices = new Set(response.txIndices.getTrueIndices());
|
|
1425
|
+
const maxReturnable = [...requestedIndices].filter(i => availableIndices.has(i)).length;
|
|
1426
|
+
|
|
1427
|
+
const returnedHashes = await Promise.all(response.txs.map(tx => tx.getTxHash().toString()));
|
|
1428
|
+
const uniqueReturned = new Set(returnedHashes.map(h => h.toString()));
|
|
1429
|
+
if (uniqueReturned.size !== returnedHashes.length) {
|
|
1430
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1431
|
+
throw new ValidationError(`Received duplicate txs in block txs response`);
|
|
1432
|
+
}
|
|
1433
|
+
if (response.txs.length > maxReturnable) {
|
|
1434
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1435
|
+
throw new ValidationError(
|
|
1436
|
+
`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`,
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// Given proposal (should have locally), ensure returned txs are valid subset and match request indices
|
|
1441
|
+
const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
|
|
1442
|
+
if (proposal) {
|
|
1443
|
+
// Build intersected indices
|
|
1444
|
+
const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
|
|
1445
|
+
|
|
1446
|
+
// Enforce subset membership and preserve increasing order by index.
|
|
1447
|
+
const hashToIndexInProposal = new Map<string, number>(
|
|
1448
|
+
proposal.txHashes.map((h, i) => [h.toString(), i] as [string, number]),
|
|
1449
|
+
);
|
|
1450
|
+
const allowedIndexSet = new Set(intersectIdx);
|
|
1451
|
+
const indices = returnedHashes.map(h => hashToIndexInProposal.get(h));
|
|
1452
|
+
const allAllowed = indices.every(idx => idx !== undefined && allowedIndexSet.has(idx));
|
|
1453
|
+
const strictlyIncreasing = indices.every((idx, i) => (i === 0 ? idx !== undefined : idx! > indices[i - 1]!));
|
|
1454
|
+
if (!allAllowed || !strictlyIncreasing) {
|
|
1455
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1456
|
+
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
1457
|
+
}
|
|
1458
|
+
} else {
|
|
1459
|
+
// No local proposal, cannot check the membership/order of the returned txs
|
|
1460
|
+
this.logger.warn(
|
|
1461
|
+
`Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`,
|
|
1462
|
+
);
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
await Promise.all(response.txs.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
1467
|
+
return true;
|
|
1468
|
+
} catch (e: any) {
|
|
1469
|
+
if (e instanceof ValidationError) {
|
|
1470
|
+
this.logger.warn(`Failed validation for requested block txs from peer ${peerId.toString()}`);
|
|
1471
|
+
} else {
|
|
1472
|
+
this.logger.error(`Error during validation of requested block txs`, e);
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
632
1477
|
}
|
|
633
1478
|
|
|
634
1479
|
/**
|
|
635
|
-
* Validate a
|
|
1480
|
+
* Validate a collection of txs that has been requested from a peer.
|
|
636
1481
|
*
|
|
637
|
-
* The core component of this validator is that
|
|
1482
|
+
* The core component of this validator is that each tx hash MUST match the requested tx hash,
|
|
638
1483
|
* In order to perform this check, the tx proof must be verified.
|
|
639
1484
|
*
|
|
640
1485
|
* Note: This function is called from within `ReqResp.sendRequest` as part of the
|
|
641
1486
|
* ReqRespSubProtocol.TX subprotocol validation.
|
|
642
1487
|
*
|
|
643
|
-
* @param requestedTxHash - The
|
|
644
|
-
* @param responseTx - The
|
|
1488
|
+
* @param requestedTxHash - The collection of the txs that was requested.
|
|
1489
|
+
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
645
1490
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
646
|
-
* @returns True if the
|
|
1491
|
+
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
647
1492
|
*/
|
|
648
1493
|
@trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx) => ({
|
|
649
1494
|
[Attributes.TX_HASH]: requestedTxHash.toString(),
|
|
650
1495
|
}))
|
|
651
|
-
private async
|
|
652
|
-
const
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
//
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
return
|
|
660
|
-
}
|
|
1496
|
+
private async validateRequestedTxs(requestedTxHash: TxHash[], responseTx: Tx[], peerId: PeerId): Promise<boolean> {
|
|
1497
|
+
const requested = new Set(requestedTxHash.map(h => h.toString()));
|
|
1498
|
+
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1499
|
+
|
|
1500
|
+
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
1501
|
+
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1502
|
+
try {
|
|
1503
|
+
await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
1504
|
+
return true;
|
|
1505
|
+
} catch (e: any) {
|
|
1506
|
+
if (e instanceof ValidationError) {
|
|
1507
|
+
this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
|
|
1508
|
+
} else {
|
|
1509
|
+
this.logger.error(`Error during validation of requested txs`, e);
|
|
1510
|
+
}
|
|
661
1511
|
|
|
662
|
-
if (validProof.result === 'invalid') {
|
|
663
|
-
// If the proof is invalid, but the txHash is correct, then this is an active attack and we severly punish
|
|
664
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
665
1512
|
return false;
|
|
666
1513
|
}
|
|
667
|
-
|
|
668
|
-
return true;
|
|
669
1514
|
}
|
|
670
1515
|
|
|
671
|
-
|
|
672
|
-
|
|
1516
|
+
/**
|
|
1517
|
+
* Validates a BLOCK response.
|
|
1518
|
+
*
|
|
1519
|
+
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1520
|
+
* Penalizes on block number mismatch or hash mismatch.
|
|
1521
|
+
*
|
|
1522
|
+
* @param requestedBlockNumber - The requested block number.
|
|
1523
|
+
* @param responseBlock - The block returned by the peer.
|
|
1524
|
+
* @param peerId - The peer that returned the block.
|
|
1525
|
+
* @returns True if the response is valid, false otherwise.
|
|
1526
|
+
*/
|
|
1527
|
+
@trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock) => ({
|
|
1528
|
+
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString(),
|
|
673
1529
|
}))
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
1530
|
+
protected async validateRequestedBlock(
|
|
1531
|
+
requestedBlockNumber: Fr,
|
|
1532
|
+
responseBlock: L2Block,
|
|
1533
|
+
peerId: PeerId,
|
|
1534
|
+
): Promise<boolean> {
|
|
1535
|
+
try {
|
|
1536
|
+
const reqNum = Number(requestedBlockNumber.toString());
|
|
1537
|
+
if (responseBlock.number !== reqNum) {
|
|
1538
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1539
|
+
return false;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1543
|
+
if (!local) {
|
|
1544
|
+
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1545
|
+
// TODO: Consider extending this validator to accept an expected hash or
|
|
1546
|
+
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1547
|
+
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1548
|
+
return false;
|
|
1549
|
+
}
|
|
1550
|
+
const [localHash, respHash] = await Promise.all([local.hash(), responseBlock.hash()]);
|
|
1551
|
+
if (!localHash.equals(respHash)) {
|
|
1552
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1553
|
+
return false;
|
|
1554
|
+
}
|
|
678
1555
|
|
|
679
|
-
if (outcome.allPassed) {
|
|
680
1556
|
return true;
|
|
1557
|
+
} catch (e) {
|
|
1558
|
+
this.logger.warn(`Error validating requested block`, e);
|
|
1559
|
+
return false;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
protected async validateRequestedTx(
|
|
1564
|
+
tx: Tx,
|
|
1565
|
+
peerId: PeerId,
|
|
1566
|
+
txValidator: TxValidator,
|
|
1567
|
+
requested?: Set<`0x${string}`>,
|
|
1568
|
+
) {
|
|
1569
|
+
const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
|
|
1570
|
+
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1571
|
+
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1572
|
+
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
681
1573
|
}
|
|
682
|
-
const { name } = outcome.failure;
|
|
683
|
-
let { severity } = outcome.failure;
|
|
684
1574
|
|
|
685
|
-
|
|
686
|
-
if (
|
|
687
|
-
|
|
1575
|
+
const { result } = await txValidator.validateTx(tx);
|
|
1576
|
+
if (result === 'invalid') {
|
|
1577
|
+
penalize(PeerErrorSeverity.LowToleranceError);
|
|
1578
|
+
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
|
|
688
1579
|
}
|
|
1580
|
+
}
|
|
689
1581
|
|
|
690
|
-
|
|
691
|
-
return
|
|
1582
|
+
protected createRequestedTxValidator(): TxValidator {
|
|
1583
|
+
return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
|
|
1584
|
+
l1ChainId: this.config.l1ChainId,
|
|
1585
|
+
rollupVersion: this.config.rollupVersion,
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
|
|
1590
|
+
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1591
|
+
return this.feesCache.gasFees;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
1595
|
+
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
1596
|
+
this.feesCache = { blockNumber, gasFees };
|
|
1597
|
+
return gasFees;
|
|
692
1598
|
}
|
|
693
1599
|
|
|
694
1600
|
/**
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
* Each validator is a pair of a validator and a severity.
|
|
698
|
-
* If a validator fails, the peer is penalized with the severity of the validator.
|
|
699
|
-
*
|
|
700
|
-
* @param blockNumber - The block number to create validators for.
|
|
701
|
-
* @returns The message validators.
|
|
1601
|
+
* Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
|
|
702
1602
|
*/
|
|
703
|
-
|
|
1603
|
+
public getBatchTxRequesterService(): BatchTxRequesterLibP2PService {
|
|
704
1604
|
return {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
severity: PeerErrorSeverity.HighToleranceError,
|
|
712
|
-
},
|
|
713
|
-
proofValidator: {
|
|
714
|
-
validator: new TxProofValidator(this.proofVerifier),
|
|
715
|
-
severity: PeerErrorSeverity.MidToleranceError,
|
|
716
|
-
},
|
|
717
|
-
doubleSpendValidator: {
|
|
718
|
-
validator: new DoubleSpendTxValidator({
|
|
719
|
-
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
720
|
-
const merkleTree = this.worldStateSynchronizer.getCommitted();
|
|
721
|
-
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
722
|
-
return indices.map(index => index !== undefined);
|
|
723
|
-
},
|
|
724
|
-
}),
|
|
725
|
-
severity: PeerErrorSeverity.HighToleranceError,
|
|
1605
|
+
reqResp: this.reqresp,
|
|
1606
|
+
connectionSampler: this.reqresp.getConnectionSampler(),
|
|
1607
|
+
txValidatorConfig: {
|
|
1608
|
+
l1ChainId: this.config.l1ChainId,
|
|
1609
|
+
rollupVersion: this.config.rollupVersion,
|
|
1610
|
+
proofVerifier: this.proofVerifier,
|
|
726
1611
|
},
|
|
1612
|
+
peerScoring: this.peerManager,
|
|
727
1613
|
};
|
|
728
1614
|
}
|
|
729
1615
|
|
|
1616
|
+
public async validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
1617
|
+
const validator = createTxValidatorForBlockProposalReceivedTxs(
|
|
1618
|
+
this.proofVerifier,
|
|
1619
|
+
{ l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
|
|
1620
|
+
this.logger.getBindings(),
|
|
1621
|
+
);
|
|
1622
|
+
|
|
1623
|
+
const results = await Promise.all(
|
|
1624
|
+
txs.map(async tx => {
|
|
1625
|
+
const result = await validator.validateTx(tx);
|
|
1626
|
+
return result.result !== 'invalid';
|
|
1627
|
+
}),
|
|
1628
|
+
);
|
|
1629
|
+
if (results.some(value => value === false)) {
|
|
1630
|
+
throw new Error('Invalid tx detected');
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/** Creates the first stage (fast) validators for gossiped transactions. */
|
|
1635
|
+
protected async createFirstStageMessageValidators(
|
|
1636
|
+
currentBlockNumber: BlockNumber,
|
|
1637
|
+
nextSlotTimestamp: UInt64,
|
|
1638
|
+
): Promise<Record<string, TransactionValidator>> {
|
|
1639
|
+
const gasFees = await this.getGasFees(currentBlockNumber);
|
|
1640
|
+
const allowedInSetup = [
|
|
1641
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1642
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1643
|
+
];
|
|
1644
|
+
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1645
|
+
const l1Constants = await this.archiver.getL1Constants();
|
|
1646
|
+
|
|
1647
|
+
return createFirstStageTxValidationsForGossipedTransactions(
|
|
1648
|
+
nextSlotTimestamp,
|
|
1649
|
+
blockNumber,
|
|
1650
|
+
this.worldStateSynchronizer,
|
|
1651
|
+
gasFees,
|
|
1652
|
+
this.config.l1ChainId,
|
|
1653
|
+
this.config.rollupVersion,
|
|
1654
|
+
protocolContractsHash,
|
|
1655
|
+
this.archiver,
|
|
1656
|
+
!this.config.disableTransactions,
|
|
1657
|
+
allowedInSetup,
|
|
1658
|
+
this.logger.getBindings(),
|
|
1659
|
+
{
|
|
1660
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1661
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1662
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1663
|
+
},
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
/** Creates the second stage (expensive proof verification) validators for gossiped transactions. */
|
|
1668
|
+
protected createSecondStageMessageValidators(): Record<string, TransactionValidator> {
|
|
1669
|
+
return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
|
|
1670
|
+
}
|
|
1671
|
+
|
|
730
1672
|
/**
|
|
731
1673
|
* Run validations on a tx.
|
|
732
1674
|
* @param tx - The tx to validate.
|
|
@@ -735,32 +1677,32 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
735
1677
|
*/
|
|
736
1678
|
private async runValidations(
|
|
737
1679
|
tx: Tx,
|
|
738
|
-
messageValidators: Record<string,
|
|
1680
|
+
messageValidators: Record<string, TransactionValidator>,
|
|
739
1681
|
): Promise<ValidationOutcome> {
|
|
740
1682
|
const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
|
|
741
1683
|
const { result } = await validator.validateTx(tx);
|
|
742
|
-
return { name, isValid: result
|
|
1684
|
+
return { name, isValid: result !== 'invalid', severity };
|
|
743
1685
|
});
|
|
744
1686
|
|
|
745
1687
|
// A promise that resolves when all validations have been run
|
|
746
|
-
const allValidations = Promise.all(validationPromises);
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
1688
|
+
const allValidations = await Promise.all(validationPromises);
|
|
1689
|
+
const failures = allValidations.filter(x => !x.isValid);
|
|
1690
|
+
if (failures.length > 0) {
|
|
1691
|
+
// Pick the most severe failure (lowest tolerance = harshest penalty)
|
|
1692
|
+
const failed = maxBy(failures, f => PeerErrorSeverityByHarshness.indexOf(f.severity))!;
|
|
1693
|
+
return {
|
|
1694
|
+
allPassed: false,
|
|
1695
|
+
failure: {
|
|
1696
|
+
isValid: { result: 'invalid' as const, reason: ['Failed validation'] },
|
|
1697
|
+
name: failed.name,
|
|
1698
|
+
severity: failed.severity,
|
|
1699
|
+
},
|
|
1700
|
+
};
|
|
1701
|
+
} else {
|
|
1702
|
+
return {
|
|
1703
|
+
allPassed: true,
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
764
1706
|
}
|
|
765
1707
|
|
|
766
1708
|
/**
|
|
@@ -774,20 +1716,23 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
774
1716
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
775
1717
|
* @returns Severity
|
|
776
1718
|
*/
|
|
777
|
-
private async handleDoubleSpendFailure(tx: Tx, blockNumber:
|
|
1719
|
+
private async handleDoubleSpendFailure(tx: Tx, blockNumber: BlockNumber): Promise<PeerErrorSeverity> {
|
|
778
1720
|
if (blockNumber <= this.config.doubleSpendSeverePeerPenaltyWindow) {
|
|
779
1721
|
return PeerErrorSeverity.HighToleranceError;
|
|
780
1722
|
}
|
|
781
1723
|
|
|
782
|
-
const snapshotValidator = new DoubleSpendTxValidator(
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
1724
|
+
const snapshotValidator = new DoubleSpendTxValidator(
|
|
1725
|
+
{
|
|
1726
|
+
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
1727
|
+
const merkleTree = this.worldStateSynchronizer.getSnapshot(
|
|
1728
|
+
BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow),
|
|
1729
|
+
);
|
|
1730
|
+
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
1731
|
+
return indices.map(index => index !== undefined);
|
|
1732
|
+
},
|
|
789
1733
|
},
|
|
790
|
-
|
|
1734
|
+
this.logger.getBindings(),
|
|
1735
|
+
);
|
|
791
1736
|
|
|
792
1737
|
const validSnapshot = await snapshotValidator.validateTx(tx);
|
|
793
1738
|
if (validSnapshot.result !== 'valid') {
|
|
@@ -798,57 +1743,45 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
798
1743
|
}
|
|
799
1744
|
|
|
800
1745
|
/**
|
|
801
|
-
* Validate
|
|
1746
|
+
* Validate a checkpoint attestation.
|
|
802
1747
|
*
|
|
803
|
-
* @param attestation - The attestation to validate.
|
|
804
|
-
* @returns True if the attestation is valid, false otherwise.
|
|
1748
|
+
* @param attestation - The checkpoint attestation to validate.
|
|
1749
|
+
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
805
1750
|
*/
|
|
806
|
-
@trackSpan('Libp2pService.
|
|
807
|
-
[Attributes.
|
|
808
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toNumber(),
|
|
1751
|
+
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1752
|
+
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
809
1753
|
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
810
|
-
[Attributes.P2P_ID]: await attestation.
|
|
1754
|
+
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
811
1755
|
}))
|
|
812
|
-
public async
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
return true;
|
|
820
|
-
}
|
|
1756
|
+
public async validateCheckpointAttestation(
|
|
1757
|
+
peerId: PeerId,
|
|
1758
|
+
attestation: CheckpointAttestation,
|
|
1759
|
+
): Promise<P2PValidationResult> {
|
|
1760
|
+
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
821
1761
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
* @param block - The block proposal to validate.
|
|
826
|
-
* @returns True if the block proposal is valid, false otherwise.
|
|
827
|
-
*/
|
|
828
|
-
@trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
|
|
829
|
-
[Attributes.SLOT_NUMBER]: block.payload.header.globalVariables.slotNumber.toString(),
|
|
830
|
-
}))
|
|
831
|
-
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<boolean> {
|
|
832
|
-
const severity = await this.blockProposalValidator.validate(block);
|
|
833
|
-
if (severity) {
|
|
834
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
835
|
-
return false;
|
|
1762
|
+
if (result.result === 'reject') {
|
|
1763
|
+
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1764
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
836
1765
|
}
|
|
837
1766
|
|
|
838
|
-
return
|
|
1767
|
+
return result;
|
|
839
1768
|
}
|
|
840
1769
|
|
|
841
1770
|
public getPeerScore(peerId: PeerId): number {
|
|
842
1771
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
843
1772
|
}
|
|
844
1773
|
|
|
1774
|
+
public handleAuthRequestFromPeer(authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage> {
|
|
1775
|
+
return this.peerManager.handleAuthRequestFromPeer(authRequest, peerId);
|
|
1776
|
+
}
|
|
1777
|
+
|
|
845
1778
|
private async sendToPeers<T extends Gossipable>(message: T) {
|
|
846
1779
|
const parent = message.constructor as typeof Gossipable;
|
|
847
1780
|
|
|
848
|
-
const identifier = await message.
|
|
1781
|
+
const identifier = await message.p2pMessageLoggingIdentifier().then(i => i.toString());
|
|
849
1782
|
this.logger.trace(`Sending message ${identifier}`, { p2pMessageIdentifier: identifier });
|
|
850
1783
|
|
|
851
|
-
const recipientsNum = await this.publishToTopic(parent.p2pTopic, message
|
|
1784
|
+
const recipientsNum = await this.publishToTopic(this.topicStrings[parent.p2pTopic], message);
|
|
852
1785
|
this.logger.debug(`Sent message ${identifier} to ${recipientsNum} peers`, {
|
|
853
1786
|
p2pMessageIdentifier: identifier,
|
|
854
1787
|
sourcePeer: this.node.peerId.toString(),
|