@aztec/p2p 0.0.1-commit.d3ec352c → 0.0.1-commit.e3c1de76
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 +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +8 -8
- package/dest/client/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +11 -14
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +459 -125
- 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 +11 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -13
- 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 +239 -265
- 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 +114 -109
- 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 +11 -8
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +17 -13
- package/dest/mem_pools/instrumentation.d.ts +7 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +31 -13
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +35 -26
- 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 +314 -335
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -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 +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- 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/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +8 -4
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +25 -20
- 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 +52 -19
- 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/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +3 -2
- 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 +9 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +22 -12
- 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 +4 -3
- 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/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- 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/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +10 -6
- 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 +7 -6
- 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 +39 -16
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +750 -187
- package/dest/services/peer-manager/metrics.d.ts +7 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +33 -21
- 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 +4 -12
- 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 +4 -2
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +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/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.js +1 -1
- 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 +16 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +19 -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 +44 -14
- 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/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -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 +10 -2
- 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/tx_collection.d.ts +6 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +6 -6
- package/dest/services/tx_provider.d.ts +4 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +11 -2
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +14 -14
- 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/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- 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 +158 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +297 -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 -123
- 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 +11 -20
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +92 -145
- 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 +18 -19
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -289
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +163 -141
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +21 -15
- package/src/mem_pools/instrumentation.ts +39 -14
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +362 -367
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- 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_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +8 -3
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +18 -13
- package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
- 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/archive_cache.ts +3 -3
- package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
- 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 +65 -24
- 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 +19 -8
- 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/test_utils.ts +1 -1
- 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/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +51 -0
- package/src/services/encoding.ts +6 -5
- package/src/services/libp2p/instrumentation.ts +32 -73
- package/src/services/libp2p/libp2p_service.ts +418 -173
- package/src/services/peer-manager/metrics.ts +39 -21
- package/src/services/peer-manager/peer_manager.ts +5 -4
- 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 +4 -1
- package/src/services/reqresp/metrics.ts +36 -27
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +1 -1
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +18 -4
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +52 -10
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/reqresp/reqresp.ts +66 -19
- package/src/services/service.ts +23 -4
- package/src/services/tx_collection/config.ts +16 -2
- 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/tx_collection.ts +7 -7
- package/src/services/tx_provider.ts +19 -4
- package/src/services/tx_provider_instrumentation.ts +24 -14
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/mock-pubsub.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +374 -0
- package/src/testbench/p2p_client_testbench_worker.ts +338 -119
- package/src/testbench/worker_client_manager.ts +304 -42
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -81
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -239
- 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/memory_tx_pool.ts +0 -285
- 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
|
|
3
|
-
import { randomInt } from '@aztec/foundation/crypto';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
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(
|
|
@@ -153,7 +178,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
153
178
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
154
179
|
private reqresp: ReqRespInterface,
|
|
155
180
|
private peerManager: PeerManagerInterface,
|
|
156
|
-
protected mempools: MemPools
|
|
181
|
+
protected mempools: MemPools,
|
|
157
182
|
private archiver: L2BlockSource & ContractDataSource,
|
|
158
183
|
private epochCache: EpochCacheInterface,
|
|
159
184
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
@@ -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
|
|
|
@@ -215,7 +257,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
215
257
|
config: P2PConfig,
|
|
216
258
|
peerId: PeerId,
|
|
217
259
|
deps: {
|
|
218
|
-
mempools: MemPools
|
|
260
|
+
mempools: MemPools;
|
|
219
261
|
l2BlockSource: L2BlockSource & ContractDataSource;
|
|
220
262
|
epochCache: EpochCacheInterface;
|
|
221
263
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
@@ -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);
|
|
@@ -486,8 +523,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
486
523
|
[ReqRespSubProtocol.BLOCK]: blockHandler.bind(this),
|
|
487
524
|
};
|
|
488
525
|
|
|
489
|
-
|
|
490
|
-
if (this.mempools.attestationPool && !this.config.disableTransactions) {
|
|
526
|
+
if (!this.config.disableTransactions) {
|
|
491
527
|
const blockTxsHandler = reqRespBlockTxsHandler(this.mempools.attestationPool, this.mempools.txPool);
|
|
492
528
|
requestResponseHandlers[ReqRespSubProtocol.BLOCK_TXS] = blockTxsHandler.bind(this);
|
|
493
529
|
}
|
|
@@ -496,10 +532,32 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
496
532
|
requestResponseHandlers[ReqRespSubProtocol.TX] = txHandler.bind(this);
|
|
497
533
|
}
|
|
498
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
|
+
|
|
499
554
|
// add GossipSub listener
|
|
500
555
|
this.node.services.pubsub.addEventListener(GossipSubEvent.MESSAGE, this.gossipSubEventHandler);
|
|
501
556
|
|
|
502
557
|
// Start running promise for peer discovery and metrics collection
|
|
558
|
+
if (!this.config.p2pDiscoveryDisabled) {
|
|
559
|
+
await this.peerDiscoveryService.start();
|
|
560
|
+
}
|
|
503
561
|
this.discoveryRunningPromise = new RunningPromise(
|
|
504
562
|
async () => {
|
|
505
563
|
await this.peerManager.heartbeat();
|
|
@@ -509,14 +567,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
509
567
|
);
|
|
510
568
|
this.discoveryRunningPromise.start();
|
|
511
569
|
|
|
512
|
-
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
513
|
-
const reqrespSubProtocolValidators = {
|
|
514
|
-
...DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
515
|
-
[ReqRespSubProtocol.TX]: this.validateRequestedTxs.bind(this),
|
|
516
|
-
[ReqRespSubProtocol.BLOCK_TXS]: this.validateRequestedBlockTxs.bind(this),
|
|
517
|
-
[ReqRespSubProtocol.BLOCK]: this.validateRequestedBlock.bind(this),
|
|
518
|
-
};
|
|
519
|
-
await this.reqresp.start(requestResponseHandlers, reqrespSubProtocolValidators);
|
|
520
570
|
this.logger.info(`Started P2P service`, {
|
|
521
571
|
listen: this.config.listenAddress,
|
|
522
572
|
port: this.config.p2pPort,
|
|
@@ -590,6 +640,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
590
640
|
return this.reqresp.sendBatchRequest(protocol, requests, pinnedPeerId);
|
|
591
641
|
}
|
|
592
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
|
+
|
|
593
652
|
/**
|
|
594
653
|
* Get the ENR of the node
|
|
595
654
|
* @returns The ENR of the node
|
|
@@ -602,6 +661,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
602
661
|
this.blockReceivedCallback = callback;
|
|
603
662
|
}
|
|
604
663
|
|
|
664
|
+
public registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback) {
|
|
665
|
+
this.checkpointReceivedCallback = callback;
|
|
666
|
+
}
|
|
667
|
+
|
|
605
668
|
/**
|
|
606
669
|
* Subscribes to a topic.
|
|
607
670
|
* @param topic - The topic to subscribe to.
|
|
@@ -623,7 +686,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
623
686
|
if (!this.node.services.pubsub) {
|
|
624
687
|
throw new Error('Pubsub service not available.');
|
|
625
688
|
}
|
|
626
|
-
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);
|
|
627
693
|
const result = await this.node.services.pubsub.publish(topic, p2pMessage.toMessageData());
|
|
628
694
|
return result.recipients.length;
|
|
629
695
|
}
|
|
@@ -644,12 +710,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
644
710
|
case this.topicStrings[TopicType.tx]:
|
|
645
711
|
topicType = TopicType.tx;
|
|
646
712
|
break;
|
|
647
|
-
case this.topicStrings[TopicType.block_attestation]:
|
|
648
|
-
topicType = TopicType.block_attestation;
|
|
649
|
-
break;
|
|
650
713
|
case this.topicStrings[TopicType.block_proposal]:
|
|
651
714
|
topicType = TopicType.block_proposal;
|
|
652
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;
|
|
653
722
|
default:
|
|
654
723
|
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
655
724
|
break;
|
|
@@ -708,23 +777,74 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
708
777
|
return;
|
|
709
778
|
}
|
|
710
779
|
|
|
780
|
+
// Determine topic type for attributes
|
|
711
781
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
712
782
|
topicType = TopicType.tx;
|
|
713
|
-
|
|
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;
|
|
714
789
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
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}`);
|
|
719
805
|
}
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
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();
|
|
724
845
|
}
|
|
725
846
|
|
|
726
|
-
if (
|
|
727
|
-
const latency = msgReceivedTime - p2pMessage.timestamp.getTime();
|
|
847
|
+
if (latency !== undefined && topicType !== undefined) {
|
|
728
848
|
this.instrumentation.recordMessageLatency(topicType, latency);
|
|
729
849
|
}
|
|
730
850
|
|
|
@@ -801,27 +921,30 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
801
921
|
}
|
|
802
922
|
|
|
803
923
|
/**
|
|
804
|
-
* Process
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
* @param attestation - The attestation to process.
|
|
924
|
+
* Process a checkpoint attestation from a peer.
|
|
925
|
+
* Validates the attestation and adds it to the pool.
|
|
808
926
|
*/
|
|
809
|
-
private async
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
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);
|
|
934
|
+
const pool = this.mempools.attestationPool;
|
|
935
|
+
const validationResult = await this.validateCheckpointAttestation(source, attestation);
|
|
936
|
+
const isValid = validationResult.result === 'accept';
|
|
937
|
+
const exists = isValid && (await pool.hasCheckpointAttestation(attestation));
|
|
815
938
|
|
|
816
939
|
let canAdd = true;
|
|
817
940
|
if (isValid && !exists) {
|
|
818
941
|
const slot = attestation.payload.header.slotNumber;
|
|
819
942
|
const { committee } = await this.epochCache.getCommittee(slot);
|
|
820
943
|
const committeeSize = committee?.length ?? 0;
|
|
821
|
-
canAdd = await pool.
|
|
944
|
+
canAdd = await pool.canAddCheckpointAttestation(attestation, committeeSize);
|
|
822
945
|
}
|
|
823
946
|
|
|
824
|
-
this.logger.trace(`Validate propagated
|
|
947
|
+
this.logger.trace(`Validate propagated checkpoint attestation`, {
|
|
825
948
|
isValid,
|
|
826
949
|
exists,
|
|
827
950
|
canAdd,
|
|
@@ -829,12 +952,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
829
952
|
[Attributes.P2P_ID]: source.toString(),
|
|
830
953
|
});
|
|
831
954
|
|
|
832
|
-
if (
|
|
955
|
+
if (validationResult.result === 'reject') {
|
|
833
956
|
return { result: TopicValidatorResult.Reject };
|
|
834
|
-
} else if (exists) {
|
|
957
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
835
958
|
return { result: TopicValidatorResult.Ignore, obj: attestation };
|
|
836
959
|
} else if (!canAdd) {
|
|
837
|
-
this.logger.warn(`Dropping
|
|
960
|
+
this.logger.warn(`Dropping checkpoint attestation due to per-(slot, proposalId) attestation cap`, {
|
|
838
961
|
slot: attestation.payload.header.slotNumber.toString(),
|
|
839
962
|
archive: attestation.archive.toString(),
|
|
840
963
|
source: source.toString(),
|
|
@@ -845,11 +968,11 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
845
968
|
}
|
|
846
969
|
};
|
|
847
970
|
|
|
848
|
-
const { result, obj: attestation } = await this.validateReceivedMessage<
|
|
971
|
+
const { result, obj: attestation } = await this.validateReceivedMessage<CheckpointAttestation>(
|
|
849
972
|
validationFunc,
|
|
850
973
|
msgId,
|
|
851
974
|
source,
|
|
852
|
-
TopicType.
|
|
975
|
+
TopicType.checkpoint_attestation,
|
|
853
976
|
);
|
|
854
977
|
|
|
855
978
|
if (result !== TopicValidatorResult.Accept || !attestation) {
|
|
@@ -857,7 +980,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
857
980
|
}
|
|
858
981
|
|
|
859
982
|
this.logger.debug(
|
|
860
|
-
`Received attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
983
|
+
`Received checkpoint attestation for slot ${attestation.slotNumber} from external peer ${source.toString()}`,
|
|
861
984
|
{
|
|
862
985
|
p2pMessageIdentifier: await attestation.p2pMessageLoggingIdentifier(),
|
|
863
986
|
slot: attestation.slotNumber,
|
|
@@ -866,31 +989,30 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
866
989
|
},
|
|
867
990
|
);
|
|
868
991
|
|
|
869
|
-
await this.mempools.attestationPool
|
|
992
|
+
await this.mempools.attestationPool.addCheckpointAttestations([attestation]);
|
|
870
993
|
}
|
|
871
994
|
|
|
872
995
|
private async processBlockFromPeer(payloadData: Buffer, msgId: string, source: PeerId): Promise<void> {
|
|
873
996
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<BlockProposal>> = async () => {
|
|
874
997
|
const block = BlockProposal.fromBuffer(payloadData);
|
|
875
|
-
const
|
|
998
|
+
const validationResult = await this.validateBlockProposal(source, block);
|
|
999
|
+
const isValid = validationResult.result === 'accept';
|
|
876
1000
|
const pool = this.mempools.attestationPool;
|
|
877
1001
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
const exists = isValid && (await pool?.hasBlockProposal(block));
|
|
881
|
-
const canAdd = isValid && (await pool?.canAddProposal(block));
|
|
1002
|
+
const exists = isValid && (await pool.hasBlockProposal(block));
|
|
1003
|
+
const canAdd = isValid && (await pool.canAddProposal(block));
|
|
882
1004
|
|
|
883
1005
|
this.logger.trace(`Validate propagated block proposal`, {
|
|
884
1006
|
isValid,
|
|
885
1007
|
exists,
|
|
886
1008
|
canAdd,
|
|
887
|
-
[Attributes.SLOT_NUMBER]: block.
|
|
1009
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
888
1010
|
[Attributes.P2P_ID]: source.toString(),
|
|
889
1011
|
});
|
|
890
1012
|
|
|
891
|
-
if (
|
|
1013
|
+
if (validationResult.result === 'reject') {
|
|
892
1014
|
return { result: TopicValidatorResult.Reject };
|
|
893
|
-
} else if (exists) {
|
|
1015
|
+
} else if (validationResult.result === 'ignore' || exists) {
|
|
894
1016
|
return { result: TopicValidatorResult.Ignore, obj: block };
|
|
895
1017
|
} else if (!canAdd) {
|
|
896
1018
|
this.peerManager.penalizePeer(source, PeerErrorSeverity.MidToleranceError);
|
|
@@ -920,6 +1042,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
920
1042
|
}
|
|
921
1043
|
|
|
922
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.
|
|
923
1047
|
@trackSpan('Libp2pService.processValidBlockProposal', async block => ({
|
|
924
1048
|
[Attributes.SLOT_NUMBER]: block.slotNumber,
|
|
925
1049
|
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
@@ -927,21 +1051,15 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
927
1051
|
}))
|
|
928
1052
|
private async processValidBlockProposal(block: BlockProposal, sender: PeerId) {
|
|
929
1053
|
const slot = block.slotNumber;
|
|
930
|
-
const previousSlot = SlotNumber(slot - 1);
|
|
931
1054
|
this.logger.verbose(`Received block proposal for slot ${slot} from external peer ${sender.toString()}.`, {
|
|
932
1055
|
p2pMessageIdentifier: await block.p2pMessageLoggingIdentifier(),
|
|
933
|
-
slot: block.slotNumber,
|
|
934
|
-
archive: block.archive.toString(),
|
|
935
1056
|
source: sender.toString(),
|
|
1057
|
+
...block.toBlockInfo(),
|
|
936
1058
|
});
|
|
937
|
-
const attestationsForPreviousSlot = await this.mempools.attestationPool?.getAttestationsForSlot(previousSlot);
|
|
938
|
-
if (attestationsForPreviousSlot !== undefined) {
|
|
939
|
-
this.logger.verbose(`Received ${attestationsForPreviousSlot.length} attestations for slot ${previousSlot}`);
|
|
940
|
-
}
|
|
941
1059
|
|
|
942
|
-
// Attempt to add proposal
|
|
1060
|
+
// Attempt to add proposal
|
|
943
1061
|
try {
|
|
944
|
-
await this.mempools.attestationPool
|
|
1062
|
+
await this.mempools.attestationPool.addBlockProposal(block);
|
|
945
1063
|
} catch (err: unknown) {
|
|
946
1064
|
// Drop proposals if we hit per-slot cap in the attestation pool; rethrow unknown errors
|
|
947
1065
|
if (err instanceof ProposalSlotCapExceededError) {
|
|
@@ -954,34 +1072,126 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
954
1072
|
}
|
|
955
1073
|
throw err;
|
|
956
1074
|
}
|
|
1075
|
+
|
|
1076
|
+
// Mark the txs in this proposal as non-evictable
|
|
957
1077
|
await this.mempools.txPool.markTxsAsNonEvictable(block.txHashes);
|
|
958
|
-
const attestations = await this.blockReceivedCallback(block, sender);
|
|
959
1078
|
|
|
960
|
-
//
|
|
961
|
-
//
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
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(),
|
|
968
1120
|
});
|
|
969
|
-
|
|
1121
|
+
return { result: TopicValidatorResult.Reject };
|
|
1122
|
+
} else {
|
|
1123
|
+
return { result: TopicValidatorResult.Accept, obj: checkpoint };
|
|
970
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;
|
|
971
1136
|
}
|
|
1137
|
+
|
|
1138
|
+
await this.processValidCheckpointProposal(checkpoint, source);
|
|
972
1139
|
}
|
|
973
1140
|
|
|
974
1141
|
/**
|
|
975
|
-
*
|
|
976
|
-
*
|
|
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.
|
|
977
1145
|
*/
|
|
978
|
-
@trackSpan('Libp2pService.
|
|
979
|
-
[Attributes.SLOT_NUMBER]:
|
|
980
|
-
[Attributes.BLOCK_ARCHIVE]:
|
|
981
|
-
[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()),
|
|
982
1150
|
}))
|
|
983
|
-
private async
|
|
984
|
-
|
|
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
|
+
}
|
|
985
1195
|
}
|
|
986
1196
|
|
|
987
1197
|
/**
|
|
@@ -1004,7 +1214,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1004
1214
|
* @returns True if the requested block transactions are valid, false otherwise.
|
|
1005
1215
|
*/
|
|
1006
1216
|
@trackSpan('Libp2pService.validateRequestedBlockTxs', request => ({
|
|
1007
|
-
[Attributes.
|
|
1217
|
+
[Attributes.BLOCK_ARCHIVE]: request.archiveRoot.toString(),
|
|
1008
1218
|
}))
|
|
1009
1219
|
private async validateRequestedBlockTxs(
|
|
1010
1220
|
request: BlockTxsRequest,
|
|
@@ -1014,10 +1224,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1014
1224
|
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1015
1225
|
|
|
1016
1226
|
try {
|
|
1017
|
-
if (!response.
|
|
1227
|
+
if (!response.archiveRoot.equals(request.archiveRoot)) {
|
|
1018
1228
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
1019
1229
|
throw new ValidationError(
|
|
1020
|
-
`Received block txs for unexpected
|
|
1230
|
+
`Received block txs for unexpected archive root: expected ${request.archiveRoot.toString()}, got ${response.archiveRoot.toString()}`,
|
|
1021
1231
|
);
|
|
1022
1232
|
}
|
|
1023
1233
|
|
|
@@ -1047,7 +1257,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1047
1257
|
}
|
|
1048
1258
|
|
|
1049
1259
|
// Given proposal (should have locally), ensure returned txs are valid subset and match request indices
|
|
1050
|
-
const proposal = await this.mempools.attestationPool
|
|
1260
|
+
const proposal = await this.mempools.attestationPool.getBlockProposal(request.archiveRoot.toString());
|
|
1051
1261
|
if (proposal) {
|
|
1052
1262
|
// Build intersected indices
|
|
1053
1263
|
const intersectIdx = request.txIndices.getTrueIndices().filter(i => response.txIndices.isSet(i));
|
|
@@ -1067,7 +1277,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1067
1277
|
} else {
|
|
1068
1278
|
// No local proposal, cannot check the membership/order of the returned txs
|
|
1069
1279
|
this.logger.warn(
|
|
1070
|
-
`Block proposal not found for
|
|
1280
|
+
`Block proposal not found for archive root ${request.archiveRoot.toString()}; cannot validate membership/order of returned txs`,
|
|
1071
1281
|
);
|
|
1072
1282
|
return false;
|
|
1073
1283
|
}
|
|
@@ -1106,7 +1316,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1106
1316
|
const requested = new Set(requestedTxHash.map(h => h.toString()));
|
|
1107
1317
|
const requestedTxValidator = this.createRequestedTxValidator();
|
|
1108
1318
|
|
|
1109
|
-
//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.
|
|
1110
1320
|
// I think we should still extract the valid txs and return them, so that we can still use the response.
|
|
1111
1321
|
try {
|
|
1112
1322
|
await Promise.all(responseTx.map(tx => this.validateRequestedTx(tx, peerId, requestedTxValidator, requested)));
|
|
@@ -1169,27 +1379,8 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1169
1379
|
}
|
|
1170
1380
|
}
|
|
1171
1381
|
|
|
1172
|
-
private createRequestedTxValidator(): TxValidator {
|
|
1173
|
-
return new AggregateTxValidator(
|
|
1174
|
-
new DataTxValidator(),
|
|
1175
|
-
new MetadataTxValidator({
|
|
1176
|
-
l1ChainId: new Fr(this.config.l1ChainId),
|
|
1177
|
-
rollupVersion: new Fr(this.config.rollupVersion),
|
|
1178
|
-
protocolContractsHash,
|
|
1179
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
1180
|
-
}),
|
|
1181
|
-
new TxProofValidator(this.proofVerifier),
|
|
1182
|
-
);
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
1382
|
private async validateRequestedTx(tx: Tx, peerId: PeerId, txValidator: TxValidator, requested?: Set<`0x${string}`>) {
|
|
1186
1383
|
const penalize = (severity: PeerErrorSeverity) => this.peerManager.penalizePeer(peerId, severity);
|
|
1187
|
-
|
|
1188
|
-
if (!(await tx.validateTxHash())) {
|
|
1189
|
-
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1190
|
-
throw new ValidationError(`Received tx with invalid hash ${tx.getTxHash().toString()}.`);
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
1384
|
if (requested && !requested.has(tx.getTxHash().toString())) {
|
|
1194
1385
|
penalize(PeerErrorSeverity.MidToleranceError);
|
|
1195
1386
|
throw new ValidationError(`Received tx with hash ${tx.getTxHash().toString()} that was not requested.`);
|
|
@@ -1202,6 +1393,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1202
1393
|
}
|
|
1203
1394
|
}
|
|
1204
1395
|
|
|
1396
|
+
private createRequestedTxValidator(): TxValidator {
|
|
1397
|
+
return createTxReqRespValidator(this.proofVerifier, {
|
|
1398
|
+
l1ChainId: this.config.l1ChainId,
|
|
1399
|
+
rollupVersion: this.config.rollupVersion,
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1205
1403
|
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
1206
1404
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1207
1405
|
}))
|
|
@@ -1244,6 +1442,22 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1244
1442
|
return gasFees;
|
|
1245
1443
|
}
|
|
1246
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
|
+
|
|
1247
1461
|
public async validate(txs: Tx[]): Promise<void> {
|
|
1248
1462
|
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1249
1463
|
|
|
@@ -1294,6 +1508,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1294
1508
|
this.proofVerifier,
|
|
1295
1509
|
!this.config.disableTransactions,
|
|
1296
1510
|
allowedInSetup,
|
|
1511
|
+
this.logger.getBindings(),
|
|
1297
1512
|
);
|
|
1298
1513
|
}
|
|
1299
1514
|
|
|
@@ -1347,15 +1562,18 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1347
1562
|
return PeerErrorSeverity.HighToleranceError;
|
|
1348
1563
|
}
|
|
1349
1564
|
|
|
1350
|
-
const snapshotValidator = new DoubleSpendTxValidator(
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
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
|
+
},
|
|
1357
1574
|
},
|
|
1358
|
-
|
|
1575
|
+
this.logger.getBindings(),
|
|
1576
|
+
);
|
|
1359
1577
|
|
|
1360
1578
|
const validSnapshot = await snapshotValidator.validateTx(tx);
|
|
1361
1579
|
if (validSnapshot.result !== 'valid') {
|
|
@@ -1366,24 +1584,28 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1366
1584
|
}
|
|
1367
1585
|
|
|
1368
1586
|
/**
|
|
1369
|
-
* Validate
|
|
1587
|
+
* Validate a checkpoint attestation.
|
|
1370
1588
|
*
|
|
1371
|
-
* @param attestation - The attestation to validate.
|
|
1372
|
-
* @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.
|
|
1373
1591
|
*/
|
|
1374
|
-
@trackSpan('Libp2pService.
|
|
1592
|
+
@trackSpan('Libp2pService.validateCheckpointAttestation', async (_, attestation) => ({
|
|
1375
1593
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.slotNumber,
|
|
1376
1594
|
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
1377
1595
|
[Attributes.P2P_ID]: await attestation.p2pMessageLoggingIdentifier().then(i => i.toString()),
|
|
1378
1596
|
}))
|
|
1379
|
-
public async
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
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);
|
|
1384
1606
|
}
|
|
1385
1607
|
|
|
1386
|
-
return
|
|
1608
|
+
return result;
|
|
1387
1609
|
}
|
|
1388
1610
|
|
|
1389
1611
|
/**
|
|
@@ -1393,17 +1615,40 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1393
1615
|
* @returns True if the block proposal is valid, false otherwise.
|
|
1394
1616
|
*/
|
|
1395
1617
|
@trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
|
|
1396
|
-
[Attributes.SLOT_NUMBER]: block.
|
|
1618
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toString(),
|
|
1397
1619
|
}))
|
|
1398
|
-
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1620
|
+
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<P2PValidationResult> {
|
|
1621
|
+
const result = await this.blockProposalValidator.validate(block);
|
|
1622
|
+
|
|
1623
|
+
if (result.result === 'reject') {
|
|
1401
1624
|
this.logger.debug(`Penalizing peer ${peerId} for block proposal validation failure`);
|
|
1402
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1403
|
-
return false;
|
|
1625
|
+
this.peerManager.penalizePeer(peerId, result.severity);
|
|
1404
1626
|
}
|
|
1405
1627
|
|
|
1406
|
-
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;
|
|
1407
1652
|
}
|
|
1408
1653
|
|
|
1409
1654
|
public getPeerScore(peerId: PeerId): number {
|