@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
|
@@ -370,14 +370,14 @@ function applyDecs2203RFactory() {
|
|
|
370
370
|
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
|
-
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5,
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _initProto;
|
|
374
374
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
375
|
+
import { maxBy, merge } from '@aztec/foundation/collection';
|
|
375
376
|
import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
376
377
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
377
378
|
import { Timer } from '@aztec/foundation/timer';
|
|
378
379
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
379
|
-
import {
|
|
380
|
-
import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicsForClientAndConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
|
|
380
|
+
import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PMessage, PeerErrorSeverity, PeerErrorSeverityByHarshness, TopicType, createTopicString, getTopicsForConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
|
|
381
381
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
382
382
|
import { Tx } from '@aztec/stdlib/tx';
|
|
383
383
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
@@ -392,11 +392,13 @@ import { identify } from '@libp2p/identify';
|
|
|
392
392
|
import { TopicValidatorResult } from '@libp2p/interface';
|
|
393
393
|
import { mplex } from '@libp2p/mplex';
|
|
394
394
|
import { tcp } from '@libp2p/tcp';
|
|
395
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
395
396
|
import { ENR } from '@nethermindeth/enr';
|
|
396
397
|
import { createLibp2p } from 'libp2p';
|
|
398
|
+
import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
|
|
397
399
|
import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, DoubleSpendTxValidator, FishermanAttestationValidator, getDefaultAllowedSetupFunctions } from '../../msg_validators/index.js';
|
|
398
400
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
399
|
-
import {
|
|
401
|
+
import { createFirstStageTxValidationsForGossipedTransactions, createSecondStageTxValidationsForGossipedTransactions, createTxValidatorForBlockProposalReceivedTxs } from '../../msg_validators/tx_validator/factory.js';
|
|
400
402
|
import { GossipSubEvent } from '../../types/index.js';
|
|
401
403
|
import { convertToMultiaddr } from '../../util.js';
|
|
402
404
|
import { getVersions } from '../../versioning.js';
|
|
@@ -407,8 +409,7 @@ import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring
|
|
|
407
409
|
import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
|
|
408
410
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
409
411
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
410
|
-
import {
|
|
411
|
-
import { pingHandler, reqGoodbyeHandler, reqRespBlockHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
|
|
412
|
+
import { ReqRespSubProtocol, ValidationError, pingHandler, reqGoodbyeHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
|
|
412
413
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
413
414
|
import { P2PInstrumentation } from './instrumentation.js';
|
|
414
415
|
_dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation)=>({
|
|
@@ -426,23 +427,12 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
426
427
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
427
428
|
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
428
429
|
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
429
|
-
})), _dec5 = trackSpan('Libp2pService.
|
|
430
|
+
})), _dec5 = trackSpan('Libp2pService.validateRequestedBlockTxsConsistency', (request)=>({
|
|
430
431
|
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString()
|
|
431
|
-
})), _dec6 = trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx)=>({
|
|
432
|
-
[Attributes.TX_HASH]: requestedTxHash.toString()
|
|
433
|
-
})), _dec7 = trackSpan('Libp2pService.validateRequestedBlock', (requestedBlockNumber, _responseBlock)=>({
|
|
434
|
-
[Attributes.BLOCK_NUMBER]: requestedBlockNumber.toString()
|
|
435
|
-
})), _dec8 = trackSpan('Libp2pService.validatePropagatedTx', (tx)=>({
|
|
436
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
437
|
-
})), _dec9 = trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation)=>({
|
|
438
|
-
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
439
|
-
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
440
|
-
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
441
432
|
}));
|
|
442
433
|
/**
|
|
443
434
|
* Lib P2P implementation of the P2PService interface.
|
|
444
435
|
*/ export class LibP2PService extends WithTracer {
|
|
445
|
-
clientType;
|
|
446
436
|
config;
|
|
447
437
|
node;
|
|
448
438
|
peerDiscoveryService;
|
|
@@ -453,6 +443,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
453
443
|
epochCache;
|
|
454
444
|
proofVerifier;
|
|
455
445
|
worldStateSynchronizer;
|
|
446
|
+
blockMinFeesProvider;
|
|
447
|
+
txValidationCache;
|
|
456
448
|
static{
|
|
457
449
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
458
450
|
[
|
|
@@ -483,27 +475,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
483
475
|
[
|
|
484
476
|
_dec5,
|
|
485
477
|
2,
|
|
486
|
-
"
|
|
487
|
-
],
|
|
488
|
-
[
|
|
489
|
-
_dec6,
|
|
490
|
-
2,
|
|
491
|
-
"validateRequestedTxs"
|
|
492
|
-
],
|
|
493
|
-
[
|
|
494
|
-
_dec7,
|
|
495
|
-
2,
|
|
496
|
-
"validateRequestedBlock"
|
|
497
|
-
],
|
|
498
|
-
[
|
|
499
|
-
_dec8,
|
|
500
|
-
2,
|
|
501
|
-
"validatePropagatedTx"
|
|
502
|
-
],
|
|
503
|
-
[
|
|
504
|
-
_dec9,
|
|
505
|
-
2,
|
|
506
|
-
"validateCheckpointAttestation"
|
|
478
|
+
"validateRequestedBlockTxsConsistency"
|
|
507
479
|
]
|
|
508
480
|
], []));
|
|
509
481
|
}
|
|
@@ -515,9 +487,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
515
487
|
checkpointAttestationValidator;
|
|
516
488
|
protocolVersion;
|
|
517
489
|
topicStrings;
|
|
518
|
-
feesCache;
|
|
519
490
|
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */ duplicateProposalCallback;
|
|
520
491
|
/** Callback invoked when a duplicate attestation is detected (triggers slashing). */ duplicateAttestationCallback;
|
|
492
|
+
/** Callback invoked when a valid checkpoint attestation is accepted into the pool. */ checkpointAttestationCallback;
|
|
521
493
|
/**
|
|
522
494
|
* Callback for when a block is received from a peer.
|
|
523
495
|
* @param block - The block received from the peer.
|
|
@@ -527,13 +499,20 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
527
499
|
* Callback for when a checkpoint proposal is received from a peer.
|
|
528
500
|
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
529
501
|
* @returns The attestations for the checkpoint, if any.
|
|
530
|
-
*/
|
|
502
|
+
*/ allNodesCheckpointReceivedCallback;
|
|
503
|
+
/**
|
|
504
|
+
* Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
|
|
505
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
506
|
+
* @returns The attestations for the checkpoint, if any.
|
|
507
|
+
*/ validatorCheckpointReceivedCallback;
|
|
531
508
|
gossipSubEventHandler;
|
|
509
|
+
ipChangedHandler;
|
|
510
|
+
discoveredP2pIp;
|
|
532
511
|
instrumentation;
|
|
533
512
|
telemetry;
|
|
534
513
|
logger;
|
|
535
|
-
constructor(
|
|
536
|
-
super(telemetry, 'LibP2PService'), this.
|
|
514
|
+
constructor(config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger = createLogger('p2p:libp2p_service'), txValidationCache){
|
|
515
|
+
super(telemetry, 'LibP2PService'), this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.reqresp = reqresp, this.peerManager = peerManager, this.mempools = mempools, this.archiver = archiver, this.epochCache = epochCache, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.blockMinFeesProvider = blockMinFeesProvider, this.txValidationCache = txValidationCache, this.msgIdSeenValidators = (_initProto(this), {}), this.protocolVersion = '', this.topicStrings = {};
|
|
537
516
|
this.telemetry = telemetry;
|
|
538
517
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
539
518
|
this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
|
|
@@ -549,35 +528,51 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
549
528
|
this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
|
|
550
529
|
this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(TopicType.checkpoint_proposal, this.protocolVersion);
|
|
551
530
|
this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(TopicType.checkpoint_attestation, this.protocolVersion);
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
531
|
+
const p2pPropagationTime = config.attestationPropagationTime;
|
|
532
|
+
const proposalValidatorOpts = {
|
|
533
|
+
txsPermitted: !config.disableTransactions,
|
|
534
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
535
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
536
|
+
p2pPropagationTime,
|
|
537
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
538
|
+
signatureContext: {
|
|
539
|
+
chainId: config.l1ChainId,
|
|
540
|
+
rollupAddress: config.rollupAddress
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, proposalValidatorOpts);
|
|
544
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
|
|
545
|
+
const attestationValidatorOpts = {
|
|
546
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
547
|
+
p2pPropagationTime,
|
|
548
|
+
signatureContext: proposalValidatorOpts.signatureContext
|
|
549
|
+
};
|
|
550
|
+
this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry, attestationValidatorOpts) : new CheckpointAttestationValidator(epochCache, attestationValidatorOpts);
|
|
559
551
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
560
552
|
this.blockReceivedCallback = async (block)=>{
|
|
561
|
-
this.logger.
|
|
553
|
+
this.logger.warn(`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`, {
|
|
562
554
|
p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier()
|
|
563
555
|
});
|
|
564
|
-
return
|
|
556
|
+
return true;
|
|
557
|
+
};
|
|
558
|
+
this.allNodesCheckpointReceivedCallback = (_checkpoint)=>{
|
|
559
|
+
throw new CheckpointProposalReceivedCallbackNotRegisteredError();
|
|
565
560
|
};
|
|
566
|
-
this.
|
|
567
|
-
this.logger.debug(`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`);
|
|
561
|
+
this.validatorCheckpointReceivedCallback = (_checkpoint)=>{
|
|
568
562
|
return Promise.resolve(undefined);
|
|
569
563
|
};
|
|
570
564
|
}
|
|
571
565
|
updateConfig(config) {
|
|
572
566
|
this.reqresp.updateConfig(config);
|
|
567
|
+
this.config = merge(this.config, config);
|
|
573
568
|
}
|
|
574
569
|
/**
|
|
575
570
|
* Creates an instance of the LibP2P service.
|
|
576
571
|
* @param config - The configuration to use when creating the service.
|
|
577
572
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
578
573
|
* @returns The new service.
|
|
579
|
-
*/ static async new(
|
|
580
|
-
const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, telemetry, logger, packageVersion } = deps;
|
|
574
|
+
*/ static async new(config, peerId, deps) {
|
|
575
|
+
const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, blockMinFeesProvider, telemetry, logger, packageVersion, txValidationCache } = deps;
|
|
581
576
|
const { p2pPort, maxPeerCount, listenAddress } = config;
|
|
582
577
|
const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
|
|
583
578
|
const datastore = new AztecDatastore(peerStore);
|
|
@@ -617,9 +612,12 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
617
612
|
const l1Constants = epochCache.getL1Constants();
|
|
618
613
|
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
619
614
|
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
615
|
+
ethereumSlotDuration: l1Constants.ethereumSlotDuration,
|
|
620
616
|
heartbeatIntervalMs: config.gossipsubInterval,
|
|
621
617
|
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
622
618
|
blockDurationMs: config.blockDurationMs,
|
|
619
|
+
l1PublishingTime: config.l1PublishingTime,
|
|
620
|
+
p2pPropagationTime: config.attestationPropagationTime,
|
|
623
621
|
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot
|
|
624
622
|
});
|
|
625
623
|
const node = await createLibp2p({
|
|
@@ -726,7 +724,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
726
724
|
})
|
|
727
725
|
}),
|
|
728
726
|
components: (components)=>({
|
|
729
|
-
connectionManager: components.connectionManager
|
|
727
|
+
connectionManager: components.connectionManager,
|
|
728
|
+
addressManager: components.addressManager
|
|
730
729
|
})
|
|
731
730
|
},
|
|
732
731
|
logger: createLibp2pComponentLogger(logger.module, logger.getBindings())
|
|
@@ -734,6 +733,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
734
733
|
const peerScoring = new PeerScoring(config, telemetry);
|
|
735
734
|
const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
|
|
736
735
|
const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
|
|
736
|
+
// Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
|
|
737
|
+
reqresp.setShouldRejectPeer((peerId)=>peerManager.shouldDisableP2PGossip(peerId));
|
|
737
738
|
// Configure application-specific scoring for gossipsub.
|
|
738
739
|
// The weight scales app score to align with gossipsub thresholds:
|
|
739
740
|
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
@@ -741,7 +742,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
741
742
|
// Note: positive topic scores can offset penalties, so alignment is best-effort.
|
|
742
743
|
node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
|
|
743
744
|
node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
744
|
-
return new LibP2PService(
|
|
745
|
+
return new LibP2PService(config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger, txValidationCache);
|
|
745
746
|
}
|
|
746
747
|
/**
|
|
747
748
|
* Starts the LibP2P service.
|
|
@@ -751,22 +752,19 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
751
752
|
if (this.node.status === 'started') {
|
|
752
753
|
throw new Error('P2P service already started');
|
|
753
754
|
}
|
|
754
|
-
// Get listen & announce addresses for logging
|
|
755
755
|
const { p2pIp, p2pPort } = this.config;
|
|
756
|
-
if (!p2pIp) {
|
|
757
|
-
throw new Error('Announce address not provided.');
|
|
756
|
+
if (!p2pIp && !this.config.queryForIp) {
|
|
757
|
+
throw new Error('Announce address not provided and queryForIp is not enabled.');
|
|
758
758
|
}
|
|
759
|
-
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
759
|
+
const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
|
|
760
760
|
// Create request response protocol handlers
|
|
761
761
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
762
762
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
763
|
-
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
764
763
|
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
765
764
|
const requestResponseHandlers = {
|
|
766
765
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
767
766
|
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
768
|
-
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
|
|
769
|
-
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
|
|
767
|
+
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
|
|
770
768
|
};
|
|
771
769
|
if (!this.config.disableTransactions) {
|
|
772
770
|
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.archiver, this.mempools.txPool);
|
|
@@ -775,18 +773,11 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
775
773
|
if (!this.config.disableTransactions) {
|
|
776
774
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
777
775
|
}
|
|
778
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
779
|
-
const reqrespSubProtocolValidators = {
|
|
780
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
781
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
782
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
783
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
|
|
784
|
-
};
|
|
785
776
|
await this.peerManager.initializePeers();
|
|
786
|
-
await this.reqresp.start(requestResponseHandlers
|
|
777
|
+
await this.reqresp.start(requestResponseHandlers);
|
|
787
778
|
await this.node.start();
|
|
788
779
|
// Subscribe to standard GossipSub topics by default
|
|
789
|
-
for (const topic of
|
|
780
|
+
for (const topic of getTopicsForConfig(this.config.disableTransactions)){
|
|
790
781
|
this.subscribeToTopic(this.topicStrings[topic]);
|
|
791
782
|
}
|
|
792
783
|
// add GossipSub listener
|
|
@@ -795,6 +786,34 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
795
786
|
if (!this.config.p2pDiscoveryDisabled) {
|
|
796
787
|
await this.peerDiscoveryService.start();
|
|
797
788
|
}
|
|
789
|
+
// Bridge discv5 IP changes to libp2p's AddressManager so peers see the updated address
|
|
790
|
+
if (this.config.queryForIp) {
|
|
791
|
+
this.discoveredP2pIp = this.config.p2pIp;
|
|
792
|
+
this.logger.info('IP change tracking enabled, bridging discv5 IP updates to libp2p AddressManager');
|
|
793
|
+
this.ipChangedHandler = (ip)=>{
|
|
794
|
+
const addressManager = this.node.services.components.addressManager;
|
|
795
|
+
const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
|
|
796
|
+
const previousIp = this.discoveredP2pIp;
|
|
797
|
+
if (previousIp) {
|
|
798
|
+
const oldAddr = multiaddr(convertToMultiaddr(previousIp, this.config.p2pPort, 'tcp'));
|
|
799
|
+
addressManager.removeObservedAddr(oldAddr);
|
|
800
|
+
this.logger.info('Libp2p announce address updated due to IP change', {
|
|
801
|
+
previousIp,
|
|
802
|
+
newIp: ip,
|
|
803
|
+
newMultiaddr: newAddr.toString()
|
|
804
|
+
});
|
|
805
|
+
} else {
|
|
806
|
+
this.logger.info('Libp2p announce address set from initial discv5 IP discovery', {
|
|
807
|
+
ip,
|
|
808
|
+
multiaddr: newAddr.toString()
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
addressManager.addObservedAddr(newAddr);
|
|
812
|
+
addressManager.confirmObservedAddr(newAddr);
|
|
813
|
+
this.discoveredP2pIp = ip;
|
|
814
|
+
};
|
|
815
|
+
this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
|
|
816
|
+
}
|
|
798
817
|
this.discoveryRunningPromise = new RunningPromise(async ()=>{
|
|
799
818
|
await this.peerManager.heartbeat();
|
|
800
819
|
}, this.logger, this.config.peerCheckIntervalMS);
|
|
@@ -812,6 +831,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
812
831
|
*/ async stop() {
|
|
813
832
|
// Remove gossip sub listener
|
|
814
833
|
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
834
|
+
if (this.ipChangedHandler) {
|
|
835
|
+
this.peerDiscoveryService.removeListener('ip:changed', this.ipChangedHandler);
|
|
836
|
+
this.ipChangedHandler = undefined;
|
|
837
|
+
}
|
|
815
838
|
// Stop peer manager
|
|
816
839
|
this.logger.debug('Stopping peer manager...');
|
|
817
840
|
await this.peerManager.stop();
|
|
@@ -825,8 +848,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
825
848
|
await this.stopLibP2P();
|
|
826
849
|
this.logger.info('LibP2P service stopped');
|
|
827
850
|
}
|
|
828
|
-
addReqRespSubProtocol(subProtocol, handler
|
|
829
|
-
return this.reqresp.addSubProtocol(subProtocol, handler
|
|
851
|
+
addReqRespSubProtocol(subProtocol, handler) {
|
|
852
|
+
return this.reqresp.addSubProtocol(subProtocol, handler);
|
|
830
853
|
}
|
|
831
854
|
registerThisValidatorAddresses(address) {
|
|
832
855
|
this.peerManager.registerThisValidatorAddresses(address);
|
|
@@ -848,14 +871,6 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
848
871
|
};
|
|
849
872
|
setImmediate(()=>void safeJob());
|
|
850
873
|
}
|
|
851
|
-
/**
|
|
852
|
-
* Send a batch of requests to peers, and return the responses
|
|
853
|
-
* @param protocol - The request response protocol to use
|
|
854
|
-
* @param requests - The requests to send to the peers
|
|
855
|
-
* @returns The responses to the requests
|
|
856
|
-
*/ sendBatchRequest(protocol, requests, pinnedPeerId) {
|
|
857
|
-
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
858
|
-
}
|
|
859
874
|
sendRequestToPeer(peerId, subProtocol, payload, dialTimeout) {
|
|
860
875
|
return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
|
|
861
876
|
}
|
|
@@ -868,8 +883,11 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
868
883
|
registerBlockReceivedCallback(callback) {
|
|
869
884
|
this.blockReceivedCallback = callback;
|
|
870
885
|
}
|
|
871
|
-
|
|
872
|
-
this.
|
|
886
|
+
registerValidatorCheckpointReceivedCallback(callback) {
|
|
887
|
+
this.validatorCheckpointReceivedCallback = callback;
|
|
888
|
+
}
|
|
889
|
+
registerAllNodesCheckpointReceivedCallback(callback) {
|
|
890
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
873
891
|
}
|
|
874
892
|
/**
|
|
875
893
|
* Registers a callback to be invoked when a duplicate proposal is detected.
|
|
@@ -884,6 +902,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
884
902
|
*/ registerDuplicateAttestationCallback(callback) {
|
|
885
903
|
this.duplicateAttestationCallback = callback;
|
|
886
904
|
}
|
|
905
|
+
registerCheckpointAttestationCallback(callback) {
|
|
906
|
+
this.checkpointAttestationCallback = callback;
|
|
907
|
+
}
|
|
887
908
|
/**
|
|
888
909
|
* Subscribes to a topic.
|
|
889
910
|
* @param topic - The topic to subscribe to.
|
|
@@ -935,6 +956,12 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
935
956
|
if (!validator || !validator.addMessage(msgId)) {
|
|
936
957
|
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
937
958
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
959
|
+
if (topicType === TopicType.tx) {
|
|
960
|
+
this.logger.verbose(`Ignoring already-seen tx gossip message`, {
|
|
961
|
+
msgId,
|
|
962
|
+
source: source.toString()
|
|
963
|
+
});
|
|
964
|
+
}
|
|
938
965
|
return {
|
|
939
966
|
result: false,
|
|
940
967
|
topicType
|
|
@@ -992,12 +1019,17 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
992
1019
|
}
|
|
993
1020
|
// Process the message, optionally within a linked span for trace propagation
|
|
994
1021
|
const processMessage = async ()=>{
|
|
1022
|
+
if (this.config.skipIncomingProposals && (msg.topic === this.topicStrings[TopicType.block_proposal] || msg.topic === this.topicStrings[TopicType.checkpoint_proposal])) {
|
|
1023
|
+
this.logger.warn(`Ignoring incoming proposal (skipIncomingProposals is set)`, {
|
|
1024
|
+
topic: msg.topic
|
|
1025
|
+
});
|
|
1026
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
995
1029
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
996
1030
|
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
997
1031
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
998
|
-
|
|
999
|
-
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
1000
|
-
}
|
|
1032
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
1001
1033
|
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
1002
1034
|
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
1003
1035
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
@@ -1042,39 +1074,131 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1042
1074
|
return;
|
|
1043
1075
|
}
|
|
1044
1076
|
async validateReceivedMessage(validationFunc, msgId, source, topicType) {
|
|
1077
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
1045
1078
|
let resultAndObj = {
|
|
1046
|
-
result: TopicValidatorResult.Reject
|
|
1079
|
+
result: TopicValidatorResult.Reject,
|
|
1080
|
+
severity: PeerErrorSeverity.MidToleranceError
|
|
1047
1081
|
};
|
|
1048
1082
|
const timer = new Timer();
|
|
1049
1083
|
try {
|
|
1050
1084
|
resultAndObj = await validationFunc();
|
|
1051
1085
|
} catch (err) {
|
|
1052
|
-
this.
|
|
1053
|
-
this.logger.error(`Error deserializing and validating gossipsub message`, err, {
|
|
1086
|
+
this.logger.error(`Error validating gossipsub message`, err, {
|
|
1054
1087
|
msgId,
|
|
1055
1088
|
source: source.toString(),
|
|
1056
1089
|
topicType
|
|
1057
1090
|
});
|
|
1058
1091
|
}
|
|
1092
|
+
const validationTimeMs = timer.ms();
|
|
1093
|
+
const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
|
|
1094
|
+
if (validationTimeMs > mcacheWindowMs * 0.75) {
|
|
1095
|
+
this.instrumentation.incSlowValidation(topicType);
|
|
1096
|
+
this.logger.warn(`Gossip validation for ${topicType} took ${validationTimeMs}ms, approaching mcache eviction window of ${mcacheWindowMs}ms. ` + `Message forwarding may be skipped if validation exceeds the window.`, {
|
|
1097
|
+
msgId,
|
|
1098
|
+
source: source.toString(),
|
|
1099
|
+
topicType,
|
|
1100
|
+
validationTimeMs,
|
|
1101
|
+
mcacheWindowMs
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1059
1104
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
1105
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, {
|
|
1106
|
+
msgId,
|
|
1107
|
+
source: source.toString(),
|
|
1108
|
+
topicType
|
|
1109
|
+
});
|
|
1060
1110
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
1111
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
1112
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
1113
|
+
msgId,
|
|
1114
|
+
source: source.toString(),
|
|
1115
|
+
topicType,
|
|
1116
|
+
severity: resultAndObj.severity
|
|
1117
|
+
});
|
|
1118
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
1119
|
+
} else {
|
|
1120
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, {
|
|
1121
|
+
msgId,
|
|
1122
|
+
source: source.toString(),
|
|
1123
|
+
topicType
|
|
1124
|
+
});
|
|
1061
1125
|
}
|
|
1062
1126
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
1063
1127
|
return resultAndObj;
|
|
1064
1128
|
}
|
|
1129
|
+
tryDeserialize(deserializeFunc, msgId, source) {
|
|
1130
|
+
try {
|
|
1131
|
+
return deserializeFunc();
|
|
1132
|
+
} catch (err) {
|
|
1133
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
1134
|
+
err,
|
|
1135
|
+
msgId,
|
|
1136
|
+
source: source.toString()
|
|
1137
|
+
});
|
|
1138
|
+
return undefined;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1065
1141
|
async handleGossipedTx(payloadData, msgId, source) {
|
|
1066
1142
|
const validationFunc = async ()=>{
|
|
1067
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1143
|
+
const tx = this.tryDeserialize(()=>Tx.fromBuffer(payloadData), msgId, source);
|
|
1144
|
+
if (!tx) {
|
|
1145
|
+
return {
|
|
1146
|
+
result: TopicValidatorResult.Reject,
|
|
1147
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1151
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1152
|
+
// Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
|
|
1153
|
+
const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1154
|
+
const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
|
|
1155
|
+
if (!firstStageOutcome.allPassed) {
|
|
1156
|
+
const { name } = firstStageOutcome.failure;
|
|
1157
|
+
let { severity } = firstStageOutcome.failure;
|
|
1158
|
+
// Double spend validator has a special case handler. We perform more detailed examination
|
|
1159
|
+
// as to how recently the nullifier was entered into the tree and if the transaction should
|
|
1160
|
+
// have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
|
|
1161
|
+
if (name === 'doubleSpendValidator') {
|
|
1162
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1163
|
+
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1164
|
+
}
|
|
1165
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 1 validation failed`, {
|
|
1166
|
+
validator: name,
|
|
1167
|
+
severity,
|
|
1168
|
+
source: source.toString()
|
|
1169
|
+
});
|
|
1170
|
+
return {
|
|
1171
|
+
result: TopicValidatorResult.Reject,
|
|
1172
|
+
severity
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
1176
|
+
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
1177
|
+
if (canAdd === 'ignored') {
|
|
1178
|
+
this.logger.verbose(`Ignoring gossiped tx ${tx.getTxHash().toString()}: pool pre-check returned ignored`, {
|
|
1179
|
+
source: source.toString()
|
|
1180
|
+
});
|
|
1181
|
+
return {
|
|
1182
|
+
result: TopicValidatorResult.Ignore,
|
|
1183
|
+
obj: tx
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
// Stage 2: expensive proof verification
|
|
1187
|
+
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
1188
|
+
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
1189
|
+
if (!secondStageOutcome.allPassed) {
|
|
1190
|
+
const { severity, name } = secondStageOutcome.failure;
|
|
1191
|
+
this.logger.verbose(`Rejecting gossiped tx ${tx.getTxHash().toString()}: stage 2 validation failed`, {
|
|
1192
|
+
validator: name,
|
|
1193
|
+
severity,
|
|
1194
|
+
source: source.toString()
|
|
1072
1195
|
});
|
|
1073
1196
|
return {
|
|
1074
|
-
result: TopicValidatorResult.Reject
|
|
1197
|
+
result: TopicValidatorResult.Reject,
|
|
1198
|
+
severity
|
|
1075
1199
|
};
|
|
1076
1200
|
}
|
|
1077
|
-
//
|
|
1201
|
+
// Pool add: persist the tx
|
|
1078
1202
|
const txHash = tx.getTxHash();
|
|
1079
1203
|
const addResult = await this.mempools.txPool.addPendingTxs([
|
|
1080
1204
|
tx
|
|
@@ -1083,8 +1207,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1083
1207
|
});
|
|
1084
1208
|
const wasAccepted = addResult.accepted.some((h)=>h.equals(txHash));
|
|
1085
1209
|
const wasIgnored = addResult.ignored.some((h)=>h.equals(txHash));
|
|
1086
|
-
this.logger.
|
|
1087
|
-
isValid,
|
|
1210
|
+
this.logger.verbose(`Validate propagated tx ${txHash.toString()}`, {
|
|
1088
1211
|
wasAccepted,
|
|
1089
1212
|
wasIgnored,
|
|
1090
1213
|
[Attributes.P2P_ID]: source.toString()
|
|
@@ -1100,8 +1223,13 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1100
1223
|
obj: tx
|
|
1101
1224
|
};
|
|
1102
1225
|
} else {
|
|
1226
|
+
this.logger.warn(`Gossiped tx ${txHash.toString()} unexpectedly rejected by pool`, {
|
|
1227
|
+
source: source.toString(),
|
|
1228
|
+
txHash: txHash.toString()
|
|
1229
|
+
});
|
|
1103
1230
|
return {
|
|
1104
|
-
result: TopicValidatorResult.Reject
|
|
1231
|
+
result: TopicValidatorResult.Reject,
|
|
1232
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1105
1233
|
};
|
|
1106
1234
|
}
|
|
1107
1235
|
};
|
|
@@ -1122,7 +1250,16 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1122
1250
|
* Process a checkpoint attestation from a peer.
|
|
1123
1251
|
* Validates the attestation and adds it to the pool.
|
|
1124
1252
|
*/ async processCheckpointAttestationFromPeer(payloadData, msgId, source) {
|
|
1125
|
-
const { result, obj: attestation } = await this.validateReceivedMessage(()=>
|
|
1253
|
+
const { result, obj: attestation } = await this.validateReceivedMessage(()=>{
|
|
1254
|
+
const attestation = this.tryDeserialize(()=>CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1255
|
+
if (!attestation) {
|
|
1256
|
+
return Promise.resolve({
|
|
1257
|
+
result: TopicValidatorResult.Reject,
|
|
1258
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1262
|
+
}, msgId, source, TopicType.checkpoint_attestation);
|
|
1126
1263
|
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
1127
1264
|
return;
|
|
1128
1265
|
}
|
|
@@ -1137,9 +1274,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1137
1274
|
const validationResult = await this.checkpointAttestationValidator.validate(attestation);
|
|
1138
1275
|
if (validationResult.result === 'reject') {
|
|
1139
1276
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1140
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1141
1277
|
return {
|
|
1142
|
-
result: TopicValidatorResult.Reject
|
|
1278
|
+
result: TopicValidatorResult.Reject,
|
|
1279
|
+
severity: validationResult.severity
|
|
1143
1280
|
};
|
|
1144
1281
|
}
|
|
1145
1282
|
if (validationResult.result === 'ignore') {
|
|
@@ -1166,9 +1303,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1166
1303
|
obj: attestation
|
|
1167
1304
|
};
|
|
1168
1305
|
}
|
|
1169
|
-
// Could not add (cap reached for signer),
|
|
1306
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1170
1307
|
if (!added) {
|
|
1171
|
-
this.logger.warn(`
|
|
1308
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1172
1309
|
slot: slot.toString(),
|
|
1173
1310
|
archive: attestation.archive.toString(),
|
|
1174
1311
|
source: peerId.toString(),
|
|
@@ -1176,8 +1313,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1176
1313
|
count
|
|
1177
1314
|
});
|
|
1178
1315
|
return {
|
|
1179
|
-
result: TopicValidatorResult.
|
|
1180
|
-
|
|
1316
|
+
result: TopicValidatorResult.Reject,
|
|
1317
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1181
1318
|
};
|
|
1182
1319
|
}
|
|
1183
1320
|
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
@@ -1198,6 +1335,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1198
1335
|
}
|
|
1199
1336
|
}
|
|
1200
1337
|
// Attestation was added successfully - accept it so other nodes can also detect the equivocation
|
|
1338
|
+
this.checkpointAttestationCallback?.(attestation);
|
|
1201
1339
|
return {
|
|
1202
1340
|
result: TopicValidatorResult.Accept,
|
|
1203
1341
|
obj: attestation
|
|
@@ -1215,9 +1353,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1215
1353
|
const validationResult = await this.blockProposalValidator.validate(block);
|
|
1216
1354
|
if (validationResult.result === 'reject') {
|
|
1217
1355
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1218
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1219
1356
|
return {
|
|
1220
|
-
result: TopicValidatorResult.Reject
|
|
1357
|
+
result: TopicValidatorResult.Reject,
|
|
1358
|
+
severity: validationResult.severity
|
|
1221
1359
|
};
|
|
1222
1360
|
}
|
|
1223
1361
|
if (validationResult.result === 'ignore') {
|
|
@@ -1247,7 +1385,6 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1247
1385
|
}
|
|
1248
1386
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1249
1387
|
if (!added) {
|
|
1250
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1251
1388
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1252
1389
|
...block.toBlockInfo(),
|
|
1253
1390
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
@@ -1259,7 +1396,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1259
1396
|
result: TopicValidatorResult.Reject,
|
|
1260
1397
|
metadata: {
|
|
1261
1398
|
isEquivocated
|
|
1262
|
-
}
|
|
1399
|
+
},
|
|
1400
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1263
1401
|
};
|
|
1264
1402
|
}
|
|
1265
1403
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1308,7 +1446,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1308
1446
|
// Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1309
1447
|
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1310
1448
|
if (!isValid) {
|
|
1311
|
-
this.logger.
|
|
1449
|
+
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1312
1450
|
}
|
|
1313
1451
|
}
|
|
1314
1452
|
/**
|
|
@@ -1316,15 +1454,24 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1316
1454
|
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1317
1455
|
*/ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
|
|
1318
1456
|
const { result, obj: checkpoint, metadata: { isEquivocated, processBlock } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
|
|
1457
|
+
// Process checkpoint proposal if valid and not equivocated.
|
|
1458
|
+
const processCheckpointFn = ()=>result === TopicValidatorResult.Accept && checkpoint && !isEquivocated ? this.processValidCheckpointProposal(checkpoint.toCore(), source) : Promise.resolve();
|
|
1319
1459
|
// If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
|
|
1320
1460
|
// TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1461
|
+
const processBlockFn = ()=>processBlock && checkpoint && checkpoint.getBlockProposal() ? this.processValidBlockProposal(checkpoint.getBlockProposal(), source) : Promise.resolve();
|
|
1462
|
+
// A node that skips checkpoint validation attests without re-executing the embedded last block, so run
|
|
1463
|
+
// the checkpoint callback first: this creates and broadcasts the attestation before the block is
|
|
1464
|
+
// processed. Otherwise the block's re-execution — which can stall until the re-execution deadline
|
|
1465
|
+
// waiting for a parent that may never arrive — would delay the attestation past the slot's attestation
|
|
1466
|
+
// window, after which peers reject it as stale.
|
|
1467
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
1468
|
+
await processCheckpointFn();
|
|
1469
|
+
await processBlockFn();
|
|
1325
1470
|
return;
|
|
1326
1471
|
}
|
|
1327
|
-
|
|
1472
|
+
// Process the block first, since it's required for the checkpoint proposal validation.
|
|
1473
|
+
await processBlockFn();
|
|
1474
|
+
await processCheckpointFn();
|
|
1328
1475
|
}
|
|
1329
1476
|
/**
|
|
1330
1477
|
* Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
|
|
@@ -1333,9 +1480,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1333
1480
|
const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1334
1481
|
if (validationResult.result === 'reject') {
|
|
1335
1482
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1336
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1337
1483
|
return {
|
|
1338
|
-
result: TopicValidatorResult.Reject
|
|
1484
|
+
result: TopicValidatorResult.Reject,
|
|
1485
|
+
severity: validationResult.severity
|
|
1339
1486
|
};
|
|
1340
1487
|
}
|
|
1341
1488
|
if (validationResult.result === 'ignore') {
|
|
@@ -1352,18 +1499,20 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1352
1499
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1353
1500
|
[Attributes.P2P_ID]: peerId.toString()
|
|
1354
1501
|
});
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1502
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1503
|
+
const { obj, metadata: { isEquivocated } = {} } = blockProposalResult;
|
|
1504
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1357
1505
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1358
1506
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1359
1507
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1360
1508
|
isEquivocated,
|
|
1361
|
-
result
|
|
1509
|
+
result: blockProposalResult.result
|
|
1362
1510
|
});
|
|
1363
1511
|
return {
|
|
1364
|
-
result: TopicValidatorResult.Reject
|
|
1512
|
+
result: TopicValidatorResult.Reject,
|
|
1513
|
+
severity: 'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError
|
|
1365
1514
|
};
|
|
1366
|
-
} else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1515
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1367
1516
|
processBlock = true;
|
|
1368
1517
|
}
|
|
1369
1518
|
}
|
|
@@ -1390,7 +1539,6 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1390
1539
|
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1391
1540
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1392
1541
|
if (!added) {
|
|
1393
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1394
1542
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1395
1543
|
...checkpoint.toCheckpointInfo(),
|
|
1396
1544
|
count,
|
|
@@ -1402,7 +1550,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1402
1550
|
metadata: {
|
|
1403
1551
|
isEquivocated,
|
|
1404
1552
|
processBlock
|
|
1405
|
-
}
|
|
1553
|
+
},
|
|
1554
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1406
1555
|
};
|
|
1407
1556
|
}
|
|
1408
1557
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1452,9 +1601,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1452
1601
|
archive: checkpoint.archive.toString(),
|
|
1453
1602
|
source: sender.toString()
|
|
1454
1603
|
});
|
|
1604
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1455
1605
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1456
1606
|
// to validate and potentially generate attestations
|
|
1457
|
-
const attestations = await this.
|
|
1607
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1458
1608
|
if (attestations && attestations.length > 0) {
|
|
1459
1609
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1460
1610
|
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
@@ -1478,14 +1628,23 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1478
1628
|
});
|
|
1479
1629
|
}
|
|
1480
1630
|
/**
|
|
1481
|
-
* Validate the requested block transactions
|
|
1631
|
+
* Validate the requested block transactions request-response consistency.
|
|
1632
|
+
* It does NOT validate the transactions themselves.
|
|
1482
1633
|
* @param request - The block transactions request.
|
|
1483
1634
|
* @param response - The block transactions response.
|
|
1484
1635
|
* @param peerId - The ID of the peer that made the request.
|
|
1485
|
-
* @returns True if the
|
|
1486
|
-
*/ async
|
|
1487
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1636
|
+
* @returns True if the request-response is consistent, false otherwise.
|
|
1637
|
+
*/ async validateRequestedBlockTxsConsistency(request, response, peerId) {
|
|
1488
1638
|
try {
|
|
1639
|
+
// A response with archiveRoot=Fr.zero is the documented "I don't have the block" signal from
|
|
1640
|
+
// reqRespBlockTxsHandler (block_txs_handler.ts:54-58): the peer lacked the block in its
|
|
1641
|
+
// attestation pool and archiver, but matched the requested hashes against its tx pool and
|
|
1642
|
+
// shipped what it found. This is legitimate behaviour, not misbehaviour — we just can't verify
|
|
1643
|
+
// membership/order without the block, so we drop the response without penalising the peer.
|
|
1644
|
+
if (response.archiveRoot.isZero()) {
|
|
1645
|
+
this.logger.debug(`Peer ${peerId.toString()} signalled missing block with Fr.zero archive root`);
|
|
1646
|
+
return false;
|
|
1647
|
+
}
|
|
1489
1648
|
if (!response.archiveRoot.equals(request.archiveRoot)) {
|
|
1490
1649
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1491
1650
|
throw new ValidationError(`Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`);
|
|
@@ -1510,18 +1669,25 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1510
1669
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1511
1670
|
throw new ValidationError(`Received more txs (${response.txs.length}) than requested-and-available (${maxReturnable})`);
|
|
1512
1671
|
}
|
|
1513
|
-
//
|
|
1514
|
-
|
|
1515
|
-
|
|
1672
|
+
// To verify membership/order of the returned txs we need the canonical tx hash list for the
|
|
1673
|
+
// block. Prefer the block proposal (held while a block is in flight), but fall back to the
|
|
1674
|
+
// archiver for blocks we only know as mined — e.g. a prover collecting txs to prove a block it
|
|
1675
|
+
// never received a proposal for. This mirrors the responder side (reqRespBlockTxsHandler),
|
|
1676
|
+
// which serves from proposal-or-archiver.
|
|
1677
|
+
const proposal = await this.mempools.attestationPool.getBlockProposalByArchive(request.archiveRoot.toString());
|
|
1678
|
+
const blockTxHashes = proposal?.txHashes ?? (await this.archiver.getBlock({
|
|
1679
|
+
archive: request.archiveRoot
|
|
1680
|
+
}))?.body.txEffects.map((e)=>e.txHash);
|
|
1681
|
+
if (blockTxHashes) {
|
|
1516
1682
|
// Build intersected indices
|
|
1517
1683
|
const intersectIdx = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
|
|
1518
1684
|
// Enforce subset membership and preserve increasing order by index.
|
|
1519
|
-
const
|
|
1685
|
+
const hashToIndexInBlock = new Map(blockTxHashes.map((h, i)=>[
|
|
1520
1686
|
h.toString(),
|
|
1521
1687
|
i
|
|
1522
1688
|
]));
|
|
1523
1689
|
const allowedIndexSet = new Set(intersectIdx);
|
|
1524
|
-
const indices = returnedHashes.map((h)=>
|
|
1690
|
+
const indices = returnedHashes.map((h)=>hashToIndexInBlock.get(h));
|
|
1525
1691
|
const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
|
|
1526
1692
|
const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
|
|
1527
1693
|
if (!allAllowed || !strictlyIncreasing) {
|
|
@@ -1529,11 +1695,11 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1529
1695
|
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
1530
1696
|
}
|
|
1531
1697
|
} else {
|
|
1532
|
-
//
|
|
1533
|
-
|
|
1698
|
+
// Neither a local proposal nor an archived block: we cannot verify membership/order of the
|
|
1699
|
+
// returned txs. This is a local-state gap, not a peer fault, so we do not penalize.
|
|
1700
|
+
this.logger.warn(`Block ${request.archiveRoot.toString()} not found in attestation pool or archiver; cannot validate membership/order of returned txs`);
|
|
1534
1701
|
return false;
|
|
1535
1702
|
}
|
|
1536
|
-
await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
1537
1703
|
return true;
|
|
1538
1704
|
} catch (e) {
|
|
1539
1705
|
if (e instanceof ValidationError) {
|
|
@@ -1544,126 +1710,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1544
1710
|
return false;
|
|
1545
1711
|
}
|
|
1546
1712
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
*
|
|
1550
|
-
* The core component of this validator is that each tx hash MUST match the requested tx hash,
|
|
1551
|
-
* In order to perform this check, the tx proof must be verified.
|
|
1552
|
-
*
|
|
1553
|
-
* Note: This function is called from within `ReqResp.sendRequest` as part of the
|
|
1554
|
-
* ReqRespSubProtocol.TX subprotocol validation.
|
|
1555
|
-
*
|
|
1556
|
-
* @param requestedTxHash - The collection of the txs that was requested.
|
|
1557
|
-
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
1558
|
-
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1559
|
-
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
1560
|
-
*/ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
|
|
1561
|
-
const requested = new Set(requestedTxHash.map((h)=>h.toString()));
|
|
1562
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1563
|
-
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
1564
|
-
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1565
|
-
try {
|
|
1566
|
-
await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
1567
|
-
return true;
|
|
1568
|
-
} catch (e) {
|
|
1569
|
-
if (e instanceof ValidationError) {
|
|
1570
|
-
this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
|
|
1571
|
-
} else {
|
|
1572
|
-
this.logger.error(`Error during validation of requested txs`, e);
|
|
1573
|
-
}
|
|
1574
|
-
return false;
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
/**
|
|
1578
|
-
* Validates a BLOCK response.
|
|
1579
|
-
*
|
|
1580
|
-
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1581
|
-
* Penalizes on block number mismatch or hash mismatch.
|
|
1582
|
-
*
|
|
1583
|
-
* @param requestedBlockNumber - The requested block number.
|
|
1584
|
-
* @param responseBlock - The block returned by the peer.
|
|
1585
|
-
* @param peerId - The peer that returned the block.
|
|
1586
|
-
* @returns True if the response is valid, false otherwise.
|
|
1587
|
-
*/ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
|
|
1588
|
-
try {
|
|
1589
|
-
const reqNum = Number(requestedBlockNumber.toString());
|
|
1590
|
-
if (responseBlock.number !== reqNum) {
|
|
1591
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1592
|
-
return false;
|
|
1593
|
-
}
|
|
1594
|
-
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1595
|
-
if (!local) {
|
|
1596
|
-
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1597
|
-
// TODO: Consider extending this validator to accept an expected hash or
|
|
1598
|
-
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1599
|
-
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1600
|
-
return false;
|
|
1601
|
-
}
|
|
1602
|
-
const [localHash, respHash] = await Promise.all([
|
|
1603
|
-
local.hash(),
|
|
1604
|
-
responseBlock.hash()
|
|
1605
|
-
]);
|
|
1606
|
-
if (!localHash.equals(respHash)) {
|
|
1607
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1608
|
-
return false;
|
|
1609
|
-
}
|
|
1610
|
-
return true;
|
|
1611
|
-
} catch (e) {
|
|
1612
|
-
this.logger.warn(`Error validating requested block`, e);
|
|
1613
|
-
return false;
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
async validateRequestedTx(tx, peerId, txValidator, requested) {
|
|
1617
|
-
const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
|
|
1618
|
-
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1619
|
-
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1620
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
1621
|
-
}
|
|
1622
|
-
const { result } = await txValidator.validateTx(tx);
|
|
1623
|
-
if (result === 'invalid') {
|
|
1624
|
-
penalize(PeerErrorSeverity.LowToleranceError);
|
|
1625
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
createRequestedTxValidator() {
|
|
1629
|
-
return createTxReqRespValidator(this.proofVerifier, {
|
|
1630
|
-
l1ChainId: this.config.l1ChainId,
|
|
1631
|
-
rollupVersion: this.config.rollupVersion
|
|
1632
|
-
});
|
|
1633
|
-
}
|
|
1634
|
-
async validatePropagatedTx(tx, peerId) {
|
|
1635
|
-
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1636
|
-
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1637
|
-
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1638
|
-
const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1639
|
-
for (const validator of messageValidators){
|
|
1640
|
-
const outcome = await this.runValidations(tx, validator);
|
|
1641
|
-
if (outcome.allPassed) {
|
|
1642
|
-
continue;
|
|
1643
|
-
}
|
|
1644
|
-
const { name } = outcome.failure;
|
|
1645
|
-
let { severity } = outcome.failure;
|
|
1646
|
-
// Double spend validator has a special case handler
|
|
1647
|
-
if (name === 'doubleSpendValidator') {
|
|
1648
|
-
const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
|
|
1649
|
-
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1650
|
-
}
|
|
1651
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1652
|
-
return false;
|
|
1653
|
-
}
|
|
1654
|
-
return true;
|
|
1655
|
-
}
|
|
1656
|
-
async getGasFees(blockNumber) {
|
|
1657
|
-
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1658
|
-
return this.feesCache.gasFees;
|
|
1659
|
-
}
|
|
1660
|
-
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
1661
|
-
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
1662
|
-
this.feesCache = {
|
|
1663
|
-
blockNumber,
|
|
1664
|
-
gasFees
|
|
1665
|
-
};
|
|
1666
|
-
return gasFees;
|
|
1713
|
+
getGasFees() {
|
|
1714
|
+
return this.blockMinFeesProvider.getCurrentMinFees();
|
|
1667
1715
|
}
|
|
1668
1716
|
/**
|
|
1669
1717
|
* Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
|
|
@@ -1674,43 +1722,42 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1674
1722
|
txValidatorConfig: {
|
|
1675
1723
|
l1ChainId: this.config.l1ChainId,
|
|
1676
1724
|
rollupVersion: this.config.rollupVersion,
|
|
1677
|
-
proofVerifier: this.proofVerifier
|
|
1725
|
+
proofVerifier: this.proofVerifier,
|
|
1726
|
+
txValidationCache: this.txValidationCache
|
|
1678
1727
|
},
|
|
1679
|
-
peerScoring: this.peerManager
|
|
1728
|
+
peerScoring: this.peerManager,
|
|
1729
|
+
validateRequestedBlockTxsConsistency: this.validateRequestedBlockTxsConsistency.bind(this)
|
|
1680
1730
|
};
|
|
1681
1731
|
}
|
|
1682
|
-
async
|
|
1683
|
-
const
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
await Promise.all(txs.map(async (tx)=>{
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
if (!outcome.allPassed) {
|
|
1691
|
-
throw new Error('Invalid tx detected', {
|
|
1692
|
-
cause: {
|
|
1693
|
-
outcome
|
|
1694
|
-
}
|
|
1695
|
-
});
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1732
|
+
async validateTxsReceivedInBlockProposal(txs) {
|
|
1733
|
+
const validator = createTxValidatorForBlockProposalReceivedTxs(this.proofVerifier, {
|
|
1734
|
+
l1ChainId: this.config.l1ChainId,
|
|
1735
|
+
rollupVersion: this.config.rollupVersion
|
|
1736
|
+
}, this.logger.getBindings(), this.txValidationCache);
|
|
1737
|
+
const results = await Promise.all(txs.map(async (tx)=>{
|
|
1738
|
+
const result = await validator.validateTx(tx);
|
|
1739
|
+
return result.result !== 'invalid';
|
|
1698
1740
|
}));
|
|
1741
|
+
if (results.some((value)=>value === false)) {
|
|
1742
|
+
throw new Error('Invalid tx detected');
|
|
1743
|
+
}
|
|
1699
1744
|
}
|
|
1700
|
-
/**
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1745
|
+
/** Creates the first stage (fast) validators for gossiped transactions. */ async createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp) {
|
|
1746
|
+
const gasFees = await this.getGasFees();
|
|
1747
|
+
const allowedInSetup = [
|
|
1748
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1749
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1750
|
+
];
|
|
1751
|
+
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1752
|
+
const l1Constants = await this.archiver.getL1Constants();
|
|
1753
|
+
return createFirstStageTxValidationsForGossipedTransactions(nextSlotTimestamp, blockNumber, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, !this.config.disableTransactions, allowedInSetup, this.logger.getBindings(), {
|
|
1754
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1755
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1756
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
/** Creates the second stage (expensive proof verification) validators for gossiped transactions. */ createSecondStageMessageValidators() {
|
|
1760
|
+
return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
|
|
1714
1761
|
}
|
|
1715
1762
|
/**
|
|
1716
1763
|
* Run validations on a tx.
|
|
@@ -1728,8 +1775,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1728
1775
|
});
|
|
1729
1776
|
// A promise that resolves when all validations have been run
|
|
1730
1777
|
const allValidations = await Promise.all(validationPromises);
|
|
1731
|
-
const
|
|
1732
|
-
if (
|
|
1778
|
+
const failures = allValidations.filter((x)=>!x.isValid);
|
|
1779
|
+
if (failures.length > 0) {
|
|
1780
|
+
// Pick the most severe failure (lowest tolerance = harshest penalty)
|
|
1781
|
+
const failed = maxBy(failures, (f)=>PeerErrorSeverityByHarshness.indexOf(f.severity));
|
|
1733
1782
|
return {
|
|
1734
1783
|
allPassed: false,
|
|
1735
1784
|
failure: {
|
|
@@ -1776,19 +1825,6 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1776
1825
|
}
|
|
1777
1826
|
return PeerErrorSeverity.HighToleranceError;
|
|
1778
1827
|
}
|
|
1779
|
-
/**
|
|
1780
|
-
* Validate a checkpoint attestation.
|
|
1781
|
-
*
|
|
1782
|
-
* @param attestation - The checkpoint attestation to validate.
|
|
1783
|
-
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1784
|
-
*/ async validateCheckpointAttestation(peerId, attestation) {
|
|
1785
|
-
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1786
|
-
if (result.result === 'reject') {
|
|
1787
|
-
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1788
|
-
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1789
|
-
}
|
|
1790
|
-
return result;
|
|
1791
|
-
}
|
|
1792
1828
|
getPeerScore(peerId) {
|
|
1793
1829
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
1794
1830
|
}
|