@aztec/p2p 0.0.1-commit.3469e52 → 0.0.1-commit.350e0a4d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -3
- package/dest/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +26 -10
- package/dest/client/factory.d.ts +13 -12
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +70 -20
- package/dest/client/interface.d.ts +90 -40
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +69 -64
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +247 -244
- package/dest/config.d.ts +169 -84
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +159 -45
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/reqresp.error.d.ts +9 -16
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +10 -17
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +164 -106
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +518 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- 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 +550 -125
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +7 -5
- package/dest/mem_pools/index.d.ts +3 -3
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/instrumentation.d.ts +12 -5
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +40 -19
- package/dest/mem_pools/interface.d.ts +5 -5
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +39 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +97 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +97 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +12 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/{tx_pool → tx_pool_v2}/eviction/invalid_txs_after_mining_rule.js +16 -35
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +5 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +243 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +11 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +137 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +223 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +122 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +368 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +68 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +178 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +91 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +1013 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +11 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +67 -13
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +9 -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 -11
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +156 -43
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
- 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/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +4 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +40 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
- package/dest/msg_validators/tx_validator/factory.d.ts +136 -5
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +268 -58
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +105 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +138 -53
- package/dest/msg_validators/tx_validator/index.d.ts +5 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +4 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +6 -6
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +24 -3
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +75 -27
- package/dest/msg_validators/tx_validator/size_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/size_validator.js +4 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +22 -5
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +8 -8
- 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 +4 -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 +4 -2
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +14 -10
- package/dest/services/discv5/discV5_service.d.ts +13 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +120 -24
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +37 -17
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +59 -15
- package/dest/services/encoding.d.ts +24 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +43 -26
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +167 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +336 -0
- package/dest/services/index.d.ts +2 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +1 -0
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +28 -3
- package/dest/services/libp2p/libp2p_service.d.ts +116 -60
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +800 -586
- package/dest/services/peer-manager/metrics.d.ts +4 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +26 -5
- package/dest/services/peer-manager/peer_manager.d.ts +20 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +83 -26
- package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +135 -17
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +44 -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 +534 -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 +35 -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 +136 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +62 -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 +176 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +11 -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 +7 -0
- package/dest/services/reqresp/config.d.ts +15 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +11 -0
- 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/interface.d.ts +27 -18
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +23 -19
- 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 +16 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +8 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +8 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
- 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 +35 -14
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +36 -8
- 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 +84 -20
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +21 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
- package/dest/services/reqresp/reqresp.d.ts +12 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +90 -188
- package/dest/services/service.d.ts +65 -13
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +11 -11
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +27 -26
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +100 -0
- package/dest/services/tx_collection/index.d.ts +3 -2
- 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 +8 -2
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/tx_collection.d.ts +50 -56
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +298 -70
- package/dest/services/tx_collection/tx_collection_sink.d.ts +19 -9
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +28 -31
- package/dest/services/tx_collection/tx_source.d.ts +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +29 -7
- package/dest/services/tx_file_store/config.d.ts +16 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +22 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +46 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +142 -0
- package/dest/services/tx_provider.d.ts +8 -6
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +12 -8
- 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 +5 -5
- 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/make-test-p2p-clients.d.ts +7 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +5 -3
- package/dest/test-helpers/mock-pubsub.d.ts +46 -6
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +115 -14
- package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +19 -20
- package/dest/test-helpers/test_tx_provider.d.ts +42 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +44 -0
- package/dest/test-helpers/testbench-utils.d.ts +164 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +400 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +26 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +284 -139
- package/dest/testbench/worker_client_manager.d.ts +57 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +277 -49
- package/dest/util.d.ts +13 -8
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +16 -16
- package/src/bootstrap/bootstrap.ts +24 -7
- package/src/client/factory.ts +139 -39
- package/src/client/interface.ts +97 -48
- package/src/client/p2p_client.ts +291 -312
- package/src/client/test/p2p_client.batch_tx_requester.bench.README.md +197 -0
- package/src/config.ts +287 -49
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +13 -19
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +585 -94
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +656 -141
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +14 -8
- package/src/mem_pools/index.ts +2 -2
- package/src/mem_pools/instrumentation.ts +29 -18
- package/src/mem_pools/interface.ts +4 -4
- package/src/mem_pools/tx_pool_v2/README.md +283 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +112 -0
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +122 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +125 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +28 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
- package/src/mem_pools/tx_pool_v2/index.ts +12 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +274 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +349 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +465 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +252 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1215 -0
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +60 -16
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +30 -16
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +163 -50
- package/src/msg_validators/tx_validator/README.md +129 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +2 -2
- package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +50 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
- package/src/msg_validators/tx_validator/factory.ts +430 -56
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +198 -51
- package/src/msg_validators/tx_validator/index.ts +4 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +18 -7
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +87 -30
- package/src/msg_validators/tx_validator/size_validator.ts +6 -2
- package/src/msg_validators/tx_validator/timestamp_validator.ts +29 -21
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +10 -3
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/data_store.ts +14 -19
- package/src/services/discv5/discV5_service.ts +127 -15
- package/src/services/discv5/persisted_enr_store.ts +158 -0
- package/src/services/dummy_service.ts +77 -39
- package/src/services/encoding.ts +42 -26
- package/src/services/gossipsub/README.md +663 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +478 -0
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/instrumentation.ts +29 -2
- package/src/services/libp2p/libp2p_service.ts +893 -648
- package/src/services/peer-manager/metrics.ts +28 -4
- package/src/services/peer-manager/peer_manager.ts +91 -25
- package/src/services/peer-manager/peer_scoring.ts +131 -9
- package/src/services/reqresp/README.md +194 -0
- package/src/services/reqresp/batch-tx-requester/README.md +344 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +660 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +61 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +168 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +249 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +24 -0
- package/src/services/reqresp/config.ts +19 -2
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
- package/src/services/reqresp/interface.ts +48 -46
- package/src/services/reqresp/metrics.ts +33 -9
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +10 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +44 -17
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +108 -16
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +23 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
- package/src/services/reqresp/reqresp.ts +107 -223
- package/src/services/service.ts +85 -29
- package/src/services/tx_collection/config.ts +41 -36
- package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +2 -1
- package/src/services/tx_collection/instrumentation.ts +11 -2
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/tx_collection.ts +367 -115
- package/src/services/tx_collection/tx_collection_sink.ts +32 -36
- package/src/services/tx_collection/tx_source.ts +29 -8
- package/src/services/tx_file_store/config.ts +37 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +163 -0
- package/src/services/tx_provider.ts +17 -11
- package/src/services/tx_provider_instrumentation.ts +11 -5
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/make-test-p2p-clients.ts +7 -6
- package/src/test-helpers/mock-pubsub.ts +137 -14
- package/src/test-helpers/reqresp-nodes.ts +17 -29
- package/src/test-helpers/test_tx_provider.ts +69 -0
- package/src/test-helpers/testbench-utils.ts +465 -0
- package/src/testbench/p2p_client_testbench_worker.ts +389 -133
- package/src/testbench/worker_client_manager.ts +355 -51
- package/src/util.ts +40 -19
- package/src/versioning.ts +3 -33
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -31
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -156
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -115
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -76
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -157
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -45
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -92
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -51
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -300
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -53
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -177
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -131
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -207
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -159
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -91
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -191
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -100
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/fast_tx_collection.ts +0 -341
- package/src/services/tx_collection/slow_tx_collection.ts +0 -233
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
3
1
|
import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
|
|
4
2
|
|
|
5
3
|
import type { PeerId } from '@libp2p/interface';
|
|
6
4
|
|
|
7
5
|
import type { P2PReqRespConfig } from './config.js';
|
|
6
|
+
import type { ConnectionSampler } from './connection-sampler/connection_sampler.js';
|
|
8
7
|
import { AuthRequest, AuthResponse } from './protocols/auth.js';
|
|
9
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
BlockTxsRequest,
|
|
10
|
+
BlockTxsResponse,
|
|
11
|
+
calculateBlockTxsResponseSize,
|
|
12
|
+
} from './protocols/block_txs/block_txs_reqresp.js';
|
|
10
13
|
import { StatusMessage } from './protocols/status.js';
|
|
14
|
+
import { calculateTxResponseSize } from './protocols/tx.js';
|
|
11
15
|
import type { ReqRespStatus } from './status.js';
|
|
12
16
|
|
|
13
17
|
/*
|
|
@@ -17,7 +21,6 @@ export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
|
|
|
17
21
|
export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
|
|
18
22
|
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
|
|
19
23
|
export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
|
|
20
|
-
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
|
|
21
24
|
export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
|
|
22
25
|
export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
|
|
23
26
|
|
|
@@ -26,7 +29,6 @@ export enum ReqRespSubProtocol {
|
|
|
26
29
|
STATUS = STATUS_PROTOCOL,
|
|
27
30
|
GOODBYE = GOODBYE_PROTOCOL,
|
|
28
31
|
TX = TX_REQ_PROTOCOL,
|
|
29
|
-
BLOCK = BLOCK_REQ_PROTOCOL,
|
|
30
32
|
AUTH = AUTH_PROTOCOL,
|
|
31
33
|
BLOCK_TXS = BLOCK_TXS_REQ_PROTOCOL,
|
|
32
34
|
}
|
|
@@ -76,32 +78,28 @@ export interface ProtocolRateLimitQuota {
|
|
|
76
78
|
globalLimit: RateLimitQuota;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
export const noopValidator = () => Promise.resolve(true);
|
|
80
|
-
|
|
81
81
|
/**
|
|
82
82
|
* A type mapping from supprotocol to it's handling function
|
|
83
83
|
*/
|
|
84
84
|
export type ReqRespSubProtocolHandlers = Record<ReqRespSubProtocol, ReqRespSubProtocolHandler>;
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Protocols that are always allowed without authentication, even when p2pAllowOnlyValidators is enabled.
|
|
88
|
+
* These are needed for the handshake and connection management flow.
|
|
89
|
+
* All other protocols require the remote peer to be authenticated.
|
|
90
|
+
*/
|
|
91
|
+
export const UNAUTHENTICATED_ALLOWED_PROTOCOLS: ReadonlySet<ReqRespSubProtocol> = new Set([
|
|
92
|
+
ReqRespSubProtocol.PING,
|
|
93
|
+
ReqRespSubProtocol.STATUS,
|
|
94
|
+
ReqRespSubProtocol.AUTH,
|
|
95
|
+
ReqRespSubProtocol.GOODBYE,
|
|
96
|
+
]);
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
102
|
-
[ReqRespSubProtocol.AUTH]: noopValidator,
|
|
103
|
-
[ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
|
|
104
|
-
};
|
|
98
|
+
/**
|
|
99
|
+
* Callback that checks whether a peer should be rejected from req/resp data protocols.
|
|
100
|
+
* Returns true if the peer should be rejected (i.e. p2pAllowOnlyValidators is on and peer is unauthenticated).
|
|
101
|
+
*/
|
|
102
|
+
export type ShouldRejectPeer = (peerId: string) => boolean;
|
|
105
103
|
|
|
106
104
|
/*
|
|
107
105
|
* Helper class to sub-protocol validation error*/
|
|
@@ -196,10 +194,6 @@ export const subProtocolMap = {
|
|
|
196
194
|
request: RequestableBuffer,
|
|
197
195
|
response: RequestableBuffer,
|
|
198
196
|
},
|
|
199
|
-
[ReqRespSubProtocol.BLOCK]: {
|
|
200
|
-
request: Fr, // block number
|
|
201
|
-
response: L2BlockNew,
|
|
202
|
-
},
|
|
203
197
|
[ReqRespSubProtocol.AUTH]: {
|
|
204
198
|
request: AuthRequest,
|
|
205
199
|
response: AuthResponse,
|
|
@@ -210,25 +204,28 @@ export const subProtocolMap = {
|
|
|
210
204
|
},
|
|
211
205
|
};
|
|
212
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Type for a function that calculates the expected response size in KB for a given request.
|
|
209
|
+
*/
|
|
210
|
+
export type ExpectedResponseSizeCalculator = (requestBuffer: Buffer) => number;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Map of sub-protocols to their expected response size calculators.
|
|
214
|
+
* These are used to validate that responses don't exceed expected sizes based on request parameters.
|
|
215
|
+
*/
|
|
216
|
+
export const subProtocolSizeCalculators: Record<ReqRespSubProtocol, ExpectedResponseSizeCalculator> = {
|
|
217
|
+
[ReqRespSubProtocol.TX]: calculateTxResponseSize,
|
|
218
|
+
[ReqRespSubProtocol.BLOCK_TXS]: calculateBlockTxsResponseSize,
|
|
219
|
+
[ReqRespSubProtocol.STATUS]: () => 1,
|
|
220
|
+
[ReqRespSubProtocol.PING]: () => 1,
|
|
221
|
+
[ReqRespSubProtocol.AUTH]: () => 1,
|
|
222
|
+
[ReqRespSubProtocol.GOODBYE]: () => 1, // No response expected, but provide minimal limit
|
|
223
|
+
};
|
|
224
|
+
|
|
213
225
|
export interface ReqRespInterface {
|
|
214
|
-
start(
|
|
215
|
-
|
|
216
|
-
subProtocolValidators: ReqRespSubProtocolValidators,
|
|
217
|
-
): Promise<void>;
|
|
218
|
-
addSubProtocol(
|
|
219
|
-
subProtocol: ReqRespSubProtocol,
|
|
220
|
-
handler: ReqRespSubProtocolHandler,
|
|
221
|
-
validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
222
|
-
): Promise<void>;
|
|
226
|
+
start(subProtocolHandlers: Partial<ReqRespSubProtocolHandlers>): Promise<void>;
|
|
227
|
+
addSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void>;
|
|
223
228
|
stop(): Promise<void>;
|
|
224
|
-
sendBatchRequest<SubProtocol extends ReqRespSubProtocol>(
|
|
225
|
-
subProtocol: SubProtocol,
|
|
226
|
-
requests: InstanceType<SubProtocolMap[SubProtocol]['request']>[],
|
|
227
|
-
pinnedPeer: PeerId | undefined,
|
|
228
|
-
timeoutMs?: number,
|
|
229
|
-
maxPeers?: number,
|
|
230
|
-
maxRetryAttempts?: number,
|
|
231
|
-
): Promise<InstanceType<SubProtocolMap[SubProtocol]['response']>[]>;
|
|
232
229
|
sendRequestToPeer(
|
|
233
230
|
peerId: PeerId,
|
|
234
231
|
subProtocol: ReqRespSubProtocol,
|
|
@@ -237,4 +234,9 @@ export interface ReqRespInterface {
|
|
|
237
234
|
): Promise<ReqRespResponse>;
|
|
238
235
|
|
|
239
236
|
updateConfig(config: Partial<P2PReqRespConfig>): void;
|
|
237
|
+
|
|
238
|
+
/** Sets the callback used to reject unauthenticated peers on gated req/resp protocols. */
|
|
239
|
+
setShouldRejectPeer(checker: ShouldRejectPeer): void;
|
|
240
|
+
|
|
241
|
+
getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>;
|
|
240
242
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Request response metrics
|
|
2
|
-
import { Attributes, Metrics } from '@aztec/telemetry-client';
|
|
2
|
+
import { Attributes, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
3
3
|
import type { TelemetryClient, Tracer, UpDownCounter } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
|
+
import { ReqRespSubProtocol } from './interface.js';
|
|
6
|
+
|
|
5
7
|
export class ReqRespMetrics {
|
|
6
8
|
public readonly tracer: Tracer;
|
|
7
9
|
|
|
@@ -18,27 +20,49 @@ export class ReqRespMetrics {
|
|
|
18
20
|
this.tracer = telemetryClient.getTracer(name);
|
|
19
21
|
|
|
20
22
|
const meter = telemetryClient.getMeter(name);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const protocolAttrs = {
|
|
24
|
+
[Attributes.P2P_REQ_RESP_PROTOCOL]: [
|
|
25
|
+
ReqRespSubProtocol.PING,
|
|
26
|
+
ReqRespSubProtocol.STATUS,
|
|
27
|
+
ReqRespSubProtocol.GOODBYE,
|
|
28
|
+
ReqRespSubProtocol.TX,
|
|
29
|
+
ReqRespSubProtocol.AUTH,
|
|
30
|
+
ReqRespSubProtocol.BLOCK_TXS,
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
this.sentRequests = createUpDownCounterWithDefault(meter, Metrics.P2P_REQ_RESP_SENT_REQUESTS, protocolAttrs);
|
|
34
|
+
this.receivedRequests = createUpDownCounterWithDefault(
|
|
35
|
+
meter,
|
|
36
|
+
Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS,
|
|
37
|
+
protocolAttrs,
|
|
38
|
+
);
|
|
23
39
|
|
|
24
|
-
this.failedOutboundRequests =
|
|
40
|
+
this.failedOutboundRequests = createUpDownCounterWithDefault(
|
|
41
|
+
meter,
|
|
42
|
+
Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS,
|
|
43
|
+
protocolAttrs,
|
|
44
|
+
);
|
|
25
45
|
|
|
26
|
-
this.failedInboundRequests =
|
|
46
|
+
this.failedInboundRequests = createUpDownCounterWithDefault(
|
|
47
|
+
meter,
|
|
48
|
+
Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS,
|
|
49
|
+
protocolAttrs,
|
|
50
|
+
);
|
|
27
51
|
}
|
|
28
52
|
|
|
29
|
-
public recordRequestSent(protocol:
|
|
53
|
+
public recordRequestSent(protocol: ReqRespSubProtocol) {
|
|
30
54
|
this.sentRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
31
55
|
}
|
|
32
56
|
|
|
33
|
-
public recordRequestReceived(protocol:
|
|
57
|
+
public recordRequestReceived(protocol: ReqRespSubProtocol) {
|
|
34
58
|
this.receivedRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
35
59
|
}
|
|
36
60
|
|
|
37
|
-
public recordRequestError(protocol:
|
|
61
|
+
public recordRequestError(protocol: ReqRespSubProtocol) {
|
|
38
62
|
this.failedOutboundRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
39
63
|
}
|
|
40
64
|
|
|
41
|
-
public recordResponseError(protocol:
|
|
65
|
+
public recordResponseError(protocol: ReqRespSubProtocol) {
|
|
42
66
|
this.failedInboundRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
43
67
|
}
|
|
44
68
|
}
|
|
@@ -58,12 +58,20 @@ export class BitVector {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* Returns all indices which are set to true
|
|
62
|
-
*
|
|
61
|
+
* Returns all indices which are set to true.
|
|
62
|
+
* Ordered by index. No duplicates.
|
|
63
|
+
*/
|
|
63
64
|
getTrueIndices(): number[] {
|
|
64
65
|
return Array.from({ length: this.length }, (_, i) => i).filter(i => this.isSet(i));
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Returns true if no indices are set to true
|
|
70
|
+
* */
|
|
71
|
+
isEmpty(): boolean {
|
|
72
|
+
return this.getTrueIndices().length === 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
67
75
|
/**
|
|
68
76
|
* Serializes the BitVector object into a Buffer
|
|
69
77
|
*
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
2
|
+
import { TxArray, TxHash } from '@aztec/stdlib/tx';
|
|
2
3
|
|
|
3
4
|
import type { PeerId } from '@libp2p/interface';
|
|
4
5
|
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
6
|
+
import type { AttestationPoolApi } from '../../../../mem_pools/attestation_pool/attestation_pool.js';
|
|
7
|
+
import type { TxPoolV2 } from '../../../../mem_pools/tx_pool_v2/interfaces.js';
|
|
7
8
|
import type { ReqRespSubProtocolHandler } from '../../interface.js';
|
|
8
9
|
import { ReqRespStatus, ReqRespStatusError } from '../../status.js';
|
|
9
10
|
import { BitVector } from './bitvector.js';
|
|
@@ -12,10 +13,15 @@ import { BlockTxsRequest, BlockTxsResponse } from './block_txs_reqresp.js';
|
|
|
12
13
|
/**
|
|
13
14
|
* Handler for block txs requests
|
|
14
15
|
* @param attestationPool - the attestation pool to check for block proposals
|
|
15
|
-
* @param
|
|
16
|
+
* @param archiver - the archiver to look up blocks by archive root
|
|
17
|
+
* @param txPool - the tx pool to fetch transactions from
|
|
16
18
|
* @returns the BlockTxs request handler
|
|
17
19
|
*/
|
|
18
|
-
export function reqRespBlockTxsHandler(
|
|
20
|
+
export function reqRespBlockTxsHandler(
|
|
21
|
+
attestationPool: AttestationPoolApi,
|
|
22
|
+
archiver: L2BlockSource,
|
|
23
|
+
txPool: TxPoolV2,
|
|
24
|
+
): ReqRespSubProtocolHandler {
|
|
19
25
|
/**
|
|
20
26
|
* Handler for block txs requests
|
|
21
27
|
* @param msg - the block txs request message
|
|
@@ -30,23 +36,44 @@ export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool:
|
|
|
30
36
|
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
// In principle assume we haven't found the block. This is how that is signaled to the requester.
|
|
40
|
+
let availableIndicesBitVector: BitVector = BitVector.init(0, []);
|
|
41
|
+
// We always try to service the explicitly requested tx hashes, even if we don't have the block.
|
|
42
|
+
const requestedTxsHashes: Set<string> = new Set(request.txHashes.map(h => h.toString()));
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
// First try attestation pool, then fall back to archiver.
|
|
45
|
+
let blockTxHashes = (await attestationPool.getBlockProposalByArchive(request.archiveRoot.toString()))?.txHashes;
|
|
46
|
+
if (!blockTxHashes) {
|
|
47
|
+
blockTxHashes = (await archiver.getBlock({ archive: request.archiveRoot }))?.body.txEffects.map(
|
|
48
|
+
effect => effect.txHash,
|
|
49
|
+
);
|
|
37
50
|
}
|
|
38
51
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
// If we have found the block,
|
|
53
|
+
if (blockTxHashes) {
|
|
54
|
+
// First confirm that we are talking about the same block (up to tx hashes and order).
|
|
55
|
+
// If we are not, then we can't:
|
|
56
|
+
// 1. Use the indices from the request to get the txs from the pool.
|
|
57
|
+
// 2. Respond to the peer with the txs we have using indices.
|
|
58
|
+
const blockTxHashesCommitment = BlockTxsRequest.computeBlockTxHashesCommitment(blockTxHashes);
|
|
59
|
+
if (blockTxHashesCommitment.equals(request.blockTxHashesCommitment)) {
|
|
60
|
+
// In that case, we can also get the available indices from the pool.
|
|
61
|
+
const txsAvailableInPool = await txPool.hasTxs(blockTxHashes);
|
|
62
|
+
// Map txs in the pool to their indices in the block
|
|
63
|
+
const availableIndices = txsAvailableInPool.map((hasTx, idx) => (hasTx ? idx : -1)).filter(idx => idx !== -1);
|
|
64
|
+
availableIndicesBitVector = BitVector.init(blockTxHashes.length, availableIndices);
|
|
43
65
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
66
|
+
// We add the requested tx hashes (by index) to the list of tx hashes we are sending to the peer.
|
|
67
|
+
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
68
|
+
blockTxHashes.filter((_, idx) => requestedIndices.has(idx)).forEach(h => requestedTxsHashes.add(h.toString()));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
48
71
|
|
|
49
|
-
|
|
72
|
+
// Finally, get the txs from the pool and create the response.
|
|
73
|
+
const responseTxs = (
|
|
74
|
+
await txPool.getTxsByHash(Array.from(requestedTxsHashes).map(h => TxHash.fromString(h)))
|
|
75
|
+
).filter(tx => !!tx);
|
|
76
|
+
const response = new BlockTxsResponse(new TxArray(...responseTxs), availableIndicesBitVector);
|
|
50
77
|
|
|
51
78
|
return response.toBuffer();
|
|
52
79
|
};
|
|
@@ -1,20 +1,82 @@
|
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
1
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import {
|
|
4
|
+
import { MAX_TX_SIZE_KB } from '@aztec/stdlib/p2p';
|
|
5
|
+
import { TxArray, type TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
4
8
|
|
|
5
9
|
import { BitVector } from './bitvector.js';
|
|
6
10
|
|
|
11
|
+
/** Minimal interface for a block source that provides tx hashes and an archive root. */
|
|
12
|
+
export interface BlockTxsSource {
|
|
13
|
+
txHashes: TxHash[];
|
|
14
|
+
archive: Fr;
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
/**
|
|
8
18
|
* Request message for requesting specific transactions from a block
|
|
9
19
|
*/
|
|
10
20
|
export class BlockTxsRequest {
|
|
11
21
|
constructor(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//
|
|
22
|
+
// Archive root after the proposed block is applied (proposal identifier).
|
|
23
|
+
readonly archiveRoot: Fr,
|
|
24
|
+
// BitVector indicating which txs from the block (proposal) we are requesting
|
|
25
|
+
// 1 means we want the tx, 0 means we don't.
|
|
26
|
+
// This will only return txs in the response if the peer has the block (proposal).
|
|
15
27
|
readonly txIndices: BitVector,
|
|
28
|
+
// If we ask for txs via indices, the responder needs to be sure that we are talking about the same block.
|
|
29
|
+
// Unfortunately, the archive root is not enough, since it's possible for the peer to have seen a different
|
|
30
|
+
// block (proposal) with the same archive root but different txs. We include a commitment to the tx hashes
|
|
31
|
+
// so that the responder can verify this (for its own sake, and not be penalized).
|
|
32
|
+
readonly blockTxHashesCommitment: Buffer32,
|
|
33
|
+
// Explicit hashes of txs we are requesting (optional). The peer will try to serve these txs even if
|
|
34
|
+
// it doesn't have the block. If the requester lists txs from the block here, this serves as a fallback.
|
|
35
|
+
// Note: if a hash here is NOT part of the block (proposal), the peer can decide to return it or not.
|
|
36
|
+
readonly txHashes: TxHashArray,
|
|
16
37
|
) {}
|
|
17
38
|
|
|
39
|
+
static computeBlockTxHashesCommitment(blockTxHashes: TxHash[]): Buffer32 {
|
|
40
|
+
return Buffer32.fromBuffer(createHash('sha256').update(serializeToBuffer(blockTxHashes)).digest());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Creates new BlockTxsRequest given a block txs source and missing tx hashes.
|
|
45
|
+
*
|
|
46
|
+
* @param blockTxsSource - The block or proposal for which we are making the request
|
|
47
|
+
* @param missingTxHashes - Tx hashes from the source we are missing
|
|
48
|
+
* @param includeFullTxHashes - Whether to include full list of missing tx hashes in the request or just Bitvector indices
|
|
49
|
+
*
|
|
50
|
+
* @returns undefined if there were no missingTxHashes matching the source hashes, otherwise
|
|
51
|
+
* returns new BlockTxsRequest
|
|
52
|
+
*/
|
|
53
|
+
static fromTxsSourceAndMissingTxs(
|
|
54
|
+
blockTxsSource: BlockTxsSource,
|
|
55
|
+
missingTxHashes: TxHash[],
|
|
56
|
+
includeFullTxHashes = false,
|
|
57
|
+
): BlockTxsRequest | undefined {
|
|
58
|
+
if (missingTxHashes.length === 0) {
|
|
59
|
+
return undefined; // No missing txs to request
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const missingHashesSet = new Set(missingTxHashes.map(t => t.toString()));
|
|
63
|
+
|
|
64
|
+
// We cannot request txs that are not part of the block
|
|
65
|
+
if (!missingHashesSet.isSubsetOf(new Set(blockTxsSource.txHashes.map(t => t.toString())))) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const missingIndices = blockTxsSource.txHashes
|
|
70
|
+
.map((hash, idx) => (missingHashesSet.has(hash.toString()) ? idx : -1))
|
|
71
|
+
.filter(i => i != -1);
|
|
72
|
+
|
|
73
|
+
const requestBitVector = BitVector.init(blockTxsSource.txHashes.length, missingIndices);
|
|
74
|
+
const hashes = includeFullTxHashes ? new TxHashArray(...missingTxHashes) : new TxHashArray();
|
|
75
|
+
const commitment = BlockTxsRequest.computeBlockTxHashesCommitment(blockTxsSource.txHashes);
|
|
76
|
+
|
|
77
|
+
return new BlockTxsRequest(blockTxsSource.archive, requestBitVector, commitment, hashes);
|
|
78
|
+
}
|
|
79
|
+
|
|
18
80
|
/**
|
|
19
81
|
* Deserializes the BlockTxRequest object from a Buffer
|
|
20
82
|
* @param buffer - Buffer or BufferReader object to deserialize
|
|
@@ -22,10 +84,12 @@ export class BlockTxsRequest {
|
|
|
22
84
|
*/
|
|
23
85
|
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
|
|
24
86
|
const reader = BufferReader.asReader(buffer);
|
|
25
|
-
const
|
|
87
|
+
const archiveRoot = Fr.fromBuffer(reader);
|
|
26
88
|
const txIndices = BitVector.fromBuffer(reader);
|
|
89
|
+
const commitment = Buffer32.fromBuffer(reader);
|
|
90
|
+
const txHashes = TxHashArray.fromBuffer(reader);
|
|
27
91
|
|
|
28
|
-
return new BlockTxsRequest(
|
|
92
|
+
return new BlockTxsRequest(archiveRoot, txIndices, commitment, txHashes);
|
|
29
93
|
}
|
|
30
94
|
|
|
31
95
|
/**
|
|
@@ -33,7 +97,12 @@ export class BlockTxsRequest {
|
|
|
33
97
|
* @returns Buffer representation of the BlockTxRequest object
|
|
34
98
|
*/
|
|
35
99
|
toBuffer(): Buffer {
|
|
36
|
-
return serializeToBuffer([
|
|
100
|
+
return serializeToBuffer([
|
|
101
|
+
this.archiveRoot,
|
|
102
|
+
this.txIndices.toBuffer(),
|
|
103
|
+
this.blockTxHashesCommitment.toBuffer(),
|
|
104
|
+
this.txHashes.toBuffer(),
|
|
105
|
+
]);
|
|
37
106
|
}
|
|
38
107
|
}
|
|
39
108
|
|
|
@@ -42,13 +111,23 @@ export class BlockTxsRequest {
|
|
|
42
111
|
*/
|
|
43
112
|
export class BlockTxsResponse {
|
|
44
113
|
constructor(
|
|
45
|
-
|
|
46
|
-
readonly txs: TxArray,
|
|
114
|
+
// List of transactions we requested and peer has.
|
|
115
|
+
readonly txs: TxArray,
|
|
47
116
|
// BitVector indicating which txs from the proposal are available at the peer
|
|
48
|
-
// 1 means the tx is available, 0 means it is not
|
|
117
|
+
// 1 means the tx is available, 0 means it is not.
|
|
118
|
+
// The vector should be empty to signal that the peer doesn't have the block.
|
|
119
|
+
// Otherwise, it should be a subset of the indices of the block tx hashes.
|
|
49
120
|
readonly txIndices: BitVector,
|
|
50
121
|
) {}
|
|
51
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Whether the response indicates that the peer has the block.
|
|
125
|
+
* @returns True if the peer has the block, false otherwise.
|
|
126
|
+
*/
|
|
127
|
+
peerHasBlock(): boolean {
|
|
128
|
+
return this.txIndices.getLength() > 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
52
131
|
/**
|
|
53
132
|
* Deserializes the BlockTxResponse object from a Buffer
|
|
54
133
|
* @param buffer - Buffer or BufferReader object to deserialize
|
|
@@ -56,24 +135,37 @@ export class BlockTxsResponse {
|
|
|
56
135
|
*/
|
|
57
136
|
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
|
|
58
137
|
const reader = BufferReader.asReader(buffer);
|
|
59
|
-
const blockHash = Fr.fromBuffer(reader);
|
|
60
138
|
const txs = TxArray.fromBuffer(reader);
|
|
61
139
|
const txIndices = BitVector.fromBuffer(reader);
|
|
62
140
|
|
|
63
|
-
return new BlockTxsResponse(
|
|
141
|
+
return new BlockTxsResponse(txs, txIndices);
|
|
64
142
|
}
|
|
65
143
|
|
|
66
144
|
/**
|
|
67
145
|
* Serializes the BlockTxResponse object into a Buffer
|
|
68
|
-
* @dev: In current implementation, txIndices is serialized as Buffer of unknown length,
|
|
69
|
-
* thus we serialize it last
|
|
70
146
|
* @returns Buffer representation of the BlockTxResponse object
|
|
71
147
|
*/
|
|
72
148
|
toBuffer(): Buffer {
|
|
73
|
-
return serializeToBuffer([this.
|
|
149
|
+
return serializeToBuffer([this.txs.toBuffer(), this.txIndices.toBuffer()]);
|
|
74
150
|
}
|
|
75
151
|
|
|
76
152
|
static empty(): BlockTxsResponse {
|
|
77
|
-
return new BlockTxsResponse(
|
|
153
|
+
return new BlockTxsResponse(new TxArray(), BitVector.init(0, []));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Calculate the expected response size for a BLOCK_TXS request.
|
|
159
|
+
* @param requestBuffer - The serialized request buffer containing BlockTxsRequest
|
|
160
|
+
* @returns Expected response size in KB
|
|
161
|
+
*/
|
|
162
|
+
export function calculateBlockTxsResponseSize(requestBuffer: Buffer): number {
|
|
163
|
+
try {
|
|
164
|
+
const request = BlockTxsRequest.fromBuffer(requestBuffer);
|
|
165
|
+
const requestedTxCount = request.txIndices.getTrueIndices().length;
|
|
166
|
+
return requestedTxCount * MAX_TX_SIZE_KB + 1; // +1 KB overhead for serialization
|
|
167
|
+
} catch {
|
|
168
|
+
// If we can't parse the request, fall back to allowing a single transaction response
|
|
169
|
+
return MAX_TX_SIZE_KB + 1;
|
|
78
170
|
}
|
|
79
171
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chunk } from '@aztec/foundation/collection';
|
|
2
|
+
import { MAX_TX_SIZE_KB } from '@aztec/stdlib/p2p';
|
|
2
3
|
import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
3
4
|
|
|
4
5
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -50,8 +51,27 @@ export function reqRespTxHandler(mempools: MemPools): ReqRespSubProtocolHandler
|
|
|
50
51
|
* Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
|
|
51
52
|
* we define Q as max number of transactions per batch, the comment explains why we use 8.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
-
//more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
|
|
55
|
-
export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
|
|
54
|
+
export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 8): Array<TxHashArray> {
|
|
56
55
|
return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
|
|
57
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Calculate the expected response size for a TX request.
|
|
60
|
+
* @param requestBuffer - The serialized request buffer containing TxHashArray
|
|
61
|
+
* @returns Expected response size in KB
|
|
62
|
+
*/
|
|
63
|
+
export function calculateTxResponseSize(requestBuffer: Buffer): number {
|
|
64
|
+
try {
|
|
65
|
+
const txHashes = TxHashArray.fromBuffer(requestBuffer);
|
|
66
|
+
// TxHashArray.fromBuffer returns empty array on parse failure, so check for that
|
|
67
|
+
if (txHashes.length === 0 && requestBuffer.length > 0) {
|
|
68
|
+
// If we got an empty array but had a non-empty buffer, parsing likely failed
|
|
69
|
+
// Fall back to allowing a single transaction response
|
|
70
|
+
return MAX_TX_SIZE_KB + 1;
|
|
71
|
+
}
|
|
72
|
+
return Math.max(txHashes.length, 1) * MAX_TX_SIZE_KB + 1; // +1 KB overhead, at least 1 tx
|
|
73
|
+
} catch {
|
|
74
|
+
// If we can't parse the request, fall back to allowing a single transaction response
|
|
75
|
+
return MAX_TX_SIZE_KB + 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -97,9 +97,10 @@ export function prettyPrintRateLimitStatus(status: RateLimitStatus) {
|
|
|
97
97
|
* 2. Individual rate limits for each peer.
|
|
98
98
|
*
|
|
99
99
|
* How it works:
|
|
100
|
-
* - When a request comes in, it first checks against the
|
|
101
|
-
* - If the
|
|
102
|
-
* - The request is only allowed if both the
|
|
100
|
+
* - When a request comes in, it first checks against the peer's individual rate limit.
|
|
101
|
+
* - If the peer limit allows, it then checks against the global rate limit.
|
|
102
|
+
* - The request is only allowed if both the peer-specific and global limits allow it.
|
|
103
|
+
* - Checking peer limit first ensures a rate-limited peer cannot exhaust the global quota.
|
|
103
104
|
* - It automatically creates and manages rate limiters for new peers as they make requests.
|
|
104
105
|
* - It periodically cleans up rate limiters for inactive peers to conserve memory.
|
|
105
106
|
*
|
|
@@ -119,10 +120,6 @@ export class SubProtocolRateLimiter {
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
allow(peerId: PeerId): RateLimitStatus {
|
|
122
|
-
if (!this.globalLimiter.allow()) {
|
|
123
|
-
return RateLimitStatus.DeniedGlobal;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
123
|
const peerIdStr = peerId.toString();
|
|
127
124
|
let peerLimiter: PeerRateLimiter | undefined = this.peerLimiters.get(peerIdStr);
|
|
128
125
|
if (!peerLimiter) {
|
|
@@ -135,10 +132,17 @@ export class SubProtocolRateLimiter {
|
|
|
135
132
|
} else {
|
|
136
133
|
peerLimiter.lastAccess = Date.now();
|
|
137
134
|
}
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
|
|
136
|
+
// Check peer limit first: a rate-limited peer must not consume global quota,
|
|
137
|
+
// otherwise one spamming peer can starve all others by exhausting the global bucket.
|
|
138
|
+
if (!peerLimiter.limiter.allow()) {
|
|
140
139
|
return RateLimitStatus.DeniedPeer;
|
|
141
140
|
}
|
|
141
|
+
|
|
142
|
+
if (!this.globalLimiter.allow()) {
|
|
143
|
+
return RateLimitStatus.DeniedGlobal;
|
|
144
|
+
}
|
|
145
|
+
|
|
142
146
|
return RateLimitStatus.Allowed;
|
|
143
147
|
}
|
|
144
148
|
|
|
@@ -9,7 +9,7 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
9
9
|
},
|
|
10
10
|
globalLimit: {
|
|
11
11
|
quotaTimeMs: 1000,
|
|
12
|
-
quotaCount:
|
|
12
|
+
quotaCount: 50,
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
[ReqRespSubProtocol.STATUS]: {
|
|
@@ -19,7 +19,7 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
19
19
|
},
|
|
20
20
|
globalLimit: {
|
|
21
21
|
quotaTimeMs: 1000,
|
|
22
|
-
quotaCount:
|
|
22
|
+
quotaCount: 50,
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
25
|
[ReqRespSubProtocol.AUTH]: {
|
|
@@ -42,16 +42,6 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
42
42
|
quotaCount: 200,
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
-
[ReqRespSubProtocol.BLOCK]: {
|
|
46
|
-
peerLimit: {
|
|
47
|
-
quotaTimeMs: 1000,
|
|
48
|
-
quotaCount: 2,
|
|
49
|
-
},
|
|
50
|
-
globalLimit: {
|
|
51
|
-
quotaTimeMs: 1000,
|
|
52
|
-
quotaCount: 5,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
45
|
[ReqRespSubProtocol.GOODBYE]: {
|
|
56
46
|
peerLimit: {
|
|
57
47
|
quotaTimeMs: 1000,
|
|
@@ -59,7 +49,7 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
59
49
|
},
|
|
60
50
|
globalLimit: {
|
|
61
51
|
quotaTimeMs: 1000,
|
|
62
|
-
quotaCount:
|
|
52
|
+
quotaCount: 50,
|
|
63
53
|
},
|
|
64
54
|
},
|
|
65
55
|
[ReqRespSubProtocol.BLOCK_TXS]: {
|