@aztec/p2p 0.0.1-commit.3e3d0c9cd → 0.0.1-commit.3f5453c7b
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 +1 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +5 -4
- 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 +21 -6
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +17 -6
- package/dest/config.d.ts +10 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +15 -0
- 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 +11 -8
- 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/tx_pool_v2/interfaces.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +5 -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/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +1 -1
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +8 -2
- 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/phases_validator.js +1 -1
- 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/encoding.d.ts +5 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -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/libp2p_service.d.ts +15 -25
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +121 -112
- 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 +37 -10
- 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 +4 -7
- 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 +43 -56
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +1 -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 +4 -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 +7 -7
- 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_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +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 +27 -10
- 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/file_store_tx_source.d.ts +5 -4
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +39 -29
- 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/services/tx_collection/tx_source.d.ts +6 -5
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +9 -7
- 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 +49 -1
- package/package.json +14 -14
- package/src/client/factory.ts +7 -2
- package/src/client/interface.ts +9 -1
- package/src/client/p2p_client.ts +23 -6
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +18 -8
- package/src/config.ts +30 -1
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +12 -8
- 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/tx_pool_v2/interfaces.ts +4 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +7 -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/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/factory.ts +7 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +25 -9
- package/src/msg_validators/tx_validator/phases_validator.ts +1 -1
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +8 -2
- package/src/services/encoding.ts +9 -1
- package/src/services/gossipsub/topic_score_params.ts +36 -4
- package/src/services/libp2p/libp2p_service.ts +122 -128
- package/src/services/peer-manager/peer_manager.ts +43 -10
- 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 +35 -60
- package/src/services/reqresp/batch-tx-requester/interface.ts +0 -1
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +6 -6
- 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_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +36 -11
- package/src/services/service.ts +6 -1
- package/src/services/tx_collection/fast_tx_collection.ts +57 -83
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- 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/services/tx_collection/tx_source.ts +8 -7
- package/src/test-helpers/mock-pubsub.ts +31 -5
- package/src/test-helpers/reqresp-nodes.ts +2 -2
- package/src/test-helpers/testbench-utils.ts +29 -3
- package/src/testbench/p2p_client_testbench_worker.ts +70 -14
- package/src/testbench/worker_client_manager.ts +55 -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
|
@@ -32,7 +32,7 @@ import { PeerScoreState, type PeerScoring } from './peer_scoring.js';
|
|
|
32
32
|
const MAX_DIAL_ATTEMPTS = 3;
|
|
33
33
|
const MAX_CACHED_PEERS = 100;
|
|
34
34
|
const MAX_CACHED_PEER_AGE_MS = 5 * 60 * 1000; // 5 minutes
|
|
35
|
-
const
|
|
35
|
+
const DEFAULT_FAILED_PEER_BAN_TIME_MS = 5 * 60 * 1000; // 5 minutes timeout after failing MAX_DIAL_ATTEMPTS
|
|
36
36
|
const GOODBYE_DIAL_TIMEOUT_MS = 1000;
|
|
37
37
|
const FAILED_AUTH_HANDSHAKE_EXPIRY_MS = 60 * 60 * 1000; // 1 hour
|
|
38
38
|
|
|
@@ -226,20 +226,30 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
/**
|
|
229
|
-
* Cleans up expired timeouts.
|
|
229
|
+
* Cleans up expired timeouts and stale failed-auth-handshake entries.
|
|
230
230
|
*
|
|
231
231
|
* When peers fail to dial after a number of retries, they are temporarily timed out.
|
|
232
232
|
* This function removes any peers that have been in the timed out state for too long.
|
|
233
233
|
* To give them a chance to reconnect.
|
|
234
|
+
*
|
|
235
|
+
* Also evicts entries from the failed-auth-handshake map whose expiry window has passed.
|
|
236
|
+
* Without this, peers that probe once and never reconnect would leave their entries in the
|
|
237
|
+
* map forever, causing an unbounded memory leak.
|
|
234
238
|
*/
|
|
235
239
|
private cleanupExpiredTimeouts() {
|
|
236
|
-
// Clean up expired timeouts
|
|
237
240
|
const now = this.dateProvider.now();
|
|
241
|
+
|
|
238
242
|
for (const [peerId, timedOutPeer] of this.timedOutPeers.entries()) {
|
|
239
243
|
if (now >= timedOutPeer.timeoutUntilMs) {
|
|
240
244
|
this.timedOutPeers.delete(peerId);
|
|
241
245
|
}
|
|
242
246
|
}
|
|
247
|
+
|
|
248
|
+
for (const [id, entry] of this.failedAuthHandshakes.entries()) {
|
|
249
|
+
if (now - entry.lastFailureTimestamp > FAILED_AUTH_HANDSHAKE_EXPIRY_MS) {
|
|
250
|
+
this.failedAuthHandshakes.delete(id);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
243
253
|
}
|
|
244
254
|
|
|
245
255
|
/**
|
|
@@ -303,15 +313,20 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
303
313
|
*/
|
|
304
314
|
private handleDisconnectedPeerEvent(e: CustomEvent<PeerId>) {
|
|
305
315
|
const peerId = e.detail;
|
|
316
|
+
const peerIdStr = peerId.toString();
|
|
306
317
|
this.metrics.peerDisconnected(peerId);
|
|
307
|
-
this.logger.verbose(`Disconnected from peer ${
|
|
308
|
-
const validatorAddress = this.authenticatedPeerIdToValidatorAddress.get(
|
|
318
|
+
this.logger.verbose(`Disconnected from peer ${peerIdStr}`);
|
|
319
|
+
const validatorAddress = this.authenticatedPeerIdToValidatorAddress.get(peerIdStr);
|
|
309
320
|
if (validatorAddress !== undefined) {
|
|
310
321
|
this.logger.info(
|
|
311
|
-
`Removing authentication for validator ${validatorAddress} at peer id ${
|
|
322
|
+
`Removing authentication for validator ${validatorAddress} at peer id ${peerIdStr} due to disconnection`,
|
|
312
323
|
);
|
|
313
324
|
this.authenticatedValidatorAddressToPeerId.delete(validatorAddress.toString());
|
|
314
|
-
this.authenticatedPeerIdToValidatorAddress.delete(
|
|
325
|
+
this.authenticatedPeerIdToValidatorAddress.delete(peerIdStr);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (this.peerScoring.getScoreState(peerIdStr) === PeerScoreState.Healthy) {
|
|
329
|
+
this.peerScoring.removePeer(peerIdStr);
|
|
315
330
|
}
|
|
316
331
|
}
|
|
317
332
|
|
|
@@ -713,6 +728,12 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
713
728
|
return;
|
|
714
729
|
}
|
|
715
730
|
|
|
731
|
+
// Don't dial peers that have exceeded the auth failure threshold
|
|
732
|
+
if (!this.isNodeAllowedToConnect(peerId)) {
|
|
733
|
+
this.logger.trace(`Skipping peer ${peerId} due to failed auth handshake attempts`);
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
|
|
716
737
|
const [multiaddrTcp] = await Promise.all([enr.getFullMultiaddr('tcp')]);
|
|
717
738
|
|
|
718
739
|
this.logger.trace(`Handling discovered peer ${peerId} at ${multiaddrTcp?.toString() ?? 'undefined address'}`);
|
|
@@ -776,7 +797,8 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
776
797
|
// Add to timed out peers
|
|
777
798
|
this.timedOutPeers.set(id, {
|
|
778
799
|
peerId: id,
|
|
779
|
-
timeoutUntilMs:
|
|
800
|
+
timeoutUntilMs:
|
|
801
|
+
this.dateProvider.now() + (this.config.peerFailedBanTimeMs ?? DEFAULT_FAILED_PEER_BAN_TIME_MS),
|
|
780
802
|
});
|
|
781
803
|
}
|
|
782
804
|
}
|
|
@@ -938,6 +960,8 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
938
960
|
`Received auth for validator ${sender.toString()} from peer ${peerIdString}, but this validator is already authenticated to peer ${peerForAddress.toString()}`,
|
|
939
961
|
{ ...logData, address: sender.toString() },
|
|
940
962
|
);
|
|
963
|
+
this.markAuthHandshakeFailed(peerId);
|
|
964
|
+
this.markPeerForDisconnect(peerId);
|
|
941
965
|
return;
|
|
942
966
|
}
|
|
943
967
|
|
|
@@ -967,14 +991,14 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
967
991
|
const peerIdStr = peerId.toString();
|
|
968
992
|
|
|
969
993
|
const existingEntry = this.failedAuthHandshakes.get(peerIdStr);
|
|
994
|
+
const failureCount = (existingEntry?.count || 0) + 1;
|
|
970
995
|
this.failedAuthHandshakes.set(peerIdStr, {
|
|
971
|
-
count:
|
|
996
|
+
count: failureCount,
|
|
972
997
|
lastFailureTimestamp: now,
|
|
973
998
|
});
|
|
974
999
|
|
|
975
1000
|
const connections = this.libP2PNode.getConnections(peerId);
|
|
976
1001
|
connections.forEach(conn => {
|
|
977
|
-
// We mark the IP address
|
|
978
1002
|
const address = conn.remoteAddr.nodeAddress().address;
|
|
979
1003
|
const existingAddressEntry = this.failedAuthHandshakes.get(address);
|
|
980
1004
|
this.failedAuthHandshakes.set(address, {
|
|
@@ -982,6 +1006,15 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
982
1006
|
lastFailureTimestamp: now,
|
|
983
1007
|
});
|
|
984
1008
|
});
|
|
1009
|
+
|
|
1010
|
+
// Ban the peer from being re-dialed for a cooldown period (exponential backoff)
|
|
1011
|
+
const banTimeMs = this.config.peerFailedBanTimeMs ?? DEFAULT_FAILED_PEER_BAN_TIME_MS;
|
|
1012
|
+
const backoffMs = banTimeMs * Math.pow(2, Math.min(failureCount - 1, 5));
|
|
1013
|
+
this.timedOutPeers.set(peerIdStr, {
|
|
1014
|
+
peerId: peerIdStr,
|
|
1015
|
+
timeoutUntilMs: now + backoffMs,
|
|
1016
|
+
});
|
|
1017
|
+
this.cachedPeers.delete(peerIdStr);
|
|
985
1018
|
}
|
|
986
1019
|
|
|
987
1020
|
/*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { median } from '@aztec/foundation/collection';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
3
4
|
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
4
5
|
import {
|
|
5
6
|
Attributes,
|
|
@@ -54,6 +55,7 @@ export enum PeerScoreState {
|
|
|
54
55
|
// TODO: move into config / constants
|
|
55
56
|
const MIN_SCORE_BEFORE_BAN = -100;
|
|
56
57
|
const MIN_SCORE_BEFORE_DISCONNECT = -50;
|
|
58
|
+
const SCORE_CLEANUP_THRESHOLD = 0.1;
|
|
57
59
|
|
|
58
60
|
export class PeerScoring {
|
|
59
61
|
private logger = createLogger('p2p:peer-scoring');
|
|
@@ -65,7 +67,11 @@ export class PeerScoring {
|
|
|
65
67
|
|
|
66
68
|
private peerStateCounter: UpDownCounter;
|
|
67
69
|
|
|
68
|
-
constructor(
|
|
70
|
+
constructor(
|
|
71
|
+
config: P2PConfig,
|
|
72
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
73
|
+
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
74
|
+
) {
|
|
69
75
|
const orderedValues = config.peerPenaltyValues?.sort((a, b) => a - b);
|
|
70
76
|
this.peerPenalties = {
|
|
71
77
|
[PeerErrorSeverity.HighToleranceError]:
|
|
@@ -92,7 +98,7 @@ export class PeerScoring {
|
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
updateScore(peerId: string, scoreDelta: number): number {
|
|
95
|
-
const currentTime =
|
|
101
|
+
const currentTime = this.dateProvider.now();
|
|
96
102
|
const lastUpdate = this.lastUpdateTime.get(peerId) || currentTime;
|
|
97
103
|
const timePassed = currentTime - lastUpdate;
|
|
98
104
|
const decayPeriods = Math.floor(timePassed / this.decayInterval);
|
|
@@ -111,19 +117,35 @@ export class PeerScoring {
|
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
decayAllScores(): void {
|
|
114
|
-
const currentTime =
|
|
120
|
+
const currentTime = this.dateProvider.now();
|
|
115
121
|
for (const [peerId, lastUpdate] of this.lastUpdateTime.entries()) {
|
|
116
122
|
const timePassed = currentTime - lastUpdate;
|
|
117
123
|
const decayPeriods = Math.floor(timePassed / this.decayInterval);
|
|
118
124
|
if (decayPeriods > 0) {
|
|
119
125
|
let score = this.scores.get(peerId) || 0;
|
|
120
126
|
score *= Math.pow(this.decayFactor, decayPeriods);
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
if (Math.abs(score) < SCORE_CLEANUP_THRESHOLD) {
|
|
128
|
+
this.scores.delete(peerId);
|
|
129
|
+
this.lastUpdateTime.delete(peerId);
|
|
130
|
+
} else {
|
|
131
|
+
this.scores.set(peerId, score);
|
|
132
|
+
this.lastUpdateTime.set(peerId, currentTime);
|
|
133
|
+
}
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
}
|
|
126
137
|
|
|
138
|
+
/** Resets all peer scores. Useful for benchmarks to prevent cross-case contamination. */
|
|
139
|
+
resetAllScores(): void {
|
|
140
|
+
this.scores.clear();
|
|
141
|
+
this.lastUpdateTime.clear();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
removePeer(peerId: string): void {
|
|
145
|
+
this.scores.delete(peerId);
|
|
146
|
+
this.lastUpdateTime.delete(peerId);
|
|
147
|
+
}
|
|
148
|
+
|
|
127
149
|
getScore(peerId: string): number {
|
|
128
150
|
return this.scores.get(peerId) || 0;
|
|
129
151
|
}
|
|
@@ -170,6 +170,37 @@ class BlockTxsResponse {
|
|
|
170
170
|
|
|
171
171
|
The `BitVector` is a compact representation where each bit corresponds to a transaction index in the block proposal. This allows efficient capability advertisement without repeating full hashes.
|
|
172
172
|
|
|
173
|
+
## Cancellation
|
|
174
|
+
|
|
175
|
+
All cancellation is managed by a single `RequestTracker` instance, shared across the entire collection
|
|
176
|
+
flow. The `RequestTracker` owns the deadline, tracks which txs are still missing, and exposes a
|
|
177
|
+
`cancellationToken` promise that resolves when the request should stop (deadline hit, all txs fetched,
|
|
178
|
+
or external `cancel()` call).
|
|
179
|
+
|
|
180
|
+
Cancellation propagates from the deepest stack level upward:
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
RequestTracker.finish()
|
|
184
|
+
├── resolves cancellationToken promise
|
|
185
|
+
│
|
|
186
|
+
├── BatchTxRequester workers (deepest)
|
|
187
|
+
│ ├── shouldStop() checks requestTracker.cancelled → exit loop
|
|
188
|
+
│ ├── sleepClampedToDeadline races sleep vs cancellationToken → wakes
|
|
189
|
+
│ └── semaphore.acquire races vs cancellationToken → wakes
|
|
190
|
+
│ │
|
|
191
|
+
│ ▼ workers settle → txQueue.end() → generator returns
|
|
192
|
+
│
|
|
193
|
+
├── Node collection loops
|
|
194
|
+
│ ├── notFinished() checks requestTracker.cancelled → exit loop
|
|
195
|
+
│ └── inter-retry sleep races vs cancellationToken → wakes
|
|
196
|
+
│ │
|
|
197
|
+
│ ▼ all node loops settle
|
|
198
|
+
│
|
|
199
|
+
└── collectFast (outermost)
|
|
200
|
+
awaits Promise.allSettled([reqresp, nodes]) → settles after inner tasks
|
|
201
|
+
finally: requestTracker.cancel() (idempotent), cleanup
|
|
202
|
+
```
|
|
203
|
+
|
|
173
204
|
## Key Files
|
|
174
205
|
|
|
175
206
|
| File | Description |
|
|
@@ -179,15 +210,16 @@ The `BitVector` is a compact representation where each bit corresponds to a tran
|
|
|
179
210
|
| `peer_collection.ts` | Manages peer classification (dumb/smart/bad) and rate limiting |
|
|
180
211
|
| `interface.ts` | Type definitions for dependencies |
|
|
181
212
|
| `../protocols/block_txs/` | Wire protocol definitions (`BlockTxsRequest`, `BlockTxsResponse`, `BitVector`) |
|
|
213
|
+
| `../../tx_collection/request_tracker.ts` | Centralized deadline, missing tx tracking, and cancellation signal |
|
|
182
214
|
|
|
183
215
|
## Stopping Conditions
|
|
184
216
|
|
|
185
|
-
The `BatchTxRequester` stops when any of these conditions are met
|
|
217
|
+
The `BatchTxRequester` stops when any of these conditions are met, all managed by the `RequestTracker`:
|
|
186
218
|
|
|
187
|
-
1. **All transactions fetched** -
|
|
188
|
-
2. **Deadline exceeded** -
|
|
189
|
-
3. **
|
|
190
|
-
4. **No transactions to fetch** -
|
|
219
|
+
1. **All transactions fetched** - `markFetched()` removes the last missing tx, triggering `finish()`
|
|
220
|
+
2. **Deadline exceeded** - `setTimeout` in `RequestTracker` fires, triggering `finish()`
|
|
221
|
+
3. **External cancellation** - `RequestTracker.cancel()` called (e.g., from `stop()`, `stopCollectingForBlocksUpTo`)
|
|
222
|
+
4. **No transactions to fetch** - Empty hash set at construction, `RequestTracker` finishes immediately
|
|
191
223
|
|
|
192
224
|
## Configuration
|
|
193
225
|
|
|
@@ -228,11 +260,15 @@ Request to peer fails
|
|
|
228
260
|
## Usage Example
|
|
229
261
|
|
|
230
262
|
```typescript
|
|
263
|
+
const requestTracker = RequestTracker.create(
|
|
264
|
+
missingTxHashes, // TxHash[] - what we need
|
|
265
|
+
new Date(Date.now() + 5_000), // deadline
|
|
266
|
+
);
|
|
267
|
+
|
|
231
268
|
const requester = new BatchTxRequester(
|
|
232
|
-
|
|
269
|
+
requestTracker, // IRequestTracker - tracks missing txs, deadline, and cancellation
|
|
233
270
|
blockTxsSource, // BlockTxsSource - the proposal or block we need txs for
|
|
234
271
|
pinnedPeer, // PeerId | undefined - peer expected to have the txs
|
|
235
|
-
timeoutMs, // number - how long to try
|
|
236
272
|
p2pService, // BatchTxRequesterLibP2PService
|
|
237
273
|
);
|
|
238
274
|
|
|
@@ -273,6 +309,8 @@ const txs = await BatchTxRequester.collectAllTxs(requester.run());
|
|
|
273
309
|
│ 1. Try RPC nodes first (fast) │ │ Periodic polling of RPC nodes │
|
|
274
310
|
│ 2. Fall back to BatchTxRequester │ │ and peers for missing txs │
|
|
275
311
|
│ │ │ │
|
|
312
|
+
│ Creates RequestTracker per │ │ │
|
|
313
|
+
│ request with deadline │ │ │
|
|
276
314
|
└───────────────────┬───────────────┘ └─────────────────────────────────────┘
|
|
277
315
|
│
|
|
278
316
|
│ For 'proposal' and 'block' requests
|
|
@@ -281,6 +319,7 @@ const txs = await BatchTxRequester.collectAllTxs(requester.run());
|
|
|
281
319
|
│ BatchTxRequester │
|
|
282
320
|
│ │
|
|
283
321
|
│ Aggressive parallel fetching from multiple peers │
|
|
322
|
+
│ Shares RequestTracker with FastTxCollection for unified cancellation │
|
|
284
323
|
│ Uses BLOCK_TXS sub-protocol for efficient batching │
|
|
285
324
|
└───────────────────┬─────────────────────────────────────────────────────────┘
|
|
286
325
|
│
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { chunkWrapAround } from '@aztec/foundation/collection';
|
|
2
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
3
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
3
|
import { FifoMemoryQueue, type ISemaphore, Semaphore } from '@aztec/foundation/queue';
|
|
5
4
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
|
-
import { DateProvider
|
|
5
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
7
6
|
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
8
7
|
import { Tx, TxArray, TxHash } from '@aztec/stdlib/tx';
|
|
9
8
|
|
|
10
9
|
import type { PeerId } from '@libp2p/interface';
|
|
11
10
|
|
|
12
|
-
import type {
|
|
11
|
+
import type { IRequestTracker } from '../../tx_collection/request_tracker.js';
|
|
13
12
|
import { ReqRespSubProtocol } from '.././interface.js';
|
|
14
13
|
import { BlockTxsRequest, BlockTxsResponse, type BlockTxsSource } from '.././protocols/index.js';
|
|
15
14
|
import { ReqRespStatus } from '.././status.js';
|
|
@@ -42,16 +41,14 @@ import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_val
|
|
|
42
41
|
* - Is the peer which was unable to send us successful response N times in a row
|
|
43
42
|
* */
|
|
44
43
|
export class BatchTxRequester {
|
|
44
|
+
private readonly requestTracker: IRequestTracker;
|
|
45
45
|
private readonly blockTxsSource: BlockTxsSource;
|
|
46
46
|
private readonly pinnedPeer: PeerId | undefined;
|
|
47
|
-
private readonly timeoutMs: number;
|
|
48
47
|
private readonly p2pService: BatchTxRequesterLibP2PService;
|
|
49
48
|
private readonly logger: Logger;
|
|
50
|
-
private readonly dateProvider: DateProvider;
|
|
51
49
|
private readonly opts: BatchTxRequesterOptions;
|
|
52
50
|
private readonly peers: IPeerCollection;
|
|
53
51
|
private readonly txsMetadata: ITxMetadataCollection;
|
|
54
|
-
private readonly deadline: number;
|
|
55
52
|
private readonly smartRequesterSemaphore: ISemaphore;
|
|
56
53
|
private readonly txQueue: FifoMemoryQueue<Tx>;
|
|
57
54
|
private readonly txValidator: IBatchRequestTxValidator;
|
|
@@ -60,21 +57,19 @@ export class BatchTxRequester {
|
|
|
60
57
|
private readonly txBatchSize: number;
|
|
61
58
|
|
|
62
59
|
constructor(
|
|
63
|
-
|
|
60
|
+
requestTracker: IRequestTracker,
|
|
64
61
|
blockTxsSource: BlockTxsSource,
|
|
65
62
|
pinnedPeer: PeerId | undefined,
|
|
66
|
-
timeoutMs: number,
|
|
67
63
|
p2pService: BatchTxRequesterLibP2PService,
|
|
68
64
|
logger?: Logger,
|
|
69
65
|
dateProvider?: DateProvider,
|
|
70
66
|
opts?: BatchTxRequesterOptions,
|
|
71
67
|
) {
|
|
68
|
+
this.requestTracker = requestTracker;
|
|
72
69
|
this.blockTxsSource = blockTxsSource;
|
|
73
70
|
this.pinnedPeer = pinnedPeer;
|
|
74
|
-
this.timeoutMs = timeoutMs;
|
|
75
71
|
this.p2pService = p2pService;
|
|
76
72
|
this.logger = logger ?? createLogger('p2p:reqresp_batch');
|
|
77
|
-
this.dateProvider = dateProvider ?? new DateProvider();
|
|
78
73
|
this.opts = opts ?? {};
|
|
79
74
|
|
|
80
75
|
this.smartParallelWorkerCount =
|
|
@@ -82,7 +77,6 @@ export class BatchTxRequester {
|
|
|
82
77
|
this.dumbParallelWorkerCount =
|
|
83
78
|
this.opts.dumbParallelWorkerCount ?? DEFAULT_BATCH_TX_REQUESTER_DUMB_PARALLEL_WORKER_COUNT;
|
|
84
79
|
this.txBatchSize = this.opts.txBatchSize ?? DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE;
|
|
85
|
-
this.deadline = this.dateProvider.now() + this.timeoutMs;
|
|
86
80
|
this.txQueue = new FifoMemoryQueue(this.logger);
|
|
87
81
|
this.txValidator = this.opts.txValidator ?? new BatchRequestTxValidator(this.p2pService.txValidatorConfig);
|
|
88
82
|
|
|
@@ -93,12 +87,12 @@ export class BatchTxRequester {
|
|
|
93
87
|
this.peers = new PeerCollection(
|
|
94
88
|
this.p2pService.connectionSampler,
|
|
95
89
|
this.pinnedPeer,
|
|
96
|
-
|
|
90
|
+
dateProvider ?? new DateProvider(),
|
|
97
91
|
badPeerThreshold,
|
|
98
92
|
this.p2pService.peerScoring,
|
|
99
93
|
);
|
|
100
94
|
}
|
|
101
|
-
this.txsMetadata = new MissingTxMetadataCollection(
|
|
95
|
+
this.txsMetadata = new MissingTxMetadataCollection(requestTracker, this.txBatchSize);
|
|
102
96
|
this.smartRequesterSemaphore = this.opts.semaphore ?? new Semaphore(0);
|
|
103
97
|
}
|
|
104
98
|
|
|
@@ -106,40 +100,30 @@ export class BatchTxRequester {
|
|
|
106
100
|
* Fetches all missing transactions and yields them one by one
|
|
107
101
|
* */
|
|
108
102
|
public async *run(): AsyncGenerator<Tx, Tx | undefined, unknown> {
|
|
109
|
-
// Our timeout is represented in milliseconds but queue expects seconds
|
|
110
|
-
// We also want to make sure we wait at least 1 second in case of very low timeouts
|
|
111
|
-
const timeoutQueueAfter = Math.max(Math.ceil(this.timeoutMs / 1_000), 1);
|
|
112
103
|
try {
|
|
113
104
|
if (this.txsMetadata.getMissingTxHashes().size === 0) {
|
|
114
105
|
return undefined;
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
// Start workers in background
|
|
118
|
-
const workersPromise =
|
|
119
|
-
|
|
120
|
-
this.
|
|
121
|
-
|
|
108
|
+
// Start workers in background. Workers stop themselves via requestTracker.checkCancelled().
|
|
109
|
+
const workersPromise = Promise.allSettled([
|
|
110
|
+
this.smartRequester(),
|
|
111
|
+
this.dumbRequester(),
|
|
112
|
+
this.pinnedPeerRequester(),
|
|
113
|
+
]).finally(() => {
|
|
122
114
|
this.txQueue.end();
|
|
123
115
|
});
|
|
124
116
|
|
|
117
|
+
// Yield txs as workers put them on the queue. The queue's end() drains remaining items
|
|
118
|
+
// before returning null, so we don't lose any txs.
|
|
125
119
|
while (true) {
|
|
126
|
-
const tx = await this.txQueue.get(
|
|
120
|
+
const tx = await this.txQueue.get();
|
|
127
121
|
|
|
128
|
-
// null indicates that the queue has ended
|
|
129
122
|
if (tx === null) {
|
|
130
123
|
break;
|
|
131
124
|
}
|
|
132
125
|
|
|
133
126
|
yield tx;
|
|
134
|
-
|
|
135
|
-
if (this.shouldStop()) {
|
|
136
|
-
// Drain queue before ending
|
|
137
|
-
let remaining;
|
|
138
|
-
while ((remaining = this.txQueue.getImmediate()) !== undefined) {
|
|
139
|
-
yield remaining;
|
|
140
|
-
}
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
127
|
}
|
|
144
128
|
|
|
145
129
|
this.unlockSmartRequesterSemaphores();
|
|
@@ -360,7 +344,10 @@ export class BatchTxRequester {
|
|
|
360
344
|
) {
|
|
361
345
|
try {
|
|
362
346
|
this.logger.trace(`Smart worker ${workerIndex} started`);
|
|
363
|
-
await
|
|
347
|
+
await Promise.race([this.smartRequesterSemaphore.acquire(), this.requestTracker.cancellationToken]);
|
|
348
|
+
if (this.requestTracker.checkCancelled()) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
364
351
|
this.logger.trace(`Smart worker ${workerIndex} acquired semaphore`);
|
|
365
352
|
|
|
366
353
|
while (!this.shouldStop()) {
|
|
@@ -384,7 +371,10 @@ export class BatchTxRequester {
|
|
|
384
371
|
//
|
|
385
372
|
// When a dumb peer responds with valid txIndices, it gets
|
|
386
373
|
// promoted to smart and releases the semaphore, waking this worker.
|
|
387
|
-
await
|
|
374
|
+
await Promise.race([this.smartRequesterSemaphore.acquire(), this.requestTracker.cancellationToken]);
|
|
375
|
+
if (this.requestTracker.checkCancelled()) {
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
388
378
|
this.logger.debug(`Worker loop smart: acquired next smart peer`);
|
|
389
379
|
continue;
|
|
390
380
|
}
|
|
@@ -411,11 +401,7 @@ export class BatchTxRequester {
|
|
|
411
401
|
});
|
|
412
402
|
}
|
|
413
403
|
} catch (err: any) {
|
|
414
|
-
|
|
415
|
-
this.logger.debug(`Smart worker ${workerIndex} timed out waiting for semaphore`);
|
|
416
|
-
} else {
|
|
417
|
-
this.logger.error(`Smart worker ${workerIndex} encountered an error: ${err}`);
|
|
418
|
-
}
|
|
404
|
+
this.logger.error(`Smart worker ${workerIndex} encountered an error: ${err}`);
|
|
419
405
|
} finally {
|
|
420
406
|
this.logger.debug(`Smart worker ${workerIndex} finished`);
|
|
421
407
|
}
|
|
@@ -528,6 +514,9 @@ export class BatchTxRequester {
|
|
|
528
514
|
});
|
|
529
515
|
|
|
530
516
|
if (hasInvalidTx) {
|
|
517
|
+
this.logger.warn(`Penalizing peer ${peerId.toString()} for sending invalid transactions in batch response`, {
|
|
518
|
+
peerId,
|
|
519
|
+
});
|
|
531
520
|
this.peers.penalisePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
532
521
|
} else {
|
|
533
522
|
// If we have received successful response from the peer, they have "redeemed" themselves and not considered bad anymore
|
|
@@ -651,27 +640,14 @@ export class BatchTxRequester {
|
|
|
651
640
|
}
|
|
652
641
|
|
|
653
642
|
/*
|
|
654
|
-
*
|
|
655
|
-
|
|
656
|
-
return this.txsMetadata.getMissingTxHashes().size == 0;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/*
|
|
660
|
-
* Checks if the BatchTxRequester should stop fetching missing txs
|
|
661
|
-
* Conditions for stopping are:
|
|
662
|
-
* - There have been no missing transactions to start with
|
|
663
|
-
* - All transactions have been fetched
|
|
664
|
-
* - The deadline has been hit (no more time to fetch)
|
|
665
|
-
* - This process has been cancelled via abortSignal
|
|
666
|
-
*
|
|
667
|
-
* @returns true if BatchTxRequester should stop, otherwise false*/
|
|
643
|
+
* Checks if the BatchTxRequester should stop fetching missing txs.
|
|
644
|
+
* Delegates to requestTracker which covers: deadline hit, all txs fetched, or external cancellation. */
|
|
668
645
|
private shouldStop() {
|
|
669
|
-
|
|
670
|
-
if (aborted) {
|
|
646
|
+
if (this.requestTracker.checkCancelled()) {
|
|
671
647
|
this.unlockSmartRequesterSemaphores();
|
|
672
648
|
}
|
|
673
649
|
|
|
674
|
-
return
|
|
650
|
+
return this.requestTracker.checkCancelled();
|
|
675
651
|
}
|
|
676
652
|
|
|
677
653
|
/*
|
|
@@ -689,10 +665,9 @@ export class BatchTxRequester {
|
|
|
689
665
|
* This ensures we don't sleep past the deadline.
|
|
690
666
|
* */
|
|
691
667
|
private async sleepClampedToDeadline(durationMs: number) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if (thereIsTimeRemaining) {
|
|
695
|
-
await sleep(Math.min(durationMs, remaining));
|
|
668
|
+
if (this.requestTracker.checkCancelled()) {
|
|
669
|
+
return;
|
|
696
670
|
}
|
|
671
|
+
await Promise.race([sleep(durationMs), this.requestTracker.cancellationToken]);
|
|
697
672
|
}
|
|
698
673
|
}
|
|
@@ -49,7 +49,6 @@ export interface BatchTxRequesterOptions {
|
|
|
49
49
|
//Injectable for testing purposes
|
|
50
50
|
semaphore?: ISemaphore;
|
|
51
51
|
peerCollection?: IPeerCollection;
|
|
52
|
-
abortSignal?: AbortSignal;
|
|
53
52
|
/** Optional tx validator for testing - if not provided, one is created from p2pService.txValidatorConfig */
|
|
54
53
|
txValidator?: IBatchRequestTxValidator;
|
|
55
54
|
}
|
|
@@ -2,7 +2,7 @@ import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
|
2
2
|
|
|
3
3
|
import type { PeerId } from '@libp2p/interface';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { IRequestTracker } from '../../tx_collection/request_tracker.js';
|
|
6
6
|
import { DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE } from './config.js';
|
|
7
7
|
import type { ITxMetadataCollection } from './interface.js';
|
|
8
8
|
|
|
@@ -41,10 +41,10 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
|
|
|
41
41
|
private txMetadata = new Map<string, MissingTxMetadata>();
|
|
42
42
|
|
|
43
43
|
constructor(
|
|
44
|
-
private
|
|
44
|
+
private requestTracker: IRequestTracker,
|
|
45
45
|
private readonly txBatchSize: number = DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE,
|
|
46
46
|
) {
|
|
47
|
-
|
|
47
|
+
requestTracker.missingTxHashes.forEach(hash => this.txMetadata.set(hash, new MissingTxMetadata(hash)));
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
public getPrioritizingNotInFlightAndLowerRequestCount(txs: string[]): MissingTxMetadata[] {
|
|
@@ -65,7 +65,7 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
public getMissingTxHashes(): Set<string> {
|
|
68
|
-
return this.
|
|
68
|
+
return this.requestTracker.missingTxHashes;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
public getTxsPeerHas(peer: PeerId): Set<string> {
|
|
@@ -128,7 +128,7 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
public alreadyFetched(txHash: TxHash): boolean {
|
|
131
|
-
return !this.
|
|
131
|
+
return !this.requestTracker.isMissing(txHash.toString());
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
public markFetched(peerId: PeerId, tx: Tx): boolean {
|
|
@@ -144,7 +144,7 @@ export class MissingTxMetadataCollection implements ITxMetadataCollection {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
txMeta.peers.add(peerId.toString());
|
|
147
|
-
return this.
|
|
147
|
+
return this.requestTracker.markFetched(tx);
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
public markPeerHas(peerId: PeerId, txHash: TxHash[]) {
|
|
@@ -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
|
}
|