@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.733c4a3
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 +7 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +35 -11
- package/dest/client/interface.d.ts +45 -32
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +38 -50
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +145 -200
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -6
- package/dest/config.d.ts +24 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -6
- 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/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- 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 +353 -87
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- 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/index.d.ts +3 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/interface.d.ts +5 -5
- package/dest/mem_pools/interface.d.ts.map +1 -1
- 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 +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
- 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 +10 -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 -1
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -0
- 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 +22 -8
- 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 +39 -5
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +74 -5
- 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 +27 -4
- 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 +11 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +13 -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 +312 -169
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
- 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/block_header_validator.d.ts +16 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- 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/timestamp_validator.d.ts +20 -4
- 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 +13 -5
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +10 -4
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +4 -3
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +346 -0
- package/dest/services/libp2p/libp2p_service.d.ts +91 -38
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +411 -321
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +25 -2
- 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/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
- 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 +15 -0
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- 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 +11 -4
- package/dest/services/service.d.ts +39 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +19 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +46 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +56 -36
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +90 -0
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +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 +7 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +60 -26
- package/dest/services/tx_collection/tx_collection.d.ts +23 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +75 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +26 -29
- 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/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -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 +9 -6
- package/dest/services/tx_provider.d.ts +4 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +9 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +29 -2
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +103 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -1
- package/dest/test-helpers/testbench-utils.d.ts +43 -38
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +128 -59
- 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 +10 -10
- 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 +66 -14
- package/src/client/interface.ts +61 -33
- package/src/client/p2p_client.ts +179 -236
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
- package/src/config.ts +35 -11
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +496 -91
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/index.ts +4 -1
- package/src/mem_pools/interface.ts +4 -4
- 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 +76 -10
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- 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 +15 -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 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +23 -8
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +103 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +32 -5
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +18 -7
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +347 -166
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/msg_validators/tx_validator/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- 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/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +18 -6
- package/src/services/encoding.ts +4 -3
- package/src/services/gossipsub/README.md +641 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +487 -0
- package/src/services/libp2p/libp2p_service.ts +431 -344
- package/src/services/peer-manager/peer_scoring.ts +25 -0
- 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/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +13 -3
- package/src/services/service.ts +51 -2
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +65 -32
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +1 -0
- 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 +66 -33
- package/src/services/tx_collection/tx_collection.ts +113 -16
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +10 -8
- package/src/services/tx_provider.ts +10 -9
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +143 -3
- package/src/test-helpers/reqresp-nodes.ts +2 -1
- package/src/test-helpers/testbench-utils.ts +127 -71
- package/src/testbench/p2p_client_testbench_worker.ts +22 -15
- package/src/util.ts +7 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
3
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
import type { FileStoreTxSource } from './file_store_tx_source.js';
|
|
8
|
+
import type { TxAddContext, TxCollectionSink } from './tx_collection_sink.js';
|
|
9
|
+
|
|
10
|
+
/** Configuration for a FileStoreTxCollection instance. */
|
|
11
|
+
export type FileStoreCollectionConfig = {
|
|
12
|
+
workerCount: number;
|
|
13
|
+
backoffBaseMs: number;
|
|
14
|
+
backoffMaxMs: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type FileStoreTxEntry = {
|
|
18
|
+
txHash: string;
|
|
19
|
+
context: TxAddContext;
|
|
20
|
+
deadline: Date;
|
|
21
|
+
attempts: number;
|
|
22
|
+
lastAttemptTime: number;
|
|
23
|
+
nextSourceIndex: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Collects txs from file stores as a fallback after P2P methods have been tried.
|
|
28
|
+
* Uses a shared worker pool that pulls entries with priority (fewest attempts first),
|
|
29
|
+
* retries with round-robin across sources, and applies exponential backoff between
|
|
30
|
+
* full cycles through all sources.
|
|
31
|
+
*/
|
|
32
|
+
export class FileStoreTxCollection {
|
|
33
|
+
/** Map from tx hash string to entry for all pending downloads. */
|
|
34
|
+
private entries = new Map<string, FileStoreTxEntry>();
|
|
35
|
+
|
|
36
|
+
/** Worker promises for the shared worker pool. */
|
|
37
|
+
private workers: Promise<void>[] = [];
|
|
38
|
+
|
|
39
|
+
/** Whether the worker pool is running. */
|
|
40
|
+
private running = false;
|
|
41
|
+
|
|
42
|
+
/** Signal used to wake sleeping workers when new entries arrive or stop is called. */
|
|
43
|
+
private wakeSignal: PromiseWithResolvers<void>;
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
private readonly sources: FileStoreTxSource[],
|
|
47
|
+
private readonly txCollectionSink: TxCollectionSink,
|
|
48
|
+
private readonly config: FileStoreCollectionConfig,
|
|
49
|
+
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
50
|
+
private readonly log: Logger = createLogger('p2p:file_store_tx_collection'),
|
|
51
|
+
) {
|
|
52
|
+
this.wakeSignal = promiseWithResolvers<void>();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Starts the shared worker pool. */
|
|
56
|
+
public start(): void {
|
|
57
|
+
if (this.sources.length === 0) {
|
|
58
|
+
this.log.debug('No file store sources configured');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.running = true;
|
|
62
|
+
for (let i = 0; i < this.config.workerCount; i++) {
|
|
63
|
+
this.workers.push(this.workerLoop());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Stops all workers and clears state. */
|
|
68
|
+
public async stop(): Promise<void> {
|
|
69
|
+
this.running = false;
|
|
70
|
+
this.wake();
|
|
71
|
+
await Promise.all(this.workers);
|
|
72
|
+
this.workers = [];
|
|
73
|
+
this.entries.clear();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Adds entries to the shared map and wakes workers. */
|
|
77
|
+
public startCollecting(txHashes: TxHash[], context: TxAddContext, deadline: Date): void {
|
|
78
|
+
if (this.sources.length === 0 || txHashes.length === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (+deadline <= this.dateProvider.now()) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const txHash of txHashes) {
|
|
86
|
+
const hashStr = txHash.toString();
|
|
87
|
+
if (!this.entries.has(hashStr)) {
|
|
88
|
+
this.entries.set(hashStr, {
|
|
89
|
+
txHash: hashStr,
|
|
90
|
+
context,
|
|
91
|
+
deadline,
|
|
92
|
+
attempts: 0,
|
|
93
|
+
lastAttemptTime: 0,
|
|
94
|
+
nextSourceIndex: Math.floor(Math.random() * this.sources.length),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.wake();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Removes entries for txs that have been found elsewhere. */
|
|
102
|
+
public foundTxs(txs: Tx[]): void {
|
|
103
|
+
for (const tx of txs) {
|
|
104
|
+
this.entries.delete(tx.getTxHash().toString());
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Clears all pending entries. */
|
|
109
|
+
public clearPending(): void {
|
|
110
|
+
this.entries.clear();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private async workerLoop(): Promise<void> {
|
|
114
|
+
while (this.running) {
|
|
115
|
+
const action = this.getNextAction();
|
|
116
|
+
if (action.type === 'sleep') {
|
|
117
|
+
await action.promise;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const entry = action.entry;
|
|
122
|
+
const source = this.sources[entry.nextSourceIndex % this.sources.length];
|
|
123
|
+
entry.nextSourceIndex++;
|
|
124
|
+
entry.attempts++;
|
|
125
|
+
entry.lastAttemptTime = this.dateProvider.now();
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const result = await this.txCollectionSink.collect(
|
|
129
|
+
() => source.getTxsByHash([TxHash.fromString(entry.txHash)]),
|
|
130
|
+
[entry.txHash],
|
|
131
|
+
{
|
|
132
|
+
description: `file-store ${source.getInfo()}`,
|
|
133
|
+
method: 'file-store',
|
|
134
|
+
fileStore: source.getInfo(),
|
|
135
|
+
},
|
|
136
|
+
entry.context,
|
|
137
|
+
);
|
|
138
|
+
if (result.txs.length > 0) {
|
|
139
|
+
this.entries.delete(entry.txHash);
|
|
140
|
+
}
|
|
141
|
+
} catch (err) {
|
|
142
|
+
this.log.trace(`Error downloading tx ${entry.txHash} from ${source.getInfo()}`, { err });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Single-pass scan: removes expired entries, finds the best ready entry, or computes sleep time. */
|
|
148
|
+
private getNextAction(): { type: 'process'; entry: FileStoreTxEntry } | { type: 'sleep'; promise: Promise<void> } {
|
|
149
|
+
const now = this.dateProvider.now();
|
|
150
|
+
let best: FileStoreTxEntry | undefined;
|
|
151
|
+
let earliestReadyAt = Infinity;
|
|
152
|
+
|
|
153
|
+
for (const [key, entry] of this.entries) {
|
|
154
|
+
if (+entry.deadline <= now) {
|
|
155
|
+
this.entries.delete(key);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const backoffMs = this.getBackoffMs(entry);
|
|
159
|
+
const readyAt = entry.lastAttemptTime + backoffMs;
|
|
160
|
+
if (readyAt > now) {
|
|
161
|
+
earliestReadyAt = Math.min(earliestReadyAt, readyAt);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!best || entry.attempts < best.attempts) {
|
|
165
|
+
best = entry;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (best) {
|
|
170
|
+
return { type: 'process', entry: best };
|
|
171
|
+
}
|
|
172
|
+
if (earliestReadyAt < Infinity) {
|
|
173
|
+
return { type: 'sleep', promise: this.sleepOrWake(earliestReadyAt - now) };
|
|
174
|
+
}
|
|
175
|
+
return { type: 'sleep', promise: this.waitForWake() };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Computes backoff for an entry. Backoff applies after a full cycle through all sources. */
|
|
179
|
+
private getBackoffMs(entry: FileStoreTxEntry): number {
|
|
180
|
+
const fullCycles = Math.floor(entry.attempts / this.sources.length);
|
|
181
|
+
if (fullCycles === 0) {
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
return Math.min(this.config.backoffBaseMs * Math.pow(2, fullCycles - 1), this.config.backoffMaxMs);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Resolves the current wake signal and creates a new one. */
|
|
188
|
+
private wake(): void {
|
|
189
|
+
this.wakeSignal.resolve();
|
|
190
|
+
this.wakeSignal = promiseWithResolvers<void>();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Waits until the wake signal is resolved. */
|
|
194
|
+
private async waitForWake(): Promise<void> {
|
|
195
|
+
await this.wakeSignal.promise;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Sleeps for the given duration or until the wake signal is resolved. */
|
|
199
|
+
private async sleepOrWake(ms: number): Promise<void> {
|
|
200
|
+
await Promise.race([sleep(ms), this.wakeSignal.promise]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
3
|
+
import { type ReadOnlyFileStore, createReadOnlyFileStore } from '@aztec/stdlib/file-store';
|
|
4
|
+
import { Tx, type TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import {
|
|
6
|
+
type Histogram,
|
|
7
|
+
Metrics,
|
|
8
|
+
type TelemetryClient,
|
|
9
|
+
type UpDownCounter,
|
|
10
|
+
getTelemetryClient,
|
|
11
|
+
} from '@aztec/telemetry-client';
|
|
12
|
+
|
|
13
|
+
import type { TxSource, TxSourceCollectionResult } from './tx_source.js';
|
|
14
|
+
|
|
15
|
+
/** TxSource implementation that downloads txs from a file store. */
|
|
16
|
+
export class FileStoreTxSource implements TxSource {
|
|
17
|
+
private downloadsSuccess: UpDownCounter;
|
|
18
|
+
private downloadsFailed: UpDownCounter;
|
|
19
|
+
private downloadDuration: Histogram;
|
|
20
|
+
private downloadSize: Histogram;
|
|
21
|
+
|
|
22
|
+
private constructor(
|
|
23
|
+
private readonly fileStore: ReadOnlyFileStore,
|
|
24
|
+
private readonly baseUrl: string,
|
|
25
|
+
private readonly basePath: string,
|
|
26
|
+
private readonly log: Logger,
|
|
27
|
+
telemetry: TelemetryClient,
|
|
28
|
+
) {
|
|
29
|
+
const meter = telemetry.getMeter('file-store-tx-source');
|
|
30
|
+
this.downloadsSuccess = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_SUCCESS);
|
|
31
|
+
this.downloadsFailed = meter.createUpDownCounter(Metrics.TX_FILE_STORE_DOWNLOADS_FAILED);
|
|
32
|
+
this.downloadDuration = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_DURATION);
|
|
33
|
+
this.downloadSize = meter.createHistogram(Metrics.TX_FILE_STORE_DOWNLOAD_SIZE);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a FileStoreTxSource from a URL.
|
|
38
|
+
* @param url - The file store URL (s3://, gs://, file://, http://, https://).
|
|
39
|
+
* @param basePath - Base path for tx files within the store.
|
|
40
|
+
* @param log - Optional logger.
|
|
41
|
+
* @param telemetry - Optional telemetry client.
|
|
42
|
+
* @returns The FileStoreTxSource instance, or undefined if creation fails.
|
|
43
|
+
*/
|
|
44
|
+
public static async create(
|
|
45
|
+
url: string,
|
|
46
|
+
basePath: string,
|
|
47
|
+
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
48
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
49
|
+
): Promise<FileStoreTxSource | undefined> {
|
|
50
|
+
try {
|
|
51
|
+
const fileStore = await createReadOnlyFileStore(url, log);
|
|
52
|
+
if (!fileStore) {
|
|
53
|
+
log.warn(`Failed to create file store for URL: ${url}`);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return new FileStoreTxSource(fileStore, url, basePath, log, telemetry);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
log.warn(`Error creating file store for URL: ${url}`, { error: err });
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getInfo(): string {
|
|
64
|
+
return `file-store:${this.baseUrl}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async getTxsByHash(txHashes: TxHash[]): Promise<TxSourceCollectionResult> {
|
|
68
|
+
const invalidTxHashes: string[] = [];
|
|
69
|
+
return {
|
|
70
|
+
validTxs: (
|
|
71
|
+
await Promise.all(
|
|
72
|
+
txHashes.map(async txHash => {
|
|
73
|
+
const path = `${this.basePath}/txs/${txHash.toString()}.bin`;
|
|
74
|
+
const timer = new Timer();
|
|
75
|
+
try {
|
|
76
|
+
const buffer = await this.fileStore.read(path);
|
|
77
|
+
const tx = Tx.fromBuffer(buffer);
|
|
78
|
+
if ((await tx.validateTxHash()) && txHash.equals(tx.txHash)) {
|
|
79
|
+
this.downloadsSuccess.add(1);
|
|
80
|
+
this.downloadDuration.record(Math.ceil(timer.ms()));
|
|
81
|
+
this.downloadSize.record(buffer.length);
|
|
82
|
+
return tx;
|
|
83
|
+
} else {
|
|
84
|
+
invalidTxHashes.push(tx.txHash.toString());
|
|
85
|
+
this.downloadsFailed.add(1);
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
// Tx not found or error reading - return undefined
|
|
90
|
+
this.downloadsFailed.add(1);
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
).filter(tx => tx !== undefined),
|
|
96
|
+
invalidTxHashes: invalidTxHashes,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Creates FileStoreTxSource instances from URLs.
|
|
103
|
+
* @param urls - Array of file store URLs.
|
|
104
|
+
* @param basePath - Base path for tx files within each store.
|
|
105
|
+
* @param log - Optional logger.
|
|
106
|
+
* @param telemetry - Optional telemetry client.
|
|
107
|
+
* @returns Array of successfully created FileStoreTxSource instances.
|
|
108
|
+
*/
|
|
109
|
+
export async function createFileStoreTxSources(
|
|
110
|
+
urls: string[],
|
|
111
|
+
basePath: string,
|
|
112
|
+
log: Logger = createLogger('p2p:file_store_tx_source'),
|
|
113
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
114
|
+
): Promise<FileStoreTxSource[]> {
|
|
115
|
+
const sources = await Promise.all(urls.map(url => FileStoreTxSource.create(url, basePath, log, telemetry)));
|
|
116
|
+
return sources.filter((s): s is FileStoreTxSource => s !== undefined);
|
|
117
|
+
}
|
|
@@ -18,7 +18,13 @@ export class TxCollectionInstrumentation {
|
|
|
18
18
|
const meter = client.getMeter(name);
|
|
19
19
|
|
|
20
20
|
this.txsCollected = createUpDownCounterWithDefault(meter, Metrics.TX_COLLECTOR_COUNT, {
|
|
21
|
-
[Attributes.TX_COLLECTION_METHOD]: [
|
|
21
|
+
[Attributes.TX_COLLECTION_METHOD]: [
|
|
22
|
+
'fast-req-resp',
|
|
23
|
+
'fast-node-rpc',
|
|
24
|
+
'slow-req-resp',
|
|
25
|
+
'slow-node-rpc',
|
|
26
|
+
'file-store',
|
|
27
|
+
],
|
|
22
28
|
});
|
|
23
29
|
|
|
24
30
|
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
2
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tracks which transactions are still missing and need to be fetched.
|
|
6
|
+
* Allows external code to mark transactions as fetched, enabling coordination
|
|
7
|
+
* between multiple fetching mechanisms (e.g., BatchTxRequester and Rpc Node requests).
|
|
8
|
+
*/
|
|
9
|
+
export interface IMissingTxsTracker {
|
|
10
|
+
/** Returns the set of transaction hashes that are still missing. */
|
|
11
|
+
get missingTxHashes(): Set<string>;
|
|
12
|
+
/** Size of this.missingTxHashes */
|
|
13
|
+
get numberOfMissingTxs(): number;
|
|
14
|
+
/** Are all requested txs are fetched */
|
|
15
|
+
allFetched(): boolean;
|
|
16
|
+
/** Checks that transaction is still missing */
|
|
17
|
+
isMissing(txHash: string): boolean;
|
|
18
|
+
/** Marks a transaction as fetched. Returns true if it was previously missing. */
|
|
19
|
+
markFetched(tx: Tx): boolean;
|
|
20
|
+
/** Get list of collected txs */
|
|
21
|
+
get collectedTxs(): Tx[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class MissingTxsTracker implements IMissingTxsTracker {
|
|
25
|
+
public readonly collectedTxs: Tx[] = [];
|
|
26
|
+
|
|
27
|
+
private constructor(public readonly missingTxHashes: Set<string>) {}
|
|
28
|
+
|
|
29
|
+
public static fromArray(hashes: TxHash[] | string[]) {
|
|
30
|
+
return new MissingTxsTracker(new Set(hashes.map(hash => hash.toString())));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
markFetched(tx: Tx): boolean {
|
|
34
|
+
if (this.missingTxHashes.delete(tx.txHash.toString())) {
|
|
35
|
+
this.collectedTxs.push(tx);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get numberOfMissingTxs(): number {
|
|
42
|
+
return this.missingTxHashes.size;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
allFetched(): boolean {
|
|
46
|
+
return this.numberOfMissingTxs === 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isMissing(txHash: string): boolean {
|
|
50
|
+
return this.missingTxHashes.has(txHash.toString());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
-
import type
|
|
3
|
+
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { PeerId } from '@libp2p/interface';
|
|
6
6
|
|
|
@@ -9,6 +9,7 @@ import type { BatchTxRequesterConfig } from '../reqresp/batch-tx-requester/confi
|
|
|
9
9
|
import type { BatchTxRequesterLibP2PService } from '../reqresp/batch-tx-requester/interface.js';
|
|
10
10
|
import type { IBatchRequestTxValidator } from '../reqresp/batch-tx-requester/tx_validator.js';
|
|
11
11
|
import { type BlockTxsSource, ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
|
|
12
|
+
import type { IMissingTxsTracker } from './missing_txs_tracker.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Strategy interface for collecting missing transactions for a block or proposal.
|
|
@@ -17,14 +18,14 @@ import { type BlockTxsSource, ReqRespSubProtocol, chunkTxHashesRequest } from '.
|
|
|
17
18
|
export interface MissingTxsCollector {
|
|
18
19
|
/**
|
|
19
20
|
* Collect missing transactions for a block or proposal.
|
|
20
|
-
* @param
|
|
21
|
+
* @param missingTxsTracker - The missing transactions tracker
|
|
21
22
|
* @param blockTxsSource - The block or proposal containing the transactions
|
|
22
23
|
* @param pinnedPeer - Optional peer expected to have the transactions
|
|
23
24
|
* @param timeoutMs - Timeout in milliseconds
|
|
24
25
|
* @returns The collected transactions
|
|
25
26
|
*/
|
|
26
27
|
collectTxs(
|
|
27
|
-
|
|
28
|
+
missingTxsTracker: IMissingTxsTracker,
|
|
28
29
|
blockTxsSource: BlockTxsSource,
|
|
29
30
|
pinnedPeer: PeerId | undefined,
|
|
30
31
|
timeoutMs: number,
|
|
@@ -45,7 +46,7 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
|
|
|
45
46
|
) {}
|
|
46
47
|
|
|
47
48
|
async collectTxs(
|
|
48
|
-
|
|
49
|
+
missingTxsTracker: IMissingTxsTracker,
|
|
49
50
|
blockTxsSource: BlockTxsSource,
|
|
50
51
|
pinnedPeer: PeerId | undefined,
|
|
51
52
|
timeoutMs: number,
|
|
@@ -58,7 +59,7 @@ export class BatchTxRequesterCollector implements MissingTxsCollector {
|
|
|
58
59
|
} = this.batchTxRequesterConfig ?? {};
|
|
59
60
|
|
|
60
61
|
const batchRequester = new BatchTxRequester(
|
|
61
|
-
|
|
62
|
+
missingTxsTracker,
|
|
62
63
|
blockTxsSource,
|
|
63
64
|
pinnedPeer,
|
|
64
65
|
timeoutMs,
|
|
@@ -93,14 +94,14 @@ export class SendBatchRequestCollector implements MissingTxsCollector {
|
|
|
93
94
|
) {}
|
|
94
95
|
|
|
95
96
|
async collectTxs(
|
|
96
|
-
|
|
97
|
+
missingTxsTracker: IMissingTxsTracker,
|
|
97
98
|
_blockTxsSource: BlockTxsSource,
|
|
98
99
|
pinnedPeer: PeerId | undefined,
|
|
99
100
|
timeoutMs: number,
|
|
100
101
|
): Promise<Tx[]> {
|
|
101
102
|
const txs = await this.p2pService.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
102
103
|
ReqRespSubProtocol.TX,
|
|
103
|
-
chunkTxHashesRequest(
|
|
104
|
+
chunkTxHashesRequest(Array.from(missingTxsTracker.missingTxHashes).map(TxHash.fromString)),
|
|
104
105
|
pinnedPeer,
|
|
105
106
|
timeoutMs,
|
|
106
107
|
this.maxPeers,
|
|
@@ -8,8 +8,7 @@ import type { L2Block } from '@aztec/stdlib/block';
|
|
|
8
8
|
import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
9
9
|
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
10
10
|
|
|
11
|
-
import { type ReqRespInterface, ReqRespSubProtocol } from '../reqresp/
|
|
12
|
-
import { chunkTxHashesRequest } from '../reqresp/protocols/tx.js';
|
|
11
|
+
import { type ReqRespInterface, ReqRespSubProtocol, chunkTxHashesRequest } from '../reqresp/index.js';
|
|
13
12
|
import type { TxCollectionConfig } from './config.js';
|
|
14
13
|
import type { FastTxCollection } from './fast_tx_collection.js';
|
|
15
14
|
import type { MissingTxInfo } from './tx_collection.js';
|
|
@@ -91,6 +90,7 @@ export class SlowTxCollection {
|
|
|
91
90
|
|
|
92
91
|
for (const txHash of txHashes) {
|
|
93
92
|
this.missingTxs.set(txHash.toString(), {
|
|
93
|
+
block,
|
|
94
94
|
blockNumber: block.number,
|
|
95
95
|
deadline: this.getDeadlineForSlot(block.header.getSlot()),
|
|
96
96
|
readyForReqResp: this.nodes.length === 0, // If we have no nodes, we can start reqresp immediately
|
|
@@ -109,18 +109,26 @@ export class SlowTxCollection {
|
|
|
109
109
|
|
|
110
110
|
// Gather all missing txs that are not in fast collection and request them from the node
|
|
111
111
|
const missingTxs = this.getMissingTxsForSlowCollection();
|
|
112
|
-
|
|
113
|
-
if (missingTxHashes.length === 0) {
|
|
112
|
+
if (missingTxs.length === 0) {
|
|
114
113
|
return;
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
//
|
|
118
|
-
for (const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
// Group by block so we pass the correct mined context to the sink
|
|
117
|
+
for (const entries of this.groupByBlock(missingTxs)) {
|
|
118
|
+
const block = entries[0][1].block;
|
|
119
|
+
const txHashes = entries.map(([txHash]) => TxHash.fromString(txHash));
|
|
120
|
+
for (const batch of chunk(txHashes, this.config.txCollectionNodeRpcMaxBatchSize)) {
|
|
121
|
+
await this.txCollectionSink.collect(
|
|
122
|
+
() => node.getTxsByHash(batch),
|
|
123
|
+
batch.map(h => h.toString()),
|
|
124
|
+
{
|
|
125
|
+
description: `node ${node.getInfo()}`,
|
|
126
|
+
node: node.getInfo(),
|
|
127
|
+
method: 'slow-node-rpc',
|
|
128
|
+
},
|
|
129
|
+
{ type: 'mined', block },
|
|
130
|
+
);
|
|
131
|
+
}
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
// Mark every tx that is still missing as ready for reqresp.
|
|
@@ -149,25 +157,30 @@ export class SlowTxCollection {
|
|
|
149
157
|
|
|
150
158
|
const pinnedPeer = undefined;
|
|
151
159
|
const timeoutMs = this.config.txCollectionSlowReqRespTimeoutMs;
|
|
152
|
-
const maxPeers = boundInclusive(Math.ceil(missingTxs.length / 3), 4, 16);
|
|
153
160
|
const maxRetryAttempts = 3;
|
|
154
|
-
// Send a batch request via reqresp for the missing txs
|
|
155
|
-
await this.txCollectionSink.collect(
|
|
156
|
-
async txHashes => {
|
|
157
|
-
const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
158
|
-
ReqRespSubProtocol.TX,
|
|
159
|
-
chunkTxHashesRequest(txHashes),
|
|
160
|
-
pinnedPeer,
|
|
161
|
-
timeoutMs,
|
|
162
|
-
maxPeers,
|
|
163
|
-
maxRetryAttempts,
|
|
164
|
-
);
|
|
165
161
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
162
|
+
// Group by block so we pass the correct mined context to the sink
|
|
163
|
+
for (const entries of this.groupByBlock(missingTxs)) {
|
|
164
|
+
const block = entries[0][1].block;
|
|
165
|
+
const txHashes = entries.map(([txHash]) => TxHash.fromString(txHash));
|
|
166
|
+
const maxPeers = boundInclusive(Math.ceil(txHashes.length / 3), 4, 16);
|
|
167
|
+
await this.txCollectionSink.collect(
|
|
168
|
+
async () => {
|
|
169
|
+
const txs = await this.reqResp.sendBatchRequest<ReqRespSubProtocol.TX>(
|
|
170
|
+
ReqRespSubProtocol.TX,
|
|
171
|
+
chunkTxHashesRequest(txHashes),
|
|
172
|
+
pinnedPeer,
|
|
173
|
+
timeoutMs,
|
|
174
|
+
maxPeers,
|
|
175
|
+
maxRetryAttempts,
|
|
176
|
+
);
|
|
177
|
+
return { validTxs: txs.flat(), invalidTxHashes: [] };
|
|
178
|
+
},
|
|
179
|
+
txHashes.map(h => h.toString()),
|
|
180
|
+
{ description: 'slow reqresp', timeoutMs, method: 'slow-req-resp' },
|
|
181
|
+
{ type: 'mined', block },
|
|
182
|
+
);
|
|
183
|
+
}
|
|
171
184
|
}
|
|
172
185
|
|
|
173
186
|
/** Retrieves all missing txs for the slow collection process. This is, all missing txs that are not part of a fast request. */
|
|
@@ -183,7 +196,7 @@ export class SlowTxCollection {
|
|
|
183
196
|
// from mined unproven blocks it has seen in the past.
|
|
184
197
|
const fastRequests = this.fastCollection.getFastCollectionRequests();
|
|
185
198
|
const fastCollectionTxs: Set<string> = new Set(
|
|
186
|
-
|
|
199
|
+
fastRequests.values().flatMap(r => Array.from(r.missingTxTracker.missingTxHashes)),
|
|
187
200
|
);
|
|
188
201
|
|
|
189
202
|
// Return all missing txs that are not in fastCollectionTxs and are ready for reqresp if requested
|
|
@@ -223,11 +236,31 @@ export class SlowTxCollection {
|
|
|
223
236
|
}
|
|
224
237
|
}
|
|
225
238
|
|
|
239
|
+
/** Groups missing tx entries by block number. */
|
|
240
|
+
private groupByBlock(entries: [string, MissingTxInfo][]): [string, MissingTxInfo][][] {
|
|
241
|
+
const groups = new Map<number, [string, MissingTxInfo][]>();
|
|
242
|
+
for (const entry of entries) {
|
|
243
|
+
const bn = +entry[1].blockNumber;
|
|
244
|
+
let group = groups.get(bn);
|
|
245
|
+
if (!group) {
|
|
246
|
+
group = [];
|
|
247
|
+
groups.set(bn, group);
|
|
248
|
+
}
|
|
249
|
+
group.push(entry);
|
|
250
|
+
}
|
|
251
|
+
return [...groups.values()];
|
|
252
|
+
}
|
|
253
|
+
|
|
226
254
|
/** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
|
|
227
255
|
private getDeadlineForSlot(slotNumber: SlotNumber): Date {
|
|
228
|
-
|
|
229
|
-
const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
|
|
230
|
-
const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
|
|
231
|
-
return new Date(Number(submissionEndTimestamp) * 1000);
|
|
256
|
+
return getProofDeadlineForSlot(slotNumber, this.constants);
|
|
232
257
|
}
|
|
233
258
|
}
|
|
259
|
+
|
|
260
|
+
/** Computes the proof submission deadline for a given slot. A tx mined in this slot is no longer interesting after this deadline. */
|
|
261
|
+
export function getProofDeadlineForSlot(slotNumber: SlotNumber, constants: L1RollupConstants): Date {
|
|
262
|
+
const epoch = getEpochAtSlot(slotNumber, constants);
|
|
263
|
+
const submissionEndEpoch = EpochNumber(epoch + constants.proofSubmissionEpochs);
|
|
264
|
+
const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, constants)[1];
|
|
265
|
+
return new Date(Number(submissionEndTimestamp) * 1000);
|
|
266
|
+
}
|