@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.7ac86ea28
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 +7 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +46 -11
- package/dest/client/interface.d.ts +43 -23
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +38 -42
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +145 -145
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -6
- package/dest/config.d.ts +23 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -1
- 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/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 +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 +4 -1
- 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 +10 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -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 +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -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 +5 -3
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +1 -1
- 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 +8 -4
- 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 +14 -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 +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -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 +16 -4
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +31 -5
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +62 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -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 +27 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +8 -3
- 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 +11 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +12 -4
- 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 +239 -109
- 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 +3 -3
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- 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/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 +12 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +9 -0
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +4 -3
- 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 +85 -35
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +370 -267
- 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 +4 -3
- 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 +5 -9
- 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/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 +4 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
- 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 +15 -0
- 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 +11 -4
- package/dest/services/service.d.ts +38 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +19 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +46 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +56 -36
- 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 +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +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 +7 -6
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- 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 +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +5 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +29 -2
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +103 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -1
- 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 +10 -10
- 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 +86 -15
- package/src/client/interface.ts +59 -23
- package/src/client/p2p_client.ts +184 -167
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
- package/src/config.ts +34 -2
- 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 +76 -10
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- 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 +4 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +15 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -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 +3 -3
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +8 -7
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +16 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +90 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +32 -5
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +17 -6
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +274 -104
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
- 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/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +17 -1
- package/src/services/encoding.ts +4 -3
- 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 +367 -271
- package/src/services/peer-manager/peer_scoring.ts +25 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +6 -6
- 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/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +13 -3
- package/src/services/service.ts +50 -1
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +65 -32
- 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 +1 -0
- 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 +8 -7
- 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 +8 -7
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +143 -3
- package/src/test-helpers/reqresp-nodes.ts +2 -1
- package/src/test-helpers/testbench-utils.ts +127 -71
- package/src/testbench/p2p_client_testbench_worker.ts +22 -15
- 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
|
@@ -14,13 +14,14 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
14
14
|
import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
|
|
15
15
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
16
16
|
import type { TxCollectionConfig } from './config.js';
|
|
17
|
+
import { MissingTxsTracker } from './missing_txs_tracker.js';
|
|
17
18
|
import {
|
|
18
19
|
BatchTxRequesterCollector,
|
|
19
20
|
type MissingTxsCollector,
|
|
20
21
|
SendBatchRequestCollector,
|
|
21
22
|
} from './proposal_tx_collector.js';
|
|
22
23
|
import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
|
|
23
|
-
import type { TxCollectionSink } from './tx_collection_sink.js';
|
|
24
|
+
import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
24
25
|
import type { TxSource } from './tx_source.js';
|
|
25
26
|
|
|
26
27
|
export class FastTxCollection {
|
|
@@ -77,29 +78,29 @@ export class FastTxCollection {
|
|
|
77
78
|
// This promise is used to await for the collection to finish during the main collectFast method.
|
|
78
79
|
// It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
|
|
79
80
|
const promise = promiseWithResolvers<void>();
|
|
80
|
-
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);
|
|
81
82
|
|
|
82
83
|
const request: FastCollectionRequest = {
|
|
83
84
|
...input,
|
|
84
85
|
blockInfo,
|
|
85
86
|
promise,
|
|
86
|
-
|
|
87
|
-
missingTxHashes: new Set(txHashes.map(t => t.toString())),
|
|
87
|
+
missingTxTracker: MissingTxsTracker.fromArray(txHashes),
|
|
88
88
|
deadline: opts.deadline,
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
const [duration] = await elapsed(() => this.collectFast(request, { ...opts }));
|
|
92
|
+
clearTimeout(timeoutTimer);
|
|
92
93
|
|
|
93
94
|
this.log.verbose(
|
|
94
|
-
`Collected ${request.
|
|
95
|
+
`Collected ${request.missingTxTracker.collectedTxs.length} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
|
|
95
96
|
{
|
|
96
97
|
...blockInfo,
|
|
97
98
|
duration,
|
|
98
99
|
requestType: input.type,
|
|
99
|
-
missingTxs: [...request.missingTxHashes],
|
|
100
|
+
missingTxs: [...request.missingTxTracker.missingTxHashes],
|
|
100
101
|
},
|
|
101
102
|
);
|
|
102
|
-
return
|
|
103
|
+
return request.missingTxTracker.collectedTxs;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
protected async collectFast(
|
|
@@ -110,7 +111,7 @@ export class FastTxCollection {
|
|
|
110
111
|
const { blockInfo } = request;
|
|
111
112
|
|
|
112
113
|
this.log.debug(
|
|
113
|
-
`Starting fast collection of ${request.
|
|
114
|
+
`Starting fast collection of ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
114
115
|
{ ...blockInfo, requestType: request.type, deadline: opts.deadline },
|
|
115
116
|
);
|
|
116
117
|
|
|
@@ -123,7 +124,7 @@ export class FastTxCollection {
|
|
|
123
124
|
await Promise.race([request.promise.promise, waitBeforeReqResp]);
|
|
124
125
|
|
|
125
126
|
// If we have collected all txs, we can stop here
|
|
126
|
-
if (request.
|
|
127
|
+
if (request.missingTxTracker.allFetched()) {
|
|
127
128
|
this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
|
|
128
129
|
return;
|
|
129
130
|
}
|
|
@@ -137,7 +138,7 @@ export class FastTxCollection {
|
|
|
137
138
|
const logCtx = {
|
|
138
139
|
...blockInfo,
|
|
139
140
|
errorMessage: err instanceof Error ? err.message : undefined,
|
|
140
|
-
missingTxs:
|
|
141
|
+
missingTxs: request.missingTxTracker.missingTxHashes.values().map(txHash => txHash.toString()),
|
|
141
142
|
};
|
|
142
143
|
if (err instanceof Error && err.name === 'TimeoutError') {
|
|
143
144
|
this.log.warn(`Timed out collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
|
|
@@ -165,7 +166,11 @@ export class FastTxCollection {
|
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
// Keep a shared priority queue of all txs pending to be requested, sorted by the number of attempts made to collect them.
|
|
168
|
-
const attemptsPerTx = [...request.missingTxHashes].map(txHash => ({
|
|
169
|
+
const attemptsPerTx = [...request.missingTxTracker.missingTxHashes].map(txHash => ({
|
|
170
|
+
txHash,
|
|
171
|
+
attempts: 0,
|
|
172
|
+
found: false,
|
|
173
|
+
}));
|
|
169
174
|
|
|
170
175
|
// Returns once we have finished all node loops. Each loop finishes when the deadline is hit, or all txs have been collected.
|
|
171
176
|
await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx, opts)));
|
|
@@ -178,7 +183,7 @@ export class FastTxCollection {
|
|
|
178
183
|
opts: { deadline: Date },
|
|
179
184
|
) {
|
|
180
185
|
const notFinished = () =>
|
|
181
|
-
this.dateProvider.now() <= +opts.deadline && request.
|
|
186
|
+
this.dateProvider.now() <= +opts.deadline && !request.missingTxTracker.allFetched() && this.requests.has(request);
|
|
182
187
|
|
|
183
188
|
const maxParallelRequests = this.config.txCollectionFastMaxParallelRequestsPerNode;
|
|
184
189
|
const maxBatchSize = this.config.txCollectionNodeRpcMaxBatchSize;
|
|
@@ -195,7 +200,7 @@ export class FastTxCollection {
|
|
|
195
200
|
if (!txToRequest) {
|
|
196
201
|
// No more txs to process
|
|
197
202
|
break;
|
|
198
|
-
} else if (!request.
|
|
203
|
+
} else if (!request.missingTxTracker.isMissing(txToRequest.txHash)) {
|
|
199
204
|
// Mark as found if it was found somewhere else, we'll then remove it from the array.
|
|
200
205
|
// We don't delete it now since 'array.splice' is pretty expensive, so we do it after sorting.
|
|
201
206
|
txToRequest.found = true;
|
|
@@ -224,16 +229,24 @@ export class FastTxCollection {
|
|
|
224
229
|
return;
|
|
225
230
|
}
|
|
226
231
|
|
|
232
|
+
const txHashes = batch.map(({ txHash }) => txHash);
|
|
227
233
|
// Collect this batch from the node
|
|
228
234
|
await this.txCollectionSink.collect(
|
|
229
|
-
|
|
230
|
-
|
|
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,
|
|
231
243
|
{
|
|
232
244
|
description: `fast ${node.getInfo()}`,
|
|
233
245
|
node: node.getInfo(),
|
|
234
246
|
method: 'fast-node-rpc',
|
|
235
247
|
...request.blockInfo,
|
|
236
248
|
},
|
|
249
|
+
this.getAddContext(request),
|
|
237
250
|
);
|
|
238
251
|
|
|
239
252
|
// Clear from the active requests the txs we just requested
|
|
@@ -266,36 +279,58 @@ export class FastTxCollection {
|
|
|
266
279
|
}
|
|
267
280
|
|
|
268
281
|
this.log.debug(
|
|
269
|
-
`Starting fast reqresp for ${request.
|
|
282
|
+
`Starting fast reqresp for ${request.missingTxTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
270
283
|
{ ...blockInfo, timeoutMs, pinnedPeer },
|
|
271
284
|
);
|
|
272
285
|
|
|
273
286
|
try {
|
|
274
287
|
await this.txCollectionSink.collect(
|
|
275
|
-
async
|
|
288
|
+
async () => {
|
|
289
|
+
let result: Tx[];
|
|
276
290
|
if (request.type === 'proposal') {
|
|
277
|
-
|
|
291
|
+
result = await this.missingTxsCollector.collectTxs(
|
|
292
|
+
request.missingTxTracker,
|
|
293
|
+
request.blockProposal,
|
|
294
|
+
pinnedPeer,
|
|
295
|
+
timeoutMs,
|
|
296
|
+
);
|
|
278
297
|
} else if (request.type === 'block') {
|
|
279
298
|
const blockTxsSource = {
|
|
280
299
|
txHashes: request.block.body.txEffects.map(e => e.txHash),
|
|
281
300
|
archive: request.block.archive.root,
|
|
282
301
|
};
|
|
283
|
-
|
|
302
|
+
result = await this.missingTxsCollector.collectTxs(
|
|
303
|
+
request.missingTxTracker,
|
|
304
|
+
blockTxsSource,
|
|
305
|
+
pinnedPeer,
|
|
306
|
+
timeoutMs,
|
|
307
|
+
);
|
|
284
308
|
} else {
|
|
285
309
|
throw new Error(`Unknown request type: ${(request as any).type}`);
|
|
286
310
|
}
|
|
311
|
+
return { validTxs: result, invalidTxHashes: [] };
|
|
287
312
|
},
|
|
288
|
-
Array.from(request.missingTxHashes)
|
|
313
|
+
Array.from(request.missingTxTracker.missingTxHashes),
|
|
289
314
|
{ description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
|
|
315
|
+
this.getAddContext(request),
|
|
290
316
|
);
|
|
291
317
|
} catch (err) {
|
|
292
318
|
this.log.error(`Error sending fast reqresp request for txs`, err, {
|
|
293
|
-
txs: [...request.missingTxHashes],
|
|
319
|
+
txs: [...request.missingTxTracker.missingTxHashes],
|
|
294
320
|
...blockInfo,
|
|
295
321
|
});
|
|
296
322
|
}
|
|
297
323
|
}
|
|
298
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
|
+
|
|
299
334
|
/**
|
|
300
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.
|
|
301
336
|
* Called internally and from the main tx collection manager whenever the tx pool emits a tx-added event.
|
|
@@ -305,22 +340,20 @@ export class FastTxCollection {
|
|
|
305
340
|
for (const tx of txs) {
|
|
306
341
|
const txHash = tx.txHash.toString();
|
|
307
342
|
// Remove the tx hash from the missing set, and add it to the found set.
|
|
308
|
-
if (request.
|
|
309
|
-
request.missingTxHashes.delete(txHash);
|
|
310
|
-
request.foundTxs.set(txHash, tx);
|
|
343
|
+
if (request.missingTxTracker.markFetched(tx)) {
|
|
311
344
|
this.log.trace(`Found tx ${txHash} for fast collection request`, {
|
|
312
345
|
...request.blockInfo,
|
|
313
346
|
txHash: tx.txHash.toString(),
|
|
314
347
|
type: request.type,
|
|
315
348
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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();
|
|
324
357
|
}
|
|
325
358
|
}
|
|
326
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
|
+
}
|
|
@@ -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
|
+
}
|