@aztec/p2p 0.0.1-commit.c7c42ec → 0.0.1-commit.c80b6263
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/dest/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +4 -4
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +6 -5
- package/dest/client/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +10 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +449 -118
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +8 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +4 -2
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- 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 +237 -263
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +113 -108
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
- package/dest/mem_pools/attestation_pool/mocks.d.ts +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- 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 +5 -14
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +22 -13
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +4 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +21 -11
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/dummy_service.d.ts +18 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +42 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +6 -5
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +30 -72
- package/dest/services/libp2p/libp2p_service.d.ts +36 -13
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +741 -173
- package/dest/services/peer-manager/metrics.d.ts +2 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +21 -26
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +0 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +7 -4
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/interface.d.ts +3 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -21
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
- 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 +14 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +15 -3
- 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 +33 -3
- package/dest/services/reqresp/protocols/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -1
- package/dest/services/reqresp/reqresp.d.ts +6 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +460 -46
- package/dest/services/service.d.ts +19 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +4 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +9 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +16 -5
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- 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 +10 -13
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +8 -8
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +5 -5
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +7 -20
- package/dest/test-helpers/index.d.ts +3 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +2 -0
- package/dest/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +156 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +296 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +218 -124
- package/dest/testbench/worker_client_manager.d.ts +51 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +226 -39
- package/package.json +16 -16
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +6 -10
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +82 -132
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +8 -3
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +19 -13
- package/src/mem_pools/instrumentation.ts +10 -18
- package/src/mem_pools/tx_pool/README.md +28 -13
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +19 -16
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +7 -4
- package/src/msg_validators/tx_validator/data_validator.ts +18 -6
- package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
- package/src/msg_validators/tx_validator/factory.ts +64 -23
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +18 -7
- package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +9 -4
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +51 -0
- package/src/services/encoding.ts +5 -4
- package/src/services/libp2p/instrumentation.ts +32 -73
- package/src/services/libp2p/libp2p_service.ts +404 -154
- package/src/services/peer-manager/metrics.ts +22 -26
- package/src/services/peer-manager/peer_manager.ts +1 -2
- package/src/services/peer-manager/peer_scoring.ts +3 -4
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +3 -0
- package/src/services/reqresp/metrics.ts +36 -27
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +16 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +46 -4
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/reqresp/reqresp.ts +66 -19
- package/src/services/service.ts +23 -4
- package/src/services/tx_collection/config.ts +15 -1
- package/src/services/tx_collection/fast_tx_collection.ts +36 -13
- package/src/services/tx_collection/index.ts +5 -0
- package/src/services/tx_collection/instrumentation.ts +5 -13
- package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +8 -8
- package/src/services/tx_provider.ts +2 -2
- package/src/services/tx_provider_instrumentation.ts +13 -20
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +372 -0
- package/src/testbench/p2p_client_testbench_worker.ts +337 -119
- package/src/testbench/worker_client_manager.ts +304 -42
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { BlockNumber
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { type Logger, createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
7
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
8
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
9
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
10
9
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
11
10
|
import type { EthAddress, L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
11
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
13
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
14
13
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
15
14
|
import {
|
|
16
|
-
BlockAttestation,
|
|
17
15
|
BlockProposal,
|
|
16
|
+
CheckpointAttestation,
|
|
17
|
+
CheckpointProposal,
|
|
18
|
+
type CheckpointProposalCore,
|
|
18
19
|
type Gossipable,
|
|
19
20
|
P2PClientType,
|
|
20
21
|
P2PMessage,
|
|
22
|
+
type ValidationResult as P2PValidationResult,
|
|
21
23
|
PeerErrorSeverity,
|
|
22
24
|
TopicType,
|
|
23
25
|
createTopicString,
|
|
@@ -28,7 +30,14 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
28
30
|
import { Tx, type TxHash, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
29
31
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
30
32
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
31
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
Attributes,
|
|
35
|
+
OtelMetricsAdapter,
|
|
36
|
+
SpanStatusCode,
|
|
37
|
+
type TelemetryClient,
|
|
38
|
+
WithTracer,
|
|
39
|
+
trackSpan,
|
|
40
|
+
} from '@aztec/telemetry-client';
|
|
32
41
|
|
|
33
42
|
import {
|
|
34
43
|
type GossipSub,
|
|
@@ -53,20 +62,19 @@ import type { P2PConfig } from '../../config.js';
|
|
|
53
62
|
import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
|
|
54
63
|
import type { MemPools } from '../../mem_pools/interface.js';
|
|
55
64
|
import {
|
|
56
|
-
AttestationValidator,
|
|
57
65
|
BlockProposalValidator,
|
|
66
|
+
CheckpointAttestationValidator,
|
|
67
|
+
CheckpointProposalValidator,
|
|
58
68
|
FishermanAttestationValidator,
|
|
59
69
|
} from '../../msg_validators/index.js';
|
|
60
70
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
61
71
|
import { getDefaultAllowedSetupFunctions } from '../../msg_validators/tx_validator/allowed_public_setup.js';
|
|
62
|
-
import { type MessageValidator, createTxMessageValidators } from '../../msg_validators/tx_validator/factory.js';
|
|
63
72
|
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} from '../../msg_validators/tx_validator/index.js';
|
|
73
|
+
type MessageValidator,
|
|
74
|
+
createTxMessageValidators,
|
|
75
|
+
createTxReqRespValidator,
|
|
76
|
+
} from '../../msg_validators/tx_validator/factory.js';
|
|
77
|
+
import { DoubleSpendTxValidator } from '../../msg_validators/tx_validator/index.js';
|
|
70
78
|
import { GossipSubEvent } from '../../types/index.js';
|
|
71
79
|
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
72
80
|
import { getVersions } from '../../versioning.js';
|
|
@@ -77,10 +85,12 @@ import { gossipScoreThresholds } from '../gossipsub/scoring.js';
|
|
|
77
85
|
import type { PeerManagerInterface } from '../peer-manager/interface.js';
|
|
78
86
|
import { PeerManager } from '../peer-manager/peer_manager.js';
|
|
79
87
|
import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
88
|
+
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
80
89
|
import type { P2PReqRespConfig } from '../reqresp/config.js';
|
|
81
90
|
import {
|
|
82
91
|
DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
83
92
|
type ReqRespInterface,
|
|
93
|
+
type ReqRespResponse,
|
|
84
94
|
ReqRespSubProtocol,
|
|
85
95
|
type ReqRespSubProtocolHandler,
|
|
86
96
|
type ReqRespSubProtocolHandlers,
|
|
@@ -101,7 +111,12 @@ import {
|
|
|
101
111
|
reqRespTxHandler,
|
|
102
112
|
} from '../reqresp/protocols/index.js';
|
|
103
113
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
104
|
-
import type {
|
|
114
|
+
import type {
|
|
115
|
+
P2PBlockReceivedCallback,
|
|
116
|
+
P2PCheckpointReceivedCallback,
|
|
117
|
+
P2PService,
|
|
118
|
+
PeerDiscoveryService,
|
|
119
|
+
} from '../service.js';
|
|
105
120
|
import { P2PInstrumentation } from './instrumentation.js';
|
|
106
121
|
|
|
107
122
|
interface ValidationResult {
|
|
@@ -125,8 +140,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
125
140
|
private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
|
|
126
141
|
|
|
127
142
|
// Message validators
|
|
128
|
-
private attestationValidator: AttestationValidator;
|
|
129
143
|
private blockProposalValidator: BlockProposalValidator;
|
|
144
|
+
private checkpointProposalValidator: CheckpointProposalValidator;
|
|
145
|
+
private checkpointAttestationValidator: CheckpointAttestationValidator;
|
|
130
146
|
|
|
131
147
|
private protocolVersion = '';
|
|
132
148
|
private topicStrings: Record<TopicType, string> = {} as Record<TopicType, string>;
|
|
@@ -140,10 +156,19 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
140
156
|
*/
|
|
141
157
|
private blockReceivedCallback: P2PBlockReceivedCallback;
|
|
142
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Callback for when a checkpoint proposal is received from a peer.
|
|
161
|
+
* @param checkpoint - The checkpoint proposal received from the peer.
|
|
162
|
+
* @returns The attestations for the checkpoint, if any.
|
|
163
|
+
*/
|
|
164
|
+
private checkpointReceivedCallback: P2PCheckpointReceivedCallback;
|
|
165
|
+
|
|
143
166
|
private gossipSubEventHandler: (e: CustomEvent<GossipsubMessage>) => void;
|
|
144
167
|
|
|
145
168
|
private instrumentation: P2PInstrumentation;
|
|
146
169
|
|
|
170
|
+
private telemetry: TelemetryClient;
|
|
171
|
+
|
|
147
172
|
protected logger: Logger;
|
|
148
173
|
|
|
149
174
|
constructor(
|
|
@@ -162,6 +187,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
162
187
|
logger: Logger = createLogger('p2p:libp2p_service'),
|
|
163
188
|
) {
|
|
164
189
|
super(telemetry, 'LibP2PService');
|
|
190
|
+
this.telemetry = telemetry;
|
|
165
191
|
|
|
166
192
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
167
193
|
this.logger = config.fishermanMode ? logger.createChild('[FISHERMAN]') : logger;
|
|
@@ -170,7 +196,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
170
196
|
|
|
171
197
|
this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
172
198
|
this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
173
|
-
this.msgIdSeenValidators[TopicType.
|
|
199
|
+
this.msgIdSeenValidators[TopicType.checkpoint_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
200
|
+
this.msgIdSeenValidators[TopicType.checkpoint_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
174
201
|
|
|
175
202
|
const versions = getVersions(config);
|
|
176
203
|
this.protocolVersion = compressComponentVersions(versions);
|
|
@@ -178,25 +205,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
178
205
|
|
|
179
206
|
this.topicStrings[TopicType.tx] = createTopicString(TopicType.tx, this.protocolVersion);
|
|
180
207
|
this.topicStrings[TopicType.block_proposal] = createTopicString(TopicType.block_proposal, this.protocolVersion);
|
|
181
|
-
this.topicStrings[TopicType.
|
|
182
|
-
TopicType.
|
|
208
|
+
this.topicStrings[TopicType.checkpoint_proposal] = createTopicString(
|
|
209
|
+
TopicType.checkpoint_proposal,
|
|
210
|
+
this.protocolVersion,
|
|
211
|
+
);
|
|
212
|
+
this.topicStrings[TopicType.checkpoint_attestation] = createTopicString(
|
|
213
|
+
TopicType.checkpoint_attestation,
|
|
183
214
|
this.protocolVersion,
|
|
184
215
|
);
|
|
185
216
|
|
|
186
|
-
// Use FishermanAttestationValidator in fisherman mode to validate attestation payloads against proposals
|
|
187
|
-
this.attestationValidator = config.fishermanMode
|
|
188
|
-
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
189
|
-
: new AttestationValidator(epochCache);
|
|
190
217
|
this.blockProposalValidator = new BlockProposalValidator(epochCache, { txsPermitted: !config.disableTransactions });
|
|
218
|
+
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
|
|
219
|
+
txsPermitted: !config.disableTransactions,
|
|
220
|
+
});
|
|
221
|
+
this.checkpointAttestationValidator = config.fishermanMode
|
|
222
|
+
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
223
|
+
: new CheckpointAttestationValidator(epochCache);
|
|
191
224
|
|
|
192
225
|
this.gossipSubEventHandler = this.handleGossipSubEvent.bind(this);
|
|
193
226
|
|
|
194
|
-
this.blockReceivedCallback = async (block: BlockProposal): Promise<
|
|
227
|
+
this.blockReceivedCallback = async (block: BlockProposal): Promise<boolean> => {
|
|
195
228
|
this.logger.debug(
|
|
196
229
|
`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber} from peer.`,
|
|
197
230
|
{ p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier() },
|
|
198
231
|
);
|
|
199
|
-
return
|
|
232
|
+
return false;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
this.checkpointReceivedCallback = (
|
|
236
|
+
checkpoint: CheckpointProposalCore,
|
|
237
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
238
|
+
this.logger.debug(
|
|
239
|
+
`Handler not yet registered: Checkpoint received callback not set. Received checkpoint for slot ${checkpoint.slotNumber} from peer.`,
|
|
240
|
+
);
|
|
241
|
+
return Promise.resolve(undefined);
|
|
200
242
|
};
|
|
201
243
|
}
|
|
202
244
|
|
|
@@ -242,14 +284,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
242
284
|
|
|
243
285
|
const datastore = new AztecDatastore(peerStore);
|
|
244
286
|
|
|
245
|
-
const otelMetricsAdapter = new OtelMetricsAdapter(telemetry);
|
|
287
|
+
const otelMetricsAdapter = new OtelMetricsAdapter(telemetry, logger.getBindings());
|
|
246
288
|
|
|
247
289
|
const peerDiscoveryService = new DiscV5Service(
|
|
248
290
|
peerId,
|
|
249
291
|
config,
|
|
250
292
|
packageVersion,
|
|
251
293
|
telemetry,
|
|
252
|
-
createLogger(`${logger.module}:discv5_service
|
|
294
|
+
createLogger(`${logger.module}:discv5_service`, logger.getBindings()),
|
|
253
295
|
);
|
|
254
296
|
|
|
255
297
|
// Seed libp2p's bootstrap discovery with private and trusted peers
|
|
@@ -265,7 +307,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
265
307
|
|
|
266
308
|
const txTopic = createTopicString(TopicType.tx, protocolVersion);
|
|
267
309
|
const blockProposalTopic = createTopicString(TopicType.block_proposal, protocolVersion);
|
|
268
|
-
const
|
|
310
|
+
const checkpointProposalTopic = createTopicString(TopicType.checkpoint_proposal, protocolVersion);
|
|
311
|
+
const checkpointAttestationTopic = createTopicString(TopicType.checkpoint_attestation, protocolVersion);
|
|
269
312
|
|
|
270
313
|
const preferredPeersEnrs: ENR[] = config.preferredPeers.map(enr => ENR.decodeTxt(enr));
|
|
271
314
|
const directPeers = (
|
|
@@ -387,12 +430,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
387
430
|
invalidMessageDeliveriesWeight: -20,
|
|
388
431
|
invalidMessageDeliveriesDecay: 0.5,
|
|
389
432
|
}),
|
|
390
|
-
[
|
|
433
|
+
[blockProposalTopic]: createTopicScoreParams({
|
|
391
434
|
topicWeight: 1,
|
|
392
435
|
invalidMessageDeliveriesWeight: -20,
|
|
393
436
|
invalidMessageDeliveriesDecay: 0.5,
|
|
394
437
|
}),
|
|
395
|
-
[
|
|
438
|
+
[checkpointProposalTopic]: createTopicScoreParams({
|
|
439
|
+
topicWeight: 1,
|
|
440
|
+
invalidMessageDeliveriesWeight: -20,
|
|
441
|
+
invalidMessageDeliveriesDecay: 0.5,
|
|
442
|
+
}),
|
|
443
|
+
[checkpointAttestationTopic]: createTopicScoreParams({
|
|
396
444
|
topicWeight: 1,
|
|
397
445
|
invalidMessageDeliveriesWeight: -20,
|
|
398
446
|
invalidMessageDeliveriesDecay: 0.5,
|
|
@@ -404,7 +452,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
404
452
|
connectionManager: components.connectionManager,
|
|
405
453
|
}),
|
|
406
454
|
},
|
|
407
|
-
logger: createLibp2pComponentLogger(logger.module),
|
|
455
|
+
logger: createLibp2pComponentLogger(logger.module, logger.getBindings()),
|
|
408
456
|
});
|
|
409
457
|
|
|
410
458
|
const peerScoring = new PeerScoring(config, telemetry);
|
|
@@ -462,17 +510,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
462
510
|
}
|
|
463
511
|
const announceTcpMultiaddr = convertToMultiaddr(p2pIp, p2pPort, 'tcp');
|
|
464
512
|
|
|
465
|
-
await this.peerManager.initializePeers();
|
|
466
|
-
if (!this.config.p2pDiscoveryDisabled) {
|
|
467
|
-
await this.peerDiscoveryService.start();
|
|
468
|
-
}
|
|
469
|
-
await this.node.start();
|
|
470
|
-
|
|
471
|
-
// Subscribe to standard GossipSub topics by default
|
|
472
|
-
for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
|
|
473
|
-
this.subscribeToTopic(this.topicStrings[topic]);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
513
|
// Create request response protocol handlers
|
|
477
514
|
const txHandler = reqRespTxHandler(this.mempools);
|
|
478
515
|
const goodbyeHandler = reqGoodbyeHandler(this.peerManager);
|
|
@@ -495,10 +532,32 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
495
532
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
496
533
|
}
|
|
497
534
|
|
|
535
|
+
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
536
|
+
const reqrespSubProtocolValidators = {
|
|
537
|
+
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
538
|
+
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
539
|
+
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
540
|
+
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
await this.peerManager.initializePeers();
|
|
544
|
+
|
|
545
|
+
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
546
|
+
|
|
547
|
+
await this.node.start();
|
|
548
|
+
|
|
549
|
+
// Subscribe to standard GossipSub topics by default
|
|
550
|
+
for (const topic of getTopicsForClientAndConfig(this.clientType, this.config.disableTransactions)) {
|
|
551
|
+
this.subscribeToTopic(this.topicStrings[topic]);
|
|
552
|
+
}
|
|
553
|
+
|
|
498
554
|
// add GossipSub listener
|
|
499
555
|
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
500
556
|
|
|
501
557
|
// Start running promise for peer discovery and metrics collection
|
|
558
|
+
if (!this.config.p2pDiscoveryDisabled) {
|
|
559
|
+
await this.peerDiscoveryService.start();
|
|
560
|
+
}
|
|
502
561
|
this.discoveryRunningPromise = new RunningPromise(
|
|
503
562
|
async () => {
|
|
504
563
|
await this.peerManager.heartbeat();
|
|
@@ -508,14 +567,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
508
567
|
);
|
|
509
568
|
this.discoveryRunningPromise.start();
|
|
510
569
|
|
|
511
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
512
|
-
const reqrespSubProtocolValidators = {
|
|
513
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
514
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
515
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
516
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
517
|
-
};
|
|
518
|
-
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
519
570
|
this.logger.info(`Started P2P service`, {
|
|
520
571
|
listen: this.config.listenAddress,
|
|
521
572
|
port: this.config.p2pPort,
|
|
@@ -589,6 +640,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
589
640
|
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
590
641
|
}
|
|
591
642
|
|
|
643
|
+
public sendRequestToPeer(
|
|
644
|
+
peerId: PeerId,
|
|
645
|
+
subProtocol: ReqRespSubProtocol,
|
|
646
|
+
payload: Buffer,
|
|
647
|
+
dialTimeout?: number,
|
|
648
|
+
): Promise<ReqRespResponse> {
|
|
649
|
+
return this.reqresp.sendRequestToPeer(peerId, subProtocol, payload, dialTimeout);
|
|
650
|
+
}
|
|
651
|
+
|
|
592
652
|
/**
|
|
593
653
|
* Get the ENR of the node
|
|
594
654
|
* @returns The ENR of the node
|
|
@@ -601,6 +661,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
601
661
|
this.blockReceivedCallback = callback;
|
|
602
662
|
}
|
|
603
663
|
|
|
664
|
+
public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
665
|
+
this.checkpointReceivedCallback = callback;
|
|
666
|
+
}
|
|
667
|
+
|
|
604
668
|
/**
|
|
605
669
|
* Subscribes to a topic.
|
|
606
670
|
* @param topic - The topic to subscribe to.
|
|
@@ -622,7 +686,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
622
686
|
if (!this.node.services.pubsub) {
|
|
623
687
|
throw new Error('Pubsub service not available.');
|
|
624
688
|
}
|
|
625
|
-
const
|
|
689
|
+
const isBlockProposal = topic === this.topicStrings[TopicType.block_proposal];
|
|
690
|
+
const traceContext =
|
|
691
|
+
this.config.debugP2PInstrumentMessages && isBlockProposal ? this.telemetry.getTraceContext() : undefined;
|
|
692
|
+
const p2pMessage = P2PMessage.fromGossipable(message, this.config.debugP2PInstrumentMessages, traceContext);
|
|
626
693
|
const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
|
|
627
694
|
return result.recipients.length;
|
|
628
695
|
}
|
|
@@ -643,12 +710,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
643
710
|
case this.topicStrings[TopicType.tx]:
|
|
644
711
|
topicType = TopicType.tx;
|
|
645
712
|
break;
|
|
646
|
-
case this.topicStrings[TopicType.block_attestation]:
|
|
647
|
-
topicType = TopicType.block_attestation;
|
|
648
|
-
break;
|
|
649
713
|
case this.topicStrings[TopicType.block_proposal]:
|
|
650
714
|
topicType = TopicType.block_proposal;
|
|
651
715
|
break;
|
|
716
|
+
case this.topicStrings[TopicType.checkpoint_proposal]:
|
|
717
|
+
topicType = TopicType.checkpoint_proposal;
|
|
718
|
+
break;
|
|
719
|
+
case this.topicStrings[TopicType.checkpoint_attestation]:
|
|
720
|
+
topicType = TopicType.checkpoint_attestation;
|
|
721
|
+
break;
|
|
652
722
|
default:
|
|
653
723
|
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
654
724
|
break;
|
|
@@ -707,23 +777,74 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
707
777
|
return;
|
|
708
778
|
}
|
|
709
779
|
|
|
780
|
+
// Determine topic type for attributes
|
|
710
781
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
711
782
|
topicType = TopicType.tx;
|
|
712
|
-
|
|
783
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
784
|
+
topicType = TopicType.checkpoint_attestation;
|
|
785
|
+
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
786
|
+
topicType = TopicType.block_proposal;
|
|
787
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
788
|
+
topicType = TopicType.checkpoint_proposal;
|
|
713
789
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
790
|
+
|
|
791
|
+
// Process the message, optionally within a linked span for trace propagation
|
|
792
|
+
const processMessage = async () => {
|
|
793
|
+
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
794
|
+
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
795
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
796
|
+
if (this.clientType === P2PClientType.Full) {
|
|
797
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
798
|
+
}
|
|
799
|
+
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
800
|
+
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
801
|
+
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
802
|
+
await this.handleGossipedCheckpointProposal(p2pMessage.payload, msgId, source);
|
|
803
|
+
} else {
|
|
804
|
+
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
718
805
|
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
const latency = p2pMessage.timestamp !== undefined ? msgReceivedTime - p2pMessage.timestamp.getTime() : undefined;
|
|
809
|
+
const propagatedContext = p2pMessage.traceContext
|
|
810
|
+
? this.telemetry.extractPropagatedContext(p2pMessage.traceContext)
|
|
811
|
+
: undefined;
|
|
812
|
+
|
|
813
|
+
if (propagatedContext) {
|
|
814
|
+
await this.tracer.startActiveSpan(
|
|
815
|
+
'LibP2PService.processMessage',
|
|
816
|
+
{
|
|
817
|
+
attributes: {
|
|
818
|
+
[Attributes.TOPIC_NAME]: topicType!,
|
|
819
|
+
[Attributes.PEER_ID]: source.toString(),
|
|
820
|
+
},
|
|
821
|
+
},
|
|
822
|
+
propagatedContext,
|
|
823
|
+
async span => {
|
|
824
|
+
try {
|
|
825
|
+
await processMessage();
|
|
826
|
+
span.setStatus({
|
|
827
|
+
code: SpanStatusCode.OK,
|
|
828
|
+
});
|
|
829
|
+
} catch (err) {
|
|
830
|
+
span.setStatus({
|
|
831
|
+
code: SpanStatusCode.ERROR,
|
|
832
|
+
message: String(err),
|
|
833
|
+
});
|
|
834
|
+
if (typeof err === 'string' || (err && err instanceof Error)) {
|
|
835
|
+
span.recordException(err);
|
|
836
|
+
}
|
|
837
|
+
throw err;
|
|
838
|
+
} finally {
|
|
839
|
+
span.end();
|
|
840
|
+
}
|
|
841
|
+
},
|
|
842
|
+
);
|
|
843
|
+
} else {
|
|
844
|
+
await processMessage();
|
|
723
845
|
}
|
|
724
846
|
|
|
725
|
-
if (
|
|
726
|
-
const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
|
|
847
|
+
if (latency !== undefined && topicType !== undefined) {
|
|
727
848
|
this.instrumentation.recordMessageLatency(topicType, latency);
|
|
728
849
|
}
|
|
729
850
|
|
|
@@ -800,27 +921,30 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
800
921
|
}
|
|
801
922
|
|
|
802
923
|
/**
|
|
803
|
-
* Process
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
* @param attestation - The attestation to process.
|
|
924
|
+
* Process a checkpoint attestation from a peer.
|
|
925
|
+
* Validates the attestation and adds it to the pool.
|
|
807
926
|
*/
|
|
808
|
-
private async
|
|
809
|
-
|
|
810
|
-
|
|
927
|
+
private async processCheckpointAttestationFromPeer(
|
|
928
|
+
payloadData: Buffer,
|
|
929
|
+
msgId: string,
|
|
930
|
+
source: PeerId,
|
|
931
|
+
): Promise<void> {
|
|
932
|
+
const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointAttestation>> = async () => {
|
|
933
|
+
const attestation = CheckpointAttestation.fromBuffer(payloadData);
|
|
811
934
|
const pool = this.mempools.attestationPool;
|
|
812
|
-
const
|
|
813
|
-
const
|
|
935
|
+
const validationResult = await this.validateCheckpointAttestation(source, attestation);
|
|
936
|
+
const isValid = validationResult.result === 'accept';
|
|
937
|
+
const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
|
|
814
938
|
|
|
815
939
|
let canAdd = true;
|
|
816
940
|
if (isValid && !exists) {
|
|
817
941
|
const slot = attestation.payload.header.slotNumber;
|
|
818
942
|
const { committee } = await this.epochCache.getCommittee(slot);
|
|
819
943
|
const committeeSize = committee?.length ?? 0;
|
|
820
|
-
canAdd = await pool.
|
|
944
|
+
canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
|
|
821
945
|
}
|
|
822
946
|
|
|
823
|
-
this.logger.trace(`Validate propagated
|
|
947
|
+
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
824
948
|
isValid,
|
|
825
949
|
exists,
|
|
826
950
|
canAdd,
|
|
@@ -828,12 +952,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
828
952
|
[Attributes.P2P_ID]: source.toString(),
|
|
829
953
|
});
|
|
830
954
|
|
|
831
|
-
if (
|
|
955
|
+
if (validationResult.result === 'reject') {
|
|
832
956
|
return { result: TopicValidatorResult.Reject };
|
|
833
|
-
} else if (exists) {
|
|
957
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
834
958
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
835
959
|
} else if (!canAdd) {
|
|
836
|
-
this.logger.warn(`Dropping
|
|
960
|
+
this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
|
|
837
961
|
slot: attestation.payload.header.slotNumber.toString(),
|
|
838
962
|
archive: attestation.archive.toString(),
|
|
839
963
|
source: source.toString(),
|
|
@@ -844,11 +968,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
844
968
|
}
|
|
845
969
|
};
|
|
846
970
|
|
|
847
|
-
const { result, obj: attestation } = await this.validateReceivedMessage<
|
|
971
|
+
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
848
972
|
validationFunc,
|
|
849
973
|
msgId,
|
|
850
974
|
source,
|
|
851
|
-
TopicType.
|
|
975
|
+
TopicType.checkpoint_attestation,
|
|
852
976
|
);
|
|
853
977
|
|
|
854
978
|
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
@@ -856,7 +980,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
856
980
|
}
|
|
857
981
|
|
|
858
982
|
this.logger.debug(
|
|
859
|
-
`Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
983
|
+
`Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
860
984
|
{
|
|
861
985
|
p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
|
|
862
986
|
slot: attestation.slotNumber,
|
|
@@ -865,13 +989,14 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
865
989
|
},
|
|
866
990
|
);
|
|
867
991
|
|
|
868
|
-
await this.mempools.attestationPool.
|
|
992
|
+
await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
|
|
869
993
|
}
|
|
870
994
|
|
|
871
995
|
private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
872
996
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockProposal>> = async () => {
|
|
873
997
|
const block = BlockProposal.fromBuffer(payloadData);
|
|
874
|
-
const
|
|
998
|
+
const validationResult = await this.validateBlockProposal(source, block);
|
|
999
|
+
const isValid = validationResult.result === 'accept';
|
|
875
1000
|
const pool = this.mempools.attestationPool;
|
|
876
1001
|
|
|
877
1002
|
const exists = isValid && (await pool.hasBlockProposal(block));
|
|
@@ -881,13 +1006,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
881
1006
|
isValid,
|
|
882
1007
|
exists,
|
|
883
1008
|
canAdd,
|
|
884
|
-
[Attributes.SLOT_NUMBER]: block.
|
|
1009
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
885
1010
|
[Attributes.P2P_ID]: source.toString(),
|
|
886
1011
|
});
|
|
887
1012
|
|
|
888
|
-
if (
|
|
1013
|
+
if (validationResult.result === 'reject') {
|
|
889
1014
|
return { result: TopicValidatorResult.Reject };
|
|
890
|
-
} else if (exists) {
|
|
1015
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
891
1016
|
return { result: TopicValidatorResult.Ignore, obj: block };
|
|
892
1017
|
} else if (!canAdd) {
|
|
893
1018
|
this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
|
|
@@ -917,6 +1042,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
917
1042
|
}
|
|
918
1043
|
|
|
919
1044
|
// REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
1045
|
+
// REFACTOR(palla): This method should be moved to the p2p_client or to a separate component,
|
|
1046
|
+
// should not be here as it does not deal with p2p networking.
|
|
920
1047
|
@trackSpan('Libp2pService.processValidBlockProposal', async block => ({
|
|
921
1048
|
[Attributes.SLOT_NUMBER]: block.slotNumber,
|
|
922
1049
|
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
@@ -924,17 +1051,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
924
1051
|
}))
|
|
925
1052
|
private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
|
|
926
1053
|
const slot = block.slotNumber;
|
|
927
|
-
const previousSlot = SlotNumber(slot - 1);
|
|
928
1054
|
this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
929
1055
|
p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
|
|
930
|
-
slot: block.slotNumber,
|
|
931
|
-
archive: block.archive.toString(),
|
|
932
1056
|
source: sender.toString(),
|
|
1057
|
+
...block.toBlockInfo(),
|
|
933
1058
|
});
|
|
934
|
-
const attestationsForPreviousSlot = await this.mempools.attestationPool.getAttestationsForSlot(previousSlot);
|
|
935
|
-
this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
|
|
936
1059
|
|
|
937
|
-
// Attempt to add proposal
|
|
1060
|
+
// Attempt to add proposal
|
|
938
1061
|
try {
|
|
939
1062
|
await this.mempools.attestationPool.addBlockProposal(block);
|
|
940
1063
|
} catch (err: unknown) {
|
|
@@ -949,34 +1072,126 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
949
1072
|
}
|
|
950
1073
|
throw err;
|
|
951
1074
|
}
|
|
1075
|
+
|
|
1076
|
+
// Mark the txs in this proposal as non-evictable
|
|
952
1077
|
await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
|
|
953
|
-
const attestations = await this.blockReceivedCallback(block, sender);
|
|
954
1078
|
|
|
955
|
-
//
|
|
956
|
-
//
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1079
|
+
// Call the block received callback to validate the proposal.
|
|
1080
|
+
// Note: Validators do NOT attest to individual blocks, only to checkpoint proposals.
|
|
1081
|
+
const isValid = await this.blockReceivedCallback(block, sender);
|
|
1082
|
+
if (!isValid) {
|
|
1083
|
+
this.logger.warn(`Block proposal validation failed for block ${block.blockNumber}`, block.toBlockInfo());
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Handle a gossiped checkpoint proposal.
|
|
1089
|
+
* Validates and processes the checkpoint proposal, then triggers the callback for attestation.
|
|
1090
|
+
*/
|
|
1091
|
+
private async handleGossipedCheckpointProposal(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
1092
|
+
// TODO(palla/mbps): This pattern is repeated across multiple message handlers, consider abstracting it.
|
|
1093
|
+
const validationFunc: () => Promise<ReceivedMessageValidationResult<CheckpointProposal>> = async () => {
|
|
1094
|
+
const checkpoint = CheckpointProposal.fromBuffer(payloadData);
|
|
1095
|
+
const validationResult = await this.validateCheckpointProposal(source, checkpoint);
|
|
1096
|
+
const isValid = validationResult.result === 'accept';
|
|
1097
|
+
const pool = this.mempools.attestationPool;
|
|
1098
|
+
|
|
1099
|
+
const exists = isValid && (await pool.hasCheckpointProposal(checkpoint));
|
|
1100
|
+
const canAdd = isValid && (await pool.canAddCheckpointProposal(checkpoint));
|
|
1101
|
+
|
|
1102
|
+
this.logger.trace(`Validate propagated checkpoint proposal`, {
|
|
1103
|
+
isValid,
|
|
1104
|
+
exists,
|
|
1105
|
+
canAdd,
|
|
1106
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1107
|
+
[Attributes.P2P_ID]: source.toString(),
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
if (validationResult.result === 'reject') {
|
|
1111
|
+
return { result: TopicValidatorResult.Reject };
|
|
1112
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
1113
|
+
return { result: TopicValidatorResult.Ignore, obj: checkpoint };
|
|
1114
|
+
} else if (!canAdd) {
|
|
1115
|
+
this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
|
|
1116
|
+
this.logger.warn(`Penalizing peer for checkpoint proposal exceeding per-slot cap`, {
|
|
1117
|
+
slot: checkpoint.slotNumber.toString(),
|
|
1118
|
+
archive: checkpoint.archive.toString(),
|
|
1119
|
+
source: source.toString(),
|
|
963
1120
|
});
|
|
964
|
-
|
|
1121
|
+
return { result: TopicValidatorResult.Reject };
|
|
1122
|
+
} else {
|
|
1123
|
+
return { result: TopicValidatorResult.Accept, obj: checkpoint };
|
|
965
1124
|
}
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
const { result, obj: checkpoint } = await this.validateReceivedMessage<CheckpointProposal>(
|
|
1128
|
+
validationFunc,
|
|
1129
|
+
msgId,
|
|
1130
|
+
source,
|
|
1131
|
+
TopicType.checkpoint_proposal,
|
|
1132
|
+
);
|
|
1133
|
+
|
|
1134
|
+
if (result !== TopicValidatorResult.Accept || !checkpoint) {
|
|
1135
|
+
return;
|
|
966
1136
|
}
|
|
1137
|
+
|
|
1138
|
+
await this.processValidCheckpointProposal(checkpoint, source);
|
|
967
1139
|
}
|
|
968
1140
|
|
|
969
1141
|
/**
|
|
970
|
-
*
|
|
971
|
-
*
|
|
1142
|
+
* Process a validated checkpoint proposal.
|
|
1143
|
+
* Extracts and processes the last block proposal (if present) first, then processes the checkpoint.
|
|
1144
|
+
* The block callback is invoked before the checkpoint callback.
|
|
972
1145
|
*/
|
|
973
|
-
@trackSpan('Libp2pService.
|
|
974
|
-
[Attributes.SLOT_NUMBER]:
|
|
975
|
-
[Attributes.BLOCK_ARCHIVE]:
|
|
976
|
-
[Attributes.P2P_ID]: await
|
|
1146
|
+
@trackSpan('Libp2pService.processValidCheckpointProposal', async checkpoint => ({
|
|
1147
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber,
|
|
1148
|
+
[Attributes.BLOCK_ARCHIVE]: checkpoint.archive.toString(),
|
|
1149
|
+
[Attributes.P2P_ID]: await checkpoint.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
977
1150
|
}))
|
|
978
|
-
private async
|
|
979
|
-
|
|
1151
|
+
private async processValidCheckpointProposal(checkpoint: CheckpointProposal, sender: PeerId) {
|
|
1152
|
+
const slot = checkpoint.slotNumber;
|
|
1153
|
+
this.logger.verbose(`Received checkpoint proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
1154
|
+
p2pMessageIdentifier: await checkpoint.p2pMessageLoggingIdentifier(),
|
|
1155
|
+
slot: checkpoint.slotNumber,
|
|
1156
|
+
archive: checkpoint.archive.toString(),
|
|
1157
|
+
source: sender.toString(),
|
|
1158
|
+
});
|
|
1159
|
+
|
|
1160
|
+
// Extract block proposal before adding to pool (pool stores them separately)
|
|
1161
|
+
const blockProposal = checkpoint.getBlockProposal();
|
|
1162
|
+
|
|
1163
|
+
// Add proposal to the pool (this extracts and stores block proposal separately)
|
|
1164
|
+
await this.mempools.attestationPool.addCheckpointProposal(checkpoint);
|
|
1165
|
+
|
|
1166
|
+
// Mark txs as non-evictable if present (from the last block)
|
|
1167
|
+
if (checkpoint.txHashes.length > 0) {
|
|
1168
|
+
await this.mempools.txPool.markTxsAsNonEvictable(checkpoint.txHashes);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// If there was a last block proposal, invoke the block callback first for validation.
|
|
1172
|
+
// Note: The block proposal is already stored in the pool by addCheckpointProposal.
|
|
1173
|
+
if (blockProposal) {
|
|
1174
|
+
const isValid = await this.blockReceivedCallback(blockProposal, sender);
|
|
1175
|
+
if (!isValid) {
|
|
1176
|
+
this.logger.warn(`Block proposal from checkpoint failed validation`, {
|
|
1177
|
+
slot: slot.toString(),
|
|
1178
|
+
archive: checkpoint.archive.toString(),
|
|
1179
|
+
blockNumber: blockProposal.blockNumber.toString(),
|
|
1180
|
+
});
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// Call the checkpoint received callback with the core version (without lastBlock)
|
|
1186
|
+
// to validate and potentially generate attestations
|
|
1187
|
+
const attestations = await this.checkpointReceivedCallback(checkpoint.toCore(), sender);
|
|
1188
|
+
if (attestations && attestations.length > 0) {
|
|
1189
|
+
// If the callback returned attestations, add them to the pool and propagate them
|
|
1190
|
+
await this.mempools.attestationPool.addCheckpointAttestations(attestations);
|
|
1191
|
+
for (const attestation of attestations) {
|
|
1192
|
+
await this.propagate(attestation);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
980
1195
|
}
|
|
981
1196
|
|
|
982
1197
|
/**
|
|
@@ -1101,7 +1316,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1101
1316
|
const requested = new Set(requestedTxHash.map(h => h.toString()));
|
|
1102
1317
|
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1103
1318
|
|
|
1104
|
-
//TODO: (mralj) - this is somewhat naive implementation, if single tx is
|
|
1319
|
+
//TODO: (mralj) - this is somewhat naive implementation, if single tx is invalid we consider the whole response invalid.
|
|
1105
1320
|
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1106
1321
|
try {
|
|
1107
1322
|
await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
@@ -1164,27 +1379,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1164
1379
|
}
|
|
1165
1380
|
}
|
|
1166
1381
|
|
|
1167
|
-
private createRequestedTxValidator(): TxValidator {
|
|
1168
|
-
return new AggregateTxValidator(
|
|
1169
|
-
new DataTxValidator(),
|
|
1170
|
-
new MetadataTxValidator({
|
|
1171
|
-
l1ChainId: new Fr(this.config.l1ChainId),
|
|
1172
|
-
rollupVersion: new Fr(this.config.rollupVersion),
|
|
1173
|
-
protocolContractsHash,
|
|
1174
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
1175
|
-
}),
|
|
1176
|
-
new TxProofValidator(this.proofVerifier),
|
|
1177
|
-
);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
1382
|
private async validateRequestedTx(tx: Tx, peerId: PeerId, txValidator: TxValidator, requested?: Set<`0x${string}`>) {
|
|
1181
1383
|
const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
|
|
1182
|
-
|
|
1183
|
-
if (!(await tx.validateTxHash())) {
|
|
1184
|
-
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1185
|
-
throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
1384
|
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1189
1385
|
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1190
1386
|
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
@@ -1197,6 +1393,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1197
1393
|
}
|
|
1198
1394
|
}
|
|
1199
1395
|
|
|
1396
|
+
private createRequestedTxValidator(): TxValidator {
|
|
1397
|
+
return createTxReqRespValidator(this.proofVerifier, {
|
|
1398
|
+
l1ChainId: this.config.l1ChainId,
|
|
1399
|
+
rollupVersion: this.config.rollupVersion,
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1200
1403
|
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
1201
1404
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1202
1405
|
}))
|
|
@@ -1239,6 +1442,22 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1239
1442
|
return gasFees;
|
|
1240
1443
|
}
|
|
1241
1444
|
|
|
1445
|
+
/**
|
|
1446
|
+
* Get the BatchTxRequesterLibP2PService dependencies for creating BatchTxRequester instances
|
|
1447
|
+
*/
|
|
1448
|
+
public getBatchTxRequesterService(): BatchTxRequesterLibP2PService {
|
|
1449
|
+
return {
|
|
1450
|
+
reqResp: this.reqresp,
|
|
1451
|
+
connectionSampler: this.reqresp.getConnectionSampler(),
|
|
1452
|
+
txValidatorConfig: {
|
|
1453
|
+
l1ChainId: this.config.l1ChainId,
|
|
1454
|
+
rollupVersion: this.config.rollupVersion,
|
|
1455
|
+
proofVerifier: this.proofVerifier,
|
|
1456
|
+
},
|
|
1457
|
+
peerScoring: this.peerManager,
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1242
1461
|
public async validate(txs: Tx[]): Promise<void> {
|
|
1243
1462
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1244
1463
|
|
|
@@ -1289,6 +1508,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1289
1508
|
this.proofVerifier,
|
|
1290
1509
|
!this.config.disableTransactions,
|
|
1291
1510
|
allowedInSetup,
|
|
1511
|
+
this.logger.getBindings(),
|
|
1292
1512
|
);
|
|
1293
1513
|
}
|
|
1294
1514
|
|
|
@@ -1342,15 +1562,18 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1342
1562
|
return PeerErrorSeverity.HighToleranceError;
|
|
1343
1563
|
}
|
|
1344
1564
|
|
|
1345
|
-
const snapshotValidator = new DoubleSpendTxValidator(
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1565
|
+
const snapshotValidator = new DoubleSpendTxValidator(
|
|
1566
|
+
{
|
|
1567
|
+
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
1568
|
+
const merkleTree = this.worldStateSynchronizer.getSnapshot(
|
|
1569
|
+
BlockNumber(blockNumber - this.config.doubleSpendSeverePeerPenaltyWindow),
|
|
1570
|
+
);
|
|
1571
|
+
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
1572
|
+
return indices.map(index => index !== undefined);
|
|
1573
|
+
},
|
|
1352
1574
|
},
|
|
1353
|
-
|
|
1575
|
+
this.logger.getBindings(),
|
|
1576
|
+
);
|
|
1354
1577
|
|
|
1355
1578
|
const validSnapshot = await snapshotValidator.validateTx(tx);
|
|
1356
1579
|
if (validSnapshot.result !== 'valid') {
|
|
@@ -1361,24 +1584,28 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1361
1584
|
}
|
|
1362
1585
|
|
|
1363
1586
|
/**
|
|
1364
|
-
* Validate
|
|
1587
|
+
* Validate a checkpoint attestation.
|
|
1365
1588
|
*
|
|
1366
|
-
* @param attestation - The attestation to validate.
|
|
1367
|
-
* @returns True if the attestation is valid, false otherwise.
|
|
1589
|
+
* @param attestation - The checkpoint attestation to validate.
|
|
1590
|
+
* @returns True if the checkpoint attestation is valid, false otherwise.
|
|
1368
1591
|
*/
|
|
1369
|
-
@trackSpan('Libp2pService.
|
|
1592
|
+
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1370
1593
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1371
1594
|
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1372
1595
|
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1373
1596
|
}))
|
|
1374
|
-
public async
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1597
|
+
public async validateCheckpointAttestation(
|
|
1598
|
+
peerId: PeerId,
|
|
1599
|
+
attestation: CheckpointAttestation,
|
|
1600
|
+
): Promise<P2PValidationResult> {
|
|
1601
|
+
const result = await this.checkpointAttestationValidator.validate(attestation);
|
|
1602
|
+
|
|
1603
|
+
if (result.result === 'reject') {
|
|
1604
|
+
this.logger.debug(`Penalizing peer ${peerId} for checkpoint attestation validation failure`);
|
|
1605
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1379
1606
|
}
|
|
1380
1607
|
|
|
1381
|
-
return
|
|
1608
|
+
return result;
|
|
1382
1609
|
}
|
|
1383
1610
|
|
|
1384
1611
|
/**
|
|
@@ -1388,17 +1615,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1388
1615
|
* @returns True if the block proposal is valid, false otherwise.
|
|
1389
1616
|
*/
|
|
1390
1617
|
@trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
|
|
1391
|
-
[Attributes.SLOT_NUMBER]: block.
|
|
1618
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
1392
1619
|
}))
|
|
1393
|
-
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1620
|
+
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<P2PValidationResult> {
|
|
1621
|
+
const result = await this.blockProposalValidator.validate(block);
|
|
1622
|
+
|
|
1623
|
+
if (result.result === 'reject') {
|
|
1396
1624
|
this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1397
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1398
|
-
return false;
|
|
1625
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1399
1626
|
}
|
|
1400
1627
|
|
|
1401
|
-
return
|
|
1628
|
+
return result;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* Validate a checkpoint proposal.
|
|
1633
|
+
*
|
|
1634
|
+
* @param checkpoint - The checkpoint proposal to validate.
|
|
1635
|
+
* @returns True if the checkpoint proposal is valid, false otherwise.
|
|
1636
|
+
*/
|
|
1637
|
+
@trackSpan('Libp2pService.validateCheckpointProposal', (_peerId, checkpoint) => ({
|
|
1638
|
+
[Attributes.SLOT_NUMBER]: checkpoint.slotNumber.toString(),
|
|
1639
|
+
}))
|
|
1640
|
+
public async validateCheckpointProposal(
|
|
1641
|
+
peerId: PeerId,
|
|
1642
|
+
checkpoint: CheckpointProposal,
|
|
1643
|
+
): Promise<P2PValidationResult> {
|
|
1644
|
+
const result = await this.checkpointProposalValidator.validate(checkpoint);
|
|
1645
|
+
|
|
1646
|
+
if (result.result === 'reject') {
|
|
1647
|
+
this.logger.debug(`Penalizing peer ${peerId} for checkpoint proposal validation failure`);
|
|
1648
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
return result;
|
|
1402
1652
|
}
|
|
1403
1653
|
|
|
1404
1654
|
public getPeerScore(peerId: PeerId): number {
|