@aztec/p2p 0.0.1-commit.7b97ef96e → 0.0.1-commit.7cbc774
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -3
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +9 -1
- package/dest/client/factory.d.ts +7 -7
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +39 -32
- package/dest/client/interface.d.ts +19 -17
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +16 -20
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +94 -105
- package/dest/config.d.ts +154 -106
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +134 -40
- 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 +1 -20
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +0 -21
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +99 -59
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +267 -197
- 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 +181 -65
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +6 -4
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +33 -15
- 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 +3 -2
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
- 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 +2 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +4 -4
- 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 +10 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
- 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 +8 -6
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
- 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 +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +18 -9
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +51 -11
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +90 -19
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- 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 +26 -44
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +5 -3
- 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 +6 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +3 -2
- 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 +256 -220
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +9 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +37 -12
- 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/clock_tolerance.d.ts +12 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +61 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +10 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +10 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +21 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +90 -44
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- 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/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/factory.d.ts +135 -7
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +252 -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 +99 -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/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 +69 -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 +2 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +35 -8
- package/dest/services/dummy_service.d.ts +12 -17
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +13 -20
- package/dest/services/encoding.d.ts +6 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +14 -8
- package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +21 -4
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +47 -55
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +344 -308
- 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 +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +40 -11
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -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 +97 -107
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +10 -6
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- 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 +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +16 -18
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -20
- 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/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +4 -2
- 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 +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -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 +0 -10
- 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 +43 -215
- package/dest/services/service.d.ts +10 -13
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +2 -23
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +2 -55
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +12 -28
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +43 -83
- package/dest/services/tx_collection/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- package/dest/services/tx_collection/index.d.ts +2 -3
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +0 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +0 -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 +36 -55
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +275 -119
- package/dest/services/tx_collection/tx_collection_sink.d.ts +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +2 -2
- package/dest/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- package/dest/services/tx_file_store/tx_file_store.d.ts +1 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +4 -14
- package/dest/services/tx_provider.d.ts +5 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +7 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- 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 +24 -11
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +45 -45
- 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 +13 -15
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +42 -15
- 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 +88 -42
- 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 +12 -7
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +15 -14
- package/src/bootstrap/bootstrap.ts +9 -1
- package/src/client/factory.ts +74 -49
- package/src/client/interface.ts +20 -30
- package/src/client/p2p_client.ts +108 -156
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +227 -45
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +0 -25
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +318 -242
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +204 -68
- package/src/mem_pools/attestation_pool/mocks.ts +13 -8
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +22 -14
- package/src/mem_pools/tx_pool_v2/README.md +9 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +10 -6
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +19 -8
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +130 -23
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +17 -2
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +267 -229
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -9
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +14 -7
- package/src/msg_validators/clock_tolerance.ts +79 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +24 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +35 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +114 -47
- package/src/msg_validators/tx_validator/README.md +127 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +6 -15
- 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/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/factory.ts +407 -80
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +199 -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/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +102 -0
- package/src/services/data_store.ts +5 -13
- package/src/services/discv5/discV5_service.ts +38 -5
- package/src/services/dummy_service.ts +15 -44
- package/src/services/encoding.ts +14 -7
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +390 -360
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +46 -11
- package/src/services/peer-manager/peer_scoring.ts +27 -5
- package/src/services/reqresp/README.md +215 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +97 -119
- package/src/services/reqresp/batch-tx-requester/interface.ts +13 -5
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- 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 +2 -2
- package/src/services/reqresp/interface.ts +21 -47
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -2
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +48 -261
- package/src/services/service.ts +13 -29
- package/src/services/tx_collection/config.ts +3 -80
- package/src/services/tx_collection/file_store_tx_collection.ts +54 -103
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/index.ts +1 -6
- package/src/services/tx_collection/instrumentation.ts +1 -7
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/tx_collection.ts +331 -176
- package/src/services/tx_collection/tx_collection_sink.ts +2 -2
- package/src/services/tx_collection/tx_source.ts +8 -7
- package/src/services/tx_file_store/tx_file_store.ts +5 -17
- package/src/services/tx_provider.ts +7 -2
- package/src/test-helpers/make-test-p2p-clients.ts +4 -3
- package/src/test-helpers/mock-pubsub.ts +49 -66
- 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 +54 -29
- package/src/testbench/p2p_client_testbench_worker.ts +91 -61
- package/src/testbench/worker_client_manager.ts +72 -25
- package/src/util.ts +33 -18
- 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/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 -54
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -327
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -49
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -57
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -211
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -346
- 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/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 -387
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -113
- package/src/services/tx_collection/slow_tx_collection.ts +0 -266
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import {
|
|
3
|
+
import { maxBy, merge } from '@aztec/foundation/collection';
|
|
4
4
|
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
7
7
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
8
8
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
9
|
-
import type { EthAddress,
|
|
9
|
+
import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
|
|
10
10
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
11
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
11
|
+
import { type BlockMinFeesProvider, GasFees } from '@aztec/stdlib/gas';
|
|
12
12
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
13
13
|
import {
|
|
14
14
|
BlockProposal,
|
|
@@ -16,17 +16,16 @@ import {
|
|
|
16
16
|
CheckpointProposal,
|
|
17
17
|
type CheckpointProposalCore,
|
|
18
18
|
type Gossipable,
|
|
19
|
-
P2PClientType,
|
|
20
19
|
P2PMessage,
|
|
21
|
-
type ValidationResult as P2PValidationResult,
|
|
22
20
|
PeerErrorSeverity,
|
|
21
|
+
PeerErrorSeverityByHarshness,
|
|
23
22
|
TopicType,
|
|
24
23
|
createTopicString,
|
|
25
|
-
|
|
24
|
+
getTopicsForConfig,
|
|
26
25
|
metricsTopicStrToLabels,
|
|
27
26
|
} from '@aztec/stdlib/p2p';
|
|
28
27
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
29
|
-
import { Tx, type
|
|
28
|
+
import { Tx, type TxValidationResult } from '@aztec/stdlib/tx';
|
|
30
29
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
31
30
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
32
31
|
import {
|
|
@@ -51,13 +50,15 @@ import { yamux } from '@chainsafe/libp2p-yamux';
|
|
|
51
50
|
import { bootstrap } from '@libp2p/bootstrap';
|
|
52
51
|
import { identify } from '@libp2p/identify';
|
|
53
52
|
import { type Message, type MultiaddrConnection, type PeerId, TopicValidatorResult } from '@libp2p/interface';
|
|
54
|
-
import type { ConnectionManager } from '@libp2p/interface-internal';
|
|
53
|
+
import type { AddressManager, ConnectionManager } from '@libp2p/interface-internal';
|
|
55
54
|
import { mplex } from '@libp2p/mplex';
|
|
56
55
|
import { tcp } from '@libp2p/tcp';
|
|
56
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
57
57
|
import { ENR } from '@nethermindeth/enr';
|
|
58
58
|
import { createLibp2p } from 'libp2p';
|
|
59
59
|
|
|
60
60
|
import type { P2PConfig } from '../../config.js';
|
|
61
|
+
import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
|
|
61
62
|
import type { MemPools } from '../../mem_pools/interface.js';
|
|
62
63
|
import {
|
|
63
64
|
BlockProposalValidator,
|
|
@@ -69,10 +70,12 @@ import {
|
|
|
69
70
|
} from '../../msg_validators/index.js';
|
|
70
71
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
71
72
|
import {
|
|
72
|
-
type
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
type TransactionValidator,
|
|
74
|
+
createFirstStageTxValidationsForGossipedTransactions,
|
|
75
|
+
createSecondStageTxValidationsForGossipedTransactions,
|
|
76
|
+
createTxValidatorForBlockProposalReceivedTxs,
|
|
75
77
|
} from '../../msg_validators/tx_validator/factory.js';
|
|
78
|
+
import { TxValidationCache } from '../../msg_validators/tx_validator/tx_validation_cache.js';
|
|
76
79
|
import { GossipSubEvent } from '../../types/index.js';
|
|
77
80
|
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
78
81
|
import { getVersions } from '../../versioning.js';
|
|
@@ -87,24 +90,18 @@ import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
|
87
90
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
88
91
|
import type { P2PReqRespConfig } from '../reqresp/config.js';
|
|
89
92
|
import {
|
|
90
|
-
|
|
93
|
+
AuthRequest,
|
|
94
|
+
BlockTxsRequest,
|
|
95
|
+
BlockTxsResponse,
|
|
91
96
|
type ReqRespInterface,
|
|
92
97
|
type ReqRespResponse,
|
|
93
98
|
ReqRespSubProtocol,
|
|
94
99
|
type ReqRespSubProtocolHandler,
|
|
95
100
|
type ReqRespSubProtocolHandlers,
|
|
96
|
-
type ReqRespSubProtocolValidators,
|
|
97
|
-
type SubProtocolMap,
|
|
98
|
-
ValidationError,
|
|
99
|
-
} from '../reqresp/index.js';
|
|
100
|
-
import {
|
|
101
|
-
AuthRequest,
|
|
102
|
-
BlockTxsRequest,
|
|
103
|
-
BlockTxsResponse,
|
|
104
101
|
StatusMessage,
|
|
102
|
+
ValidationError,
|
|
105
103
|
pingHandler,
|
|
106
104
|
reqGoodbyeHandler,
|
|
107
|
-
reqRespBlockHandler,
|
|
108
105
|
reqRespBlockTxsHandler,
|
|
109
106
|
reqRespStatusHandler,
|
|
110
107
|
reqRespTxHandler,
|
|
@@ -112,6 +109,7 @@ import {
|
|
|
112
109
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
113
110
|
import type {
|
|
114
111
|
P2PBlockReceivedCallback,
|
|
112
|
+
P2PCheckpointAttestationCallback,
|
|
115
113
|
P2PCheckpointReceivedCallback,
|
|
116
114
|
P2PDuplicateAttestationCallback,
|
|
117
115
|
P2PService,
|
|
@@ -130,12 +128,12 @@ type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: Vali
|
|
|
130
128
|
// REFACTOR: Unify with the type above
|
|
131
129
|
type ReceivedMessageValidationResult<T, M = undefined> =
|
|
132
130
|
| { obj: T; result: Exclude<TopicValidatorResult, TopicValidatorResult.Reject>; metadata?: M }
|
|
133
|
-
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M };
|
|
131
|
+
| { obj?: T; result: TopicValidatorResult.Reject; metadata?: M; severity: PeerErrorSeverity };
|
|
134
132
|
|
|
135
133
|
/**
|
|
136
134
|
* Lib P2P implementation of the P2PService interface.
|
|
137
135
|
*/
|
|
138
|
-
export class LibP2PService
|
|
136
|
+
export class LibP2PService extends WithTracer implements P2PService {
|
|
139
137
|
private discoveryRunningPromise?: RunningPromise;
|
|
140
138
|
private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
|
|
141
139
|
|
|
@@ -147,8 +145,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
147
145
|
private protocolVersion = '';
|
|
148
146
|
private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
|
|
149
147
|
|
|
150
|
-
private feesCache: { blockNumber: BlockNumber; gasFees: GasFees } | undefined;
|
|
151
|
-
|
|
152
148
|
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */
|
|
153
149
|
private duplicateProposalCallback?: (info: {
|
|
154
150
|
slot: SlotNumber;
|
|
@@ -159,6 +155,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
159
155
|
/** Callback invoked when a duplicate attestation is detected (triggers slashing). */
|
|
160
156
|
private duplicateAttestationCallback?: P2PDuplicateAttestationCallback;
|
|
161
157
|
|
|
158
|
+
/** Callback invoked when a valid checkpoint attestation is accepted into the pool. */
|
|
159
|
+
private checkpointAttestationCallback?: P2PCheckpointAttestationCallback;
|
|
160
|
+
|
|
162
161
|
/**
|
|
163
162
|
* Callback for when a block is received from a peer.
|
|
164
163
|
* @param block - The block received from the peer.
|
|
@@ -171,10 +170,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
171
170
|
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
172
171
|
* @returns The attestations for the checkpoint, if any.
|
|
173
172
|
*/
|
|
174
|
-
private
|
|
173
|
+
private allNodesCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
174
|
+
/**
|
|
175
|
+
* Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
|
|
176
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
177
|
+
* @returns The attestations for the checkpoint, if any.
|
|
178
|
+
*/
|
|
179
|
+
private validatorCheckpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
175
180
|
|
|
176
181
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
177
182
|
|
|
183
|
+
private ipChangedHandler?: (ip: string) => void;
|
|
184
|
+
private discoveredP2pIp?: string;
|
|
185
|
+
|
|
178
186
|
private instrumentation: P2PInstrumentation;
|
|
179
187
|
|
|
180
188
|
private telemetry: TelemetryClient;
|
|
@@ -182,7 +190,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
182
190
|
protected logger: Logger;
|
|
183
191
|
|
|
184
192
|
constructor(
|
|
185
|
-
private clientType: T,
|
|
186
193
|
private config: P2PConfig,
|
|
187
194
|
protected node: PubSubLibp2p,
|
|
188
195
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
@@ -193,8 +200,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
193
200
|
private epochCache: EpochCacheInterface,
|
|
194
201
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
195
202
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
203
|
+
private blockMinFeesProvider: BlockMinFeesProvider,
|
|
196
204
|
telemetry: TelemetryClient,
|
|
197
205
|
logger: Logger = createLogger('p2p:libp2p_service'),
|
|
206
|
+
private txValidationCache?: TxValidationCache,
|
|
198
207
|
) {
|
|
199
208
|
super(telemetry, 'LibP2PService');
|
|
200
209
|
this.telemetry = telemetry;
|
|
@@ -224,36 +233,55 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
224
233
|
this.protocolVersion,
|
|
225
234
|
);
|
|
226
235
|
|
|
227
|
-
|
|
228
|
-
|
|
236
|
+
const p2pPropagationTime = config.attestationPropagationTime;
|
|
237
|
+
const proposalValidatorOpts = {
|
|
229
238
|
txsPermitted: !config.disableTransactions,
|
|
230
|
-
|
|
239
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
240
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
241
|
+
p2pPropagationTime,
|
|
242
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
243
|
+
signatureContext: {
|
|
244
|
+
chainId: config.l1ChainId,
|
|
245
|
+
rollupAddress: config.rollupAddress,
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
|
|
249
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
|
|
250
|
+
const attestationValidatorOpts = {
|
|
251
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
252
|
+
p2pPropagationTime,
|
|
253
|
+
signatureContext: proposalValidatorOpts.signatureContext,
|
|
254
|
+
};
|
|
231
255
|
this.checkpointAttestationValidator = config.fishermanMode
|
|
232
|
-
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
233
|
-
: new CheckpointAttestationValidator(epochCache);
|
|
256
|
+
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry, attestationValidatorOpts)
|
|
257
|
+
: new CheckpointAttestationValidator(epochCache, attestationValidatorOpts);
|
|
234
258
|
|
|
235
259
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
236
260
|
|
|
237
261
|
this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
|
|
238
|
-
this.logger.
|
|
239
|
-
`Handler not yet registered
|
|
262
|
+
this.logger.warn(
|
|
263
|
+
`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`,
|
|
240
264
|
{ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
|
|
241
265
|
);
|
|
242
|
-
return
|
|
266
|
+
return true;
|
|
243
267
|
};
|
|
244
268
|
|
|
245
|
-
this.
|
|
246
|
-
|
|
269
|
+
this.allNodesCheckpointReceivedCallback = (
|
|
270
|
+
_checkpoint: CheckpointProposalCore,
|
|
271
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
272
|
+
throw new CheckpointProposalReceivedCallbackNotRegisteredError();
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
this.validatorCheckpointReceivedCallback = (
|
|
276
|
+
_checkpoint: CheckpointProposalCore,
|
|
247
277
|
): Promise<CheckpointAttestation[] | undefined> => {
|
|
248
|
-
this.logger.debug(
|
|
249
|
-
`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
|
|
250
|
-
);
|
|
251
278
|
return Promise.resolve(undefined);
|
|
252
279
|
};
|
|
253
280
|
}
|
|
254
281
|
|
|
255
|
-
public updateConfig(config: Partial<P2PReqRespConfig
|
|
282
|
+
public updateConfig(config: Partial<P2PReqRespConfig & Pick<P2PConfig, 'skipIncomingProposals'>>) {
|
|
256
283
|
this.reqresp.updateConfig(config);
|
|
284
|
+
this.config = merge(this.config, config);
|
|
257
285
|
}
|
|
258
286
|
|
|
259
287
|
/**
|
|
@@ -262,8 +290,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
262
290
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
263
291
|
* @returns The new service.
|
|
264
292
|
*/
|
|
265
|
-
public static async new
|
|
266
|
-
clientType: T,
|
|
293
|
+
public static async new(
|
|
267
294
|
config: P2PConfig,
|
|
268
295
|
peerId: PeerId,
|
|
269
296
|
deps: {
|
|
@@ -273,9 +300,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
273
300
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
274
301
|
worldStateSynchronizer: WorldStateSynchronizer;
|
|
275
302
|
peerStore: AztecAsyncKVStore;
|
|
303
|
+
blockMinFeesProvider: BlockMinFeesProvider;
|
|
276
304
|
telemetry: TelemetryClient;
|
|
277
305
|
logger: Logger;
|
|
278
306
|
packageVersion: string;
|
|
307
|
+
txValidationCache?: TxValidationCache;
|
|
279
308
|
},
|
|
280
309
|
) {
|
|
281
310
|
const {
|
|
@@ -285,9 +314,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
285
314
|
mempools,
|
|
286
315
|
proofVerifier,
|
|
287
316
|
peerStore,
|
|
317
|
+
blockMinFeesProvider,
|
|
288
318
|
telemetry,
|
|
289
319
|
logger,
|
|
290
320
|
packageVersion,
|
|
321
|
+
txValidationCache,
|
|
291
322
|
} = deps;
|
|
292
323
|
const { p2pPort, maxPeerCount, listenAddress } = config;
|
|
293
324
|
const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
|
|
@@ -338,9 +369,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
338
369
|
const l1Constants = epochCache.getL1Constants();
|
|
339
370
|
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
340
371
|
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
372
|
+
ethereumSlotDuration: l1Constants.ethereumSlotDuration,
|
|
341
373
|
heartbeatIntervalMs: config.gossipsubInterval,
|
|
342
374
|
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
343
375
|
blockDurationMs: config.blockDurationMs,
|
|
376
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
377
|
+
p2pPropagationTime: config.attestationPropagationTime,
|
|
344
378
|
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
|
|
345
379
|
});
|
|
346
380
|
|
|
@@ -442,8 +476,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
442
476
|
topics: topicScoreParams,
|
|
443
477
|
}),
|
|
444
478
|
}) as (components: GossipSubComponents) => GossipSub,
|
|
445
|
-
components: (components: { connectionManager: ConnectionManager }) => ({
|
|
479
|
+
components: (components: { connectionManager: ConnectionManager; addressManager: AddressManager }) => ({
|
|
446
480
|
connectionManager: components.connectionManager,
|
|
481
|
+
addressManager: components.addressManager,
|
|
447
482
|
}),
|
|
448
483
|
},
|
|
449
484
|
logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
|
|
@@ -465,6 +500,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
465
500
|
epochCache,
|
|
466
501
|
);
|
|
467
502
|
|
|
503
|
+
// Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
|
|
504
|
+
reqresp.setShouldRejectPeer(peerId => peerManager.shouldDisableP2PGossip(peerId));
|
|
505
|
+
|
|
468
506
|
// Configure application-specific scoring for gossipsub.
|
|
469
507
|
// The weight scales app score to align with gossipsub thresholds:
|
|
470
508
|
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
@@ -475,7 +513,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
475
513
|
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
476
514
|
|
|
477
515
|
return new LibP2PService(
|
|
478
|
-
clientType,
|
|
479
516
|
config,
|
|
480
517
|
node,
|
|
481
518
|
peerDiscoveryService,
|
|
@@ -486,8 +523,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
486
523
|
epochCache,
|
|
487
524
|
proofVerifier,
|
|
488
525
|
worldStateSynchronizer,
|
|
526
|
+
blockMinFeesProvider,
|
|
489
527
|
telemetry,
|
|
490
528
|
logger,
|
|
529
|
+
txValidationCache,
|
|
491
530
|
);
|
|
492
531
|
}
|
|
493
532
|
|
|
@@ -501,24 +540,21 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
501
540
|
throw new Error('P2P service already started');
|
|
502
541
|
}
|
|
503
542
|
|
|
504
|
-
// Get listen & announce addresses for logging
|
|
505
543
|
const { p2pIp, p2pPort } = this.config;
|
|
506
|
-
if (!p2pIp) {
|
|
507
|
-
throw new Error('Announce address not provided.');
|
|
544
|
+
if (!p2pIp && !this.config.queryForIp) {
|
|
545
|
+
throw new Error('Announce address not provided and queryForIp is not enabled.');
|
|
508
546
|
}
|
|
509
|
-
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
547
|
+
const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
|
|
510
548
|
|
|
511
549
|
// Create request response protocol handlers
|
|
512
550
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
513
551
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
514
|
-
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
515
552
|
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
516
553
|
|
|
517
554
|
const requestResponseHandlers: Partial<ReqRespSubProtocolHandlers> = {
|
|
518
555
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
519
556
|
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
520
557
|
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this),
|
|
521
|
-
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
522
558
|
};
|
|
523
559
|
|
|
524
560
|
if (!this.config.disableTransactions) {
|
|
@@ -534,22 +570,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
534
570
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
535
571
|
}
|
|
536
572
|
|
|
537
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
538
|
-
const reqrespSubProtocolValidators = {
|
|
539
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
540
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
541
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
542
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
543
|
-
};
|
|
544
|
-
|
|
545
573
|
await this.peerManager.initializePeers();
|
|
546
574
|
|
|
547
|
-
await this.reqresp.start(requestResponseHandlers
|
|
575
|
+
await this.reqresp.start(requestResponseHandlers);
|
|
548
576
|
|
|
549
577
|
await this.node.start();
|
|
550
578
|
|
|
551
579
|
// Subscribe to standard GossipSub topics by default
|
|
552
|
-
for (const topic of
|
|
580
|
+
for (const topic of getTopicsForConfig(this.config.disableTransactions)) {
|
|
553
581
|
this.subscribeToTopic(this.topicStrings[topic]);
|
|
554
582
|
}
|
|
555
583
|
|
|
@@ -560,6 +588,38 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
560
588
|
if (!this.config.p2pDiscoveryDisabled) {
|
|
561
589
|
await this.peerDiscoveryService.start();
|
|
562
590
|
}
|
|
591
|
+
|
|
592
|
+
// Bridge discv5 IP changes to libp2p's AddressManager so peers see the updated address
|
|
593
|
+
if (this.config.queryForIp) {
|
|
594
|
+
this.discoveredP2pIp = this.config.p2pIp;
|
|
595
|
+
this.logger.info('IP change tracking enabled, bridging discv5 IP updates to libp2p AddressManager');
|
|
596
|
+
this.ipChangedHandler = (ip: string) => {
|
|
597
|
+
const addressManager = this.node.services.components.addressManager;
|
|
598
|
+
const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
|
|
599
|
+
const previousIp = this.discoveredP2pIp;
|
|
600
|
+
|
|
601
|
+
if (previousIp) {
|
|
602
|
+
const oldAddr = multiaddr(convertToMultiaddr(previousIp, this.config.p2pPort, 'tcp'));
|
|
603
|
+
addressManager.removeObservedAddr(oldAddr);
|
|
604
|
+
this.logger.info('Libp2p announce address updated due to IP change', {
|
|
605
|
+
previousIp,
|
|
606
|
+
newIp: ip,
|
|
607
|
+
newMultiaddr: newAddr.toString(),
|
|
608
|
+
});
|
|
609
|
+
} else {
|
|
610
|
+
this.logger.info('Libp2p announce address set from initial discv5 IP discovery', {
|
|
611
|
+
ip,
|
|
612
|
+
multiaddr: newAddr.toString(),
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
addressManager.addObservedAddr(newAddr);
|
|
617
|
+
addressManager.confirmObservedAddr(newAddr);
|
|
618
|
+
this.discoveredP2pIp = ip;
|
|
619
|
+
};
|
|
620
|
+
this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
|
|
621
|
+
}
|
|
622
|
+
|
|
563
623
|
this.discoveryRunningPromise = new RunningPromise(
|
|
564
624
|
async () => {
|
|
565
625
|
await this.peerManager.heartbeat();
|
|
@@ -585,6 +645,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
585
645
|
// Remove gossip sub listener
|
|
586
646
|
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
587
647
|
|
|
648
|
+
if (this.ipChangedHandler) {
|
|
649
|
+
this.peerDiscoveryService.removeListener('ip:changed', this.ipChangedHandler);
|
|
650
|
+
this.ipChangedHandler = undefined;
|
|
651
|
+
}
|
|
652
|
+
|
|
588
653
|
// Stop peer manager
|
|
589
654
|
this.logger.debug('Stopping peer manager...');
|
|
590
655
|
await this.peerManager.stop();
|
|
@@ -599,12 +664,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
599
664
|
this.logger.info('LibP2P service stopped');
|
|
600
665
|
}
|
|
601
666
|
|
|
602
|
-
addReqRespSubProtocol(
|
|
603
|
-
subProtocol
|
|
604
|
-
handler: ReqRespSubProtocolHandler,
|
|
605
|
-
validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
606
|
-
): Promise<void> {
|
|
607
|
-
return this.reqresp.addSubProtocol(subProtocol, handler, validator);
|
|
667
|
+
addReqRespSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void> {
|
|
668
|
+
return this.reqresp.addSubProtocol(subProtocol, handler);
|
|
608
669
|
}
|
|
609
670
|
|
|
610
671
|
public registerThisValidatorAddresses(address: EthAddress[]): void {
|
|
@@ -632,20 +693,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
632
693
|
setImmediate(() => void safeJob());
|
|
633
694
|
}
|
|
634
695
|
|
|
635
|
-
/**
|
|
636
|
-
* Send a batch of requests to peers, and return the responses
|
|
637
|
-
* @param protocol - The request response protocol to use
|
|
638
|
-
* @param requests - The requests to send to the peers
|
|
639
|
-
* @returns The responses to the requests
|
|
640
|
-
*/
|
|
641
|
-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
642
|
-
protocol: SubProtocol,
|
|
643
|
-
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
644
|
-
pinnedPeerId: PeerId | undefined,
|
|
645
|
-
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]> {
|
|
646
|
-
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
696
|
public sendRequestToPeer(
|
|
650
697
|
peerId: PeerId,
|
|
651
698
|
subProtocol: ReqRespSubProtocol,
|
|
@@ -667,8 +714,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
667
714
|
this.blockReceivedCallback = callback;
|
|
668
715
|
}
|
|
669
716
|
|
|
670
|
-
public
|
|
671
|
-
this.
|
|
717
|
+
public registerValidatorCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
718
|
+
this.validatorCheckpointReceivedCallback = callback;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
public registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
722
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
672
723
|
}
|
|
673
724
|
|
|
674
725
|
/**
|
|
@@ -690,6 +741,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
690
741
|
this.duplicateAttestationCallback = callback;
|
|
691
742
|
}
|
|
692
743
|
|
|
744
|
+
public registerCheckpointAttestationCallback(callback: P2PCheckpointAttestationCallback): void {
|
|
745
|
+
this.checkpointAttestationCallback = callback;
|
|
746
|
+
}
|
|
747
|
+
|
|
693
748
|
/**
|
|
694
749
|
* Subscribes to a topic.
|
|
695
750
|
* @param topic - The topic to subscribe to.
|
|
@@ -754,6 +809,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
754
809
|
if (!validator || !validator.addMessage(msgId)) {
|
|
755
810
|
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
756
811
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
812
|
+
if (topicType === TopicType.tx) {
|
|
813
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, { msgId, source: source.toString() });
|
|
814
|
+
}
|
|
757
815
|
return { result: false, topicType };
|
|
758
816
|
}
|
|
759
817
|
|
|
@@ -815,12 +873,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
815
873
|
|
|
816
874
|
// Process the message, optionally within a linked span for trace propagation
|
|
817
875
|
const processMessage = async () => {
|
|
876
|
+
if (
|
|
877
|
+
this.config.skipIncomingProposals &&
|
|
878
|
+
(msg.topic === this.topicStrings[TopicType.block_proposal] ||
|
|
879
|
+
msg.topic === this.topicStrings[TopicType.checkpoint_proposal])
|
|
880
|
+
) {
|
|
881
|
+
this.logger.warn(`Ignoring incoming proposal (skipIncomingProposals is set)`, { topic: msg.topic });
|
|
882
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
818
885
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
819
886
|
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
820
887
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
821
|
-
|
|
822
|
-
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
823
|
-
}
|
|
888
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
824
889
|
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
825
890
|
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
826
891
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
@@ -882,47 +947,124 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
882
947
|
source: PeerId,
|
|
883
948
|
topicType: TopicType,
|
|
884
949
|
): Promise<ReceivedMessageValidationResult<T, M>> {
|
|
885
|
-
|
|
950
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
951
|
+
let resultAndObj: ReceivedMessageValidationResult<T, M> = {
|
|
952
|
+
result: TopicValidatorResult.Reject,
|
|
953
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
954
|
+
};
|
|
886
955
|
const timer = new Timer();
|
|
887
956
|
try {
|
|
888
957
|
resultAndObj = await validationFunc();
|
|
889
958
|
} catch (err) {
|
|
890
|
-
this.
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
959
|
+
this.logger.error(`Error validating gossipsub message`, err, { msgId, source: source.toString(), topicType });
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
const validationTimeMs = timer.ms();
|
|
963
|
+
const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
|
|
964
|
+
if (validationTimeMs > mcacheWindowMs * 0.75) {
|
|
965
|
+
this.instrumentation.incSlowValidation(topicType);
|
|
966
|
+
this.logger.warn(
|
|
967
|
+
`Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` +
|
|
968
|
+
`Message forwarding may be skipped if validation exceeds the window.`,
|
|
969
|
+
{ msgId, source: source.toString(), topicType, validationTimeMs, mcacheWindowMs },
|
|
970
|
+
);
|
|
896
971
|
}
|
|
897
972
|
|
|
898
973
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
974
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, { msgId, source: source.toString(), topicType });
|
|
899
975
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
976
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
977
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
978
|
+
msgId,
|
|
979
|
+
source: source.toString(),
|
|
980
|
+
topicType,
|
|
981
|
+
severity: resultAndObj.severity,
|
|
982
|
+
});
|
|
983
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
984
|
+
} else {
|
|
985
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, { msgId, source: source.toString(), topicType });
|
|
900
986
|
}
|
|
901
987
|
|
|
902
988
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
903
989
|
return resultAndObj;
|
|
904
990
|
}
|
|
905
991
|
|
|
992
|
+
private tryDeserialize<T>(deserializeFunc: () => T, msgId: string, source: PeerId): T | undefined {
|
|
993
|
+
try {
|
|
994
|
+
return deserializeFunc();
|
|
995
|
+
} catch (err) {
|
|
996
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
997
|
+
err,
|
|
998
|
+
msgId,
|
|
999
|
+
source: source.toString(),
|
|
1000
|
+
});
|
|
1001
|
+
return undefined;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
906
1005
|
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
907
1006
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
908
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1007
|
+
const tx = this.tryDeserialize(() => Tx.fromBuffer(payloadData), msgId, source);
|
|
1008
|
+
if (!tx) {
|
|
1009
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.LowToleranceError };
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1013
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1014
|
+
|
|
1015
|
+
// Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
|
|
1016
|
+
const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1017
|
+
const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
|
|
1018
|
+
if (!firstStageOutcome.allPassed) {
|
|
1019
|
+
const { name } = firstStageOutcome.failure;
|
|
1020
|
+
let { severity } = firstStageOutcome.failure;
|
|
1021
|
+
|
|
1022
|
+
// Double spend validator has a special case handler. We perform more detailed examination
|
|
1023
|
+
// as to how recently the nullifier was entered into the tree and if the transaction should
|
|
1024
|
+
// have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
|
|
1025
|
+
if (name === 'doubleSpendValidator') {
|
|
1026
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1027
|
+
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
1031
|
+
validator: name,
|
|
1032
|
+
severity,
|
|
1033
|
+
source: source.toString(),
|
|
913
1034
|
});
|
|
914
|
-
return { result: TopicValidatorResult.Reject };
|
|
1035
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
1039
|
+
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
1040
|
+
if (canAdd === 'ignored') {
|
|
1041
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
1042
|
+
source: source.toString(),
|
|
1043
|
+
});
|
|
1044
|
+
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
915
1045
|
}
|
|
916
1046
|
|
|
917
|
-
//
|
|
1047
|
+
// Stage 2: expensive proof verification
|
|
1048
|
+
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
1049
|
+
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
1050
|
+
if (!secondStageOutcome.allPassed) {
|
|
1051
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
1052
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1053
|
+
validator: name,
|
|
1054
|
+
severity,
|
|
1055
|
+
source: source.toString(),
|
|
1056
|
+
});
|
|
1057
|
+
return { result: TopicValidatorResult.Reject, severity };
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// Pool add: persist the tx
|
|
918
1061
|
const txHash = tx.getTxHash();
|
|
919
1062
|
const addResult = await this.mempools.txPool.addPendingTxs([tx], { source: 'gossip' });
|
|
920
1063
|
|
|
921
1064
|
const wasAccepted = addResult.accepted.some(h => h.equals(txHash));
|
|
922
1065
|
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
923
1066
|
|
|
924
|
-
this.logger.
|
|
925
|
-
isValid,
|
|
1067
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
926
1068
|
wasAccepted,
|
|
927
1069
|
wasIgnored,
|
|
928
1070
|
[Attributes.P2P_ID]: source.toString(),
|
|
@@ -933,7 +1075,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
933
1075
|
} else if (wasIgnored) {
|
|
934
1076
|
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
935
1077
|
} else {
|
|
936
|
-
|
|
1078
|
+
this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
|
|
1079
|
+
source: source.toString(),
|
|
1080
|
+
txHash: txHash.toString(),
|
|
1081
|
+
});
|
|
1082
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
937
1083
|
}
|
|
938
1084
|
};
|
|
939
1085
|
|
|
@@ -963,7 +1109,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
963
1109
|
source: PeerId,
|
|
964
1110
|
): Promise<void> {
|
|
965
1111
|
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
966
|
-
() =>
|
|
1112
|
+
() => {
|
|
1113
|
+
const attestation = this.tryDeserialize(() => CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1114
|
+
if (!attestation) {
|
|
1115
|
+
return Promise.resolve({
|
|
1116
|
+
result: TopicValidatorResult.Reject,
|
|
1117
|
+
severity: PeerErrorSeverity.LowToleranceError,
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1121
|
+
},
|
|
967
1122
|
msgId,
|
|
968
1123
|
source,
|
|
969
1124
|
TopicType.checkpoint_attestation,
|
|
@@ -996,8 +1151,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
996
1151
|
|
|
997
1152
|
if (validationResult.result === 'reject') {
|
|
998
1153
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
999
|
-
|
|
1000
|
-
return { result: TopicValidatorResult.Reject };
|
|
1154
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1001
1155
|
}
|
|
1002
1156
|
|
|
1003
1157
|
if (validationResult.result === 'ignore') {
|
|
@@ -1023,16 +1177,16 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1023
1177
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
1024
1178
|
}
|
|
1025
1179
|
|
|
1026
|
-
// Could not add (cap reached for signer),
|
|
1180
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1027
1181
|
if (!added) {
|
|
1028
|
-
this.logger.warn(`
|
|
1182
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1029
1183
|
slot: slot.toString(),
|
|
1030
1184
|
archive: attestation.archive.toString(),
|
|
1031
1185
|
source: peerId.toString(),
|
|
1032
1186
|
attester: attestation.getSender()?.toString(),
|
|
1033
1187
|
count,
|
|
1034
1188
|
});
|
|
1035
|
-
return { result: TopicValidatorResult.
|
|
1189
|
+
return { result: TopicValidatorResult.Reject, severity: PeerErrorSeverity.HighToleranceError };
|
|
1036
1190
|
}
|
|
1037
1191
|
|
|
1038
1192
|
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
@@ -1051,6 +1205,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1051
1205
|
}
|
|
1052
1206
|
|
|
1053
1207
|
// Attestation was added successfully - accept it so other nodes can also detect the equivocation
|
|
1208
|
+
this.checkpointAttestationCallback?.(attestation);
|
|
1054
1209
|
return { result: TopicValidatorResult.Accept, obj: attestation };
|
|
1055
1210
|
}
|
|
1056
1211
|
|
|
@@ -1087,8 +1242,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1087
1242
|
|
|
1088
1243
|
if (validationResult.result === 'reject') {
|
|
1089
1244
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1090
|
-
|
|
1091
|
-
return { result: TopicValidatorResult.Reject };
|
|
1245
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1092
1246
|
}
|
|
1093
1247
|
|
|
1094
1248
|
if (validationResult.result === 'ignore') {
|
|
@@ -1112,7 +1266,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1112
1266
|
|
|
1113
1267
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1114
1268
|
if (!added) {
|
|
1115
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1116
1269
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1117
1270
|
...block.toBlockInfo(),
|
|
1118
1271
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
@@ -1120,7 +1273,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1120
1273
|
proposer: block.getSender()?.toString(),
|
|
1121
1274
|
source: peerId.toString(),
|
|
1122
1275
|
});
|
|
1123
|
-
return {
|
|
1276
|
+
return {
|
|
1277
|
+
result: TopicValidatorResult.Reject,
|
|
1278
|
+
metadata: { isEquivocated },
|
|
1279
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1280
|
+
};
|
|
1124
1281
|
}
|
|
1125
1282
|
|
|
1126
1283
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1165,7 +1322,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1165
1322
|
// Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1166
1323
|
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1167
1324
|
if (!isValid) {
|
|
1168
|
-
this.logger.
|
|
1325
|
+
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1169
1326
|
}
|
|
1170
1327
|
}
|
|
1171
1328
|
|
|
@@ -1185,17 +1342,33 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1185
1342
|
TopicType.checkpoint_proposal,
|
|
1186
1343
|
);
|
|
1187
1344
|
|
|
1345
|
+
// Process checkpoint proposal if valid and not equivocated.
|
|
1346
|
+
const processCheckpointFn = () =>
|
|
1347
|
+
result === TopicValidatorResult.Accept && checkpoint && !isEquivocated
|
|
1348
|
+
? this.processValidCheckpointProposal(checkpoint.toCore(), source)
|
|
1349
|
+
: Promise.resolve();
|
|
1350
|
+
|
|
1188
1351
|
// If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
|
|
1189
1352
|
// TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1353
|
+
const processBlockFn = () =>
|
|
1354
|
+
processBlock && checkpoint && checkpoint.getBlockProposal()
|
|
1355
|
+
? this.processValidBlockProposal(checkpoint.getBlockProposal()!, source)
|
|
1356
|
+
: Promise.resolve();
|
|
1357
|
+
|
|
1358
|
+
// A node that skips checkpoint validation attests without re-executing the embedded last block, so run
|
|
1359
|
+
// the checkpoint callback first: this creates and broadcasts the attestation before the block is
|
|
1360
|
+
// processed. Otherwise the block's re-execution — which can stall until the re-execution deadline
|
|
1361
|
+
// waiting for a parent that may never arrive — would delay the attestation past the slot's attestation
|
|
1362
|
+
// window, after which peers reject it as stale.
|
|
1363
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
1364
|
+
await processCheckpointFn();
|
|
1365
|
+
await processBlockFn();
|
|
1195
1366
|
return;
|
|
1196
1367
|
}
|
|
1197
1368
|
|
|
1198
|
-
|
|
1369
|
+
// Process the block first, since it's required for the checkpoint proposal validation.
|
|
1370
|
+
await processBlockFn();
|
|
1371
|
+
await processCheckpointFn();
|
|
1199
1372
|
}
|
|
1200
1373
|
|
|
1201
1374
|
/**
|
|
@@ -1213,8 +1386,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1213
1386
|
|
|
1214
1387
|
if (validationResult.result === 'reject') {
|
|
1215
1388
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1216
|
-
|
|
1217
|
-
return { result: TopicValidatorResult.Reject };
|
|
1389
|
+
return { result: TopicValidatorResult.Reject, severity: validationResult.severity };
|
|
1218
1390
|
}
|
|
1219
1391
|
|
|
1220
1392
|
if (validationResult.result === 'ignore') {
|
|
@@ -1229,20 +1401,21 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1229
1401
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1230
1402
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1231
1403
|
});
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
metadata: { isEquivocated } = {},
|
|
1236
|
-
} = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1237
|
-
if (result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1404
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1405
|
+
const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
|
|
1406
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1238
1407
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1239
1408
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1240
1409
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1241
1410
|
isEquivocated,
|
|
1242
|
-
result,
|
|
1411
|
+
result: blockProposalResult.result,
|
|
1243
1412
|
});
|
|
1244
|
-
return {
|
|
1245
|
-
|
|
1413
|
+
return {
|
|
1414
|
+
result: TopicValidatorResult.Reject,
|
|
1415
|
+
severity:
|
|
1416
|
+
'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError,
|
|
1417
|
+
};
|
|
1418
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1246
1419
|
processBlock = true;
|
|
1247
1420
|
}
|
|
1248
1421
|
}
|
|
@@ -1269,13 +1442,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1269
1442
|
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1270
1443
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1271
1444
|
if (!added) {
|
|
1272
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1273
1445
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1274
1446
|
...checkpoint.toCheckpointInfo(),
|
|
1275
1447
|
count,
|
|
1276
1448
|
source: peerId.toString(),
|
|
1277
1449
|
});
|
|
1278
|
-
return {
|
|
1450
|
+
return {
|
|
1451
|
+
result: TopicValidatorResult.Reject,
|
|
1452
|
+
obj: checkpoint,
|
|
1453
|
+
metadata: { isEquivocated, processBlock },
|
|
1454
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
1455
|
+
};
|
|
1279
1456
|
}
|
|
1280
1457
|
|
|
1281
1458
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1320,9 +1497,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1320
1497
|
source: sender.toString(),
|
|
1321
1498
|
});
|
|
1322
1499
|
|
|
1500
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1501
|
+
|
|
1323
1502
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1324
1503
|
// to validate and potentially generate attestations
|
|
1325
|
-
const attestations = await this.
|
|
1504
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1326
1505
|
if (attestations && attestations.length > 0) {
|
|
1327
1506
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1328
1507
|
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
@@ -1345,23 +1524,32 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1345
1524
|
}
|
|
1346
1525
|
|
|
1347
1526
|
/**
|
|
1348
|
-
* Validate the requested block transactions
|
|
1527
|
+
* Validate the requested block transactions request-response consistency.
|
|
1528
|
+
* It does NOT validate the transactions themselves.
|
|
1349
1529
|
* @param request - The block transactions request.
|
|
1350
1530
|
* @param response - The block transactions response.
|
|
1351
1531
|
* @param peerId - The ID of the peer that made the request.
|
|
1352
|
-
* @returns True if the
|
|
1532
|
+
* @returns True if the request-response is consistent, false otherwise.
|
|
1353
1533
|
*/
|
|
1354
|
-
@trackSpan('Libp2pService.
|
|
1534
|
+
@trackSpan('Libp2pService.validateRequestedBlockTxsConsistency', request => ({
|
|
1355
1535
|
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
|
|
1356
1536
|
}))
|
|
1357
|
-
protected async
|
|
1537
|
+
protected async validateRequestedBlockTxsConsistency(
|
|
1358
1538
|
request: BlockTxsRequest,
|
|
1359
1539
|
response: BlockTxsResponse,
|
|
1360
1540
|
peerId: PeerId,
|
|
1361
1541
|
): Promise<boolean> {
|
|
1362
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1363
|
-
|
|
1364
1542
|
try {
|
|
1543
|
+
// A response with archiveRoot=Fr.zero is the documented "I don't have the block" signal from
|
|
1544
|
+
// reqRespBlockTxsHandler (block_txs_handler.ts:54-58): the peer lacked the block in its
|
|
1545
|
+
// attestation pool and archiver, but matched the requested hashes against its tx pool and
|
|
1546
|
+
// shipped what it found. This is legitimate behaviour, not misbehaviour — we just can't verify
|
|
1547
|
+
// membership/order without the block, so we drop the response without penalising the peer.
|
|
1548
|
+
if (response.archiveRoot.isZero()) {
|
|
1549
|
+
this.logger.debug(`Peer ${peerId.toString()} signalled missing block with Fr.zero archive root`);
|
|
1550
|
+
return false;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1365
1553
|
if (!response.archiveRoot.equals(request.archiveRoot)) {
|
|
1366
1554
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1367
1555
|
throw new ValidationError(
|
|
@@ -1394,18 +1582,26 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1394
1582
|
);
|
|
1395
1583
|
}
|
|
1396
1584
|
|
|
1397
|
-
//
|
|
1398
|
-
|
|
1399
|
-
|
|
1585
|
+
// To verify membership/order of the returned txs we need the canonical tx hash list for the
|
|
1586
|
+
// block. Prefer the block proposal (held while a block is in flight), but fall back to the
|
|
1587
|
+
// archiver for blocks we only know as mined — e.g. a prover collecting txs to prove a block it
|
|
1588
|
+
// never received a proposal for. This mirrors the responder side (reqRespBlockTxsHandler),
|
|
1589
|
+
// which serves from proposal-or-archiver.
|
|
1590
|
+
const proposal = await this.mempools.attestationPool.getBlockProposalByArchive(request.archiveRoot.toString());
|
|
1591
|
+
const blockTxHashes =
|
|
1592
|
+
proposal?.txHashes ??
|
|
1593
|
+
(await this.archiver.getBlock({ archive: request.archiveRoot }))?.body.txEffects.map(e => e.txHash);
|
|
1594
|
+
|
|
1595
|
+
if (blockTxHashes) {
|
|
1400
1596
|
// Build intersected indices
|
|
1401
1597
|
const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
|
|
1402
1598
|
|
|
1403
1599
|
// Enforce subset membership and preserve increasing order by index.
|
|
1404
|
-
const
|
|
1405
|
-
|
|
1600
|
+
const hashToIndexInBlock = new Map<string, number>(
|
|
1601
|
+
blockTxHashes.map((h, i) => [h.toString(), i] as [string, number]),
|
|
1406
1602
|
);
|
|
1407
1603
|
const allowedIndexSet = new Set(intersectIdx);
|
|
1408
|
-
const indices = returnedHashes.map(h =>
|
|
1604
|
+
const indices = returnedHashes.map(h => hashToIndexInBlock.get(h));
|
|
1409
1605
|
const allAllowed = indices.every(idx => idx !== undefined && allowedIndexSet.has(idx));
|
|
1410
1606
|
const strictlyIncreasing = indices.every((idx, i) => (i === 0 ? idx !== undefined : idx! > indices[i - 1]!));
|
|
1411
1607
|
if (!allAllowed || !strictlyIncreasing) {
|
|
@@ -1413,14 +1609,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1413
1609
|
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
1414
1610
|
}
|
|
1415
1611
|
} else {
|
|
1416
|
-
//
|
|
1612
|
+
// Neither a local proposal nor an archived block: we cannot verify membership/order of the
|
|
1613
|
+
// returned txs. This is a local-state gap, not a peer fault, so we do not penalize.
|
|
1417
1614
|
this.logger.warn(
|
|
1418
|
-
`Block
|
|
1615
|
+
`Block ${request.archiveRoot.toString()} not found in attestation pool or archiver; cannot validate membership/order of returned txs`,
|
|
1419
1616
|
);
|
|
1420
1617
|
return false;
|
|
1421
1618
|
}
|
|
1422
1619
|
|
|
1423
|
-
await Promise.all(response.txs.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
1424
1620
|
return true;
|
|
1425
1621
|
} catch (e: any) {
|
|
1426
1622
|
if (e instanceof ValidationError) {
|
|
@@ -1433,156 +1629,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1433
1629
|
}
|
|
1434
1630
|
}
|
|
1435
1631
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
*
|
|
1439
|
-
* The core component of this validator is that each tx hash MUST match the requested tx hash,
|
|
1440
|
-
* In order to perform this check, the tx proof must be verified.
|
|
1441
|
-
*
|
|
1442
|
-
* Note: This function is called from within `ReqResp.sendRequest` as part of the
|
|
1443
|
-
* ReqRespSubProtocol.TX subprotocol validation.
|
|
1444
|
-
*
|
|
1445
|
-
* @param requestedTxHash - The collection of the txs that was requested.
|
|
1446
|
-
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
1447
|
-
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1448
|
-
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
1449
|
-
*/
|
|
1450
|
-
@trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx) => ({
|
|
1451
|
-
[Attributes.TX_HASH]: requestedTxHash.toString(),
|
|
1452
|
-
}))
|
|
1453
|
-
private async validateRequestedTxs(requestedTxHash: TxHash[], responseTx: Tx[], peerId: PeerId): Promise<boolean> {
|
|
1454
|
-
const requested = new Set(requestedTxHash.map(h => h.toString()));
|
|
1455
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1456
|
-
|
|
1457
|
-
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
1458
|
-
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1459
|
-
try {
|
|
1460
|
-
await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
1461
|
-
return true;
|
|
1462
|
-
} catch (e: any) {
|
|
1463
|
-
if (e instanceof ValidationError) {
|
|
1464
|
-
this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
|
|
1465
|
-
} else {
|
|
1466
|
-
this.logger.error(`Error during validation of requested txs`, e);
|
|
1467
|
-
}
|
|
1468
|
-
|
|
1469
|
-
return false;
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
/**
|
|
1474
|
-
* Validates a BLOCK response.
|
|
1475
|
-
*
|
|
1476
|
-
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1477
|
-
* Penalizes on block number mismatch or hash mismatch.
|
|
1478
|
-
*
|
|
1479
|
-
* @param requestedBlockNumber - The requested block number.
|
|
1480
|
-
* @param responseBlock - The block returned by the peer.
|
|
1481
|
-
* @param peerId - The peer that returned the block.
|
|
1482
|
-
* @returns True if the response is valid, false otherwise.
|
|
1483
|
-
*/
|
|
1484
|
-
@trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock) => ({
|
|
1485
|
-
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString(),
|
|
1486
|
-
}))
|
|
1487
|
-
protected async validateRequestedBlock(
|
|
1488
|
-
requestedBlockNumber: Fr,
|
|
1489
|
-
responseBlock: L2Block,
|
|
1490
|
-
peerId: PeerId,
|
|
1491
|
-
): Promise<boolean> {
|
|
1492
|
-
try {
|
|
1493
|
-
const reqNum = Number(requestedBlockNumber.toString());
|
|
1494
|
-
if (responseBlock.number !== reqNum) {
|
|
1495
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1496
|
-
return false;
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1500
|
-
if (!local) {
|
|
1501
|
-
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1502
|
-
// TODO: Consider extending this validator to accept an expected hash or
|
|
1503
|
-
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1504
|
-
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1505
|
-
return false;
|
|
1506
|
-
}
|
|
1507
|
-
const [localHash, respHash] = await Promise.all([local.hash(), responseBlock.hash()]);
|
|
1508
|
-
if (!localHash.equals(respHash)) {
|
|
1509
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1510
|
-
return false;
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
return true;
|
|
1514
|
-
} catch (e) {
|
|
1515
|
-
this.logger.warn(`Error validating requested block`, e);
|
|
1516
|
-
return false;
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
protected async validateRequestedTx(
|
|
1521
|
-
tx: Tx,
|
|
1522
|
-
peerId: PeerId,
|
|
1523
|
-
txValidator: TxValidator,
|
|
1524
|
-
requested?: Set<`0x${string}`>,
|
|
1525
|
-
) {
|
|
1526
|
-
const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
|
|
1527
|
-
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1528
|
-
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1529
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
const { result } = await txValidator.validateTx(tx);
|
|
1533
|
-
if (result === 'invalid') {
|
|
1534
|
-
penalize(PeerErrorSeverity.LowToleranceError);
|
|
1535
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
protected createRequestedTxValidator(): TxValidator {
|
|
1540
|
-
return createTxReqRespValidator(this.proofVerifier, {
|
|
1541
|
-
l1ChainId: this.config.l1ChainId,
|
|
1542
|
-
rollupVersion: this.config.rollupVersion,
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
1547
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1548
|
-
}))
|
|
1549
|
-
protected async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
|
|
1550
|
-
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1551
|
-
|
|
1552
|
-
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1553
|
-
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1554
|
-
const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1555
|
-
|
|
1556
|
-
for (const validator of messageValidators) {
|
|
1557
|
-
const outcome = await this.runValidations(tx, validator);
|
|
1558
|
-
|
|
1559
|
-
if (outcome.allPassed) {
|
|
1560
|
-
continue;
|
|
1561
|
-
}
|
|
1562
|
-
const { name } = outcome.failure;
|
|
1563
|
-
let { severity } = outcome.failure;
|
|
1564
|
-
|
|
1565
|
-
// Double spend validator has a special case handler
|
|
1566
|
-
if (name === 'doubleSpendValidator') {
|
|
1567
|
-
const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
|
|
1568
|
-
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1572
|
-
return false;
|
|
1573
|
-
}
|
|
1574
|
-
return true;
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
|
|
1578
|
-
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1579
|
-
return this.feesCache.gasFees;
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
1583
|
-
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
1584
|
-
this.feesCache = { blockNumber, gasFees };
|
|
1585
|
-
return gasFees;
|
|
1632
|
+
private getGasFees(): Promise<GasFees> {
|
|
1633
|
+
return this.blockMinFeesProvider.getCurrentMinFees();
|
|
1586
1634
|
}
|
|
1587
1635
|
|
|
1588
1636
|
/**
|
|
@@ -1596,65 +1644,70 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1596
1644
|
l1ChainId: this.config.l1ChainId,
|
|
1597
1645
|
rollupVersion: this.config.rollupVersion,
|
|
1598
1646
|
proofVerifier: this.proofVerifier,
|
|
1647
|
+
txValidationCache: this.txValidationCache,
|
|
1599
1648
|
},
|
|
1600
1649
|
peerScoring: this.peerManager,
|
|
1650
|
+
validateRequestedBlockTxsConsistency: this.validateRequestedBlockTxsConsistency.bind(this),
|
|
1601
1651
|
};
|
|
1602
1652
|
}
|
|
1603
1653
|
|
|
1604
|
-
public async
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1654
|
+
public async validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
1655
|
+
const validator = createTxValidatorForBlockProposalReceivedTxs(
|
|
1656
|
+
this.proofVerifier,
|
|
1657
|
+
{ l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
|
|
1658
|
+
this.logger.getBindings(),
|
|
1659
|
+
this.txValidationCache,
|
|
1660
|
+
);
|
|
1610
1661
|
|
|
1611
|
-
await Promise.all(
|
|
1662
|
+
const results = await Promise.all(
|
|
1612
1663
|
txs.map(async tx => {
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
if (!outcome.allPassed) {
|
|
1616
|
-
throw new Error('Invalid tx detected', { cause: { outcome } });
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1664
|
+
const result = await validator.validateTx(tx);
|
|
1665
|
+
return result.result !== 'invalid';
|
|
1619
1666
|
}),
|
|
1620
1667
|
);
|
|
1668
|
+
if (results.some(value => value === false)) {
|
|
1669
|
+
throw new Error('Invalid tx detected');
|
|
1670
|
+
}
|
|
1621
1671
|
}
|
|
1622
1672
|
|
|
1623
|
-
/**
|
|
1624
|
-
|
|
1625
|
-
*
|
|
1626
|
-
* Each validator is a pair of a validator and a severity.
|
|
1627
|
-
* If a validator fails, the peer is penalized with the severity of the validator.
|
|
1628
|
-
*
|
|
1629
|
-
* @param currentBlockNumber - The current synced block number.
|
|
1630
|
-
* @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
|
|
1631
|
-
* @returns The message validators.
|
|
1632
|
-
*/
|
|
1633
|
-
private async createMessageValidators(
|
|
1673
|
+
/** Creates the first stage (fast) validators for gossiped transactions. */
|
|
1674
|
+
protected async createFirstStageMessageValidators(
|
|
1634
1675
|
currentBlockNumber: BlockNumber,
|
|
1635
1676
|
nextSlotTimestamp: UInt64,
|
|
1636
|
-
): Promise<Record<string,
|
|
1637
|
-
const gasFees = await this.getGasFees(
|
|
1638
|
-
const allowedInSetup =
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1677
|
+
): Promise<Record<string, TransactionValidator>> {
|
|
1678
|
+
const gasFees = await this.getGasFees();
|
|
1679
|
+
const allowedInSetup = [
|
|
1680
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1681
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1682
|
+
];
|
|
1683
|
+
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1684
|
+
const l1Constants = await this.archiver.getL1Constants();
|
|
1685
|
+
|
|
1686
|
+
return createFirstStageTxValidationsForGossipedTransactions(
|
|
1643
1687
|
nextSlotTimestamp,
|
|
1644
|
-
|
|
1688
|
+
blockNumber,
|
|
1645
1689
|
this.worldStateSynchronizer,
|
|
1646
1690
|
gasFees,
|
|
1647
1691
|
this.config.l1ChainId,
|
|
1648
1692
|
this.config.rollupVersion,
|
|
1649
1693
|
protocolContractsHash,
|
|
1650
1694
|
this.archiver,
|
|
1651
|
-
this.proofVerifier,
|
|
1652
1695
|
!this.config.disableTransactions,
|
|
1653
1696
|
allowedInSetup,
|
|
1654
1697
|
this.logger.getBindings(),
|
|
1698
|
+
{
|
|
1699
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1700
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1701
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1702
|
+
},
|
|
1655
1703
|
);
|
|
1656
1704
|
}
|
|
1657
1705
|
|
|
1706
|
+
/** Creates the second stage (expensive proof verification) validators for gossiped transactions. */
|
|
1707
|
+
protected createSecondStageMessageValidators(): Record<string, TransactionValidator> {
|
|
1708
|
+
return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1658
1711
|
/**
|
|
1659
1712
|
* Run validations on a tx.
|
|
1660
1713
|
* @param tx - The tx to validate.
|
|
@@ -1663,7 +1716,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1663
1716
|
*/
|
|
1664
1717
|
private async runValidations(
|
|
1665
1718
|
tx: Tx,
|
|
1666
|
-
messageValidators: Record<string,
|
|
1719
|
+
messageValidators: Record<string, TransactionValidator>,
|
|
1667
1720
|
): Promise<ValidationOutcome> {
|
|
1668
1721
|
const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
|
|
1669
1722
|
const { result } = await validator.validateTx(tx);
|
|
@@ -1672,8 +1725,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1672
1725
|
|
|
1673
1726
|
// A promise that resolves when all validations have been run
|
|
1674
1727
|
const allValidations = await Promise.all(validationPromises);
|
|
1675
|
-
const
|
|
1676
|
-
if (
|
|
1728
|
+
const failures = allValidations.filter(x => !x.isValid);
|
|
1729
|
+
if (failures.length > 0) {
|
|
1730
|
+
// Pick the most severe failure (lowest tolerance = harshest penalty)
|
|
1731
|
+
const failed = maxBy(failures, f => PeerErrorSeverityByHarshness.indexOf(f.severity))!;
|
|
1677
1732
|
return {
|
|
1678
1733
|
allPassed: false,
|
|
1679
1734
|
failure: {
|
|
@@ -1726,31 +1781,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1726
1781
|
return PeerErrorSeverity.HighToleranceError;
|
|
1727
1782
|
}
|
|
1728
1783
|
|
|
1729
|
-
/**
|
|
1730
|
-
* Validate a checkpoint attestation.
|
|
1731
|
-
*
|
|
1732
|
-
* @param attestation - The checkpoint attestation to validate.
|
|
1733
|
-
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1734
|
-
*/
|
|
1735
|
-
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1736
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1737
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1738
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1739
|
-
}))
|
|
1740
|
-
public async validateCheckpointAttestation(
|
|
1741
|
-
peerId: PeerId,
|
|
1742
|
-
attestation: CheckpointAttestation,
|
|
1743
|
-
): Promise<P2PValidationResult> {
|
|
1744
|
-
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1745
|
-
|
|
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
|
-
|
|
1751
|
-
return result;
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
1784
|
public getPeerScore(peerId: PeerId): number {
|
|
1755
1785
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1756
1786
|
}
|