@aztec/p2p 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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 +129 -3
- package/dest/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +4 -4
- package/dest/client/factory.d.ts +11 -11
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -20
- package/dest/client/interface.d.ts +68 -35
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +53 -65
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +632 -335
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +315 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +137 -87
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +124 -54
- 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/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 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +113 -76
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +448 -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 +529 -289
- 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 +11 -8
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +17 -13
- package/dest/mem_pools/index.d.ts +3 -3
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/instrumentation.d.ts +9 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +33 -13
- package/dest/mem_pools/interface.d.ts +6 -7
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
- 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 +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +97 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +5 -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 +215 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +10 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +134 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +220 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +108 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +337 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +62 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +167 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +78 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +923 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +8 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +63 -21
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +9 -7
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +24 -15
- package/dest/msg_validators/clock_tolerance.d.ts +32 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +88 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +14 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +20 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +20 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +124 -0
- 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/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -3
- 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 +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +39 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
- package/dest/msg_validators/tx_validator/factory.d.ts +139 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +255 -58
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +24 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +68 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +122 -58
- package/dest/msg_validators/tx_validator/index.d.ts +4 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +3 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +4 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +6 -6
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +24 -3
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +75 -27
- package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +23 -5
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +8 -8
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- 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 -2
- 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 +14 -10
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/dummy_service.d.ts +31 -4
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +54 -1
- package/dest/services/encoding.d.ts +7 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +23 -15
- 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 +184 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +363 -0
- package/dest/services/index.d.ts +2 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +1 -0
- 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 +43 -71
- package/dest/services/libp2p/libp2p_service.d.ts +109 -44
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +1128 -431
- package/dest/services/peer-manager/metrics.d.ts +9 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +39 -21
- package/dest/services/peer-manager/peer_manager.d.ts +7 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +43 -23
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +64 -16
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +51 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +543 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +47 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +35 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +136 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +62 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +176 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/interface.d.ts +25 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +23 -10
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +16 -21
- package/dest/services/reqresp/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
- 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 +27 -9
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +30 -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 +60 -14
- 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/status.d.ts +5 -4
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -3
- package/dest/services/reqresp/protocols/tx.d.ts +8 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +21 -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 +9 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +497 -58
- package/dest/services/service.d.ts +59 -4
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +22 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +56 -2
- package/dest/services/tx_collection/fast_tx_collection.d.ts +10 -9
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +95 -84
- 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 +38 -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 +100 -0
- package/dest/services/tx_collection/index.d.ts +3 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +2 -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 +11 -13
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +9 -4
- 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 +31 -20
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +79 -7
- 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 +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +26 -7
- package/dest/services/tx_file_store/config.d.ts +16 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +22 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +48 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +152 -0
- package/dest/services/tx_provider.d.ts +7 -5
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +20 -10
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +14 -14
- package/dest/test-helpers/index.d.ts +3 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +2 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +40 -6
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +139 -13
- package/dest/test-helpers/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +5 -5
- package/dest/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +163 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +386 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +281 -134
- package/dest/testbench/worker_client_manager.d.ts +60 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +280 -41
- package/dest/util.d.ts +3 -3
- package/dest/util.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +116 -45
- package/src/client/interface.ts +81 -36
- package/src/client/p2p_client.ts +299 -396
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +355 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +196 -64
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +515 -78
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +614 -322
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +22 -15
- package/src/mem_pools/index.ts +2 -2
- package/src/mem_pools/instrumentation.ts +43 -14
- package/src/mem_pools/interface.ts +5 -7
- package/src/mem_pools/tx_pool_v2/README.md +283 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +122 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +125 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +27 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
- package/src/mem_pools/tx_pool_v2/index.ts +12 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +247 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +343 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +430 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +238 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1105 -0
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +51 -24
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +25 -19
- package/src/msg_validators/clock_tolerance.ts +120 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +23 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +29 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +122 -0
- package/src/msg_validators/tx_validator/README.md +119 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +2 -2
- package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +60 -7
- package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
- package/src/msg_validators/tx_validator/factory.ts +416 -58
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +44 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +162 -61
- package/src/msg_validators/tx_validator/index.ts +3 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +31 -12
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +87 -30
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +30 -19
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
- package/src/services/data_store.ts +14 -19
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +71 -2
- package/src/services/encoding.ts +22 -13
- 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 +519 -0
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/instrumentation.ts +48 -75
- package/src/services/libp2p/libp2p_service.ts +827 -461
- package/src/services/peer-manager/metrics.ts +46 -21
- package/src/services/peer-manager/peer_manager.ts +50 -15
- package/src/services/peer-manager/peer_scoring.ts +55 -9
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +344 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +673 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +54 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +168 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +249 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/config.ts +2 -2
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +48 -10
- package/src/services/reqresp/metrics.ts +35 -27
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +35 -12
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +75 -10
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/status.ts +16 -12
- package/src/services/reqresp/protocols/tx.ts +24 -5
- 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 +116 -32
- package/src/services/service.ts +78 -5
- package/src/services/tx_collection/config.ts +84 -2
- package/src/services/tx_collection/fast_tx_collection.ts +114 -93
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +6 -0
- package/src/services/tx_collection/instrumentation.ts +11 -13
- package/src/services/tx_collection/proposal_tx_collector.ts +108 -0
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +69 -36
- package/src/services/tx_collection/tx_collection.ts +123 -27
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +28 -8
- package/src/services/tx_file_store/config.ts +37 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +175 -0
- package/src/services/tx_provider.ts +29 -12
- package/src/services/tx_provider_instrumentation.ts +24 -14
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/make-test-p2p-clients.ts +4 -6
- package/src/test-helpers/mock-pubsub.ts +178 -15
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +8 -10
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +457 -0
- package/src/testbench/p2p_client_testbench_worker.ts +410 -131
- package/src/testbench/worker_client_manager.ts +367 -43
- package/src/util.ts +8 -2
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -37
- 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 -213
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -30
- 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 -219
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -115
- 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 -617
- package/dest/mem_pools/tx_pool/index.d.ts +0 -4
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -3
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -8
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -10
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -122
- 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 -394
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- 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 -31
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -298
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -287
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -750
- package/src/mem_pools/tx_pool/index.ts +0 -3
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
- package/src/mem_pools/tx_pool/priority.ts +0 -13
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -135
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -313
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
- package/src/services/reqresp/protocols/block.ts +0 -36
|
@@ -1,750 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
5
|
-
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
6
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
7
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
8
|
-
import type { MerkleTreeReadOperations, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
|
-
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
10
|
-
import type { TxAddedToPoolStats } from '@aztec/stdlib/stats';
|
|
11
|
-
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
12
|
-
import { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
13
|
-
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
|
-
|
|
15
|
-
import assert from 'assert';
|
|
16
|
-
import EventEmitter from 'node:events';
|
|
17
|
-
|
|
18
|
-
import { ArchiveCache } from '../../msg_validators/tx_validator/archive_cache.js';
|
|
19
|
-
import { GasTxValidator } from '../../msg_validators/tx_validator/gas_validator.js';
|
|
20
|
-
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
21
|
-
import { getPendingTxPriority } from './priority.js';
|
|
22
|
-
import type { TxPool, TxPoolEvents, TxPoolOptions } from './tx_pool.js';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* KV implementation of the Transaction Pool.
|
|
26
|
-
*/
|
|
27
|
-
export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<TxPoolEvents>) implements TxPool {
|
|
28
|
-
#store: AztecAsyncKVStore;
|
|
29
|
-
|
|
30
|
-
/** Our tx pool, stored as a Map, with K: tx hash and V: the transaction. */
|
|
31
|
-
#txs: AztecAsyncMap<string, Buffer>;
|
|
32
|
-
|
|
33
|
-
/** The maximum cumulative tx size that the pending txs in the pool take up. */
|
|
34
|
-
#maxTxPoolSize: number = 0;
|
|
35
|
-
|
|
36
|
-
/** The tx evicion logic will kick after pool size is greater than maxTxPoolSize * txPoolOverflowFactor */
|
|
37
|
-
txPoolOverflowFactor: number = 1;
|
|
38
|
-
|
|
39
|
-
/** Index from tx hash to the block number in which they were mined, filtered by mined txs. */
|
|
40
|
-
#minedTxHashToBlock: AztecAsyncMap<string, number>;
|
|
41
|
-
|
|
42
|
-
/** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */
|
|
43
|
-
#pendingTxPriorityToHash: AztecAsyncMultiMap<string, string>;
|
|
44
|
-
|
|
45
|
-
/** Index from tx hash to its tx size (in bytes), filtered by pending txs. */
|
|
46
|
-
#pendingTxHashToSize: AztecAsyncMap<string, number>;
|
|
47
|
-
|
|
48
|
-
/** Index from tx hash to its header hash, filtered by pending txs. */
|
|
49
|
-
#pendingTxHashToHeaderHash: AztecAsyncMap<string, string>;
|
|
50
|
-
|
|
51
|
-
/** Map from tx hash to the block number it was originally mined in (for soft-deleted txs). */
|
|
52
|
-
#deletedMinedTxHashes: AztecAsyncMap<string, number>;
|
|
53
|
-
|
|
54
|
-
/** MultiMap from block number to deleted mined tx hashes for efficient cleanup. */
|
|
55
|
-
#blockToDeletedMinedTxHash: AztecAsyncMultiMap<number, string>;
|
|
56
|
-
|
|
57
|
-
/** The cumulative tx size in bytes that the pending txs in the pool take up. */
|
|
58
|
-
#pendingTxSize: AztecAsyncSingleton<number>;
|
|
59
|
-
|
|
60
|
-
/** In-memory mapping of pending tx hashes to the hydrated pending tx in the pool. */
|
|
61
|
-
#pendingTxs: Map<string, Tx>;
|
|
62
|
-
|
|
63
|
-
/** In-memory set of txs that should not be evicted from the pool. */
|
|
64
|
-
#nonEvictableTxs: Set<string>;
|
|
65
|
-
|
|
66
|
-
/** KV store for archived txs. */
|
|
67
|
-
#archive: AztecAsyncKVStore;
|
|
68
|
-
|
|
69
|
-
/** Archived txs map for future lookup. */
|
|
70
|
-
#archivedTxs: AztecAsyncMap<string, Buffer>;
|
|
71
|
-
|
|
72
|
-
/** Indexes of the archived txs by insertion order. */
|
|
73
|
-
#archivedTxIndices: AztecAsyncMap<number, string>;
|
|
74
|
-
|
|
75
|
-
/** Number of txs to archive. */
|
|
76
|
-
#archivedTxLimit: number = 0;
|
|
77
|
-
|
|
78
|
-
/** The world state synchronizer used in the node. */
|
|
79
|
-
#worldStateSynchronizer: WorldStateSynchronizer;
|
|
80
|
-
|
|
81
|
-
#log: Logger;
|
|
82
|
-
|
|
83
|
-
#metrics: PoolInstrumentation<Tx>;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Class constructor for KV TxPool. Initiates our transaction pool as an AztecMap.
|
|
87
|
-
* @param store - A KV store for live txs in the pool.
|
|
88
|
-
* @param archive - A KV store for archived txs.
|
|
89
|
-
* @param telemetry - A telemetry client.
|
|
90
|
-
* @param archivedTxLimit - The number of txs to archive.
|
|
91
|
-
* @param log - A logger.
|
|
92
|
-
*/
|
|
93
|
-
constructor(
|
|
94
|
-
store: AztecAsyncKVStore,
|
|
95
|
-
archive: AztecAsyncKVStore,
|
|
96
|
-
worldStateSynchronizer: WorldStateSynchronizer,
|
|
97
|
-
telemetry: TelemetryClient = getTelemetryClient(),
|
|
98
|
-
config: TxPoolOptions = {},
|
|
99
|
-
log = createLogger('p2p:tx_pool'),
|
|
100
|
-
) {
|
|
101
|
-
super();
|
|
102
|
-
|
|
103
|
-
this.#log = log;
|
|
104
|
-
this.updateConfig(config);
|
|
105
|
-
|
|
106
|
-
this.#txs = store.openMap('txs');
|
|
107
|
-
this.#minedTxHashToBlock = store.openMap('txHashToBlockMined');
|
|
108
|
-
this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash');
|
|
109
|
-
this.#pendingTxHashToSize = store.openMap('pendingTxHashToSize');
|
|
110
|
-
this.#pendingTxHashToHeaderHash = store.openMap('pendingTxHashToHeaderHash');
|
|
111
|
-
this.#pendingTxSize = store.openSingleton('pendingTxSize');
|
|
112
|
-
this.#deletedMinedTxHashes = store.openMap('deletedMinedTxHashes');
|
|
113
|
-
this.#blockToDeletedMinedTxHash = store.openMultiMap('blockToDeletedMinedTxHash');
|
|
114
|
-
|
|
115
|
-
this.#pendingTxs = new Map<string, Tx>();
|
|
116
|
-
this.#nonEvictableTxs = new Set<string>();
|
|
117
|
-
|
|
118
|
-
this.#archivedTxs = archive.openMap('archivedTxs');
|
|
119
|
-
this.#archivedTxIndices = archive.openMap('archivedTxIndices');
|
|
120
|
-
|
|
121
|
-
this.#store = store;
|
|
122
|
-
this.#archive = archive;
|
|
123
|
-
this.#worldStateSynchronizer = worldStateSynchronizer;
|
|
124
|
-
this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, this.countTxs, () => store.estimateSize());
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private countTxs: PoolStatsCallback = async () => {
|
|
128
|
-
const [pending = 0, mined = 0] = await Promise.all([this.getPendingTxCount(), this.getMinedTxCount()]);
|
|
129
|
-
|
|
130
|
-
return Promise.resolve({
|
|
131
|
-
itemCount: {
|
|
132
|
-
pending,
|
|
133
|
-
mined,
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
public async isEmpty(): Promise<boolean> {
|
|
139
|
-
for await (const _ of this.#txs.entriesAsync()) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Marks transactions as mined in a block and updates the pool state accordingly.
|
|
146
|
-
* Removes the transactions from the pending set and adds them to the mined set.
|
|
147
|
-
* Also evicts any transactions that become invalid after the block is mined.
|
|
148
|
-
* @param txHashes - Array of transaction hashes that were mined
|
|
149
|
-
* @param blockHeader - The header of the block the transactions were mined in
|
|
150
|
-
*/
|
|
151
|
-
public async markAsMined(txHashes: TxHash[], blockHeader: BlockHeader): Promise<void> {
|
|
152
|
-
if (txHashes.length === 0) {
|
|
153
|
-
return Promise.resolve();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const minedNullifiers = new Set<string>();
|
|
157
|
-
const minedFeePayers = new Set<string>();
|
|
158
|
-
|
|
159
|
-
await this.#store.transactionAsync(async () => {
|
|
160
|
-
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
161
|
-
for (const hash of txHashes) {
|
|
162
|
-
const key = hash.toString();
|
|
163
|
-
|
|
164
|
-
// If this tx was previously soft-deleted, remove it from the deleted sets
|
|
165
|
-
if (await this.#deletedMinedTxHashes.hasAsync(key)) {
|
|
166
|
-
const originalBlock = await this.#deletedMinedTxHashes.getAsync(key);
|
|
167
|
-
await this.#deletedMinedTxHashes.delete(key);
|
|
168
|
-
// Remove from block-to-hash mapping
|
|
169
|
-
if (originalBlock !== undefined) {
|
|
170
|
-
await this.#blockToDeletedMinedTxHash.deleteValue(originalBlock, key);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
await this.#minedTxHashToBlock.set(key, blockHeader.globalVariables.blockNumber);
|
|
175
|
-
|
|
176
|
-
const tx = await this.getPendingTxByHash(hash);
|
|
177
|
-
if (tx) {
|
|
178
|
-
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
179
|
-
nullifiers.forEach(nullifier => minedNullifiers.add(nullifier.toString()));
|
|
180
|
-
minedFeePayers.add(tx.data.feePayer.toString());
|
|
181
|
-
pendingTxSize -= tx.getSize();
|
|
182
|
-
await this.removePendingTxIndices(tx, key);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
await this.#pendingTxSize.set(pendingTxSize);
|
|
186
|
-
|
|
187
|
-
await this.evictInvalidTxsAfterMining(txHashes, blockHeader, minedNullifiers, minedFeePayers);
|
|
188
|
-
});
|
|
189
|
-
// We update this after the transaction above. This ensures that the non-evictable transactions are not evicted
|
|
190
|
-
// until any that have been mined are marked as such.
|
|
191
|
-
// The non-evictable set is not considered when evicting transactions that are invalid after a block is mined.
|
|
192
|
-
this.#nonEvictableTxs.clear();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
public async markMinedAsPending(txHashes: TxHash[]): Promise<void> {
|
|
196
|
-
if (txHashes.length === 0) {
|
|
197
|
-
return Promise.resolve();
|
|
198
|
-
}
|
|
199
|
-
await this.#store.transactionAsync(async () => {
|
|
200
|
-
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
201
|
-
for (const hash of txHashes) {
|
|
202
|
-
const key = hash.toString();
|
|
203
|
-
await this.#minedTxHashToBlock.delete(key);
|
|
204
|
-
|
|
205
|
-
// Rehydrate the tx in the in-memory pending txs mapping
|
|
206
|
-
const tx = await this.getPendingTxByHash(hash);
|
|
207
|
-
if (tx) {
|
|
208
|
-
await this.addPendingTxIndices(tx, key);
|
|
209
|
-
pendingTxSize += tx.getSize();
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
await this.#pendingTxSize.set(pendingTxSize);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
await this.evictInvalidTxsAfterReorg(txHashes);
|
|
217
|
-
await this.evictLowPriorityTxs(txHashes);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
public async getPendingTxHashes(): Promise<TxHash[]> {
|
|
221
|
-
const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync({ reverse: true }));
|
|
222
|
-
return vals.map(TxHash.fromString);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
public async getMinedTxHashes(): Promise<[TxHash, number][]> {
|
|
226
|
-
const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
|
|
227
|
-
return vals.map(([txHash, blockNumber]) => [TxHash.fromString(txHash), blockNumber]);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
public async getPendingTxCount(): Promise<number> {
|
|
231
|
-
return (await this.#pendingTxHashToHeaderHash.sizeAsync()) ?? 0;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public async getMinedTxCount(): Promise<number> {
|
|
235
|
-
return (await this.#minedTxHashToBlock.sizeAsync()) ?? 0;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
public async getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined> {
|
|
239
|
-
const key = txHash.toString();
|
|
240
|
-
const [isMined, isKnown, isDeleted] = await Promise.all([
|
|
241
|
-
this.#minedTxHashToBlock.hasAsync(key),
|
|
242
|
-
this.#txs.hasAsync(key),
|
|
243
|
-
this.#deletedMinedTxHashes.hasAsync(key),
|
|
244
|
-
]);
|
|
245
|
-
|
|
246
|
-
if (isDeleted) {
|
|
247
|
-
return 'deleted';
|
|
248
|
-
} else if (isMined) {
|
|
249
|
-
return 'mined';
|
|
250
|
-
} else if (isKnown) {
|
|
251
|
-
return 'pending';
|
|
252
|
-
} else {
|
|
253
|
-
return undefined;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Checks if a transaction exists in the pool and returns it.
|
|
259
|
-
* @param txHash - The generated tx hash.
|
|
260
|
-
* @returns The transaction, if found, 'undefined' otherwise.
|
|
261
|
-
*/
|
|
262
|
-
public async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
263
|
-
const buffer = await this.#txs.getAsync(txHash.toString());
|
|
264
|
-
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
async getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
268
|
-
const txs = await Promise.all(txHashes.map(txHash => this.#txs.getAsync(txHash.toString())));
|
|
269
|
-
return txs.map(buffer => (buffer ? Tx.fromBuffer(buffer) : undefined));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
async hasTxs(txHashes: TxHash[]): Promise<boolean[]> {
|
|
273
|
-
return await Promise.all(txHashes.map(txHash => this.#txs.hasAsync(txHash.toString())));
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
async hasTx(txHash: TxHash): Promise<boolean> {
|
|
277
|
-
const result = await this.hasTxs([txHash]);
|
|
278
|
-
return result[0];
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Checks if an archived tx exists and returns it.
|
|
283
|
-
* @param txHash - The tx hash.
|
|
284
|
-
* @returns The transaction metadata, if found, 'undefined' otherwise.
|
|
285
|
-
*/
|
|
286
|
-
public async getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
287
|
-
const buffer = await this.#archivedTxs.getAsync(txHash.toString());
|
|
288
|
-
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
293
|
-
* @param txs - An array of txs to be added to the pool.
|
|
294
|
-
* @returns Empty promise.
|
|
295
|
-
*/
|
|
296
|
-
public async addTxs(txs: Tx[], opts: { source?: string } = {}): Promise<number> {
|
|
297
|
-
const addedTxs: Tx[] = [];
|
|
298
|
-
const hashesAndStats = txs.map(tx => ({ txHash: tx.getTxHash(), txStats: tx.getStats() }));
|
|
299
|
-
await this.#store.transactionAsync(async () => {
|
|
300
|
-
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
301
|
-
await Promise.all(
|
|
302
|
-
txs.map(async (tx, i) => {
|
|
303
|
-
const { txHash, txStats } = hashesAndStats[i];
|
|
304
|
-
const key = txHash.toString();
|
|
305
|
-
if (await this.#txs.hasAsync(key)) {
|
|
306
|
-
this.#log.debug(`Tx ${txHash.toString()} already exists in the pool`);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
this.#log.verbose(`Adding tx ${txHash.toString()} to pool`, {
|
|
311
|
-
eventName: 'tx-added-to-pool',
|
|
312
|
-
...txStats,
|
|
313
|
-
} satisfies TxAddedToPoolStats);
|
|
314
|
-
|
|
315
|
-
await this.#txs.set(key, tx.toBuffer());
|
|
316
|
-
addedTxs.push(tx as Tx);
|
|
317
|
-
|
|
318
|
-
if (!(await this.#minedTxHashToBlock.hasAsync(key))) {
|
|
319
|
-
pendingTxSize += tx.getSize();
|
|
320
|
-
await this.addPendingTxIndices(tx, key);
|
|
321
|
-
this.#metrics.recordSize(tx);
|
|
322
|
-
}
|
|
323
|
-
}),
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
await this.#pendingTxSize.set(pendingTxSize);
|
|
327
|
-
await this.evictLowPriorityTxs(hashesAndStats.map(({ txHash }) => txHash));
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
if (addedTxs.length > 0) {
|
|
331
|
-
this.emit('txs-added', { ...opts, txs: addedTxs });
|
|
332
|
-
}
|
|
333
|
-
return addedTxs.length;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
338
|
-
* Mined transactions are soft-deleted with a timestamp, pending transactions are permanently deleted.
|
|
339
|
-
* @param txHashes - An array of tx hashes to be deleted from the tx pool.
|
|
340
|
-
* @returns Empty promise.
|
|
341
|
-
*/
|
|
342
|
-
public deleteTxs(txHashes: TxHash[], opts: { eviction?: boolean; permanently?: boolean } = {}): Promise<void> {
|
|
343
|
-
if (txHashes.length === 0) {
|
|
344
|
-
return Promise.resolve();
|
|
345
|
-
}
|
|
346
|
-
const deletedTxs: Tx[] = [];
|
|
347
|
-
const poolDbTx = this.#store.transactionAsync(async () => {
|
|
348
|
-
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
349
|
-
for (const hash of txHashes) {
|
|
350
|
-
const key = hash.toString();
|
|
351
|
-
const tx = await this.getTxByHash(hash);
|
|
352
|
-
|
|
353
|
-
if (tx) {
|
|
354
|
-
const minedBlockNumber = await this.#minedTxHashToBlock.getAsync(key);
|
|
355
|
-
|
|
356
|
-
if (minedBlockNumber !== undefined) {
|
|
357
|
-
await this.#minedTxHashToBlock.delete(key);
|
|
358
|
-
if (opts.permanently) {
|
|
359
|
-
// Permanently delete mined transactions if specified
|
|
360
|
-
this.#log.trace(`Deleting mined tx ${key} from pool`);
|
|
361
|
-
await this.#txs.delete(key);
|
|
362
|
-
} else {
|
|
363
|
-
// Soft-delete mined transactions: remove from mined set but keep in storage
|
|
364
|
-
this.#log.trace(`Soft-deleting mined tx ${key} from pool`);
|
|
365
|
-
await this.#deletedMinedTxHashes.set(key, minedBlockNumber);
|
|
366
|
-
await this.#blockToDeletedMinedTxHash.set(minedBlockNumber, key);
|
|
367
|
-
}
|
|
368
|
-
} else {
|
|
369
|
-
// Permanently delete pending transactions
|
|
370
|
-
this.#log.trace(`Deleting pending tx ${key} from pool`);
|
|
371
|
-
pendingTxSize -= tx.getSize();
|
|
372
|
-
await this.removePendingTxIndices(tx, key);
|
|
373
|
-
await this.#txs.delete(key);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (!opts.eviction && this.#archivedTxLimit) {
|
|
377
|
-
deletedTxs.push(tx);
|
|
378
|
-
}
|
|
379
|
-
} else {
|
|
380
|
-
this.#log.trace(`Skipping deletion of missing tx ${key} from pool`);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
await this.#pendingTxSize.set(pendingTxSize);
|
|
385
|
-
});
|
|
386
|
-
this.#log.debug(`Deleted ${txHashes.length} txs from pool`, { txHashes });
|
|
387
|
-
return this.#archivedTxLimit ? poolDbTx.then(() => this.archiveTxs(deletedTxs)) : poolDbTx;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Gets all the transactions stored in the pool.
|
|
392
|
-
* @returns Array of tx objects in the order they were added to the pool.
|
|
393
|
-
*/
|
|
394
|
-
public async getAllTxs(): Promise<Tx[]> {
|
|
395
|
-
const vals = await toArray(this.#txs.valuesAsync());
|
|
396
|
-
return vals.map(buffer => Tx.fromBuffer(buffer));
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Gets the hashes of all transactions currently in the tx pool.
|
|
401
|
-
* @returns An array of transaction hashes found in the tx pool.
|
|
402
|
-
*/
|
|
403
|
-
public async getAllTxHashes(): Promise<TxHash[]> {
|
|
404
|
-
const vals = await toArray(this.#txs.keysAsync());
|
|
405
|
-
return vals.map(x => TxHash.fromString(x));
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
public updateConfig({ maxTxPoolSize, txPoolOverflowFactor, archivedTxLimit }: TxPoolOptions): void {
|
|
409
|
-
if (typeof maxTxPoolSize === 'number') {
|
|
410
|
-
assert(maxTxPoolSize >= 0, 'maxTxPoolSize must be greater or equal to 0');
|
|
411
|
-
this.#maxTxPoolSize = maxTxPoolSize;
|
|
412
|
-
|
|
413
|
-
if (maxTxPoolSize === 0) {
|
|
414
|
-
this.#log.info(`Disabling maximum tx mempool size. Tx eviction stopped`);
|
|
415
|
-
} else {
|
|
416
|
-
this.#log.info(`Setting maximum tx mempool size`, { maxTxPoolSize });
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (typeof txPoolOverflowFactor === 'number') {
|
|
421
|
-
assert(txPoolOverflowFactor >= 1, 'txPoolOveflowFactor must be greater or equal to 1');
|
|
422
|
-
this.txPoolOverflowFactor = txPoolOverflowFactor;
|
|
423
|
-
this.#log.info(`Allowing tx pool size to grow above limit`, { maxTxPoolSize, txPoolOverflowFactor });
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (typeof archivedTxLimit === 'number') {
|
|
427
|
-
assert(archivedTxLimit >= 0, 'archivedTxLimit must be greater or equal to 0');
|
|
428
|
-
this.#archivedTxLimit = archivedTxLimit;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// deletedMinedCleanupThresholdMs is no longer used in block-based cleanup
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
public markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void> {
|
|
435
|
-
txHashes.forEach(txHash => this.#nonEvictableTxs.add(txHash.toString()));
|
|
436
|
-
return Promise.resolve();
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
|
|
441
|
-
* @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
|
|
442
|
-
* @returns The number of transactions permanently deleted.
|
|
443
|
-
*/
|
|
444
|
-
public async cleanupDeletedMinedTxs(blockNumber: number): Promise<number> {
|
|
445
|
-
let deletedCount = 0;
|
|
446
|
-
const txHashesToDelete: string[] = [];
|
|
447
|
-
const blocksToDelete: number[] = [];
|
|
448
|
-
|
|
449
|
-
await this.#store.transactionAsync(async () => {
|
|
450
|
-
// Iterate through all entries and check block numbers
|
|
451
|
-
for await (const [block, txHash] of this.#blockToDeletedMinedTxHash.entriesAsync()) {
|
|
452
|
-
if (block <= blockNumber) {
|
|
453
|
-
// Permanently delete the transaction
|
|
454
|
-
await this.#txs.delete(txHash);
|
|
455
|
-
await this.#deletedMinedTxHashes.delete(txHash);
|
|
456
|
-
txHashesToDelete.push(txHash);
|
|
457
|
-
if (!blocksToDelete.includes(block)) {
|
|
458
|
-
blocksToDelete.push(block);
|
|
459
|
-
}
|
|
460
|
-
deletedCount++;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// Clean up block-to-hash mapping - delete all values for each block
|
|
465
|
-
for (const block of blocksToDelete) {
|
|
466
|
-
const txHashesForBlock = await toArray(this.#blockToDeletedMinedTxHash.getValuesAsync(block));
|
|
467
|
-
for (const txHash of txHashesForBlock) {
|
|
468
|
-
await this.#blockToDeletedMinedTxHash.deleteValue(block, txHash);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
if (deletedCount > 0) {
|
|
474
|
-
this.#log.debug(`Permanently deleted ${deletedCount} deleted mined txs from blocks up to ${blockNumber}`);
|
|
475
|
-
}
|
|
476
|
-
return deletedCount;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Creates a GasTxValidator instance.
|
|
481
|
-
* @param db - DB for the validator to use
|
|
482
|
-
* @returns A GasTxValidator instance
|
|
483
|
-
*/
|
|
484
|
-
protected createGasTxValidator(db: MerkleTreeReadOperations): GasTxValidator {
|
|
485
|
-
return new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, GasFees.empty());
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Creates an ArchiveCache instance.
|
|
490
|
-
* @param db - DB for the cache to use
|
|
491
|
-
* @returns An ArchiveCache instance
|
|
492
|
-
*/
|
|
493
|
-
protected createArchiveCache(db: MerkleTreeReadOperations): ArchiveCache {
|
|
494
|
-
return new ArchiveCache(db);
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* Checks if a cached transaction exists in the in-memory pending tx pool and returns it.
|
|
499
|
-
* Otherwise, it checks the tx pool, updates the pending tx pool, and returns the tx.
|
|
500
|
-
* @param txHash - The generated tx hash.
|
|
501
|
-
* @returns The transaction, if found, 'undefined' otherwise.
|
|
502
|
-
*/
|
|
503
|
-
private async getPendingTxByHash(txHash: TxHash | string): Promise<Tx | undefined> {
|
|
504
|
-
let key;
|
|
505
|
-
if (typeof txHash === 'string') {
|
|
506
|
-
key = txHash;
|
|
507
|
-
txHash = TxHash.fromString(txHash);
|
|
508
|
-
} else {
|
|
509
|
-
key = txHash.toString();
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (this.#pendingTxs.has(key)) {
|
|
513
|
-
return this.#pendingTxs.get(key);
|
|
514
|
-
}
|
|
515
|
-
const tx = await this.getTxByHash(txHash);
|
|
516
|
-
if (tx) {
|
|
517
|
-
this.#pendingTxs.set(key, tx);
|
|
518
|
-
return tx;
|
|
519
|
-
}
|
|
520
|
-
return undefined;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
|
|
525
|
-
* @param txs - The list of transactions to archive.
|
|
526
|
-
* @returns Empty promise.
|
|
527
|
-
*/
|
|
528
|
-
private async archiveTxs(txs: Tx[]): Promise<void> {
|
|
529
|
-
if (txs.length === 0) {
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
try {
|
|
533
|
-
const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
|
|
534
|
-
await this.#archive.transactionAsync(async () => {
|
|
535
|
-
// calculate the head and tail indices of the archived txs by insertion order.
|
|
536
|
-
let headIdx =
|
|
537
|
-
((await this.#archivedTxIndices.entriesAsync({ limit: 1, reverse: true }).next()).value?.[0] ?? -1) + 1;
|
|
538
|
-
let tailIdx = (await this.#archivedTxIndices.entriesAsync({ limit: 1 }).next()).value?.[0] ?? 0;
|
|
539
|
-
|
|
540
|
-
for (let i = 0; i < txs.length; i++) {
|
|
541
|
-
const tx = txs[i];
|
|
542
|
-
while (headIdx - tailIdx >= this.#archivedTxLimit) {
|
|
543
|
-
const txHash = await this.#archivedTxIndices.getAsync(tailIdx);
|
|
544
|
-
if (txHash) {
|
|
545
|
-
await this.#archivedTxs.delete(txHash);
|
|
546
|
-
await this.#archivedTxIndices.delete(tailIdx);
|
|
547
|
-
}
|
|
548
|
-
tailIdx++;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const archivedTx: Tx = new Tx(
|
|
552
|
-
tx.txHash,
|
|
553
|
-
tx.data,
|
|
554
|
-
ChonkProof.empty(),
|
|
555
|
-
tx.contractClassLogFields,
|
|
556
|
-
tx.publicFunctionCalldata,
|
|
557
|
-
);
|
|
558
|
-
const txHash = txHashes[i].toString();
|
|
559
|
-
await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
|
|
560
|
-
await this.#archivedTxIndices.set(headIdx, txHash);
|
|
561
|
-
headIdx++;
|
|
562
|
-
}
|
|
563
|
-
this.#log.debug(`Archived ${txs.length} txs`, { txHashes });
|
|
564
|
-
this.#log.debug(`Total archived txs: ${headIdx - tailIdx}`);
|
|
565
|
-
});
|
|
566
|
-
} catch (error) {
|
|
567
|
-
this.#log.error(`Error archiving txs`, { error });
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Evicts pending txs with the lowest priority fees from the pool to accomodate the max tx count and cumulative max tx size
|
|
573
|
-
* after new txs are added.
|
|
574
|
-
*
|
|
575
|
-
* @param newTxHashes - The tx hashes of the new txs added to the pool.
|
|
576
|
-
* @returns The total number of txs evicted from the pool and the number of new txs that were evicted.
|
|
577
|
-
*/
|
|
578
|
-
private async evictLowPriorityTxs(
|
|
579
|
-
newTxHashes: TxHash[],
|
|
580
|
-
): Promise<{ numLowPriorityTxsEvicted: number; numNewTxsEvicted: number }> {
|
|
581
|
-
if (this.#maxTxPoolSize === undefined || this.#maxTxPoolSize === 0) {
|
|
582
|
-
return { numLowPriorityTxsEvicted: 0, numNewTxsEvicted: 0 };
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
let numNewTxsEvicted = 0;
|
|
586
|
-
const txsToEvict: TxHash[] = [];
|
|
587
|
-
|
|
588
|
-
let pendingTxsSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
589
|
-
if (pendingTxsSize > this.#maxTxPoolSize * this.txPoolOverflowFactor) {
|
|
590
|
-
for await (const txHash of this.#pendingTxPriorityToHash.valuesAsync()) {
|
|
591
|
-
if (this.#nonEvictableTxs.has(txHash.toString())) {
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
const txSize =
|
|
595
|
-
(await this.#pendingTxHashToSize.getAsync(txHash.toString())) ??
|
|
596
|
-
(await this.getPendingTxByHash(txHash))?.getSize();
|
|
597
|
-
|
|
598
|
-
this.#log.verbose(`Evicting tx ${txHash} from pool due to low priority to satisfy max tx size limit`, {
|
|
599
|
-
txHash,
|
|
600
|
-
txSize,
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
txsToEvict.push(TxHash.fromString(txHash));
|
|
604
|
-
|
|
605
|
-
if (txSize) {
|
|
606
|
-
pendingTxsSize -= txSize;
|
|
607
|
-
if (pendingTxsSize <= this.#maxTxPoolSize) {
|
|
608
|
-
break;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
numNewTxsEvicted += newTxHashes.filter(txHash => txsToEvict.includes(txHash)).length;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
if (txsToEvict.length > 0) {
|
|
616
|
-
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
617
|
-
}
|
|
618
|
-
return {
|
|
619
|
-
numLowPriorityTxsEvicted: txsToEvict.length,
|
|
620
|
-
numNewTxsEvicted,
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Evicts invalid pending txs from the pool after a txs from a block are mined.
|
|
626
|
-
* Eviction criteria includes:
|
|
627
|
-
* - txs with nullifiers that are already included in the mined block
|
|
628
|
-
* - txs with an insufficient fee payer balance
|
|
629
|
-
* - txs with an expiration timestamp lower than that of the mined block
|
|
630
|
-
*
|
|
631
|
-
* @param minedTxHashes - The tx hashes of the txs mined in the block.
|
|
632
|
-
* @param blockHeader - The header of the mined block.
|
|
633
|
-
* @returns The total number of txs evicted from the pool.
|
|
634
|
-
*/
|
|
635
|
-
private async evictInvalidTxsAfterMining(
|
|
636
|
-
minedTxHashes: TxHash[],
|
|
637
|
-
blockHeader: BlockHeader,
|
|
638
|
-
minedNullifiers: Set<string>,
|
|
639
|
-
minedFeePayers: Set<string>,
|
|
640
|
-
): Promise<number> {
|
|
641
|
-
if (minedTxHashes.length === 0) {
|
|
642
|
-
return 0;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
const { blockNumber, timestamp } = blockHeader.globalVariables;
|
|
646
|
-
|
|
647
|
-
// Wait for world state to be synced to at least the mined block number
|
|
648
|
-
await this.#worldStateSynchronizer.syncImmediate(blockNumber);
|
|
649
|
-
|
|
650
|
-
const db = this.#worldStateSynchronizer.getCommitted();
|
|
651
|
-
const gasTxValidator = this.createGasTxValidator(db);
|
|
652
|
-
|
|
653
|
-
const txsToEvict: TxHash[] = [];
|
|
654
|
-
for await (const txHash of this.#pendingTxPriorityToHash.valuesAsync()) {
|
|
655
|
-
const tx = await this.getPendingTxByHash(txHash);
|
|
656
|
-
if (!tx) {
|
|
657
|
-
continue;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// Evict pending txs that share nullifiers with mined txs
|
|
661
|
-
const txNullifiers = tx.data.getNonEmptyNullifiers();
|
|
662
|
-
if (txNullifiers.some(nullifier => minedNullifiers.has(nullifier.toString()))) {
|
|
663
|
-
this.#log.verbose(`Evicting tx ${txHash} from pool due to a duplicate nullifier with a mined tx`);
|
|
664
|
-
txsToEvict.push(TxHash.fromString(txHash));
|
|
665
|
-
continue;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// Evict pending txs with an insufficient fee payer balance
|
|
669
|
-
if (
|
|
670
|
-
minedFeePayers.has(tx.data.feePayer.toString()) &&
|
|
671
|
-
(await gasTxValidator.validateTxFee(tx)).result === 'invalid'
|
|
672
|
-
) {
|
|
673
|
-
this.#log.verbose(`Evicting tx ${txHash} from pool due to an insufficient fee payer balance`);
|
|
674
|
-
txsToEvict.push(TxHash.fromString(txHash));
|
|
675
|
-
continue;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
|
|
679
|
-
const includeByTimestamp = tx.data.includeByTimestamp;
|
|
680
|
-
if (includeByTimestamp <= timestamp) {
|
|
681
|
-
this.#log.verbose(
|
|
682
|
-
`Evicting tx ${txHash} from pool due to the tx being expired (includeByTimestamp: ${includeByTimestamp}, mined block timestamp: ${timestamp})`,
|
|
683
|
-
);
|
|
684
|
-
txsToEvict.push(TxHash.fromString(txHash));
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
if (txsToEvict.length > 0) {
|
|
690
|
-
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
691
|
-
}
|
|
692
|
-
return txsToEvict.length;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
/**
|
|
696
|
-
* Evicts pending txs that no longer have valid archive roots or fee payer balances from the pool after a reorg.
|
|
697
|
-
*
|
|
698
|
-
* @param txHashes - The tx hashes of the txs that were moved from mined to pending.
|
|
699
|
-
* @returns The total number of txs evicted from the pool.
|
|
700
|
-
*/
|
|
701
|
-
private async evictInvalidTxsAfterReorg(txHashes: TxHash[]): Promise<number> {
|
|
702
|
-
if (txHashes.length === 0) {
|
|
703
|
-
return 0;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
await this.#worldStateSynchronizer.syncImmediate();
|
|
707
|
-
const db = this.#worldStateSynchronizer.getCommitted();
|
|
708
|
-
const archiveCache = this.createArchiveCache(db);
|
|
709
|
-
const gasTxValidator = this.createGasTxValidator(db);
|
|
710
|
-
|
|
711
|
-
const txsToEvict: TxHash[] = [];
|
|
712
|
-
|
|
713
|
-
for await (const [txHash, headerHash] of this.#pendingTxHashToHeaderHash.entriesAsync()) {
|
|
714
|
-
const tx = await this.getPendingTxByHash(txHash);
|
|
715
|
-
if (!tx) {
|
|
716
|
-
continue;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
const [index] = await archiveCache.getArchiveIndices([Fr.fromString(headerHash)]);
|
|
720
|
-
if (index === undefined) {
|
|
721
|
-
this.#log.verbose(`Evicting tx ${txHash} from pool due to an invalid archive root`);
|
|
722
|
-
txsToEvict.push(TxHash.fromString(txHash));
|
|
723
|
-
continue;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
if ((await gasTxValidator.validateTxFee(tx)).result === 'invalid') {
|
|
727
|
-
this.#log.verbose(`Evicting tx ${txHash} from pool due to an insufficient fee payer balance`);
|
|
728
|
-
txsToEvict.push(TxHash.fromString(txHash));
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
if (txsToEvict.length > 0) {
|
|
733
|
-
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
734
|
-
}
|
|
735
|
-
return txsToEvict.length;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
private async addPendingTxIndices(tx: Tx, txHash: string): Promise<void> {
|
|
739
|
-
await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), txHash);
|
|
740
|
-
await this.#pendingTxHashToSize.set(txHash, tx.getSize());
|
|
741
|
-
await this.#pendingTxHashToHeaderHash.set(txHash, (await tx.data.constants.anchorBlockHeader.hash()).toString());
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
private async removePendingTxIndices(tx: Tx, txHash: string): Promise<void> {
|
|
745
|
-
await this.#pendingTxPriorityToHash.deleteValue(getPendingTxPriority(tx), txHash);
|
|
746
|
-
await this.#pendingTxHashToSize.delete(txHash);
|
|
747
|
-
await this.#pendingTxHashToHeaderHash.delete(txHash);
|
|
748
|
-
this.#pendingTxs.delete(txHash);
|
|
749
|
-
}
|
|
750
|
-
}
|