@aztec/p2p 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8
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 +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +1 -0
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +3 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +30 -8
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
- package/dest/config.d.ts +107 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -12
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +16 -9
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +5 -6
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +6 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- 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 +26 -43
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +1 -1
- 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 +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +2 -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 +18 -1
- 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 +20 -11
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
- package/dest/msg_validators/clock_tolerance.d.ts +12 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +54 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
- 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 +2 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +19 -11
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +11 -9
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/dummy_service.d.ts +6 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +6 -1
- package/dest/services/gossipsub/topic_score_params.d.ts +13 -2
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +21 -4
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +15 -25
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +150 -115
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +39 -11
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -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 +82 -101
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +14 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -11
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
- package/dest/services/reqresp/reqresp.d.ts +4 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +13 -3
- package/dest/services/service.d.ts +5 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +57 -73
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.js +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +3 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- 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/mock-pubsub.d.ts +11 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +35 -10
- 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 +1 -2
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +21 -2
- package/dest/testbench/p2p_client_testbench_worker.js +66 -15
- package/dest/testbench/worker_client_manager.d.ts +8 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +51 -2
- package/dest/util.d.ts +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +2 -1
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +34 -9
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
- package/src/config.ts +29 -17
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +17 -12
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +7 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +12 -6
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +3 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +19 -1
- package/src/msg_validators/attestation_validator/README.md +1 -1
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
- package/src/msg_validators/clock_tolerance.ts +72 -3
- package/src/msg_validators/proposal_validator/README.md +4 -4
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +4 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +17 -10
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/gas_validator.ts +25 -9
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +8 -2
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +146 -130
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +45 -11
- package/src/services/peer-manager/peer_scoring.ts +27 -5
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +78 -111
- package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/config.ts +2 -2
- package/src/services/reqresp/interface.ts +21 -11
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +21 -2
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +1 -1
- package/src/services/tx_collection/tx_collection.ts +3 -5
- package/src/test-helpers/make-test-p2p-clients.ts +1 -1
- package/src/test-helpers/mock-pubsub.ts +31 -5
- package/src/test-helpers/reqresp-nodes.ts +3 -3
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +71 -15
- package/src/testbench/worker_client_manager.ts +57 -2
- package/src/util.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -123
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -402
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
- package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -163
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -321
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { L2Block } from '@aztec/stdlib/block';
|
|
3
|
-
import { MAX_L2_BLOCK_SIZE_KB } from '@aztec/stdlib/p2p';
|
|
4
1
|
import { TxArray, TxHashArray } from '@aztec/stdlib/tx';
|
|
5
2
|
|
|
6
3
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -24,7 +21,6 @@ export const PING_PROTOCOL = '/aztec/req/ping/1.0.0';
|
|
|
24
21
|
export const STATUS_PROTOCOL = '/aztec/req/status/1.0.0';
|
|
25
22
|
export const GOODBYE_PROTOCOL = '/aztec/req/goodbye/1.0.0';
|
|
26
23
|
export const TX_REQ_PROTOCOL = '/aztec/req/tx/1.0.0';
|
|
27
|
-
export const BLOCK_REQ_PROTOCOL = '/aztec/req/block/1.0.0';
|
|
28
24
|
export const AUTH_PROTOCOL = '/aztec/req/auth/1.0.0';
|
|
29
25
|
export const BLOCK_TXS_REQ_PROTOCOL = '/aztec/req/block_txs/1.0.0';
|
|
30
26
|
|
|
@@ -33,7 +29,6 @@ export enum ReqRespSubProtocol {
|
|
|
33
29
|
STATUS = STATUS_PROTOCOL,
|
|
34
30
|
GOODBYE = GOODBYE_PROTOCOL,
|
|
35
31
|
TX = TX_REQ_PROTOCOL,
|
|
36
|
-
BLOCK = BLOCK_REQ_PROTOCOL,
|
|
37
32
|
AUTH = AUTH_PROTOCOL,
|
|
38
33
|
BLOCK_TXS = BLOCK_TXS_REQ_PROTOCOL,
|
|
39
34
|
}
|
|
@@ -100,12 +95,29 @@ export type ReqRespSubProtocolValidators = {
|
|
|
100
95
|
[S in ReqRespSubProtocol]: ResponseValidator<any, any>;
|
|
101
96
|
};
|
|
102
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Protocols that are always allowed without authentication, even when p2pAllowOnlyValidators is enabled.
|
|
100
|
+
* These are needed for the handshake and connection management flow.
|
|
101
|
+
* All other protocols require the remote peer to be authenticated.
|
|
102
|
+
*/
|
|
103
|
+
export const UNAUTHENTICATED_ALLOWED_PROTOCOLS: ReadonlySet<ReqRespSubProtocol> = new Set([
|
|
104
|
+
ReqRespSubProtocol.PING,
|
|
105
|
+
ReqRespSubProtocol.STATUS,
|
|
106
|
+
ReqRespSubProtocol.AUTH,
|
|
107
|
+
ReqRespSubProtocol.GOODBYE,
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Callback that checks whether a peer should be rejected from req/resp data protocols.
|
|
112
|
+
* Returns true if the peer should be rejected (i.e. p2pAllowOnlyValidators is on and peer is unauthenticated).
|
|
113
|
+
*/
|
|
114
|
+
export type ShouldRejectPeer = (peerId: string) => boolean;
|
|
115
|
+
|
|
103
116
|
export const DEFAULT_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
|
|
104
117
|
[ReqRespSubProtocol.PING]: noopValidator,
|
|
105
118
|
[ReqRespSubProtocol.STATUS]: noopValidator,
|
|
106
119
|
[ReqRespSubProtocol.TX]: noopValidator,
|
|
107
120
|
[ReqRespSubProtocol.GOODBYE]: noopValidator,
|
|
108
|
-
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
109
121
|
[ReqRespSubProtocol.AUTH]: noopValidator,
|
|
110
122
|
[ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
|
|
111
123
|
};
|
|
@@ -203,10 +215,6 @@ export const subProtocolMap = {
|
|
|
203
215
|
request: RequestableBuffer,
|
|
204
216
|
response: RequestableBuffer,
|
|
205
217
|
},
|
|
206
|
-
[ReqRespSubProtocol.BLOCK]: {
|
|
207
|
-
request: Fr, // block number
|
|
208
|
-
response: L2Block,
|
|
209
|
-
},
|
|
210
218
|
[ReqRespSubProtocol.AUTH]: {
|
|
211
219
|
request: AuthRequest,
|
|
212
220
|
response: AuthResponse,
|
|
@@ -229,7 +237,6 @@ export type ExpectedResponseSizeCalculator = (requestBuffer: Buffer) => number;
|
|
|
229
237
|
export const subProtocolSizeCalculators: Record<ReqRespSubProtocol, ExpectedResponseSizeCalculator> = {
|
|
230
238
|
[ReqRespSubProtocol.TX]: calculateTxResponseSize,
|
|
231
239
|
[ReqRespSubProtocol.BLOCK_TXS]: calculateBlockTxsResponseSize,
|
|
232
|
-
[ReqRespSubProtocol.BLOCK]: () => MAX_L2_BLOCK_SIZE_KB,
|
|
233
240
|
[ReqRespSubProtocol.STATUS]: () => 1,
|
|
234
241
|
[ReqRespSubProtocol.PING]: () => 1,
|
|
235
242
|
[ReqRespSubProtocol.AUTH]: () => 1,
|
|
@@ -264,5 +271,8 @@ export interface ReqRespInterface {
|
|
|
264
271
|
|
|
265
272
|
updateConfig(config: Partial<P2PReqRespConfig>): void;
|
|
266
273
|
|
|
274
|
+
/** Sets the callback used to reject unauthenticated peers on gated req/resp protocols. */
|
|
275
|
+
setShouldRejectPeer(checker: ShouldRejectPeer): void;
|
|
276
|
+
|
|
267
277
|
getConnectionSampler(): Pick<ConnectionSampler, 'getPeerListSortedByConnectionCountAsc'>;
|
|
268
278
|
}
|
|
@@ -51,9 +51,7 @@ export function reqRespTxHandler(mempools: MemPools): ReqRespSubProtocolHandler
|
|
|
51
51
|
* Per: https://github.com/AztecProtocol/aztec-packages/issues/15149#issuecomment-2999054485
|
|
52
52
|
* we define Q as max number of transactions per batch, the comment explains why we use 8.
|
|
53
53
|
*/
|
|
54
|
-
|
|
55
|
-
//more info: https://github.com/AztecProtocol/aztec-packages/pull/15516#pullrequestreview-2995474321
|
|
56
|
-
export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 1): Array<TxHashArray> {
|
|
54
|
+
export function chunkTxHashesRequest(hashes: TxHash[], chunkSize = 8): Array<TxHashArray> {
|
|
57
55
|
return chunk(hashes, chunkSize).map(chunk => new TxHashArray(...chunk));
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -42,16 +42,6 @@ export const DEFAULT_RATE_LIMITS: ReqRespSubProtocolRateLimits = {
|
|
|
42
42
|
quotaCount: 200,
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
-
[ReqRespSubProtocol.BLOCK]: {
|
|
46
|
-
peerLimit: {
|
|
47
|
-
quotaTimeMs: 1000,
|
|
48
|
-
quotaCount: 2,
|
|
49
|
-
},
|
|
50
|
-
globalLimit: {
|
|
51
|
-
quotaTimeMs: 1000,
|
|
52
|
-
quotaCount: 5,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
45
|
[ReqRespSubProtocol.GOODBYE]: {
|
|
56
46
|
peerLimit: {
|
|
57
47
|
quotaTimeMs: 1000,
|
|
@@ -34,7 +34,9 @@ import {
|
|
|
34
34
|
type ReqRespSubProtocolHandlers,
|
|
35
35
|
type ReqRespSubProtocolRateLimits,
|
|
36
36
|
type ReqRespSubProtocolValidators,
|
|
37
|
+
type ShouldRejectPeer,
|
|
37
38
|
type SubProtocolMap,
|
|
39
|
+
UNAUTHENTICATED_ALLOWED_PROTOCOLS,
|
|
38
40
|
responseFromBuffer,
|
|
39
41
|
subProtocolSizeCalculators,
|
|
40
42
|
} from './interface.js';
|
|
@@ -72,6 +74,8 @@ export class ReqResp implements ReqRespInterface {
|
|
|
72
74
|
|
|
73
75
|
private snappyTransform: SnappyTransform;
|
|
74
76
|
|
|
77
|
+
private shouldRejectPeer: ShouldRejectPeer | undefined;
|
|
78
|
+
|
|
75
79
|
private metrics: ReqRespMetrics;
|
|
76
80
|
|
|
77
81
|
constructor(
|
|
@@ -108,6 +112,10 @@ export class ReqResp implements ReqRespInterface {
|
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
114
|
|
|
115
|
+
public setShouldRejectPeer(checker: ShouldRejectPeer): void {
|
|
116
|
+
this.shouldRejectPeer = checker;
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
get tracer() {
|
|
112
120
|
return this.metrics.tracer;
|
|
113
121
|
}
|
|
@@ -320,7 +328,7 @@ export class ReqResp implements ReqRespInterface {
|
|
|
320
328
|
};
|
|
321
329
|
|
|
322
330
|
for (const index of indices) {
|
|
323
|
-
this.logger.
|
|
331
|
+
this.logger.trace(`Sending request ${index} to peer ${peerAsString}`);
|
|
324
332
|
const response = await this.sendRequestToPeer(peer, subProtocol, requestBuffers[index]);
|
|
325
333
|
|
|
326
334
|
// Check the status of the response buffer
|
|
@@ -596,6 +604,15 @@ export class ReqResp implements ReqRespInterface {
|
|
|
596
604
|
throw new ReqRespStatusError(ReqRespStatus.RATE_LIMIT_EXCEEDED);
|
|
597
605
|
}
|
|
598
606
|
|
|
607
|
+
// When p2pAllowOnlyValidators is enabled, reject unauthenticated peers on data protocols
|
|
608
|
+
if (
|
|
609
|
+
!UNAUTHENTICATED_ALLOWED_PROTOCOLS.has(protocol) &&
|
|
610
|
+
(this.shouldRejectPeer?.(connection.remotePeer.toString()) ?? false)
|
|
611
|
+
) {
|
|
612
|
+
this.logger.debug(`Rejecting unauthenticated peer ${connection.remotePeer} on gated protocol ${protocol}`);
|
|
613
|
+
throw new ReqRespStatusError(ReqRespStatus.FAILURE);
|
|
614
|
+
}
|
|
615
|
+
|
|
599
616
|
await this.processStream(protocol, incomingStream);
|
|
600
617
|
} catch (err: any) {
|
|
601
618
|
this.metrics.recordResponseError(protocol);
|
|
@@ -621,7 +638,9 @@ export class ReqResp implements ReqRespInterface {
|
|
|
621
638
|
// and that this stream should be dropped
|
|
622
639
|
const isMessageToNotWarn =
|
|
623
640
|
err instanceof Error &&
|
|
624
|
-
['stream reset', 'Cannot push value onto an ended pushable'].some(msg =>
|
|
641
|
+
['stream reset', 'Cannot push value onto an ended pushable', 'read ECONNRESET'].some(msg =>
|
|
642
|
+
err.message.includes(msg),
|
|
643
|
+
);
|
|
625
644
|
const level = isMessageToNotWarn ? 'debug' : 'warn';
|
|
626
645
|
this.logger[level]('Unknown stream error while handling the stream, aborting', {
|
|
627
646
|
protocol,
|
package/src/services/service.ts
CHANGED
|
@@ -117,7 +117,12 @@ export interface P2PService {
|
|
|
117
117
|
// Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
118
118
|
registerBlockReceivedCallback(callback: P2PBlockReceivedCallback): void;
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
registerValidatorCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback): void;
|
|
121
|
+
|
|
122
|
+
registerAllNodesCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback): void;
|
|
123
|
+
|
|
124
|
+
/** Fires the all-nodes checkpoint callback for our own proposal (gossipsub doesn't deliver own messages). */
|
|
125
|
+
notifyOwnCheckpointProposal(checkpoint: CheckpointProposalCore): Promise<void>;
|
|
121
126
|
|
|
122
127
|
/**
|
|
123
128
|
* Registers a callback invoked when a duplicate proposal is detected (equivocation).
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { times } from '@aztec/foundation/collection';
|
|
3
|
-
import { AbortError, TimeoutError } from '@aztec/foundation/error';
|
|
4
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
6
4
|
import { sleep } from '@aztec/foundation/sleep';
|
|
7
5
|
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
8
6
|
import type { L2BlockInfo } from '@aztec/stdlib/block';
|
|
9
|
-
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
10
7
|
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
11
8
|
|
|
12
9
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -14,12 +11,12 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
14
11
|
import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/config.js';
|
|
15
12
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
16
13
|
import type { TxCollectionConfig } from './config.js';
|
|
17
|
-
import { MissingTxsTracker } from './missing_txs_tracker.js';
|
|
18
14
|
import {
|
|
19
15
|
BatchTxRequesterCollector,
|
|
20
16
|
type MissingTxsCollector,
|
|
21
17
|
SendBatchRequestCollector,
|
|
22
18
|
} from './proposal_tx_collector.js';
|
|
19
|
+
import { RequestTracker } from './request_tracker.js';
|
|
23
20
|
import type { FastCollectionRequest, FastCollectionRequestInput } from './tx_collection.js';
|
|
24
21
|
import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
25
22
|
import type { TxSource } from './tx_source.js';
|
|
@@ -48,7 +45,9 @@ export class FastTxCollection {
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
public async stop() {
|
|
51
|
-
this.requests.forEach(request =>
|
|
48
|
+
this.requests.forEach(request => {
|
|
49
|
+
request.requestTracker.cancel();
|
|
50
|
+
});
|
|
52
51
|
await Promise.resolve();
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -75,81 +74,65 @@ export class FastTxCollection {
|
|
|
75
74
|
? { ...input.blockProposal.toBlockInfo(), blockNumber: input.blockNumber }
|
|
76
75
|
: { ...input.block.toBlockInfo() };
|
|
77
76
|
|
|
78
|
-
// This promise is used to await for the collection to finish during the main collectFast method.
|
|
79
|
-
// It gets resolved in `foundTxs` when all txs have been collected, or rejected if the request is aborted or hits the deadline.
|
|
80
|
-
const promise = promiseWithResolvers<void>();
|
|
81
|
-
const timeoutTimer = setTimeout(() => promise.reject(new TimeoutError(`Timed out while collecting txs`)), timeout);
|
|
82
|
-
|
|
83
77
|
const request: FastCollectionRequest = {
|
|
84
78
|
...input,
|
|
85
79
|
blockInfo,
|
|
86
|
-
|
|
87
|
-
missingTxTracker: MissingTxsTracker.fromArray(txHashes),
|
|
88
|
-
deadline: opts.deadline,
|
|
80
|
+
requestTracker: RequestTracker.create(txHashes, opts.deadline, this.dateProvider),
|
|
89
81
|
};
|
|
90
82
|
|
|
91
83
|
const [duration] = await elapsed(() => this.collectFast(request, { ...opts }));
|
|
92
|
-
clearTimeout(timeoutTimer);
|
|
93
84
|
|
|
94
85
|
this.log.verbose(
|
|
95
|
-
`Collected ${request.
|
|
86
|
+
`Collected ${request.requestTracker.collectedTxs.length} txs out of ${txHashes.length} for ${input.type} at slot ${blockInfo.slotNumber}`,
|
|
96
87
|
{
|
|
97
88
|
...blockInfo,
|
|
98
89
|
duration,
|
|
99
90
|
requestType: input.type,
|
|
100
|
-
missingTxs: [...request.
|
|
91
|
+
missingTxs: [...request.requestTracker.missingTxHashes],
|
|
101
92
|
},
|
|
102
93
|
);
|
|
103
|
-
return request.
|
|
94
|
+
return request.requestTracker.collectedTxs;
|
|
104
95
|
}
|
|
105
96
|
|
|
106
|
-
protected async collectFast(
|
|
107
|
-
request: FastCollectionRequest,
|
|
108
|
-
opts: { proposal?: BlockProposal; deadline: Date; pinnedPeer?: PeerId },
|
|
109
|
-
) {
|
|
97
|
+
protected async collectFast(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
|
|
110
98
|
this.requests.add(request);
|
|
111
99
|
const { blockInfo } = request;
|
|
112
100
|
|
|
113
101
|
this.log.debug(
|
|
114
|
-
`Starting fast collection of ${request.
|
|
115
|
-
{ ...blockInfo, requestType: request.type, deadline:
|
|
102
|
+
`Starting fast collection of ${request.requestTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
103
|
+
{ ...blockInfo, requestType: request.type, deadline: request.requestTracker.deadline },
|
|
116
104
|
);
|
|
117
105
|
|
|
118
106
|
try {
|
|
119
107
|
// Start blasting all nodes for the txs. We give them a little time to respond before we start reqresp.
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
const nodeCollectionPromise = this.collectFastFromNodes(request
|
|
108
|
+
// We race against the cancellation token to exit as soon as all txs are collected, the deadline expires,
|
|
109
|
+
// or the request is externally cancelled.
|
|
110
|
+
const nodeCollectionPromise = this.collectFastFromNodes(request);
|
|
123
111
|
const waitBeforeReqResp = sleep(this.config.txCollectionFastNodesTimeoutBeforeReqRespMs);
|
|
124
|
-
await Promise.race([request.
|
|
112
|
+
await Promise.race([request.requestTracker.cancellationToken, waitBeforeReqResp]);
|
|
125
113
|
|
|
126
|
-
// If we have collected all txs, we can stop here
|
|
127
|
-
|
|
128
|
-
|
|
114
|
+
// If we have collected all txs or the request was cancelled, we can stop here.
|
|
115
|
+
// Wait for node collection to settle so inner tasks finish before we return.
|
|
116
|
+
if (request.requestTracker.checkCancelled()) {
|
|
117
|
+
if (request.requestTracker.allFetched()) {
|
|
118
|
+
this.log.debug(`All txs collected for slot ${blockInfo.slotNumber} without reqresp`, blockInfo);
|
|
119
|
+
}
|
|
120
|
+
await nodeCollectionPromise;
|
|
129
121
|
return;
|
|
130
122
|
}
|
|
131
123
|
|
|
132
124
|
// Start blasting reqresp for the remaining txs. Note that node collection keeps running in parallel.
|
|
133
125
|
// We stop when we have collected all txs, timed out, or both node collection and reqresp have given up.
|
|
134
|
-
|
|
135
|
-
await Promise.
|
|
126
|
+
// Inner tasks observe requestTracker.checkCancelled() and stop themselves, so this settles shortly after cancellation.
|
|
127
|
+
await Promise.allSettled([this.collectFastViaReqResp(request, opts), nodeCollectionPromise]);
|
|
136
128
|
} catch (err) {
|
|
137
|
-
|
|
138
|
-
const logCtx = {
|
|
129
|
+
this.log.error(`Error collecting txs for ${request.type} for slot ${blockInfo.slotNumber}`, err, {
|
|
139
130
|
...blockInfo,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
if (err instanceof Error && err.name === 'TimeoutError') {
|
|
144
|
-
this.log.warn(`Timed out collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
|
|
145
|
-
} else if (err instanceof Error && err.name === 'AbortError') {
|
|
146
|
-
this.log.warn(`Aborted collecting txs for ${request.type} at slot ${blockInfo.slotNumber}`, logCtx);
|
|
147
|
-
} else {
|
|
148
|
-
this.log.error(`Error collecting txs for ${request.type} for slot ${blockInfo.slotNumber}`, err, logCtx);
|
|
149
|
-
}
|
|
131
|
+
missingTxs: request.requestTracker.missingTxHashes.values().map(txHash => txHash.toString()),
|
|
132
|
+
});
|
|
150
133
|
} finally {
|
|
151
134
|
// Ensure no unresolved promises and remove the request from the set
|
|
152
|
-
request.
|
|
135
|
+
request.requestTracker.cancel();
|
|
153
136
|
this.requests.delete(request);
|
|
154
137
|
}
|
|
155
138
|
}
|
|
@@ -160,30 +143,28 @@ export class FastTxCollection {
|
|
|
160
143
|
* the txs that have been requested less often whenever we need to send a new batch of requests. We ensure that no
|
|
161
144
|
* tx is requested more than once at the same time to the same node.
|
|
162
145
|
*/
|
|
163
|
-
private async collectFastFromNodes(request: FastCollectionRequest
|
|
146
|
+
private async collectFastFromNodes(request: FastCollectionRequest): Promise<void> {
|
|
164
147
|
if (this.nodes.length === 0) {
|
|
165
148
|
return;
|
|
166
149
|
}
|
|
167
150
|
|
|
168
151
|
// Keep a shared priority queue of all txs pending to be requested, sorted by the number of attempts made to collect them.
|
|
169
|
-
const attemptsPerTx = [...request.
|
|
152
|
+
const attemptsPerTx = [...request.requestTracker.missingTxHashes].map(txHash => ({
|
|
170
153
|
txHash,
|
|
171
154
|
attempts: 0,
|
|
172
155
|
found: false,
|
|
173
156
|
}));
|
|
174
157
|
|
|
175
158
|
// Returns once we have finished all node loops. Each loop finishes when the deadline is hit, or all txs have been collected.
|
|
176
|
-
await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx
|
|
159
|
+
await Promise.allSettled(this.nodes.map(node => this.collectFastFromNode(request, node, attemptsPerTx)));
|
|
177
160
|
}
|
|
178
161
|
|
|
179
162
|
private async collectFastFromNode(
|
|
180
163
|
request: FastCollectionRequest,
|
|
181
164
|
node: TxSource,
|
|
182
165
|
attemptsPerTx: { txHash: string; attempts: number; found: boolean }[],
|
|
183
|
-
opts: { deadline: Date },
|
|
184
166
|
) {
|
|
185
|
-
const notFinished = () =>
|
|
186
|
-
this.dateProvider.now() <= +opts.deadline && !request.missingTxTracker.allFetched() && this.requests.has(request);
|
|
167
|
+
const notFinished = () => !request.requestTracker.checkCancelled();
|
|
187
168
|
|
|
188
169
|
const maxParallelRequests = this.config.txCollectionFastMaxParallelRequestsPerNode;
|
|
189
170
|
const maxBatchSize = this.config.txCollectionNodeRpcMaxBatchSize;
|
|
@@ -200,7 +181,7 @@ export class FastTxCollection {
|
|
|
200
181
|
if (!txToRequest) {
|
|
201
182
|
// No more txs to process
|
|
202
183
|
break;
|
|
203
|
-
} else if (!request.
|
|
184
|
+
} else if (!request.requestTracker.isMissing(txToRequest.txHash)) {
|
|
204
185
|
// Mark as found if it was found somewhere else, we'll then remove it from the array.
|
|
205
186
|
// We don't delete it now since 'array.splice' is pretty expensive, so we do it after sorting.
|
|
206
187
|
txToRequest.found = true;
|
|
@@ -235,7 +216,7 @@ export class FastTxCollection {
|
|
|
235
216
|
async () => {
|
|
236
217
|
const result = await node.getTxsByHash(txHashes.map(TxHash.fromString));
|
|
237
218
|
for (const tx of result.validTxs) {
|
|
238
|
-
request.
|
|
219
|
+
request.requestTracker.markFetched(tx);
|
|
239
220
|
}
|
|
240
221
|
return result;
|
|
241
222
|
},
|
|
@@ -254,9 +235,12 @@ export class FastTxCollection {
|
|
|
254
235
|
activeRequestsToThisNode.delete(requestedTx.txHash);
|
|
255
236
|
}
|
|
256
237
|
|
|
257
|
-
// Sleep a bit until hitting the node again
|
|
238
|
+
// Sleep a bit until hitting the node again, but wake up immediately on cancellation
|
|
258
239
|
if (notFinished()) {
|
|
259
|
-
await
|
|
240
|
+
await Promise.race([
|
|
241
|
+
sleep(this.config.txCollectionFastNodeIntervalMs),
|
|
242
|
+
request.requestTracker.cancellationToken,
|
|
243
|
+
]);
|
|
260
244
|
}
|
|
261
245
|
}
|
|
262
246
|
};
|
|
@@ -266,21 +250,20 @@ export class FastTxCollection {
|
|
|
266
250
|
}
|
|
267
251
|
|
|
268
252
|
private async collectFastViaReqResp(request: FastCollectionRequest, opts: { pinnedPeer?: PeerId }) {
|
|
269
|
-
const timeoutMs = +request.deadline - this.dateProvider.now();
|
|
270
253
|
const pinnedPeer = opts.pinnedPeer;
|
|
271
254
|
const blockInfo = request.blockInfo;
|
|
272
255
|
const slotNumber = blockInfo.slotNumber;
|
|
273
|
-
if (timeoutMs < 100) {
|
|
256
|
+
if (request.requestTracker.timeoutMs < 100) {
|
|
274
257
|
this.log.warn(
|
|
275
258
|
`Not initiating fast reqresp for txs for ${request.type} at slot ${blockInfo.slotNumber} due to timeout`,
|
|
276
|
-
{ timeoutMs, ...blockInfo },
|
|
259
|
+
{ timeoutMs: request.requestTracker.timeoutMs, ...blockInfo },
|
|
277
260
|
);
|
|
278
261
|
return;
|
|
279
262
|
}
|
|
280
263
|
|
|
281
264
|
this.log.debug(
|
|
282
|
-
`Starting fast reqresp for ${request.
|
|
283
|
-
{ ...blockInfo, timeoutMs, pinnedPeer },
|
|
265
|
+
`Starting fast reqresp for ${request.requestTracker.numberOfMissingTxs} txs for ${request.type} at slot ${blockInfo.slotNumber}`,
|
|
266
|
+
{ ...blockInfo, timeoutMs: request.requestTracker.timeoutMs, pinnedPeer },
|
|
284
267
|
);
|
|
285
268
|
|
|
286
269
|
try {
|
|
@@ -289,34 +272,28 @@ export class FastTxCollection {
|
|
|
289
272
|
let result: Tx[];
|
|
290
273
|
if (request.type === 'proposal') {
|
|
291
274
|
result = await this.missingTxsCollector.collectTxs(
|
|
292
|
-
request.
|
|
275
|
+
request.requestTracker,
|
|
293
276
|
request.blockProposal,
|
|
294
277
|
pinnedPeer,
|
|
295
|
-
timeoutMs,
|
|
296
278
|
);
|
|
297
279
|
} else if (request.type === 'block') {
|
|
298
280
|
const blockTxsSource = {
|
|
299
281
|
txHashes: request.block.body.txEffects.map(e => e.txHash),
|
|
300
282
|
archive: request.block.archive.root,
|
|
301
283
|
};
|
|
302
|
-
result = await this.missingTxsCollector.collectTxs(
|
|
303
|
-
request.missingTxTracker,
|
|
304
|
-
blockTxsSource,
|
|
305
|
-
pinnedPeer,
|
|
306
|
-
timeoutMs,
|
|
307
|
-
);
|
|
284
|
+
result = await this.missingTxsCollector.collectTxs(request.requestTracker, blockTxsSource, pinnedPeer);
|
|
308
285
|
} else {
|
|
309
286
|
throw new Error(`Unknown request type: ${(request as any).type}`);
|
|
310
287
|
}
|
|
311
288
|
return { validTxs: result, invalidTxHashes: [] };
|
|
312
289
|
},
|
|
313
|
-
Array.from(request.
|
|
290
|
+
Array.from(request.requestTracker.missingTxHashes),
|
|
314
291
|
{ description: `reqresp for slot ${slotNumber}`, method: 'fast-req-resp', ...opts, ...request.blockInfo },
|
|
315
292
|
this.getAddContext(request),
|
|
316
293
|
);
|
|
317
294
|
} catch (err) {
|
|
318
295
|
this.log.error(`Error sending fast reqresp request for txs`, err, {
|
|
319
|
-
txs: [...request.
|
|
296
|
+
txs: [...request.requestTracker.missingTxHashes],
|
|
320
297
|
...blockInfo,
|
|
321
298
|
});
|
|
322
299
|
}
|
|
@@ -340,20 +317,19 @@ export class FastTxCollection {
|
|
|
340
317
|
for (const tx of txs) {
|
|
341
318
|
const txHash = tx.txHash.toString();
|
|
342
319
|
// Remove the tx hash from the missing set, and add it to the found set.
|
|
343
|
-
if (request.
|
|
320
|
+
if (request.requestTracker.markFetched(tx)) {
|
|
344
321
|
this.log.trace(`Found tx ${txHash} for fast collection request`, {
|
|
345
322
|
...request.blockInfo,
|
|
346
323
|
txHash: tx.txHash.toString(),
|
|
347
324
|
type: request.type,
|
|
348
325
|
});
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
request.promise.resolve();
|
|
326
|
+
if (request.requestTracker.allFetched()) {
|
|
327
|
+
this.log.trace(`All txs found for fast collection request`, {
|
|
328
|
+
...request.blockInfo,
|
|
329
|
+
type: request.type,
|
|
330
|
+
});
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
357
333
|
}
|
|
358
334
|
}
|
|
359
335
|
}
|
|
@@ -366,8 +342,7 @@ export class FastTxCollection {
|
|
|
366
342
|
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
367
343
|
for (const request of this.requests) {
|
|
368
344
|
if (request.blockInfo.blockNumber <= blockNumber) {
|
|
369
|
-
request.
|
|
370
|
-
this.requests.delete(request);
|
|
345
|
+
request.requestTracker.cancel();
|
|
371
346
|
}
|
|
372
347
|
}
|
|
373
348
|
}
|
|
@@ -379,8 +354,7 @@ export class FastTxCollection {
|
|
|
379
354
|
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
380
355
|
for (const request of this.requests) {
|
|
381
356
|
if (request.blockInfo.blockNumber > blockNumber) {
|
|
382
|
-
request.
|
|
383
|
-
this.requests.delete(request);
|
|
357
|
+
request.requestTracker.cancel();
|
|
384
358
|
}
|
|
385
359
|
}
|
|
386
360
|
}
|
|
@@ -9,7 +9,7 @@ import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/confi
|
|
|
9
9
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
10
10
|
import type { IBatchRequestTxValidator } from '../reqresp/batch-tx-requester/tx_validator.js';
|
|
11
11
|
import { type BlockTxsSource, ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
|
|
12
|
-
import type {
|
|
12
|
+
import type { IRequestTracker } from './request_tracker.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Strategy interface for collecting missing transactions for a block or proposal.
|
|
@@ -18,17 +18,15 @@ import type { IMissingTxsTracker } from './missing_txs_tracker.js';
|
|
|
18
18
|
export interface MissingTxsCollector {
|
|
19
19
|
/**
|
|
20
20
|
* Collect missing transactions for a block or proposal.
|
|
21
|
-
* @param
|
|
21
|
+
* @param requestTracker - The missing transactions tracker
|
|
22
22
|
* @param blockTxsSource - The block or proposal containing the transactions
|
|
23
23
|
* @param pinnedPeer - Optional peer expected to have the transactions
|
|
24
|
-
* @param timeoutMs - Timeout in milliseconds
|
|
25
24
|
* @returns The collected transactions
|
|
26
25
|
*/
|
|
27
26
|
collectTxs(
|
|
28
|
-
|
|
27
|
+
requestTracker: IRequestTracker,
|
|
29
28
|
blockTxsSource: BlockTxsSource,
|
|
30
29
|
pinnedPeer: PeerId | undefined,
|
|
31
|
-
timeoutMs: number,
|
|
32
30
|
): Promise<Tx[]>;
|
|
33
31
|
}
|
|
34
32
|
|
|
@@ -46,10 +44,9 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
|
|
|
46
44
|
) {}
|
|
47
45
|
|
|
48
46
|
async collectTxs(
|
|
49
|
-
|
|
47
|
+
requestTracker: IRequestTracker,
|
|
50
48
|
blockTxsSource: BlockTxsSource,
|
|
51
49
|
pinnedPeer: PeerId | undefined,
|
|
52
|
-
timeoutMs: number,
|
|
53
50
|
): Promise<Tx[]> {
|
|
54
51
|
const {
|
|
55
52
|
batchTxRequesterSmartParallelWorkerCount: smartParallelWorkerCount,
|
|
@@ -59,10 +56,9 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
|
|
|
59
56
|
} = this.batchTxRequesterConfig ?? {};
|
|
60
57
|
|
|
61
58
|
const batchRequester = new BatchTxRequester(
|
|
62
|
-
|
|
59
|
+
requestTracker,
|
|
63
60
|
blockTxsSource,
|
|
64
61
|
pinnedPeer,
|
|
65
|
-
timeoutMs,
|
|
66
62
|
this.p2pService,
|
|
67
63
|
this.log,
|
|
68
64
|
this.dateProvider,
|
|
@@ -94,16 +90,15 @@ export class SendBatchRequestCollector implements MissingTxsCollector {
|
|
|
94
90
|
) {}
|
|
95
91
|
|
|
96
92
|
async collectTxs(
|
|
97
|
-
|
|
93
|
+
requestTracker: IRequestTracker,
|
|
98
94
|
_blockTxsSource: BlockTxsSource,
|
|
99
95
|
pinnedPeer: PeerId | undefined,
|
|
100
|
-
timeoutMs: number,
|
|
101
96
|
): Promise<Tx[]> {
|
|
102
97
|
const txs = await this.p2pService.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
103
98
|
ReqRespSubProtocol.TX,
|
|
104
|
-
chunkTxHashesRequest(Array.from(
|
|
99
|
+
chunkTxHashesRequest(Array.from(requestTracker.missingTxHashes).map(TxHash.fromString)),
|
|
105
100
|
pinnedPeer,
|
|
106
|
-
timeoutMs,
|
|
101
|
+
requestTracker.timeoutMs,
|
|
107
102
|
this.maxPeers,
|
|
108
103
|
this.maxRetryAttempts,
|
|
109
104
|
);
|