@aztec/p2p 0.0.0-test.0 → 0.0.1-commit.023c3e5
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/bootstrap/bootstrap.d.ts +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +26 -13
- package/dest/client/factory.d.ts +15 -5
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +61 -25
- package/dest/client/index.d.ts +2 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +170 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +75 -193
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +765 -229
- 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 +305 -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 +154 -125
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +182 -34
- package/dest/enr/generate-enr.d.ts +11 -3
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +4 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -25
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +299 -174
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +29 -11
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +168 -62
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +24 -10
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +133 -82
- package/dest/mem_pools/attestation_pool/mocks.d.ts +234 -11
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +19 -21
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +16 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +56 -41
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +75 -16
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +493 -142
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +7 -2
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +72 -11
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +276 -45
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +7 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +79 -10
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +76 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -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/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -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 +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -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 +6 -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 +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +5 -4
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +7 -6
- 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 +60 -87
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -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 +24 -29
- package/dest/msg_validators/tx_validator/factory.d.ts +21 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +84 -0
- 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 +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +12 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +110 -0
- package/dest/msg_validators/tx_validator/index.d.ts +9 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +8 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +10 -5
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +40 -21
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
- 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 +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +14 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +24 -0
- 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 +8 -7
- 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 +10 -6
- package/dest/services/discv5/discV5_service.d.ts +10 -9
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +64 -37
- package/dest/services/dummy_service.d.ts +66 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +130 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +75 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +5 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +20 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +122 -0
- package/dest/services/libp2p/libp2p_service.d.ts +107 -95
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +1328 -313
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +12 -3
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +44 -12
- package/dest/services/peer-manager/peer_manager.d.ts +103 -23
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +551 -82
- 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 +43 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -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 +566 -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 +50 -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 +37 -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 +151 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -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 +139 -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 +11 -9
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +23 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +73 -10
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +32 -17
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +154 -84
- 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/index.d.ts +3 -2
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +75 -24
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +46 -27
- 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 +17 -21
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +6 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +30 -6
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +34 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +87 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +52 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +59 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +105 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +3 -1
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +1 -3
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +40 -7
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +76 -5
- package/dest/services/reqresp/protocols/tx.d.ts +14 -4
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- 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 +21 -1
- package/dest/services/reqresp/reqresp.d.ts +29 -66
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +753 -248
- package/dest/services/reqresp/status.d.ts +10 -4
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +40 -20
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +28 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +66 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +311 -0
- package/dest/services/tx_collection/index.d.ts +4 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +3 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +31 -0
- 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/slow_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +177 -0
- package/dest/services/tx_collection/tx_collection.d.ts +110 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +128 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +111 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +51 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +219 -0
- package/dest/services/tx_provider_instrumentation.d.ts +16 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +4 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +3 -0
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -16
- package/dest/test-helpers/mock-pubsub.d.ts +59 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +130 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +62 -28
- 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 +158 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +297 -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 +259 -90
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +51 -11
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +232 -53
- package/dest/types/index.d.ts +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +24 -16
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +75 -69
- package/dest/versioning.d.ts +4 -4
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +32 -27
- package/src/bootstrap/bootstrap.ts +34 -15
- package/src/client/factory.ts +135 -53
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +213 -0
- package/src/client/p2p_client.ts +476 -383
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +304 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +119 -24
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +352 -201
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +233 -72
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +199 -96
- package/src/mem_pools/attestation_pool/mocks.ts +24 -17
- package/src/mem_pools/instrumentation.ts +72 -48
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +580 -143
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +9 -2
- package/src/mem_pools/tx_pool/tx_pool.ts +75 -10
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +225 -36
- package/src/msg_validators/attestation_validator/attestation_validator.ts +72 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +94 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +10 -9
- package/src/msg_validators/tx_validator/data_validator.ts +95 -71
- package/src/msg_validators/tx_validator/double_spend_validator.ts +23 -20
- package/src/msg_validators/tx_validator/factory.ts +151 -0
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -0
- package/src/msg_validators/tx_validator/index.ts +8 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +72 -24
- package/src/msg_validators/tx_validator/phases_validator.ts +118 -0
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +52 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +22 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +14 -8
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +85 -39
- package/src/services/dummy_service.ts +198 -9
- package/src/services/encoding.ts +82 -6
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +126 -0
- package/src/services/libp2p/libp2p_service.ts +1170 -353
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +55 -12
- package/src/services/peer-manager/peer_manager.ts +657 -80
- package/src/services/peer-manager/peer_scoring.ts +45 -3
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +77 -10
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +166 -95
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +95 -37
- package/src/services/reqresp/metrics.ts +40 -28
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +26 -4
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +106 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +67 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +121 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +9 -7
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +121 -5
- package/src/services/reqresp/protocols/tx.ts +36 -8
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +449 -271
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +65 -22
- package/src/services/tx_collection/config.ts +98 -0
- package/src/services/tx_collection/fast_tx_collection.ts +364 -0
- package/src/services/tx_collection/index.ts +7 -0
- package/src/services/tx_collection/instrumentation.ts +35 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
- package/src/services/tx_collection/slow_tx_collection.ts +233 -0
- package/src/services/tx_collection/tx_collection.ts +216 -0
- package/src/services/tx_collection/tx_collection_sink.ts +129 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +232 -0
- package/src/services/tx_provider_instrumentation.ts +54 -0
- package/src/test-helpers/index.ts +3 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +111 -21
- package/src/test-helpers/mock-pubsub.ts +188 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +87 -36
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +374 -0
- package/src/testbench/p2p_client_testbench_worker.ts +434 -89
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +315 -59
- package/src/types/index.ts +2 -0
- package/src/util.ts +105 -91
- package/src/versioning.ts +11 -4
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -56
- 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 -141
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -8
- 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 -21
- 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/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -174
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -29
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
import type { TxPoolOptions } from '../tx_pool.js';
|
|
5
|
+
import {
|
|
6
|
+
type EvictionContext,
|
|
7
|
+
EvictionEvent,
|
|
8
|
+
type EvictionResult,
|
|
9
|
+
type EvictionRule,
|
|
10
|
+
type TxPoolOperations,
|
|
11
|
+
} from './eviction_strategy.js';
|
|
12
|
+
|
|
13
|
+
export interface LowPriorityEvictionConfig {
|
|
14
|
+
/** Maximum number of pending transactions before eviction kicks in */
|
|
15
|
+
maxPoolSize: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Eviction rule that removes low-priority transactions when the number of pending transactions exceeds configured limits.
|
|
20
|
+
* Only triggers on TXS_ADDED events and respects non-evictable transactions.
|
|
21
|
+
*/
|
|
22
|
+
export class LowPriorityEvictionRule implements EvictionRule {
|
|
23
|
+
public readonly name = 'LowPriorityEviction';
|
|
24
|
+
|
|
25
|
+
private log = createLogger('p2p:mempool:tx_pool:low_priority_eviction_rule');
|
|
26
|
+
|
|
27
|
+
constructor(private config: LowPriorityEvictionConfig) {}
|
|
28
|
+
|
|
29
|
+
public async evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult> {
|
|
30
|
+
if (context.event !== EvictionEvent.TXS_ADDED) {
|
|
31
|
+
return {
|
|
32
|
+
reason: 'low_priority',
|
|
33
|
+
success: true,
|
|
34
|
+
txsEvicted: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (this.config.maxPoolSize === 0) {
|
|
39
|
+
return {
|
|
40
|
+
reason: 'low_priority',
|
|
41
|
+
success: true,
|
|
42
|
+
txsEvicted: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const currentTxCount = await txPool.getPendingTxCount();
|
|
48
|
+
const maxCount = this.config.maxPoolSize;
|
|
49
|
+
|
|
50
|
+
if (currentTxCount <= maxCount) {
|
|
51
|
+
this.log.trace(`Not evicting low priority txs. Pending tx count below limit ${currentTxCount} <= ${maxCount}`);
|
|
52
|
+
return {
|
|
53
|
+
reason: 'low_priority',
|
|
54
|
+
success: true,
|
|
55
|
+
txsEvicted: [],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.log.verbose(`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${maxCount}`);
|
|
60
|
+
const numberToEvict = currentTxCount - maxCount;
|
|
61
|
+
const txsToEvict: TxHash[] = await txPool.getLowestPriorityEvictable(numberToEvict);
|
|
62
|
+
|
|
63
|
+
if (txsToEvict.length > 0) {
|
|
64
|
+
await txPool.deleteTxs(txsToEvict);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const numNewTxsEvicted = context.newTxs.filter(newTxHash =>
|
|
68
|
+
txsToEvict.some(evictedTx => evictedTx.equals(newTxHash)),
|
|
69
|
+
).length;
|
|
70
|
+
|
|
71
|
+
this.log.verbose(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`, {
|
|
72
|
+
txsEvicted: txsToEvict,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
reason: 'low_priority',
|
|
77
|
+
success: true,
|
|
78
|
+
txsEvicted: txsToEvict,
|
|
79
|
+
};
|
|
80
|
+
} catch (err) {
|
|
81
|
+
this.log.error('Failed to evict low priority transactions', { err });
|
|
82
|
+
return {
|
|
83
|
+
reason: 'low_priority',
|
|
84
|
+
success: false,
|
|
85
|
+
txsEvicted: [],
|
|
86
|
+
error: new Error('Failed to evict low priority txs', { cause: err }),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Updates the configuration for this eviction rule
|
|
93
|
+
*/
|
|
94
|
+
updateConfig(config: TxPoolOptions): void {
|
|
95
|
+
if (config.maxPendingTxCount !== undefined) {
|
|
96
|
+
this.config.maxPoolSize = config.maxPendingTxCount;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Gets the current configuration
|
|
102
|
+
*/
|
|
103
|
+
getConfig(): LowPriorityEvictionConfig {
|
|
104
|
+
return { ...this.config };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { findIndexInSortedArray, insertIntoSortedArray } from '@aztec/foundation/array';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
import type { PreAddEvictionResult, PreAddEvictionRule, PreAddPoolAccess } from './eviction_strategy.js';
|
|
7
|
+
|
|
8
|
+
const cmpTxHash = (a: TxHash, b: TxHash) => Fr.cmp(a.hash, b.hash);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Pre-add eviction rule that checks for nullifier conflicts between incoming and existing transactions.
|
|
12
|
+
*
|
|
13
|
+
* When an incoming tx shares nullifiers with existing pending txs:
|
|
14
|
+
* - If the incoming tx has strictly higher priority fee, evict all conflicting txs
|
|
15
|
+
* - If any conflicting tx has equal or higher priority fee, reject the incoming tx
|
|
16
|
+
*
|
|
17
|
+
* This prevents nullifier spam attacks where an attacker floods the mempool with
|
|
18
|
+
* transactions spending the same nullifiers.
|
|
19
|
+
*/
|
|
20
|
+
export class NullifierConflictPreAddRule implements PreAddEvictionRule {
|
|
21
|
+
public readonly name = 'NullifierConflictPreAdd';
|
|
22
|
+
|
|
23
|
+
private log = createLogger('p2p:mempool:tx_pool:nullifier_conflict_pre_add_rule');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Check if the incoming transaction conflicts with existing transactions via nullifiers.
|
|
27
|
+
*
|
|
28
|
+
* @param tx - The incoming transaction
|
|
29
|
+
* @param poolAccess - Read-only access to pool state
|
|
30
|
+
* @returns Result with rejection status and txs to evict
|
|
31
|
+
*/
|
|
32
|
+
async check(tx: Tx, poolAccess: PreAddPoolAccess): Promise<PreAddEvictionResult> {
|
|
33
|
+
const txHash = tx.getTxHash();
|
|
34
|
+
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
35
|
+
const txHashesToEvict: TxHash[] = [];
|
|
36
|
+
const incomingPriority = poolAccess.getTxPriority(tx);
|
|
37
|
+
|
|
38
|
+
for (const nullifier of nullifiers) {
|
|
39
|
+
const conflictingHash = await poolAccess.getTxHashByNullifier(nullifier);
|
|
40
|
+
|
|
41
|
+
if (
|
|
42
|
+
!conflictingHash ||
|
|
43
|
+
conflictingHash.equals(txHash) ||
|
|
44
|
+
findIndexInSortedArray(txHashesToEvict, conflictingHash, cmpTxHash) !== -1
|
|
45
|
+
) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Get the conflicting tx's priority
|
|
50
|
+
const conflictingTx = await poolAccess.getPendingTxByHash(conflictingHash);
|
|
51
|
+
if (!conflictingTx) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const conflictingPriority = poolAccess.getTxPriority(conflictingTx);
|
|
56
|
+
|
|
57
|
+
// If incoming tx has strictly higher priority, mark for eviction
|
|
58
|
+
// Otherwise, reject incoming tx (ties go to existing tx)
|
|
59
|
+
if (incomingPriority > conflictingPriority) {
|
|
60
|
+
insertIntoSortedArray(txHashesToEvict, conflictingHash, cmpTxHash);
|
|
61
|
+
} else {
|
|
62
|
+
this.log.debug(
|
|
63
|
+
`Rejecting tx ${txHash.toString()}: nullifier conflict with ${conflictingHash.toString()} which has higher or equal fee`,
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
shouldReject: true,
|
|
67
|
+
txHashesToEvict: [],
|
|
68
|
+
reason: `nullifier conflict with ${conflictingHash.toString()}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { shouldReject: false, txHashesToEvict };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -7,7 +7,14 @@ import type { Tx } from '@aztec/stdlib/tx';
|
|
|
7
7
|
* We currently use the sum of the priority fees for the tx for this value, represented as hex.
|
|
8
8
|
*/
|
|
9
9
|
export function getPendingTxPriority(tx: Tx): string {
|
|
10
|
+
return Buffer32.fromBigInt(getTxPriorityFee(tx)).toString();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the priority of a tx.
|
|
15
|
+
*/
|
|
16
|
+
export function getTxPriorityFee(tx: Tx): bigint {
|
|
10
17
|
const priorityFees = tx.getGasSettings().maxPriorityFeesPerGas;
|
|
11
|
-
const totalFees = priorityFees.feePerDaGas
|
|
12
|
-
return
|
|
18
|
+
const totalFees = priorityFees.feePerDaGas + priorityFees.feePerL2Gas;
|
|
19
|
+
return totalFees;
|
|
13
20
|
}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
3
|
+
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
|
+
|
|
5
|
+
export type TxPoolOptions = {
|
|
6
|
+
maxPendingTxCount?: number;
|
|
7
|
+
archivedTxLimit?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type TxPoolEvents = {
|
|
11
|
+
['txs-added']: (args: { txs: Tx[]; source?: string }) => void | Promise<void>;
|
|
12
|
+
};
|
|
2
13
|
|
|
3
14
|
/**
|
|
4
15
|
* Interface of a transaction pool. The pool includes tx requests and is kept up-to-date by a P2P client.
|
|
5
16
|
*/
|
|
6
|
-
export interface TxPool {
|
|
17
|
+
export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
|
|
7
18
|
/**
|
|
8
19
|
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
9
20
|
* @param txs - An array of txs to be added to the pool.
|
|
21
|
+
* @returns The number of txs added to the pool. Note if the transaction already exists, it will not be added again.
|
|
10
22
|
*/
|
|
11
|
-
addTxs(txs: Tx[]): Promise<
|
|
23
|
+
addTxs(txs: Tx[], opts?: { source?: string }): Promise<number>;
|
|
12
24
|
|
|
13
25
|
/**
|
|
14
26
|
* Checks if a transaction exists in the pool and returns it.
|
|
@@ -17,6 +29,27 @@ export interface TxPool {
|
|
|
17
29
|
*/
|
|
18
30
|
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
19
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Checks if transactions exist in the pool and returns them.
|
|
34
|
+
* @param txHashes - The hashes of the transactions
|
|
35
|
+
* @returns The transactions, if found, 'undefined' otherwise.
|
|
36
|
+
*/
|
|
37
|
+
getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Checks if transactions exist in the pool
|
|
41
|
+
* @param txHashes - The hashes of the transactions to check for
|
|
42
|
+
* @returns True or False for each tx hash
|
|
43
|
+
*/
|
|
44
|
+
hasTxs(txHashes: TxHash[]): Promise<boolean[]>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a transaction exists in the pool
|
|
48
|
+
* @param txHash - The hash of the transaction to check for
|
|
49
|
+
* @returns True if the transaction exists, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
hasTx(txHash: TxHash): Promise<boolean>;
|
|
52
|
+
|
|
20
53
|
/**
|
|
21
54
|
* Checks if an archived transaction exists in the pool and returns it.
|
|
22
55
|
* @param txHash - The hash of the transaction, used as an ID.
|
|
@@ -27,21 +60,23 @@ export interface TxPool {
|
|
|
27
60
|
/**
|
|
28
61
|
* Marks the set of txs as mined, as opposed to pending.
|
|
29
62
|
* @param txHashes - Hashes of the txs to flag as mined.
|
|
63
|
+
* @param blockHeader - The header of the mined block.
|
|
30
64
|
*/
|
|
31
|
-
markAsMined(txHashes: TxHash[],
|
|
65
|
+
markAsMined(txHashes: TxHash[], blockHeader: BlockHeader): Promise<void>;
|
|
32
66
|
|
|
33
67
|
/**
|
|
34
68
|
* Moves mined txs back to the pending set in the case of a reorg.
|
|
35
69
|
* Note: txs not known by this peer will be ignored.
|
|
36
70
|
* @param txHashes - Hashes of the txs to flag as pending.
|
|
71
|
+
* @param latestBlock - The block number the chain was pruned to.
|
|
37
72
|
*/
|
|
38
|
-
markMinedAsPending(txHashes: TxHash[]): Promise<void>;
|
|
73
|
+
markMinedAsPending(txHashes: TxHash[], latestBlock: BlockNumber): Promise<void>;
|
|
39
74
|
|
|
40
75
|
/**
|
|
41
76
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
42
77
|
* @param txHashes - An array of tx hashes to be removed from the tx pool.
|
|
43
78
|
*/
|
|
44
|
-
deleteTxs(txHashes: TxHash[]): Promise<void>;
|
|
79
|
+
deleteTxs(txHashes: TxHash[], opts?: { permanently?: boolean }): Promise<void>;
|
|
45
80
|
|
|
46
81
|
/**
|
|
47
82
|
* Gets all transactions currently in the tx pool.
|
|
@@ -61,16 +96,46 @@ export interface TxPool {
|
|
|
61
96
|
*/
|
|
62
97
|
getPendingTxHashes(): Promise<TxHash[]>;
|
|
63
98
|
|
|
99
|
+
/** Returns the number of pending txs in the pool. */
|
|
100
|
+
getPendingTxCount(): Promise<number>;
|
|
101
|
+
|
|
64
102
|
/**
|
|
65
103
|
* Gets the hashes of mined transactions currently in the tx pool.
|
|
66
104
|
* @returns An array of mined transaction hashes found in the tx pool.
|
|
67
105
|
*/
|
|
68
|
-
getMinedTxHashes(): Promise<[tx: TxHash, blockNumber:
|
|
106
|
+
getMinedTxHashes(): Promise<[tx: TxHash, blockNumber: BlockNumber][]>;
|
|
69
107
|
|
|
70
108
|
/**
|
|
71
|
-
* Returns whether the given tx hash is flagged as pending or
|
|
109
|
+
* Returns whether the given tx hash is flagged as pending, mined, or deleted.
|
|
72
110
|
* @param txHash - Hash of the tx to query.
|
|
73
|
-
* @returns Pending or
|
|
111
|
+
* @returns Pending, mined, or deleted depending on its status, or undefined if not found.
|
|
112
|
+
*/
|
|
113
|
+
getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Configure the maximum size of the tx pool
|
|
117
|
+
* @param maxSizeBytes - The maximum size in bytes of the mempool. Set to undefined to disable it
|
|
118
|
+
*/
|
|
119
|
+
updateConfig(config: TxPoolOptions): void;
|
|
120
|
+
|
|
121
|
+
/** Returns whether the pool is empty. */
|
|
122
|
+
isEmpty(): Promise<boolean>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Marks transactions as non-evictible in the pool.
|
|
126
|
+
* @param txHashes - Hashes of the transactions to mark as non-evictible.
|
|
127
|
+
*/
|
|
128
|
+
markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Clears collection of non-evictable transactions in the pool
|
|
132
|
+
*/
|
|
133
|
+
clearNonEvictableTxs(): Promise<void>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
|
|
137
|
+
* @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
|
|
138
|
+
* @returns The number of transactions permanently deleted.
|
|
74
139
|
*/
|
|
75
|
-
|
|
140
|
+
cleanupDeletedMinedTxs(blockNumber: BlockNumber): Promise<number>;
|
|
76
141
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { unfreeze } from '@aztec/foundation/types';
|
|
2
3
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
3
4
|
import { mockTx } from '@aztec/stdlib/testing';
|
|
4
|
-
import type
|
|
5
|
+
import { BlockHeader, GlobalVariables, type Tx } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
7
|
import type { TxPool } from './tx_pool.js';
|
|
7
8
|
|
|
@@ -12,79 +13,123 @@ import type { TxPool } from './tx_pool.js';
|
|
|
12
13
|
export function describeTxPool(getTxPool: () => TxPool) {
|
|
13
14
|
let pool: TxPool;
|
|
14
15
|
|
|
16
|
+
const minedBlockHeader = BlockHeader.empty({
|
|
17
|
+
globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(1), timestamp: 0n }),
|
|
18
|
+
});
|
|
19
|
+
|
|
15
20
|
beforeEach(() => {
|
|
16
21
|
pool = getTxPool();
|
|
17
22
|
});
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
pool.removeAllListeners('txs-added');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('adds txs to the pool as pending', async () => {
|
|
29
|
+
const tx1 = await mockTx(1);
|
|
21
30
|
|
|
22
31
|
await pool.addTxs([tx1]);
|
|
23
|
-
const poolTx = await pool.getTxByHash(
|
|
24
|
-
expect(
|
|
25
|
-
await expect(pool.getTxStatus(
|
|
26
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
32
|
+
const poolTx = await pool.getTxByHash(tx1.getTxHash());
|
|
33
|
+
expect(poolTx!.getTxHash()).toEqual(tx1.getTxHash());
|
|
34
|
+
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('pending');
|
|
35
|
+
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]);
|
|
36
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
27
37
|
});
|
|
28
38
|
|
|
29
|
-
it('
|
|
30
|
-
const tx1 = await mockTx();
|
|
39
|
+
it('emits txs-added event with new txs', async () => {
|
|
40
|
+
const tx1 = await mockTx(1); // existing and pending
|
|
41
|
+
const tx2 = await mockTx(2); // mined but not known
|
|
42
|
+
const tx3 = await mockTx(3); // brand new
|
|
31
43
|
|
|
32
44
|
await pool.addTxs([tx1]);
|
|
33
|
-
await pool.
|
|
45
|
+
await pool.markAsMined([tx2.getTxHash()], minedBlockHeader);
|
|
46
|
+
|
|
47
|
+
let txsFromEvent: Tx[] | undefined = undefined;
|
|
48
|
+
pool.once('txs-added', ({ txs }) => {
|
|
49
|
+
txsFromEvent = txs;
|
|
50
|
+
});
|
|
34
51
|
|
|
35
|
-
await
|
|
36
|
-
|
|
52
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
53
|
+
expect(txsFromEvent).toBeDefined();
|
|
54
|
+
expect(txsFromEvent).toHaveLength(2);
|
|
55
|
+
const eventHashes = txsFromEvent!.map(tx => tx.getTxHash());
|
|
56
|
+
expect(eventHashes).toEqual(expect.arrayContaining([tx2.getTxHash(), tx3.getTxHash()]));
|
|
37
57
|
});
|
|
38
58
|
|
|
39
|
-
it('
|
|
59
|
+
it('removes txs from the pool', async () => {
|
|
60
|
+
const pendingTx = await mockTx(1);
|
|
61
|
+
const minedTx = await mockTx(2);
|
|
62
|
+
|
|
63
|
+
await pool.addTxs([pendingTx, minedTx]);
|
|
64
|
+
await pool.markAsMined([minedTx.getTxHash()], minedBlockHeader);
|
|
65
|
+
|
|
66
|
+
// Delete a pending tx - should be permanently deleted
|
|
67
|
+
await pool.deleteTxs([pendingTx.getTxHash()]);
|
|
68
|
+
await expect(pool.getTxByHash(pendingTx.getTxHash())).resolves.toBeUndefined();
|
|
69
|
+
await expect(pool.getTxStatus(pendingTx.getTxHash())).resolves.toBeUndefined();
|
|
70
|
+
|
|
71
|
+
// Delete a mined tx - should be soft-deleted (still in storage)
|
|
72
|
+
await pool.deleteTxs([minedTx.getTxHash()]);
|
|
73
|
+
await expect(pool.getTxByHash(minedTx.getTxHash())).resolves.toBeDefined();
|
|
74
|
+
await expect(pool.getTxStatus(minedTx.getTxHash())).resolves.toEqual('deleted');
|
|
75
|
+
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
76
|
+
|
|
77
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('marks txs as mined', async () => {
|
|
40
81
|
const tx1 = await mockTx(1);
|
|
41
82
|
const tx2 = await mockTx(2);
|
|
42
83
|
|
|
43
84
|
await pool.addTxs([tx1, tx2]);
|
|
44
|
-
await pool.markAsMined([
|
|
85
|
+
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
45
86
|
|
|
46
|
-
await
|
|
47
|
-
|
|
48
|
-
await expect(pool.
|
|
49
|
-
await expect(pool.
|
|
87
|
+
const retrievedTx = await pool.getTxByHash(tx1.getTxHash());
|
|
88
|
+
expect(retrievedTx?.getTxHash()).toEqual(tx1.getTxHash());
|
|
89
|
+
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('mined');
|
|
90
|
+
await expect(pool.getMinedTxHashes()).resolves.toEqual([[tx1.getTxHash(), 1]]);
|
|
91
|
+
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx2.getTxHash()]);
|
|
92
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
50
93
|
});
|
|
51
94
|
|
|
52
|
-
it('
|
|
95
|
+
it('marks txs as pending after being mined', async () => {
|
|
53
96
|
const tx1 = await mockTx(1);
|
|
54
97
|
const tx2 = await mockTx(2);
|
|
55
98
|
|
|
56
99
|
await pool.addTxs([tx1, tx2]);
|
|
57
|
-
await pool.markAsMined([
|
|
100
|
+
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
58
101
|
|
|
59
|
-
await pool.markMinedAsPending([
|
|
102
|
+
await pool.markMinedAsPending([tx1.getTxHash()], BlockNumber(1));
|
|
60
103
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
61
104
|
const pending = await pool.getPendingTxHashes();
|
|
62
105
|
expect(pending).toHaveLength(2);
|
|
63
|
-
expect(pending).toEqual(expect.arrayContaining([
|
|
106
|
+
expect(pending).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash()]));
|
|
107
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(2);
|
|
64
108
|
});
|
|
65
109
|
|
|
66
|
-
it('
|
|
110
|
+
it('only marks txs as pending if they are known', async () => {
|
|
67
111
|
const tx1 = await mockTx(1);
|
|
68
112
|
// simulate a situation where not all peers have all the txs
|
|
69
113
|
const tx2 = await mockTx(2);
|
|
70
|
-
const someTxHashThatThisPeerDidNotSee =
|
|
114
|
+
const someTxHashThatThisPeerDidNotSee = tx2.getTxHash();
|
|
71
115
|
await pool.addTxs([tx1]);
|
|
72
116
|
// this peer knows that tx2 was mined, but it does not have the tx object
|
|
73
|
-
await pool.markAsMined([
|
|
117
|
+
await pool.markAsMined([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], minedBlockHeader);
|
|
74
118
|
expect(await pool.getMinedTxHashes()).toEqual(
|
|
75
119
|
expect.arrayContaining([
|
|
76
|
-
[
|
|
120
|
+
[tx1.getTxHash(), 1],
|
|
77
121
|
[someTxHashThatThisPeerDidNotSee, 1],
|
|
78
122
|
]),
|
|
79
123
|
);
|
|
80
124
|
|
|
81
125
|
// reorg: both txs should now become available again
|
|
82
|
-
await pool.markMinedAsPending([
|
|
126
|
+
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], BlockNumber(1));
|
|
83
127
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
84
|
-
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
128
|
+
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]); // tx2 is not in the pool
|
|
129
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
85
130
|
});
|
|
86
131
|
|
|
87
|
-
it('
|
|
132
|
+
it('returns all transactions in the pool', async () => {
|
|
88
133
|
const tx1 = await mockTx(1);
|
|
89
134
|
const tx2 = await mockTx(2);
|
|
90
135
|
const tx3 = await mockTx(3);
|
|
@@ -93,10 +138,12 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
93
138
|
|
|
94
139
|
const poolTxs = await pool.getAllTxs();
|
|
95
140
|
expect(poolTxs).toHaveLength(3);
|
|
96
|
-
|
|
141
|
+
const poolHashes = poolTxs.map(tx => tx.getTxHash());
|
|
142
|
+
expect(poolHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx2.getTxHash(), tx3.getTxHash()]));
|
|
143
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
97
144
|
});
|
|
98
145
|
|
|
99
|
-
it('
|
|
146
|
+
it('returns all txHashes in the pool', async () => {
|
|
100
147
|
const tx1 = await mockTx(1);
|
|
101
148
|
const tx2 = await mockTx(2);
|
|
102
149
|
const tx3 = await mockTx(3);
|
|
@@ -104,13 +151,58 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
104
151
|
await pool.addTxs([tx1, tx2, tx3]);
|
|
105
152
|
|
|
106
153
|
const poolTxHashes = await pool.getAllTxHashes();
|
|
154
|
+
const expectedHashes = [tx1, tx2, tx3].map(tx => tx.getTxHash());
|
|
107
155
|
expect(poolTxHashes).toHaveLength(3);
|
|
108
|
-
expect(poolTxHashes).toEqual(
|
|
109
|
-
|
|
110
|
-
);
|
|
156
|
+
expect(poolTxHashes).toEqual(expect.arrayContaining(expectedHashes));
|
|
157
|
+
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
111
158
|
});
|
|
112
159
|
|
|
113
|
-
it('
|
|
160
|
+
it('returns txs by their hash', async () => {
|
|
161
|
+
const tx1 = await mockTx(1);
|
|
162
|
+
const tx2 = await mockTx(2);
|
|
163
|
+
const tx3 = await mockTx(3);
|
|
164
|
+
|
|
165
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
166
|
+
|
|
167
|
+
const requestedTxs = await pool.getTxsByHash([tx1.getTxHash(), tx3.getTxHash()]);
|
|
168
|
+
expect(requestedTxs).toHaveLength(2);
|
|
169
|
+
const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
|
|
170
|
+
expect(requestedHashes).toEqual(expect.arrayContaining([tx1.getTxHash(), tx3.getTxHash()]));
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('returns a large number of transactions by their hash', async () => {
|
|
174
|
+
const numTxs = 1_000;
|
|
175
|
+
const txs = await Promise.all(Array.from({ length: numTxs }, (_, i) => mockTx(i)));
|
|
176
|
+
const hashes = txs.map(tx => tx.getTxHash());
|
|
177
|
+
await pool.addTxs(txs);
|
|
178
|
+
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
179
|
+
expect(requestedTxs).toHaveLength(numTxs);
|
|
180
|
+
const requestedHashes = requestedTxs.map(tx => tx!.getTxHash());
|
|
181
|
+
expect(requestedHashes).toEqual(expect.arrayContaining(hashes));
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('returns whether or not txs exist', async () => {
|
|
185
|
+
const tx1 = await mockTx(1);
|
|
186
|
+
const tx2 = await mockTx(2);
|
|
187
|
+
const tx3 = await mockTx(3);
|
|
188
|
+
|
|
189
|
+
await pool.addTxs([tx1, tx2, tx3]);
|
|
190
|
+
|
|
191
|
+
const tx4 = await mockTx(4);
|
|
192
|
+
const tx5 = await mockTx(5);
|
|
193
|
+
|
|
194
|
+
const availability = await pool.hasTxs([
|
|
195
|
+
tx1.getTxHash(),
|
|
196
|
+
tx2.getTxHash(),
|
|
197
|
+
tx3.getTxHash(),
|
|
198
|
+
tx4.getTxHash(),
|
|
199
|
+
tx5.getTxHash(),
|
|
200
|
+
]);
|
|
201
|
+
expect(availability).toHaveLength(5);
|
|
202
|
+
expect(availability).toEqual(expect.arrayContaining([true, true, true, false, false]));
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('returns pending tx hashes sorted by priority', async () => {
|
|
114
206
|
const withPriorityFee = (tx: Tx, fee: number) => {
|
|
115
207
|
unfreeze(tx.data.constants.txContext.gasSettings).maxPriorityFeesPerGas = new GasFees(fee, fee);
|
|
116
208
|
return tx;
|
|
@@ -125,6 +217,103 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
125
217
|
|
|
126
218
|
const poolTxHashes = await pool.getPendingTxHashes();
|
|
127
219
|
expect(poolTxHashes).toHaveLength(4);
|
|
128
|
-
expect(poolTxHashes).toEqual(
|
|
220
|
+
expect(poolTxHashes).toEqual([tx4, tx1, tx3, tx2].map(tx => tx.getTxHash()));
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe('soft-delete', () => {
|
|
224
|
+
it('soft-deletes mined txs and keeps them in storage', async () => {
|
|
225
|
+
const txs = await Promise.all([mockTx(1), mockTx(2), mockTx(3)]);
|
|
226
|
+
await pool.addTxs(txs);
|
|
227
|
+
|
|
228
|
+
// Mark first tx as mined
|
|
229
|
+
await pool.markAsMined([txs[0].getTxHash()], minedBlockHeader);
|
|
230
|
+
|
|
231
|
+
// Verify initial state
|
|
232
|
+
await expect(pool.getPendingTxCount()).resolves.toBe(2);
|
|
233
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
234
|
+
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeDefined();
|
|
235
|
+
|
|
236
|
+
// Delete mined tx - should be soft-deleted
|
|
237
|
+
await pool.deleteTxs([txs[0].getTxHash()]);
|
|
238
|
+
|
|
239
|
+
// Delete pending tx - should be permanently deleted
|
|
240
|
+
await pool.deleteTxs([txs[1].getTxHash()]);
|
|
241
|
+
|
|
242
|
+
// Verify mined tx still exists in storage but has 'deleted' status
|
|
243
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
244
|
+
await expect(pool.getTxStatus(txs[0].getTxHash())).resolves.toEqual('deleted');
|
|
245
|
+
|
|
246
|
+
// Verify pending tx is permanently deleted
|
|
247
|
+
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
248
|
+
await expect(pool.getTxStatus(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
249
|
+
|
|
250
|
+
// Verify remaining pending count
|
|
251
|
+
await expect(pool.getPendingTxCount()).resolves.toBe(1);
|
|
252
|
+
|
|
253
|
+
// Verify pending hashes don't include deleted txs
|
|
254
|
+
const pendingHashes = await pool.getPendingTxHashes();
|
|
255
|
+
expect(pendingHashes).toHaveLength(1);
|
|
256
|
+
expect(pendingHashes.map(h => h.toString())).toContain(txs[2].getTxHash().toString());
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('cleans up old deleted mined transactions', async () => {
|
|
260
|
+
const txs = await Promise.all([mockTx(1), mockTx(2), mockTx(3)]);
|
|
261
|
+
await pool.addTxs(txs);
|
|
262
|
+
|
|
263
|
+
// Mark first two as mined in block 1
|
|
264
|
+
await pool.markAsMined([txs[0].getTxHash(), txs[1].getTxHash()], minedBlockHeader);
|
|
265
|
+
|
|
266
|
+
// Soft-delete mined transactions
|
|
267
|
+
await pool.deleteTxs([txs[0].getTxHash(), txs[1].getTxHash()]);
|
|
268
|
+
|
|
269
|
+
// Clean up deleted mined txs from block 1 and earlier
|
|
270
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
271
|
+
|
|
272
|
+
// Verify old transactions are permanently deleted
|
|
273
|
+
expect(deletedCount).toBe(2);
|
|
274
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeUndefined();
|
|
275
|
+
await expect(pool.getTxByHash(txs[1].getTxHash())).resolves.toBeUndefined();
|
|
276
|
+
await expect(pool.getTxByHash(txs[2].getTxHash())).resolves.toBeDefined();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('does not clean up recent deleted mined transactions', async () => {
|
|
280
|
+
const txs = await Promise.all([mockTx(1), mockTx(2)]);
|
|
281
|
+
await pool.addTxs(txs);
|
|
282
|
+
|
|
283
|
+
// Mark as mined in block 2
|
|
284
|
+
const laterBlockHeader = BlockHeader.empty({
|
|
285
|
+
globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(2), timestamp: 0n }),
|
|
286
|
+
});
|
|
287
|
+
await pool.markAsMined([txs[0].getTxHash()], laterBlockHeader);
|
|
288
|
+
|
|
289
|
+
// Soft-delete a mined transaction
|
|
290
|
+
await pool.deleteTxs([txs[0].getTxHash()]);
|
|
291
|
+
|
|
292
|
+
// Try to clean up with block 1 (before the mined block)
|
|
293
|
+
const deletedCount = await pool.cleanupDeletedMinedTxs(BlockNumber(1));
|
|
294
|
+
|
|
295
|
+
// Verify no transactions were cleaned up
|
|
296
|
+
expect(deletedCount).toBe(0);
|
|
297
|
+
await expect(pool.getTxByHash(txs[0].getTxHash())).resolves.toBeDefined();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('restores deleted mined tx when it is mined again', async () => {
|
|
301
|
+
const tx = await mockTx(1);
|
|
302
|
+
await pool.addTxs([tx]);
|
|
303
|
+
|
|
304
|
+
// Mark as mined
|
|
305
|
+
await pool.markAsMined([tx.getTxHash()], minedBlockHeader);
|
|
306
|
+
|
|
307
|
+
// Soft-delete it
|
|
308
|
+
await pool.deleteTxs([tx.getTxHash()]);
|
|
309
|
+
await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('deleted');
|
|
310
|
+
|
|
311
|
+
// Mark as mined again (e.g., after a reorg)
|
|
312
|
+
await pool.markAsMined([tx.getTxHash()], minedBlockHeader);
|
|
313
|
+
|
|
314
|
+
// Should be back to mined status
|
|
315
|
+
await expect(pool.getTxStatus(tx.getTxHash())).resolves.toEqual('mined');
|
|
316
|
+
await expect(pool.getTxByHash(tx.getTxHash())).resolves.toBeDefined();
|
|
317
|
+
});
|
|
129
318
|
});
|
|
130
319
|
}
|