@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -3
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -6
- package/dest/client/factory.d.ts +11 -10
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +64 -17
- package/dest/client/interface.d.ts +86 -40
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +67 -64
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +251 -251
- package/dest/config.d.ts +173 -94
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +158 -44
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/reqresp.error.d.ts +9 -16
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +10 -17
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +106 -55
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +302 -195
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +274 -115
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +7 -5
- package/dest/mem_pools/index.d.ts +2 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +12 -5
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +38 -17
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +10 -5
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +29 -20
- 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 +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +8 -4
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +15 -5
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +3 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +64 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +6 -5
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +9 -8
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +15 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +2 -1
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +25 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +67 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +62 -16
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +81 -15
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +147 -19
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +26 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +79 -43
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +27 -7
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +94 -32
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +62 -9
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +537 -246
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +36 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/factory.d.ts +133 -7
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +261 -61
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +104 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
- package/dest/msg_validators/tx_validator/index.d.ts +5 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +4 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/discv5/discV5_service.d.ts +13 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +119 -23
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +25 -19
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +28 -20
- package/dest/services/encoding.d.ts +24 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +43 -26
- package/dest/services/gossipsub/topic_score_params.d.ts +23 -17
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +36 -24
- package/dest/services/libp2p/instrumentation.d.ts +6 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +21 -0
- package/dest/services/libp2p/libp2p_service.d.ts +71 -60
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +602 -407
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +31 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +127 -26
- package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +102 -13
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +5 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +95 -127
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
- package/dest/services/reqresp/config.d.ts +15 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +11 -0
- package/dest/services/reqresp/interface.d.ts +25 -18
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +23 -19
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +18 -7
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +57 -24
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +21 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
- package/dest/services/reqresp/reqresp.d.ts +7 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +85 -219
- package/dest/services/service.d.ts +63 -19
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +11 -14
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +26 -33
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +100 -0
- package/dest/services/tx_collection/index.d.ts +3 -3
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -1
- package/dest/services/tx_collection/instrumentation.js +1 -2
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/tx_collection.d.ts +45 -51
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +296 -68
- package/dest/services/tx_collection/tx_collection_sink.d.ts +19 -9
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +28 -31
- package/dest/services/tx_collection/tx_source.d.ts +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +29 -7
- package/dest/services/tx_file_store/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -5
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +13 -20
- package/dest/services/tx_provider.d.ts +6 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +12 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +5 -3
- package/dest/test-helpers/mock-pubsub.d.ts +56 -6
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +128 -14
- package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +17 -19
- package/dest/test-helpers/test_tx_provider.d.ts +3 -1
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
- package/dest/test-helpers/test_tx_provider.js +3 -0
- package/dest/test-helpers/testbench-utils.d.ts +49 -37
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +142 -50
- package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +112 -49
- package/dest/testbench/worker_client_manager.d.ts +12 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +57 -11
- package/dest/util.d.ts +13 -8
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +17 -17
- package/src/bootstrap/bootstrap.ts +17 -3
- package/src/client/factory.ts +129 -28
- package/src/client/interface.ts +88 -48
- package/src/client/p2p_client.ts +284 -317
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +280 -49
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +13 -19
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +373 -236
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +298 -119
- package/src/mem_pools/attestation_pool/index.ts +3 -3
- package/src/mem_pools/attestation_pool/mocks.ts +14 -8
- package/src/mem_pools/index.ts +1 -1
- package/src/mem_pools/instrumentation.ts +27 -17
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +85 -11
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +30 -20
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +6 -4
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +21 -6
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +5 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +67 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +4 -6
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -10
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -10
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
- package/src/mem_pools/tx_pool_v2/index.ts +2 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +96 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +63 -16
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +215 -27
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +91 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +122 -33
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +602 -242
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
- package/src/msg_validators/tx_validator/README.md +129 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +44 -1
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +413 -80
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
- package/src/msg_validators/tx_validator/index.ts +4 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/data_store.ts +5 -13
- package/src/services/discv5/discV5_service.ts +126 -14
- package/src/services/discv5/persisted_enr_store.ts +158 -0
- package/src/services/dummy_service.ts +38 -46
- package/src/services/encoding.ts +42 -26
- package/src/services/gossipsub/README.md +59 -22
- package/src/services/gossipsub/topic_score_params.ts +58 -31
- package/src/services/libp2p/instrumentation.ts +22 -0
- package/src/services/libp2p/libp2p_service.ts +687 -466
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +140 -25
- package/src/services/peer-manager/peer_scoring.ts +102 -8
- package/src/services/reqresp/README.md +194 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +92 -138
- package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
- package/src/services/reqresp/config.ts +19 -2
- package/src/services/reqresp/interface.ts +45 -46
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +36 -32
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +64 -20
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +23 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
- package/src/services/reqresp/reqresp.ts +100 -263
- package/src/services/service.ts +80 -35
- package/src/services/tx_collection/config.ts +40 -49
- package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +2 -6
- package/src/services/tx_collection/instrumentation.ts +1 -1
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/tx_collection.ts +362 -110
- package/src/services/tx_collection/tx_collection_sink.ts +32 -36
- package/src/services/tx_collection/tx_source.ts +29 -8
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +15 -25
- package/src/services/tx_provider.ts +15 -9
- package/src/test-helpers/make-test-p2p-clients.ts +7 -6
- package/src/test-helpers/mock-pubsub.ts +152 -14
- package/src/test-helpers/reqresp-nodes.ts +15 -28
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +171 -68
- package/src/testbench/p2p_client_testbench_worker.ts +121 -64
- package/src/testbench/worker_client_manager.ts +72 -25
- package/src/util.ts +40 -19
- package/src/versioning.ts +3 -33
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/clock_tolerance.d.ts +0 -21
- package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
- package/dest/msg_validators/clock_tolerance.js +0 -37
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -52
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -307
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -49
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -53
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -177
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/clock_tolerance.ts +0 -51
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/fast_tx_collection.ts +0 -354
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -112
- package/src/services/tx_collection/slow_tx_collection.ts +0 -233
|
@@ -370,17 +370,20 @@ function applyDecs2203RFactory() {
|
|
|
370
370
|
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
|
-
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5,
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _initProto;
|
|
374
374
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
375
|
-
import {
|
|
375
|
+
import { compactArray, maxBy, merge } from '@aztec/foundation/collection';
|
|
376
376
|
import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
377
377
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
378
378
|
import { Timer } from '@aztec/foundation/timer';
|
|
379
379
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
380
|
-
import {
|
|
381
|
-
import {
|
|
380
|
+
import { DEFAULT_MAX_BLOCKS_PER_CHECKPOINT } from '@aztec/stdlib/config';
|
|
381
|
+
import { getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
382
|
+
import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PMessage, PeerErrorSeverity, PeerErrorSeverityByHarshness, TopicType, ValidatedBlockProposal, ValidatedCheckpointProposalCore, createTopicString, getTopicsForConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
|
|
383
|
+
import { ConsensusTimetable, getDefaultCheckpointProposalSyncGrace } from '@aztec/stdlib/timetable';
|
|
382
384
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
383
385
|
import { Tx } from '@aztec/stdlib/tx';
|
|
386
|
+
import { InvalidBlockProposalTxsError } from '@aztec/stdlib/validators';
|
|
384
387
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
385
388
|
import { Attributes, OtelMetricsAdapter, SpanStatusCode, WithTracer, trackSpan } from '@aztec/telemetry-client';
|
|
386
389
|
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
@@ -393,25 +396,39 @@ import { identify } from '@libp2p/identify';
|
|
|
393
396
|
import { TopicValidatorResult } from '@libp2p/interface';
|
|
394
397
|
import { mplex } from '@libp2p/mplex';
|
|
395
398
|
import { tcp } from '@libp2p/tcp';
|
|
399
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
396
400
|
import { ENR } from '@nethermindeth/enr';
|
|
397
401
|
import { createLibp2p } from 'libp2p';
|
|
402
|
+
import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
|
|
398
403
|
import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, DoubleSpendTxValidator, FishermanAttestationValidator, getDefaultAllowedSetupFunctions } from '../../msg_validators/index.js';
|
|
399
404
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
400
|
-
import {
|
|
405
|
+
import { createFirstStageTxValidationsForGossipedTransactions, createSecondStageTxValidationsForGossipedTransactions, createTxValidatorForBlockProposalReceivedTxs } from '../../msg_validators/tx_validator/factory.js';
|
|
401
406
|
import { GossipSubEvent } from '../../types/index.js';
|
|
402
407
|
import { convertToMultiaddr } from '../../util.js';
|
|
403
408
|
import { getVersions } from '../../versioning.js';
|
|
404
409
|
import { AztecDatastore } from '../data_store.js';
|
|
405
410
|
import { DiscV5Service } from '../discv5/discV5_service.js';
|
|
406
|
-
import { SnappyTransform,
|
|
411
|
+
import { SnappyTransform, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
407
412
|
import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
408
413
|
import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
|
|
409
414
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
410
415
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
411
|
-
import {
|
|
412
|
-
import { pingHandler, reqGoodbyeHandler,
|
|
416
|
+
import { YAMUX_MAX_MESSAGE_SIZE_BYTES } from '../reqresp/config.js';
|
|
417
|
+
import { ReqRespSubProtocol, ValidationError, pingHandler, reqGoodbyeHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
|
|
413
418
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
414
419
|
import { P2PInstrumentation } from './instrumentation.js';
|
|
420
|
+
/**
|
|
421
|
+
* Builds the {@link ConsensusTimetable} shared by the gossip validators for proposal/attestation receive-window
|
|
422
|
+
* bounds. Derived purely from protocol slot-timing constants plus the block sub-slot duration and the consensus
|
|
423
|
+
* materialization grace, so every node agrees on these bounds without depending on proposer operational budgets.
|
|
424
|
+
*/ function buildConsensusTimetable(config, l1Constants) {
|
|
425
|
+
const blockDuration = config.blockDurationMs / 1000;
|
|
426
|
+
return new ConsensusTimetable({
|
|
427
|
+
l1Constants,
|
|
428
|
+
blockDuration,
|
|
429
|
+
checkpointProposalSyncGrace: config.checkpointProposalSyncGraceSeconds ?? getDefaultCheckpointProposalSyncGrace(blockDuration)
|
|
430
|
+
});
|
|
431
|
+
}
|
|
415
432
|
_dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation)=>({
|
|
416
433
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString()
|
|
417
434
|
})), _dec1 = trackSpan('Libp2pService.validateAndStoreBlockProposal', (_peerId, block)=>({
|
|
@@ -427,23 +444,12 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
427
444
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
428
445
|
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
429
446
|
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
430
|
-
})), _dec5 = trackSpan('Libp2pService.
|
|
447
|
+
})), _dec5 = trackSpan('Libp2pService.validateRequestedBlockTxsConsistency', (request)=>({
|
|
431
448
|
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString()
|
|
432
|
-
})), _dec6 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
|
|
433
|
-
[Attributes.TX_HASH]: requestedTxHash.toString()
|
|
434
|
-
})), _dec7 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
|
|
435
|
-
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
|
|
436
|
-
})), _dec8 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
|
|
437
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
438
|
-
})), _dec9 = trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation)=>({
|
|
439
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
440
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
441
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
442
449
|
}));
|
|
443
450
|
/**
|
|
444
451
|
* Lib P2P implementation of the P2PService interface.
|
|
445
452
|
*/ export class LibP2PService extends WithTracer {
|
|
446
|
-
clientType;
|
|
447
453
|
config;
|
|
448
454
|
node;
|
|
449
455
|
peerDiscoveryService;
|
|
@@ -454,6 +460,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
454
460
|
epochCache;
|
|
455
461
|
proofVerifier;
|
|
456
462
|
worldStateSynchronizer;
|
|
463
|
+
blockMinFeesProvider;
|
|
464
|
+
txValidationCache;
|
|
457
465
|
static{
|
|
458
466
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
459
467
|
[
|
|
@@ -484,27 +492,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
484
492
|
[
|
|
485
493
|
_dec5,
|
|
486
494
|
2,
|
|
487
|
-
"
|
|
488
|
-
],
|
|
489
|
-
[
|
|
490
|
-
_dec6,
|
|
491
|
-
2,
|
|
492
|
-
"validateRequestedTxs"
|
|
493
|
-
],
|
|
494
|
-
[
|
|
495
|
-
_dec7,
|
|
496
|
-
2,
|
|
497
|
-
"validateRequestedBlock"
|
|
498
|
-
],
|
|
499
|
-
[
|
|
500
|
-
_dec8,
|
|
501
|
-
2,
|
|
502
|
-
"validatePropagatedTx"
|
|
503
|
-
],
|
|
504
|
-
[
|
|
505
|
-
_dec9,
|
|
506
|
-
2,
|
|
507
|
-
"validateCheckpointAttestation"
|
|
495
|
+
"validateRequestedBlockTxsConsistency"
|
|
508
496
|
]
|
|
509
497
|
], []));
|
|
510
498
|
}
|
|
@@ -516,8 +504,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
516
504
|
checkpointAttestationValidator;
|
|
517
505
|
protocolVersion;
|
|
518
506
|
topicStrings;
|
|
519
|
-
feesCache;
|
|
520
507
|
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */ duplicateProposalCallback;
|
|
508
|
+
/** Callback invoked when an oversized block proposal is stored as slashing evidence (triggers slashing). */ oversizedProposalCallback;
|
|
509
|
+
/** Callback invoked when a duplicate attestation is detected (triggers slashing). */ duplicateAttestationCallback;
|
|
510
|
+
/** Callback invoked when a valid checkpoint attestation is accepted into the pool. */ checkpointAttestationCallback;
|
|
521
511
|
/**
|
|
522
512
|
* Callback for when a block is received from a peer.
|
|
523
513
|
* @param block - The block received from the peer.
|
|
@@ -527,13 +517,20 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
527
517
|
* Callback for when a checkpoint proposal is received from a peer.
|
|
528
518
|
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
529
519
|
* @returns The attestations for the checkpoint, if any.
|
|
530
|
-
*/
|
|
520
|
+
*/ allNodesCheckpointReceivedCallback;
|
|
521
|
+
/**
|
|
522
|
+
* Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
|
|
523
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
524
|
+
* @returns The attestations for the checkpoint, if any.
|
|
525
|
+
*/ validatorCheckpointReceivedCallback;
|
|
531
526
|
gossipSubEventHandler;
|
|
527
|
+
ipChangedHandler;
|
|
528
|
+
discoveredP2pIp;
|
|
532
529
|
instrumentation;
|
|
533
530
|
telemetry;
|
|
534
531
|
logger;
|
|
535
|
-
constructor(
|
|
536
|
-
super(telemetry, 'LibP2PService'), this.
|
|
532
|
+
constructor(config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger = createLogger('p2p:libp2p_service'), txValidationCache){
|
|
533
|
+
super(telemetry, 'LibP2PService'), this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.reqresp = reqresp, this.peerManager = peerManager, this.mempools = mempools, this.archiver = archiver, this.epochCache = epochCache, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.blockMinFeesProvider = blockMinFeesProvider, this.txValidationCache = txValidationCache, this.msgIdSeenValidators = (_initProto(this), {}), this.protocolVersion = '', this.topicStrings = {};
|
|
537
534
|
this.telemetry = telemetry;
|
|
538
535
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
539
536
|
this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
|
|
@@ -549,40 +546,57 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
549
546
|
this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
|
|
550
547
|
this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(TopicType.checkpoint_proposal, this.protocolVersion);
|
|
551
548
|
this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(TopicType.checkpoint_attestation, this.protocolVersion);
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
txsPermitted: !config.disableTransactions
|
|
557
|
-
|
|
558
|
-
|
|
549
|
+
// Build the consensus timetable once from protocol slot-timing constants and inject it into every
|
|
550
|
+
// validator so they share one set of receive-window bounds, independent of proposer operational budgets.
|
|
551
|
+
const consensusTimetable = buildConsensusTimetable(config, epochCache.getL1Constants());
|
|
552
|
+
const proposalValidatorOpts = {
|
|
553
|
+
txsPermitted: !config.disableTransactions,
|
|
554
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
555
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
556
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
557
|
+
signatureContext: {
|
|
558
|
+
chainId: config.l1ChainId,
|
|
559
|
+
rollupAddress: config.rollupAddress
|
|
560
|
+
},
|
|
561
|
+
clockDisparityMs: config.maxGossipClockDisparityMs
|
|
562
|
+
};
|
|
563
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, proposalValidatorOpts);
|
|
564
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, consensusTimetable, proposalValidatorOpts);
|
|
565
|
+
const attestationValidatorOpts = {
|
|
566
|
+
signatureContext: proposalValidatorOpts.signatureContext,
|
|
567
|
+
clockDisparityMs: config.maxGossipClockDisparityMs
|
|
568
|
+
};
|
|
569
|
+
this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, consensusTimetable, mempools.attestationPool, telemetry, attestationValidatorOpts) : new CheckpointAttestationValidator(epochCache, consensusTimetable, attestationValidatorOpts);
|
|
559
570
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
560
571
|
this.blockReceivedCallback = async (block)=>{
|
|
561
|
-
this.logger.
|
|
572
|
+
this.logger.warn(`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`, {
|
|
562
573
|
p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
|
|
563
574
|
});
|
|
564
|
-
return
|
|
575
|
+
return true;
|
|
565
576
|
};
|
|
566
|
-
this.
|
|
567
|
-
|
|
577
|
+
this.allNodesCheckpointReceivedCallback = (_checkpoint)=>{
|
|
578
|
+
throw new CheckpointProposalReceivedCallbackNotRegisteredError();
|
|
579
|
+
};
|
|
580
|
+
this.validatorCheckpointReceivedCallback = (_checkpoint)=>{
|
|
568
581
|
return Promise.resolve(undefined);
|
|
569
582
|
};
|
|
570
583
|
}
|
|
571
584
|
updateConfig(config) {
|
|
572
585
|
this.reqresp.updateConfig(config);
|
|
586
|
+
this.config = merge(this.config, config);
|
|
573
587
|
}
|
|
574
588
|
/**
|
|
575
589
|
* Creates an instance of the LibP2P service.
|
|
576
590
|
* @param config - The configuration to use when creating the service.
|
|
577
591
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
578
592
|
* @returns The new service.
|
|
579
|
-
*/ static async new(
|
|
580
|
-
const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, telemetry, logger, packageVersion } = deps;
|
|
593
|
+
*/ static async new(config, peerId, deps) {
|
|
594
|
+
const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, blockMinFeesProvider, telemetry, logger, packageVersion, txValidationCache } = deps;
|
|
581
595
|
const { p2pPort, maxPeerCount, listenAddress } = config;
|
|
582
596
|
const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
|
|
583
597
|
const datastore = new AztecDatastore(peerStore);
|
|
584
598
|
const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
|
|
585
|
-
const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`, logger.getBindings()));
|
|
599
|
+
const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`, logger.getBindings()), peerStore);
|
|
586
600
|
// Seed libp2p's bootstrap discovery with private and trusted peers
|
|
587
601
|
const bootstrapNodes = [
|
|
588
602
|
...config.privatePeers,
|
|
@@ -597,30 +611,45 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
597
611
|
const versions = getVersions(config);
|
|
598
612
|
const protocolVersion = compressComponentVersions(versions);
|
|
599
613
|
const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
|
|
600
|
-
const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
614
|
+
const directPeers = compactArray(await Promise.all(preferredPeersEnrs.map(async (enr)=>{
|
|
615
|
+
try {
|
|
616
|
+
const peerId = await enr.peerId();
|
|
617
|
+
const address = enr.getLocationMultiaddr('tcp');
|
|
618
|
+
if (address === undefined) {
|
|
619
|
+
throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
id: peerId,
|
|
623
|
+
addrs: [
|
|
624
|
+
address
|
|
625
|
+
]
|
|
626
|
+
};
|
|
627
|
+
} catch (err) {
|
|
628
|
+
// A malformed configured ENR shouldn't abort node setup — skip it and log.
|
|
629
|
+
logger.warn(`Skipping preferred peer with invalid ENR`, {
|
|
630
|
+
err
|
|
631
|
+
});
|
|
632
|
+
return undefined;
|
|
605
633
|
}
|
|
606
|
-
|
|
607
|
-
id: peerId,
|
|
608
|
-
addrs: [
|
|
609
|
-
address
|
|
610
|
-
]
|
|
611
|
-
};
|
|
612
|
-
}))).filter((peer)=>peer !== undefined);
|
|
634
|
+
})));
|
|
613
635
|
const announceTcpMultiaddr = config.p2pIp ? [
|
|
614
636
|
convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
|
|
615
637
|
] : [];
|
|
616
|
-
// Create dynamic topic score params based on network configuration
|
|
638
|
+
// Create dynamic topic score params based on network configuration. Scoring uses the network-wide
|
|
639
|
+
// max-blocks-per-checkpoint config value directly to size expected per-slot message rates; these are
|
|
640
|
+
// peer-rate thresholds, not consensus deadlines, so they need no proposer operational budgets.
|
|
617
641
|
const l1Constants = epochCache.getL1Constants();
|
|
618
642
|
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
619
643
|
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
620
644
|
heartbeatIntervalMs: config.gossipsubInterval,
|
|
621
645
|
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
622
|
-
|
|
646
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint ?? DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
|
|
647
|
+
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot
|
|
623
648
|
});
|
|
649
|
+
// Restrict gossipsub to exactly the topics we subscribe to. Without this, an arbitrary-topic
|
|
650
|
+
// message is transformed, msg-id'd and inserted into the seenCache before the subscription check,
|
|
651
|
+
// so a crafted topic colliding on msg id can suppress a real message as a duplicate.
|
|
652
|
+
const allowedTopics = getTopicsForConfig(config.disableTransactions).map((topic)=>createTopicString(topic, protocolVersion));
|
|
624
653
|
const node = await createLibp2p({
|
|
625
654
|
start: false,
|
|
626
655
|
peerId,
|
|
@@ -654,8 +683,11 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
654
683
|
],
|
|
655
684
|
datastore,
|
|
656
685
|
peerDiscovery,
|
|
686
|
+
// Pin the yamux frame size: MAX_REQRESP_REQUEST_SIZE_BYTES relies on a reqresp request fitting in one frame.
|
|
657
687
|
streamMuxers: [
|
|
658
|
-
yamux(
|
|
688
|
+
yamux({
|
|
689
|
+
maxMessageSize: YAMUX_MAX_MESSAGE_SIZE_BYTES
|
|
690
|
+
}),
|
|
659
691
|
mplex()
|
|
660
692
|
],
|
|
661
693
|
connectionEncryption: [
|
|
@@ -673,7 +705,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
673
705
|
},
|
|
674
706
|
connectionGater: {
|
|
675
707
|
denyInboundConnection: (maConn)=>{
|
|
676
|
-
const allowed = peerManager.
|
|
708
|
+
const allowed = peerManager.isAddressAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
|
|
677
709
|
if (allowed) {
|
|
678
710
|
return false;
|
|
679
711
|
}
|
|
@@ -683,7 +715,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
683
715
|
denyInboundEncryptedConnection: (peerId, _maConn)=>{
|
|
684
716
|
//NOTE: it is not necessary to check address here because this was already done by
|
|
685
717
|
// denyInboundConnection
|
|
686
|
-
const allowed = peerManager.
|
|
718
|
+
const allowed = peerManager.isPeerAllowedToConnect(peerId);
|
|
687
719
|
if (allowed) {
|
|
688
720
|
return false;
|
|
689
721
|
}
|
|
@@ -710,9 +742,13 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
710
742
|
mcacheLength: config.gossipsubMcacheLength,
|
|
711
743
|
mcacheGossip: config.gossipsubMcacheGossip,
|
|
712
744
|
seenTTL: config.gossipsubSeenTTL,
|
|
745
|
+
allowedTopics,
|
|
746
|
+
// No fastMsgIdFn: the fast-path dedup cache keys on a non-cryptographic 64-bit hash of the
|
|
747
|
+
// raw data only (no topic), so a collision — accidental or engineered via a weak seed — drops
|
|
748
|
+
// a different message with no fallback to the full id. Dedup instead rests solely on the
|
|
749
|
+
// cryptographic, topic-framed msgIdFn below.
|
|
713
750
|
msgIdFn: getMsgIdFn,
|
|
714
751
|
msgIdToStrFn: msgIdToStrFn,
|
|
715
|
-
fastMsgIdFn: fastMsgIdFn,
|
|
716
752
|
dataTransform: new SnappyTransform(),
|
|
717
753
|
metricsRegister: otelMetricsAdapter,
|
|
718
754
|
metricsTopicStrToLabel: metricsTopicStrToLabels(protocolVersion),
|
|
@@ -725,7 +761,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
725
761
|
})
|
|
726
762
|
}),
|
|
727
763
|
components: (components)=>({
|
|
728
|
-
connectionManager: components.connectionManager
|
|
764
|
+
connectionManager: components.connectionManager,
|
|
765
|
+
addressManager: components.addressManager
|
|
729
766
|
})
|
|
730
767
|
},
|
|
731
768
|
logger: createLibp2pComponentLogger(logger.module, logger.getBindings())
|
|
@@ -733,6 +770,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
733
770
|
const peerScoring = new PeerScoring(config, telemetry);
|
|
734
771
|
const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
|
|
735
772
|
const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
|
|
773
|
+
// Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
|
|
774
|
+
reqresp.setShouldRejectPeer((peerId)=>peerManager.shouldDisableP2PGossip(peerId));
|
|
736
775
|
// Configure application-specific scoring for gossipsub.
|
|
737
776
|
// The weight scales app score to align with gossipsub thresholds:
|
|
738
777
|
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
@@ -740,7 +779,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
740
779
|
// Note: positive topic scores can offset penalties, so alignment is best-effort.
|
|
741
780
|
node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
|
|
742
781
|
node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
743
|
-
return new LibP2PService(
|
|
782
|
+
return new LibP2PService(config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger, txValidationCache);
|
|
744
783
|
}
|
|
745
784
|
/**
|
|
746
785
|
* Starts the LibP2P service.
|
|
@@ -750,22 +789,19 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
750
789
|
if (this.node.status === 'started') {
|
|
751
790
|
throw new Error('P2P service already started');
|
|
752
791
|
}
|
|
753
|
-
// Get listen & announce addresses for logging
|
|
754
792
|
const { p2pIp, p2pPort } = this.config;
|
|
755
|
-
if (!p2pIp) {
|
|
756
|
-
throw new Error('Announce address not provided.');
|
|
793
|
+
if (!p2pIp && !this.config.queryForIp) {
|
|
794
|
+
throw new Error('Announce address not provided and queryForIp is not enabled.');
|
|
757
795
|
}
|
|
758
|
-
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
796
|
+
const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
|
|
759
797
|
// Create request response protocol handlers
|
|
760
798
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
761
799
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
762
|
-
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
763
800
|
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
764
801
|
const requestResponseHandlers = {
|
|
765
802
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
766
803
|
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
767
|
-
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
|
|
768
|
-
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
|
|
804
|
+
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
|
|
769
805
|
};
|
|
770
806
|
if (!this.config.disableTransactions) {
|
|
771
807
|
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.archiver, this.mempools.txPool);
|
|
@@ -774,18 +810,11 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
774
810
|
if (!this.config.disableTransactions) {
|
|
775
811
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
776
812
|
}
|
|
777
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
778
|
-
const reqrespSubProtocolValidators = {
|
|
779
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
780
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
781
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
782
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
|
|
783
|
-
};
|
|
784
813
|
await this.peerManager.initializePeers();
|
|
785
|
-
await this.reqresp.start(requestResponseHandlers
|
|
814
|
+
await this.reqresp.start(requestResponseHandlers);
|
|
786
815
|
await this.node.start();
|
|
787
816
|
// Subscribe to standard GossipSub topics by default
|
|
788
|
-
for (const topic of
|
|
817
|
+
for (const topic of getTopicsForConfig(this.config.disableTransactions)){
|
|
789
818
|
this.subscribeToTopic(this.topicStrings[topic]);
|
|
790
819
|
}
|
|
791
820
|
// add GossipSub listener
|
|
@@ -794,6 +823,34 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
794
823
|
if (!this.config.p2pDiscoveryDisabled) {
|
|
795
824
|
await this.peerDiscoveryService.start();
|
|
796
825
|
}
|
|
826
|
+
// Bridge discv5 IP changes to libp2p's AddressManager so peers see the updated address
|
|
827
|
+
if (this.config.queryForIp) {
|
|
828
|
+
this.discoveredP2pIp = this.config.p2pIp;
|
|
829
|
+
this.logger.info('IP change tracking enabled, bridging discv5 IP updates to libp2p AddressManager');
|
|
830
|
+
this.ipChangedHandler = (ip)=>{
|
|
831
|
+
const addressManager = this.node.services.components.addressManager;
|
|
832
|
+
const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
|
|
833
|
+
const previousIp = this.discoveredP2pIp;
|
|
834
|
+
if (previousIp) {
|
|
835
|
+
const oldAddr = multiaddr(convertToMultiaddr(previousIp, this.config.p2pPort, 'tcp'));
|
|
836
|
+
addressManager.removeObservedAddr(oldAddr);
|
|
837
|
+
this.logger.info('Libp2p announce address updated due to IP change', {
|
|
838
|
+
previousIp,
|
|
839
|
+
newIp: ip,
|
|
840
|
+
newMultiaddr: newAddr.toString()
|
|
841
|
+
});
|
|
842
|
+
} else {
|
|
843
|
+
this.logger.info('Libp2p announce address set from initial discv5 IP discovery', {
|
|
844
|
+
ip,
|
|
845
|
+
multiaddr: newAddr.toString()
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
addressManager.addObservedAddr(newAddr);
|
|
849
|
+
addressManager.confirmObservedAddr(newAddr);
|
|
850
|
+
this.discoveredP2pIp = ip;
|
|
851
|
+
};
|
|
852
|
+
this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
|
|
853
|
+
}
|
|
797
854
|
this.discoveryRunningPromise = new RunningPromise(async ()=>{
|
|
798
855
|
await this.peerManager.heartbeat();
|
|
799
856
|
}, this.logger, this.config.peerCheckIntervalMS);
|
|
@@ -811,6 +868,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
811
868
|
*/ async stop() {
|
|
812
869
|
// Remove gossip sub listener
|
|
813
870
|
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
871
|
+
if (this.ipChangedHandler) {
|
|
872
|
+
this.peerDiscoveryService.removeListener('ip:changed', this.ipChangedHandler);
|
|
873
|
+
this.ipChangedHandler = undefined;
|
|
874
|
+
}
|
|
814
875
|
// Stop peer manager
|
|
815
876
|
this.logger.debug('Stopping peer manager...');
|
|
816
877
|
await this.peerManager.stop();
|
|
@@ -824,8 +885,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
824
885
|
await this.stopLibP2P();
|
|
825
886
|
this.logger.info('LibP2P service stopped');
|
|
826
887
|
}
|
|
827
|
-
addReqRespSubProtocol(subProtocol, handler
|
|
828
|
-
return this.reqresp.addSubProtocol(subProtocol, handler
|
|
888
|
+
addReqRespSubProtocol(subProtocol, handler) {
|
|
889
|
+
return this.reqresp.addSubProtocol(subProtocol, handler);
|
|
829
890
|
}
|
|
830
891
|
registerThisValidatorAddresses(address) {
|
|
831
892
|
this.peerManager.registerThisValidatorAddresses(address);
|
|
@@ -833,6 +894,16 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
833
894
|
getPeers(includePending) {
|
|
834
895
|
return this.peerManager.getPeers(includePending);
|
|
835
896
|
}
|
|
897
|
+
getP2PConnectivity() {
|
|
898
|
+
const connectedPeers = this.peerManager.getPeers().filter((peer)=>peer.status === 'connected').length;
|
|
899
|
+
return {
|
|
900
|
+
enabled: true,
|
|
901
|
+
connectedPeers
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
getGossipMeshPeerCount(topicType) {
|
|
905
|
+
return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
|
|
906
|
+
}
|
|
836
907
|
handleGossipSubEvent(e) {
|
|
837
908
|
this.logger.trace(`Received PUBSUB message.`);
|
|
838
909
|
const safeJob = async ()=>{
|
|
@@ -844,14 +915,6 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
844
915
|
};
|
|
845
916
|
setImmediate(()=>void safeJob());
|
|
846
917
|
}
|
|
847
|
-
/**
|
|
848
|
-
* Send a batch of requests to peers, and return the responses
|
|
849
|
-
* @param protocol - The request response protocol to use
|
|
850
|
-
* @param requests - The requests to send to the peers
|
|
851
|
-
* @returns The responses to the requests
|
|
852
|
-
*/ sendBatchRequest(protocol, requests, pinnedPeerId) {
|
|
853
|
-
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
854
|
-
}
|
|
855
918
|
sendRequestToPeer(peerId, subProtocol, payload, dialTimeout) {
|
|
856
919
|
return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
|
|
857
920
|
}
|
|
@@ -864,8 +927,11 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
864
927
|
registerBlockReceivedCallback(callback) {
|
|
865
928
|
this.blockReceivedCallback = callback;
|
|
866
929
|
}
|
|
867
|
-
|
|
868
|
-
this.
|
|
930
|
+
registerValidatorCheckpointReceivedCallback(callback) {
|
|
931
|
+
this.validatorCheckpointReceivedCallback = callback;
|
|
932
|
+
}
|
|
933
|
+
registerAllNodesCheckpointReceivedCallback(callback) {
|
|
934
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
869
935
|
}
|
|
870
936
|
/**
|
|
871
937
|
* Registers a callback to be invoked when a duplicate proposal is detected.
|
|
@@ -874,6 +940,21 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
874
940
|
this.duplicateProposalCallback = callback;
|
|
875
941
|
}
|
|
876
942
|
/**
|
|
943
|
+
* Registers a callback to be invoked when an oversized block proposal is stored as slashing evidence.
|
|
944
|
+
*/ registerOversizedProposalCallback(callback) {
|
|
945
|
+
this.oversizedProposalCallback = callback;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Registers a callback to be invoked when a duplicate attestation is detected.
|
|
949
|
+
* A validator signing attestations for different proposals at the same slot.
|
|
950
|
+
* This callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
951
|
+
*/ registerDuplicateAttestationCallback(callback) {
|
|
952
|
+
this.duplicateAttestationCallback = callback;
|
|
953
|
+
}
|
|
954
|
+
registerCheckpointAttestationCallback(callback) {
|
|
955
|
+
this.checkpointAttestationCallback = callback;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
877
958
|
* Subscribes to a topic.
|
|
878
959
|
* @param topic - The topic to subscribe to.
|
|
879
960
|
*/ subscribeToTopic(topic) {
|
|
@@ -924,6 +1005,12 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
924
1005
|
if (!validator || !validator.addMessage(msgId)) {
|
|
925
1006
|
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
926
1007
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
1008
|
+
if (topicType === TopicType.tx) {
|
|
1009
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, {
|
|
1010
|
+
msgId,
|
|
1011
|
+
source: source.toString()
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
927
1014
|
return {
|
|
928
1015
|
result: false,
|
|
929
1016
|
topicType
|
|
@@ -981,12 +1068,17 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
981
1068
|
}
|
|
982
1069
|
// Process the message, optionally within a linked span for trace propagation
|
|
983
1070
|
const processMessage = async ()=>{
|
|
1071
|
+
if (this.config.skipIncomingProposals && (msg.topic === this.topicStrings[TopicType.block_proposal] || msg.topic === this.topicStrings[TopicType.checkpoint_proposal])) {
|
|
1072
|
+
this.logger.warn(`Ignoring incoming proposal (skipIncomingProposals is set)`, {
|
|
1073
|
+
topic: msg.topic
|
|
1074
|
+
});
|
|
1075
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
984
1078
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
985
1079
|
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
986
1080
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
987
|
-
|
|
988
|
-
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
989
|
-
}
|
|
1081
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
990
1082
|
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
991
1083
|
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
992
1084
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
@@ -1030,77 +1122,215 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1030
1122
|
}
|
|
1031
1123
|
return;
|
|
1032
1124
|
}
|
|
1033
|
-
async validateReceivedMessage(validationFunc, msgId, source, topicType) {
|
|
1125
|
+
async validateReceivedMessage(validationFunc, msgId, source, topicType, stageTimings) {
|
|
1126
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
1034
1127
|
let resultAndObj = {
|
|
1035
|
-
result: TopicValidatorResult.Reject
|
|
1128
|
+
result: TopicValidatorResult.Reject,
|
|
1129
|
+
severity: PeerErrorSeverity.MidToleranceError
|
|
1036
1130
|
};
|
|
1037
1131
|
const timer = new Timer();
|
|
1038
1132
|
try {
|
|
1039
1133
|
resultAndObj = await validationFunc();
|
|
1040
1134
|
} catch (err) {
|
|
1041
|
-
this.
|
|
1042
|
-
this.logger.error(`Error deserializing and validating gossipsub message`, err, {
|
|
1135
|
+
this.logger.error(`Error validating gossipsub message`, err, {
|
|
1043
1136
|
msgId,
|
|
1044
1137
|
source: source.toString(),
|
|
1045
1138
|
topicType
|
|
1046
1139
|
});
|
|
1047
1140
|
}
|
|
1141
|
+
const validationTimeMs = timer.ms();
|
|
1142
|
+
const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
|
|
1143
|
+
if (validationTimeMs > mcacheWindowMs * 0.75) {
|
|
1144
|
+
this.instrumentation.incSlowValidation(topicType);
|
|
1145
|
+
this.logger.warn(`Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` + `Message forwarding may be skipped if validation exceeds the window.`, {
|
|
1146
|
+
msgId,
|
|
1147
|
+
source: source.toString(),
|
|
1148
|
+
topicType,
|
|
1149
|
+
validationTimeMs,
|
|
1150
|
+
mcacheWindowMs,
|
|
1151
|
+
stageTimings
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1048
1154
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
1155
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, {
|
|
1156
|
+
msgId,
|
|
1157
|
+
source: source.toString(),
|
|
1158
|
+
topicType,
|
|
1159
|
+
validationTimeMs,
|
|
1160
|
+
stageTimings
|
|
1161
|
+
});
|
|
1049
1162
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
1163
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
1164
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
1165
|
+
msgId,
|
|
1166
|
+
source: source.toString(),
|
|
1167
|
+
topicType,
|
|
1168
|
+
severity: resultAndObj.severity
|
|
1169
|
+
});
|
|
1170
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
1171
|
+
} else {
|
|
1172
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, {
|
|
1173
|
+
msgId,
|
|
1174
|
+
source: source.toString(),
|
|
1175
|
+
topicType
|
|
1176
|
+
});
|
|
1050
1177
|
}
|
|
1051
1178
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
1052
1179
|
return resultAndObj;
|
|
1053
1180
|
}
|
|
1181
|
+
tryDeserialize(deserializeFunc, msgId, source) {
|
|
1182
|
+
try {
|
|
1183
|
+
return deserializeFunc();
|
|
1184
|
+
} catch (err) {
|
|
1185
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
1186
|
+
err,
|
|
1187
|
+
msgId,
|
|
1188
|
+
source: source.toString()
|
|
1189
|
+
});
|
|
1190
|
+
return undefined;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1054
1193
|
async handleGossipedTx(payloadData, msgId, source) {
|
|
1194
|
+
// Per-stage timings so slow validations can be attributed to a specific stage (see A-1656).
|
|
1195
|
+
const stageTimings = {};
|
|
1196
|
+
const timed = async (stage, fn)=>{
|
|
1197
|
+
const timer = new Timer();
|
|
1198
|
+
try {
|
|
1199
|
+
return await fn();
|
|
1200
|
+
} finally{
|
|
1201
|
+
const ms = timer.ms();
|
|
1202
|
+
stageTimings[stage] = Math.ceil(ms);
|
|
1203
|
+
this.instrumentation.recordTxValidationStage(stage, ms);
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1055
1206
|
const validationFunc = async ()=>{
|
|
1056
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1207
|
+
const tx = await timed('deserialize', ()=>this.tryDeserialize(()=>Tx.fromBuffer(payloadData), msgId, source));
|
|
1208
|
+
if (!tx) {
|
|
1209
|
+
return {
|
|
1210
|
+
result: TopicValidatorResult.Reject,
|
|
1211
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
// Stage 1 setup: chain tip, epoch info, gas fees, and L1 constants reads
|
|
1215
|
+
const { currentBlockNumber, firstStageValidators } = await timed('fast_validation_setup', async ()=>{
|
|
1216
|
+
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1217
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1218
|
+
const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1219
|
+
return {
|
|
1220
|
+
currentBlockNumber,
|
|
1221
|
+
firstStageValidators
|
|
1222
|
+
};
|
|
1063
1223
|
});
|
|
1064
|
-
|
|
1224
|
+
// Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
|
|
1225
|
+
const firstStageOutcome = await timed('fast_validation', ()=>this.runValidations(tx, firstStageValidators));
|
|
1226
|
+
if (!firstStageOutcome.allPassed) {
|
|
1227
|
+
const { name } = firstStageOutcome.failure;
|
|
1228
|
+
let { severity } = firstStageOutcome.failure;
|
|
1229
|
+
// Double spend validator has a special case handler. We perform more detailed examination
|
|
1230
|
+
// as to how recently the nullifier was entered into the tree and if the transaction should
|
|
1231
|
+
// have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
|
|
1232
|
+
if (name === 'doubleSpendValidator') {
|
|
1233
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1234
|
+
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1235
|
+
}
|
|
1236
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
1237
|
+
validator: name,
|
|
1238
|
+
severity,
|
|
1239
|
+
source: source.toString()
|
|
1240
|
+
});
|
|
1065
1241
|
return {
|
|
1066
|
-
result: TopicValidatorResult.Reject
|
|
1242
|
+
result: TopicValidatorResult.Reject,
|
|
1243
|
+
severity
|
|
1067
1244
|
};
|
|
1068
|
-
}
|
|
1245
|
+
}
|
|
1246
|
+
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
1247
|
+
const canAdd = await timed('pool_precheck', ()=>this.mempools.txPool.canAddPendingTx(tx));
|
|
1248
|
+
if (canAdd === 'ignored') {
|
|
1249
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
1250
|
+
source: source.toString()
|
|
1251
|
+
});
|
|
1069
1252
|
return {
|
|
1070
1253
|
result: TopicValidatorResult.Ignore,
|
|
1071
1254
|
obj: tx
|
|
1072
1255
|
};
|
|
1073
|
-
}
|
|
1256
|
+
}
|
|
1257
|
+
// Stage 2: expensive proof verification
|
|
1258
|
+
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
1259
|
+
const secondStageOutcome = await timed('proof_verify', ()=>this.runValidations(tx, secondStageValidators));
|
|
1260
|
+
if (!secondStageOutcome.allPassed) {
|
|
1261
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
1262
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1263
|
+
validator: name,
|
|
1264
|
+
severity,
|
|
1265
|
+
source: source.toString()
|
|
1266
|
+
});
|
|
1267
|
+
return {
|
|
1268
|
+
result: TopicValidatorResult.Reject,
|
|
1269
|
+
severity
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
// Pool add: persist the tx
|
|
1273
|
+
const txHash = tx.getTxHash();
|
|
1274
|
+
const addResult = await timed('pool_add', ()=>this.mempools.txPool.addPendingTxs([
|
|
1275
|
+
tx
|
|
1276
|
+
], {
|
|
1277
|
+
source: 'gossip'
|
|
1278
|
+
}));
|
|
1279
|
+
const wasAccepted = addResult.accepted.some((h)=>h.equals(txHash));
|
|
1280
|
+
const wasIgnored = addResult.ignored.some((h)=>h.equals(txHash));
|
|
1281
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
1282
|
+
wasAccepted,
|
|
1283
|
+
wasIgnored,
|
|
1284
|
+
[Attributes.P2P_ID]: source.toString()
|
|
1285
|
+
});
|
|
1286
|
+
if (wasAccepted) {
|
|
1074
1287
|
return {
|
|
1075
1288
|
result: TopicValidatorResult.Accept,
|
|
1076
1289
|
obj: tx
|
|
1077
1290
|
};
|
|
1291
|
+
} else if (wasIgnored) {
|
|
1292
|
+
return {
|
|
1293
|
+
result: TopicValidatorResult.Ignore,
|
|
1294
|
+
obj: tx
|
|
1295
|
+
};
|
|
1296
|
+
} else {
|
|
1297
|
+
this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
|
|
1298
|
+
source: source.toString(),
|
|
1299
|
+
txHash: txHash.toString()
|
|
1300
|
+
});
|
|
1301
|
+
return {
|
|
1302
|
+
result: TopicValidatorResult.Reject,
|
|
1303
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1304
|
+
};
|
|
1078
1305
|
}
|
|
1079
1306
|
};
|
|
1080
|
-
const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.tx);
|
|
1307
|
+
const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.tx, stageTimings);
|
|
1081
1308
|
if (result !== TopicValidatorResult.Accept || !tx) {
|
|
1082
1309
|
return;
|
|
1083
1310
|
}
|
|
1311
|
+
// Tx was accepted into pool and will be propagated - just log and record metrics
|
|
1084
1312
|
const txHash = tx.getTxHash();
|
|
1085
1313
|
const txHashString = txHash.toString();
|
|
1086
1314
|
this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()} via gossip`, {
|
|
1087
1315
|
source: source.toString(),
|
|
1088
1316
|
txHash: txHashString
|
|
1089
1317
|
});
|
|
1090
|
-
if (this.config.dropTransactions && randomInt(1000) < this.config.dropTransactionsProbability * 1000) {
|
|
1091
|
-
this.logger.warn(`Intentionally dropping tx ${txHashString} (probability rule)`);
|
|
1092
|
-
return;
|
|
1093
|
-
}
|
|
1094
1318
|
this.instrumentation.incrementTxReceived(1);
|
|
1095
|
-
await this.mempools.txPool.addTxs([
|
|
1096
|
-
tx
|
|
1097
|
-
]);
|
|
1098
1319
|
}
|
|
1099
1320
|
/**
|
|
1100
1321
|
* Process a checkpoint attestation from a peer.
|
|
1101
1322
|
* Validates the attestation and adds it to the pool.
|
|
1102
1323
|
*/ async processCheckpointAttestationFromPeer(payloadData, msgId, source) {
|
|
1103
|
-
const { result, obj: attestation } = await this.validateReceivedMessage(()=>
|
|
1324
|
+
const { result, obj: attestation } = await this.validateReceivedMessage(()=>{
|
|
1325
|
+
const attestation = this.tryDeserialize(()=>CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1326
|
+
if (!attestation) {
|
|
1327
|
+
return Promise.resolve({
|
|
1328
|
+
result: TopicValidatorResult.Reject,
|
|
1329
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1333
|
+
}, msgId, source, TopicType.checkpoint_attestation);
|
|
1104
1334
|
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
1105
1335
|
return;
|
|
1106
1336
|
}
|
|
@@ -1115,9 +1345,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1115
1345
|
const validationResult = await this.checkpointAttestationValidator.validate(attestation);
|
|
1116
1346
|
if (validationResult.result === 'reject') {
|
|
1117
1347
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1118
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1119
1348
|
return {
|
|
1120
|
-
result: TopicValidatorResult.Reject
|
|
1349
|
+
result: TopicValidatorResult.Reject,
|
|
1350
|
+
severity: validationResult.severity
|
|
1121
1351
|
};
|
|
1122
1352
|
}
|
|
1123
1353
|
if (validationResult.result === 'ignore') {
|
|
@@ -1126,58 +1356,78 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1126
1356
|
obj: attestation
|
|
1127
1357
|
};
|
|
1128
1358
|
}
|
|
1129
|
-
// Get committee size for the attestation's slot
|
|
1130
|
-
const slot = attestation.payload.header.slotNumber;
|
|
1131
|
-
const { committee } = await this.epochCache.getCommittee(slot);
|
|
1132
|
-
const committeeSize = committee?.length ?? 0;
|
|
1133
1359
|
// Try to add the attestation: this handles existence check, cap check, and adding in one call
|
|
1134
|
-
|
|
1360
|
+
// count is the number of attestations by this signer for this slot (for duplicate detection)
|
|
1361
|
+
const slot = attestation.payload.header.slotNumber;
|
|
1362
|
+
const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddCheckpointAttestation(attestation);
|
|
1135
1363
|
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
1136
1364
|
added,
|
|
1137
1365
|
alreadyExists,
|
|
1366
|
+
count,
|
|
1138
1367
|
[Attributes.SLOT_NUMBER]: slot.toString(),
|
|
1139
1368
|
[Attributes.P2P_ID]: peerId.toString()
|
|
1140
1369
|
});
|
|
1141
|
-
//
|
|
1370
|
+
// Exact same attestation received, no need to re-broadcast
|
|
1142
1371
|
if (alreadyExists) {
|
|
1143
1372
|
return {
|
|
1144
1373
|
result: TopicValidatorResult.Ignore,
|
|
1145
1374
|
obj: attestation
|
|
1146
1375
|
};
|
|
1147
1376
|
}
|
|
1148
|
-
// Could not add (cap reached),
|
|
1377
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1149
1378
|
if (!added) {
|
|
1150
|
-
this.logger.warn(`
|
|
1379
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1151
1380
|
slot: slot.toString(),
|
|
1152
1381
|
archive: attestation.archive.toString(),
|
|
1153
|
-
source: peerId.toString()
|
|
1382
|
+
source: peerId.toString(),
|
|
1383
|
+
attester: attestation.getSender()?.toString(),
|
|
1384
|
+
count
|
|
1154
1385
|
});
|
|
1155
1386
|
return {
|
|
1156
|
-
result: TopicValidatorResult.
|
|
1157
|
-
|
|
1387
|
+
result: TopicValidatorResult.Reject,
|
|
1388
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1158
1389
|
};
|
|
1159
1390
|
}
|
|
1160
|
-
//
|
|
1391
|
+
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
1392
|
+
// count is the number of attestations by this signer for this slot
|
|
1393
|
+
if (count === 2) {
|
|
1394
|
+
const attester = attestation.getSender();
|
|
1395
|
+
if (attester) {
|
|
1396
|
+
this.logger.warn(`Detected duplicate attestation (equivocation) at slot ${slot}`, {
|
|
1397
|
+
slot: slot.toString(),
|
|
1398
|
+
archive: attestation.archive.toString(),
|
|
1399
|
+
source: peerId.toString(),
|
|
1400
|
+
attester: attester.toString()
|
|
1401
|
+
});
|
|
1402
|
+
this.duplicateAttestationCallback?.({
|
|
1403
|
+
slot,
|
|
1404
|
+
attester
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
// Attestation was added successfully - accept it so other nodes can also detect the equivocation
|
|
1409
|
+
this.checkpointAttestationCallback?.(attestation);
|
|
1161
1410
|
return {
|
|
1162
1411
|
result: TopicValidatorResult.Accept,
|
|
1163
1412
|
obj: attestation
|
|
1164
1413
|
};
|
|
1165
1414
|
}
|
|
1166
1415
|
async processBlockFromPeer(payloadData, msgId, source) {
|
|
1167
|
-
const { result, obj: block, metadata: { isEquivocated } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
|
|
1168
|
-
// If not accepted or
|
|
1169
|
-
|
|
1416
|
+
const { result, obj: block, metadata: { isEquivocated, isOversized } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
|
|
1417
|
+
// If not accepted, equivocated, or oversized, return. Oversized proposals are re-broadcast as
|
|
1418
|
+
// slashing evidence but never attested or processed.
|
|
1419
|
+
if (result !== TopicValidatorResult.Accept || !block || isEquivocated || isOversized) {
|
|
1170
1420
|
return;
|
|
1171
1421
|
}
|
|
1172
|
-
await this.processValidBlockProposal(block, source);
|
|
1422
|
+
await this.processValidBlockProposal(ValidatedBlockProposal(block), source);
|
|
1173
1423
|
}
|
|
1174
1424
|
/** Validates a block proposal. Triggers a penalization to the peer that sent it if invalid. Adds to the mempool if valid. */ async validateAndStoreBlockProposal(peerId, block) {
|
|
1175
1425
|
const validationResult = await this.blockProposalValidator.validate(block);
|
|
1176
1426
|
if (validationResult.result === 'reject') {
|
|
1177
1427
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1178
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1179
1428
|
return {
|
|
1180
|
-
result: TopicValidatorResult.Reject
|
|
1429
|
+
result: TopicValidatorResult.Reject,
|
|
1430
|
+
severity: validationResult.severity
|
|
1181
1431
|
};
|
|
1182
1432
|
}
|
|
1183
1433
|
if (validationResult.result === 'ignore') {
|
|
@@ -1187,8 +1437,12 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1187
1437
|
};
|
|
1188
1438
|
}
|
|
1189
1439
|
// Try to add the proposal: this handles existence check, cap check, and adding in one call
|
|
1190
|
-
const { added, alreadyExists,
|
|
1191
|
-
const isEquivocated =
|
|
1440
|
+
const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
|
|
1441
|
+
const isEquivocated = count !== undefined && count > 1;
|
|
1442
|
+
// An oversized proposal (index at or beyond the consensus per-checkpoint limit) is structurally valid
|
|
1443
|
+
// proposer misbehavior: it is stored and re-broadcast as slashing evidence but never processed or
|
|
1444
|
+
// attested to. No-ops when maxBlocksPerCheckpoint is unset (local/test).
|
|
1445
|
+
const isOversized = this.config.maxBlocksPerCheckpoint !== undefined && block.indexWithinCheckpoint >= this.config.maxBlocksPerCheckpoint;
|
|
1192
1446
|
// Duplicate proposal received, no need to re-broadcast
|
|
1193
1447
|
if (alreadyExists) {
|
|
1194
1448
|
this.logger.debug(`Ignoring duplicate block proposal received`, {
|
|
@@ -1201,27 +1455,47 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1201
1455
|
result: TopicValidatorResult.Ignore,
|
|
1202
1456
|
obj: block,
|
|
1203
1457
|
metadata: {
|
|
1204
|
-
isEquivocated
|
|
1458
|
+
isEquivocated,
|
|
1459
|
+
isOversized
|
|
1205
1460
|
}
|
|
1206
1461
|
};
|
|
1207
1462
|
}
|
|
1208
1463
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1209
1464
|
if (!added) {
|
|
1210
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1211
1465
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1212
1466
|
...block.toBlockInfo(),
|
|
1213
1467
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1214
|
-
|
|
1468
|
+
count,
|
|
1215
1469
|
proposer: block.getSender()?.toString(),
|
|
1216
1470
|
source: peerId.toString()
|
|
1217
1471
|
});
|
|
1218
1472
|
return {
|
|
1219
1473
|
result: TopicValidatorResult.Reject,
|
|
1220
1474
|
metadata: {
|
|
1221
|
-
isEquivocated
|
|
1222
|
-
|
|
1475
|
+
isEquivocated,
|
|
1476
|
+
isOversized
|
|
1477
|
+
},
|
|
1478
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1223
1479
|
};
|
|
1224
1480
|
}
|
|
1481
|
+
// The proposal was stored: if oversized, invoke the oversized callback so the proposer can be
|
|
1482
|
+
// slashed. Fired alongside (not instead of) equivocation detection below.
|
|
1483
|
+
if (isOversized) {
|
|
1484
|
+
const proposer = block.getSender();
|
|
1485
|
+
if (proposer) {
|
|
1486
|
+
this.logger.warn(`Detected oversized block proposal at slot ${block.slotNumber}`, {
|
|
1487
|
+
...block.toBlockInfo(),
|
|
1488
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1489
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint,
|
|
1490
|
+
source: peerId.toString(),
|
|
1491
|
+
proposer: proposer.toString()
|
|
1492
|
+
});
|
|
1493
|
+
this.oversizedProposalCallback?.({
|
|
1494
|
+
slot: block.slotNumber,
|
|
1495
|
+
proposer
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1225
1499
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1226
1500
|
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1227
1501
|
if (isEquivocated) {
|
|
@@ -1232,7 +1506,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1232
1506
|
proposer: proposer?.toString()
|
|
1233
1507
|
});
|
|
1234
1508
|
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1235
|
-
if (proposer &&
|
|
1509
|
+
if (proposer && count === 2) {
|
|
1236
1510
|
this.duplicateProposalCallback?.({
|
|
1237
1511
|
slot: block.slotNumber,
|
|
1238
1512
|
proposer,
|
|
@@ -1243,14 +1517,19 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1243
1517
|
result: TopicValidatorResult.Accept,
|
|
1244
1518
|
obj: block,
|
|
1245
1519
|
metadata: {
|
|
1246
|
-
isEquivocated
|
|
1520
|
+
isEquivocated,
|
|
1521
|
+
isOversized
|
|
1247
1522
|
}
|
|
1248
1523
|
};
|
|
1249
1524
|
}
|
|
1250
1525
|
// Otherwise, we're good to go!
|
|
1251
1526
|
return {
|
|
1252
1527
|
result: TopicValidatorResult.Accept,
|
|
1253
|
-
obj: block
|
|
1528
|
+
obj: block,
|
|
1529
|
+
metadata: {
|
|
1530
|
+
isEquivocated: false,
|
|
1531
|
+
isOversized
|
|
1532
|
+
}
|
|
1254
1533
|
};
|
|
1255
1534
|
}
|
|
1256
1535
|
// REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
|
|
@@ -1262,29 +1541,55 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1262
1541
|
source: sender.toString(),
|
|
1263
1542
|
...block.toBlockInfo()
|
|
1264
1543
|
});
|
|
1265
|
-
// Mark the txs in this proposal as
|
|
1266
|
-
await this.mempools.txPool.
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1544
|
+
// Mark the txs in this proposal as protected
|
|
1545
|
+
await this.mempools.txPool.protectTxs(block.txHashes, block.blockHeader);
|
|
1546
|
+
if (!await this.tryBlockReceivedCallback(block, sender)) {
|
|
1547
|
+
// Release the protections this proposal created so its txs return to pending. Only entries still
|
|
1548
|
+
// keyed to this slot are cleared, so a tx referenced by a live proposal at another slot stays protected.
|
|
1549
|
+
await this.mempools.txPool.unprotectTxs(block.txHashes, slot);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Runs the block received callback to validate a proposal, and returns whether it was accepted.
|
|
1554
|
+
* A callback that throws is reported as a rejection: the proposal is no more usable than one explicitly
|
|
1555
|
+
* rejected, and letting the error escape would leave the proposal's tx protections in place.
|
|
1556
|
+
* Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1557
|
+
*/ async tryBlockReceivedCallback(block, sender) {
|
|
1558
|
+
try {
|
|
1559
|
+
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1560
|
+
if (!isValid) {
|
|
1561
|
+
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1562
|
+
}
|
|
1563
|
+
return isValid;
|
|
1564
|
+
} catch (err) {
|
|
1565
|
+
this.logger.error(`Error validating block proposal for block ${block.blockNumber}`, err, block.toBlockInfo());
|
|
1566
|
+
return false;
|
|
1272
1567
|
}
|
|
1273
1568
|
}
|
|
1274
1569
|
/**
|
|
1275
1570
|
* Handle a gossiped checkpoint proposal.
|
|
1276
1571
|
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1277
1572
|
*/ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
|
|
1278
|
-
const { result, obj: checkpoint, metadata: { isEquivocated, processBlock } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
|
|
1573
|
+
const { result, obj: checkpoint, metadata: { isEquivocated, processBlock, isOversized } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
|
|
1574
|
+
// An oversized checkpoint is re-broadcast as slashing evidence but never attested or processed.
|
|
1575
|
+
// Process checkpoint proposal if valid and neither equivocated nor oversized.
|
|
1576
|
+
const processCheckpointFn = ()=>result === TopicValidatorResult.Accept && checkpoint && !isEquivocated && !isOversized ? this.processValidCheckpointProposal(ValidatedCheckpointProposalCore(checkpoint.toCore()), source) : Promise.resolve();
|
|
1279
1577
|
// If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
|
|
1280
1578
|
// TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1579
|
+
const processBlockFn = ()=>processBlock && checkpoint && checkpoint.getBlockProposal() ? this.processValidBlockProposal(ValidatedBlockProposal(checkpoint.getBlockProposal()), source) : Promise.resolve();
|
|
1580
|
+
// A node that skips checkpoint validation attests without re-executing the embedded last block, so run
|
|
1581
|
+
// the checkpoint callback first: this creates and broadcasts the attestation before the block is
|
|
1582
|
+
// processed. Otherwise the block's re-execution — which can stall until the re-execution deadline
|
|
1583
|
+
// waiting for a parent that may never arrive — would delay the attestation past the slot's attestation
|
|
1584
|
+
// window, after which peers reject it as stale.
|
|
1585
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
1586
|
+
await processCheckpointFn();
|
|
1587
|
+
await processBlockFn();
|
|
1285
1588
|
return;
|
|
1286
1589
|
}
|
|
1287
|
-
|
|
1590
|
+
// Process the block first, since it's required for the checkpoint proposal validation.
|
|
1591
|
+
await processBlockFn();
|
|
1592
|
+
await processCheckpointFn();
|
|
1288
1593
|
}
|
|
1289
1594
|
/**
|
|
1290
1595
|
* Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
|
|
@@ -1293,9 +1598,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1293
1598
|
const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1294
1599
|
if (validationResult.result === 'reject') {
|
|
1295
1600
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1296
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1297
1601
|
return {
|
|
1298
|
-
result: TopicValidatorResult.Reject
|
|
1602
|
+
result: TopicValidatorResult.Reject,
|
|
1603
|
+
severity: validationResult.severity
|
|
1299
1604
|
};
|
|
1300
1605
|
}
|
|
1301
1606
|
if (validationResult.result === 'ignore') {
|
|
@@ -1307,31 +1612,36 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1307
1612
|
// Extract and try to add the block proposal first if present
|
|
1308
1613
|
const blockProposal = checkpoint.getBlockProposal();
|
|
1309
1614
|
let processBlock = false;
|
|
1615
|
+
let isOversized = false;
|
|
1310
1616
|
if (blockProposal) {
|
|
1311
1617
|
this.logger.debug(`Validating block proposal from propagated checkpoint`, {
|
|
1312
1618
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1313
1619
|
[Attributes.P2P_ID]: peerId.toString()
|
|
1314
1620
|
});
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1621
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1622
|
+
const { obj, metadata: { isEquivocated, isOversized: blockIsOversized } = {} } = blockProposalResult;
|
|
1623
|
+
isOversized = blockIsOversized ?? false;
|
|
1624
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1317
1625
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1318
1626
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1319
1627
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1320
1628
|
isEquivocated,
|
|
1321
|
-
result
|
|
1629
|
+
result: blockProposalResult.result
|
|
1322
1630
|
});
|
|
1323
1631
|
return {
|
|
1324
|
-
result: TopicValidatorResult.Reject
|
|
1632
|
+
result: TopicValidatorResult.Reject,
|
|
1633
|
+
severity: 'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError
|
|
1325
1634
|
};
|
|
1326
|
-
} else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1635
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated && !isOversized) {
|
|
1636
|
+
// An oversized terminal block is re-broadcast as slashing evidence but never processed.
|
|
1327
1637
|
processBlock = true;
|
|
1328
1638
|
}
|
|
1329
1639
|
}
|
|
1330
1640
|
// Try to add the checkpoint proposal core: this handles existence check, cap check, and adding in one call
|
|
1331
1641
|
const checkpointCore = checkpoint.toCore();
|
|
1332
1642
|
const tryAddResult = await this.mempools.attestationPool.tryAddCheckpointProposal(checkpointCore);
|
|
1333
|
-
const { added, alreadyExists,
|
|
1334
|
-
const isEquivocated =
|
|
1643
|
+
const { added, alreadyExists, count } = tryAddResult;
|
|
1644
|
+
const isEquivocated = count !== undefined && count > 1;
|
|
1335
1645
|
// Duplicate proposal received, do not re-broadcast
|
|
1336
1646
|
if (alreadyExists) {
|
|
1337
1647
|
this.logger.debug(`Ignoring duplicate checkpoint proposal received`, {
|
|
@@ -1343,17 +1653,17 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1343
1653
|
obj: checkpoint,
|
|
1344
1654
|
metadata: {
|
|
1345
1655
|
isEquivocated,
|
|
1346
|
-
processBlock
|
|
1656
|
+
processBlock,
|
|
1657
|
+
isOversized
|
|
1347
1658
|
}
|
|
1348
1659
|
};
|
|
1349
1660
|
}
|
|
1350
|
-
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1661
|
+
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast.
|
|
1351
1662
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1352
1663
|
if (!added) {
|
|
1353
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1354
1664
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1355
1665
|
...checkpoint.toCheckpointInfo(),
|
|
1356
|
-
|
|
1666
|
+
count,
|
|
1357
1667
|
source: peerId.toString()
|
|
1358
1668
|
});
|
|
1359
1669
|
return {
|
|
@@ -1361,8 +1671,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1361
1671
|
obj: checkpoint,
|
|
1362
1672
|
metadata: {
|
|
1363
1673
|
isEquivocated,
|
|
1364
|
-
processBlock
|
|
1365
|
-
|
|
1674
|
+
processBlock,
|
|
1675
|
+
isOversized
|
|
1676
|
+
},
|
|
1677
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1366
1678
|
};
|
|
1367
1679
|
}
|
|
1368
1680
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1375,7 +1687,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1375
1687
|
proposer: proposer?.toString()
|
|
1376
1688
|
});
|
|
1377
1689
|
// Invoke the duplicate callback on the first duplicate spotted only
|
|
1378
|
-
if (proposer &&
|
|
1690
|
+
if (proposer && count === 2) {
|
|
1379
1691
|
this.duplicateProposalCallback?.({
|
|
1380
1692
|
slot: checkpoint.slotNumber,
|
|
1381
1693
|
proposer,
|
|
@@ -1387,7 +1699,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1387
1699
|
obj: checkpoint,
|
|
1388
1700
|
metadata: {
|
|
1389
1701
|
isEquivocated,
|
|
1390
|
-
processBlock
|
|
1702
|
+
processBlock,
|
|
1703
|
+
isOversized
|
|
1391
1704
|
}
|
|
1392
1705
|
};
|
|
1393
1706
|
}
|
|
@@ -1397,7 +1710,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1397
1710
|
obj: checkpoint,
|
|
1398
1711
|
metadata: {
|
|
1399
1712
|
processBlock,
|
|
1400
|
-
isEquivocated
|
|
1713
|
+
isEquivocated,
|
|
1714
|
+
isOversized
|
|
1401
1715
|
}
|
|
1402
1716
|
};
|
|
1403
1717
|
}
|
|
@@ -1412,9 +1726,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1412
1726
|
archive: checkpoint.archive.toString(),
|
|
1413
1727
|
source: sender.toString()
|
|
1414
1728
|
});
|
|
1729
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1415
1730
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1416
1731
|
// to validate and potentially generate attestations
|
|
1417
|
-
const attestations = await this.
|
|
1732
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1418
1733
|
if (attestations && attestations.length > 0) {
|
|
1419
1734
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1420
1735
|
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
@@ -1438,192 +1753,78 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1438
1753
|
});
|
|
1439
1754
|
}
|
|
1440
1755
|
/**
|
|
1441
|
-
* Validate the requested block transactions
|
|
1756
|
+
* Validate the requested block transactions request-response consistency.
|
|
1757
|
+
* It does NOT validate the transactions themselves.
|
|
1442
1758
|
* @param request - The block transactions request.
|
|
1443
1759
|
* @param response - The block transactions response.
|
|
1444
1760
|
* @param peerId - The ID of the peer that made the request.
|
|
1445
|
-
* @returns True if the
|
|
1446
|
-
*/ async
|
|
1447
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1761
|
+
* @returns True if the request-response is consistent, false otherwise.
|
|
1762
|
+
*/ async validateRequestedBlockTxsConsistency(request, response, peerId) {
|
|
1448
1763
|
try {
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
throw new ValidationError(`Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`);
|
|
1452
|
-
}
|
|
1453
|
-
if (response.txIndices.getLength() !== request.txIndices.getLength()) {
|
|
1454
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1455
|
-
throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`);
|
|
1456
|
-
}
|
|
1457
|
-
// Check no duplicates and not exceeding returnable count
|
|
1458
|
-
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
1459
|
-
const availableIndices = new Set(response.txIndices.getTrueIndices());
|
|
1460
|
-
const maxReturnable = [
|
|
1461
|
-
...requestedIndices
|
|
1462
|
-
].filter((i)=>availableIndices.has(i)).length;
|
|
1463
|
-
const returnedHashes = await Promise.all(response.txs.map((tx)=>tx.getTxHash().toString()));
|
|
1764
|
+
// Check for duplicates txs (or hashes) in the response.
|
|
1765
|
+
const returnedHashes = response.txs.map((tx)=>tx.getTxHash().toString());
|
|
1464
1766
|
const uniqueReturned = new Set(returnedHashes.map((h)=>h.toString()));
|
|
1465
1767
|
if (uniqueReturned.size !== returnedHashes.length) {
|
|
1466
1768
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1467
1769
|
throw new ValidationError(`Received duplicate txs in block txs response`);
|
|
1468
1770
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
if (
|
|
1476
|
-
//
|
|
1477
|
-
|
|
1478
|
-
//
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
i
|
|
1482
|
-
]));
|
|
1483
|
-
const allowedIndexSet = new Set(intersectIdx);
|
|
1484
|
-
const indices = returnedHashes.map((h)=>hashToIndexInProposal.get(h));
|
|
1485
|
-
const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
|
|
1486
|
-
const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
|
|
1487
|
-
if (!allAllowed || !strictlyIncreasing) {
|
|
1488
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1489
|
-
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
1490
|
-
}
|
|
1491
|
-
} else {
|
|
1492
|
-
// No local proposal, cannot check the membership/order of the returned txs
|
|
1493
|
-
this.logger.warn(`Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`);
|
|
1771
|
+
// We get the block tx hashes from the proposal or the archiver.
|
|
1772
|
+
const proposal = await this.mempools.attestationPool.getBlockProposalByArchive(request.archiveRoot.toString());
|
|
1773
|
+
const blockTxHashes = proposal?.txHashes ?? (await this.archiver.getBlock({
|
|
1774
|
+
archive: request.archiveRoot
|
|
1775
|
+
}))?.body.txEffects.map((e)=>e.txHash);
|
|
1776
|
+
// If we don't have the block, we can't verify membership/order of the returned txs.
|
|
1777
|
+
if (!blockTxHashes) {
|
|
1778
|
+
// This shouldn't happen, since we asked for the block (proposal).
|
|
1779
|
+
// Neither a local proposal nor an archived block: we cannot verify membership/order of the
|
|
1780
|
+
// returned txs. This is a local-state gap, not a peer fault, so we do not penalize.
|
|
1781
|
+
this.logger.warn(`Block ${request.archiveRoot.toString()} not found in attestation pool or archiver; cannot validate membership/order of returned txs`);
|
|
1782
|
+
// NOTE: We mark the response as invalid, given the limitations of a true/false return value.
|
|
1494
1783
|
return false;
|
|
1495
1784
|
}
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
return false;
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* Validate a collection of txs that has been requested from a peer.
|
|
1509
|
-
*
|
|
1510
|
-
* The core component of this validator is that each tx hash MUST match the requested tx hash,
|
|
1511
|
-
* In order to perform this check, the tx proof must be verified.
|
|
1512
|
-
*
|
|
1513
|
-
* Note: This function is called from within `ReqResp.sendRequest` as part of the
|
|
1514
|
-
* ReqRespSubProtocol.TX subprotocol validation.
|
|
1515
|
-
*
|
|
1516
|
-
* @param requestedTxHash - The collection of the txs that was requested.
|
|
1517
|
-
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
1518
|
-
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1519
|
-
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
1520
|
-
*/ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
|
|
1521
|
-
const requested = new Set(requestedTxHash.map((h)=>h.toString()));
|
|
1522
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1523
|
-
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
1524
|
-
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1525
|
-
try {
|
|
1526
|
-
await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
1527
|
-
return true;
|
|
1528
|
-
} catch (e) {
|
|
1529
|
-
if (e instanceof ValidationError) {
|
|
1530
|
-
this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
|
|
1531
|
-
} else {
|
|
1532
|
-
this.logger.error(`Error during validation of requested txs`, e);
|
|
1533
|
-
}
|
|
1534
|
-
return false;
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
/**
|
|
1538
|
-
* Validates a BLOCK response.
|
|
1539
|
-
*
|
|
1540
|
-
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1541
|
-
* Penalizes on block number mismatch or hash mismatch.
|
|
1542
|
-
*
|
|
1543
|
-
* @param requestedBlockNumber - The requested block number.
|
|
1544
|
-
* @param responseBlock - The block returned by the peer.
|
|
1545
|
-
* @param peerId - The peer that returned the block.
|
|
1546
|
-
* @returns True if the response is valid, false otherwise.
|
|
1547
|
-
*/ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
|
|
1548
|
-
try {
|
|
1549
|
-
const reqNum = Number(requestedBlockNumber.toString());
|
|
1550
|
-
if (responseBlock.number !== reqNum) {
|
|
1785
|
+
// Verify that the returned tx hashes are a subset of (tx hashes by index) U (explicitly requested tx hashes).
|
|
1786
|
+
const uniqueRequestedHashes = new Set([
|
|
1787
|
+
// tx hashes requested by index.
|
|
1788
|
+
...request.txIndices.getTrueIndices().map((i)=>blockTxHashes[i].toString()),
|
|
1789
|
+
// explicitly requested tx hashes.
|
|
1790
|
+
...request.txHashes.map((h)=>h.toString())
|
|
1791
|
+
]);
|
|
1792
|
+
if (!returnedHashes.every((h)=>uniqueRequestedHashes.has(h))) {
|
|
1551
1793
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1552
|
-
|
|
1794
|
+
throw new ValidationError('Returned txs should be a subset of (tx hashes by index) U (explicitly requested tx hashes)');
|
|
1553
1795
|
}
|
|
1554
|
-
|
|
1555
|
-
if (!
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1559
|
-
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1560
|
-
return false;
|
|
1796
|
+
// Tx indices information is optional, but if present, we need to verify a few things.
|
|
1797
|
+
if (!response.peerHasBlock()) {
|
|
1798
|
+
this.logger.debug(`Peer ${peerId.toString()} signalled missing block`);
|
|
1799
|
+
return true;
|
|
1561
1800
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
responseBlock.hash()
|
|
1565
|
-
]);
|
|
1566
|
-
if (!localHash.equals(respHash)) {
|
|
1801
|
+
// If the response has a non-empty bitvector, it needs to be consistent with the number of txs in the block.
|
|
1802
|
+
if (response.txIndices.getLength() !== blockTxHashes.length) {
|
|
1567
1803
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1568
|
-
|
|
1804
|
+
throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${blockTxHashes.length}, got ${response.txIndices.getLength()}`);
|
|
1805
|
+
}
|
|
1806
|
+
// For every index we requested that the peer claims to have (per its bitvector), the
|
|
1807
|
+
// corresponding tx must be present in the response. A peer advertising availability but
|
|
1808
|
+
// withholding the tx is inconsistent.
|
|
1809
|
+
const returnedHashSet = new Set(returnedHashes);
|
|
1810
|
+
const expectedIndices = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
|
|
1811
|
+
const missingExpected = expectedIndices.some((i)=>!returnedHashSet.has(blockTxHashes[i].toString()));
|
|
1812
|
+
if (missingExpected) {
|
|
1813
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1814
|
+
throw new ValidationError('Peer advertised requested txs via indices but did not return them');
|
|
1569
1815
|
}
|
|
1570
1816
|
return true;
|
|
1571
1817
|
} catch (e) {
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
async validateRequestedTx(tx, peerId, txValidator, requested) {
|
|
1577
|
-
const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
|
|
1578
|
-
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1579
|
-
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1580
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
1581
|
-
}
|
|
1582
|
-
const { result } = await txValidator.validateTx(tx);
|
|
1583
|
-
if (result === 'invalid') {
|
|
1584
|
-
penalize(PeerErrorSeverity.LowToleranceError);
|
|
1585
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
createRequestedTxValidator() {
|
|
1589
|
-
return createTxReqRespValidator(this.proofVerifier, {
|
|
1590
|
-
l1ChainId: this.config.l1ChainId,
|
|
1591
|
-
rollupVersion: this.config.rollupVersion
|
|
1592
|
-
});
|
|
1593
|
-
}
|
|
1594
|
-
async validatePropagatedTx(tx, peerId) {
|
|
1595
|
-
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1596
|
-
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1597
|
-
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1598
|
-
const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1599
|
-
for (const validator of messageValidators){
|
|
1600
|
-
const outcome = await this.runValidations(tx, validator);
|
|
1601
|
-
if (outcome.allPassed) {
|
|
1602
|
-
continue;
|
|
1603
|
-
}
|
|
1604
|
-
const { name } = outcome.failure;
|
|
1605
|
-
let { severity } = outcome.failure;
|
|
1606
|
-
// Double spend validator has a special case handler
|
|
1607
|
-
if (name === 'doubleSpendValidator') {
|
|
1608
|
-
const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
|
|
1609
|
-
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1818
|
+
if (e instanceof ValidationError) {
|
|
1819
|
+
this.logger.warn(`Failed validation for requested block txs from peer ${peerId.toString()}`);
|
|
1820
|
+
} else {
|
|
1821
|
+
this.logger.error(`Error during validation of requested block txs`, e);
|
|
1610
1822
|
}
|
|
1611
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1612
1823
|
return false;
|
|
1613
1824
|
}
|
|
1614
|
-
return true;
|
|
1615
1825
|
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
return this.feesCache.gasFees;
|
|
1619
|
-
}
|
|
1620
|
-
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
1621
|
-
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
1622
|
-
this.feesCache = {
|
|
1623
|
-
blockNumber,
|
|
1624
|
-
gasFees
|
|
1625
|
-
};
|
|
1626
|
-
return gasFees;
|
|
1826
|
+
getGasFees() {
|
|
1827
|
+
return this.blockMinFeesProvider.getCurrentMinFees();
|
|
1627
1828
|
}
|
|
1628
1829
|
/**
|
|
1629
1830
|
* Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
|
|
@@ -1634,43 +1835,48 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1634
1835
|
txValidatorConfig: {
|
|
1635
1836
|
l1ChainId: this.config.l1ChainId,
|
|
1636
1837
|
rollupVersion: this.config.rollupVersion,
|
|
1637
|
-
proofVerifier: this.proofVerifier
|
|
1838
|
+
proofVerifier: this.proofVerifier,
|
|
1839
|
+
txValidationCache: this.txValidationCache
|
|
1638
1840
|
},
|
|
1639
|
-
peerScoring: this.peerManager
|
|
1841
|
+
peerScoring: this.peerManager,
|
|
1842
|
+
validateRequestedBlockTxsConsistency: this.validateRequestedBlockTxsConsistency.bind(this)
|
|
1640
1843
|
};
|
|
1641
1844
|
}
|
|
1642
|
-
async
|
|
1643
|
-
const
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
await Promise.all(txs.map(async (tx)=>{
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
});
|
|
1845
|
+
async validateTxsReceivedInBlockProposal(txs) {
|
|
1846
|
+
const validator = createTxValidatorForBlockProposalReceivedTxs(this.proofVerifier, {
|
|
1847
|
+
l1ChainId: this.config.l1ChainId,
|
|
1848
|
+
rollupVersion: this.config.rollupVersion
|
|
1849
|
+
}, this.logger.getBindings(), this.txValidationCache);
|
|
1850
|
+
const results = await Promise.all(txs.map(async (tx)=>({
|
|
1851
|
+
txHash: tx.getTxHash(),
|
|
1852
|
+
result: await validator.validateTx(tx)
|
|
1853
|
+
})));
|
|
1854
|
+
const invalidTxs = results.flatMap(({ txHash, result })=>result.result === 'invalid' ? [
|
|
1855
|
+
{
|
|
1856
|
+
txHash,
|
|
1857
|
+
reasons: result.reason
|
|
1656
1858
|
}
|
|
1657
|
-
|
|
1658
|
-
|
|
1859
|
+
] : []);
|
|
1860
|
+
if (invalidTxs.length > 0) {
|
|
1861
|
+
throw new InvalidBlockProposalTxsError(invalidTxs);
|
|
1862
|
+
}
|
|
1659
1863
|
}
|
|
1660
|
-
/**
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1864
|
+
/** Creates the first stage (fast) validators for gossiped transactions. */ async createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp) {
|
|
1865
|
+
const gasFees = await this.getGasFees();
|
|
1866
|
+
const allowedInSetup = [
|
|
1867
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1868
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1869
|
+
];
|
|
1870
|
+
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1871
|
+
const l1Constants = await this.archiver.getL1Constants();
|
|
1872
|
+
const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
|
|
1873
|
+
return createFirstStageTxValidationsForGossipedTransactions(nextSlotTimestamp, blockNumber, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, !this.config.disableTransactions, allowedInSetup, this.logger.getBindings(), {
|
|
1874
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
1875
|
+
maxTxDAGas: networkTxGasLimits.daGas
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
/** Creates the second stage (expensive proof verification) validators for gossiped transactions. */ createSecondStageMessageValidators() {
|
|
1879
|
+
return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
|
|
1674
1880
|
}
|
|
1675
1881
|
/**
|
|
1676
1882
|
* Run validations on a tx.
|
|
@@ -1688,8 +1894,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1688
1894
|
});
|
|
1689
1895
|
// A promise that resolves when all validations have been run
|
|
1690
1896
|
const allValidations = await Promise.all(validationPromises);
|
|
1691
|
-
const
|
|
1692
|
-
if (
|
|
1897
|
+
const failures = allValidations.filter((x)=>!x.isValid);
|
|
1898
|
+
if (failures.length > 0) {
|
|
1899
|
+
// Pick the most severe failure (lowest tolerance = harshest penalty)
|
|
1900
|
+
const failed = maxBy(failures, (f)=>PeerErrorSeverityByHarshness.indexOf(f.severity));
|
|
1693
1901
|
return {
|
|
1694
1902
|
allPassed: false,
|
|
1695
1903
|
failure: {
|
|
@@ -1736,19 +1944,6 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1736
1944
|
}
|
|
1737
1945
|
return PeerErrorSeverity.HighToleranceError;
|
|
1738
1946
|
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Validate a checkpoint attestation.
|
|
1741
|
-
*
|
|
1742
|
-
* @param attestation - The checkpoint attestation to validate.
|
|
1743
|
-
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1744
|
-
*/ async validateCheckpointAttestation(peerId, attestation) {
|
|
1745
|
-
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1746
|
-
if (result.result === 'reject') {
|
|
1747
|
-
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1748
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1749
|
-
}
|
|
1750
|
-
return result;
|
|
1751
|
-
}
|
|
1752
1947
|
getPeerScore(peerId) {
|
|
1753
1948
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1754
1949
|
}
|