@aztec/p2p 0.0.1-commit.4d79d1f2d → 0.0.1-commit.4d9804df
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -3
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -6
- package/dest/client/factory.d.ts +9 -8
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +50 -34
- package/dest/client/interface.d.ts +59 -27
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +40 -34
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +162 -135
- package/dest/config.d.ts +164 -100
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +149 -49
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/reqresp.error.d.ts +9 -16
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +10 -17
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +103 -59
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +278 -196
- 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 +224 -65
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +7 -5
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +12 -5
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +38 -17
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +32 -15
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +95 -24
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +8 -4
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +3 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +9 -7
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- 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 +60 -14
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +59 -15
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +116 -20
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +26 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +79 -43
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +20 -7
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +34 -12
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +29 -7
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +473 -211
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -21
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +36 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +133 -7
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +261 -61
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +104 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
- package/dest/msg_validators/tx_validator/index.d.ts +5 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +4 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
- 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/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/discv5/discV5_service.d.ts +13 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +119 -23
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +18 -18
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +19 -20
- package/dest/services/encoding.d.ts +23 -6
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +41 -24
- package/dest/services/gossipsub/topic_score_params.d.ts +23 -17
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +36 -24
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +57 -56
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +483 -373
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +20 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +83 -26
- package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +102 -13
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +5 -8
- 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 +95 -127
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -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 +31 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -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 +52 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
- package/dest/services/reqresp/config.d.ts +15 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +11 -0
- package/dest/services/reqresp/interface.d.ts +16 -18
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -20
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
- package/dest/services/reqresp/reqresp.d.ts +7 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +75 -216
- package/dest/services/service.d.ts +29 -14
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +8 -17
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +17 -40
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +25 -32
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +96 -87
- package/dest/services/tx_collection/file_store_tx_source.d.ts +17 -6
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +53 -10
- package/dest/services/tx_collection/index.d.ts +2 -3
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +0 -1
- package/dest/services/tx_collection/instrumentation.js +1 -2
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/tx_collection.d.ts +39 -55
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +280 -108
- package/dest/services/tx_collection/tx_collection_sink.d.ts +7 -6
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +15 -24
- package/dest/services/tx_collection/tx_source.d.ts +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +29 -7
- package/dest/services/tx_file_store/tx_file_store.d.ts +3 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +13 -20
- package/dest/services/tx_provider.d.ts +5 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +7 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +5 -3
- package/dest/test-helpers/mock-pubsub.d.ts +26 -12
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +51 -45
- package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +17 -19
- package/dest/test-helpers/test_tx_provider.d.ts +3 -1
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
- package/dest/test-helpers/test_tx_provider.js +3 -0
- package/dest/test-helpers/testbench-utils.d.ts +22 -16
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +56 -16
- package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +111 -48
- package/dest/testbench/worker_client_manager.d.ts +12 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +57 -11
- package/dest/util.d.ts +13 -8
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +16 -16
- package/src/bootstrap/bootstrap.ts +17 -3
- package/src/client/factory.ts +95 -51
- package/src/client/interface.ts +59 -35
- package/src/client/p2p_client.ts +186 -196
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +259 -57
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +13 -19
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +336 -242
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +244 -69
- package/src/mem_pools/attestation_pool/mocks.ts +14 -8
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +27 -17
- package/src/mem_pools/tx_pool_v2/README.md +52 -28
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +114 -27
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +8 -4
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +5 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -8
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +61 -14
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +170 -28
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +91 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +54 -14
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +527 -207
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
- package/src/msg_validators/tx_validator/README.md +129 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +6 -15
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +44 -1
- package/src/msg_validators/tx_validator/factory.ts +413 -80
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
- package/src/msg_validators/tx_validator/index.ts +4 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/data_store.ts +5 -13
- package/src/services/discv5/discV5_service.ts +126 -14
- package/src/services/discv5/persisted_enr_store.ts +158 -0
- package/src/services/dummy_service.ts +26 -45
- package/src/services/encoding.ts +40 -24
- package/src/services/gossipsub/README.md +59 -22
- package/src/services/gossipsub/topic_score_params.ts +58 -31
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +554 -428
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +91 -25
- package/src/services/peer-manager/peer_scoring.ts +102 -8
- package/src/services/reqresp/README.md +194 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +92 -138
- package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
- package/src/services/reqresp/config.ts +19 -2
- package/src/services/reqresp/interface.ts +21 -47
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
- package/src/services/reqresp/reqresp.ts +87 -260
- package/src/services/service.ts +42 -30
- package/src/services/tx_collection/config.ts +24 -59
- package/src/services/tx_collection/file_store_tx_collection.ts +108 -107
- package/src/services/tx_collection/file_store_tx_source.ts +69 -10
- package/src/services/tx_collection/index.ts +1 -6
- package/src/services/tx_collection/instrumentation.ts +1 -1
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/tx_collection.ts +342 -156
- package/src/services/tx_collection/tx_collection_sink.ts +17 -31
- package/src/services/tx_collection/tx_source.ts +29 -8
- package/src/services/tx_file_store/tx_file_store.ts +11 -21
- package/src/services/tx_provider.ts +7 -2
- package/src/test-helpers/make-test-p2p-clients.ts +4 -3
- package/src/test-helpers/mock-pubsub.ts +59 -66
- package/src/test-helpers/reqresp-nodes.ts +15 -28
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +74 -31
- package/src/testbench/p2p_client_testbench_worker.ts +120 -63
- package/src/testbench/worker_client_manager.ts +72 -25
- package/src/util.ts +40 -19
- package/src/versioning.ts +3 -33
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/clock_tolerance.d.ts +0 -21
- package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
- package/dest/msg_validators/clock_tolerance.js +0 -37
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -54
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -321
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -49
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -55
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -206
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/clock_tolerance.ts +0 -51
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/fast_tx_collection.ts +0 -366
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -112
- package/src/services/tx_collection/slow_tx_collection.ts +0 -262
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ConfigMappingsType,
|
|
3
|
-
booleanConfigHelper,
|
|
4
|
-
enumConfigHelper,
|
|
5
|
-
numberConfigHelper,
|
|
6
|
-
} from '@aztec/foundation/config';
|
|
1
|
+
import { type ConfigMappingsType, numberConfigHelper } from '@aztec/foundation/config';
|
|
7
2
|
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/api-limit';
|
|
8
3
|
|
|
9
|
-
export type MissingTxsCollectorType = 'new' | 'old';
|
|
10
|
-
|
|
11
4
|
export type TxCollectionConfig = {
|
|
12
5
|
/** How long to wait before starting reqresp for fast collection */
|
|
13
6
|
txCollectionFastNodesTimeoutBeforeReqRespMs: number;
|
|
14
|
-
/** How often to collect from configured nodes */
|
|
15
|
-
txCollectionSlowNodesIntervalMs: number;
|
|
16
|
-
/** How ofter to collect from peers */
|
|
17
|
-
txCollectionSlowReqRespIntervalMs: number;
|
|
18
|
-
/** How long to wait for a reqresp response during slow collection */
|
|
19
|
-
txCollectionSlowReqRespTimeoutMs: number;
|
|
20
|
-
/** How often to reconcile found txs with the tx pool */
|
|
21
|
-
txCollectionReconcileIntervalMs: number;
|
|
22
|
-
/** Whether to disable the slow collection loop if we are dealing with any immediate requests */
|
|
23
|
-
txCollectionDisableSlowDuringFastRequests: boolean;
|
|
24
7
|
/** How many ms to wait between retried request to a node via RPC during fast collection */
|
|
25
8
|
txCollectionFastNodeIntervalMs: number;
|
|
26
9
|
/** A comma-separated list of Aztec node RPC URLs to use for tx collection */
|
|
@@ -29,14 +12,16 @@ export type TxCollectionConfig = {
|
|
|
29
12
|
txCollectionFastMaxParallelRequestsPerNode: number;
|
|
30
13
|
/** Maximum number of transactions to request from a node in a single batch */
|
|
31
14
|
txCollectionNodeRpcMaxBatchSize: number;
|
|
32
|
-
/** Which collector implementation to use for missing txs collection */
|
|
33
|
-
txCollectionMissingTxsCollectorType: MissingTxsCollectorType;
|
|
34
15
|
/** A comma-separated list of file store URLs (s3://, gs://, file://, http://) for tx collection */
|
|
35
16
|
txCollectionFileStoreUrls: string[];
|
|
36
|
-
/** Delay in ms before file store collection
|
|
37
|
-
txCollectionFileStoreSlowDelayMs: number;
|
|
38
|
-
/** Delay in ms before file store collection starts after fast collection is triggered */
|
|
17
|
+
/** Delay in ms from reqresp start before file store collection begins */
|
|
39
18
|
txCollectionFileStoreFastDelayMs: number;
|
|
19
|
+
/** Number of concurrent workers for fast file store collection */
|
|
20
|
+
txCollectionFileStoreFastWorkerCount: number;
|
|
21
|
+
/** Base backoff time in ms for fast file store collection retries */
|
|
22
|
+
txCollectionFileStoreFastBackoffBaseMs: number;
|
|
23
|
+
/** Max backoff time in ms for fast file store collection retries */
|
|
24
|
+
txCollectionFileStoreFastBackoffMaxMs: number;
|
|
40
25
|
};
|
|
41
26
|
|
|
42
27
|
export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig> = {
|
|
@@ -45,31 +30,6 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
|
|
|
45
30
|
description: 'How long to wait before starting reqresp for fast collection',
|
|
46
31
|
...numberConfigHelper(200),
|
|
47
32
|
},
|
|
48
|
-
txCollectionSlowNodesIntervalMs: {
|
|
49
|
-
env: 'TX_COLLECTION_SLOW_NODES_INTERVAL_MS',
|
|
50
|
-
description: 'How often to collect from configured nodes in the slow collection loop',
|
|
51
|
-
...numberConfigHelper(12_000),
|
|
52
|
-
},
|
|
53
|
-
txCollectionSlowReqRespIntervalMs: {
|
|
54
|
-
env: 'TX_COLLECTION_SLOW_REQ_RESP_INTERVAL_MS',
|
|
55
|
-
description: 'How often to collect from peers via reqresp in the slow collection loop',
|
|
56
|
-
...numberConfigHelper(12_000),
|
|
57
|
-
},
|
|
58
|
-
txCollectionSlowReqRespTimeoutMs: {
|
|
59
|
-
env: 'TX_COLLECTION_SLOW_REQ_RESP_TIMEOUT_MS',
|
|
60
|
-
description: 'How long to wait for a reqresp response during slow collection',
|
|
61
|
-
...numberConfigHelper(20_000),
|
|
62
|
-
},
|
|
63
|
-
txCollectionReconcileIntervalMs: {
|
|
64
|
-
env: 'TX_COLLECTION_RECONCILE_INTERVAL_MS',
|
|
65
|
-
description: 'How often to reconcile found txs from the tx pool',
|
|
66
|
-
...numberConfigHelper(60_000),
|
|
67
|
-
},
|
|
68
|
-
txCollectionDisableSlowDuringFastRequests: {
|
|
69
|
-
env: 'TX_COLLECTION_DISABLE_SLOW_DURING_FAST_REQUESTS',
|
|
70
|
-
description: 'Whether to disable the slow collection loop if we are dealing with any immediate requests',
|
|
71
|
-
...booleanConfigHelper(true),
|
|
72
|
-
},
|
|
73
33
|
txCollectionFastNodeIntervalMs: {
|
|
74
34
|
env: 'TX_COLLECTION_FAST_NODE_INTERVAL_MS',
|
|
75
35
|
description: 'How many ms to wait between retried request to a node via RPC during fast collection',
|
|
@@ -96,11 +56,6 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
|
|
|
96
56
|
description: 'Maximum number of transactions to request from a node in a single batch',
|
|
97
57
|
...numberConfigHelper(MAX_RPC_TXS_LEN),
|
|
98
58
|
},
|
|
99
|
-
txCollectionMissingTxsCollectorType: {
|
|
100
|
-
env: 'TX_COLLECTION_MISSING_TXS_COLLECTOR_TYPE',
|
|
101
|
-
description: 'Which collector implementation to use for missing txs collection (new or old)',
|
|
102
|
-
...enumConfigHelper(['new', 'old'] as const, 'new'),
|
|
103
|
-
},
|
|
104
59
|
txCollectionFileStoreUrls: {
|
|
105
60
|
env: 'TX_COLLECTION_FILE_STORE_URLS',
|
|
106
61
|
description: 'A comma-separated list of file store URLs (s3://, gs://, file://, http://) for tx collection',
|
|
@@ -111,14 +66,24 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
|
|
|
111
66
|
.filter(url => url.length > 0),
|
|
112
67
|
defaultValue: [],
|
|
113
68
|
},
|
|
114
|
-
txCollectionFileStoreSlowDelayMs: {
|
|
115
|
-
env: 'TX_COLLECTION_FILE_STORE_SLOW_DELAY_MS',
|
|
116
|
-
description: 'Delay before file store collection starts after slow collection',
|
|
117
|
-
...numberConfigHelper(24_000),
|
|
118
|
-
},
|
|
119
69
|
txCollectionFileStoreFastDelayMs: {
|
|
120
70
|
env: 'TX_COLLECTION_FILE_STORE_FAST_DELAY_MS',
|
|
121
|
-
description: 'Delay before file store collection
|
|
71
|
+
description: 'Delay in ms from reqresp start before file store collection begins',
|
|
122
72
|
...numberConfigHelper(2_000),
|
|
123
73
|
},
|
|
74
|
+
txCollectionFileStoreFastWorkerCount: {
|
|
75
|
+
env: 'TX_COLLECTION_FILE_STORE_FAST_WORKER_COUNT',
|
|
76
|
+
description: 'Number of concurrent workers for fast file store collection',
|
|
77
|
+
...numberConfigHelper(5),
|
|
78
|
+
},
|
|
79
|
+
txCollectionFileStoreFastBackoffBaseMs: {
|
|
80
|
+
env: 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_BASE_MS',
|
|
81
|
+
description: 'Base backoff time in ms for fast file store collection retries',
|
|
82
|
+
...numberConfigHelper(1_000),
|
|
83
|
+
},
|
|
84
|
+
txCollectionFileStoreFastBackoffMaxMs: {
|
|
85
|
+
env: 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_MAX_MS',
|
|
86
|
+
description: 'Max backoff time in ms for fast file store collection retries',
|
|
87
|
+
...numberConfigHelper(5_000),
|
|
88
|
+
},
|
|
124
89
|
};
|
|
@@ -1,136 +1,96 @@
|
|
|
1
|
+
import { times } from '@aztec/foundation/collection';
|
|
1
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
4
6
|
|
|
5
7
|
import type { FileStoreTxSource } from './file_store_tx_source.js';
|
|
8
|
+
import type { IRequestTracker } from './request_tracker.js';
|
|
6
9
|
import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
/** Configuration for a FileStoreTxCollection instance. */
|
|
12
|
+
export type FileStoreCollectionConfig = {
|
|
13
|
+
workerCount: number;
|
|
14
|
+
backoffBaseMs: number;
|
|
15
|
+
backoffMaxMs: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type FileStoreTxEntry = {
|
|
19
|
+
txHash: string;
|
|
20
|
+
attempts: number;
|
|
21
|
+
lastAttemptTime: number;
|
|
22
|
+
nextSourceIndex: number;
|
|
23
|
+
};
|
|
10
24
|
|
|
11
25
|
/**
|
|
12
26
|
* Collects txs from file stores as a fallback after P2P methods have been tried.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
27
|
+
* Each call to startCollecting spins up its own worker pool which pulls entries with priority
|
|
28
|
+
* (fewest attempts first), retries with round-robin across sources, and applies exponential
|
|
29
|
+
* backoff between full cycles through all sources. Workers self-terminate when the request
|
|
30
|
+
* tracker is cancelled (deadline / all-fetched / external) or when there is nothing left to do.
|
|
15
31
|
*/
|
|
16
32
|
export class FileStoreTxCollection {
|
|
17
|
-
/** Map from tx hash to add context for txs queued for download. */
|
|
18
|
-
private pendingTxs = new Map<string, TxAddContext>();
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Tracks tx hashes found elsewhere, even before startCollecting is called.
|
|
22
|
-
* Needed because the orchestrator delays startCollecting via a real sleep, but foundTxs
|
|
23
|
-
* may arrive during that delay — before the hashes are added to pendingTxs.
|
|
24
|
-
*/
|
|
25
|
-
private foundTxHashes = new Set<string>();
|
|
26
|
-
|
|
27
|
-
/** Queue of tx hashes to be downloaded. */
|
|
28
|
-
private downloadQueue = new FifoMemoryQueue<TxHash>();
|
|
29
|
-
|
|
30
|
-
/** Worker promises for concurrent downloads. */
|
|
31
|
-
private workers: Promise<void>[] = [];
|
|
32
|
-
|
|
33
|
-
/** Whether the collection has been started. */
|
|
34
|
-
private started = false;
|
|
35
|
-
|
|
36
33
|
constructor(
|
|
37
|
-
private readonly
|
|
34
|
+
private readonly sources: FileStoreTxSource[],
|
|
38
35
|
private readonly txCollectionSink: TxCollectionSink,
|
|
36
|
+
private readonly config: FileStoreCollectionConfig,
|
|
37
|
+
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
39
38
|
private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
|
|
40
39
|
) {}
|
|
41
40
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Spins up workers to download all txs still missing from the tracker, racing across the
|
|
43
|
+
* configured file store sources. Resolves once all workers settle.
|
|
44
|
+
*/
|
|
45
|
+
public async startCollecting(requestTracker: IRequestTracker, context: TxAddContext): Promise<void> {
|
|
46
|
+
if (this.sources.length === 0 || requestTracker.checkCancelled()) {
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
51
|
+
const entries: Set<FileStoreTxEntry> = new Set();
|
|
52
|
+
for (const hashStr of requestTracker.missingTxHashes) {
|
|
53
|
+
entries.add({
|
|
54
|
+
txHash: hashStr,
|
|
55
|
+
attempts: 0,
|
|
56
|
+
lastAttemptTime: 0,
|
|
57
|
+
nextSourceIndex: Math.floor(Math.random() * this.sources.length),
|
|
58
|
+
});
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Stops all collection activity. */
|
|
64
|
-
public async stop() {
|
|
65
|
-
if (!this.started) {
|
|
61
|
+
// Yield before spawning so the synchronous caller can finish any follow-up (eg. marking a tx
|
|
62
|
+
// as fetched on the tracker, or cancelling it) before workers begin scanning entries.
|
|
63
|
+
await Promise.resolve();
|
|
64
|
+
if (requestTracker.checkCancelled()) {
|
|
66
65
|
return;
|
|
67
66
|
}
|
|
68
|
-
this.started = false;
|
|
69
|
-
this.downloadQueue.end();
|
|
70
|
-
await Promise.all(this.workers);
|
|
71
|
-
this.workers = [];
|
|
72
|
-
this.pendingTxs.clear();
|
|
73
|
-
this.foundTxHashes.clear();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Remove the given tx hashes from pending. */
|
|
77
|
-
public stopCollecting(txHashes: TxHash[]) {
|
|
78
|
-
for (const txHash of txHashes) {
|
|
79
|
-
const hashStr = txHash.toString();
|
|
80
|
-
this.pendingTxs.delete(hashStr);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
67
|
|
|
84
|
-
|
|
85
|
-
public clearPending() {
|
|
86
|
-
this.pendingTxs.clear();
|
|
87
|
-
this.foundTxHashes.clear();
|
|
68
|
+
await Promise.allSettled(times(this.config.workerCount, () => this.workerLoop(entries, requestTracker, context)));
|
|
88
69
|
}
|
|
89
70
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
71
|
+
private async workerLoop(
|
|
72
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
73
|
+
entries: Set<FileStoreTxEntry>,
|
|
74
|
+
requestTracker: IRequestTracker,
|
|
75
|
+
context: TxAddContext,
|
|
76
|
+
): Promise<void> {
|
|
77
|
+
while (!requestTracker.checkCancelled() && entries.size > 0) {
|
|
78
|
+
const action = this.getNextAction(entries, requestTracker);
|
|
79
|
+
if (action.type === 'sleep') {
|
|
80
|
+
await Promise.race([sleep(action.ms), requestTracker.cancellationToken]);
|
|
81
|
+
continue;
|
|
97
82
|
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
83
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
this.foundTxHashes.add(hashStr);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Processes a single tx hash from the download queue. */
|
|
111
|
-
private async processDownload(txHash: TxHash) {
|
|
112
|
-
const hashStr = txHash.toString();
|
|
113
|
-
const context = this.pendingTxs.get(hashStr);
|
|
114
|
-
|
|
115
|
-
// Skip if already found by another method
|
|
116
|
-
if (!context) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
await this.downloadTx(txHash, context);
|
|
121
|
-
this.pendingTxs.delete(hashStr);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** Attempt to download a tx from file stores (round-robin). */
|
|
125
|
-
private async downloadTx(txHash: TxHash, context: TxAddContext) {
|
|
126
|
-
const startIndex = Math.floor(Math.random() * this.fileStoreSources.length);
|
|
127
|
-
for (let i = startIndex; i < startIndex + this.fileStoreSources.length; i++) {
|
|
128
|
-
const source = this.fileStoreSources[i % this.fileStoreSources.length];
|
|
84
|
+
const entry = action.entry;
|
|
85
|
+
const source = this.sources[entry.nextSourceIndex % this.sources.length];
|
|
86
|
+
entry.nextSourceIndex++;
|
|
87
|
+
entry.attempts++;
|
|
88
|
+
entry.lastAttemptTime = this.dateProvider.now();
|
|
129
89
|
|
|
130
90
|
try {
|
|
131
91
|
const result = await this.txCollectionSink.collect(
|
|
132
|
-
|
|
133
|
-
[txHash],
|
|
92
|
+
() => source.getTxsByHash([TxHash.fromString(entry.txHash)]),
|
|
93
|
+
[entry.txHash],
|
|
134
94
|
{
|
|
135
95
|
description: `file-store ${source.getInfo()}`,
|
|
136
96
|
method: 'file-store',
|
|
@@ -138,15 +98,56 @@ export class FileStoreTxCollection {
|
|
|
138
98
|
},
|
|
139
99
|
context,
|
|
140
100
|
);
|
|
141
|
-
|
|
142
101
|
if (result.txs.length > 0) {
|
|
143
|
-
|
|
102
|
+
entries.delete(entry);
|
|
144
103
|
}
|
|
145
104
|
} catch (err) {
|
|
146
|
-
this.log.trace(`
|
|
105
|
+
this.log.trace(`Error downloading tx ${entry.txHash} from ${source.getInfo()}`, { err });
|
|
147
106
|
}
|
|
148
107
|
}
|
|
108
|
+
}
|
|
149
109
|
|
|
150
|
-
|
|
110
|
+
/** Single-pass scan: removes stale entries, finds the best ready entry, or computes sleep time. */
|
|
111
|
+
private getNextAction(
|
|
112
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
113
|
+
entries: Set<FileStoreTxEntry>,
|
|
114
|
+
requestTracker: IRequestTracker,
|
|
115
|
+
): { type: 'process'; entry: FileStoreTxEntry } | { type: 'sleep'; ms: number } {
|
|
116
|
+
const now = this.dateProvider.now();
|
|
117
|
+
let best: FileStoreTxEntry | undefined;
|
|
118
|
+
let earliestReadyAt = Infinity;
|
|
119
|
+
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
// Drop entries whose tx was already found via another collection path.
|
|
122
|
+
if (!requestTracker.isMissing(entry.txHash)) {
|
|
123
|
+
entries.delete(entry);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const backoffMs = this.getBackoffMs(entry);
|
|
127
|
+
const readyAt = entry.lastAttemptTime + backoffMs;
|
|
128
|
+
if (readyAt > now) {
|
|
129
|
+
earliestReadyAt = Math.min(earliestReadyAt, readyAt);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (!best || entry.attempts < best.attempts) {
|
|
133
|
+
best = entry;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (best) {
|
|
138
|
+
return { type: 'process', entry: best };
|
|
139
|
+
}
|
|
140
|
+
// earliestReadyAt is finite whenever there are surviving entries; if entries became empty,
|
|
141
|
+
// the outer worker loop will exit on its next iteration via entries.size === 0.
|
|
142
|
+
return { type: 'sleep', ms: earliestReadyAt === Infinity ? 0 : earliestReadyAt - now };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Computes backoff for an entry. Backoff applies after a full cycle through all sources. */
|
|
146
|
+
private getBackoffMs(entry: FileStoreTxEntry): number {
|
|
147
|
+
const fullCycles = Math.floor(entry.attempts / this.sources.length);
|
|
148
|
+
if (fullCycles === 0) {
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
return Math.min(this.config.backoffBaseMs * Math.pow(2, fullCycles - 1), this.config.backoffMaxMs);
|
|
151
152
|
}
|
|
152
153
|
}
|
|
@@ -1,26 +1,54 @@
|
|
|
1
|
+
import { partitionAsync } from '@aztec/foundation/collection';
|
|
1
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
2
4
|
import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
|
|
3
|
-
import { Tx, type TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import { Tx, type TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
6
|
+
import {
|
|
7
|
+
type Histogram,
|
|
8
|
+
Metrics,
|
|
9
|
+
type TelemetryClient,
|
|
10
|
+
type UpDownCounter,
|
|
11
|
+
getTelemetryClient,
|
|
12
|
+
} from '@aztec/telemetry-client';
|
|
4
13
|
|
|
5
|
-
import type { TxSource } from './tx_source.js';
|
|
14
|
+
import type { TxSource, TxSourceCollectionResult } from './tx_source.js';
|
|
6
15
|
|
|
7
16
|
/** TxSource implementation that downloads txs from a file store. */
|
|
8
17
|
export class FileStoreTxSource implements TxSource {
|
|
18
|
+
private downloadsSuccess: UpDownCounter;
|
|
19
|
+
private downloadsFailed: UpDownCounter;
|
|
20
|
+
private downloadDuration: Histogram;
|
|
21
|
+
private downloadSize: Histogram;
|
|
22
|
+
|
|
9
23
|
private constructor(
|
|
10
24
|
private readonly fileStore: ReadOnlyFileStore,
|
|
11
25
|
private readonly baseUrl: string,
|
|
26
|
+
private readonly basePath: string,
|
|
27
|
+
private readonly txValidator: TxValidator,
|
|
12
28
|
private readonly log: Logger,
|
|
13
|
-
|
|
29
|
+
telemetry: TelemetryClient,
|
|
30
|
+
) {
|
|
31
|
+
const meter = telemetry.getMeter('file-store-tx-source');
|
|
32
|
+
this.downloadsSuccess = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_SUCCESS);
|
|
33
|
+
this.downloadsFailed = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_FAILED);
|
|
34
|
+
this.downloadDuration = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_DURATION);
|
|
35
|
+
this.downloadSize = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_SIZE);
|
|
36
|
+
}
|
|
14
37
|
|
|
15
38
|
/**
|
|
16
39
|
* Creates a FileStoreTxSource from a URL.
|
|
17
40
|
* @param url - The file store URL (s3://, gs://, file://, http://, https://).
|
|
41
|
+
* @param basePath - Base path for tx files within the store.
|
|
18
42
|
* @param log - Optional logger.
|
|
43
|
+
* @param telemetry - Optional telemetry client.
|
|
19
44
|
* @returns The FileStoreTxSource instance, or undefined if creation fails.
|
|
20
45
|
*/
|
|
21
46
|
public static async create(
|
|
22
47
|
url: string,
|
|
48
|
+
basePath: string,
|
|
49
|
+
txValidator: TxValidator,
|
|
23
50
|
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
51
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
24
52
|
): Promise<FileStoreTxSource | undefined> {
|
|
25
53
|
try {
|
|
26
54
|
const fileStore = await createReadOnlyFileStore(url, log);
|
|
@@ -28,7 +56,7 @@ export class FileStoreTxSource implements TxSource {
|
|
|
28
56
|
log.warn(`Failed to create file store for URL: ${url}`);
|
|
29
57
|
return undefined;
|
|
30
58
|
}
|
|
31
|
-
return new FileStoreTxSource(fileStore, url, log);
|
|
59
|
+
return new FileStoreTxSource(fileStore, url, basePath, txValidator, log, telemetry);
|
|
32
60
|
} catch (err) {
|
|
33
61
|
log.warn(`Error creating file store for URL: ${url}`, { error: err });
|
|
34
62
|
return undefined;
|
|
@@ -39,32 +67,63 @@ export class FileStoreTxSource implements TxSource {
|
|
|
39
67
|
return `file-store:${this.baseUrl}`;
|
|
40
68
|
}
|
|
41
69
|
|
|
42
|
-
public getTxsByHash(txHashes: TxHash[]): Promise<
|
|
43
|
-
|
|
70
|
+
public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
|
|
71
|
+
const results = await Promise.all(
|
|
44
72
|
txHashes.map(async txHash => {
|
|
45
|
-
const path =
|
|
73
|
+
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
74
|
+
const timer = new Timer();
|
|
46
75
|
try {
|
|
47
76
|
const buffer = await this.fileStore.read(path);
|
|
48
|
-
|
|
77
|
+
const tx = Tx.fromBuffer(buffer);
|
|
78
|
+
return { tx, downloadDuration: timer.ms(), downloadSize: buffer.length };
|
|
49
79
|
} catch {
|
|
50
|
-
|
|
80
|
+
this.downloadsFailed.add(1);
|
|
51
81
|
return undefined;
|
|
52
82
|
}
|
|
53
83
|
}),
|
|
54
84
|
);
|
|
85
|
+
|
|
86
|
+
const txs = results.filter(tx => tx !== undefined);
|
|
87
|
+
const [validTxs, invalidTxs] = await partitionAsync(
|
|
88
|
+
txs,
|
|
89
|
+
async ({ tx, downloadDuration, downloadSize }): Promise<boolean> => {
|
|
90
|
+
const valid = await this.txValidator.validateTx(tx);
|
|
91
|
+
if (valid.result === 'valid') {
|
|
92
|
+
this.downloadsSuccess.add(1);
|
|
93
|
+
this.downloadDuration.record(Math.ceil(downloadDuration));
|
|
94
|
+
this.downloadSize.record(downloadSize);
|
|
95
|
+
return true;
|
|
96
|
+
} else {
|
|
97
|
+
this.downloadsFailed.add(1);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
validTxs: validTxs.map(({ tx }) => tx),
|
|
105
|
+
invalidTxHashes: invalidTxs.map(({ tx }) => tx.getTxHash().toString()),
|
|
106
|
+
};
|
|
55
107
|
}
|
|
56
108
|
}
|
|
57
109
|
|
|
58
110
|
/**
|
|
59
111
|
* Creates FileStoreTxSource instances from URLs.
|
|
60
112
|
* @param urls - Array of file store URLs.
|
|
113
|
+
* @param basePath - Base path for tx files within each store.
|
|
61
114
|
* @param log - Optional logger.
|
|
115
|
+
* @param telemetry - Optional telemetry client.
|
|
62
116
|
* @returns Array of successfully created FileStoreTxSource instances.
|
|
63
117
|
*/
|
|
64
118
|
export async function createFileStoreTxSources(
|
|
65
119
|
urls: string[],
|
|
120
|
+
basePath: string,
|
|
121
|
+
txValidator: TxValidator,
|
|
66
122
|
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
123
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
67
124
|
): Promise<FileStoreTxSource[]> {
|
|
68
|
-
const sources = await Promise.all(
|
|
125
|
+
const sources = await Promise.all(
|
|
126
|
+
urls.map(url => FileStoreTxSource.create(url, basePath, txValidator, log, telemetry)),
|
|
127
|
+
);
|
|
69
128
|
return sources.filter((s): s is FileStoreTxSource => s !== undefined);
|
|
70
129
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export { TxCollection, type FastCollectionRequestInput } from './tx_collection.js';
|
|
1
|
+
export { TxCollection, type FastCollectionRequestInput, type IReqRespTxsCollector } from './tx_collection.js';
|
|
2
2
|
export { type TxSource, createNodeRpcTxSources, NodeRpcTxSource } from './tx_source.js';
|
|
3
|
-
export {
|
|
4
|
-
type MissingTxsCollector,
|
|
5
|
-
BatchTxRequesterCollector,
|
|
6
|
-
SendBatchRequestCollector,
|
|
7
|
-
} from './proposal_tx_collector.js';
|
|
8
3
|
export { FileStoreTxSource, createFileStoreTxSources } from './file_store_tx_source.js';
|
|
@@ -18,7 +18,7 @@ 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]: ['fast-req-resp', 'fast-node-rpc', '
|
|
21
|
+
[Attributes.TX_COLLECTION_METHOD]: ['fast-req-resp', 'fast-node-rpc', 'file-store'],
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tracks which transactions are still missing and need to be fetched.
|
|
8
|
+
* Manages the request deadline and serves as the sole source of cancellation signal.
|
|
9
|
+
* The request is cancelled when all txs are fetched or the deadline expires.
|
|
10
|
+
*/
|
|
11
|
+
export interface IRequestTracker {
|
|
12
|
+
/** Returns the set of transaction hashes that are still missing. */
|
|
13
|
+
get missingTxHashes(): Set<string>;
|
|
14
|
+
/** Size of this.missingTxHashes */
|
|
15
|
+
get numberOfMissingTxs(): number;
|
|
16
|
+
/** Are all requested txs fetched */
|
|
17
|
+
allFetched(): boolean;
|
|
18
|
+
/** Checks that transaction is still missing */
|
|
19
|
+
isMissing(txHash: string): boolean;
|
|
20
|
+
/** Marks a transaction as fetched. Returns true if it was previously missing. */
|
|
21
|
+
markFetched(tx: Tx): boolean;
|
|
22
|
+
/** Get list of collected txs */
|
|
23
|
+
get collectedTxs(): Tx[];
|
|
24
|
+
/** The deadline for this request. */
|
|
25
|
+
get deadline(): Date;
|
|
26
|
+
/** Remaining time in milliseconds until deadline. Returns 0 if already past. */
|
|
27
|
+
get timeoutMs(): number;
|
|
28
|
+
/** Checks whether the request is cancelled (deadline expired or all fetched). May trigger cancellation if deadline has passed. */
|
|
29
|
+
checkCancelled(): boolean;
|
|
30
|
+
/** Resolves when deadline expires or all txs are fetched. */
|
|
31
|
+
get cancellationToken(): Promise<void>;
|
|
32
|
+
/** Externally cancel the request. */
|
|
33
|
+
cancel(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class RequestTracker implements IRequestTracker {
|
|
37
|
+
public readonly collectedTxs: Tx[] = [];
|
|
38
|
+
private done = false;
|
|
39
|
+
private readonly cancellationTokenPromise: PromiseWithResolvers<void>;
|
|
40
|
+
private readonly deadlineTimer: ReturnType<typeof setTimeout> | undefined;
|
|
41
|
+
|
|
42
|
+
private constructor(
|
|
43
|
+
public readonly missingTxHashes: Set<string>,
|
|
44
|
+
public readonly deadline: Date,
|
|
45
|
+
private readonly dateProvider?: DateProvider,
|
|
46
|
+
) {
|
|
47
|
+
this.cancellationTokenPromise = promiseWithResolvers<void>();
|
|
48
|
+
|
|
49
|
+
if (missingTxHashes.size === 0) {
|
|
50
|
+
this.finish();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const now = this.dateProvider?.now() ?? Date.now();
|
|
55
|
+
const remaining = deadline.getTime() - now;
|
|
56
|
+
if (remaining <= 0) {
|
|
57
|
+
this.finish();
|
|
58
|
+
} else {
|
|
59
|
+
this.deadlineTimer = setTimeout(() => this.finish(), remaining);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public static create(hashes: TxHash[] | string[], deadline: Date, dateProvider?: DateProvider) {
|
|
64
|
+
return new RequestTracker(new Set(hashes.map(hash => hash.toString())), deadline, dateProvider);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
markFetched(tx: Tx): boolean {
|
|
68
|
+
if (this.missingTxHashes.delete(tx.txHash.toString())) {
|
|
69
|
+
this.collectedTxs.push(tx);
|
|
70
|
+
if (this.allFetched()) {
|
|
71
|
+
this.finish();
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get numberOfMissingTxs(): number {
|
|
79
|
+
return this.missingTxHashes.size;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
allFetched(): boolean {
|
|
83
|
+
return this.numberOfMissingTxs === 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
isMissing(txHash: string): boolean {
|
|
87
|
+
return this.missingTxHashes.has(txHash.toString());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get timeoutMs(): number {
|
|
91
|
+
const now = this.dateProvider?.now() ?? Date.now();
|
|
92
|
+
return Math.max(0, this.deadline.getTime() - now);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
checkCancelled(): boolean {
|
|
96
|
+
if (this.done) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
// Synchronous fallback: check deadline even if setTimeout hasn't fired yet.
|
|
100
|
+
// This prevents macrotask starvation in tight async loops from blocking cancellation.
|
|
101
|
+
const now = this.dateProvider?.now() ?? Date.now();
|
|
102
|
+
if (now >= this.deadline.getTime()) {
|
|
103
|
+
this.finish();
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get cancellationToken(): Promise<void> {
|
|
110
|
+
return this.cancellationTokenPromise.promise;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
cancel(): void {
|
|
114
|
+
this.finish();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private finish() {
|
|
118
|
+
if (this.done) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.done = true;
|
|
122
|
+
if (this.deadlineTimer) {
|
|
123
|
+
clearTimeout(this.deadlineTimer);
|
|
124
|
+
}
|
|
125
|
+
this.cancellationTokenPromise.resolve();
|
|
126
|
+
}
|
|
127
|
+
}
|