@aztec/p2p 5.0.0-private.20260319 → 5.0.0-rc.2
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 +4 -1
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -6
- package/dest/client/factory.d.ts +4 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +33 -24
- package/dest/client/interface.d.ts +43 -11
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +33 -19
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +100 -44
- package/dest/config.d.ts +137 -107
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +64 -23
- 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 +98 -56
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +265 -196
- 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 +175 -59
- 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 +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +17 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +6 -6
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +1 -1
- 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/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +5 -2
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +13 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +7 -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 +10 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +8 -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 +7 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +8 -3
- 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 +153 -111
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -16
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +8 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +2 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +8 -3
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +8 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +25 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +77 -14
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +8 -15
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +3 -3
- 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 +14 -15
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +36 -17
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +47 -10
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +65 -48
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/discv5/discV5_service.d.ts +13 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +119 -23
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +15 -15
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +15 -16
- package/dest/services/encoding.d.ts +8 -8
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +11 -15
- package/dest/services/gossipsub/topic_score_params.d.ts +6 -12
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +4 -14
- 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 +44 -39
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +383 -278
- package/dest/services/peer-manager/peer_manager.d.ts +20 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +79 -23
- package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +102 -13
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -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 +38 -44
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +8 -5
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- 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/bitvector.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +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 +31 -28
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +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 +26 -207
- package/dest/services/service.d.ts +25 -12
- 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/tx_collection.d.ts +35 -51
- 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 +13 -8
- 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 +3 -1
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +3 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +5 -2
- package/dest/test-helpers/mock-pubsub.d.ts +23 -9
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +44 -44
- package/dest/test-helpers/reqresp-nodes.d.ts +4 -5
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +16 -18
- 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 +14 -14
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +25 -13
- 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 +102 -41
- package/dest/testbench/worker_client_manager.d.ts +10 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +51 -9
- package/dest/util.d.ts +11 -6
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +16 -16
- package/src/bootstrap/bootstrap.ts +17 -3
- package/src/client/factory.ts +52 -24
- package/src/client/interface.ts +38 -17
- package/src/client/p2p_client.ts +118 -76
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +130 -31
- 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 +319 -238
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +198 -62
- package/src/mem_pools/attestation_pool/mocks.ts +13 -8
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +5 -1
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +7 -7
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +1 -1
- 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/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +18 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +20 -8
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +12 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +8 -4
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +163 -117
- package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -15
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
- package/src/msg_validators/proposal_validator/README.md +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +15 -3
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +26 -3
- package/src/msg_validators/proposal_validator/proposal_validator.ts +89 -11
- package/src/msg_validators/tx_validator/README.md +13 -3
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -12
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +3 -3
- 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 +44 -20
- package/src/msg_validators/tx_validator/gas_validator.ts +99 -54
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +3 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/data_store.ts +5 -13
- package/src/services/discv5/discV5_service.ts +126 -14
- package/src/services/discv5/persisted_enr_store.ts +158 -0
- package/src/services/dummy_service.ts +20 -39
- package/src/services/encoding.ts +11 -21
- package/src/services/gossipsub/README.md +33 -11
- package/src/services/gossipsub/topic_score_params.ts +9 -18
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +436 -311
- package/src/services/peer-manager/peer_manager.ts +86 -22
- package/src/services/peer-manager/peer_scoring.ts +102 -8
- package/src/services/reqresp/README.md +0 -14
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +42 -52
- package/src/services/reqresp/batch-tx-requester/interface.ts +11 -4
- 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/bitvector.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
- 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 +29 -252
- package/src/services/service.ts +31 -28
- 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/tx_collection.ts +330 -173
- package/src/services/tx_collection/tx_collection_sink.ts +2 -2
- package/src/services/tx_collection/tx_source.ts +10 -8
- package/src/services/tx_file_store/tx_file_store.ts +5 -17
- package/src/services/tx_provider.ts +5 -0
- package/src/test-helpers/make-test-p2p-clients.ts +3 -0
- package/src/test-helpers/mock-pubsub.ts +46 -60
- package/src/test-helpers/reqresp-nodes.ts +12 -22
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +31 -26
- package/src/testbench/p2p_client_testbench_worker.ts +110 -55
- package/src/testbench/worker_client_manager.ts +59 -20
- package/src/util.ts +32 -17
- 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 -123
- 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 -402
- package/dest/msg_validators/clock_tolerance.d.ts +0 -21
- package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
- package/dest/msg_validators/clock_tolerance.js +0 -38
- 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 -51
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -311
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -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 -344
- 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 -163
- 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 -321
- package/src/msg_validators/clock_tolerance.ts +0 -52
- 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 -361
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -108
- package/src/services/tx_collection/slow_tx_collection.ts +0 -266
|
@@ -370,15 +370,17 @@ 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 } from '@aztec/foundation/collection';
|
|
375
|
+
import { compactArray, maxBy, merge } from '@aztec/foundation/collection';
|
|
376
376
|
import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
377
377
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
378
378
|
import { Timer } from '@aztec/foundation/timer';
|
|
379
379
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
380
|
-
import {
|
|
380
|
+
import { DEFAULT_MAX_BLOCKS_PER_CHECKPOINT } from '@aztec/stdlib/config';
|
|
381
|
+
import { getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
381
382
|
import { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PMessage, PeerErrorSeverity, PeerErrorSeverityByHarshness, TopicType, createTopicString, getTopicsForConfig, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
|
|
383
|
+
import { ConsensusTimetable, getDefaultCheckpointProposalSyncGrace } from '@aztec/stdlib/timetable';
|
|
382
384
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
383
385
|
import { Tx } from '@aztec/stdlib/tx';
|
|
384
386
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
@@ -393,24 +395,38 @@ import { identify } from '@libp2p/identify';
|
|
|
393
395
|
import { TopicValidatorResult } from '@libp2p/interface';
|
|
394
396
|
import { mplex } from '@libp2p/mplex';
|
|
395
397
|
import { tcp } from '@libp2p/tcp';
|
|
398
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
396
399
|
import { ENR } from '@nethermindeth/enr';
|
|
397
400
|
import { createLibp2p } from 'libp2p';
|
|
401
|
+
import { CheckpointProposalReceivedCallbackNotRegisteredError } from '../../errors/p2p-service.error.js';
|
|
398
402
|
import { BlockProposalValidator, CheckpointAttestationValidator, CheckpointProposalValidator, DoubleSpendTxValidator, FishermanAttestationValidator, getDefaultAllowedSetupFunctions } from '../../msg_validators/index.js';
|
|
399
403
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
400
|
-
import { createFirstStageTxValidationsForGossipedTransactions, createSecondStageTxValidationsForGossipedTransactions, createTxValidatorForBlockProposalReceivedTxs
|
|
404
|
+
import { createFirstStageTxValidationsForGossipedTransactions, createSecondStageTxValidationsForGossipedTransactions, createTxValidatorForBlockProposalReceivedTxs } from '../../msg_validators/tx_validator/factory.js';
|
|
401
405
|
import { GossipSubEvent } from '../../types/index.js';
|
|
402
406
|
import { convertToMultiaddr } from '../../util.js';
|
|
403
407
|
import { getVersions } from '../../versioning.js';
|
|
404
408
|
import { AztecDatastore } from '../data_store.js';
|
|
405
409
|
import { DiscV5Service } from '../discv5/discV5_service.js';
|
|
406
|
-
import { SnappyTransform,
|
|
410
|
+
import { SnappyTransform, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
407
411
|
import { APP_SPECIFIC_WEIGHT, gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
408
412
|
import { createAllTopicScoreParams } from '../gossipsub/topic_score_params.js';
|
|
409
413
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
410
414
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
411
|
-
import {
|
|
415
|
+
import { ReqRespSubProtocol, ValidationError, pingHandler, reqGoodbyeHandler, reqRespBlockTxsHandler, reqRespStatusHandler, reqRespTxHandler } from '../reqresp/index.js';
|
|
412
416
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
413
417
|
import { P2PInstrumentation } from './instrumentation.js';
|
|
418
|
+
/**
|
|
419
|
+
* Builds the {@link ConsensusTimetable} shared by the gossip validators for proposal/attestation receive-window
|
|
420
|
+
* bounds. Derived purely from protocol slot-timing constants plus the block sub-slot duration and the consensus
|
|
421
|
+
* materialization grace, so every node agrees on these bounds without depending on proposer operational budgets.
|
|
422
|
+
*/ function buildConsensusTimetable(config, l1Constants) {
|
|
423
|
+
const blockDuration = config.blockDurationMs / 1000;
|
|
424
|
+
return new ConsensusTimetable({
|
|
425
|
+
l1Constants,
|
|
426
|
+
blockDuration,
|
|
427
|
+
checkpointProposalSyncGrace: config.checkpointProposalSyncGraceSeconds ?? getDefaultCheckpointProposalSyncGrace(blockDuration)
|
|
428
|
+
});
|
|
429
|
+
}
|
|
414
430
|
_dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId, attestation)=>({
|
|
415
431
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber.toString()
|
|
416
432
|
})), _dec1 = trackSpan('Libp2pService.validateAndStoreBlockProposal', (_peerId, block)=>({
|
|
@@ -426,12 +442,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
426
442
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
427
443
|
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
428
444
|
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then((i)=>i.toString())
|
|
429
|
-
})), _dec5 = trackSpan('Libp2pService.
|
|
445
|
+
})), _dec5 = trackSpan('Libp2pService.validateRequestedBlockTxsConsistency', (request)=>({
|
|
430
446
|
[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
447
|
}));
|
|
436
448
|
/**
|
|
437
449
|
* Lib P2P implementation of the P2PService interface.
|
|
@@ -446,6 +458,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
446
458
|
epochCache;
|
|
447
459
|
proofVerifier;
|
|
448
460
|
worldStateSynchronizer;
|
|
461
|
+
blockMinFeesProvider;
|
|
462
|
+
txValidationCache;
|
|
449
463
|
static{
|
|
450
464
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
451
465
|
[
|
|
@@ -476,17 +490,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
476
490
|
[
|
|
477
491
|
_dec5,
|
|
478
492
|
2,
|
|
479
|
-
"
|
|
480
|
-
],
|
|
481
|
-
[
|
|
482
|
-
_dec6,
|
|
483
|
-
2,
|
|
484
|
-
"validateRequestedTxs"
|
|
485
|
-
],
|
|
486
|
-
[
|
|
487
|
-
_dec7,
|
|
488
|
-
2,
|
|
489
|
-
"validateRequestedBlock"
|
|
493
|
+
"validateRequestedBlockTxsConsistency"
|
|
490
494
|
]
|
|
491
495
|
], []));
|
|
492
496
|
}
|
|
@@ -498,9 +502,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
498
502
|
checkpointAttestationValidator;
|
|
499
503
|
protocolVersion;
|
|
500
504
|
topicStrings;
|
|
501
|
-
feesCache;
|
|
502
505
|
/** Callback invoked when a duplicate proposal is detected (triggers slashing). */ duplicateProposalCallback;
|
|
506
|
+
/** Callback invoked when an oversized block proposal is stored as slashing evidence (triggers slashing). */ oversizedProposalCallback;
|
|
503
507
|
/** Callback invoked when a duplicate attestation is detected (triggers slashing). */ duplicateAttestationCallback;
|
|
508
|
+
/** Callback invoked when a valid checkpoint attestation is accepted into the pool. */ checkpointAttestationCallback;
|
|
504
509
|
/**
|
|
505
510
|
* Callback for when a block is received from a peer.
|
|
506
511
|
* @param block - The block received from the peer.
|
|
@@ -510,13 +515,20 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
510
515
|
* Callback for when a checkpoint proposal is received from a peer.
|
|
511
516
|
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
512
517
|
* @returns The attestations for the checkpoint, if any.
|
|
513
|
-
*/
|
|
518
|
+
*/ allNodesCheckpointReceivedCallback;
|
|
519
|
+
/**
|
|
520
|
+
* Callback for when a checkpoint proposal is received - specifically for validators - from a peer.
|
|
521
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
522
|
+
* @returns The attestations for the checkpoint, if any.
|
|
523
|
+
*/ validatorCheckpointReceivedCallback;
|
|
514
524
|
gossipSubEventHandler;
|
|
525
|
+
ipChangedHandler;
|
|
526
|
+
discoveredP2pIp;
|
|
515
527
|
instrumentation;
|
|
516
528
|
telemetry;
|
|
517
529
|
logger;
|
|
518
|
-
constructor(config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
|
|
519
|
-
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.msgIdSeenValidators = (_initProto(this), {}), this.protocolVersion = '', this.topicStrings = {};
|
|
530
|
+
constructor(config, node, peerDiscoveryService, reqresp, peerManager, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger = createLogger('p2p:libp2p_service'), txValidationCache){
|
|
531
|
+
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 = {};
|
|
520
532
|
this.telemetry = telemetry;
|
|
521
533
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
522
534
|
this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
|
|
@@ -532,13 +544,27 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
532
544
|
this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
|
|
533
545
|
this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(TopicType.checkpoint_proposal, this.protocolVersion);
|
|
534
546
|
this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(TopicType.checkpoint_attestation, this.protocolVersion);
|
|
547
|
+
// Build the consensus timetable once from protocol slot-timing constants and inject it into every
|
|
548
|
+
// validator so they share one set of receive-window bounds, independent of proposer operational budgets.
|
|
549
|
+
const consensusTimetable = buildConsensusTimetable(config, epochCache.getL1Constants());
|
|
535
550
|
const proposalValidatorOpts = {
|
|
536
551
|
txsPermitted: !config.disableTransactions,
|
|
537
|
-
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint
|
|
552
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
|
|
553
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
554
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
555
|
+
signatureContext: {
|
|
556
|
+
chainId: config.l1ChainId,
|
|
557
|
+
rollupAddress: config.rollupAddress
|
|
558
|
+
},
|
|
559
|
+
clockDisparityMs: config.maxGossipClockDisparityMs
|
|
560
|
+
};
|
|
561
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, proposalValidatorOpts);
|
|
562
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, consensusTimetable, proposalValidatorOpts);
|
|
563
|
+
const attestationValidatorOpts = {
|
|
564
|
+
signatureContext: proposalValidatorOpts.signatureContext,
|
|
565
|
+
clockDisparityMs: config.maxGossipClockDisparityMs
|
|
538
566
|
};
|
|
539
|
-
this.
|
|
540
|
-
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, proposalValidatorOpts);
|
|
541
|
-
this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry) : new CheckpointAttestationValidator(epochCache);
|
|
567
|
+
this.checkpointAttestationValidator = config.fishermanMode ? new FishermanAttestationValidator(epochCache, consensusTimetable, mempools.attestationPool, telemetry, attestationValidatorOpts) : new CheckpointAttestationValidator(epochCache, consensusTimetable, attestationValidatorOpts);
|
|
542
568
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
543
569
|
this.blockReceivedCallback = async (block)=>{
|
|
544
570
|
this.logger.warn(`Handler for block received not yet registered on P2P service. Received block ${block.blockNumber} for slot ${block.slotNumber} from peer.`, {
|
|
@@ -546,13 +572,16 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
546
572
|
});
|
|
547
573
|
return true;
|
|
548
574
|
};
|
|
549
|
-
this.
|
|
550
|
-
|
|
575
|
+
this.allNodesCheckpointReceivedCallback = (_checkpoint)=>{
|
|
576
|
+
throw new CheckpointProposalReceivedCallbackNotRegisteredError();
|
|
577
|
+
};
|
|
578
|
+
this.validatorCheckpointReceivedCallback = (_checkpoint)=>{
|
|
551
579
|
return Promise.resolve(undefined);
|
|
552
580
|
};
|
|
553
581
|
}
|
|
554
582
|
updateConfig(config) {
|
|
555
583
|
this.reqresp.updateConfig(config);
|
|
584
|
+
this.config = merge(this.config, config);
|
|
556
585
|
}
|
|
557
586
|
/**
|
|
558
587
|
* Creates an instance of the LibP2P service.
|
|
@@ -560,12 +589,12 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
560
589
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
561
590
|
* @returns The new service.
|
|
562
591
|
*/ static async new(config, peerId, deps) {
|
|
563
|
-
const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, telemetry, logger, packageVersion } = deps;
|
|
592
|
+
const { worldStateSynchronizer, epochCache, l2BlockSource, mempools, proofVerifier, peerStore, blockMinFeesProvider, telemetry, logger, packageVersion, txValidationCache } = deps;
|
|
564
593
|
const { p2pPort, maxPeerCount, listenAddress } = config;
|
|
565
594
|
const bindAddrTcp = convertToMultiaddr(listenAddress, p2pPort, 'tcp');
|
|
566
595
|
const datastore = new AztecDatastore(peerStore);
|
|
567
596
|
const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
|
|
568
|
-
const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`, logger.getBindings()));
|
|
597
|
+
const peerDiscoveryService = new DiscV5Service(peerId, config, packageVersion, telemetry, createLogger(`${logger.module}:discv5_service`, logger.getBindings()), peerStore);
|
|
569
598
|
// Seed libp2p's bootstrap discovery with private and trusted peers
|
|
570
599
|
const bootstrapNodes = [
|
|
571
600
|
...config.privatePeers,
|
|
@@ -580,31 +609,45 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
580
609
|
const versions = getVersions(config);
|
|
581
610
|
const protocolVersion = compressComponentVersions(versions);
|
|
582
611
|
const preferredPeersEnrs = config.preferredPeers.map((enr)=>ENR.decodeTxt(enr));
|
|
583
|
-
const directPeers = (await Promise.all(preferredPeersEnrs.map(async (enr)=>{
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
612
|
+
const directPeers = compactArray(await Promise.all(preferredPeersEnrs.map(async (enr)=>{
|
|
613
|
+
try {
|
|
614
|
+
const peerId = await enr.peerId();
|
|
615
|
+
const address = enr.getLocationMultiaddr('tcp');
|
|
616
|
+
if (address === undefined) {
|
|
617
|
+
throw new Error(`Direct peer ${peerId.toString()} has no TCP address, ENR: ${enr.encodeTxt()}`);
|
|
618
|
+
}
|
|
619
|
+
return {
|
|
620
|
+
id: peerId,
|
|
621
|
+
addrs: [
|
|
622
|
+
address
|
|
623
|
+
]
|
|
624
|
+
};
|
|
625
|
+
} catch (err) {
|
|
626
|
+
// A malformed configured ENR shouldn't abort node setup — skip it and log.
|
|
627
|
+
logger.warn(`Skipping preferred peer with invalid ENR`, {
|
|
628
|
+
err
|
|
629
|
+
});
|
|
630
|
+
return undefined;
|
|
588
631
|
}
|
|
589
|
-
|
|
590
|
-
id: peerId,
|
|
591
|
-
addrs: [
|
|
592
|
-
address
|
|
593
|
-
]
|
|
594
|
-
};
|
|
595
|
-
}))).filter((peer)=>peer !== undefined);
|
|
632
|
+
})));
|
|
596
633
|
const announceTcpMultiaddr = config.p2pIp ? [
|
|
597
634
|
convertToMultiaddr(config.p2pIp, p2pPort, 'tcp')
|
|
598
635
|
] : [];
|
|
599
|
-
// Create dynamic topic score params based on network configuration
|
|
636
|
+
// Create dynamic topic score params based on network configuration. Scoring uses the network-wide
|
|
637
|
+
// max-blocks-per-checkpoint config value directly to size expected per-slot message rates; these are
|
|
638
|
+
// peer-rate thresholds, not consensus deadlines, so they need no proposer operational budgets.
|
|
600
639
|
const l1Constants = epochCache.getL1Constants();
|
|
601
640
|
const topicScoreParams = createAllTopicScoreParams(protocolVersion, {
|
|
602
641
|
slotDurationMs: l1Constants.slotDuration * 1000,
|
|
603
642
|
heartbeatIntervalMs: config.gossipsubInterval,
|
|
604
643
|
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
605
|
-
|
|
644
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint ?? DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
|
|
606
645
|
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot
|
|
607
646
|
});
|
|
647
|
+
// Restrict gossipsub to exactly the topics we subscribe to. Without this, an arbitrary-topic
|
|
648
|
+
// message is transformed, msg-id'd and inserted into the seenCache before the subscription check,
|
|
649
|
+
// so a crafted topic colliding on msg id can suppress a real message as a duplicate.
|
|
650
|
+
const allowedTopics = getTopicsForConfig(config.disableTransactions).map((topic)=>createTopicString(topic, protocolVersion));
|
|
608
651
|
const node = await createLibp2p({
|
|
609
652
|
start: false,
|
|
610
653
|
peerId,
|
|
@@ -657,7 +700,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
657
700
|
},
|
|
658
701
|
connectionGater: {
|
|
659
702
|
denyInboundConnection: (maConn)=>{
|
|
660
|
-
const allowed = peerManager.
|
|
703
|
+
const allowed = peerManager.isAddressAllowedToConnect(maConn.remoteAddr.nodeAddress().address);
|
|
661
704
|
if (allowed) {
|
|
662
705
|
return false;
|
|
663
706
|
}
|
|
@@ -667,7 +710,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
667
710
|
denyInboundEncryptedConnection: (peerId, _maConn)=>{
|
|
668
711
|
//NOTE: it is not necessary to check address here because this was already done by
|
|
669
712
|
// denyInboundConnection
|
|
670
|
-
const allowed = peerManager.
|
|
713
|
+
const allowed = peerManager.isPeerAllowedToConnect(peerId);
|
|
671
714
|
if (allowed) {
|
|
672
715
|
return false;
|
|
673
716
|
}
|
|
@@ -694,9 +737,13 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
694
737
|
mcacheLength: config.gossipsubMcacheLength,
|
|
695
738
|
mcacheGossip: config.gossipsubMcacheGossip,
|
|
696
739
|
seenTTL: config.gossipsubSeenTTL,
|
|
740
|
+
allowedTopics,
|
|
741
|
+
// No fastMsgIdFn: the fast-path dedup cache keys on a non-cryptographic 64-bit hash of the
|
|
742
|
+
// raw data only (no topic), so a collision — accidental or engineered via a weak seed — drops
|
|
743
|
+
// a different message with no fallback to the full id. Dedup instead rests solely on the
|
|
744
|
+
// cryptographic, topic-framed msgIdFn below.
|
|
697
745
|
msgIdFn: getMsgIdFn,
|
|
698
746
|
msgIdToStrFn: msgIdToStrFn,
|
|
699
|
-
fastMsgIdFn: fastMsgIdFn,
|
|
700
747
|
dataTransform: new SnappyTransform(),
|
|
701
748
|
metricsRegister: otelMetricsAdapter,
|
|
702
749
|
metricsTopicStrToLabel: metricsTopicStrToLabels(protocolVersion),
|
|
@@ -709,7 +756,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
709
756
|
})
|
|
710
757
|
}),
|
|
711
758
|
components: (components)=>({
|
|
712
|
-
connectionManager: components.connectionManager
|
|
759
|
+
connectionManager: components.connectionManager,
|
|
760
|
+
addressManager: components.addressManager
|
|
713
761
|
})
|
|
714
762
|
},
|
|
715
763
|
logger: createLibp2pComponentLogger(logger.module, logger.getBindings())
|
|
@@ -717,6 +765,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
717
765
|
const peerScoring = new PeerScoring(config, telemetry);
|
|
718
766
|
const reqresp = new ReqResp(config, node, peerScoring, createLogger(`${logger.module}:reqresp`));
|
|
719
767
|
const peerManager = new PeerManager(node, peerDiscoveryService, config, telemetry, createLogger(`${logger.module}:peer_manager`), peerScoring, reqresp, worldStateSynchronizer, protocolVersion, epochCache);
|
|
768
|
+
// Gate req/resp data protocols for unauthenticated peers when p2pAllowOnlyValidators is enabled
|
|
769
|
+
reqresp.setShouldRejectPeer((peerId)=>peerManager.shouldDisableP2PGossip(peerId));
|
|
720
770
|
// Configure application-specific scoring for gossipsub.
|
|
721
771
|
// The weight scales app score to align with gossipsub thresholds:
|
|
722
772
|
// - Disconnect (-50) × 10 = -500 = gossipThreshold (stops receiving gossip)
|
|
@@ -724,7 +774,7 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
724
774
|
// Note: positive topic scores can offset penalties, so alignment is best-effort.
|
|
725
775
|
node.services.pubsub.score.params.appSpecificWeight = APP_SPECIFIC_WEIGHT;
|
|
726
776
|
node.services.pubsub.score.params.appSpecificScore = (peerId)=>peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
727
|
-
return new LibP2PService(config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger);
|
|
777
|
+
return new LibP2PService(config, node, peerDiscoveryService, reqresp, peerManager, mempools, l2BlockSource, epochCache, proofVerifier, worldStateSynchronizer, blockMinFeesProvider, telemetry, logger, txValidationCache);
|
|
728
778
|
}
|
|
729
779
|
/**
|
|
730
780
|
* Starts the LibP2P service.
|
|
@@ -734,22 +784,19 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
734
784
|
if (this.node.status === 'started') {
|
|
735
785
|
throw new Error('P2P service already started');
|
|
736
786
|
}
|
|
737
|
-
// Get listen & announce addresses for logging
|
|
738
787
|
const { p2pIp, p2pPort } = this.config;
|
|
739
|
-
if (!p2pIp) {
|
|
740
|
-
throw new Error('Announce address not provided.');
|
|
788
|
+
if (!p2pIp && !this.config.queryForIp) {
|
|
789
|
+
throw new Error('Announce address not provided and queryForIp is not enabled.');
|
|
741
790
|
}
|
|
742
|
-
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
791
|
+
const announceTcpMultiaddr = p2pIp ? convertToMultiaddr(p2pIp, p2pPort, 'tcp') : undefined;
|
|
743
792
|
// Create request response protocol handlers
|
|
744
793
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
745
794
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
746
|
-
const blockHandler = reqRespBlockHandler(this.archiver);
|
|
747
795
|
const statusHandler = reqRespStatusHandler(this.protocolVersion, this.worldStateSynchronizer, this.logger);
|
|
748
796
|
const requestResponseHandlers = {
|
|
749
797
|
[ReqRespSubProtocol.PING]: pingHandler,
|
|
750
798
|
[ReqRespSubProtocol.STATUS]: statusHandler.bind(this),
|
|
751
|
-
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
|
|
752
|
-
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this)
|
|
799
|
+
[ReqRespSubProtocol.GOODBYE]: goodbyeHandler.bind(this)
|
|
753
800
|
};
|
|
754
801
|
if (!this.config.disableTransactions) {
|
|
755
802
|
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.archiver, this.mempools.txPool);
|
|
@@ -758,15 +805,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
758
805
|
if (!this.config.disableTransactions) {
|
|
759
806
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
760
807
|
}
|
|
761
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
762
|
-
const reqrespSubProtocolValidators = {
|
|
763
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
764
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
765
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
766
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this)
|
|
767
|
-
};
|
|
768
808
|
await this.peerManager.initializePeers();
|
|
769
|
-
await this.reqresp.start(requestResponseHandlers
|
|
809
|
+
await this.reqresp.start(requestResponseHandlers);
|
|
770
810
|
await this.node.start();
|
|
771
811
|
// Subscribe to standard GossipSub topics by default
|
|
772
812
|
for (const topic of getTopicsForConfig(this.config.disableTransactions)){
|
|
@@ -778,6 +818,34 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
778
818
|
if (!this.config.p2pDiscoveryDisabled) {
|
|
779
819
|
await this.peerDiscoveryService.start();
|
|
780
820
|
}
|
|
821
|
+
// Bridge discv5 IP changes to libp2p's AddressManager so peers see the updated address
|
|
822
|
+
if (this.config.queryForIp) {
|
|
823
|
+
this.discoveredP2pIp = this.config.p2pIp;
|
|
824
|
+
this.logger.info('IP change tracking enabled, bridging discv5 IP updates to libp2p AddressManager');
|
|
825
|
+
this.ipChangedHandler = (ip)=>{
|
|
826
|
+
const addressManager = this.node.services.components.addressManager;
|
|
827
|
+
const newAddr = multiaddr(convertToMultiaddr(ip, this.config.p2pPort, 'tcp'));
|
|
828
|
+
const previousIp = this.discoveredP2pIp;
|
|
829
|
+
if (previousIp) {
|
|
830
|
+
const oldAddr = multiaddr(convertToMultiaddr(previousIp, this.config.p2pPort, 'tcp'));
|
|
831
|
+
addressManager.removeObservedAddr(oldAddr);
|
|
832
|
+
this.logger.info('Libp2p announce address updated due to IP change', {
|
|
833
|
+
previousIp,
|
|
834
|
+
newIp: ip,
|
|
835
|
+
newMultiaddr: newAddr.toString()
|
|
836
|
+
});
|
|
837
|
+
} else {
|
|
838
|
+
this.logger.info('Libp2p announce address set from initial discv5 IP discovery', {
|
|
839
|
+
ip,
|
|
840
|
+
multiaddr: newAddr.toString()
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
addressManager.addObservedAddr(newAddr);
|
|
844
|
+
addressManager.confirmObservedAddr(newAddr);
|
|
845
|
+
this.discoveredP2pIp = ip;
|
|
846
|
+
};
|
|
847
|
+
this.peerDiscoveryService.on('ip:changed', this.ipChangedHandler);
|
|
848
|
+
}
|
|
781
849
|
this.discoveryRunningPromise = new RunningPromise(async ()=>{
|
|
782
850
|
await this.peerManager.heartbeat();
|
|
783
851
|
}, this.logger, this.config.peerCheckIntervalMS);
|
|
@@ -795,6 +863,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
795
863
|
*/ async stop() {
|
|
796
864
|
// Remove gossip sub listener
|
|
797
865
|
this.node.services.pubsub.removeEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
866
|
+
if (this.ipChangedHandler) {
|
|
867
|
+
this.peerDiscoveryService.removeListener('ip:changed', this.ipChangedHandler);
|
|
868
|
+
this.ipChangedHandler = undefined;
|
|
869
|
+
}
|
|
798
870
|
// Stop peer manager
|
|
799
871
|
this.logger.debug('Stopping peer manager...');
|
|
800
872
|
await this.peerManager.stop();
|
|
@@ -808,8 +880,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
808
880
|
await this.stopLibP2P();
|
|
809
881
|
this.logger.info('LibP2P service stopped');
|
|
810
882
|
}
|
|
811
|
-
addReqRespSubProtocol(subProtocol, handler
|
|
812
|
-
return this.reqresp.addSubProtocol(subProtocol, handler
|
|
883
|
+
addReqRespSubProtocol(subProtocol, handler) {
|
|
884
|
+
return this.reqresp.addSubProtocol(subProtocol, handler);
|
|
813
885
|
}
|
|
814
886
|
registerThisValidatorAddresses(address) {
|
|
815
887
|
this.peerManager.registerThisValidatorAddresses(address);
|
|
@@ -831,14 +903,6 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
831
903
|
};
|
|
832
904
|
setImmediate(()=>void safeJob());
|
|
833
905
|
}
|
|
834
|
-
/**
|
|
835
|
-
* Send a batch of requests to peers, and return the responses
|
|
836
|
-
* @param protocol - The request response protocol to use
|
|
837
|
-
* @param requests - The requests to send to the peers
|
|
838
|
-
* @returns The responses to the requests
|
|
839
|
-
*/ sendBatchRequest(protocol, requests, pinnedPeerId) {
|
|
840
|
-
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
841
|
-
}
|
|
842
906
|
sendRequestToPeer(peerId, subProtocol, payload, dialTimeout) {
|
|
843
907
|
return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
|
|
844
908
|
}
|
|
@@ -851,8 +915,11 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
851
915
|
registerBlockReceivedCallback(callback) {
|
|
852
916
|
this.blockReceivedCallback = callback;
|
|
853
917
|
}
|
|
854
|
-
|
|
855
|
-
this.
|
|
918
|
+
registerValidatorCheckpointReceivedCallback(callback) {
|
|
919
|
+
this.validatorCheckpointReceivedCallback = callback;
|
|
920
|
+
}
|
|
921
|
+
registerAllNodesCheckpointReceivedCallback(callback) {
|
|
922
|
+
this.allNodesCheckpointReceivedCallback = callback;
|
|
856
923
|
}
|
|
857
924
|
/**
|
|
858
925
|
* Registers a callback to be invoked when a duplicate proposal is detected.
|
|
@@ -861,12 +928,20 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
861
928
|
this.duplicateProposalCallback = callback;
|
|
862
929
|
}
|
|
863
930
|
/**
|
|
931
|
+
* Registers a callback to be invoked when an oversized block proposal is stored as slashing evidence.
|
|
932
|
+
*/ registerOversizedProposalCallback(callback) {
|
|
933
|
+
this.oversizedProposalCallback = callback;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
864
936
|
* Registers a callback to be invoked when a duplicate attestation is detected.
|
|
865
937
|
* A validator signing attestations for different proposals at the same slot.
|
|
866
938
|
* This callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
867
939
|
*/ registerDuplicateAttestationCallback(callback) {
|
|
868
940
|
this.duplicateAttestationCallback = callback;
|
|
869
941
|
}
|
|
942
|
+
registerCheckpointAttestationCallback(callback) {
|
|
943
|
+
this.checkpointAttestationCallback = callback;
|
|
944
|
+
}
|
|
870
945
|
/**
|
|
871
946
|
* Subscribes to a topic.
|
|
872
947
|
* @param topic - The topic to subscribe to.
|
|
@@ -981,6 +1056,13 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
981
1056
|
}
|
|
982
1057
|
// Process the message, optionally within a linked span for trace propagation
|
|
983
1058
|
const processMessage = async ()=>{
|
|
1059
|
+
if (this.config.skipIncomingProposals && (msg.topic === this.topicStrings[TopicType.block_proposal] || msg.topic === this.topicStrings[TopicType.checkpoint_proposal])) {
|
|
1060
|
+
this.logger.warn(`Ignoring incoming proposal (skipIncomingProposals is set)`, {
|
|
1061
|
+
topic: msg.topic
|
|
1062
|
+
});
|
|
1063
|
+
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
984
1066
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
985
1067
|
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
986
1068
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
@@ -1029,29 +1111,79 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1029
1111
|
return;
|
|
1030
1112
|
}
|
|
1031
1113
|
async validateReceivedMessage(validationFunc, msgId, source, topicType) {
|
|
1114
|
+
// Default to reject result with a penalty if validation function throws an error
|
|
1032
1115
|
let resultAndObj = {
|
|
1033
|
-
result: TopicValidatorResult.Reject
|
|
1116
|
+
result: TopicValidatorResult.Reject,
|
|
1117
|
+
severity: PeerErrorSeverity.MidToleranceError
|
|
1034
1118
|
};
|
|
1035
1119
|
const timer = new Timer();
|
|
1036
1120
|
try {
|
|
1037
1121
|
resultAndObj = await validationFunc();
|
|
1038
1122
|
} catch (err) {
|
|
1039
|
-
this.
|
|
1040
|
-
this.logger.error(`Error deserializing and validating gossipsub message`, err, {
|
|
1123
|
+
this.logger.error(`Error validating gossipsub message`, err, {
|
|
1041
1124
|
msgId,
|
|
1042
1125
|
source: source.toString(),
|
|
1043
1126
|
topicType
|
|
1044
1127
|
});
|
|
1045
1128
|
}
|
|
1129
|
+
const validationTimeMs = timer.ms();
|
|
1130
|
+
const mcacheWindowMs = this.config.gossipsubMcacheLength * this.config.gossipsubInterval;
|
|
1131
|
+
if (validationTimeMs > mcacheWindowMs * 0.75) {
|
|
1132
|
+
this.instrumentation.incSlowValidation(topicType);
|
|
1133
|
+
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.`, {
|
|
1134
|
+
msgId,
|
|
1135
|
+
source: source.toString(),
|
|
1136
|
+
topicType,
|
|
1137
|
+
validationTimeMs,
|
|
1138
|
+
mcacheWindowMs
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1046
1141
|
if (resultAndObj.result === TopicValidatorResult.Accept) {
|
|
1142
|
+
this.logger.debug(`Message ${topicType} accepted by validator`, {
|
|
1143
|
+
msgId,
|
|
1144
|
+
source: source.toString(),
|
|
1145
|
+
topicType
|
|
1146
|
+
});
|
|
1047
1147
|
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
1148
|
+
} else if (resultAndObj.result === TopicValidatorResult.Reject) {
|
|
1149
|
+
this.logger.warn(`Message ${topicType} rejected by validator with severity ${resultAndObj.severity}`, {
|
|
1150
|
+
msgId,
|
|
1151
|
+
source: source.toString(),
|
|
1152
|
+
topicType,
|
|
1153
|
+
severity: resultAndObj.severity
|
|
1154
|
+
});
|
|
1155
|
+
this.peerManager.penalizePeer(source, resultAndObj.severity);
|
|
1156
|
+
} else {
|
|
1157
|
+
this.logger.trace(`Message ${topicType} ignored by validator`, {
|
|
1158
|
+
msgId,
|
|
1159
|
+
source: source.toString(),
|
|
1160
|
+
topicType
|
|
1161
|
+
});
|
|
1048
1162
|
}
|
|
1049
1163
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result);
|
|
1050
1164
|
return resultAndObj;
|
|
1051
1165
|
}
|
|
1166
|
+
tryDeserialize(deserializeFunc, msgId, source) {
|
|
1167
|
+
try {
|
|
1168
|
+
return deserializeFunc();
|
|
1169
|
+
} catch (err) {
|
|
1170
|
+
this.logger.warn(`Failed to deserialize gossipsub message from buffer`, {
|
|
1171
|
+
err,
|
|
1172
|
+
msgId,
|
|
1173
|
+
source: source.toString()
|
|
1174
|
+
});
|
|
1175
|
+
return undefined;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1052
1178
|
async handleGossipedTx(payloadData, msgId, source) {
|
|
1053
1179
|
const validationFunc = async ()=>{
|
|
1054
|
-
const tx = Tx.fromBuffer(payloadData);
|
|
1180
|
+
const tx = this.tryDeserialize(()=>Tx.fromBuffer(payloadData), msgId, source);
|
|
1181
|
+
if (!tx) {
|
|
1182
|
+
return {
|
|
1183
|
+
result: TopicValidatorResult.Reject,
|
|
1184
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1055
1187
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1056
1188
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1057
1189
|
// Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
|
|
@@ -1072,9 +1204,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1072
1204
|
severity,
|
|
1073
1205
|
source: source.toString()
|
|
1074
1206
|
});
|
|
1075
|
-
this.peerManager.penalizePeer(source, severity);
|
|
1076
1207
|
return {
|
|
1077
|
-
result: TopicValidatorResult.Reject
|
|
1208
|
+
result: TopicValidatorResult.Reject,
|
|
1209
|
+
severity
|
|
1078
1210
|
};
|
|
1079
1211
|
}
|
|
1080
1212
|
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
@@ -1098,9 +1230,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1098
1230
|
severity,
|
|
1099
1231
|
source: source.toString()
|
|
1100
1232
|
});
|
|
1101
|
-
this.peerManager.penalizePeer(source, severity);
|
|
1102
1233
|
return {
|
|
1103
|
-
result: TopicValidatorResult.Reject
|
|
1234
|
+
result: TopicValidatorResult.Reject,
|
|
1235
|
+
severity
|
|
1104
1236
|
};
|
|
1105
1237
|
}
|
|
1106
1238
|
// Pool add: persist the tx
|
|
@@ -1132,9 +1264,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1132
1264
|
source: source.toString(),
|
|
1133
1265
|
txHash: txHash.toString()
|
|
1134
1266
|
});
|
|
1135
|
-
this.peerManager.penalizePeer(source, PeerErrorSeverity.HighToleranceError);
|
|
1136
1267
|
return {
|
|
1137
|
-
result: TopicValidatorResult.Reject
|
|
1268
|
+
result: TopicValidatorResult.Reject,
|
|
1269
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1138
1270
|
};
|
|
1139
1271
|
}
|
|
1140
1272
|
};
|
|
@@ -1155,7 +1287,16 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1155
1287
|
* Process a checkpoint attestation from a peer.
|
|
1156
1288
|
* Validates the attestation and adds it to the pool.
|
|
1157
1289
|
*/ async processCheckpointAttestationFromPeer(payloadData, msgId, source) {
|
|
1158
|
-
const { result, obj: attestation } = await this.validateReceivedMessage(()=>
|
|
1290
|
+
const { result, obj: attestation } = await this.validateReceivedMessage(()=>{
|
|
1291
|
+
const attestation = this.tryDeserialize(()=>CheckpointAttestation.fromBuffer(payloadData), msgId, source);
|
|
1292
|
+
if (!attestation) {
|
|
1293
|
+
return Promise.resolve({
|
|
1294
|
+
result: TopicValidatorResult.Reject,
|
|
1295
|
+
severity: PeerErrorSeverity.LowToleranceError
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
return this.validateAndStoreCheckpointAttestation(source, attestation);
|
|
1299
|
+
}, msgId, source, TopicType.checkpoint_attestation);
|
|
1159
1300
|
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
1160
1301
|
return;
|
|
1161
1302
|
}
|
|
@@ -1170,9 +1311,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1170
1311
|
const validationResult = await this.checkpointAttestationValidator.validate(attestation);
|
|
1171
1312
|
if (validationResult.result === 'reject') {
|
|
1172
1313
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1173
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1174
1314
|
return {
|
|
1175
|
-
result: TopicValidatorResult.Reject
|
|
1315
|
+
result: TopicValidatorResult.Reject,
|
|
1316
|
+
severity: validationResult.severity
|
|
1176
1317
|
};
|
|
1177
1318
|
}
|
|
1178
1319
|
if (validationResult.result === 'ignore') {
|
|
@@ -1199,9 +1340,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1199
1340
|
obj: attestation
|
|
1200
1341
|
};
|
|
1201
1342
|
}
|
|
1202
|
-
// Could not add (cap reached for signer),
|
|
1343
|
+
// Could not add (cap reached for signer), penalize and do not re-broadcast
|
|
1203
1344
|
if (!added) {
|
|
1204
|
-
this.logger.warn(`
|
|
1345
|
+
this.logger.warn(`Rejecting checkpoint attestation due to cap`, {
|
|
1205
1346
|
slot: slot.toString(),
|
|
1206
1347
|
archive: attestation.archive.toString(),
|
|
1207
1348
|
source: peerId.toString(),
|
|
@@ -1209,8 +1350,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1209
1350
|
count
|
|
1210
1351
|
});
|
|
1211
1352
|
return {
|
|
1212
|
-
result: TopicValidatorResult.
|
|
1213
|
-
|
|
1353
|
+
result: TopicValidatorResult.Reject,
|
|
1354
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1214
1355
|
};
|
|
1215
1356
|
}
|
|
1216
1357
|
// Check if this is a duplicate attestation (signer attested to a different proposal at the same slot)
|
|
@@ -1231,15 +1372,17 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1231
1372
|
}
|
|
1232
1373
|
}
|
|
1233
1374
|
// Attestation was added successfully - accept it so other nodes can also detect the equivocation
|
|
1375
|
+
this.checkpointAttestationCallback?.(attestation);
|
|
1234
1376
|
return {
|
|
1235
1377
|
result: TopicValidatorResult.Accept,
|
|
1236
1378
|
obj: attestation
|
|
1237
1379
|
};
|
|
1238
1380
|
}
|
|
1239
1381
|
async processBlockFromPeer(payloadData, msgId, source) {
|
|
1240
|
-
const { result, obj: block, metadata: { isEquivocated } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
|
|
1241
|
-
// If not accepted or
|
|
1242
|
-
|
|
1382
|
+
const { result, obj: block, metadata: { isEquivocated, isOversized } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreBlockProposal(source, BlockProposal.fromBuffer(payloadData)), msgId, source, TopicType.block_proposal);
|
|
1383
|
+
// If not accepted, equivocated, or oversized, return. Oversized proposals are re-broadcast as
|
|
1384
|
+
// slashing evidence but never attested or processed.
|
|
1385
|
+
if (result !== TopicValidatorResult.Accept || !block || isEquivocated || isOversized) {
|
|
1243
1386
|
return;
|
|
1244
1387
|
}
|
|
1245
1388
|
await this.processValidBlockProposal(block, source);
|
|
@@ -1248,9 +1391,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1248
1391
|
const validationResult = await this.blockProposalValidator.validate(block);
|
|
1249
1392
|
if (validationResult.result === 'reject') {
|
|
1250
1393
|
this.logger.warn(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1251
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1252
1394
|
return {
|
|
1253
|
-
result: TopicValidatorResult.Reject
|
|
1395
|
+
result: TopicValidatorResult.Reject,
|
|
1396
|
+
severity: validationResult.severity
|
|
1254
1397
|
};
|
|
1255
1398
|
}
|
|
1256
1399
|
if (validationResult.result === 'ignore') {
|
|
@@ -1262,6 +1405,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1262
1405
|
// Try to add the proposal: this handles existence check, cap check, and adding in one call
|
|
1263
1406
|
const { added, alreadyExists, count } = await this.mempools.attestationPool.tryAddBlockProposal(block);
|
|
1264
1407
|
const isEquivocated = count !== undefined && count > 1;
|
|
1408
|
+
// An oversized proposal (index at or beyond the consensus per-checkpoint limit) is structurally valid
|
|
1409
|
+
// proposer misbehavior: it is stored and re-broadcast as slashing evidence but never processed or
|
|
1410
|
+
// attested to. No-ops when maxBlocksPerCheckpoint is unset (local/test).
|
|
1411
|
+
const isOversized = this.config.maxBlocksPerCheckpoint !== undefined && block.indexWithinCheckpoint >= this.config.maxBlocksPerCheckpoint;
|
|
1265
1412
|
// Duplicate proposal received, no need to re-broadcast
|
|
1266
1413
|
if (alreadyExists) {
|
|
1267
1414
|
this.logger.debug(`Ignoring duplicate block proposal received`, {
|
|
@@ -1274,13 +1421,13 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1274
1421
|
result: TopicValidatorResult.Ignore,
|
|
1275
1422
|
obj: block,
|
|
1276
1423
|
metadata: {
|
|
1277
|
-
isEquivocated
|
|
1424
|
+
isEquivocated,
|
|
1425
|
+
isOversized
|
|
1278
1426
|
}
|
|
1279
1427
|
};
|
|
1280
1428
|
}
|
|
1281
1429
|
// Too many blocks received for this slot and index, penalize peer and do not re-broadcast
|
|
1282
1430
|
if (!added) {
|
|
1283
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1284
1431
|
this.logger.warn(`Penalizing peer for block proposal exceeding per-position cap`, {
|
|
1285
1432
|
...block.toBlockInfo(),
|
|
1286
1433
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
@@ -1291,10 +1438,30 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1291
1438
|
return {
|
|
1292
1439
|
result: TopicValidatorResult.Reject,
|
|
1293
1440
|
metadata: {
|
|
1294
|
-
isEquivocated
|
|
1295
|
-
|
|
1441
|
+
isEquivocated,
|
|
1442
|
+
isOversized
|
|
1443
|
+
},
|
|
1444
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1296
1445
|
};
|
|
1297
1446
|
}
|
|
1447
|
+
// The proposal was stored: if oversized, invoke the oversized callback so the proposer can be
|
|
1448
|
+
// slashed. Fired alongside (not instead of) equivocation detection below.
|
|
1449
|
+
if (isOversized) {
|
|
1450
|
+
const proposer = block.getSender();
|
|
1451
|
+
if (proposer) {
|
|
1452
|
+
this.logger.warn(`Detected oversized block proposal at slot ${block.slotNumber}`, {
|
|
1453
|
+
...block.toBlockInfo(),
|
|
1454
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1455
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint,
|
|
1456
|
+
source: peerId.toString(),
|
|
1457
|
+
proposer: proposer.toString()
|
|
1458
|
+
});
|
|
1459
|
+
this.oversizedProposalCallback?.({
|
|
1460
|
+
slot: block.slotNumber,
|
|
1461
|
+
proposer
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1298
1465
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
1299
1466
|
// and do re-broadcast it so other nodes in the network know to slash the proposer
|
|
1300
1467
|
if (isEquivocated) {
|
|
@@ -1316,14 +1483,19 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1316
1483
|
result: TopicValidatorResult.Accept,
|
|
1317
1484
|
obj: block,
|
|
1318
1485
|
metadata: {
|
|
1319
|
-
isEquivocated
|
|
1486
|
+
isEquivocated,
|
|
1487
|
+
isOversized
|
|
1320
1488
|
}
|
|
1321
1489
|
};
|
|
1322
1490
|
}
|
|
1323
1491
|
// Otherwise, we're good to go!
|
|
1324
1492
|
return {
|
|
1325
1493
|
result: TopicValidatorResult.Accept,
|
|
1326
|
-
obj: block
|
|
1494
|
+
obj: block,
|
|
1495
|
+
metadata: {
|
|
1496
|
+
isEquivocated: false,
|
|
1497
|
+
isOversized
|
|
1498
|
+
}
|
|
1327
1499
|
};
|
|
1328
1500
|
}
|
|
1329
1501
|
// REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
|
|
@@ -1342,22 +1514,35 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1342
1514
|
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1343
1515
|
if (!isValid) {
|
|
1344
1516
|
this.logger.info(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1517
|
+
// Release the protections this proposal created so its txs return to pending. Only entries still
|
|
1518
|
+
// keyed to this slot are cleared, so a tx referenced by a live proposal at another slot stays protected.
|
|
1519
|
+
await this.mempools.txPool.unprotectTxs(block.txHashes, slot);
|
|
1345
1520
|
}
|
|
1346
1521
|
}
|
|
1347
1522
|
/**
|
|
1348
1523
|
* Handle a gossiped checkpoint proposal.
|
|
1349
1524
|
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1350
1525
|
*/ async handleGossipedCheckpointProposal(payloadData, msgId, source) {
|
|
1351
|
-
const { result, obj: checkpoint, metadata: { isEquivocated, processBlock } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
|
|
1526
|
+
const { result, obj: checkpoint, metadata: { isEquivocated, processBlock, isOversized } = {} } = await this.validateReceivedMessage(()=>this.validateAndStoreCheckpointProposal(source, CheckpointProposal.fromBuffer(payloadData)), msgId, source, TopicType.checkpoint_proposal);
|
|
1527
|
+
// An oversized checkpoint is re-broadcast as slashing evidence but never attested or processed.
|
|
1528
|
+
// Process checkpoint proposal if valid and neither equivocated nor oversized.
|
|
1529
|
+
const processCheckpointFn = ()=>result === TopicValidatorResult.Accept && checkpoint && !isEquivocated && !isOversized ? this.processValidCheckpointProposal(checkpoint.toCore(), source) : Promise.resolve();
|
|
1352
1530
|
// If the checkpoint contained a valid last block, we process it even if the checkpoint itself is to be rejected
|
|
1353
1531
|
// TODO(palla/mbps): Is this ok? Should we be considering a block from a checkpoint that was equivocated?
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1532
|
+
const processBlockFn = ()=>processBlock && checkpoint && checkpoint.getBlockProposal() ? this.processValidBlockProposal(checkpoint.getBlockProposal(), source) : Promise.resolve();
|
|
1533
|
+
// A node that skips checkpoint validation attests without re-executing the embedded last block, so run
|
|
1534
|
+
// the checkpoint callback first: this creates and broadcasts the attestation before the block is
|
|
1535
|
+
// processed. Otherwise the block's re-execution — which can stall until the re-execution deadline
|
|
1536
|
+
// waiting for a parent that may never arrive — would delay the attestation past the slot's attestation
|
|
1537
|
+
// window, after which peers reject it as stale.
|
|
1538
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
1539
|
+
await processCheckpointFn();
|
|
1540
|
+
await processBlockFn();
|
|
1358
1541
|
return;
|
|
1359
1542
|
}
|
|
1360
|
-
|
|
1543
|
+
// Process the block first, since it's required for the checkpoint proposal validation.
|
|
1544
|
+
await processBlockFn();
|
|
1545
|
+
await processCheckpointFn();
|
|
1361
1546
|
}
|
|
1362
1547
|
/**
|
|
1363
1548
|
* Validates a checkpoint proposal. Penalizes peer if validation fails. Adds the checkpoint and
|
|
@@ -1366,9 +1551,9 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1366
1551
|
const validationResult = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1367
1552
|
if (validationResult.result === 'reject') {
|
|
1368
1553
|
this.logger.warn(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1369
|
-
this.peerManager.penalizePeer(peerId, validationResult.severity);
|
|
1370
1554
|
return {
|
|
1371
|
-
result: TopicValidatorResult.Reject
|
|
1555
|
+
result: TopicValidatorResult.Reject,
|
|
1556
|
+
severity: validationResult.severity
|
|
1372
1557
|
};
|
|
1373
1558
|
}
|
|
1374
1559
|
if (validationResult.result === 'ignore') {
|
|
@@ -1380,23 +1565,28 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1380
1565
|
// Extract and try to add the block proposal first if present
|
|
1381
1566
|
const blockProposal = checkpoint.getBlockProposal();
|
|
1382
1567
|
let processBlock = false;
|
|
1568
|
+
let isOversized = false;
|
|
1383
1569
|
if (blockProposal) {
|
|
1384
1570
|
this.logger.debug(`Validating block proposal from propagated checkpoint`, {
|
|
1385
1571
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1386
1572
|
[Attributes.P2P_ID]: peerId.toString()
|
|
1387
1573
|
});
|
|
1388
|
-
const
|
|
1389
|
-
|
|
1574
|
+
const blockProposalResult = await this.validateAndStoreBlockProposal(peerId, blockProposal);
|
|
1575
|
+
const { obj, metadata: { isEquivocated, isOversized: blockIsOversized } = {} } = blockProposalResult;
|
|
1576
|
+
isOversized = blockIsOversized ?? false;
|
|
1577
|
+
if (blockProposalResult.result === TopicValidatorResult.Reject || !obj || isEquivocated) {
|
|
1390
1578
|
this.logger.debug(`Rejecting checkpoint due to invalid last block proposal`, {
|
|
1391
1579
|
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1392
1580
|
[Attributes.P2P_ID]: peerId.toString(),
|
|
1393
1581
|
isEquivocated,
|
|
1394
|
-
result
|
|
1582
|
+
result: blockProposalResult.result
|
|
1395
1583
|
});
|
|
1396
1584
|
return {
|
|
1397
|
-
result: TopicValidatorResult.Reject
|
|
1585
|
+
result: TopicValidatorResult.Reject,
|
|
1586
|
+
severity: 'severity' in blockProposalResult ? blockProposalResult.severity : PeerErrorSeverity.MidToleranceError
|
|
1398
1587
|
};
|
|
1399
|
-
} else if (result === TopicValidatorResult.Accept && obj && !isEquivocated) {
|
|
1588
|
+
} else if (blockProposalResult.result === TopicValidatorResult.Accept && obj && !isEquivocated && !isOversized) {
|
|
1589
|
+
// An oversized terminal block is re-broadcast as slashing evidence but never processed.
|
|
1400
1590
|
processBlock = true;
|
|
1401
1591
|
}
|
|
1402
1592
|
}
|
|
@@ -1416,14 +1606,14 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1416
1606
|
obj: checkpoint,
|
|
1417
1607
|
metadata: {
|
|
1418
1608
|
isEquivocated,
|
|
1419
|
-
processBlock
|
|
1609
|
+
processBlock,
|
|
1610
|
+
isOversized
|
|
1420
1611
|
}
|
|
1421
1612
|
};
|
|
1422
1613
|
}
|
|
1423
|
-
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast
|
|
1614
|
+
// Too many checkpoint proposals received for this slot, penalize peer and do not re-broadcast.
|
|
1424
1615
|
// Note: We still return the checkpoint obj so the lastBlock can be processed if valid
|
|
1425
1616
|
if (!added) {
|
|
1426
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
1427
1617
|
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1428
1618
|
...checkpoint.toCheckpointInfo(),
|
|
1429
1619
|
count,
|
|
@@ -1434,8 +1624,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1434
1624
|
obj: checkpoint,
|
|
1435
1625
|
metadata: {
|
|
1436
1626
|
isEquivocated,
|
|
1437
|
-
processBlock
|
|
1438
|
-
|
|
1627
|
+
processBlock,
|
|
1628
|
+
isOversized
|
|
1629
|
+
},
|
|
1630
|
+
severity: PeerErrorSeverity.HighToleranceError
|
|
1439
1631
|
};
|
|
1440
1632
|
}
|
|
1441
1633
|
// If this was a duplicate proposal, do not process it, but do invoke the duplicate callback,
|
|
@@ -1460,7 +1652,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1460
1652
|
obj: checkpoint,
|
|
1461
1653
|
metadata: {
|
|
1462
1654
|
isEquivocated,
|
|
1463
|
-
processBlock
|
|
1655
|
+
processBlock,
|
|
1656
|
+
isOversized
|
|
1464
1657
|
}
|
|
1465
1658
|
};
|
|
1466
1659
|
}
|
|
@@ -1470,7 +1663,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1470
1663
|
obj: checkpoint,
|
|
1471
1664
|
metadata: {
|
|
1472
1665
|
processBlock,
|
|
1473
|
-
isEquivocated
|
|
1666
|
+
isEquivocated,
|
|
1667
|
+
isOversized
|
|
1474
1668
|
}
|
|
1475
1669
|
};
|
|
1476
1670
|
}
|
|
@@ -1485,9 +1679,10 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1485
1679
|
archive: checkpoint.archive.toString(),
|
|
1486
1680
|
source: sender.toString()
|
|
1487
1681
|
});
|
|
1682
|
+
await this.allNodesCheckpointReceivedCallback(checkpoint, sender);
|
|
1488
1683
|
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1489
1684
|
// to validate and potentially generate attestations
|
|
1490
|
-
const attestations = await this.
|
|
1685
|
+
const attestations = await this.validatorCheckpointReceivedCallback(checkpoint, sender);
|
|
1491
1686
|
if (attestations && attestations.length > 0) {
|
|
1492
1687
|
// If the callback returned attestations, add them to the pool and propagate them
|
|
1493
1688
|
await this.mempools.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
@@ -1511,62 +1706,66 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1511
1706
|
});
|
|
1512
1707
|
}
|
|
1513
1708
|
/**
|
|
1514
|
-
* Validate the requested block transactions
|
|
1709
|
+
* Validate the requested block transactions request-response consistency.
|
|
1710
|
+
* It does NOT validate the transactions themselves.
|
|
1515
1711
|
* @param request - The block transactions request.
|
|
1516
1712
|
* @param response - The block transactions response.
|
|
1517
1713
|
* @param peerId - The ID of the peer that made the request.
|
|
1518
|
-
* @returns True if the
|
|
1519
|
-
*/ async
|
|
1520
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1714
|
+
* @returns True if the request-response is consistent, false otherwise.
|
|
1715
|
+
*/ async validateRequestedBlockTxsConsistency(request, response, peerId) {
|
|
1521
1716
|
try {
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
throw new ValidationError(`Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`);
|
|
1525
|
-
}
|
|
1526
|
-
if (response.txIndices.getLength() !== request.txIndices.getLength()) {
|
|
1527
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1528
|
-
throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${request.txIndices.getLength()}, got ${response.txIndices.getLength()}`);
|
|
1529
|
-
}
|
|
1530
|
-
// Check no duplicates and not exceeding returnable count
|
|
1531
|
-
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
1532
|
-
const availableIndices = new Set(response.txIndices.getTrueIndices());
|
|
1533
|
-
const maxReturnable = [
|
|
1534
|
-
...requestedIndices
|
|
1535
|
-
].filter((i)=>availableIndices.has(i)).length;
|
|
1536
|
-
const returnedHashes = await Promise.all(response.txs.map((tx)=>tx.getTxHash().toString()));
|
|
1717
|
+
// Check for duplicates txs (or hashes) in the response.
|
|
1718
|
+
const returnedHashes = response.txs.map((tx)=>tx.getTxHash().toString());
|
|
1537
1719
|
const uniqueReturned = new Set(returnedHashes.map((h)=>h.toString()));
|
|
1538
1720
|
if (uniqueReturned.size !== returnedHashes.length) {
|
|
1539
1721
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1540
1722
|
throw new ValidationError(`Received duplicate txs in block txs response`);
|
|
1541
1723
|
}
|
|
1542
|
-
|
|
1724
|
+
// We get the block tx hashes from the proposal or the archiver.
|
|
1725
|
+
const proposal = await this.mempools.attestationPool.getBlockProposalByArchive(request.archiveRoot.toString());
|
|
1726
|
+
const blockTxHashes = proposal?.txHashes ?? (await this.archiver.getBlock({
|
|
1727
|
+
archive: request.archiveRoot
|
|
1728
|
+
}))?.body.txEffects.map((e)=>e.txHash);
|
|
1729
|
+
// If we don't have the block, we can't verify membership/order of the returned txs.
|
|
1730
|
+
if (!blockTxHashes) {
|
|
1731
|
+
// This shouldn't happen, since we asked for the block (proposal).
|
|
1732
|
+
// Neither a local proposal nor an archived block: we cannot verify membership/order of the
|
|
1733
|
+
// returned txs. This is a local-state gap, not a peer fault, so we do not penalize.
|
|
1734
|
+
this.logger.warn(`Block ${request.archiveRoot.toString()} not found in attestation pool or archiver; cannot validate membership/order of returned txs`);
|
|
1735
|
+
// NOTE: We mark the response as invalid, given the limitations of a true/false return value.
|
|
1736
|
+
return false;
|
|
1737
|
+
}
|
|
1738
|
+
// Verify that the returned tx hashes are a subset of (tx hashes by index) U (explicitly requested tx hashes).
|
|
1739
|
+
const uniqueRequestedHashes = new Set([
|
|
1740
|
+
// tx hashes requested by index.
|
|
1741
|
+
...request.txIndices.getTrueIndices().map((i)=>blockTxHashes[i].toString()),
|
|
1742
|
+
// explicitly requested tx hashes.
|
|
1743
|
+
...request.txHashes.map((h)=>h.toString())
|
|
1744
|
+
]);
|
|
1745
|
+
if (!returnedHashes.every((h)=>uniqueRequestedHashes.has(h))) {
|
|
1746
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1747
|
+
throw new ValidationError('Returned txs should be a subset of (tx hashes by index) U (explicitly requested tx hashes)');
|
|
1748
|
+
}
|
|
1749
|
+
// Tx indices information is optional, but if present, we need to verify a few things.
|
|
1750
|
+
if (!response.peerHasBlock()) {
|
|
1751
|
+
this.logger.debug(`Peer ${peerId.toString()} signalled missing block`);
|
|
1752
|
+
return true;
|
|
1753
|
+
}
|
|
1754
|
+
// If the response has a non-empty bitvector, it needs to be consistent with the number of txs in the block.
|
|
1755
|
+
if (response.txIndices.getLength() !== blockTxHashes.length) {
|
|
1543
1756
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1544
|
-
throw new ValidationError(`Received
|
|
1757
|
+
throw new ValidationError(`Received block txs with mismatched bitvector length: expected ${blockTxHashes.length}, got ${response.txIndices.getLength()}`);
|
|
1545
1758
|
}
|
|
1546
|
-
//
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
]));
|
|
1556
|
-
const allowedIndexSet = new Set(intersectIdx);
|
|
1557
|
-
const indices = returnedHashes.map((h)=>hashToIndexInProposal.get(h));
|
|
1558
|
-
const allAllowed = indices.every((idx)=>idx !== undefined && allowedIndexSet.has(idx));
|
|
1559
|
-
const strictlyIncreasing = indices.every((idx, i)=>i === 0 ? idx !== undefined : idx > indices[i - 1]);
|
|
1560
|
-
if (!allAllowed || !strictlyIncreasing) {
|
|
1561
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1562
|
-
throw new ValidationError('Returned txs do not match expected subset/order for requested indices');
|
|
1563
|
-
}
|
|
1564
|
-
} else {
|
|
1565
|
-
// No local proposal, cannot check the membership/order of the returned txs
|
|
1566
|
-
this.logger.warn(`Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`);
|
|
1567
|
-
return false;
|
|
1759
|
+
// For every index we requested that the peer claims to have (per its bitvector), the
|
|
1760
|
+
// corresponding tx must be present in the response. A peer advertising availability but
|
|
1761
|
+
// withholding the tx is inconsistent.
|
|
1762
|
+
const returnedHashSet = new Set(returnedHashes);
|
|
1763
|
+
const expectedIndices = request.txIndices.getTrueIndices().filter((i)=>response.txIndices.isSet(i));
|
|
1764
|
+
const missingExpected = expectedIndices.some((i)=>!returnedHashSet.has(blockTxHashes[i].toString()));
|
|
1765
|
+
if (missingExpected) {
|
|
1766
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1767
|
+
throw new ValidationError('Peer advertised requested txs via indices but did not return them');
|
|
1568
1768
|
}
|
|
1569
|
-
await Promise.all(response.txs.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator)));
|
|
1570
1769
|
return true;
|
|
1571
1770
|
} catch (e) {
|
|
1572
1771
|
if (e instanceof ValidationError) {
|
|
@@ -1577,104 +1776,8 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1577
1776
|
return false;
|
|
1578
1777
|
}
|
|
1579
1778
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
*
|
|
1583
|
-
* The core component of this validator is that each tx hash MUST match the requested tx hash,
|
|
1584
|
-
* In order to perform this check, the tx proof must be verified.
|
|
1585
|
-
*
|
|
1586
|
-
* Note: This function is called from within `ReqResp.sendRequest` as part of the
|
|
1587
|
-
* ReqRespSubProtocol.TX subprotocol validation.
|
|
1588
|
-
*
|
|
1589
|
-
* @param requestedTxHash - The collection of the txs that was requested.
|
|
1590
|
-
* @param responseTx - The collection of txs that was received as a response to the request.
|
|
1591
|
-
* @param peerId - The peer ID of the peer that sent the tx.
|
|
1592
|
-
* @returns True if the whole collection of txs is valid, false otherwise.
|
|
1593
|
-
*/ async validateRequestedTxs(requestedTxHash, responseTx, peerId) {
|
|
1594
|
-
const requested = new Set(requestedTxHash.map((h)=>h.toString()));
|
|
1595
|
-
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1596
|
-
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
1597
|
-
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1598
|
-
try {
|
|
1599
|
-
await Promise.all(responseTx.map((tx)=>this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
1600
|
-
return true;
|
|
1601
|
-
} catch (e) {
|
|
1602
|
-
if (e instanceof ValidationError) {
|
|
1603
|
-
this.logger.warn(`Failed to validate requested txs from peer ${peerId.toString()}, reason ${e.message}`);
|
|
1604
|
-
} else {
|
|
1605
|
-
this.logger.error(`Error during validation of requested txs`, e);
|
|
1606
|
-
}
|
|
1607
|
-
return false;
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
/**
|
|
1611
|
-
* Validates a BLOCK response.
|
|
1612
|
-
*
|
|
1613
|
-
* If a local copy exists, enforces hash equality. If missing, rejects (no penalty) since the hash cannot be verified.
|
|
1614
|
-
* Penalizes on block number mismatch or hash mismatch.
|
|
1615
|
-
*
|
|
1616
|
-
* @param requestedBlockNumber - The requested block number.
|
|
1617
|
-
* @param responseBlock - The block returned by the peer.
|
|
1618
|
-
* @param peerId - The peer that returned the block.
|
|
1619
|
-
* @returns True if the response is valid, false otherwise.
|
|
1620
|
-
*/ async validateRequestedBlock(requestedBlockNumber, responseBlock, peerId) {
|
|
1621
|
-
try {
|
|
1622
|
-
const reqNum = Number(requestedBlockNumber.toString());
|
|
1623
|
-
if (responseBlock.number !== reqNum) {
|
|
1624
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
1625
|
-
return false;
|
|
1626
|
-
}
|
|
1627
|
-
const local = await this.archiver.getBlock(BlockNumber(reqNum));
|
|
1628
|
-
if (!local) {
|
|
1629
|
-
// We are missing the local block; we cannot verify the hash yet. Reject without penalizing.
|
|
1630
|
-
// TODO: Consider extending this validator to accept an expected hash or
|
|
1631
|
-
// performing quorum-based checks when using P2P syncing prior to L1 sync.
|
|
1632
|
-
this.logger.warn(`Local block ${reqNum} not found; rejecting BLOCK response without hash verification`);
|
|
1633
|
-
return false;
|
|
1634
|
-
}
|
|
1635
|
-
const [localHash, respHash] = await Promise.all([
|
|
1636
|
-
local.hash(),
|
|
1637
|
-
responseBlock.hash()
|
|
1638
|
-
]);
|
|
1639
|
-
if (!localHash.equals(respHash)) {
|
|
1640
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1641
|
-
return false;
|
|
1642
|
-
}
|
|
1643
|
-
return true;
|
|
1644
|
-
} catch (e) {
|
|
1645
|
-
this.logger.warn(`Error validating requested block`, e);
|
|
1646
|
-
return false;
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
async validateRequestedTx(tx, peerId, txValidator, requested) {
|
|
1650
|
-
const penalize = (severity)=>this.peerManager.penalizePeer(peerId, severity);
|
|
1651
|
-
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1652
|
-
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1653
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
1654
|
-
}
|
|
1655
|
-
const { result } = await txValidator.validateTx(tx);
|
|
1656
|
-
if (result === 'invalid') {
|
|
1657
|
-
penalize(PeerErrorSeverity.LowToleranceError);
|
|
1658
|
-
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that is invalid.`);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
createRequestedTxValidator() {
|
|
1662
|
-
return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
|
|
1663
|
-
l1ChainId: this.config.l1ChainId,
|
|
1664
|
-
rollupVersion: this.config.rollupVersion
|
|
1665
|
-
});
|
|
1666
|
-
}
|
|
1667
|
-
async getGasFees(blockNumber) {
|
|
1668
|
-
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1669
|
-
return this.feesCache.gasFees;
|
|
1670
|
-
}
|
|
1671
|
-
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
1672
|
-
const gasFees = header?.globalVariables.gasFees ?? GasFees.empty();
|
|
1673
|
-
this.feesCache = {
|
|
1674
|
-
blockNumber,
|
|
1675
|
-
gasFees
|
|
1676
|
-
};
|
|
1677
|
-
return gasFees;
|
|
1779
|
+
getGasFees() {
|
|
1780
|
+
return this.blockMinFeesProvider.getCurrentMinFees();
|
|
1678
1781
|
}
|
|
1679
1782
|
/**
|
|
1680
1783
|
* Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
|
|
@@ -1685,16 +1788,18 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1685
1788
|
txValidatorConfig: {
|
|
1686
1789
|
l1ChainId: this.config.l1ChainId,
|
|
1687
1790
|
rollupVersion: this.config.rollupVersion,
|
|
1688
|
-
proofVerifier: this.proofVerifier
|
|
1791
|
+
proofVerifier: this.proofVerifier,
|
|
1792
|
+
txValidationCache: this.txValidationCache
|
|
1689
1793
|
},
|
|
1690
|
-
peerScoring: this.peerManager
|
|
1794
|
+
peerScoring: this.peerManager,
|
|
1795
|
+
validateRequestedBlockTxsConsistency: this.validateRequestedBlockTxsConsistency.bind(this)
|
|
1691
1796
|
};
|
|
1692
1797
|
}
|
|
1693
1798
|
async validateTxsReceivedInBlockProposal(txs) {
|
|
1694
1799
|
const validator = createTxValidatorForBlockProposalReceivedTxs(this.proofVerifier, {
|
|
1695
1800
|
l1ChainId: this.config.l1ChainId,
|
|
1696
1801
|
rollupVersion: this.config.rollupVersion
|
|
1697
|
-
}, this.logger.getBindings());
|
|
1802
|
+
}, this.logger.getBindings(), this.txValidationCache);
|
|
1698
1803
|
const results = await Promise.all(txs.map(async (tx)=>{
|
|
1699
1804
|
const result = await validator.validateTx(tx);
|
|
1700
1805
|
return result.result !== 'invalid';
|
|
@@ -1704,17 +1809,17 @@ _dec = trackSpan('Libp2pService.validateAndStoreCheckpointAttestation', (_peerId
|
|
|
1704
1809
|
}
|
|
1705
1810
|
}
|
|
1706
1811
|
/** Creates the first stage (fast) validators for gossiped transactions. */ async createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp) {
|
|
1707
|
-
const gasFees = await this.getGasFees(
|
|
1812
|
+
const gasFees = await this.getGasFees();
|
|
1708
1813
|
const allowedInSetup = [
|
|
1709
1814
|
...await getDefaultAllowedSetupFunctions(),
|
|
1710
1815
|
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1711
1816
|
];
|
|
1712
1817
|
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1713
1818
|
const l1Constants = await this.archiver.getL1Constants();
|
|
1819
|
+
const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
|
|
1714
1820
|
return createFirstStageTxValidationsForGossipedTransactions(nextSlotTimestamp, blockNumber, this.worldStateSynchronizer, gasFees, this.config.l1ChainId, this.config.rollupVersion, protocolContractsHash, this.archiver, !this.config.disableTransactions, allowedInSetup, this.logger.getBindings(), {
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1821
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
1822
|
+
maxTxDAGas: networkTxGasLimits.daGas
|
|
1718
1823
|
});
|
|
1719
1824
|
}
|
|
1720
1825
|
/** Creates the second stage (expensive proof verification) validators for gossiped transactions. */ createSecondStageMessageValidators() {
|