@aztec/p2p 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +9 -1
- package/dest/client/factory.d.ts +3 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +12 -9
- package/dest/client/interface.d.ts +6 -4
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +11 -8
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +53 -17
- package/dest/config.d.ts +43 -17
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +48 -8
- package/dest/errors/reqresp.error.d.ts +1 -20
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +0 -21
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +93 -55
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +258 -195
- 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 +175 -59
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +6 -4
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +17 -1
- 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/tx_pool_v2_impl.d.ts +1 -1
- 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 +73 -83
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +18 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -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 +3 -4
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +13 -11
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +5 -2
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +5 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +8 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +28 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +8 -15
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +3 -3
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/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 +1 -0
- package/dest/msg_validators/tx_validator/factory.d.ts +5 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +11 -7
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- 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/discv5/discV5_service.d.ts +2 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +35 -8
- package/dest/services/dummy_service.d.ts +10 -17
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +9 -18
- package/dest/services/libp2p/libp2p_service.d.ts +19 -21
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +147 -148
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -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 +35 -44
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +8 -5
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- 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/interface.d.ts +3 -10
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +0 -9
- 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/reqresp.d.ts +5 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +16 -206
- package/dest/services/service.d.ts +7 -13
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +2 -23
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +2 -55
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +12 -28
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +43 -83
- 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.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +0 -2
- package/dest/services/tx_collection/tx_collection.d.ts +35 -51
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +275 -119
- package/dest/services/tx_collection/tx_collection_sink.d.ts +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +2 -2
- package/dest/services/tx_file_store/tx_file_store.d.ts +1 -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 +4 -14
- package/dest/services/tx_provider.d.ts +3 -1
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +3 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +13 -7
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +12 -37
- package/dest/test-helpers/reqresp-nodes.d.ts +4 -5
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +11 -15
- 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 +12 -14
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +19 -14
- 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 +13 -24
- package/dest/testbench/worker_client_manager.d.ts +3 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +2 -8
- package/dest/util.d.ts +11 -6
- 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 +15 -14
- package/src/bootstrap/bootstrap.ts +9 -1
- package/src/client/factory.ts +20 -5
- package/src/client/interface.ts +6 -10
- package/src/client/p2p_client.ts +61 -36
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +94 -6
- package/src/errors/reqresp.error.ts +0 -25
- package/src/mem_pools/attestation_pool/attestation_pool.ts +309 -238
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +198 -62
- package/src/mem_pools/attestation_pool/mocks.ts +13 -8
- package/src/mem_pools/instrumentation.ts +5 -1
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +73 -90
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -1
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +11 -7
- package/src/msg_validators/clock_tolerance.ts +13 -12
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +9 -2
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +14 -2
- package/src/msg_validators/proposal_validator/proposal_validator.ts +39 -2
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -12
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +3 -3
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/data_validator.ts +2 -0
- package/src/msg_validators/tx_validator/factory.ts +15 -6
- package/src/msg_validators/tx_validator/index.ts +2 -0
- 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/discv5/discV5_service.ts +38 -5
- package/src/services/dummy_service.ts +12 -43
- package/src/services/libp2p/libp2p_service.ts +169 -167
- package/src/services/peer-manager/peer_manager.ts +1 -0
- package/src/services/reqresp/README.md +0 -14
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +39 -52
- package/src/services/reqresp/batch-tx-requester/interface.ts +11 -4
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
- package/src/services/reqresp/interface.ts +2 -38
- 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/reqresp.ts +11 -251
- package/src/services/service.ts +9 -30
- package/src/services/tx_collection/config.ts +3 -80
- package/src/services/tx_collection/file_store_tx_collection.ts +54 -103
- package/src/services/tx_collection/index.ts +1 -6
- package/src/services/tx_collection/instrumentation.ts +1 -7
- package/src/services/tx_collection/tx_collection.ts +330 -173
- package/src/services/tx_collection/tx_collection_sink.ts +2 -2
- package/src/services/tx_file_store/tx_file_store.ts +5 -17
- package/src/services/tx_provider.ts +5 -0
- package/src/test-helpers/make-test-p2p-clients.ts +1 -0
- package/src/test-helpers/mock-pubsub.ts +17 -60
- package/src/test-helpers/reqresp-nodes.ts +8 -20
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +23 -27
- package/src/testbench/p2p_client_testbench_worker.ts +16 -42
- package/src/testbench/worker_client_manager.ts +4 -19
- package/src/util.ts +32 -17
- 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 -318
- 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/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/tx_collection/fast_tx_collection.d.ts +0 -51
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -311
- 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 -50
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -57
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -211
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -357
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
- package/src/services/tx_collection/fast_tx_collection.ts +0 -361
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -108
- package/src/services/tx_collection/slow_tx_collection.ts +0 -266
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { times } from '@aztec/foundation/collection';
|
|
1
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
3
3
|
import { sleep } from '@aztec/foundation/sleep';
|
|
4
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import {
|
|
5
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
7
|
import type { FileStoreTxSource } from './file_store_tx_source.js';
|
|
8
|
+
import type { IRequestTracker } from './request_tracker.js';
|
|
8
9
|
import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
9
10
|
|
|
10
11
|
/** Configuration for a FileStoreTxCollection instance. */
|
|
@@ -16,8 +17,6 @@ export type FileStoreCollectionConfig = {
|
|
|
16
17
|
|
|
17
18
|
type FileStoreTxEntry = {
|
|
18
19
|
txHash: string;
|
|
19
|
-
context: TxAddContext;
|
|
20
|
-
deadline: Date;
|
|
21
20
|
attempts: number;
|
|
22
21
|
lastAttemptTime: number;
|
|
23
22
|
nextSourceIndex: number;
|
|
@@ -25,96 +24,60 @@ type FileStoreTxEntry = {
|
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Collects txs from file stores as a fallback after P2P methods have been tried.
|
|
28
|
-
*
|
|
29
|
-
* retries with round-robin across sources, and applies exponential
|
|
30
|
-
* full cycles through all sources.
|
|
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.
|
|
31
31
|
*/
|
|
32
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
33
|
constructor(
|
|
46
34
|
private readonly sources: FileStoreTxSource[],
|
|
47
35
|
private readonly txCollectionSink: TxCollectionSink,
|
|
48
36
|
private readonly config: FileStoreCollectionConfig,
|
|
49
37
|
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
50
38
|
private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
|
|
51
|
-
) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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()) {
|
|
39
|
+
) {}
|
|
40
|
+
|
|
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()) {
|
|
82
47
|
return;
|
|
83
48
|
}
|
|
84
49
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
nextSourceIndex: Math.floor(Math.random() * this.sources.length),
|
|
95
|
-
});
|
|
96
|
-
}
|
|
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
|
+
});
|
|
97
59
|
}
|
|
98
|
-
this.wake();
|
|
99
|
-
}
|
|
100
60
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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()) {
|
|
65
|
+
return;
|
|
105
66
|
}
|
|
106
|
-
}
|
|
107
67
|
|
|
108
|
-
|
|
109
|
-
public clearPending(): void {
|
|
110
|
-
this.entries.clear();
|
|
68
|
+
await Promise.allSettled(times(this.config.workerCount, () => this.workerLoop(entries, requestTracker, context)));
|
|
111
69
|
}
|
|
112
70
|
|
|
113
|
-
private async workerLoop(
|
|
114
|
-
|
|
115
|
-
|
|
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);
|
|
116
79
|
if (action.type === 'sleep') {
|
|
117
|
-
await action.
|
|
80
|
+
await Promise.race([sleep(action.ms), requestTracker.cancellationToken]);
|
|
118
81
|
continue;
|
|
119
82
|
}
|
|
120
83
|
|
|
@@ -133,10 +96,10 @@ export class FileStoreTxCollection {
|
|
|
133
96
|
method: 'file-store',
|
|
134
97
|
fileStore: source.getInfo(),
|
|
135
98
|
},
|
|
136
|
-
|
|
99
|
+
context,
|
|
137
100
|
);
|
|
138
101
|
if (result.txs.length > 0) {
|
|
139
|
-
|
|
102
|
+
entries.delete(entry);
|
|
140
103
|
}
|
|
141
104
|
} catch (err) {
|
|
142
105
|
this.log.trace(`Error downloading tx ${entry.txHash} from ${source.getInfo()}`, { err });
|
|
@@ -144,15 +107,20 @@ export class FileStoreTxCollection {
|
|
|
144
107
|
}
|
|
145
108
|
}
|
|
146
109
|
|
|
147
|
-
/** Single-pass scan: removes
|
|
148
|
-
private getNextAction(
|
|
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 } {
|
|
149
116
|
const now = this.dateProvider.now();
|
|
150
117
|
let best: FileStoreTxEntry | undefined;
|
|
151
118
|
let earliestReadyAt = Infinity;
|
|
152
119
|
|
|
153
|
-
for (const
|
|
154
|
-
|
|
155
|
-
|
|
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);
|
|
156
124
|
continue;
|
|
157
125
|
}
|
|
158
126
|
const backoffMs = this.getBackoffMs(entry);
|
|
@@ -169,10 +137,9 @@ export class FileStoreTxCollection {
|
|
|
169
137
|
if (best) {
|
|
170
138
|
return { type: 'process', entry: best };
|
|
171
139
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
return { type: 'sleep', promise: this.waitForWake() };
|
|
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 };
|
|
176
143
|
}
|
|
177
144
|
|
|
178
145
|
/** Computes backoff for an entry. Backoff applies after a full cycle through all sources. */
|
|
@@ -183,20 +150,4 @@ export class FileStoreTxCollection {
|
|
|
183
150
|
}
|
|
184
151
|
return Math.min(this.config.backoffBaseMs * Math.pow(2, fullCycles - 1), this.config.backoffMaxMs);
|
|
185
152
|
}
|
|
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
153
|
}
|
|
@@ -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,13 +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]: [
|
|
22
|
-
'fast-req-resp',
|
|
23
|
-
'fast-node-rpc',
|
|
24
|
-
'slow-req-resp',
|
|
25
|
-
'slow-node-rpc',
|
|
26
|
-
'file-store',
|
|
27
|
-
],
|
|
21
|
+
[Attributes.TX_COLLECTION_METHOD]: ['fast-req-resp', 'fast-node-rpc', 'file-store'],
|
|
28
22
|
});
|
|
29
23
|
|
|
30
24
|
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
|