@aztec/p2p 0.0.1-commit.f295ac2 → 0.0.1-commit.fc805bf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +4 -4
- package/dest/client/factory.d.ts +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +6 -5
- package/dest/client/p2p_client.d.ts +1 -1
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +9 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +8 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -0
- 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 +2 -2
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +3 -3
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +3 -2
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +3 -2
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +8 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +41 -10
- 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/attestation_validator/fisherman_attestation_validator.js +18 -6
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +55 -31
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +3 -3
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +93 -64
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +3 -2
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +4 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +8 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +21 -11
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +3 -2
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +10 -6
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/dummy_service.d.ts +13 -1
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +39 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +2 -3
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -3
- package/dest/services/libp2p/libp2p_service.d.ts +13 -7
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +60 -51
- package/dest/services/peer-manager/metrics.d.ts +2 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +20 -5
- 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 +8 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
- package/dest/services/reqresp/interface.d.ts +5 -3
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +2 -2
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +5 -0
- 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 +16 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +18 -6
- 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 +43 -13
- package/dest/services/reqresp/reqresp.d.ts +6 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +58 -22
- package/dest/services/service.d.ts +4 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +4 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +9 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +6 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +16 -5
- 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 +9 -2
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +8 -8
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +5 -5
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +5 -5
- package/dest/test-helpers/index.d.ts +3 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +2 -0
- package/dest/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +158 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +297 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +212 -133
- package/dest/testbench/worker_client_manager.d.ts +51 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +226 -44
- package/package.json +14 -14
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +6 -10
- package/src/client/p2p_client.ts +14 -7
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +6 -1
- package/src/mem_pools/instrumentation.ts +2 -1
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +2 -2
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +2 -1
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +2 -1
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +10 -7
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
- package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +14 -8
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +31 -31
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +91 -67
- package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
- package/src/msg_validators/tx_validator/block_header_validator.ts +6 -5
- package/src/msg_validators/tx_validator/data_validator.ts +6 -2
- package/src/msg_validators/tx_validator/double_spend_validator.ts +4 -3
- package/src/msg_validators/tx_validator/factory.ts +64 -23
- package/src/msg_validators/tx_validator/gas_validator.ts +9 -3
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +6 -3
- package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +6 -3
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +45 -0
- package/src/services/encoding.ts +2 -3
- package/src/services/libp2p/instrumentation.ts +15 -2
- package/src/services/libp2p/libp2p_service.ts +99 -73
- package/src/services/peer-manager/metrics.ts +21 -4
- package/src/services/peer-manager/peer_scoring.ts +4 -1
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +16 -0
- package/src/services/reqresp/interface.ts +5 -2
- package/src/services/reqresp/metrics.ts +34 -9
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +7 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +18 -4
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +51 -9
- package/src/services/reqresp/reqresp.ts +66 -19
- package/src/services/service.ts +4 -0
- package/src/services/tx_collection/config.ts +15 -1
- package/src/services/tx_collection/fast_tx_collection.ts +36 -13
- package/src/services/tx_collection/index.ts +5 -0
- package/src/services/tx_collection/instrumentation.ts +11 -2
- package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +8 -8
- package/src/services/tx_provider.ts +2 -2
- package/src/services/tx_provider_instrumentation.ts +11 -5
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +374 -0
- package/src/testbench/p2p_client_testbench_worker.ts +321 -126
- package/src/testbench/worker_client_manager.ts +304 -47
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Request response metrics
|
|
2
|
-
import { Attributes, Metrics } from '@aztec/telemetry-client';
|
|
2
|
+
import { Attributes, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
3
3
|
import type { TelemetryClient, Tracer, UpDownCounter } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
|
+
import { ReqRespSubProtocol } from './interface.js';
|
|
6
|
+
|
|
5
7
|
export class ReqRespMetrics {
|
|
6
8
|
public readonly tracer: Tracer;
|
|
7
9
|
|
|
@@ -18,27 +20,50 @@ export class ReqRespMetrics {
|
|
|
18
20
|
this.tracer = telemetryClient.getTracer(name);
|
|
19
21
|
|
|
20
22
|
const meter = telemetryClient.getMeter(name);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const protocolAttrs = {
|
|
24
|
+
[Attributes.P2P_REQ_RESP_PROTOCOL]: [
|
|
25
|
+
ReqRespSubProtocol.PING,
|
|
26
|
+
ReqRespSubProtocol.STATUS,
|
|
27
|
+
ReqRespSubProtocol.GOODBYE,
|
|
28
|
+
ReqRespSubProtocol.TX,
|
|
29
|
+
ReqRespSubProtocol.BLOCK,
|
|
30
|
+
ReqRespSubProtocol.AUTH,
|
|
31
|
+
ReqRespSubProtocol.BLOCK_TXS,
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
this.sentRequests = createUpDownCounterWithDefault(meter, Metrics.P2P_REQ_RESP_SENT_REQUESTS, protocolAttrs);
|
|
35
|
+
this.receivedRequests = createUpDownCounterWithDefault(
|
|
36
|
+
meter,
|
|
37
|
+
Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS,
|
|
38
|
+
protocolAttrs,
|
|
39
|
+
);
|
|
23
40
|
|
|
24
|
-
this.failedOutboundRequests =
|
|
41
|
+
this.failedOutboundRequests = createUpDownCounterWithDefault(
|
|
42
|
+
meter,
|
|
43
|
+
Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS,
|
|
44
|
+
protocolAttrs,
|
|
45
|
+
);
|
|
25
46
|
|
|
26
|
-
this.failedInboundRequests =
|
|
47
|
+
this.failedInboundRequests = createUpDownCounterWithDefault(
|
|
48
|
+
meter,
|
|
49
|
+
Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS,
|
|
50
|
+
protocolAttrs,
|
|
51
|
+
);
|
|
27
52
|
}
|
|
28
53
|
|
|
29
|
-
public recordRequestSent(protocol:
|
|
54
|
+
public recordRequestSent(protocol: ReqRespSubProtocol) {
|
|
30
55
|
this.sentRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
31
56
|
}
|
|
32
57
|
|
|
33
|
-
public recordRequestReceived(protocol:
|
|
58
|
+
public recordRequestReceived(protocol: ReqRespSubProtocol) {
|
|
34
59
|
this.receivedRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
35
60
|
}
|
|
36
61
|
|
|
37
|
-
public recordRequestError(protocol:
|
|
62
|
+
public recordRequestError(protocol: ReqRespSubProtocol) {
|
|
38
63
|
this.failedOutboundRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
39
64
|
}
|
|
40
65
|
|
|
41
|
-
public recordResponseError(protocol:
|
|
66
|
+
public recordResponseError(protocol: ReqRespSubProtocol) {
|
|
42
67
|
this.failedInboundRequests.add(1, { [Attributes.P2P_REQ_RESP_PROTOCOL]: protocol });
|
|
43
68
|
}
|
|
44
69
|
}
|
|
@@ -64,6 +64,13 @@ export class BitVector {
|
|
|
64
64
|
return Array.from({ length: this.length }, (_, i) => i).filter(i => this.isSet(i));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Returns true if no indices are set to true
|
|
69
|
+
* */
|
|
70
|
+
isEmpty(): boolean {
|
|
71
|
+
return this.getTrueIndices().length === 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
/**
|
|
68
75
|
* Serializes the BitVector object into a Buffer
|
|
69
76
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import { TxArray } from '@aztec/stdlib/tx';
|
|
2
3
|
|
|
3
4
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -30,8 +31,22 @@ export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool:
|
|
|
30
31
|
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
const blockProposal = await attestationPool.getBlockProposal(request.
|
|
34
|
+
const blockProposal = await attestationPool.getBlockProposal(request.archiveRoot.toString());
|
|
34
35
|
|
|
36
|
+
let requestedTxsHashes;
|
|
37
|
+
if (request.txHashes.length > 0) {
|
|
38
|
+
requestedTxsHashes = request.txHashes;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// This is scenario in which we don't have this block proposal the peer is requesting from us
|
|
42
|
+
// But peer has sent requested tx hashes, so we can send them the transactions
|
|
43
|
+
if (!blockProposal && requestedTxsHashes !== undefined) {
|
|
44
|
+
const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
|
|
45
|
+
const response = new BlockTxsResponse(Fr.zero(), new TxArray(...responseTxs), BitVector.init(0, []));
|
|
46
|
+
return response.toBuffer();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If don't have this block proposal and peer has not sent requested tx hashes
|
|
35
50
|
if (!blockProposal) {
|
|
36
51
|
throw new ReqRespStatusError(ReqRespStatus.NOT_FOUND);
|
|
37
52
|
}
|
|
@@ -42,11 +57,10 @@ export function reqRespBlockTxsHandler(attestationPool: AttestationPool, txPool:
|
|
|
42
57
|
const responseBitVector = BitVector.init(blockProposal.txHashes.length, availableIndices);
|
|
43
58
|
|
|
44
59
|
const requestedIndices = new Set(request.txIndices.getTrueIndices());
|
|
45
|
-
|
|
60
|
+
requestedTxsHashes = blockProposal.txHashes.filter((_, idx) => requestedIndices.has(idx));
|
|
46
61
|
|
|
47
62
|
const responseTxs = (await txPool.getTxsByHash(requestedTxsHashes)).filter(tx => !!tx);
|
|
48
|
-
|
|
49
|
-
const response = new BlockTxsResponse(request.blockHash, new TxArray(...responseTxs), responseBitVector);
|
|
63
|
+
const response = new BlockTxsResponse(request.archiveRoot, new TxArray(...responseTxs), responseBitVector);
|
|
50
64
|
|
|
51
65
|
return response.toBuffer();
|
|
52
66
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
-
import {
|
|
3
|
+
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
4
|
+
import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
4
5
|
|
|
5
6
|
import { BitVector } from './bitvector.js';
|
|
6
7
|
|
|
@@ -9,12 +10,52 @@ import { BitVector } from './bitvector.js';
|
|
|
9
10
|
*/
|
|
10
11
|
export class BlockTxsRequest {
|
|
11
12
|
constructor(
|
|
12
|
-
|
|
13
|
+
// Archive root after the proposed block is applied (proposal identifier)
|
|
14
|
+
readonly archiveRoot: Fr,
|
|
15
|
+
// Hashes of txs we are requesting
|
|
16
|
+
readonly txHashes: TxHashArray,
|
|
13
17
|
// BitVector indicating which txs from the proposal we are requesting
|
|
14
18
|
// 1 means we want the tx, 0 means we don't
|
|
19
|
+
// If we know peer has the Block Proposal then we can use this BitVector
|
|
20
|
+
// Otherwise we can use this optimization
|
|
15
21
|
readonly txIndices: BitVector,
|
|
16
22
|
) {}
|
|
17
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Creates new BlockTxsRequest given proposal and missing tx hashes
|
|
26
|
+
*
|
|
27
|
+
* @param: blockProposal - The block proposal for which we are making request
|
|
28
|
+
* @param: missingTxHashes - Tx hashes from the proposal we are missing
|
|
29
|
+
* @param: includeFullTxHashes - Whether to include full list of missing tx hashes in the request or just Bitvector indices
|
|
30
|
+
*
|
|
31
|
+
* @returns undefined if there were no missingTxHashes matching BlockProposal hashes, otherwise
|
|
32
|
+
* returns new BlockTxsRequest*/
|
|
33
|
+
static fromBlockProposalAndMissingTxs(
|
|
34
|
+
blockProposal: BlockProposal,
|
|
35
|
+
missingTxHashes: TxHash[],
|
|
36
|
+
includeFullTxHashes = false,
|
|
37
|
+
): BlockTxsRequest | undefined {
|
|
38
|
+
if (missingTxHashes.length === 0) {
|
|
39
|
+
return undefined; // No missing txs to request
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const missingHashesSet = new Set(missingTxHashes.map(t => t.toString()));
|
|
43
|
+
|
|
44
|
+
// We cannot request txs that are not part of the block proposal
|
|
45
|
+
if (!missingHashesSet.isSubsetOf(new Set(blockProposal.txHashes.map(t => t.toString())))) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const missingIndices = blockProposal.txHashes
|
|
50
|
+
.map((hash, idx) => (missingHashesSet.has(hash.toString()) ? idx : -1))
|
|
51
|
+
.filter(i => i != -1);
|
|
52
|
+
|
|
53
|
+
const requestBitVector = BitVector.init(blockProposal.txHashes.length, missingIndices);
|
|
54
|
+
const hashes = includeFullTxHashes ? new TxHashArray(...missingTxHashes) : new TxHashArray();
|
|
55
|
+
|
|
56
|
+
return new BlockTxsRequest(blockProposal.archive, hashes, requestBitVector);
|
|
57
|
+
}
|
|
58
|
+
|
|
18
59
|
/**
|
|
19
60
|
* Deserializes the BlockTxRequest object from a Buffer
|
|
20
61
|
* @param buffer - Buffer or BufferReader object to deserialize
|
|
@@ -22,10 +63,11 @@ export class BlockTxsRequest {
|
|
|
22
63
|
*/
|
|
23
64
|
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsRequest {
|
|
24
65
|
const reader = BufferReader.asReader(buffer);
|
|
25
|
-
const
|
|
66
|
+
const archiveRoot = Fr.fromBuffer(reader);
|
|
67
|
+
const txHashes = TxHashArray.fromBuffer(reader);
|
|
26
68
|
const txIndices = BitVector.fromBuffer(reader);
|
|
27
69
|
|
|
28
|
-
return new BlockTxsRequest(
|
|
70
|
+
return new BlockTxsRequest(archiveRoot, txHashes, txIndices);
|
|
29
71
|
}
|
|
30
72
|
|
|
31
73
|
/**
|
|
@@ -33,7 +75,7 @@ export class BlockTxsRequest {
|
|
|
33
75
|
* @returns Buffer representation of the BlockTxRequest object
|
|
34
76
|
*/
|
|
35
77
|
toBuffer(): Buffer {
|
|
36
|
-
return serializeToBuffer([this.
|
|
78
|
+
return serializeToBuffer([this.archiveRoot, this.txHashes.toBuffer(), this.txIndices.toBuffer()]);
|
|
37
79
|
}
|
|
38
80
|
}
|
|
39
81
|
|
|
@@ -42,7 +84,7 @@ export class BlockTxsRequest {
|
|
|
42
84
|
*/
|
|
43
85
|
export class BlockTxsResponse {
|
|
44
86
|
constructor(
|
|
45
|
-
readonly
|
|
87
|
+
readonly archiveRoot: Fr,
|
|
46
88
|
readonly txs: TxArray, // List of transactions we requested and peer has
|
|
47
89
|
// BitVector indicating which txs from the proposal are available at the peer
|
|
48
90
|
// 1 means the tx is available, 0 means it is not
|
|
@@ -56,11 +98,11 @@ export class BlockTxsResponse {
|
|
|
56
98
|
*/
|
|
57
99
|
static fromBuffer(buffer: Buffer | BufferReader): BlockTxsResponse {
|
|
58
100
|
const reader = BufferReader.asReader(buffer);
|
|
59
|
-
const
|
|
101
|
+
const archiveRoot = Fr.fromBuffer(reader);
|
|
60
102
|
const txs = TxArray.fromBuffer(reader);
|
|
61
103
|
const txIndices = BitVector.fromBuffer(reader);
|
|
62
104
|
|
|
63
|
-
return new BlockTxsResponse(
|
|
105
|
+
return new BlockTxsResponse(archiveRoot, txs, txIndices);
|
|
64
106
|
}
|
|
65
107
|
|
|
66
108
|
/**
|
|
@@ -70,7 +112,7 @@ export class BlockTxsResponse {
|
|
|
70
112
|
* @returns Buffer representation of the BlockTxResponse object
|
|
71
113
|
*/
|
|
72
114
|
toBuffer(): Buffer {
|
|
73
|
-
return serializeToBuffer([this.
|
|
115
|
+
return serializeToBuffer([this.archiveRoot, this.txs.toBuffer(), this.txIndices.toBuffer()]);
|
|
74
116
|
}
|
|
75
117
|
|
|
76
118
|
static empty(): BlockTxsResponse {
|
|
@@ -111,6 +111,13 @@ export class ReqResp implements ReqRespInterface {
|
|
|
111
111
|
return this.metrics.tracer;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Get the connection sampler instance
|
|
116
|
+
*/
|
|
117
|
+
getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'> {
|
|
118
|
+
return this.connectionSampler;
|
|
119
|
+
}
|
|
120
|
+
|
|
114
121
|
/**
|
|
115
122
|
* Start the reqresp service
|
|
116
123
|
*/
|
|
@@ -212,6 +219,14 @@ export class ReqResp implements ReqRespInterface {
|
|
|
212
219
|
const responseValidator = this.subProtocolValidators[subProtocol] ?? DEFAULT_SUB_PROTOCOL_VALIDATORS[subProtocol];
|
|
213
220
|
const responses: InstanceType<SubProtocolMap[SubProtocol]['response']>[] = new Array(requests.length);
|
|
214
221
|
const requestBuffers = requests.map(req => req.toBuffer());
|
|
222
|
+
const isEmptyResponse = (value: unknown): boolean => {
|
|
223
|
+
// Some responses serialize to a non-empty buffer even when they contain no items (e.g., empty TxArray).
|
|
224
|
+
if (!value || typeof value !== 'object') {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const length = (value as { length?: number }).length;
|
|
228
|
+
return typeof length === 'number' && length === 0;
|
|
229
|
+
};
|
|
215
230
|
|
|
216
231
|
const requestFunction = async (signal: AbortSignal) => {
|
|
217
232
|
// Track which requests still need to be processed
|
|
@@ -252,7 +267,9 @@ export class ReqResp implements ReqRespInterface {
|
|
|
252
267
|
for (const requestIndex of pendingRequestIndices) {
|
|
253
268
|
const peer = batchSampler.getPeerForRequest(requestIndex);
|
|
254
269
|
if (!peer) {
|
|
255
|
-
|
|
270
|
+
// No peer available for this specific index (all peers exhausted for it)
|
|
271
|
+
// Skip this index for now - it stays in pendingRequestIndices for retry
|
|
272
|
+
continue;
|
|
256
273
|
}
|
|
257
274
|
const peerAsString = peer.toString();
|
|
258
275
|
if (!requestBatches.has(peerAsString)) {
|
|
@@ -271,6 +288,12 @@ export class ReqResp implements ReqRespInterface {
|
|
|
271
288
|
});
|
|
272
289
|
}
|
|
273
290
|
|
|
291
|
+
// If no requests could be assigned (all peers exhausted for all indices), exit early
|
|
292
|
+
if (requestBatches.size === 0) {
|
|
293
|
+
this.logger.warn('No peers available for any pending request indices, stopping batch request');
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
|
|
274
297
|
// Make parallel requests for each peer's batch
|
|
275
298
|
// A batch entry will look something like this:
|
|
276
299
|
// PeerId0: [0, 1, 2, 3]
|
|
@@ -282,38 +305,61 @@ export class ReqResp implements ReqRespInterface {
|
|
|
282
305
|
const batchResults = await Promise.all(
|
|
283
306
|
Array.from(requestBatches.entries()).map(async ([peerAsString, { peerId: peer, indices }]) => {
|
|
284
307
|
try {
|
|
308
|
+
const markIndexFailed = (index: number) => batchSampler.markPeerFailedForIndex(peer, index);
|
|
285
309
|
// Requests all going to the same peer are sent synchronously
|
|
286
310
|
const peerResults: { index: number; response: InstanceType<SubProtocolMap[SubProtocol]['response']> }[] =
|
|
287
311
|
[];
|
|
312
|
+
let shouldReplacePeer = false;
|
|
313
|
+
const handleFailure = (status: ReqRespStatus, index: number) => {
|
|
314
|
+
this.logger.warn(
|
|
315
|
+
`Request to peer ${peerAsString} failed with status ${prettyPrintReqRespStatus(status)}`,
|
|
316
|
+
);
|
|
317
|
+
markIndexFailed(index);
|
|
318
|
+
return status === ReqRespStatus.RATE_LIMIT_EXCEEDED;
|
|
319
|
+
};
|
|
320
|
+
|
|
288
321
|
for (const index of indices) {
|
|
289
|
-
this.logger.
|
|
322
|
+
this.logger.info(`Sending request ${index} to peer ${peerAsString}`);
|
|
290
323
|
const response = await this.sendRequestToPeer(peer, subProtocol, requestBuffers[index]);
|
|
291
324
|
|
|
292
325
|
// Check the status of the response buffer
|
|
293
326
|
if (response.status !== ReqRespStatus.SUCCESS) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
// they will be split among remaining peers and the new sampled peer
|
|
300
|
-
batchSampler.removePeerAndReplace(peer);
|
|
301
|
-
return { peer, results: peerResults };
|
|
327
|
+
shouldReplacePeer = handleFailure(response.status, index);
|
|
328
|
+
if (shouldReplacePeer) {
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
continue;
|
|
302
332
|
}
|
|
303
333
|
|
|
304
|
-
if (response
|
|
305
|
-
|
|
306
|
-
|
|
334
|
+
if (response.data.length === 0) {
|
|
335
|
+
markIndexFailed(index);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
307
338
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
339
|
+
const object = responseFromBuffer(subProtocol, response.data);
|
|
340
|
+
if (isEmptyResponse(object)) {
|
|
341
|
+
markIndexFailed(index);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const isValid = await responseValidator(requests[index], object, peer);
|
|
346
|
+
if (!isValid) {
|
|
347
|
+
markIndexFailed(index);
|
|
348
|
+
continue;
|
|
311
349
|
}
|
|
350
|
+
|
|
351
|
+
peerResults.push({ index, response: object });
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// If peer had a hard failure (rate limit), replace it for future iterations
|
|
355
|
+
if (shouldReplacePeer) {
|
|
356
|
+
this.logger.warn(`Peer ${peerAsString} hit a hard failure, removing from sampler`);
|
|
357
|
+
batchSampler.removePeerAndReplace(peer);
|
|
312
358
|
}
|
|
313
359
|
|
|
314
360
|
return { peer, results: peerResults };
|
|
315
361
|
} catch (error) {
|
|
316
|
-
this.logger.
|
|
362
|
+
this.logger.warn(`Failed batch request to peer ${peerAsString}:`, error);
|
|
317
363
|
batchSampler.removePeerAndReplace(peer);
|
|
318
364
|
return { peer, results: [] };
|
|
319
365
|
}
|
|
@@ -334,7 +380,7 @@ export class ReqResp implements ReqRespInterface {
|
|
|
334
380
|
}
|
|
335
381
|
|
|
336
382
|
if (retryAttempts >= maxRetryAttempts) {
|
|
337
|
-
this.logger.
|
|
383
|
+
this.logger.warn(`Max retry attempts ${maxRetryAttempts} reached for batch request`);
|
|
338
384
|
}
|
|
339
385
|
|
|
340
386
|
return responses;
|
|
@@ -347,7 +393,7 @@ export class ReqResp implements ReqRespInterface {
|
|
|
347
393
|
() => new CollectiveReqRespTimeoutError(),
|
|
348
394
|
);
|
|
349
395
|
} catch (e: any) {
|
|
350
|
-
this.logger.
|
|
396
|
+
this.logger.warn(`${e.message} | subProtocol: ${subProtocol}`);
|
|
351
397
|
return [];
|
|
352
398
|
}
|
|
353
399
|
}
|
|
@@ -409,6 +455,7 @@ export class ReqResp implements ReqRespInterface {
|
|
|
409
455
|
);
|
|
410
456
|
return resp;
|
|
411
457
|
} catch (e: any) {
|
|
458
|
+
this.logger.warn(`SUBPROTOCOL: ${subProtocol}\n`, e);
|
|
412
459
|
// On error we immediately abort the stream, this is preferred way,
|
|
413
460
|
// because it signals to the sender that error happened, whereas
|
|
414
461
|
// closing the stream only closes our side and is much slower
|
package/src/services/service.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
7
7
|
import type { ENR } from '@nethermindeth/enr';
|
|
8
8
|
import type EventEmitter from 'events';
|
|
9
9
|
|
|
10
|
+
import type { BatchTxRequesterLibP2PService } from './reqresp/batch-tx-requester/interface.js';
|
|
10
11
|
import type { P2PReqRespConfig } from './reqresp/config.js';
|
|
11
12
|
import type { StatusMessage } from './reqresp/index.js';
|
|
12
13
|
import type {
|
|
@@ -103,6 +104,9 @@ export interface P2PService {
|
|
|
103
104
|
|
|
104
105
|
/** If node running this P2P stack is validator, passes in validator address to P2P layer */
|
|
105
106
|
registerThisValidatorAddresses(address: EthAddress[]): void;
|
|
107
|
+
|
|
108
|
+
/** Get BatchTxRequester service dependencies */
|
|
109
|
+
getBatchTxRequesterService(): BatchTxRequesterLibP2PService;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
/**
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type ConfigMappingsType,
|
|
3
|
+
booleanConfigHelper,
|
|
4
|
+
enumConfigHelper,
|
|
5
|
+
numberConfigHelper,
|
|
6
|
+
} from '@aztec/foundation/config';
|
|
2
7
|
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/api-limit';
|
|
3
8
|
|
|
9
|
+
export type ProposalTxCollectorType = 'new' | 'old';
|
|
10
|
+
|
|
4
11
|
export type TxCollectionConfig = {
|
|
5
12
|
/** How long to wait before starting reqresp for fast collection */
|
|
6
13
|
txCollectionFastNodesTimeoutBeforeReqRespMs: number;
|
|
@@ -22,6 +29,8 @@ export type TxCollectionConfig = {
|
|
|
22
29
|
txCollectionFastMaxParallelRequestsPerNode: number;
|
|
23
30
|
/** Maximum number of transactions to request from a node in a single batch */
|
|
24
31
|
txCollectionNodeRpcMaxBatchSize: number;
|
|
32
|
+
/** Which collector implementation to use for proposal tx collection */
|
|
33
|
+
txCollectionProposalTxCollectorType: ProposalTxCollectorType;
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig> = {
|
|
@@ -81,4 +90,9 @@ export const txCollectionConfigMappings: ConfigMappingsType<TxCollectionConfig>
|
|
|
81
90
|
description: 'Maximum number of transactions to request from a node in a single batch',
|
|
82
91
|
...numberConfigHelper(MAX_RPC_TXS_LEN),
|
|
83
92
|
},
|
|
93
|
+
txCollectionProposalTxCollectorType: {
|
|
94
|
+
env: 'TX_COLLECTION_PROPOSAL_TX_COLLECTOR_TYPE',
|
|
95
|
+
description: 'Which collector implementation to use for proposal tx collection (new or old)',
|
|
96
|
+
...enumConfigHelper(['new', 'old'] as const, 'new'),
|
|
97
|
+
},
|
|
84
98
|
};
|
|
@@ -12,9 +12,16 @@ import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
|
12
12
|
|
|
13
13
|
import type { PeerId } from '@libp2p/interface';
|
|
14
14
|
|
|
15
|
-
import
|
|
15
|
+
import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
|
|
16
|
+
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
17
|
+
import { ReqRespSubProtocol } from '../reqresp/interface.js';
|
|
16
18
|
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
17
19
|
import type { TxCollectionConfig } from './config.js';
|
|
20
|
+
import {
|
|
21
|
+
BatchTxRequesterCollector,
|
|
22
|
+
type ProposalTxCollector,
|
|
23
|
+
SendBatchRequestCollector,
|
|
24
|
+
} from './proposal_tx_collector.js';
|
|
18
25
|
import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
|
|
19
26
|
import type { TxCollectionSink } from './tx_collection_sink.js';
|
|
20
27
|
import type { TxSource } from './tx_source.js';
|
|
@@ -22,15 +29,25 @@ import type { TxSource } from './tx_source.js';
|
|
|
22
29
|
export class FastTxCollection {
|
|
23
30
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
24
31
|
protected requests: Set<FastCollectionRequest> = new Set();
|
|
32
|
+
private proposalTxCollector: ProposalTxCollector;
|
|
25
33
|
|
|
26
34
|
constructor(
|
|
27
|
-
private
|
|
35
|
+
private p2pService: BatchTxRequesterLibP2PService,
|
|
28
36
|
private nodes: TxSource[],
|
|
29
37
|
private txCollectionSink: TxCollectionSink,
|
|
30
38
|
private config: TxCollectionConfig,
|
|
31
39
|
private dateProvider: DateProvider = new DateProvider(),
|
|
32
40
|
private log: Logger = createLogger('p2p:tx_collection_service'),
|
|
33
|
-
|
|
41
|
+
proposalTxCollector?: ProposalTxCollector,
|
|
42
|
+
) {
|
|
43
|
+
const batchTxRequesterConfig = this.config as Partial<BatchTxRequesterConfig>;
|
|
44
|
+
const proposalCollectorType = this.config.txCollectionProposalTxCollectorType;
|
|
45
|
+
this.proposalTxCollector =
|
|
46
|
+
proposalTxCollector ??
|
|
47
|
+
(proposalCollectorType === 'old'
|
|
48
|
+
? new SendBatchRequestCollector(p2pService)
|
|
49
|
+
: new BatchTxRequesterCollector(p2pService, log, dateProvider, undefined, batchTxRequesterConfig));
|
|
50
|
+
}
|
|
34
51
|
|
|
35
52
|
public async stop() {
|
|
36
53
|
this.requests.forEach(request => request.promise.reject(new AbortError(`Stopped collection service`)));
|
|
@@ -261,16 +278,22 @@ export class FastTxCollection {
|
|
|
261
278
|
try {
|
|
262
279
|
await this.txCollectionSink.collect(
|
|
263
280
|
async txHashes => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
281
|
+
if (request.type === 'proposal') {
|
|
282
|
+
return await this.proposalTxCollector.collectTxs(txHashes, request.blockProposal, pinnedPeer, timeoutMs);
|
|
283
|
+
} else if (request.type === 'block') {
|
|
284
|
+
const txs = await this.p2pService.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
285
|
+
ReqRespSubProtocol.TX,
|
|
286
|
+
chunkTxHashesRequest(txHashes),
|
|
287
|
+
pinnedPeer,
|
|
288
|
+
timeoutMs,
|
|
289
|
+
maxPeers,
|
|
290
|
+
maxRetryAttempts,
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
return txs.flat();
|
|
294
|
+
} else {
|
|
295
|
+
throw new Error(`Unknown request type: ${(request as any).type}`);
|
|
296
|
+
}
|
|
274
297
|
},
|
|
275
298
|
Array.from(request.missingTxHashes).map(txHash => TxHash.fromString(txHash)),
|
|
276
299
|
{ description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export { TxCollection, type FastCollectionRequestInput } from './tx_collection.js';
|
|
2
2
|
export { type TxSource, createNodeRpcTxSources, NodeRpcTxSource } from './tx_source.js';
|
|
3
|
+
export {
|
|
4
|
+
type ProposalTxCollector,
|
|
5
|
+
BatchTxRequesterCollector,
|
|
6
|
+
SendBatchRequestCollector,
|
|
7
|
+
} from './proposal_tx_collector.js';
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Attributes,
|
|
3
|
+
type Histogram,
|
|
4
|
+
Metrics,
|
|
5
|
+
type TelemetryClient,
|
|
6
|
+
type UpDownCounter,
|
|
7
|
+
createUpDownCounterWithDefault,
|
|
8
|
+
} from '@aztec/telemetry-client';
|
|
2
9
|
|
|
3
10
|
import type { CollectionMethod } from './tx_collection.js';
|
|
4
11
|
|
|
@@ -10,7 +17,9 @@ export class TxCollectionInstrumentation {
|
|
|
10
17
|
constructor(client: TelemetryClient, name: string) {
|
|
11
18
|
const meter = client.getMeter(name);
|
|
12
19
|
|
|
13
|
-
this.txsCollected = meter
|
|
20
|
+
this.txsCollected = createUpDownCounterWithDefault(meter, Metrics.TX_COLLECTOR_COUNT, {
|
|
21
|
+
[Attributes.TX_COLLECTION_METHOD]: ['fast-req-resp', 'fast-node-rpc', 'slow-req-resp', 'slow-node-rpc'],
|
|
22
|
+
});
|
|
14
23
|
|
|
15
24
|
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
|
|
16
25
|
|