@aztec/p2p 0.0.1-commit.8afd444 → 0.0.1-commit.9117c5f5a
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/client/factory.d.ts +10 -10
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +39 -15
- package/dest/client/interface.d.ts +46 -33
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +39 -51
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +145 -200
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +7 -8
- package/dest/config.d.ts +25 -9
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -6
- 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 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -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 +353 -87
- 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 +2 -2
- package/dest/mem_pools/index.d.ts +3 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- 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/eviction/invalid_txs_after_mining_rule.js +3 -3
- 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 +43 -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 +103 -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 +93 -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 +10 -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 +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +174 -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_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
- 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 +73 -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 +211 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +9 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +119 -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 +193 -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 +108 -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 +354 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +60 -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 +161 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +77 -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 +905 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- 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 +3 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +219 -58
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/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/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/dummy_service.d.ts +13 -5
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +10 -4
- package/dest/services/encoding.d.ts +3 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +11 -10
- 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 +173 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +346 -0
- package/dest/services/libp2p/libp2p_service.d.ts +94 -42
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +420 -337
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +25 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +6 -5
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +26 -53
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- 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 +16 -11
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +21 -10
- 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 +27 -11
- 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 +20 -0
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +13 -5
- package/dest/services/service.d.ts +39 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +22 -4
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +49 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -5
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +64 -48
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -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 +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -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 +90 -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 +2 -1
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +15 -14
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +6 -6
- package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +60 -26
- package/dest/services/tx_collection/tx_collection.d.ts +23 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +75 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +26 -29
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +9 -6
- package/dest/services/tx_provider.d.ts +4 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +9 -8
- 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 +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +30 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +105 -4
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +4 -3
- package/dest/test-helpers/testbench-utils.d.ts +43 -38
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +128 -59
- package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +15 -15
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +74 -27
- package/src/client/interface.ts +56 -34
- package/src/client/p2p_client.ts +180 -247
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -11
- package/src/config.ts +35 -11
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +496 -91
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/index.ts +4 -1
- package/src/mem_pools/interface.ts +4 -4
- package/src/mem_pools/tx_pool/README.md +1 -1
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/README.md +275 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -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 +121 -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 +27 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +209 -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 +90 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -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 +242 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +297 -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 +444 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +223 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1083 -0
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/msg_validators/tx_validator/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +353 -77
- package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +18 -6
- package/src/services/encoding.ts +9 -9
- package/src/services/gossipsub/README.md +641 -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 +487 -0
- package/src/services/libp2p/libp2p_service.ts +445 -360
- package/src/services/peer-manager/peer_scoring.ts +25 -0
- package/src/services/reqresp/batch-tx-requester/README.md +7 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +31 -59
- package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +23 -14
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +38 -15
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +16 -4
- package/src/services/service.ts +51 -2
- package/src/services/tx_collection/config.ts +74 -6
- package/src/services/tx_collection/fast_tx_collection.ts +74 -51
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +2 -1
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +20 -21
- package/src/services/tx_collection/slow_tx_collection.ts +66 -33
- package/src/services/tx_collection/tx_collection.ts +113 -16
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +10 -8
- package/src/services/tx_provider.ts +10 -9
- package/src/test-helpers/make-test-p2p-clients.ts +3 -5
- package/src/test-helpers/mock-pubsub.ts +146 -9
- package/src/test-helpers/reqresp-nodes.ts +4 -6
- package/src/test-helpers/testbench-utils.ts +127 -71
- package/src/testbench/p2p_client_testbench_worker.ts +24 -21
- package/src/util.ts +7 -1
- 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/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
|
@@ -2,7 +2,6 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { times } from '@aztec/foundation/collection';
|
|
3
3
|
import { AbortError, TimeoutError } from '@aztec/foundation/error';
|
|
4
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { boundInclusive } from '@aztec/foundation/number';
|
|
6
5
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
7
6
|
import { sleep } from '@aztec/foundation/sleep';
|
|
8
7
|
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
@@ -14,37 +13,36 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
14
13
|
|
|
15
14
|
import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
|
|
16
15
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
17
|
-
import { ReqRespSubProtocol } from '../reqresp/interface.js';
|
|
18
|
-
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
19
16
|
import type { TxCollectionConfig } from './config.js';
|
|
17
|
+
import { MissingTxsTracker } from './missing_txs_tracker.js';
|
|
20
18
|
import {
|
|
21
19
|
BatchTxRequesterCollector,
|
|
22
|
-
type
|
|
20
|
+
type MissingTxsCollector,
|
|
23
21
|
SendBatchRequestCollector,
|
|
24
22
|
} from './proposal_tx_collector.js';
|
|
25
23
|
import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
|
|
26
|
-
import type { TxCollectionSink } from './tx_collection_sink.js';
|
|
24
|
+
import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
27
25
|
import type { TxSource } from './tx_source.js';
|
|
28
26
|
|
|
29
27
|
export class FastTxCollection {
|
|
30
28
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
31
29
|
protected requests: Set<FastCollectionRequest> = new Set();
|
|
32
|
-
private
|
|
30
|
+
private missingTxsCollector: MissingTxsCollector;
|
|
33
31
|
|
|
34
32
|
constructor(
|
|
35
|
-
|
|
33
|
+
p2pService: BatchTxRequesterLibP2PService,
|
|
36
34
|
private nodes: TxSource[],
|
|
37
35
|
private txCollectionSink: TxCollectionSink,
|
|
38
36
|
private config: TxCollectionConfig,
|
|
39
37
|
private dateProvider: DateProvider = new DateProvider(),
|
|
40
38
|
private log: Logger = createLogger('p2p:tx_collection_service'),
|
|
41
|
-
|
|
39
|
+
missingTxsCollector?: MissingTxsCollector,
|
|
42
40
|
) {
|
|
43
41
|
const batchTxRequesterConfig = this.config as Partial<BatchTxRequesterConfig>;
|
|
44
|
-
const
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
(
|
|
42
|
+
const missingTxsCollectorType = this.config.txCollectionMissingTxsCollectorType;
|
|
43
|
+
this.missingTxsCollector =
|
|
44
|
+
missingTxsCollector ??
|
|
45
|
+
(missingTxsCollectorType === 'old'
|
|
48
46
|
? new SendBatchRequestCollector(p2pService)
|
|
49
47
|
: new BatchTxRequesterCollector(p2pService, log, dateProvider, undefined, batchTxRequesterConfig));
|
|
50
48
|
}
|
|
@@ -80,29 +78,29 @@ export class FastTxCollection {
|
|
|
80
78
|
// This promise is used to await for the collection to finish during the main collectFast method.
|
|
81
79
|
// It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
|
|
82
80
|
const promise = promiseWithResolvers<void>();
|
|
83
|
-
setTimeout(() => promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
|
|
81
|
+
const timeoutTimer = setTimeout(() => promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
|
|
84
82
|
|
|
85
83
|
const request: FastCollectionRequest = {
|
|
86
84
|
...input,
|
|
87
85
|
blockInfo,
|
|
88
86
|
promise,
|
|
89
|
-
|
|
90
|
-
missingTxHashes: new Set(txHashes.map(t => t.toString())),
|
|
87
|
+
missingTxTracker: MissingTxsTracker.fromArray(txHashes),
|
|
91
88
|
deadline: opts.deadline,
|
|
92
89
|
};
|
|
93
90
|
|
|
94
91
|
const [duration] = await elapsed(() => this.collectFast(request, { ...opts }));
|
|
92
|
+
clearTimeout(timeoutTimer);
|
|
95
93
|
|
|
96
94
|
this.log.verbose(
|
|
97
|
-
`Collected ${request.
|
|
95
|
+
`Collected ${request.missingTxTracker.collectedTxs.length} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
|
|
98
96
|
{
|
|
99
97
|
...blockInfo,
|
|
100
98
|
duration,
|
|
101
99
|
requestType: input.type,
|
|
102
|
-
missingTxs: [...request.missingTxHashes],
|
|
100
|
+
missingTxs: [...request.missingTxTracker.missingTxHashes],
|
|
103
101
|
},
|
|
104
102
|
);
|
|
105
|
-
return
|
|
103
|
+
return request.missingTxTracker.collectedTxs;
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
protected async collectFast(
|
|
@@ -113,7 +111,7 @@ export class FastTxCollection {
|
|
|
113
111
|
const { blockInfo } = request;
|
|
114
112
|
|
|
115
113
|
this.log.debug(
|
|
116
|
-
`Starting fast collection of ${request.
|
|
114
|
+
`Starting fast collection of ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
117
115
|
{ ...blockInfo, requestType: request.type, deadline: opts.deadline },
|
|
118
116
|
);
|
|
119
117
|
|
|
@@ -126,7 +124,7 @@ export class FastTxCollection {
|
|
|
126
124
|
await Promise.race([request.promise.promise, waitBeforeReqResp]);
|
|
127
125
|
|
|
128
126
|
// If we have collected all txs, we can stop here
|
|
129
|
-
if (request.
|
|
127
|
+
if (request.missingTxTracker.allFetched()) {
|
|
130
128
|
this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
|
|
131
129
|
return;
|
|
132
130
|
}
|
|
@@ -140,7 +138,7 @@ export class FastTxCollection {
|
|
|
140
138
|
const logCtx = {
|
|
141
139
|
...blockInfo,
|
|
142
140
|
errorMessage: err instanceof Error ? err.message : undefined,
|
|
143
|
-
missingTxs:
|
|
141
|
+
missingTxs: request.missingTxTracker.missingTxHashes.values().map(txHash => txHash.toString()),
|
|
144
142
|
};
|
|
145
143
|
if (err instanceof Error && err.name === 'TimeoutError') {
|
|
146
144
|
this.log.warn(`Timed out collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
|
|
@@ -168,7 +166,11 @@ export class FastTxCollection {
|
|
|
168
166
|
}
|
|
169
167
|
|
|
170
168
|
// Keep a shared priority queue of all txs pending to be requested, sorted by the number of attempts made to collect them.
|
|
171
|
-
const attemptsPerTx = [...request.missingTxHashes].map(txHash => ({
|
|
169
|
+
const attemptsPerTx = [...request.missingTxTracker.missingTxHashes].map(txHash => ({
|
|
170
|
+
txHash,
|
|
171
|
+
attempts: 0,
|
|
172
|
+
found: false,
|
|
173
|
+
}));
|
|
172
174
|
|
|
173
175
|
// Returns once we have finished all node loops. Each loop finishes when the deadline is hit, or all txs have been collected.
|
|
174
176
|
await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx, opts)));
|
|
@@ -181,7 +183,7 @@ export class FastTxCollection {
|
|
|
181
183
|
opts: { deadline: Date },
|
|
182
184
|
) {
|
|
183
185
|
const notFinished = () =>
|
|
184
|
-
this.dateProvider.now() <= +opts.deadline && request.
|
|
186
|
+
this.dateProvider.now() <= +opts.deadline && !request.missingTxTracker.allFetched() && this.requests.has(request);
|
|
185
187
|
|
|
186
188
|
const maxParallelRequests = this.config.txCollectionFastMaxParallelRequestsPerNode;
|
|
187
189
|
const maxBatchSize = this.config.txCollectionNodeRpcMaxBatchSize;
|
|
@@ -198,7 +200,7 @@ export class FastTxCollection {
|
|
|
198
200
|
if (!txToRequest) {
|
|
199
201
|
// No more txs to process
|
|
200
202
|
break;
|
|
201
|
-
} else if (!request.
|
|
203
|
+
} else if (!request.missingTxTracker.isMissing(txToRequest.txHash)) {
|
|
202
204
|
// Mark as found if it was found somewhere else, we'll then remove it from the array.
|
|
203
205
|
// We don't delete it now since 'array.splice' is pretty expensive, so we do it after sorting.
|
|
204
206
|
txToRequest.found = true;
|
|
@@ -227,16 +229,24 @@ export class FastTxCollection {
|
|
|
227
229
|
return;
|
|
228
230
|
}
|
|
229
231
|
|
|
232
|
+
const txHashes = batch.map(({ txHash }) => txHash);
|
|
230
233
|
// Collect this batch from the node
|
|
231
234
|
await this.txCollectionSink.collect(
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
async () => {
|
|
236
|
+
const result = await node.getTxsByHash(txHashes.map(TxHash.fromString));
|
|
237
|
+
for (const tx of result.validTxs) {
|
|
238
|
+
request.missingTxTracker.markFetched(tx);
|
|
239
|
+
}
|
|
240
|
+
return result;
|
|
241
|
+
},
|
|
242
|
+
txHashes,
|
|
234
243
|
{
|
|
235
244
|
description: `fast ${node.getInfo()}`,
|
|
236
245
|
node: node.getInfo(),
|
|
237
246
|
method: 'fast-node-rpc',
|
|
238
247
|
...request.blockInfo,
|
|
239
248
|
},
|
|
249
|
+
this.getAddContext(request),
|
|
240
250
|
);
|
|
241
251
|
|
|
242
252
|
// Clear from the active requests the txs we just requested
|
|
@@ -258,8 +268,6 @@ export class FastTxCollection {
|
|
|
258
268
|
private async collectFastViaReqResp(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
|
|
259
269
|
const timeoutMs = +request.deadline - this.dateProvider.now();
|
|
260
270
|
const pinnedPeer = opts.pinnedPeer;
|
|
261
|
-
const maxPeers = boundInclusive(Math.ceil(request.missingTxHashes.size / 2), 8, 32);
|
|
262
|
-
const maxRetryAttempts = 5;
|
|
263
271
|
const blockInfo = request.blockInfo;
|
|
264
272
|
const slotNumber = blockInfo.slotNumber;
|
|
265
273
|
if (timeoutMs < 100) {
|
|
@@ -271,41 +279,58 @@ export class FastTxCollection {
|
|
|
271
279
|
}
|
|
272
280
|
|
|
273
281
|
this.log.debug(
|
|
274
|
-
`Starting fast reqresp for ${request.
|
|
282
|
+
`Starting fast reqresp for ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
275
283
|
{ ...blockInfo, timeoutMs, pinnedPeer },
|
|
276
284
|
);
|
|
277
285
|
|
|
278
286
|
try {
|
|
279
287
|
await this.txCollectionSink.collect(
|
|
280
|
-
async
|
|
288
|
+
async () => {
|
|
289
|
+
let result: Tx[];
|
|
281
290
|
if (request.type === 'proposal') {
|
|
282
|
-
|
|
291
|
+
result = await this.missingTxsCollector.collectTxs(
|
|
292
|
+
request.missingTxTracker,
|
|
293
|
+
request.blockProposal,
|
|
294
|
+
pinnedPeer,
|
|
295
|
+
timeoutMs,
|
|
296
|
+
);
|
|
283
297
|
} else if (request.type === 'block') {
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
298
|
+
const blockTxsSource = {
|
|
299
|
+
txHashes: request.block.body.txEffects.map(e => e.txHash),
|
|
300
|
+
archive: request.block.archive.root,
|
|
301
|
+
};
|
|
302
|
+
result = await this.missingTxsCollector.collectTxs(
|
|
303
|
+
request.missingTxTracker,
|
|
304
|
+
blockTxsSource,
|
|
287
305
|
pinnedPeer,
|
|
288
306
|
timeoutMs,
|
|
289
|
-
maxPeers,
|
|
290
|
-
maxRetryAttempts,
|
|
291
307
|
);
|
|
292
|
-
|
|
293
|
-
return txs.flat();
|
|
294
308
|
} else {
|
|
295
309
|
throw new Error(`Unknown request type: ${(request as any).type}`);
|
|
296
310
|
}
|
|
311
|
+
return { validTxs: result, invalidTxHashes: [] };
|
|
297
312
|
},
|
|
298
|
-
Array.from(request.missingTxHashes)
|
|
313
|
+
Array.from(request.missingTxTracker.missingTxHashes),
|
|
299
314
|
{ description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
|
|
315
|
+
this.getAddContext(request),
|
|
300
316
|
);
|
|
301
317
|
} catch (err) {
|
|
302
318
|
this.log.error(`Error sending fast reqresp request for txs`, err, {
|
|
303
|
-
txs: [...request.missingTxHashes],
|
|
319
|
+
txs: [...request.missingTxTracker.missingTxHashes],
|
|
304
320
|
...blockInfo,
|
|
305
321
|
});
|
|
306
322
|
}
|
|
307
323
|
}
|
|
308
324
|
|
|
325
|
+
/** Returns the TxAddContext for the given request, used by the sink to add txs to the pool correctly. */
|
|
326
|
+
private getAddContext(request: FastCollectionRequest): TxAddContext {
|
|
327
|
+
if (request.type === 'proposal') {
|
|
328
|
+
return { type: 'proposal', blockHeader: request.blockProposal.blockHeader };
|
|
329
|
+
} else {
|
|
330
|
+
return { type: 'mined', block: request.block };
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
309
334
|
/**
|
|
310
335
|
* Handle txs by marking them as found for the requests that are waiting for them, and resolves the request if all its txs have been found.
|
|
311
336
|
* Called internally and from the main tx collection manager whenever the tx pool emits a tx-added event.
|
|
@@ -315,22 +340,20 @@ export class FastTxCollection {
|
|
|
315
340
|
for (const tx of txs) {
|
|
316
341
|
const txHash = tx.txHash.toString();
|
|
317
342
|
// Remove the tx hash from the missing set, and add it to the found set.
|
|
318
|
-
if (request.
|
|
319
|
-
request.missingTxHashes.delete(txHash);
|
|
320
|
-
request.foundTxs.set(txHash, tx);
|
|
343
|
+
if (request.missingTxTracker.markFetched(tx)) {
|
|
321
344
|
this.log.trace(`Found tx ${txHash} for fast collection request`, {
|
|
322
345
|
...request.blockInfo,
|
|
323
346
|
txHash: tx.txHash.toString(),
|
|
324
347
|
type: request.type,
|
|
325
348
|
});
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
349
|
+
}
|
|
350
|
+
// If we found all txs for this request, we resolve the promise
|
|
351
|
+
if (request.missingTxTracker.allFetched()) {
|
|
352
|
+
this.log.trace(`All txs found for fast collection request`, {
|
|
353
|
+
...request.blockInfo,
|
|
354
|
+
type: request.type,
|
|
355
|
+
});
|
|
356
|
+
request.promise.resolve();
|
|
334
357
|
}
|
|
335
358
|
}
|
|
336
359
|
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
3
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
import type { FileStoreTxSource } from './file_store_tx_source.js';
|
|
8
|
+
import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
9
|
+
|
|
10
|
+
/** Configuration for a FileStoreTxCollection instance. */
|
|
11
|
+
export type FileStoreCollectionConfig = {
|
|
12
|
+
workerCount: number;
|
|
13
|
+
backoffBaseMs: number;
|
|
14
|
+
backoffMaxMs: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type FileStoreTxEntry = {
|
|
18
|
+
txHash: string;
|
|
19
|
+
context: TxAddContext;
|
|
20
|
+
deadline: Date;
|
|
21
|
+
attempts: number;
|
|
22
|
+
lastAttemptTime: number;
|
|
23
|
+
nextSourceIndex: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Collects txs from file stores as a fallback after P2P methods have been tried.
|
|
28
|
+
* Uses a shared worker pool that pulls entries with priority (fewest attempts first),
|
|
29
|
+
* retries with round-robin across sources, and applies exponential backoff between
|
|
30
|
+
* full cycles through all sources.
|
|
31
|
+
*/
|
|
32
|
+
export class FileStoreTxCollection {
|
|
33
|
+
/** Map from tx hash string to entry for all pending downloads. */
|
|
34
|
+
private entries = new Map<string, FileStoreTxEntry>();
|
|
35
|
+
|
|
36
|
+
/** Worker promises for the shared worker pool. */
|
|
37
|
+
private workers: Promise<void>[] = [];
|
|
38
|
+
|
|
39
|
+
/** Whether the worker pool is running. */
|
|
40
|
+
private running = false;
|
|
41
|
+
|
|
42
|
+
/** Signal used to wake sleeping workers when new entries arrive or stop is called. */
|
|
43
|
+
private wakeSignal: PromiseWithResolvers<void>;
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
private readonly sources: FileStoreTxSource[],
|
|
47
|
+
private readonly txCollectionSink: TxCollectionSink,
|
|
48
|
+
private readonly config: FileStoreCollectionConfig,
|
|
49
|
+
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
50
|
+
private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
|
|
51
|
+
) {
|
|
52
|
+
this.wakeSignal = promiseWithResolvers<void>();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Starts the shared worker pool. */
|
|
56
|
+
public start(): void {
|
|
57
|
+
if (this.sources.length === 0) {
|
|
58
|
+
this.log.debug('No file store sources configured');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.running = true;
|
|
62
|
+
for (let i = 0; i < this.config.workerCount; i++) {
|
|
63
|
+
this.workers.push(this.workerLoop());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Stops all workers and clears state. */
|
|
68
|
+
public async stop(): Promise<void> {
|
|
69
|
+
this.running = false;
|
|
70
|
+
this.wake();
|
|
71
|
+
await Promise.all(this.workers);
|
|
72
|
+
this.workers = [];
|
|
73
|
+
this.entries.clear();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Adds entries to the shared map and wakes workers. */
|
|
77
|
+
public startCollecting(txHashes: TxHash[], context: TxAddContext, deadline: Date): void {
|
|
78
|
+
if (this.sources.length === 0 || txHashes.length === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (+deadline <= this.dateProvider.now()) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const txHash of txHashes) {
|
|
86
|
+
const hashStr = txHash.toString();
|
|
87
|
+
if (!this.entries.has(hashStr)) {
|
|
88
|
+
this.entries.set(hashStr, {
|
|
89
|
+
txHash: hashStr,
|
|
90
|
+
context,
|
|
91
|
+
deadline,
|
|
92
|
+
attempts: 0,
|
|
93
|
+
lastAttemptTime: 0,
|
|
94
|
+
nextSourceIndex: Math.floor(Math.random() * this.sources.length),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.wake();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Removes entries for txs that have been found elsewhere. */
|
|
102
|
+
public foundTxs(txs: Tx[]): void {
|
|
103
|
+
for (const tx of txs) {
|
|
104
|
+
this.entries.delete(tx.getTxHash().toString());
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Clears all pending entries. */
|
|
109
|
+
public clearPending(): void {
|
|
110
|
+
this.entries.clear();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private async workerLoop(): Promise<void> {
|
|
114
|
+
while (this.running) {
|
|
115
|
+
const action = this.getNextAction();
|
|
116
|
+
if (action.type === 'sleep') {
|
|
117
|
+
await action.promise;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const entry = action.entry;
|
|
122
|
+
const source = this.sources[entry.nextSourceIndex % this.sources.length];
|
|
123
|
+
entry.nextSourceIndex++;
|
|
124
|
+
entry.attempts++;
|
|
125
|
+
entry.lastAttemptTime = this.dateProvider.now();
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const result = await this.txCollectionSink.collect(
|
|
129
|
+
() => source.getTxsByHash([TxHash.fromString(entry.txHash)]),
|
|
130
|
+
[entry.txHash],
|
|
131
|
+
{
|
|
132
|
+
description: `file-store ${source.getInfo()}`,
|
|
133
|
+
method: 'file-store',
|
|
134
|
+
fileStore: source.getInfo(),
|
|
135
|
+
},
|
|
136
|
+
entry.context,
|
|
137
|
+
);
|
|
138
|
+
if (result.txs.length > 0) {
|
|
139
|
+
this.entries.delete(entry.txHash);
|
|
140
|
+
}
|
|
141
|
+
} catch (err) {
|
|
142
|
+
this.log.trace(`Error downloading tx ${entry.txHash} from ${source.getInfo()}`, { err });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Single-pass scan: removes expired entries, finds the best ready entry, or computes sleep time. */
|
|
148
|
+
private getNextAction(): { type: 'process'; entry: FileStoreTxEntry } | { type: 'sleep'; promise: Promise<void> } {
|
|
149
|
+
const now = this.dateProvider.now();
|
|
150
|
+
let best: FileStoreTxEntry | undefined;
|
|
151
|
+
let earliestReadyAt = Infinity;
|
|
152
|
+
|
|
153
|
+
for (const [key, entry] of this.entries) {
|
|
154
|
+
if (+entry.deadline <= now) {
|
|
155
|
+
this.entries.delete(key);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const backoffMs = this.getBackoffMs(entry);
|
|
159
|
+
const readyAt = entry.lastAttemptTime + backoffMs;
|
|
160
|
+
if (readyAt > now) {
|
|
161
|
+
earliestReadyAt = Math.min(earliestReadyAt, readyAt);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!best || entry.attempts < best.attempts) {
|
|
165
|
+
best = entry;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (best) {
|
|
170
|
+
return { type: 'process', entry: best };
|
|
171
|
+
}
|
|
172
|
+
if (earliestReadyAt < Infinity) {
|
|
173
|
+
return { type: 'sleep', promise: this.sleepOrWake(earliestReadyAt - now) };
|
|
174
|
+
}
|
|
175
|
+
return { type: 'sleep', promise: this.waitForWake() };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Computes backoff for an entry. Backoff applies after a full cycle through all sources. */
|
|
179
|
+
private getBackoffMs(entry: FileStoreTxEntry): number {
|
|
180
|
+
const fullCycles = Math.floor(entry.attempts / this.sources.length);
|
|
181
|
+
if (fullCycles === 0) {
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
return Math.min(this.config.backoffBaseMs * Math.pow(2, fullCycles - 1), this.config.backoffMaxMs);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Resolves the current wake signal and creates a new one. */
|
|
188
|
+
private wake(): void {
|
|
189
|
+
this.wakeSignal.resolve();
|
|
190
|
+
this.wakeSignal = promiseWithResolvers<void>();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Waits until the wake signal is resolved. */
|
|
194
|
+
private async waitForWake(): Promise<void> {
|
|
195
|
+
await this.wakeSignal.promise;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Sleeps for the given duration or until the wake signal is resolved. */
|
|
199
|
+
private async sleepOrWake(ms: number): Promise<void> {
|
|
200
|
+
await Promise.race([sleep(ms), this.wakeSignal.promise]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
3
|
+
import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
|
|
4
|
+
import { Tx, type TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import {
|
|
6
|
+
type Histogram,
|
|
7
|
+
Metrics,
|
|
8
|
+
type TelemetryClient,
|
|
9
|
+
type UpDownCounter,
|
|
10
|
+
getTelemetryClient,
|
|
11
|
+
} from '@aztec/telemetry-client';
|
|
12
|
+
|
|
13
|
+
import type { TxSource, TxSourceCollectionResult } from './tx_source.js';
|
|
14
|
+
|
|
15
|
+
/** TxSource implementation that downloads txs from a file store. */
|
|
16
|
+
export class FileStoreTxSource implements TxSource {
|
|
17
|
+
private downloadsSuccess: UpDownCounter;
|
|
18
|
+
private downloadsFailed: UpDownCounter;
|
|
19
|
+
private downloadDuration: Histogram;
|
|
20
|
+
private downloadSize: Histogram;
|
|
21
|
+
|
|
22
|
+
private constructor(
|
|
23
|
+
private readonly fileStore: ReadOnlyFileStore,
|
|
24
|
+
private readonly baseUrl: string,
|
|
25
|
+
private readonly basePath: string,
|
|
26
|
+
private readonly log: Logger,
|
|
27
|
+
telemetry: TelemetryClient,
|
|
28
|
+
) {
|
|
29
|
+
const meter = telemetry.getMeter('file-store-tx-source');
|
|
30
|
+
this.downloadsSuccess = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_SUCCESS);
|
|
31
|
+
this.downloadsFailed = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_FAILED);
|
|
32
|
+
this.downloadDuration = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_DURATION);
|
|
33
|
+
this.downloadSize = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_SIZE);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a FileStoreTxSource from a URL.
|
|
38
|
+
* @param url - The file store URL (s3://, gs://, file://, http://, https://).
|
|
39
|
+
* @param basePath - Base path for tx files within the store.
|
|
40
|
+
* @param log - Optional logger.
|
|
41
|
+
* @param telemetry - Optional telemetry client.
|
|
42
|
+
* @returns The FileStoreTxSource instance, or undefined if creation fails.
|
|
43
|
+
*/
|
|
44
|
+
public static async create(
|
|
45
|
+
url: string,
|
|
46
|
+
basePath: string,
|
|
47
|
+
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
48
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
49
|
+
): Promise<FileStoreTxSource | undefined> {
|
|
50
|
+
try {
|
|
51
|
+
const fileStore = await createReadOnlyFileStore(url, log);
|
|
52
|
+
if (!fileStore) {
|
|
53
|
+
log.warn(`Failed to create file store for URL: ${url}`);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
log.warn(`Error creating file store for URL: ${url}`, { error: err });
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getInfo(): string {
|
|
64
|
+
return `file-store:${this.baseUrl}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
|
|
68
|
+
const invalidTxHashes: string[] = [];
|
|
69
|
+
return {
|
|
70
|
+
validTxs: (
|
|
71
|
+
await Promise.all(
|
|
72
|
+
txHashes.map(async txHash => {
|
|
73
|
+
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
74
|
+
const timer = new Timer();
|
|
75
|
+
try {
|
|
76
|
+
const buffer = await this.fileStore.read(path);
|
|
77
|
+
const tx = Tx.fromBuffer(buffer);
|
|
78
|
+
if ((await tx.validateTxHash()) && txHash.equals(tx.txHash)) {
|
|
79
|
+
this.downloadsSuccess.add(1);
|
|
80
|
+
this.downloadDuration.record(Math.ceil(timer.ms()));
|
|
81
|
+
this.downloadSize.record(buffer.length);
|
|
82
|
+
return tx;
|
|
83
|
+
} else {
|
|
84
|
+
invalidTxHashes.push(tx.txHash.toString());
|
|
85
|
+
this.downloadsFailed.add(1);
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
// Tx not found or error reading - return undefined
|
|
90
|
+
this.downloadsFailed.add(1);
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
).filter(tx => tx !== undefined),
|
|
96
|
+
invalidTxHashes: invalidTxHashes,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Creates FileStoreTxSource instances from URLs.
|
|
103
|
+
* @param urls - Array of file store URLs.
|
|
104
|
+
* @param basePath - Base path for tx files within each store.
|
|
105
|
+
* @param log - Optional logger.
|
|
106
|
+
* @param telemetry - Optional telemetry client.
|
|
107
|
+
* @returns Array of successfully created FileStoreTxSource instances.
|
|
108
|
+
*/
|
|
109
|
+
export async function createFileStoreTxSources(
|
|
110
|
+
urls: string[],
|
|
111
|
+
basePath: string,
|
|
112
|
+
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
113
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
114
|
+
): Promise<FileStoreTxSource[]> {
|
|
115
|
+
const sources = await Promise.all(urls.map(url => FileStoreTxSource.create(url, basePath, log, telemetry)));
|
|
116
|
+
return sources.filter((s): s is FileStoreTxSource => s !== undefined);
|
|
117
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { TxCollection, type FastCollectionRequestInput } from './tx_collection.js';
|
|
2
2
|
export { type TxSource, createNodeRpcTxSources, NodeRpcTxSource } from './tx_source.js';
|
|
3
3
|
export {
|
|
4
|
-
type
|
|
4
|
+
type MissingTxsCollector,
|
|
5
5
|
BatchTxRequesterCollector,
|
|
6
6
|
SendBatchRequestCollector,
|
|
7
7
|
} from './proposal_tx_collector.js';
|
|
8
|
+
export { FileStoreTxSource, createFileStoreTxSources } from './file_store_tx_source.js';
|
|
@@ -18,7 +18,13 @@ export class TxCollectionInstrumentation {
|
|
|
18
18
|
const meter = client.getMeter(name);
|
|
19
19
|
|
|
20
20
|
this.txsCollected = createUpDownCounterWithDefault(meter, Metrics.TX_COLLECTOR_COUNT, {
|
|
21
|
-
[Attributes.TX_COLLECTION_METHOD]: [
|
|
21
|
+
[Attributes.TX_COLLECTION_METHOD]: [
|
|
22
|
+
'fast-req-resp',
|
|
23
|
+
'fast-node-rpc',
|
|
24
|
+
'slow-req-resp',
|
|
25
|
+
'slow-node-rpc',
|
|
26
|
+
'file-store',
|
|
27
|
+
],
|
|
22
28
|
});
|
|
23
29
|
|
|
24
30
|
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
2
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tracks which transactions are still missing and need to be fetched.
|
|
6
|
+
* Allows external code to mark transactions as fetched, enabling coordination
|
|
7
|
+
* between multiple fetching mechanisms (e.g., BatchTxRequester and Rpc Node requests).
|
|
8
|
+
*/
|
|
9
|
+
export interface IMissingTxsTracker {
|
|
10
|
+
/** Returns the set of transaction hashes that are still missing. */
|
|
11
|
+
get missingTxHashes(): Set<string>;
|
|
12
|
+
/** Size of this.missingTxHashes */
|
|
13
|
+
get numberOfMissingTxs(): number;
|
|
14
|
+
/** Are all requested txs are fetched */
|
|
15
|
+
allFetched(): boolean;
|
|
16
|
+
/** Checks that transaction is still missing */
|
|
17
|
+
isMissing(txHash: string): boolean;
|
|
18
|
+
/** Marks a transaction as fetched. Returns true if it was previously missing. */
|
|
19
|
+
markFetched(tx: Tx): boolean;
|
|
20
|
+
/** Get list of collected txs */
|
|
21
|
+
get collectedTxs(): Tx[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class MissingTxsTracker implements IMissingTxsTracker {
|
|
25
|
+
public readonly collectedTxs: Tx[] = [];
|
|
26
|
+
|
|
27
|
+
private constructor(public readonly missingTxHashes: Set<string>) {}
|
|
28
|
+
|
|
29
|
+
public static fromArray(hashes: TxHash[] | string[]) {
|
|
30
|
+
return new MissingTxsTracker(new Set(hashes.map(hash => hash.toString())));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
markFetched(tx: Tx): boolean {
|
|
34
|
+
if (this.missingTxHashes.delete(tx.txHash.toString())) {
|
|
35
|
+
this.collectedTxs.push(tx);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get numberOfMissingTxs(): number {
|
|
42
|
+
return this.missingTxHashes.size;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
allFetched(): boolean {
|
|
46
|
+
return this.numberOfMissingTxs === 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isMissing(txHash: string): boolean {
|
|
50
|
+
return this.missingTxHashes.has(txHash.toString());
|
|
51
|
+
}
|
|
52
|
+
}
|