@aztec/p2p 0.0.0-test.0 → 0.0.1-commit.023c3e5
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 +26 -13
- package/dest/client/factory.d.ts +15 -5
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +61 -25
- package/dest/client/index.d.ts +2 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +170 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +75 -193
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +765 -229
- 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 +154 -125
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +182 -34
- package/dest/enr/generate-enr.d.ts +11 -3
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +4 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -25
- 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 +299 -174
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +29 -11
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +168 -62
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +24 -10
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +133 -82
- package/dest/mem_pools/attestation_pool/mocks.d.ts +234 -11
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +19 -21
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +16 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +56 -41
- 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 +75 -16
- 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 +493 -142
- 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 +7 -2
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +72 -11
- 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 +276 -45
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +7 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +79 -10
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +76 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- 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/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- 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/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- 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 +7 -6
- 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 +60 -87
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -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 +24 -29
- package/dest/msg_validators/tx_validator/factory.d.ts +21 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +84 -0
- 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 +12 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +110 -0
- package/dest/msg_validators/tx_validator/index.d.ts +9 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +8 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +10 -5
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +40 -21
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
- 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 +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +14 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
- 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 +8 -7
- 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.d.ts +10 -9
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +64 -37
- package/dest/services/dummy_service.d.ts +66 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +130 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +75 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +5 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +20 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +122 -0
- package/dest/services/libp2p/libp2p_service.d.ts +107 -95
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +1328 -313
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +12 -3
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +44 -12
- package/dest/services/peer-manager/peer_manager.d.ts +103 -23
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +551 -82
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +43 -2
- 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/config.d.ts +11 -9
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +23 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +73 -10
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +32 -17
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +154 -84
- 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/index.d.ts +3 -2
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +75 -24
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +46 -27
- 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 +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +6 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +30 -6
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +34 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +87 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +52 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +59 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +105 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +3 -1
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +1 -3
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +40 -7
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +76 -5
- package/dest/services/reqresp/protocols/tx.d.ts +14 -4
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- 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 +21 -1
- package/dest/services/reqresp/reqresp.d.ts +29 -66
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +753 -248
- package/dest/services/reqresp/status.d.ts +10 -4
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +40 -20
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +28 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +66 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +311 -0
- package/dest/services/tx_collection/index.d.ts +4 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +3 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +31 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +177 -0
- package/dest/services/tx_collection/tx_collection.d.ts +110 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +128 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +111 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +51 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +219 -0
- package/dest/services/tx_provider_instrumentation.d.ts +16 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +4 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +3 -0
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -16
- package/dest/test-helpers/mock-pubsub.d.ts +59 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +130 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +62 -28
- 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 +259 -90
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +51 -11
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +232 -53
- package/dest/types/index.d.ts +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +24 -16
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +75 -69
- package/dest/versioning.d.ts +4 -4
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +32 -27
- package/src/bootstrap/bootstrap.ts +34 -15
- package/src/client/factory.ts +135 -53
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +213 -0
- package/src/client/p2p_client.ts +476 -383
- 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 +304 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +119 -24
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +352 -201
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +233 -72
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +199 -96
- package/src/mem_pools/attestation_pool/mocks.ts +24 -17
- package/src/mem_pools/instrumentation.ts +72 -48
- 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 +580 -143
- 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 +9 -2
- package/src/mem_pools/tx_pool/tx_pool.ts +75 -10
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +225 -36
- package/src/msg_validators/attestation_validator/attestation_validator.ts +72 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +94 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- 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/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +10 -9
- package/src/msg_validators/tx_validator/data_validator.ts +95 -71
- package/src/msg_validators/tx_validator/double_spend_validator.ts +23 -20
- package/src/msg_validators/tx_validator/factory.ts +151 -0
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -0
- package/src/msg_validators/tx_validator/index.ts +8 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +72 -24
- package/src/msg_validators/tx_validator/phases_validator.ts +118 -0
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +52 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +22 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +14 -8
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +85 -39
- package/src/services/dummy_service.ts +198 -9
- package/src/services/encoding.ts +82 -6
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +126 -0
- package/src/services/libp2p/libp2p_service.ts +1170 -353
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +55 -12
- package/src/services/peer-manager/peer_manager.ts +657 -80
- package/src/services/peer-manager/peer_scoring.ts +45 -3
- 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/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +77 -10
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +166 -95
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +95 -37
- package/src/services/reqresp/metrics.ts +40 -28
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +26 -4
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +106 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +67 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +121 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +9 -7
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +121 -5
- package/src/services/reqresp/protocols/tx.ts +36 -8
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +449 -271
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +65 -22
- package/src/services/tx_collection/config.ts +98 -0
- package/src/services/tx_collection/fast_tx_collection.ts +364 -0
- package/src/services/tx_collection/index.ts +7 -0
- package/src/services/tx_collection/instrumentation.ts +35 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
- package/src/services/tx_collection/slow_tx_collection.ts +233 -0
- package/src/services/tx_collection/tx_collection.ts +216 -0
- package/src/services/tx_collection/tx_collection_sink.ts +129 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +232 -0
- package/src/services/tx_provider_instrumentation.ts +54 -0
- package/src/test-helpers/index.ts +3 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +111 -21
- package/src/test-helpers/mock-pubsub.ts +188 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +87 -36
- 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 +434 -89
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +315 -59
- package/src/types/index.ts +2 -0
- package/src/util.ts +105 -91
- package/src/versioning.ts +11 -4
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -56
- 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 -141
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -8
- 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 -21
- 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 -174
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -29
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
4
|
+
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
import type { PeerId } from '@libp2p/interface';
|
|
7
|
+
|
|
8
|
+
import { BatchTxRequester } from '../reqresp/batch-tx-requester/batch_tx_requester.js';
|
|
9
|
+
import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
|
|
10
|
+
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
11
|
+
import type { IBatchRequestTxValidator } from '../reqresp/batch-tx-requester/tx_validator.js';
|
|
12
|
+
import { ReqRespSubProtocol } from '../reqresp/interface.js';
|
|
13
|
+
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Strategy interface for collecting transactions for block proposals.
|
|
17
|
+
* Allows swapping between different tx collection implementations for benchmarking.
|
|
18
|
+
*/
|
|
19
|
+
export interface ProposalTxCollector {
|
|
20
|
+
/**
|
|
21
|
+
* Collect transactions for a block proposal.
|
|
22
|
+
* @param txHashes - The transaction hashes to collect
|
|
23
|
+
* @param blockProposal - The block proposal containing the transactions
|
|
24
|
+
* @param pinnedPeer - Optional peer that sent the proposal (expected to have all txs)
|
|
25
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
26
|
+
* @returns The collected transactions
|
|
27
|
+
*/
|
|
28
|
+
collectTxs(
|
|
29
|
+
txHashes: TxHash[],
|
|
30
|
+
blockProposal: BlockProposal,
|
|
31
|
+
pinnedPeer: PeerId | undefined,
|
|
32
|
+
timeoutMs: number,
|
|
33
|
+
): Promise<Tx[]>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Collects transactions using the BatchTxRequester implementation.
|
|
38
|
+
* This uses a smart/dumb peer strategy with parallel workers.
|
|
39
|
+
*/
|
|
40
|
+
export class BatchTxRequesterCollector implements ProposalTxCollector {
|
|
41
|
+
constructor(
|
|
42
|
+
private p2pService: BatchTxRequesterLibP2PService,
|
|
43
|
+
private log: Logger,
|
|
44
|
+
private dateProvider: DateProvider,
|
|
45
|
+
private txValidator?: IBatchRequestTxValidator,
|
|
46
|
+
private batchTxRequesterConfig?: Partial<BatchTxRequesterConfig>,
|
|
47
|
+
) {}
|
|
48
|
+
|
|
49
|
+
async collectTxs(
|
|
50
|
+
txHashes: TxHash[],
|
|
51
|
+
blockProposal: BlockProposal,
|
|
52
|
+
pinnedPeer: PeerId | undefined,
|
|
53
|
+
timeoutMs: number,
|
|
54
|
+
): Promise<Tx[]> {
|
|
55
|
+
const {
|
|
56
|
+
batchTxRequesterSmartParallelWorkerCount: smartParallelWorkerCount,
|
|
57
|
+
batchTxRequesterDumbParallelWorkerCount: dumbParallelWorkerCount,
|
|
58
|
+
batchTxRequesterTxBatchSize: txBatchSize,
|
|
59
|
+
batchTxRequesterBadPeerThreshold: badPeerThreshold,
|
|
60
|
+
} = this.batchTxRequesterConfig ?? {};
|
|
61
|
+
|
|
62
|
+
const batchRequester = new BatchTxRequester(
|
|
63
|
+
txHashes,
|
|
64
|
+
blockProposal,
|
|
65
|
+
pinnedPeer,
|
|
66
|
+
timeoutMs,
|
|
67
|
+
this.p2pService,
|
|
68
|
+
this.log,
|
|
69
|
+
this.dateProvider,
|
|
70
|
+
{
|
|
71
|
+
smartParallelWorkerCount,
|
|
72
|
+
dumbParallelWorkerCount,
|
|
73
|
+
txBatchSize,
|
|
74
|
+
badPeerThreshold,
|
|
75
|
+
txValidator: this.txValidator,
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return await BatchTxRequester.collectAllTxs(batchRequester.run());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const DEFAULT_MAX_PEERS = 10;
|
|
84
|
+
const DEFAULT_MAX_RETRY_ATTEMPTS = 3;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Collects transactions using the sendBatchRequest implementation from ReqResp.
|
|
88
|
+
* This is the original implementation that balances requests across peers.
|
|
89
|
+
*/
|
|
90
|
+
export class SendBatchRequestCollector implements ProposalTxCollector {
|
|
91
|
+
constructor(
|
|
92
|
+
private p2pService: BatchTxRequesterLibP2PService,
|
|
93
|
+
private maxPeers: number = DEFAULT_MAX_PEERS,
|
|
94
|
+
private maxRetryAttempts: number = DEFAULT_MAX_RETRY_ATTEMPTS,
|
|
95
|
+
) {}
|
|
96
|
+
|
|
97
|
+
async collectTxs(
|
|
98
|
+
txHashes: TxHash[],
|
|
99
|
+
_blockProposal: BlockProposal,
|
|
100
|
+
pinnedPeer: PeerId | undefined,
|
|
101
|
+
timeoutMs: number,
|
|
102
|
+
): Promise<Tx[]> {
|
|
103
|
+
const txs = await this.p2pService.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
104
|
+
ReqRespSubProtocol.TX,
|
|
105
|
+
chunkTxHashesRequest(txHashes),
|
|
106
|
+
pinnedPeer,
|
|
107
|
+
timeoutMs,
|
|
108
|
+
this.maxPeers,
|
|
109
|
+
this.maxRetryAttempts,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return txs.flat();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { chunk } from '@aztec/foundation/collection';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { boundInclusive } from '@aztec/foundation/number';
|
|
5
|
+
import { RunningPromise } from '@aztec/foundation/promise';
|
|
6
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
7
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
8
|
+
import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
9
|
+
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
10
|
+
|
|
11
|
+
import { type ReqRespInterface, ReqRespSubProtocol } from '../reqresp/interface.js';
|
|
12
|
+
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
13
|
+
import type { TxCollectionConfig } from './config.js';
|
|
14
|
+
import type { FastTxCollection } from './fast_tx_collection.js';
|
|
15
|
+
import type { MissingTxInfo } from './tx_collection.js';
|
|
16
|
+
import type { TxCollectionSink } from './tx_collection_sink.js';
|
|
17
|
+
import type { TxSource } from './tx_source.js';
|
|
18
|
+
|
|
19
|
+
export class SlowTxCollection {
|
|
20
|
+
/** Map from tx hash to missing tx info to collect via slow loop */
|
|
21
|
+
private missingTxs: Map<string, MissingTxInfo> = new Map();
|
|
22
|
+
|
|
23
|
+
/** One slow collection loop for each node tx source we have */
|
|
24
|
+
private nodesSlowCollectionLoops: RunningPromise[];
|
|
25
|
+
|
|
26
|
+
/** Slow collection loop for reqresp which collects txs from peers */
|
|
27
|
+
private reqrespSlowCollectionLoop: RunningPromise;
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
private reqResp: Pick<ReqRespInterface, 'sendBatchRequest'>,
|
|
31
|
+
private nodes: TxSource[],
|
|
32
|
+
private txCollectionSink: TxCollectionSink,
|
|
33
|
+
private fastCollection: Pick<FastTxCollection, 'getFastCollectionRequests'>,
|
|
34
|
+
private constants: L1RollupConstants,
|
|
35
|
+
private config: TxCollectionConfig,
|
|
36
|
+
private dateProvider: DateProvider = new DateProvider(),
|
|
37
|
+
private log: Logger = createLogger('p2p:tx_collection_service'),
|
|
38
|
+
) {
|
|
39
|
+
this.nodesSlowCollectionLoops = this.nodes.map(
|
|
40
|
+
node =>
|
|
41
|
+
new RunningPromise(
|
|
42
|
+
() => this.collectMissingTxsFromNode(node),
|
|
43
|
+
this.log,
|
|
44
|
+
this.config.txCollectionSlowNodesIntervalMs,
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
this.reqrespSlowCollectionLoop = new RunningPromise(
|
|
49
|
+
() => this.collectMissingTxsViaReqResp(),
|
|
50
|
+
this.log,
|
|
51
|
+
this.config.txCollectionSlowReqRespIntervalMs,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public getMissingTxHashes() {
|
|
56
|
+
return Array.from(this.missingTxs.keys()).map(TxHash.fromString);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public start() {
|
|
60
|
+
this.nodesSlowCollectionLoops.forEach(loop => loop.start());
|
|
61
|
+
this.reqrespSlowCollectionLoop.start();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async stop() {
|
|
65
|
+
await Promise.all([
|
|
66
|
+
this.reqrespSlowCollectionLoop.stop(),
|
|
67
|
+
...this.nodesSlowCollectionLoops.map(loop => loop.stop()),
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public async trigger() {
|
|
72
|
+
await Promise.all([
|
|
73
|
+
this.reqrespSlowCollectionLoop.trigger(),
|
|
74
|
+
...this.nodesSlowCollectionLoops.map(loop => loop.trigger()),
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
79
|
+
public startCollecting(block: L2Block, txHashes: TxHash[]) {
|
|
80
|
+
const slot = block.header.getSlot();
|
|
81
|
+
const deadline = this.getDeadlineForSlot(slot);
|
|
82
|
+
if (+deadline < this.dateProvider.now()) {
|
|
83
|
+
this.log.debug(`Skipping collection of txs for block ${block.number} at slot ${slot} as it is already expired`, {
|
|
84
|
+
blockNumber: block.number,
|
|
85
|
+
slot: slot.toString(),
|
|
86
|
+
txHashes: txHashes.map(txHash => txHash.toString()),
|
|
87
|
+
deadline: +deadline,
|
|
88
|
+
now: this.dateProvider.now(),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (const txHash of txHashes) {
|
|
93
|
+
this.missingTxs.set(txHash.toString(), {
|
|
94
|
+
blockNumber: block.number,
|
|
95
|
+
deadline: this.getDeadlineForSlot(block.header.getSlot()),
|
|
96
|
+
readyForReqResp: this.nodes.length === 0, // If we have no nodes, we can start reqresp immediately
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Entrypoint for the node slow collection loop */
|
|
102
|
+
private async collectMissingTxsFromNode(node: TxSource) {
|
|
103
|
+
// If we have any fast requests, we skip the slow collection for this node if configured to do so
|
|
104
|
+
const requests = this.fastCollection.getFastCollectionRequests();
|
|
105
|
+
if (this.config.txCollectionDisableSlowDuringFastRequests && requests.size > 0) {
|
|
106
|
+
this.log.trace(`Skipping node slow collection due to active fast requests`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Gather all missing txs that are not in fast collection and request them from the node
|
|
111
|
+
const missingTxs = this.getMissingTxsForSlowCollection();
|
|
112
|
+
const missingTxHashes = missingTxs.map(([txHash]) => txHash).map(TxHash.fromString);
|
|
113
|
+
if (missingTxHashes.length === 0) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Request in chunks to avoid hitting RPC limits
|
|
118
|
+
for (const batch of chunk(missingTxHashes, this.config.txCollectionNodeRpcMaxBatchSize)) {
|
|
119
|
+
await this.txCollectionSink.collect(txHashes => node.getTxsByHash(txHashes), batch, {
|
|
120
|
+
description: `node ${node.getInfo()}`,
|
|
121
|
+
node: node.getInfo(),
|
|
122
|
+
method: 'slow-node-rpc',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Mark every tx that is still missing as ready for reqresp.
|
|
127
|
+
// Note that we can just mark all requested txs as ready for reqresp, without filtering out the ones
|
|
128
|
+
// we retrieved, since the ones already found will have been removed from `missingTxs`.
|
|
129
|
+
missingTxs.forEach(([_txHash, info]) => {
|
|
130
|
+
info.readyForReqResp = true;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Entrypoint for the reqresp slow collection loop */
|
|
135
|
+
private async collectMissingTxsViaReqResp() {
|
|
136
|
+
// If we have any fast requests, we skip the slow collection if configured to do so
|
|
137
|
+
const requests = this.fastCollection.getFastCollectionRequests();
|
|
138
|
+
if (this.config.txCollectionDisableSlowDuringFastRequests && requests.size > 0) {
|
|
139
|
+
this.log.trace(`Skipping reqresp slow collection due to active fast requests`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Gather all missing txs that are not in fast collection and are ready for reqresp
|
|
144
|
+
// A tx is flagged as ready for reqresp if it has been requested from a node at least once
|
|
145
|
+
const missingTxs = this.getMissingTxsForSlowCollection({ onlyReqRespReady: true });
|
|
146
|
+
if (missingTxs.length === 0) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const pinnedPeer = undefined;
|
|
151
|
+
const timeoutMs = this.config.txCollectionSlowReqRespTimeoutMs;
|
|
152
|
+
const maxPeers = boundInclusive(Math.ceil(missingTxs.length / 3), 4, 16);
|
|
153
|
+
const maxRetryAttempts = 3;
|
|
154
|
+
// Send a batch request via reqresp for the missing txs
|
|
155
|
+
await this.txCollectionSink.collect(
|
|
156
|
+
async txHashes => {
|
|
157
|
+
const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
158
|
+
ReqRespSubProtocol.TX,
|
|
159
|
+
chunkTxHashesRequest(txHashes),
|
|
160
|
+
pinnedPeer,
|
|
161
|
+
timeoutMs,
|
|
162
|
+
maxPeers,
|
|
163
|
+
maxRetryAttempts,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
return txs.flat();
|
|
167
|
+
},
|
|
168
|
+
missingTxs.map(([txHash]) => TxHash.fromString(txHash)),
|
|
169
|
+
{ description: 'slow reqresp', timeoutMs, method: 'slow-req-resp' },
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Retrieves all missing txs for the slow collection process. This is, all missing txs that are not part of a fast request. */
|
|
174
|
+
private getMissingTxsForSlowCollection(opts: { onlyReqRespReady?: boolean } = {}): [string, MissingTxInfo][] {
|
|
175
|
+
// Remove expired txs from missingTxs
|
|
176
|
+
const now = this.dateProvider.now();
|
|
177
|
+
const expiredTxs = Array.from(this.missingTxs.entries()).filter(([_, value]) => +value.deadline < now);
|
|
178
|
+
expiredTxs.forEach(([txHash]) => this.missingTxs.delete(txHash));
|
|
179
|
+
|
|
180
|
+
// Gather all txs that are marked for fast collection, we do not want to collect them via slow collection.
|
|
181
|
+
// There are some situations where a tx is in both slow and fast collection, for example when a prover node
|
|
182
|
+
// is fast-collecting missing txs for proving an epoch, and still has the tx in the slow collection loops
|
|
183
|
+
// from mined unproven blocks it has seen in the past.
|
|
184
|
+
const fastRequests = this.fastCollection.getFastCollectionRequests();
|
|
185
|
+
const fastCollectionTxs: Set<string> = new Set(
|
|
186
|
+
...Array.from(fastRequests.values()).flatMap(r => r.missingTxHashes),
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested
|
|
190
|
+
return Array.from(this.missingTxs.entries())
|
|
191
|
+
.filter(([txHash, _]) => !fastCollectionTxs.has(txHash))
|
|
192
|
+
.filter(([_, value]) => !opts.onlyReqRespReady || value.readyForReqResp);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Stop collecting the given txs since we have found them. Called whenever tx pool emits a tx-added event. */
|
|
196
|
+
public foundTxs(txs: Tx[]): void {
|
|
197
|
+
for (const txHash of txs.map(tx => tx.txHash)) {
|
|
198
|
+
this.missingTxs.delete(txHash.toString());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
204
|
+
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
205
|
+
*/
|
|
206
|
+
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
207
|
+
for (const [txHash, info] of this.missingTxs.entries()) {
|
|
208
|
+
if (info.blockNumber <= blockNumber) {
|
|
209
|
+
this.missingTxs.delete(txHash);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Stop collecting all txs for blocks greater than the block number specified.
|
|
216
|
+
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
217
|
+
*/
|
|
218
|
+
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
219
|
+
for (const [txHash, info] of this.missingTxs.entries()) {
|
|
220
|
+
if (info.blockNumber > blockNumber) {
|
|
221
|
+
this.missingTxs.delete(txHash);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
|
|
227
|
+
private getDeadlineForSlot(slotNumber: SlotNumber): Date {
|
|
228
|
+
const epoch = getEpochAtSlot(slotNumber, this.constants);
|
|
229
|
+
const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
|
|
230
|
+
const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
|
|
231
|
+
return new Date(Number(submissionEndTimestamp) * 1000);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { compactArray } from '@aztec/foundation/collection';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type PromiseWithResolvers, RunningPromise } from '@aztec/foundation/promise';
|
|
5
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
+
import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
|
|
7
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
8
|
+
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
9
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
10
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
11
|
+
|
|
12
|
+
import type { PeerId } from '@libp2p/interface';
|
|
13
|
+
|
|
14
|
+
import type { TxPool } from '../../mem_pools/index.js';
|
|
15
|
+
import type { TxPoolEvents } from '../../mem_pools/tx_pool/tx_pool.js';
|
|
16
|
+
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
17
|
+
import type { TxCollectionConfig } from './config.js';
|
|
18
|
+
import { FastTxCollection } from './fast_tx_collection.js';
|
|
19
|
+
import { SlowTxCollection } from './slow_tx_collection.js';
|
|
20
|
+
import { TxCollectionSink } from './tx_collection_sink.js';
|
|
21
|
+
import type { TxSource } from './tx_source.js';
|
|
22
|
+
|
|
23
|
+
export type CollectionMethod = 'fast-req-resp' | 'fast-node-rpc' | 'slow-req-resp' | 'slow-node-rpc';
|
|
24
|
+
|
|
25
|
+
export type MissingTxInfo = { blockNumber: BlockNumber; deadline: Date; readyForReqResp: boolean };
|
|
26
|
+
|
|
27
|
+
export type FastCollectionRequestInput =
|
|
28
|
+
| { type: 'block'; block: L2Block }
|
|
29
|
+
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
|
|
30
|
+
|
|
31
|
+
export type FastCollectionRequest = FastCollectionRequestInput & {
|
|
32
|
+
missingTxHashes: Set<string>;
|
|
33
|
+
deadline: Date;
|
|
34
|
+
blockInfo: L2BlockInfo;
|
|
35
|
+
promise: PromiseWithResolvers<void>;
|
|
36
|
+
foundTxs: Map<string, Tx>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Coordinates tx collection from remote RPC nodes and reqresp.
|
|
41
|
+
*
|
|
42
|
+
* The slow collection loops are used for periodically collecting missing txs from mined blocks,
|
|
43
|
+
* from remote RPC nodes and via reqresp. The fast collection methods are used to quickly gather
|
|
44
|
+
* txs, usually for attesting to block proposals or preparing to prove an epoch. The slow and fast
|
|
45
|
+
* collection instances both send their txs to the collection sink, which handles metrics and adds
|
|
46
|
+
* them to the tx pool. Whenever a tx is added to either the sink or the pool, this service is notified
|
|
47
|
+
* via events and notifies the slow and fast collection loops to stop collecting that tx, so that we don't
|
|
48
|
+
* collect the same tx multiple times.
|
|
49
|
+
*/
|
|
50
|
+
export class TxCollection {
|
|
51
|
+
/** Slow collection background loops */
|
|
52
|
+
protected readonly slowCollection: SlowTxCollection;
|
|
53
|
+
|
|
54
|
+
/** Fast collection methods */
|
|
55
|
+
protected readonly fastCollection: FastTxCollection;
|
|
56
|
+
|
|
57
|
+
/** Loop for periodically reconciling found transactions from the tx pool in case we missed some */
|
|
58
|
+
private readonly reconcileFoundTxsLoop: RunningPromise;
|
|
59
|
+
|
|
60
|
+
/** Handles txs found by the slow and fast collection loops */
|
|
61
|
+
private readonly txCollectionSink: TxCollectionSink;
|
|
62
|
+
|
|
63
|
+
/** Handler for the txs-added event from the tx pool */
|
|
64
|
+
protected readonly handleTxsAddedToPool: TxPoolEvents['txs-added'];
|
|
65
|
+
|
|
66
|
+
/** Handler for the txs-added event from the tx collection sink */
|
|
67
|
+
protected readonly handleTxsFound: TxPoolEvents['txs-added'];
|
|
68
|
+
|
|
69
|
+
constructor(
|
|
70
|
+
private readonly p2pService: BatchTxRequesterLibP2PService,
|
|
71
|
+
private readonly nodes: TxSource[],
|
|
72
|
+
private readonly constants: L1RollupConstants,
|
|
73
|
+
private readonly txPool: TxPool,
|
|
74
|
+
private readonly config: TxCollectionConfig,
|
|
75
|
+
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
76
|
+
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
77
|
+
private readonly log: Logger = createLogger('p2p:tx_collection_service'),
|
|
78
|
+
) {
|
|
79
|
+
this.txCollectionSink = new TxCollectionSink(this.txPool, telemetryClient, this.log);
|
|
80
|
+
|
|
81
|
+
this.fastCollection = new FastTxCollection(
|
|
82
|
+
this.p2pService,
|
|
83
|
+
this.nodes,
|
|
84
|
+
this.txCollectionSink,
|
|
85
|
+
this.config,
|
|
86
|
+
this.dateProvider,
|
|
87
|
+
this.log,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
this.slowCollection = new SlowTxCollection(
|
|
91
|
+
this.p2pService.reqResp,
|
|
92
|
+
this.nodes,
|
|
93
|
+
this.txCollectionSink,
|
|
94
|
+
this.fastCollection,
|
|
95
|
+
constants,
|
|
96
|
+
this.config,
|
|
97
|
+
this.dateProvider,
|
|
98
|
+
this.log,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
this.reconcileFoundTxsLoop = new RunningPromise(
|
|
102
|
+
() => this.reconcileFoundTxsWithPool(),
|
|
103
|
+
this.log,
|
|
104
|
+
this.config.txCollectionReconcileIntervalMs,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
this.handleTxsFound = (args: Parameters<TxPoolEvents['txs-added']>[0]) => {
|
|
108
|
+
this.foundTxs(args.txs);
|
|
109
|
+
};
|
|
110
|
+
this.txCollectionSink.on('txs-added', this.handleTxsFound);
|
|
111
|
+
|
|
112
|
+
this.handleTxsAddedToPool = (args: Parameters<TxPoolEvents['txs-added']>[0]) => {
|
|
113
|
+
const { txs, source } = args;
|
|
114
|
+
if (source !== 'tx-collection') {
|
|
115
|
+
this.foundTxs(txs);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
this.txPool.on('txs-added', this.handleTxsAddedToPool);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Starts all collection loops. */
|
|
122
|
+
public start(): Promise<void> {
|
|
123
|
+
this.slowCollection.start();
|
|
124
|
+
this.reconcileFoundTxsLoop.start();
|
|
125
|
+
|
|
126
|
+
// TODO(palla/txs): Collect mined unproven tx hashes for txs we dont have in the pool and populate missingTxs on startup
|
|
127
|
+
return Promise.resolve();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Stops all activity. */
|
|
131
|
+
public async stop() {
|
|
132
|
+
await Promise.all([this.slowCollection.stop(), this.fastCollection.stop(), this.reconcileFoundTxsLoop.stop()]);
|
|
133
|
+
|
|
134
|
+
this.txPool.removeListener('txs-added', this.handleTxsAddedToPool);
|
|
135
|
+
this.txCollectionSink.removeListener('txs-added', this.handleTxsFound);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Force trigger the slow collection and reconciliation loops */
|
|
139
|
+
public async trigger() {
|
|
140
|
+
await Promise.all([this.reconcileFoundTxsLoop.trigger(), this.slowCollection.trigger()]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Returns L1 rollup constants. */
|
|
144
|
+
public getConstants(): L1RollupConstants {
|
|
145
|
+
return this.constants;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
149
|
+
public startCollecting(block: L2Block, txHashes: TxHash[]) {
|
|
150
|
+
return this.slowCollection.startCollecting(block, txHashes);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Collects the set of txs for the given block proposal as fast as possible */
|
|
154
|
+
public collectFastForProposal(
|
|
155
|
+
blockProposal: BlockProposal,
|
|
156
|
+
blockNumber: BlockNumber,
|
|
157
|
+
txHashes: TxHash[] | string[],
|
|
158
|
+
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
159
|
+
) {
|
|
160
|
+
return this.collectFastFor({ type: 'proposal', blockProposal, blockNumber }, txHashes, opts);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Collects the set of txs for the given mined block as fast as possible */
|
|
164
|
+
public collectFastForBlock(
|
|
165
|
+
block: L2Block,
|
|
166
|
+
txHashes: TxHash[] | string[],
|
|
167
|
+
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
168
|
+
) {
|
|
169
|
+
return this.collectFastFor({ type: 'block', block }, txHashes, opts);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Collects the set of txs for the given proposal or block as fast as possible */
|
|
173
|
+
public collectFastFor(
|
|
174
|
+
input: FastCollectionRequestInput,
|
|
175
|
+
txHashes: TxHash[] | string[],
|
|
176
|
+
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
177
|
+
) {
|
|
178
|
+
return this.fastCollection.collectFastFor(input, txHashes, opts);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Mark the given txs as found. Stops collecting them. */
|
|
182
|
+
private foundTxs(txs: Tx[]) {
|
|
183
|
+
this.slowCollection.foundTxs(txs);
|
|
184
|
+
this.fastCollection.foundTxs(txs);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
189
|
+
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
190
|
+
*/
|
|
191
|
+
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
192
|
+
this.slowCollection.stopCollectingForBlocksUpTo(blockNumber);
|
|
193
|
+
this.fastCollection.stopCollectingForBlocksUpTo(blockNumber);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Stop collecting all txs for blocks greater than the block number specified.
|
|
198
|
+
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
199
|
+
*/
|
|
200
|
+
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
201
|
+
this.slowCollection.stopCollectingForBlocksAfter(blockNumber);
|
|
202
|
+
this.fastCollection.stopCollectingForBlocksAfter(blockNumber);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Every now and then, check if the pool has received one of the txs we are looking for, just to catch any race conditions */
|
|
206
|
+
private async reconcileFoundTxsWithPool() {
|
|
207
|
+
const missingTxHashes = this.slowCollection.getMissingTxHashes();
|
|
208
|
+
const foundTxs = compactArray(await this.txPool.getTxsByHash(missingTxHashes));
|
|
209
|
+
if (foundTxs.length > 0) {
|
|
210
|
+
this.log.verbose(`Found ${foundTxs.length} txs in the pool during reconciliation`, {
|
|
211
|
+
foundTxs: foundTxs.map(t => t.getTxHash().toString()),
|
|
212
|
+
});
|
|
213
|
+
this.foundTxs(foundTxs);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { elapsed } from '@aztec/foundation/timer';
|
|
3
|
+
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
4
|
+
import { Tx, type TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
+
|
|
7
|
+
import EventEmitter from 'node:events';
|
|
8
|
+
|
|
9
|
+
import type { TxPool, TxPoolEvents } from '../../mem_pools/tx_pool/tx_pool.js';
|
|
10
|
+
import { TxCollectionInstrumentation } from './instrumentation.js';
|
|
11
|
+
import type { CollectionMethod } from './tx_collection.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Executes collection requests from the fast and slow collection loops, and handles collected txs
|
|
15
|
+
* by adding them to the tx pool and emitting events, as well as handling logging and metrics.
|
|
16
|
+
*/
|
|
17
|
+
export class TxCollectionSink extends (EventEmitter as new () => TypedEventEmitter<TxPoolEvents>) {
|
|
18
|
+
private readonly instrumentation: TxCollectionInstrumentation;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
private readonly txPool: TxPool,
|
|
22
|
+
telemetryClient: TelemetryClient,
|
|
23
|
+
private readonly log: Logger,
|
|
24
|
+
) {
|
|
25
|
+
super();
|
|
26
|
+
this.instrumentation = new TxCollectionInstrumentation(telemetryClient, 'TxCollection');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async collect(
|
|
30
|
+
collectValidTxsFn: (txHashes: TxHash[]) => Promise<(Tx | undefined)[]>,
|
|
31
|
+
requested: TxHash[],
|
|
32
|
+
info: Record<string, any> & { description: string; method: CollectionMethod },
|
|
33
|
+
) {
|
|
34
|
+
this.log.trace(`Requesting ${requested.length} txs via ${info.description}`, {
|
|
35
|
+
...info,
|
|
36
|
+
requestedTxs: requested.map(t => t.toString()),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Execute collection function and measure the time taken, catching any errors.
|
|
40
|
+
const [duration, txs] = await elapsed(async () => {
|
|
41
|
+
try {
|
|
42
|
+
const response = await collectValidTxsFn(requested);
|
|
43
|
+
return response.filter(tx => tx !== undefined);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
this.log.error(`Error collecting txs via ${info.description}`, err, {
|
|
46
|
+
...info,
|
|
47
|
+
requestedTxs: requested.map(hash => hash.toString()),
|
|
48
|
+
});
|
|
49
|
+
return [] as Tx[];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (txs.length === 0) {
|
|
54
|
+
this.log.trace(`No txs found via ${info.description}`, {
|
|
55
|
+
...info,
|
|
56
|
+
requestedTxs: requested.map(t => t.toString()),
|
|
57
|
+
});
|
|
58
|
+
return { txs, requested, duration };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Validate tx hashes for all collected txs from external sources
|
|
62
|
+
const validTxs: Tx[] = [];
|
|
63
|
+
const invalidTxHashes: string[] = [];
|
|
64
|
+
await Promise.all(
|
|
65
|
+
txs.map(async tx => {
|
|
66
|
+
const isValid = await tx.validateTxHash();
|
|
67
|
+
if (isValid) {
|
|
68
|
+
validTxs.push(tx);
|
|
69
|
+
} else {
|
|
70
|
+
invalidTxHashes.push(tx.getTxHash().toString());
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (invalidTxHashes.length > 0) {
|
|
76
|
+
this.log.warn(`Rejecting ${invalidTxHashes.length} txs with invalid hashes from ${info.description}`, {
|
|
77
|
+
...info,
|
|
78
|
+
invalidTxHashes,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (validTxs.length === 0) {
|
|
83
|
+
this.log.trace(`No valid txs found via ${info.description} after validation`, {
|
|
84
|
+
...info,
|
|
85
|
+
requestedTxs: requested.map(t => t.toString()),
|
|
86
|
+
invalidTxHashes,
|
|
87
|
+
});
|
|
88
|
+
return { txs: [], requested, duration };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.log.verbose(
|
|
92
|
+
`Collected ${validTxs.length} txs out of ${requested.length} requested via ${info.description} in ${duration}ms`,
|
|
93
|
+
{
|
|
94
|
+
...info,
|
|
95
|
+
duration,
|
|
96
|
+
txs: validTxs.map(t => t.getTxHash().toString()),
|
|
97
|
+
requestedTxs: requested.map(t => t.toString()),
|
|
98
|
+
rejectedCount: invalidTxHashes.length,
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return await this.foundTxs(validTxs, { ...info, duration });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private async foundTxs(
|
|
106
|
+
txs: Tx[],
|
|
107
|
+
info: Record<string, any> & { description: string; method: CollectionMethod; duration: number },
|
|
108
|
+
) {
|
|
109
|
+
// Report metrics for the collection
|
|
110
|
+
this.instrumentation.increaseTxsFor(info.method, txs.length, info.duration);
|
|
111
|
+
|
|
112
|
+
// Mark txs as found in the slow missing txs set and all fast requests
|
|
113
|
+
this.emit('txs-added', { txs });
|
|
114
|
+
|
|
115
|
+
// Add the txs to the tx pool (should not fail, but we catch it just in case)
|
|
116
|
+
try {
|
|
117
|
+
await this.txPool.addTxs(txs, { source: `tx-collection` });
|
|
118
|
+
} catch (err) {
|
|
119
|
+
this.log.error(`Error adding txs to the pool via ${info.description}`, err, {
|
|
120
|
+
...info,
|
|
121
|
+
txs: txs.map(tx => tx.txHash.toString()),
|
|
122
|
+
});
|
|
123
|
+
// Return no txs since none have been added
|
|
124
|
+
return { txs: [] };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { txs };
|
|
128
|
+
}
|
|
129
|
+
}
|