@aztec/p2p 0.0.1-commit.4d79d1f2d → 0.0.1-commit.5358163d3
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 +6 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +23 -30
- package/dest/client/interface.d.ts +14 -19
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +9 -18
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +52 -72
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
- package/dest/config.d.ts +20 -14
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +30 -35
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -2
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +10 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -2
- package/dest/mem_pools/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/eviction/invalid_txs_after_mining_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +30 -13
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +91 -20
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +20 -6
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +34 -8
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +76 -10
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +36 -14
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
- 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 +14 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
- 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 +299 -142
- 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 +10 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +166 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -10
- package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +219 -58
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +25 -24
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/dummy_service.d.ts +4 -4
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +4 -4
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +9 -8
- package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +32 -10
- package/dest/services/libp2p/libp2p_service.d.ts +16 -13
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +77 -84
- 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 +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +2 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -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 +49 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +2 -1
- package/dest/services/service.d.ts +5 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +13 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +30 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +39 -33
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +38 -29
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +126 -77
- package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -6
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +49 -16
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +17 -12
- package/dest/services/tx_collection/tx_collection.d.ts +9 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +26 -10
- package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +13 -22
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/tx_file_store.d.ts +3 -2
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +9 -6
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +8 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +8 -3
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +7 -1
- package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +13 -13
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +39 -48
- package/src/client/interface.ts +17 -20
- package/src/client/p2p_client.ts +60 -104
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
- package/src/config.ts +44 -42
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +13 -4
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool/README.md +1 -1
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/README.md +43 -27
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +109 -22
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +21 -6
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +107 -17
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +21 -7
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +331 -138
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +1 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +1 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +15 -1
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +144 -1
- package/src/msg_validators/tx_validator/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +27 -13
- package/src/msg_validators/tx_validator/factory.ts +353 -77
- package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +25 -29
- package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
- package/src/services/dummy_service.ts +6 -6
- package/src/services/encoding.ts +7 -7
- package/src/services/gossipsub/README.md +29 -14
- package/src/services/gossipsub/topic_score_params.ts +49 -13
- package/src/services/libp2p/libp2p_service.ts +89 -92
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
- package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/reqresp.ts +3 -1
- package/src/services/service.ts +11 -2
- package/src/services/tx_collection/config.ts +42 -0
- package/src/services/tx_collection/fast_tx_collection.ts +51 -30
- package/src/services/tx_collection/file_store_tx_collection.ts +143 -93
- package/src/services/tx_collection/file_store_tx_source.ts +64 -17
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
- package/src/services/tx_collection/slow_tx_collection.ts +17 -13
- package/src/services/tx_collection/tx_collection.ts +45 -14
- package/src/services/tx_collection/tx_collection_sink.ts +15 -29
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/tx_file_store.ts +6 -4
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +0 -2
- package/src/test-helpers/mock-pubsub.ts +13 -6
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/test-helpers/testbench-utils.ts +11 -3
- package/src/testbench/p2p_client_testbench_worker.ts +22 -19
- package/src/util.ts +7 -1
|
@@ -16,13 +16,12 @@ import {
|
|
|
16
16
|
CheckpointProposal,
|
|
17
17
|
type CheckpointProposalCore,
|
|
18
18
|
type Gossipable,
|
|
19
|
-
P2PClientType,
|
|
20
19
|
P2PMessage,
|
|
21
20
|
type ValidationResult as P2PValidationResult,
|
|
22
21
|
PeerErrorSeverity,
|
|
23
22
|
TopicType,
|
|
24
23
|
createTopicString,
|
|
25
|
-
|
|
24
|
+
getTopicsForConfig,
|
|
26
25
|
metricsTopicStrToLabels,
|
|
27
26
|
} from '@aztec/stdlib/p2p';
|
|
28
27
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
@@ -69,9 +68,11 @@ import {
|
|
|
69
68
|
} from '../../msg_validators/index.js';
|
|
70
69
|
import { MessageSeenValidator } from '../../msg_validators/msg_seen_validator/msg_seen_validator.js';
|
|
71
70
|
import {
|
|
72
|
-
type
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
type TransactionValidator,
|
|
72
|
+
createFirstStageTxValidationsForGossipedTransactions,
|
|
73
|
+
createSecondStageTxValidationsForGossipedTransactions,
|
|
74
|
+
createTxValidatorForBlockProposalReceivedTxs,
|
|
75
|
+
createTxValidatorForReqResponseReceivedTxs,
|
|
75
76
|
} from '../../msg_validators/tx_validator/factory.js';
|
|
76
77
|
import { GossipSubEvent } from '../../types/index.js';
|
|
77
78
|
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
@@ -87,6 +88,9 @@ import { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
|
87
88
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
88
89
|
import type { P2PReqRespConfig } from '../reqresp/config.js';
|
|
89
90
|
import {
|
|
91
|
+
AuthRequest,
|
|
92
|
+
BlockTxsRequest,
|
|
93
|
+
BlockTxsResponse,
|
|
90
94
|
DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
91
95
|
type ReqRespInterface,
|
|
92
96
|
type ReqRespResponse,
|
|
@@ -94,14 +98,9 @@ import {
|
|
|
94
98
|
type ReqRespSubProtocolHandler,
|
|
95
99
|
type ReqRespSubProtocolHandlers,
|
|
96
100
|
type ReqRespSubProtocolValidators,
|
|
101
|
+
StatusMessage,
|
|
97
102
|
type SubProtocolMap,
|
|
98
103
|
ValidationError,
|
|
99
|
-
} from '../reqresp/index.js';
|
|
100
|
-
import {
|
|
101
|
-
AuthRequest,
|
|
102
|
-
BlockTxsRequest,
|
|
103
|
-
BlockTxsResponse,
|
|
104
|
-
StatusMessage,
|
|
105
104
|
pingHandler,
|
|
106
105
|
reqGoodbyeHandler,
|
|
107
106
|
reqRespBlockHandler,
|
|
@@ -135,7 +134,7 @@ type ReceivedMessageValidationResult<T, M = undefined> =
|
|
|
135
134
|
/**
|
|
136
135
|
* Lib P2P implementation of the P2PService interface.
|
|
137
136
|
*/
|
|
138
|
-
export class LibP2PService
|
|
137
|
+
export class LibP2PService extends WithTracer implements P2PService {
|
|
139
138
|
private discoveryRunningPromise?: RunningPromise;
|
|
140
139
|
private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
|
|
141
140
|
|
|
@@ -182,7 +181,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
182
181
|
protected logger: Logger;
|
|
183
182
|
|
|
184
183
|
constructor(
|
|
185
|
-
private clientType: T,
|
|
186
184
|
private config: P2PConfig,
|
|
187
185
|
protected node: PubSubLibp2p,
|
|
188
186
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
@@ -224,9 +222,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
224
222
|
this.protocolVersion,
|
|
225
223
|
);
|
|
226
224
|
|
|
227
|
-
this.blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
225
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
226
|
+
txsPermitted: !config.disableTransactions,
|
|
227
|
+
maxTxsPerBlock: config.maxTxsPerBlock,
|
|
228
|
+
});
|
|
228
229
|
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
|
|
229
230
|
txsPermitted: !config.disableTransactions,
|
|
231
|
+
maxTxsPerBlock: config.maxTxsPerBlock,
|
|
230
232
|
});
|
|
231
233
|
this.checkpointAttestationValidator = config.fishermanMode
|
|
232
234
|
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
@@ -262,8 +264,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
262
264
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
263
265
|
* @returns The new service.
|
|
264
266
|
*/
|
|
265
|
-
public static async new
|
|
266
|
-
clientType: T,
|
|
267
|
+
public static async new(
|
|
267
268
|
config: P2PConfig,
|
|
268
269
|
peerId: PeerId,
|
|
269
270
|
deps: {
|
|
@@ -341,6 +342,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
341
342
|
heartbeatIntervalMs: config.gossipsubInterval,
|
|
342
343
|
targetCommitteeSize: l1Constants.targetCommitteeSize,
|
|
343
344
|
blockDurationMs: config.blockDurationMs,
|
|
345
|
+
expectedBlockProposalsPerSlot: config.expectedBlockProposalsPerSlot,
|
|
344
346
|
});
|
|
345
347
|
|
|
346
348
|
const node = await createLibp2p({
|
|
@@ -474,7 +476,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
474
476
|
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
475
477
|
|
|
476
478
|
return new LibP2PService(
|
|
477
|
-
clientType,
|
|
478
479
|
config,
|
|
479
480
|
node,
|
|
480
481
|
peerDiscoveryService,
|
|
@@ -548,7 +549,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
548
549
|
await this.node.start();
|
|
549
550
|
|
|
550
551
|
// Subscribe to standard GossipSub topics by default
|
|
551
|
-
for (const topic of
|
|
552
|
+
for (const topic of getTopicsForConfig(this.config.disableTransactions)) {
|
|
552
553
|
this.subscribeToTopic(this.topicStrings[topic]);
|
|
553
554
|
}
|
|
554
555
|
|
|
@@ -614,6 +615,10 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
614
615
|
return this.peerManager.getPeers(includePending);
|
|
615
616
|
}
|
|
616
617
|
|
|
618
|
+
public getGossipMeshPeerCount(topicType: TopicType): number {
|
|
619
|
+
return this.node.services.pubsub.getMeshPeers(this.topicStrings[topicType]).length;
|
|
620
|
+
}
|
|
621
|
+
|
|
617
622
|
private handleGossipSubEvent(e: CustomEvent<GossipsubMessage>) {
|
|
618
623
|
this.logger.trace(`Received PUBSUB message.`);
|
|
619
624
|
|
|
@@ -813,9 +818,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
813
818
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
814
819
|
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
815
820
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
816
|
-
|
|
817
|
-
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
818
|
-
}
|
|
821
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
819
822
|
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
820
823
|
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
821
824
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
@@ -901,15 +904,45 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
901
904
|
protected async handleGossipedTx(payloadData: Buffer, msgId: string, source: PeerId) {
|
|
902
905
|
const validationFunc: () => Promise<ReceivedMessageValidationResult<Tx>> = async () => {
|
|
903
906
|
const tx = Tx.fromBuffer(payloadData);
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
907
|
+
|
|
908
|
+
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
909
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
910
|
+
|
|
911
|
+
// Stage 1: fast validators (metadata, data, timestamps, double-spend, gas, phases, block header)
|
|
912
|
+
const firstStageValidators = await this.createFirstStageMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
913
|
+
const firstStageOutcome = await this.runValidations(tx, firstStageValidators);
|
|
914
|
+
if (!firstStageOutcome.allPassed) {
|
|
915
|
+
const { name } = firstStageOutcome.failure;
|
|
916
|
+
let { severity } = firstStageOutcome.failure;
|
|
917
|
+
|
|
918
|
+
// Double spend validator has a special case handler. We perform more detailed examination
|
|
919
|
+
// as to how recently the nullifier was entered into the tree and if the transaction should
|
|
920
|
+
// have 'known' the nullifier existed. This determines the severity of the penalty applied to the peer.
|
|
921
|
+
if (name === 'doubleSpendValidator') {
|
|
922
|
+
const txBlockNumber = BlockNumber(currentBlockNumber + 1);
|
|
923
|
+
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
this.peerManager.penalizePeer(source, severity);
|
|
909
927
|
return { result: TopicValidatorResult.Reject };
|
|
910
928
|
}
|
|
911
929
|
|
|
912
|
-
//
|
|
930
|
+
// Pool pre-check: see if the pool would accept this tx before doing expensive proof verification
|
|
931
|
+
const canAdd = await this.mempools.txPool.canAddPendingTx(tx);
|
|
932
|
+
if (canAdd === 'ignored') {
|
|
933
|
+
return { result: TopicValidatorResult.Ignore, obj: tx };
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// Stage 2: expensive proof verification
|
|
937
|
+
const secondStageValidators = this.createSecondStageMessageValidators();
|
|
938
|
+
const secondStageOutcome = await this.runValidations(tx, secondStageValidators);
|
|
939
|
+
if (!secondStageOutcome.allPassed) {
|
|
940
|
+
const { severity } = secondStageOutcome.failure;
|
|
941
|
+
this.peerManager.penalizePeer(source, severity);
|
|
942
|
+
return { result: TopicValidatorResult.Reject };
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// Pool add: persist the tx
|
|
913
946
|
const txHash = tx.getTxHash();
|
|
914
947
|
const addResult = await this.mempools.txPool.addPendingTxs([tx], { source: 'gossip' });
|
|
915
948
|
|
|
@@ -917,7 +950,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
917
950
|
const wasIgnored = addResult.ignored.some(h => h.equals(txHash));
|
|
918
951
|
|
|
919
952
|
this.logger.trace(`Validate propagated tx`, {
|
|
920
|
-
isValid,
|
|
921
953
|
wasAccepted,
|
|
922
954
|
wasIgnored,
|
|
923
955
|
[Attributes.P2P_ID]: source.toString(),
|
|
@@ -1532,43 +1564,12 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1532
1564
|
}
|
|
1533
1565
|
|
|
1534
1566
|
protected createRequestedTxValidator(): TxValidator {
|
|
1535
|
-
return
|
|
1567
|
+
return createTxValidatorForReqResponseReceivedTxs(this.proofVerifier, {
|
|
1536
1568
|
l1ChainId: this.config.l1ChainId,
|
|
1537
1569
|
rollupVersion: this.config.rollupVersion,
|
|
1538
1570
|
});
|
|
1539
1571
|
}
|
|
1540
1572
|
|
|
1541
|
-
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
1542
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1543
|
-
}))
|
|
1544
|
-
protected async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
|
|
1545
|
-
const currentBlockNumber = await this.archiver.getBlockNumber();
|
|
1546
|
-
|
|
1547
|
-
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1548
|
-
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1549
|
-
const messageValidators = await this.createMessageValidators(currentBlockNumber, nextSlotTimestamp);
|
|
1550
|
-
|
|
1551
|
-
for (const validator of messageValidators) {
|
|
1552
|
-
const outcome = await this.runValidations(tx, validator);
|
|
1553
|
-
|
|
1554
|
-
if (outcome.allPassed) {
|
|
1555
|
-
continue;
|
|
1556
|
-
}
|
|
1557
|
-
const { name } = outcome.failure;
|
|
1558
|
-
let { severity } = outcome.failure;
|
|
1559
|
-
|
|
1560
|
-
// Double spend validator has a special case handler
|
|
1561
|
-
if (name === 'doubleSpendValidator') {
|
|
1562
|
-
const txBlockNumber = BlockNumber(currentBlockNumber + 1); // tx is expected to be in the next block
|
|
1563
|
-
severity = await this.handleDoubleSpendFailure(tx, txBlockNumber);
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
this.peerManager.penalizePeer(peerId, severity);
|
|
1567
|
-
return false;
|
|
1568
|
-
}
|
|
1569
|
-
return true;
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
1573
|
private async getGasFees(blockNumber: BlockNumber): Promise<GasFees> {
|
|
1573
1574
|
if (blockNumber === this.feesCache?.blockNumber) {
|
|
1574
1575
|
return this.feesCache.gasFees;
|
|
@@ -1596,60 +1597,56 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1596
1597
|
};
|
|
1597
1598
|
}
|
|
1598
1599
|
|
|
1599
|
-
public async
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1600
|
+
public async validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
1601
|
+
const validator = createTxValidatorForBlockProposalReceivedTxs(
|
|
1602
|
+
this.proofVerifier,
|
|
1603
|
+
{ l1ChainId: this.config.l1ChainId, rollupVersion: this.config.rollupVersion },
|
|
1604
|
+
this.logger.getBindings(),
|
|
1605
|
+
);
|
|
1605
1606
|
|
|
1606
|
-
await Promise.all(
|
|
1607
|
+
const results = await Promise.all(
|
|
1607
1608
|
txs.map(async tx => {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
if (!outcome.allPassed) {
|
|
1611
|
-
throw new Error('Invalid tx detected', { cause: { outcome } });
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1609
|
+
const result = await validator.validateTx(tx);
|
|
1610
|
+
return result.result !== 'invalid';
|
|
1614
1611
|
}),
|
|
1615
1612
|
);
|
|
1613
|
+
if (results.some(value => value === false)) {
|
|
1614
|
+
throw new Error('Invalid tx detected');
|
|
1615
|
+
}
|
|
1616
1616
|
}
|
|
1617
1617
|
|
|
1618
|
-
/**
|
|
1619
|
-
|
|
1620
|
-
*
|
|
1621
|
-
* Each validator is a pair of a validator and a severity.
|
|
1622
|
-
* If a validator fails, the peer is penalized with the severity of the validator.
|
|
1623
|
-
*
|
|
1624
|
-
* @param currentBlockNumber - The current synced block number.
|
|
1625
|
-
* @param nextSlotTimestamp - The timestamp of the next slot (used to validate txs are not expired).
|
|
1626
|
-
* @returns The message validators.
|
|
1627
|
-
*/
|
|
1628
|
-
private async createMessageValidators(
|
|
1618
|
+
/** Creates the first stage (fast) validators for gossiped transactions. */
|
|
1619
|
+
protected async createFirstStageMessageValidators(
|
|
1629
1620
|
currentBlockNumber: BlockNumber,
|
|
1630
1621
|
nextSlotTimestamp: UInt64,
|
|
1631
|
-
): Promise<Record<string,
|
|
1622
|
+
): Promise<Record<string, TransactionValidator>> {
|
|
1632
1623
|
const gasFees = await this.getGasFees(currentBlockNumber);
|
|
1633
|
-
const allowedInSetup =
|
|
1634
|
-
|
|
1635
|
-
|
|
1624
|
+
const allowedInSetup = [
|
|
1625
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1626
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1627
|
+
];
|
|
1628
|
+
const blockNumber = BlockNumber(currentBlockNumber + 1);
|
|
1636
1629
|
|
|
1637
|
-
return
|
|
1630
|
+
return createFirstStageTxValidationsForGossipedTransactions(
|
|
1638
1631
|
nextSlotTimestamp,
|
|
1639
|
-
|
|
1632
|
+
blockNumber,
|
|
1640
1633
|
this.worldStateSynchronizer,
|
|
1641
1634
|
gasFees,
|
|
1642
1635
|
this.config.l1ChainId,
|
|
1643
1636
|
this.config.rollupVersion,
|
|
1644
1637
|
protocolContractsHash,
|
|
1645
1638
|
this.archiver,
|
|
1646
|
-
this.proofVerifier,
|
|
1647
1639
|
!this.config.disableTransactions,
|
|
1648
1640
|
allowedInSetup,
|
|
1649
1641
|
this.logger.getBindings(),
|
|
1650
1642
|
);
|
|
1651
1643
|
}
|
|
1652
1644
|
|
|
1645
|
+
/** Creates the second stage (expensive proof verification) validators for gossiped transactions. */
|
|
1646
|
+
protected createSecondStageMessageValidators(): Record<string, TransactionValidator> {
|
|
1647
|
+
return createSecondStageTxValidationsForGossipedTransactions(this.proofVerifier, this.logger.getBindings());
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1653
1650
|
/**
|
|
1654
1651
|
* Run validations on a tx.
|
|
1655
1652
|
* @param tx - The tx to validate.
|
|
@@ -1658,7 +1655,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
1658
1655
|
*/
|
|
1659
1656
|
private async runValidations(
|
|
1660
1657
|
tx: Tx,
|
|
1661
|
-
messageValidators: Record<string,
|
|
1658
|
+
messageValidators: Record<string, TransactionValidator>,
|
|
1662
1659
|
): Promise<ValidationOutcome> {
|
|
1663
1660
|
const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
|
|
1664
1661
|
const { result } = await validator.validateTx(tx);
|
|
@@ -18,6 +18,7 @@ export class PeerManagerMetrics {
|
|
|
18
18
|
private sentGoodbyes: UpDownCounter;
|
|
19
19
|
private receivedGoodbyes: UpDownCounter;
|
|
20
20
|
private peerCount: Gauge;
|
|
21
|
+
private healthyPeerCount: Gauge;
|
|
21
22
|
private lowScoreDisconnects: UpDownCounter;
|
|
22
23
|
private peerConnectionDuration: Histogram;
|
|
23
24
|
|
|
@@ -49,6 +50,7 @@ export class PeerManagerMetrics {
|
|
|
49
50
|
goodbyeReasonAttrs,
|
|
50
51
|
);
|
|
51
52
|
this.peerCount = meter.createGauge(Metrics.PEER_MANAGER_PEER_COUNT);
|
|
53
|
+
this.healthyPeerCount = meter.createGauge(Metrics.PEER_MANAGER_HEALTHY_PEER_COUNT);
|
|
52
54
|
this.lowScoreDisconnects = createUpDownCounterWithDefault(meter, Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS, {
|
|
53
55
|
[Attributes.P2P_PEER_SCORE_STATE]: ['Banned', 'Disconnect'],
|
|
54
56
|
});
|
|
@@ -67,6 +69,10 @@ export class PeerManagerMetrics {
|
|
|
67
69
|
this.peerCount.record(count);
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
public recordHealthyPeerCount(count: number) {
|
|
73
|
+
this.healthyPeerCount.record(count);
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
public recordLowScoreDisconnect(scoreState: 'Banned' | 'Disconnect') {
|
|
71
77
|
this.lowScoreDisconnects.add(1, { [Attributes.P2P_PEER_SCORE_STATE]: scoreState });
|
|
72
78
|
}
|
|
@@ -79,6 +85,7 @@ export class PeerManagerMetrics {
|
|
|
79
85
|
const connectedAt = this.peerConnectedAt.get(id.toString());
|
|
80
86
|
if (connectedAt) {
|
|
81
87
|
this.peerConnectionDuration.record(Date.now() - connectedAt);
|
|
88
|
+
this.peerConnectedAt.delete(id.toString());
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
}
|
|
@@ -515,7 +515,8 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
515
515
|
...this.peerScoring.getStats(),
|
|
516
516
|
});
|
|
517
517
|
|
|
518
|
-
this.metrics.recordPeerCount(
|
|
518
|
+
this.metrics.recordPeerCount(connections.length);
|
|
519
|
+
this.metrics.recordHealthyPeerCount(healthyConnections.length);
|
|
519
520
|
|
|
520
521
|
// Exit if no peers to connect
|
|
521
522
|
if (peersToConnect <= 0) {
|
|
@@ -8,8 +8,8 @@ import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
|
8
8
|
import { Tx, TxArray, TxHash } from '@aztec/stdlib/tx';
|
|
9
9
|
|
|
10
10
|
import type { PeerId } from '@libp2p/interface';
|
|
11
|
-
import { peerIdFromString } from '@libp2p/peer-id';
|
|
12
11
|
|
|
12
|
+
import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
|
|
13
13
|
import { ReqRespSubProtocol } from '.././interface.js';
|
|
14
14
|
import { BlockTxsRequest, BlockTxsResponse, type BlockTxsSource } from '.././protocols/index.js';
|
|
15
15
|
import { ReqRespStatus } from '.././status.js';
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE,
|
|
21
21
|
} from './config.js';
|
|
22
22
|
import type { BatchTxRequesterLibP2PService, BatchTxRequesterOptions, ITxMetadataCollection } from './interface.js';
|
|
23
|
-
import {
|
|
23
|
+
import { MissingTxMetadataCollection } from './missing_txs.js';
|
|
24
24
|
import { type IPeerCollection, PeerCollection } from './peer_collection.js';
|
|
25
25
|
import { BatchRequestTxValidator, type IBatchRequestTxValidator } from './tx_validator.js';
|
|
26
26
|
|
|
@@ -60,7 +60,7 @@ export class BatchTxRequester {
|
|
|
60
60
|
private readonly txBatchSize: number;
|
|
61
61
|
|
|
62
62
|
constructor(
|
|
63
|
-
|
|
63
|
+
missingTxsTracker: IMissingTxsTracker,
|
|
64
64
|
blockTxsSource: BlockTxsSource,
|
|
65
65
|
pinnedPeer: PeerId | undefined,
|
|
66
66
|
timeoutMs: number,
|
|
@@ -89,18 +89,16 @@ export class BatchTxRequester {
|
|
|
89
89
|
if (this.opts.peerCollection) {
|
|
90
90
|
this.peers = this.opts.peerCollection;
|
|
91
91
|
} else {
|
|
92
|
-
const initialPeers = this.p2pService.connectionSampler.getPeerListSortedByConnectionCountAsc();
|
|
93
92
|
const badPeerThreshold = this.opts.badPeerThreshold ?? DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD;
|
|
94
93
|
this.peers = new PeerCollection(
|
|
95
|
-
|
|
94
|
+
this.p2pService.connectionSampler,
|
|
96
95
|
this.pinnedPeer,
|
|
97
96
|
this.dateProvider,
|
|
98
97
|
badPeerThreshold,
|
|
99
98
|
this.p2pService.peerScoring,
|
|
100
99
|
);
|
|
101
100
|
}
|
|
102
|
-
|
|
103
|
-
this.txsMetadata = new MissingTxMetadataCollection(entries, this.txBatchSize);
|
|
101
|
+
this.txsMetadata = new MissingTxMetadataCollection(missingTxsTracker, this.txBatchSize);
|
|
104
102
|
this.smartRequesterSemaphore = this.opts.semaphore ?? new Semaphore(0);
|
|
105
103
|
}
|
|
106
104
|
|
|
@@ -227,7 +225,6 @@ export class BatchTxRequester {
|
|
|
227
225
|
* Starts dumb worker loops
|
|
228
226
|
* */
|
|
229
227
|
private async dumbRequester() {
|
|
230
|
-
const nextPeerIndex = this.makeRoundRobinIndexer();
|
|
231
228
|
const nextBatchIndex = this.makeRoundRobinIndexer();
|
|
232
229
|
|
|
233
230
|
// Chunk missing tx hashes into batches of txBatchSize, wrapping around to ensure no peer gets less than txBatchSize
|
|
@@ -263,15 +260,9 @@ export class BatchTxRequester {
|
|
|
263
260
|
return { blockRequest, txs };
|
|
264
261
|
};
|
|
265
262
|
|
|
266
|
-
const
|
|
267
|
-
const peers = this.peers.getDumbPeersToQuery();
|
|
268
|
-
const idx = nextPeerIndex(() => peers.length);
|
|
269
|
-
return idx === undefined ? undefined : peerIdFromString(peers[idx]);
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const workerCount = Math.min(this.dumbParallelWorkerCount, this.peers.getAllPeers().size);
|
|
263
|
+
const workerCount = this.dumbParallelWorkerCount;
|
|
273
264
|
const workers = Array.from({ length: workerCount }, (_, index) =>
|
|
274
|
-
this.dumbWorkerLoop(
|
|
265
|
+
this.dumbWorkerLoop(this.peers.nextDumbPeerToQuery.bind(this.peers), makeRequest, index + 1),
|
|
275
266
|
);
|
|
276
267
|
|
|
277
268
|
await Promise.allSettled(workers);
|
|
@@ -332,14 +323,6 @@ export class BatchTxRequester {
|
|
|
332
323
|
* Starts smart worker loops
|
|
333
324
|
* */
|
|
334
325
|
private async smartRequester() {
|
|
335
|
-
const nextPeerIndex = this.makeRoundRobinIndexer();
|
|
336
|
-
|
|
337
|
-
const nextPeer = () => {
|
|
338
|
-
const peers = this.peers.getSmartPeersToQuery();
|
|
339
|
-
const idx = nextPeerIndex(() => peers.length);
|
|
340
|
-
return idx === undefined ? undefined : peerIdFromString(peers[idx]);
|
|
341
|
-
};
|
|
342
|
-
|
|
343
326
|
const makeRequest = (pid: PeerId) => {
|
|
344
327
|
const txs = this.txsMetadata.getTxsToRequestFromThePeer(pid);
|
|
345
328
|
const blockRequest = BlockTxsRequest.fromTxsSourceAndMissingTxs(this.blockTxsSource, txs);
|
|
@@ -350,9 +333,8 @@ export class BatchTxRequester {
|
|
|
350
333
|
return { blockRequest, txs };
|
|
351
334
|
};
|
|
352
335
|
|
|
353
|
-
const workers = Array.from(
|
|
354
|
-
|
|
355
|
-
(_, index) => this.smartWorkerLoop(nextPeer, makeRequest, index + 1),
|
|
336
|
+
const workers = Array.from({ length: this.smartParallelWorkerCount }, (_, index) =>
|
|
337
|
+
this.smartWorkerLoop(this.peers.nextSmartPeerToQuery.bind(this.peers), makeRequest, index + 1),
|
|
356
338
|
);
|
|
357
339
|
|
|
358
340
|
await Promise.allSettled(workers);
|
|
@@ -387,26 +369,18 @@ export class BatchTxRequester {
|
|
|
387
369
|
if (weRanOutOfPeersToQuery) {
|
|
388
370
|
this.logger.debug(`Worker loop smart: No more peers to query`);
|
|
389
371
|
|
|
390
|
-
// If
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const thereAreSomeRateLimitedSmartPeers = nextSmartPeerDelay !== undefined;
|
|
397
|
-
if (thereAreSomeRateLimitedSmartPeers) {
|
|
398
|
-
await this.sleepClampedToDeadline(nextSmartPeerDelay);
|
|
399
|
-
continue;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
this.logger.debug(`Worker loop smart: No more smart peers to query killing ${workerIndex}`);
|
|
403
|
-
break;
|
|
372
|
+
// If we have rate limited peers wait for them.
|
|
373
|
+
const nextSmartPeerDelay = this.peers.getNextSmartPeerAvailabilityDelayMs();
|
|
374
|
+
const thereAreSomeRateLimitedSmartPeers = nextSmartPeerDelay !== undefined;
|
|
375
|
+
if (thereAreSomeRateLimitedSmartPeers) {
|
|
376
|
+
await this.sleepClampedToDeadline(nextSmartPeerDelay);
|
|
377
|
+
continue;
|
|
404
378
|
}
|
|
405
379
|
|
|
406
|
-
// Otherwise there are still some dumb peers that could become smart.
|
|
407
380
|
// We end up here when all known smart peers became temporarily unavailable via combination of
|
|
408
381
|
// (bad, in-flight, or rate-limited) or in some weird scenario all current smart peers turn bad which is permanent
|
|
409
|
-
// but dumb peers
|
|
382
|
+
// but there are dumb peers that could be promoted
|
|
383
|
+
// or new peer can join as dumb and be promoted later
|
|
410
384
|
//
|
|
411
385
|
// When a dumb peer responds with valid txIndices, it gets
|
|
412
386
|
// promoted to smart and releases the semaphore, waking this worker.
|
|
@@ -599,9 +573,7 @@ export class BatchTxRequester {
|
|
|
599
573
|
this.markTxsPeerHas(peerId, response);
|
|
600
574
|
|
|
601
575
|
// Unblock smart workers
|
|
602
|
-
|
|
603
|
-
this.smartRequesterSemaphore.release();
|
|
604
|
-
}
|
|
576
|
+
this.smartRequesterSemaphore.release();
|
|
605
577
|
}
|
|
606
578
|
|
|
607
579
|
private isBlockResponseValid(response: BlockTxsResponse): boolean {
|
|
@@ -661,7 +633,7 @@ export class BatchTxRequester {
|
|
|
661
633
|
/*
|
|
662
634
|
* @returns true if all missing txs have been fetched */
|
|
663
635
|
private fetchedAllTxs() {
|
|
664
|
-
return
|
|
636
|
+
return this.txsMetadata.getMissingTxHashes().size == 0;
|
|
665
637
|
}
|
|
666
638
|
|
|
667
639
|
/*
|
|
@@ -679,7 +651,7 @@ export class BatchTxRequester {
|
|
|
679
651
|
this.unlockSmartRequesterSemaphores();
|
|
680
652
|
}
|
|
681
653
|
|
|
682
|
-
return aborted || this.
|
|
654
|
+
return aborted || this.fetchedAllTxs() || this.dateProvider.now() > this.deadline;
|
|
683
655
|
}
|
|
684
656
|
|
|
685
657
|
/*
|
|
@@ -6,7 +6,6 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
6
6
|
|
|
7
7
|
import type { ConnectionSampler } from '../connection-sampler/connection_sampler.js';
|
|
8
8
|
import type { ReqRespInterface } from '../interface.js';
|
|
9
|
-
import type { MissingTxMetadata } from './missing_txs.js';
|
|
10
9
|
import type { IPeerCollection } from './peer_collection.js';
|
|
11
10
|
import type { BatchRequestTxValidatorConfig, IBatchRequestTxValidator } from './tx_validator.js';
|
|
12
11
|
|
|
@@ -15,18 +14,15 @@ export interface IPeerPenalizer {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export interface ITxMetadataCollection {
|
|
18
|
-
size: number;
|
|
19
|
-
values(): IterableIterator<MissingTxMetadata>;
|
|
20
17
|
getMissingTxHashes(): Set<string>;
|
|
18
|
+
markFetched(peerId: PeerId, tx: Tx): boolean;
|
|
21
19
|
getTxsToRequestFromThePeer(peer: PeerId): TxHash[];
|
|
22
20
|
markRequested(txHash: TxHash): void;
|
|
23
21
|
markInFlightBySmartPeer(txHash: TxHash): void;
|
|
24
22
|
markNotInFlightBySmartPeer(txHash: TxHash): void;
|
|
25
23
|
alreadyFetched(txHash: TxHash): boolean;
|
|
26
24
|
// Returns true if tx was marked as fetched, false if it was already marked as fetched
|
|
27
|
-
markFetched(peerId: PeerId, tx: Tx): boolean;
|
|
28
25
|
markPeerHas(peerId: PeerId, txHashes: TxHash[]): void;
|
|
29
|
-
getFetchedTxs(): Tx[];
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
/**
|