@aztec/p2p 5.0.0-private.20260319 → 5.0.0-rc.2
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/README.md +4 -1
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -6
- package/dest/client/factory.d.ts +4 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +33 -24
- package/dest/client/interface.d.ts +43 -11
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +33 -19
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +100 -44
- package/dest/config.d.ts +137 -107
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +64 -23
- 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/errors/reqresp.error.d.ts +1 -20
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +0 -21
- package/dest/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 +98 -56
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +265 -196
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +175 -59
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +6 -4
- package/dest/mem_pools/index.d.ts +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +17 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +1 -5
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +1 -7
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +6 -6
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -1
- 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 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +5 -2
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +13 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +7 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +10 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +8 -3
- 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 +7 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +8 -3
- 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 +153 -111
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -16
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +8 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +2 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +8 -3
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +8 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +25 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +77 -14
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +8 -15
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/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 +2 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +36 -2
- package/dest/msg_validators/tx_validator/factory.d.ts +14 -15
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +36 -17
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +47 -10
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +65 -48
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/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/discv5/discV5_service.d.ts +13 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +119 -23
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +15 -15
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +15 -16
- package/dest/services/encoding.d.ts +8 -8
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +11 -15
- package/dest/services/gossipsub/topic_score_params.d.ts +6 -12
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +4 -14
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +44 -39
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +383 -278
- package/dest/services/peer-manager/peer_manager.d.ts +20 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +79 -23
- package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +102 -13
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +38 -44
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +8 -5
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +5 -14
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +16 -18
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -20
- 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/block_txs/bitvector.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +31 -28
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +12 -7
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +42 -24
- package/dest/services/reqresp/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 +7 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +26 -207
- package/dest/services/service.d.ts +25 -12
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +2 -23
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +2 -55
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +12 -28
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +43 -83
- package/dest/services/tx_collection/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/index.d.ts +2 -3
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +0 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +0 -2
- package/dest/services/tx_collection/tx_collection.d.ts +35 -51
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +275 -119
- package/dest/services/tx_collection/tx_collection_sink.d.ts +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +2 -2
- package/dest/services/tx_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 +13 -8
- package/dest/services/tx_file_store/tx_file_store.d.ts +1 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +4 -14
- package/dest/services/tx_provider.d.ts +3 -1
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +3 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +5 -2
- package/dest/test-helpers/mock-pubsub.d.ts +23 -9
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +44 -44
- package/dest/test-helpers/reqresp-nodes.d.ts +4 -5
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +16 -18
- package/dest/test-helpers/test_tx_provider.d.ts +3 -1
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
- package/dest/test-helpers/test_tx_provider.js +3 -0
- package/dest/test-helpers/testbench-utils.d.ts +14 -14
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +25 -13
- package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +102 -41
- package/dest/testbench/worker_client_manager.d.ts +10 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +51 -9
- package/dest/util.d.ts +11 -6
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +16 -16
- package/src/bootstrap/bootstrap.ts +17 -3
- package/src/client/factory.ts +52 -24
- package/src/client/interface.ts +38 -17
- package/src/client/p2p_client.ts +118 -76
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +130 -31
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +0 -25
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +319 -238
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +198 -62
- package/src/mem_pools/attestation_pool/mocks.ts +13 -8
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +5 -1
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +1 -9
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +7 -7
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +1 -1
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/interfaces.ts +18 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +20 -8
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +12 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +8 -4
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +163 -117
- package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -15
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
- package/src/msg_validators/proposal_validator/README.md +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +15 -3
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +26 -3
- package/src/msg_validators/proposal_validator/proposal_validator.ts +89 -11
- package/src/msg_validators/tx_validator/README.md +13 -3
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -12
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +3 -3
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +44 -1
- package/src/msg_validators/tx_validator/factory.ts +44 -20
- package/src/msg_validators/tx_validator/gas_validator.ts +99 -54
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +3 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/data_store.ts +5 -13
- package/src/services/discv5/discV5_service.ts +126 -14
- package/src/services/discv5/persisted_enr_store.ts +158 -0
- package/src/services/dummy_service.ts +20 -39
- package/src/services/encoding.ts +11 -21
- package/src/services/gossipsub/README.md +33 -11
- package/src/services/gossipsub/topic_score_params.ts +9 -18
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +436 -311
- package/src/services/peer-manager/peer_manager.ts +86 -22
- package/src/services/peer-manager/peer_scoring.ts +102 -8
- package/src/services/reqresp/README.md +0 -14
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +42 -52
- package/src/services/reqresp/batch-tx-requester/interface.ts +11 -4
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +12 -25
- package/src/services/reqresp/config.ts +2 -2
- package/src/services/reqresp/interface.ts +21 -47
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +34 -30
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +47 -20
- package/src/services/reqresp/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 +29 -252
- package/src/services/service.ts +31 -28
- package/src/services/tx_collection/config.ts +3 -80
- package/src/services/tx_collection/file_store_tx_collection.ts +54 -103
- package/src/services/tx_collection/file_store_tx_source.ts +43 -31
- package/src/services/tx_collection/index.ts +1 -6
- package/src/services/tx_collection/instrumentation.ts +1 -7
- package/src/services/tx_collection/tx_collection.ts +330 -173
- package/src/services/tx_collection/tx_collection_sink.ts +2 -2
- package/src/services/tx_collection/tx_source.ts +10 -8
- package/src/services/tx_file_store/tx_file_store.ts +5 -17
- package/src/services/tx_provider.ts +5 -0
- package/src/test-helpers/make-test-p2p-clients.ts +3 -0
- package/src/test-helpers/mock-pubsub.ts +46 -60
- package/src/test-helpers/reqresp-nodes.ts +12 -22
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +31 -26
- package/src/testbench/p2p_client_testbench_worker.ts +110 -55
- package/src/testbench/worker_client_manager.ts +59 -20
- package/src/util.ts +32 -17
- package/src/versioning.ts +3 -33
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
- package/dest/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/msg_validators/clock_tolerance.d.ts +0 -21
- package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
- package/dest/msg_validators/clock_tolerance.js +0 -38
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
- package/dest/services/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/fast_tx_collection.d.ts +0 -51
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -311
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -50
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -57
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -211
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -344
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
- 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/msg_validators/clock_tolerance.ts +0 -52
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/fast_tx_collection.ts +0 -361
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -108
- package/src/services/tx_collection/slow_tx_collection.ts +0 -266
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { unfreeze } from '@aztec/foundation/types';
|
|
3
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
4
|
-
import { mockTx } from '@aztec/stdlib/testing';
|
|
5
|
-
import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
6
|
-
/**
|
|
7
|
-
* Tests a TxPool implementation.
|
|
8
|
-
* @param getTxPool - Gets a fresh TxPool
|
|
9
|
-
*/ export function describeTxPool(getTxPool) {
|
|
10
|
-
let pool;
|
|
11
|
-
const minedBlockHeader = BlockHeader.empty({
|
|
12
|
-
globalVariables: GlobalVariables.empty({
|
|
13
|
-
blockNumber: BlockNumber(1),
|
|
14
|
-
timestamp: 0n
|
|
15
|
-
})
|
|
16
|
-
});
|
|
17
|
-
beforeEach(()=>{
|
|
18
|
-
pool = getTxPool();
|
|
19
|
-
});
|
|
20
|
-
afterEach(()=>{
|
|
21
|
-
pool.removeAllListeners('txs-added');
|
|
22
|
-
});
|
|
23
|
-
it('adds txs to the pool as pending', async ()=>{
|
|
24
|
-
const tx1 = await mockTx(1);
|
|
25
|
-
await pool.addTxs([
|
|
26
|
-
tx1
|
|
27
|
-
]);
|
|
28
|
-
const poolTx = await pool.getTxByHash(tx1.getTxHash());
|
|
29
|
-
expect(poolTx.getTxHash()).toEqual(tx1.getTxHash());
|
|
30
|
-
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('pending');
|
|
31
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
32
|
-
tx1.getTxHash()
|
|
33
|
-
]);
|
|
34
|
-
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
35
|
-
});
|
|
36
|
-
it('emits txs-added event with new txs', async ()=>{
|
|
37
|
-
const tx1 = await mockTx(1); // existing and pending
|
|
38
|
-
const tx2 = await mockTx(2); // mined but not known
|
|
39
|
-
const tx3 = await mockTx(3); // brand new
|
|
40
|
-
await pool.addTxs([
|
|
41
|
-
tx1
|
|
42
|
-
]);
|
|
43
|
-
await pool.markAsMined([
|
|
44
|
-
tx2.getTxHash()
|
|
45
|
-
], minedBlockHeader);
|
|
46
|
-
let txsFromEvent = undefined;
|
|
47
|
-
pool.once('txs-added', ({ txs })=>{
|
|
48
|
-
txsFromEvent = txs;
|
|
49
|
-
});
|
|
50
|
-
await pool.addTxs([
|
|
51
|
-
tx1,
|
|
52
|
-
tx2,
|
|
53
|
-
tx3
|
|
54
|
-
]);
|
|
55
|
-
expect(txsFromEvent).toBeDefined();
|
|
56
|
-
expect(txsFromEvent).toHaveLength(2);
|
|
57
|
-
const eventHashes = txsFromEvent.map((tx)=>tx.getTxHash());
|
|
58
|
-
expect(eventHashes).toEqual(expect.arrayContaining([
|
|
59
|
-
tx2.getTxHash(),
|
|
60
|
-
tx3.getTxHash()
|
|
61
|
-
]));
|
|
62
|
-
});
|
|
63
|
-
it('removes txs from the pool', async ()=>{
|
|
64
|
-
const pendingTx = await mockTx(1);
|
|
65
|
-
const minedTx = await mockTx(2);
|
|
66
|
-
await pool.addTxs([
|
|
67
|
-
pendingTx,
|
|
68
|
-
minedTx
|
|
69
|
-
]);
|
|
70
|
-
await pool.markAsMined([
|
|
71
|
-
minedTx.getTxHash()
|
|
72
|
-
], minedBlockHeader);
|
|
73
|
-
// Delete a pending tx - should be permanently deleted
|
|
74
|
-
await pool.deleteTxs([
|
|
75
|
-
pendingTx.getTxHash()
|
|
76
|
-
]);
|
|
77
|
-
await expect(pool.getTxByHash(pendingTx.getTxHash())).resolves.toBeUndefined();
|
|
78
|
-
await expect(pool.getTxStatus(pendingTx.getTxHash())).resolves.toBeUndefined();
|
|
79
|
-
// Delete a mined tx - should be soft-deleted (still in storage)
|
|
80
|
-
await pool.deleteTxs([
|
|
81
|
-
minedTx.getTxHash()
|
|
82
|
-
]);
|
|
83
|
-
await expect(pool.getTxByHash(minedTx.getTxHash())).resolves.toBeDefined();
|
|
84
|
-
await expect(pool.getTxStatus(minedTx.getTxHash())).resolves.toEqual('deleted');
|
|
85
|
-
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
86
|
-
await expect(pool.getPendingTxCount()).resolves.toEqual(0);
|
|
87
|
-
});
|
|
88
|
-
it('marks txs as mined', async ()=>{
|
|
89
|
-
const tx1 = await mockTx(1);
|
|
90
|
-
const tx2 = await mockTx(2);
|
|
91
|
-
await pool.addTxs([
|
|
92
|
-
tx1,
|
|
93
|
-
tx2
|
|
94
|
-
]);
|
|
95
|
-
await pool.markAsMined([
|
|
96
|
-
tx1.getTxHash()
|
|
97
|
-
], minedBlockHeader);
|
|
98
|
-
const retrievedTx = await pool.getTxByHash(tx1.getTxHash());
|
|
99
|
-
expect(retrievedTx?.getTxHash()).toEqual(tx1.getTxHash());
|
|
100
|
-
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('mined');
|
|
101
|
-
await expect(pool.getMinedTxHashes()).resolves.toEqual([
|
|
102
|
-
[
|
|
103
|
-
tx1.getTxHash(),
|
|
104
|
-
1
|
|
105
|
-
]
|
|
106
|
-
]);
|
|
107
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
108
|
-
tx2.getTxHash()
|
|
109
|
-
]);
|
|
110
|
-
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
111
|
-
});
|
|
112
|
-
it('marks txs as pending after being mined', async ()=>{
|
|
113
|
-
const tx1 = await mockTx(1);
|
|
114
|
-
const tx2 = await mockTx(2);
|
|
115
|
-
await pool.addTxs([
|
|
116
|
-
tx1,
|
|
117
|
-
tx2
|
|
118
|
-
]);
|
|
119
|
-
await pool.markAsMined([
|
|
120
|
-
tx1.getTxHash()
|
|
121
|
-
], minedBlockHeader);
|
|
122
|
-
await pool.markMinedAsPending([
|
|
123
|
-
tx1.getTxHash()
|
|
124
|
-
], BlockNumber(1));
|
|
125
|
-
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
126
|
-
const pending = await pool.getPendingTxHashes();
|
|
127
|
-
expect(pending).toHaveLength(2);
|
|
128
|
-
expect(pending).toEqual(expect.arrayContaining([
|
|
129
|
-
tx1.getTxHash(),
|
|
130
|
-
tx2.getTxHash()
|
|
131
|
-
]));
|
|
132
|
-
await expect(pool.getPendingTxCount()).resolves.toEqual(2);
|
|
133
|
-
});
|
|
134
|
-
it('only marks txs as pending if they are known', async ()=>{
|
|
135
|
-
const tx1 = await mockTx(1);
|
|
136
|
-
// simulate a situation where not all peers have all the txs
|
|
137
|
-
const tx2 = await mockTx(2);
|
|
138
|
-
const someTxHashThatThisPeerDidNotSee = tx2.getTxHash();
|
|
139
|
-
await pool.addTxs([
|
|
140
|
-
tx1
|
|
141
|
-
]);
|
|
142
|
-
// this peer knows that tx2 was mined, but it does not have the tx object
|
|
143
|
-
await pool.markAsMined([
|
|
144
|
-
tx1.getTxHash(),
|
|
145
|
-
someTxHashThatThisPeerDidNotSee
|
|
146
|
-
], minedBlockHeader);
|
|
147
|
-
expect(await pool.getMinedTxHashes()).toEqual(expect.arrayContaining([
|
|
148
|
-
[
|
|
149
|
-
tx1.getTxHash(),
|
|
150
|
-
1
|
|
151
|
-
],
|
|
152
|
-
[
|
|
153
|
-
someTxHashThatThisPeerDidNotSee,
|
|
154
|
-
1
|
|
155
|
-
]
|
|
156
|
-
]));
|
|
157
|
-
// reorg: both txs should now become available again
|
|
158
|
-
await pool.markMinedAsPending([
|
|
159
|
-
tx1.getTxHash(),
|
|
160
|
-
someTxHashThatThisPeerDidNotSee
|
|
161
|
-
], BlockNumber(1));
|
|
162
|
-
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
163
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
164
|
-
tx1.getTxHash()
|
|
165
|
-
]); // tx2 is not in the pool
|
|
166
|
-
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
167
|
-
});
|
|
168
|
-
it('returns all transactions in the pool', async ()=>{
|
|
169
|
-
const tx1 = await mockTx(1);
|
|
170
|
-
const tx2 = await mockTx(2);
|
|
171
|
-
const tx3 = await mockTx(3);
|
|
172
|
-
await pool.addTxs([
|
|
173
|
-
tx1,
|
|
174
|
-
tx2,
|
|
175
|
-
tx3
|
|
176
|
-
]);
|
|
177
|
-
const poolTxs = await pool.getAllTxs();
|
|
178
|
-
expect(poolTxs).toHaveLength(3);
|
|
179
|
-
const poolHashes = poolTxs.map((tx)=>tx.getTxHash());
|
|
180
|
-
expect(poolHashes).toEqual(expect.arrayContaining([
|
|
181
|
-
tx1.getTxHash(),
|
|
182
|
-
tx2.getTxHash(),
|
|
183
|
-
tx3.getTxHash()
|
|
184
|
-
]));
|
|
185
|
-
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
186
|
-
});
|
|
187
|
-
it('returns all txHashes in the pool', async ()=>{
|
|
188
|
-
const tx1 = await mockTx(1);
|
|
189
|
-
const tx2 = await mockTx(2);
|
|
190
|
-
const tx3 = await mockTx(3);
|
|
191
|
-
await pool.addTxs([
|
|
192
|
-
tx1,
|
|
193
|
-
tx2,
|
|
194
|
-
tx3
|
|
195
|
-
]);
|
|
196
|
-
const poolTxHashes = await pool.getAllTxHashes();
|
|
197
|
-
const expectedHashes = [
|
|
198
|
-
tx1,
|
|
199
|
-
tx2,
|
|
200
|
-
tx3
|
|
201
|
-
].map((tx)=>tx.getTxHash());
|
|
202
|
-
expect(poolTxHashes).toHaveLength(3);
|
|
203
|
-
expect(poolTxHashes).toEqual(expect.arrayContaining(expectedHashes));
|
|
204
|
-
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
205
|
-
});
|
|
206
|
-
it('returns txs by their hash', async ()=>{
|
|
207
|
-
const tx1 = await mockTx(1);
|
|
208
|
-
const tx2 = await mockTx(2);
|
|
209
|
-
const tx3 = await mockTx(3);
|
|
210
|
-
await pool.addTxs([
|
|
211
|
-
tx1,
|
|
212
|
-
tx2,
|
|
213
|
-
tx3
|
|
214
|
-
]);
|
|
215
|
-
const requestedTxs = await pool.getTxsByHash([
|
|
216
|
-
tx1.getTxHash(),
|
|
217
|
-
tx3.getTxHash()
|
|
218
|
-
]);
|
|
219
|
-
expect(requestedTxs).toHaveLength(2);
|
|
220
|
-
const requestedHashes = requestedTxs.map((tx)=>tx.getTxHash());
|
|
221
|
-
expect(requestedHashes).toEqual(expect.arrayContaining([
|
|
222
|
-
tx1.getTxHash(),
|
|
223
|
-
tx3.getTxHash()
|
|
224
|
-
]));
|
|
225
|
-
});
|
|
226
|
-
it('returns a large number of transactions by their hash', async ()=>{
|
|
227
|
-
const numTxs = 1_000;
|
|
228
|
-
const txs = await Promise.all(Array.from({
|
|
229
|
-
length: numTxs
|
|
230
|
-
}, (_, i)=>mockTx(i)));
|
|
231
|
-
const hashes = txs.map((tx)=>tx.getTxHash());
|
|
232
|
-
await pool.addTxs(txs);
|
|
233
|
-
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
234
|
-
expect(requestedTxs).toHaveLength(numTxs);
|
|
235
|
-
const requestedHashes = requestedTxs.map((tx)=>tx.getTxHash());
|
|
236
|
-
expect(requestedHashes).toEqual(expect.arrayContaining(hashes));
|
|
237
|
-
});
|
|
238
|
-
it('returns whether or not txs exist', async ()=>{
|
|
239
|
-
const tx1 = await mockTx(1);
|
|
240
|
-
const tx2 = await mockTx(2);
|
|
241
|
-
const tx3 = await mockTx(3);
|
|
242
|
-
await pool.addTxs([
|
|
243
|
-
tx1,
|
|
244
|
-
tx2,
|
|
245
|
-
tx3
|
|
246
|
-
]);
|
|
247
|
-
const tx4 = await mockTx(4);
|
|
248
|
-
const tx5 = await mockTx(5);
|
|
249
|
-
const availability = await pool.hasTxs([
|
|
250
|
-
tx1.getTxHash(),
|
|
251
|
-
tx2.getTxHash(),
|
|
252
|
-
tx3.getTxHash(),
|
|
253
|
-
tx4.getTxHash(),
|
|
254
|
-
tx5.getTxHash()
|
|
255
|
-
]);
|
|
256
|
-
expect(availability).toHaveLength(5);
|
|
257
|
-
expect(availability).toEqual(expect.arrayContaining([
|
|
258
|
-
true,
|
|
259
|
-
true,
|
|
260
|
-
true,
|
|
261
|
-
false,
|
|
262
|
-
false
|
|
263
|
-
]));
|
|
264
|
-
});
|
|
265
|
-
it('returns pending tx hashes sorted by priority', async ()=>{
|
|
266
|
-
const withPriorityFee = (tx, fee)=>{
|
|
267
|
-
const gs = unfreeze(tx.data.constants.txContext.gasSettings);
|
|
268
|
-
gs.maxPriorityFeesPerGas = new GasFees(fee, fee);
|
|
269
|
-
gs.maxFeesPerGas = new GasFees(fee, fee);
|
|
270
|
-
return tx;
|
|
271
|
-
};
|
|
272
|
-
const tx1 = withPriorityFee(await mockTx(0), 1000);
|
|
273
|
-
const tx2 = withPriorityFee(await mockTx(1), 100);
|
|
274
|
-
const tx3 = withPriorityFee(await mockTx(2), 200);
|
|
275
|
-
const tx4 = withPriorityFee(await mockTx(3), 3000);
|
|
276
|
-
await pool.addTxs([
|
|
277
|
-
tx1,
|
|
278
|
-
tx2,
|
|
279
|
-
tx3,
|
|
280
|
-
tx4
|
|
281
|
-
]);
|
|
282
|
-
const poolTxHashes = await pool.getPendingTxHashes();
|
|
283
|
-
expect(poolTxHashes).toHaveLength(4);
|
|
284
|
-
expect(poolTxHashes).toEqual([
|
|
285
|
-
tx4,
|
|
286
|
-
tx1,
|
|
287
|
-
tx3,
|
|
288
|
-
tx2
|
|
289
|
-
].map((tx)=>tx.getTxHash()));
|
|
290
|
-
});
|
|
291
|
-
describe('soft-delete', ()=>{
|
|
292
|
-
it('soft-deletes mined txs and keeps them in storage', async ()=>{
|
|
293
|
-
const txs = await Promise.all([
|
|
294
|
-
mockTx(1),
|
|
295
|
-
mockTx(2),
|
|
296
|
-
mockTx(3)
|
|
297
|
-
]);
|
|
298
|
-
await pool.addTxs(txs);
|
|
299
|
-
// Mark first tx as mined
|
|
300
|
-
await pool.markAsMined([
|
|
301
|
-
txs[0].getTxHash()
|
|
302
|
-
], minedBlockHeader);
|
|
303
|
-
// Verify initial state
|
|
304
|
-
await expect(pool.getPendingTxCount()).resolves.toBe(2);
|
|
305
|
-
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
306
|
-
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeDefined();
|
|
307
|
-
// Delete mined tx - should be soft-deleted
|
|
308
|
-
await pool.deleteTxs([
|
|
309
|
-
txs[0].getTxHash()
|
|
310
|
-
]);
|
|
311
|
-
// Delete pending tx - should be permanently deleted
|
|
312
|
-
await pool.deleteTxs([
|
|
313
|
-
txs[1].getTxHash()
|
|
314
|
-
]);
|
|
315
|
-
// Verify mined tx still exists in storage but has 'deleted' status
|
|
316
|
-
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
317
|
-
await expect(pool.getTxStatus(txs[0].getTxHash())).resolves.toEqual('deleted');
|
|
318
|
-
// Verify pending tx is permanently deleted
|
|
319
|
-
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
320
|
-
await expect(pool.getTxStatus(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
321
|
-
// Verify remaining pending count
|
|
322
|
-
await expect(pool.getPendingTxCount()).resolves.toBe(1);
|
|
323
|
-
// Verify pending hashes don't include deleted txs
|
|
324
|
-
const pendingHashes = await pool.getPendingTxHashes();
|
|
325
|
-
expect(pendingHashes).toHaveLength(1);
|
|
326
|
-
expect(pendingHashes.map((h)=>h.toString())).toContain(txs[2].getTxHash().toString());
|
|
327
|
-
});
|
|
328
|
-
it('cleans up old deleted mined transactions', async ()=>{
|
|
329
|
-
const txs = await Promise.all([
|
|
330
|
-
mockTx(1),
|
|
331
|
-
mockTx(2),
|
|
332
|
-
mockTx(3)
|
|
333
|
-
]);
|
|
334
|
-
await pool.addTxs(txs);
|
|
335
|
-
// Mark first two as mined in block 1
|
|
336
|
-
await pool.markAsMined([
|
|
337
|
-
txs[0].getTxHash(),
|
|
338
|
-
txs[1].getTxHash()
|
|
339
|
-
], minedBlockHeader);
|
|
340
|
-
// Soft-delete mined transactions
|
|
341
|
-
await pool.deleteTxs([
|
|
342
|
-
txs[0].getTxHash(),
|
|
343
|
-
txs[1].getTxHash()
|
|
344
|
-
]);
|
|
345
|
-
// Clean up deleted mined txs from block 1 and earlier
|
|
346
|
-
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
347
|
-
// Verify old transactions are permanently deleted
|
|
348
|
-
expect(deletedCount).toBe(2);
|
|
349
|
-
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeUndefined();
|
|
350
|
-
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
351
|
-
await expect(pool.getTxByHash(txs[2].getTxHash())).resolves.toBeDefined();
|
|
352
|
-
});
|
|
353
|
-
it('does not clean up recent deleted mined transactions', async ()=>{
|
|
354
|
-
const txs = await Promise.all([
|
|
355
|
-
mockTx(1),
|
|
356
|
-
mockTx(2)
|
|
357
|
-
]);
|
|
358
|
-
await pool.addTxs(txs);
|
|
359
|
-
// Mark as mined in block 2
|
|
360
|
-
const laterBlockHeader = BlockHeader.empty({
|
|
361
|
-
globalVariables: GlobalVariables.empty({
|
|
362
|
-
blockNumber: BlockNumber(2),
|
|
363
|
-
timestamp: 0n
|
|
364
|
-
})
|
|
365
|
-
});
|
|
366
|
-
await pool.markAsMined([
|
|
367
|
-
txs[0].getTxHash()
|
|
368
|
-
], laterBlockHeader);
|
|
369
|
-
// Soft-delete a mined transaction
|
|
370
|
-
await pool.deleteTxs([
|
|
371
|
-
txs[0].getTxHash()
|
|
372
|
-
]);
|
|
373
|
-
// Try to clean up with block 1 (before the mined block)
|
|
374
|
-
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
375
|
-
// Verify no transactions were cleaned up
|
|
376
|
-
expect(deletedCount).toBe(0);
|
|
377
|
-
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
378
|
-
});
|
|
379
|
-
it('restores deleted mined tx when it is mined again', async ()=>{
|
|
380
|
-
const tx = await mockTx(1);
|
|
381
|
-
await pool.addTxs([
|
|
382
|
-
tx
|
|
383
|
-
]);
|
|
384
|
-
// Mark as mined
|
|
385
|
-
await pool.markAsMined([
|
|
386
|
-
tx.getTxHash()
|
|
387
|
-
], minedBlockHeader);
|
|
388
|
-
// Soft-delete it
|
|
389
|
-
await pool.deleteTxs([
|
|
390
|
-
tx.getTxHash()
|
|
391
|
-
]);
|
|
392
|
-
await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('deleted');
|
|
393
|
-
// Mark as mined again (e.g., after a reorg)
|
|
394
|
-
await pool.markAsMined([
|
|
395
|
-
tx.getTxHash()
|
|
396
|
-
], minedBlockHeader);
|
|
397
|
-
// Should be back to mined status
|
|
398
|
-
await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('mined');
|
|
399
|
-
await expect(pool.getTxByHash(tx.getTxHash())).resolves.toBeDefined();
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
/**
|
|
4
|
-
* Maximum clock disparity tolerance for P2P message validation (in milliseconds).
|
|
5
|
-
* Messages for the previous slot are accepted if we're within this many milliseconds
|
|
6
|
-
* of the current slot start. This prevents penalizing peers for messages that
|
|
7
|
-
* were valid when sent but arrived slightly late due to network latency.
|
|
8
|
-
*
|
|
9
|
-
* This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
|
|
10
|
-
*/
|
|
11
|
-
export declare const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
12
|
-
/**
|
|
13
|
-
* Checks if a message for the previous slot should be accepted due to clock tolerance.
|
|
14
|
-
*
|
|
15
|
-
* @param messageSlot - The slot number from the received message
|
|
16
|
-
* @param currentSlot - The current slot number
|
|
17
|
-
* @param epochCache - EpochCache to get timing information
|
|
18
|
-
* @returns true if the message is for the previous slot AND we're within the clock tolerance window
|
|
19
|
-
*/
|
|
20
|
-
export declare function isWithinClockTolerance(messageSlot: SlotNumber, currentSlot: SlotNumber, epochCache: EpochCacheInterface): boolean;
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xvY2tfdG9sZXJhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbXNnX3ZhbGlkYXRvcnMvY2xvY2tfdG9sZXJhbmNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDOUQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRTdEOzs7Ozs7O0dBT0c7QUFDSCxlQUFPLE1BQU0saUNBQWlDLE1BQU0sQ0FBQztBQUVyRDs7Ozs7OztHQU9HO0FBQ0gsd0JBQWdCLHNCQUFzQixDQUNwQyxXQUFXLEVBQUUsVUFBVSxFQUN2QixXQUFXLEVBQUUsVUFBVSxFQUN2QixVQUFVLEVBQUUsbUJBQW1CLEdBQzlCLE9BQU8sQ0EwQlQifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clock_tolerance.d.ts","sourceRoot":"","sources":["../../src/msg_validators/clock_tolerance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,MAAM,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,UAAU,EACvB,WAAW,EAAE,UAAU,EACvB,UAAU,EAAE,mBAAmB,GAC9B,OAAO,CA0BT"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
/**
|
|
3
|
-
* Maximum clock disparity tolerance for P2P message validation (in milliseconds).
|
|
4
|
-
* Messages for the previous slot are accepted if we're within this many milliseconds
|
|
5
|
-
* of the current slot start. This prevents penalizing peers for messages that
|
|
6
|
-
* were valid when sent but arrived slightly late due to network latency.
|
|
7
|
-
*
|
|
8
|
-
* This follows Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.
|
|
9
|
-
*/ export const MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
10
|
-
/**
|
|
11
|
-
* Checks if a message for the previous slot should be accepted due to clock tolerance.
|
|
12
|
-
*
|
|
13
|
-
* @param messageSlot - The slot number from the received message
|
|
14
|
-
* @param currentSlot - The current slot number
|
|
15
|
-
* @param epochCache - EpochCache to get timing information
|
|
16
|
-
* @returns true if the message is for the previous slot AND we're within the clock tolerance window
|
|
17
|
-
*/ export function isWithinClockTolerance(messageSlot, currentSlot, epochCache) {
|
|
18
|
-
// Guard against slot 0 edge case (genesis)
|
|
19
|
-
if (currentSlot === SlotNumber.ZERO) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
// Only apply tolerance to messages for the previous slot
|
|
23
|
-
const previousSlot = SlotNumber(currentSlot - 1);
|
|
24
|
-
if (messageSlot !== previousSlot) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
// Check how far we are into the current slot (in milliseconds)
|
|
28
|
-
const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
|
|
29
|
-
const targetSlot = epochCache.getTargetSlot();
|
|
30
|
-
// Sanity check: ensure the epoch cache's target slot matches the expected current slot
|
|
31
|
-
if (targetSlot !== currentSlot) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
// ts is in seconds, convert to ms; nowMs is already in milliseconds
|
|
35
|
-
const slotStartMs = slotStartTs * 1000n;
|
|
36
|
-
const elapsedMs = Number(nowMs - slotStartMs);
|
|
37
|
-
return elapsedMs < MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS;
|
|
38
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { PeerId } from '@libp2p/interface';
|
|
2
|
-
import type { ConnectionSampler } from './connection_sampler.js';
|
|
3
|
-
/**
|
|
4
|
-
* Manages batches of peers for parallel request processing.
|
|
5
|
-
* Tracks active peers and provides deterministic peer assignment for requests.
|
|
6
|
-
*
|
|
7
|
-
* Example with 3 peers and 10 requests:
|
|
8
|
-
*
|
|
9
|
-
* Peers: [P1] [P2] [P3]
|
|
10
|
-
* ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
11
|
-
* Requests: 0,1,2,9 | 3,4,5 | 6,7,8
|
|
12
|
-
*
|
|
13
|
-
* Each peer handles a bucket of consecutive requests.
|
|
14
|
-
* If a peer fails, it is replaced while maintaining the same bucket.
|
|
15
|
-
*/
|
|
16
|
-
export declare class BatchConnectionSampler {
|
|
17
|
-
private readonly connectionSampler;
|
|
18
|
-
private readonly logger;
|
|
19
|
-
private readonly batch;
|
|
20
|
-
private readonly requestsPerPeer;
|
|
21
|
-
/** Tracks peer-index combinations that returned empty/invalid responses */
|
|
22
|
-
private readonly failedPeerIndices;
|
|
23
|
-
constructor(connectionSampler: ConnectionSampler, batchSize: number, maxPeers: number, exclude?: PeerId[], logger?: import("@aztec/foundation/log").Logger);
|
|
24
|
-
/**
|
|
25
|
-
* Gets the peer responsible for handling a specific request index.
|
|
26
|
-
* If the primary peer has previously failed for this index, tries other peers.
|
|
27
|
-
* If all batch peers have failed, attempts to sample a new peer.
|
|
28
|
-
*
|
|
29
|
-
* @param index - The request index
|
|
30
|
-
* @returns The peer assigned to handle this request, or undefined if no peer available
|
|
31
|
-
*/
|
|
32
|
-
getPeerForRequest(index: number): PeerId | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Attempts to sample a new peer that isn't already in the batch.
|
|
35
|
-
* If successful, adds the peer to the batch.
|
|
36
|
-
*
|
|
37
|
-
* @returns The new peer if one was sampled, undefined otherwise
|
|
38
|
-
*/
|
|
39
|
-
private sampleNewPeer;
|
|
40
|
-
/**
|
|
41
|
-
* Marks that a peer returned an empty/invalid response for a specific request index.
|
|
42
|
-
* The peer will not be assigned this index again.
|
|
43
|
-
*
|
|
44
|
-
* @param peerId - The peer that failed
|
|
45
|
-
* @param index - The request index that failed
|
|
46
|
-
*/
|
|
47
|
-
markPeerFailedForIndex(peerId: PeerId, index: number): void;
|
|
48
|
-
/**
|
|
49
|
-
* Removes a peer and replaces it with a new one, maintaining the same position
|
|
50
|
-
* in the batch array to keep request distribution consistent
|
|
51
|
-
*
|
|
52
|
-
* @param peerId - The peer to remove and replace
|
|
53
|
-
*/
|
|
54
|
-
removePeerAndReplace(peerId: PeerId): void;
|
|
55
|
-
/**
|
|
56
|
-
* Gets the number of active peers
|
|
57
|
-
*/
|
|
58
|
-
get activePeerCount(): number;
|
|
59
|
-
/**
|
|
60
|
-
* Gets the number of requests each peer is assigned to handle
|
|
61
|
-
*/
|
|
62
|
-
get requestsPerBucket(): number;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmF0Y2hfY29ubmVjdGlvbl9zYW1wbGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvc2VydmljZXMvcmVxcmVzcC9jb25uZWN0aW9uLXNhbXBsZXIvYmF0Y2hfY29ubmVjdGlvbl9zYW1wbGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWhELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFakU7Ozs7Ozs7Ozs7OztHQVlHO0FBQ0gscUJBQWEsc0JBQXNCO0lBTy9CLE9BQU8sQ0FBQyxRQUFRLENBQUMsaUJBQWlCO0lBSWxDLE9BQU8sQ0FBQyxRQUFRLENBQUMsTUFBTTtJQVZ6QixPQUFPLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBZ0I7SUFDdEMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxlQUFlLENBQVM7SUFDekMsMkVBQTJFO0lBQzNFLE9BQU8sQ0FBQyxRQUFRLENBQUMsaUJBQWlCLENBQXVDO0lBRXpFLFlBQ21CLGlCQUFpQixFQUFFLGlCQUFpQixFQUNyRCxTQUFTLEVBQUUsTUFBTSxFQUNqQixRQUFRLEVBQUUsTUFBTSxFQUNoQixPQUFPLENBQUMsRUFBRSxNQUFNLEVBQUUsRUFDRCxNQUFNLHlDQUF1RCxFQWUvRTtJQUVEOzs7Ozs7O09BT0c7SUFDSCxpQkFBaUIsQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE1BQU0sR0FBRyxTQUFTLENBMkJuRDtJQUVEOzs7OztPQUtHO0lBQ0gsT0FBTyxDQUFDLGFBQWE7SUFjckI7Ozs7OztPQU1HO0lBQ0gsc0JBQXNCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsTUFBTSxHQUFHLElBQUksQ0FTMUQ7SUFFRDs7Ozs7T0FLRztJQUNILG9CQUFvQixDQUFDLE1BQU0sRUFBRSxNQUFNLEdBQUcsSUFBSSxDQWlCekM7SUFFRDs7T0FFRztJQUNILElBQUksZUFBZSxJQUFJLE1BQU0sQ0FFNUI7SUFFRDs7T0FFRztJQUNILElBQUksaUJBQWlCLElBQUksTUFBTSxDQUU5QjtDQUNGIn0=
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch_connection_sampler.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/connection-sampler/batch_connection_sampler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAsB;IAO/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAIlC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAVzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAuC;IAEzE,YACmB,iBAAiB,EAAE,iBAAiB,EACrD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAAE,EACD,MAAM,yCAAuD,EAe/E;IAED;;;;;;;OAOG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA2BnD;IAED;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAcrB;;;;;;OAMG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAS1D;IAED;;;;;OAKG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAiBzC;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;OAEG;IACH,IAAI,iBAAiB,IAAI,MAAM,CAE9B;CACF"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
/**
|
|
3
|
-
* Manages batches of peers for parallel request processing.
|
|
4
|
-
* Tracks active peers and provides deterministic peer assignment for requests.
|
|
5
|
-
*
|
|
6
|
-
* Example with 3 peers and 10 requests:
|
|
7
|
-
*
|
|
8
|
-
* Peers: [P1] [P2] [P3]
|
|
9
|
-
* ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
10
|
-
* Requests: 0,1,2,9 | 3,4,5 | 6,7,8
|
|
11
|
-
*
|
|
12
|
-
* Each peer handles a bucket of consecutive requests.
|
|
13
|
-
* If a peer fails, it is replaced while maintaining the same bucket.
|
|
14
|
-
*/ export class BatchConnectionSampler {
|
|
15
|
-
connectionSampler;
|
|
16
|
-
logger;
|
|
17
|
-
batch;
|
|
18
|
-
requestsPerPeer;
|
|
19
|
-
/** Tracks peer-index combinations that returned empty/invalid responses */ failedPeerIndices;
|
|
20
|
-
constructor(connectionSampler, batchSize, maxPeers, exclude, logger = createLogger('p2p:reqresp:batch-connection-sampler')){
|
|
21
|
-
this.connectionSampler = connectionSampler;
|
|
22
|
-
this.logger = logger;
|
|
23
|
-
this.batch = [];
|
|
24
|
-
this.failedPeerIndices = new Map();
|
|
25
|
-
if (maxPeers <= 0) {
|
|
26
|
-
throw new Error('Max peers cannot be 0');
|
|
27
|
-
}
|
|
28
|
-
if (batchSize <= 0) {
|
|
29
|
-
throw new Error('Batch size cannot be 0');
|
|
30
|
-
}
|
|
31
|
-
// Calculate how many requests each peer should handle, cannot be 0
|
|
32
|
-
this.requestsPerPeer = Math.max(1, Math.floor(batchSize / maxPeers));
|
|
33
|
-
// Sample initial peers
|
|
34
|
-
const excluding = exclude && new Map(exclude.map((peerId)=>[
|
|
35
|
-
peerId.toString(),
|
|
36
|
-
true
|
|
37
|
-
]));
|
|
38
|
-
this.batch = this.connectionSampler.samplePeersBatch(maxPeers, excluding);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Gets the peer responsible for handling a specific request index.
|
|
42
|
-
* If the primary peer has previously failed for this index, tries other peers.
|
|
43
|
-
* If all batch peers have failed, attempts to sample a new peer.
|
|
44
|
-
*
|
|
45
|
-
* @param index - The request index
|
|
46
|
-
* @returns The peer assigned to handle this request, or undefined if no peer available
|
|
47
|
-
*/ getPeerForRequest(index) {
|
|
48
|
-
if (this.batch.length === 0) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
// Calculate which peer bucket this index belongs to
|
|
52
|
-
const primaryPeerIndex = Math.floor(index / this.requestsPerPeer) % this.batch.length;
|
|
53
|
-
// Try peers starting from primary, wrapping around
|
|
54
|
-
for(let offset = 0; offset < this.batch.length; offset++){
|
|
55
|
-
const peerIndex = (primaryPeerIndex + offset) % this.batch.length;
|
|
56
|
-
const peer = this.batch[peerIndex];
|
|
57
|
-
const peerKey = peer.toString();
|
|
58
|
-
const failedIndices = this.failedPeerIndices.get(peerKey);
|
|
59
|
-
if (!failedIndices || !failedIndices.has(index)) {
|
|
60
|
-
return peer;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// All batch peers have failed for this index - try to sample a new peer
|
|
64
|
-
const newPeer = this.sampleNewPeer();
|
|
65
|
-
if (newPeer) {
|
|
66
|
-
return newPeer;
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Attempts to sample a new peer that isn't already in the batch.
|
|
72
|
-
* If successful, adds the peer to the batch.
|
|
73
|
-
*
|
|
74
|
-
* @returns The new peer if one was sampled, undefined otherwise
|
|
75
|
-
*/ sampleNewPeer() {
|
|
76
|
-
// Exclude all current batch peers
|
|
77
|
-
const excluding = new Map(this.batch.map((p)=>[
|
|
78
|
-
p.toString(),
|
|
79
|
-
true
|
|
80
|
-
]));
|
|
81
|
-
const newPeer = this.connectionSampler.getPeer(excluding);
|
|
82
|
-
if (newPeer) {
|
|
83
|
-
this.batch.push(newPeer);
|
|
84
|
-
this.logger.trace('Sampled new peer for exhausted index', {
|
|
85
|
-
newPeer: newPeer.toString()
|
|
86
|
-
});
|
|
87
|
-
return newPeer;
|
|
88
|
-
}
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Marks that a peer returned an empty/invalid response for a specific request index.
|
|
93
|
-
* The peer will not be assigned this index again.
|
|
94
|
-
*
|
|
95
|
-
* @param peerId - The peer that failed
|
|
96
|
-
* @param index - The request index that failed
|
|
97
|
-
*/ markPeerFailedForIndex(peerId, index) {
|
|
98
|
-
const peerKey = peerId.toString();
|
|
99
|
-
let failedIndices = this.failedPeerIndices.get(peerKey);
|
|
100
|
-
if (!failedIndices) {
|
|
101
|
-
failedIndices = new Set();
|
|
102
|
-
this.failedPeerIndices.set(peerKey, failedIndices);
|
|
103
|
-
}
|
|
104
|
-
failedIndices.add(index);
|
|
105
|
-
this.logger.trace('Marked peer failed for index', {
|
|
106
|
-
peerId: peerKey,
|
|
107
|
-
index
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Removes a peer and replaces it with a new one, maintaining the same position
|
|
112
|
-
* in the batch array to keep request distribution consistent
|
|
113
|
-
*
|
|
114
|
-
* @param peerId - The peer to remove and replace
|
|
115
|
-
*/ removePeerAndReplace(peerId) {
|
|
116
|
-
const index = this.batch.findIndex((p)=>p === peerId);
|
|
117
|
-
if (index === -1) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const excluding = new Map([
|
|
121
|
-
[
|
|
122
|
-
peerId.toString(),
|
|
123
|
-
true
|
|
124
|
-
]
|
|
125
|
-
]);
|
|
126
|
-
const newPeer = this.connectionSampler.getPeer(excluding); // Q: Shouldn't we accumulate all excluded peers? Otherwise the sampler could return us a previously excluded peer?
|
|
127
|
-
if (newPeer) {
|
|
128
|
-
this.batch[index] = newPeer;
|
|
129
|
-
this.logger.trace('Replaced peer', {
|
|
130
|
-
peerId,
|
|
131
|
-
newPeer
|
|
132
|
-
});
|
|
133
|
-
} else {
|
|
134
|
-
// If we couldn't get a replacement, remove the peer and compact the array
|
|
135
|
-
this.batch.splice(index, 1);
|
|
136
|
-
this.logger.trace('Removed peer', {
|
|
137
|
-
peerId
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Gets the number of active peers
|
|
143
|
-
*/ get activePeerCount() {
|
|
144
|
-
return this.batch.length;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Gets the number of requests each peer is assigned to handle
|
|
148
|
-
*/ get requestsPerBucket() {
|
|
149
|
-
return this.requestsPerPeer;
|
|
150
|
-
}
|
|
151
|
-
}
|