@aztec/p2p 0.0.1-commit.03f7ef2 → 0.0.1-commit.0658669b3
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 +4 -4
- package/dest/client/factory.d.ts +7 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +41 -14
- package/dest/client/interface.d.ts +60 -34
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +46 -59
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +600 -313
- 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 +38 -13
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -18
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +111 -76
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +527 -287
- 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 +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- package/dest/mem_pools/index.d.ts +3 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/instrumentation.d.ts +3 -3
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +11 -18
- package/dest/mem_pools/interface.d.ts +5 -5
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +35 -26
- 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 +312 -336
- 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 +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +8 -4
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +7 -7
- 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 +93 -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 +95 -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 +174 -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 +73 -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 +211 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +9 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +105 -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 +164 -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 +355 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +60 -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 +161 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +77 -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 +891 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -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 +22 -13
- 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/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 +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/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/archive_cache.js +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/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 +4 -1
- 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 +118 -5
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +228 -57
- 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 +59 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +84 -52
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
- 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 +3 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- 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/timestamp_validator.d.ts +22 -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 +10 -6
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/dummy_service.d.ts +28 -4
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +49 -1
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +9 -7
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +346 -0
- package/dest/services/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 +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +30 -72
- package/dest/services/libp2p/libp2p_service.d.ts +111 -35
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +1019 -365
- package/dest/services/peer-manager/metrics.d.ts +7 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +33 -21
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +2 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -6
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +48 -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 +539 -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 +46 -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 +34 -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 +130 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +60 -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 +173 -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/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 +12 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- 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/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 +29 -6
- 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 +59 -13
- package/dest/services/reqresp/protocols/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -1
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +6 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +471 -50
- package/dest/services/service.d.ts +56 -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 +55 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +7 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +71 -44
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +90 -0
- package/dest/services/tx_collection/index.d.ts +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/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +49 -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 +9 -5
- 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 +29 -16
- 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 +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/config.d.ts +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 +6 -6
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +12 -9
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +7 -20
- 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 +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +29 -2
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +103 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -1
- package/dest/test-helpers/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 +366 -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 +221 -126
- package/dest/testbench/worker_client_manager.d.ts +51 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +226 -39
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +76 -24
- package/src/client/interface.ts +78 -35
- package/src/client/p2p_client.ts +263 -358
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +346 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +57 -27
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +510 -78
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +612 -320
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +20 -13
- package/src/mem_pools/index.ts +4 -1
- package/src/mem_pools/instrumentation.ts +19 -25
- package/src/mem_pools/interface.ts +4 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +360 -368
- 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 +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +8 -3
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +7 -7
- package/src/mem_pools/tx_pool_v2/README.md +275 -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 +121 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +122 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +27 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +209 -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 +90 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -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 +242 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +255 -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 +444 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +223 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1063 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +21 -18
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- 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/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
- package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
- package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
- package/src/msg_validators/tx_validator/data_validator.ts +18 -6
- package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
- package/src/msg_validators/tx_validator/factory.ts +372 -55
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +106 -54
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +18 -7
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +29 -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 +10 -7
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +65 -2
- package/src/services/encoding.ts +8 -6
- package/src/services/gossipsub/README.md +641 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +487 -0
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/instrumentation.ts +32 -73
- package/src/services/libp2p/libp2p_service.ts +705 -364
- package/src/services/peer-manager/metrics.ts +39 -21
- package/src/services/peer-manager/peer_manager.ts +3 -2
- package/src/services/peer-manager/peer_scoring.ts +28 -4
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +678 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +53 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +161 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +244 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- 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 +29 -1
- package/src/services/reqresp/metrics.ts +36 -27
- 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 +74 -9
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +79 -22
- package/src/services/service.ts +73 -5
- package/src/services/tx_collection/config.ts +83 -1
- package/src/services/tx_collection/fast_tx_collection.ts +93 -47
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +6 -0
- package/src/services/tx_collection/instrumentation.ts +11 -13
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +113 -0
- package/src/services/tx_collection/slow_tx_collection.ts +68 -35
- package/src/services/tx_collection/tx_collection.ts +121 -24
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +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 +16 -12
- package/src/services/tx_provider_instrumentation.ts +13 -20
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +143 -3
- package/src/test-helpers/reqresp-nodes.ts +2 -1
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +430 -0
- package/src/testbench/p2p_client_testbench_worker.ts +348 -122
- package/src/testbench/worker_client_manager.ts +304 -42
- package/src/util.ts +7 -1
- 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/memory_tx_pool.d.ts +0 -81
- 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 -242
- 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/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/memory_tx_pool.ts +0 -288
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- 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
18
|
const totalFees = priorityFees.feePerDaGas + priorityFees.feePerL2Gas;
|
|
12
|
-
return
|
|
19
|
+
return totalFees;
|
|
13
20
|
}
|
|
@@ -3,8 +3,7 @@ import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
|
3
3
|
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
export type TxPoolOptions = {
|
|
6
|
-
|
|
7
|
-
txPoolOverflowFactor?: number;
|
|
6
|
+
maxPendingTxCount?: number;
|
|
8
7
|
archivedTxLimit?: number;
|
|
9
8
|
};
|
|
10
9
|
|
|
@@ -69,8 +68,9 @@ export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
|
|
|
69
68
|
* Moves mined txs back to the pending set in the case of a reorg.
|
|
70
69
|
* Note: txs not known by this peer will be ignored.
|
|
71
70
|
* @param txHashes - Hashes of the txs to flag as pending.
|
|
71
|
+
* @param latestBlock - The block number the chain was pruned to.
|
|
72
72
|
*/
|
|
73
|
-
markMinedAsPending(txHashes: TxHash[]): Promise<void>;
|
|
73
|
+
markMinedAsPending(txHashes: TxHash[], latestBlock: BlockNumber): Promise<void>;
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
@@ -127,6 +127,11 @@ export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
|
|
|
127
127
|
*/
|
|
128
128
|
markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void>;
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Clears collection of non-evictable transactions in the pool
|
|
132
|
+
*/
|
|
133
|
+
clearNonEvictableTxs(): Promise<void>;
|
|
134
|
+
|
|
130
135
|
/**
|
|
131
136
|
* Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
|
|
132
137
|
* @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
|
|
@@ -26,7 +26,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it('adds txs to the pool as pending', async () => {
|
|
29
|
-
const tx1 = await mockTx();
|
|
29
|
+
const tx1 = await mockTx(1);
|
|
30
30
|
|
|
31
31
|
await pool.addTxs([tx1]);
|
|
32
32
|
const poolTx = await pool.getTxByHash(tx1.getTxHash());
|
|
@@ -37,9 +37,9 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it('emits txs-added event with new txs', async () => {
|
|
40
|
-
const tx1 = await mockTx(); // existing and pending
|
|
41
|
-
const tx2 = await mockTx(); // mined but not known
|
|
42
|
-
const tx3 = await mockTx(); // brand new
|
|
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
|
|
43
43
|
|
|
44
44
|
await pool.addTxs([tx1]);
|
|
45
45
|
await pool.markAsMined([tx2.getTxHash()], minedBlockHeader);
|
|
@@ -56,7 +56,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
56
56
|
expect(eventHashes).toEqual(expect.arrayContaining([tx2.getTxHash(), tx3.getTxHash()]));
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it('
|
|
59
|
+
it('removes txs from the pool', async () => {
|
|
60
60
|
const pendingTx = await mockTx(1);
|
|
61
61
|
const minedTx = await mockTx(2);
|
|
62
62
|
|
|
@@ -99,7 +99,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
99
99
|
await pool.addTxs([tx1, tx2]);
|
|
100
100
|
await pool.markAsMined([tx1.getTxHash()], minedBlockHeader);
|
|
101
101
|
|
|
102
|
-
await pool.markMinedAsPending([tx1.getTxHash()]);
|
|
102
|
+
await pool.markMinedAsPending([tx1.getTxHash()], BlockNumber(1));
|
|
103
103
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
104
104
|
const pending = await pool.getPendingTxHashes();
|
|
105
105
|
expect(pending).toHaveLength(2);
|
|
@@ -123,7 +123,7 @@ export function describeTxPool(getTxPool: () => TxPool) {
|
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
// reorg: both txs should now become available again
|
|
126
|
-
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee]);
|
|
126
|
+
await pool.markMinedAsPending([tx1.getTxHash(), someTxHashThatThisPeerDidNotSee], BlockNumber(1));
|
|
127
127
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
128
128
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([tx1.getTxHash()]); // tx2 is not in the pool
|
|
129
129
|
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# TxPoolV2
|
|
2
|
+
|
|
3
|
+
Transaction pool implementation with explicit state management and pluggable eviction rules.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
TxPoolV2 manages transactions through a state machine with clear transitions:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
addPendingTxs()
|
|
11
|
+
│
|
|
12
|
+
▼
|
|
13
|
+
┌─────────────────────────────────────┐
|
|
14
|
+
│ PENDING │◄──────────────────┐
|
|
15
|
+
│ (awaiting block inclusion) │ │
|
|
16
|
+
└─────────────────────────────────────┘ │
|
|
17
|
+
│ │
|
|
18
|
+
│ protectTxs() / addProtectedTxs() │
|
|
19
|
+
▼ │
|
|
20
|
+
┌─────────────────────────────────────┐ │
|
|
21
|
+
│ PROTECTED │───────────────────┘
|
|
22
|
+
│ (in a block proposal) │ prepareForSlot()
|
|
23
|
+
└─────────────────────────────────────┘ (slot passed without mining)
|
|
24
|
+
│ │
|
|
25
|
+
│ handleMinedBlock() │
|
|
26
|
+
▼ │
|
|
27
|
+
┌─────────────────────────────────────┐ │
|
|
28
|
+
│ MINED │───────────────────┘
|
|
29
|
+
│ (included in a block) │ handlePrunedBlocks()
|
|
30
|
+
└─────────────────────────────────────┘ (reorg)
|
|
31
|
+
│ │
|
|
32
|
+
│ handleFinalizedBlock() │ eviction after reorg
|
|
33
|
+
│ / eviction / failed exec │ (validation failure)
|
|
34
|
+
▼ ▼
|
|
35
|
+
┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
|
|
36
|
+
│ SLOT-SOFT-DELETED │ │ PRUNE-SOFT-DELETED │
|
|
37
|
+
│ (kept in DB until next slot) │ │ (kept in DB until finalized) │
|
|
38
|
+
└─────────────────────────────────────┘ └─────────────────────────────────────┘
|
|
39
|
+
│ │
|
|
40
|
+
│ prepareForSlot() │ handleFinalizedBlock()
|
|
41
|
+
│ (slot advanced) │ (mined block finalized)
|
|
42
|
+
▼ ▼
|
|
43
|
+
┌─────────────────────────────────────┐ ┌─────────────────────────────────────┐
|
|
44
|
+
│ HARD-DELETED │ │ HARD-DELETED │
|
|
45
|
+
│ (permanently removed from DB) │ │ (permanently removed from DB) │
|
|
46
|
+
└─────────────────────────────────────┘ └─────────────────────────────────────┘
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Key Components
|
|
50
|
+
|
|
51
|
+
### TxPoolV2 (`tx_pool_v2.ts`)
|
|
52
|
+
|
|
53
|
+
The public API wrapper that serializes all operations through a queue to prevent race conditions. Delegates to `TxPoolV2Impl` for actual logic.
|
|
54
|
+
|
|
55
|
+
### TxPoolV2Impl (`tx_pool_v2_impl.ts`)
|
|
56
|
+
|
|
57
|
+
Core implementation containing:
|
|
58
|
+
- KV store persistence for transactions and metadata
|
|
59
|
+
- In-memory indices for fast lookups (by nullifier, fee payer, priority)
|
|
60
|
+
- State transition logic
|
|
61
|
+
- Pre-add rule execution
|
|
62
|
+
- Post-event eviction rule execution
|
|
63
|
+
|
|
64
|
+
### DeletedPool (`deleted_pool.ts`)
|
|
65
|
+
|
|
66
|
+
Manages all transaction deletions in the pool with two soft-deletion mechanisms:
|
|
67
|
+
- **Slot-based**: Non-pruned txs are kept in DB until the next slot, allowing other nodes to fetch them via reqresp
|
|
68
|
+
- **Prune-based**: Txs from pruned blocks are kept in DB until their original mined block is finalized
|
|
69
|
+
|
|
70
|
+
All deletions go through `DeletedPool.deleteTx()`, which routes to the appropriate path based on whether the tx is tracked as being from a pruned block.
|
|
71
|
+
|
|
72
|
+
### TxMetaData (`tx_metadata.ts`)
|
|
73
|
+
|
|
74
|
+
Lightweight metadata stored alongside each transaction:
|
|
75
|
+
- `txHash`: Transaction identifier
|
|
76
|
+
- `anchorBlockHeaderHash`: Hash of the anchor block header
|
|
77
|
+
- `priorityFee`: For priority ordering and challenges
|
|
78
|
+
- `feePayer`: For balance-based eviction
|
|
79
|
+
- `claimAmount`: Fee payer's claim from bridging
|
|
80
|
+
- `feeLimit`: Maximum fee the tx can pay
|
|
81
|
+
- `nullifiers`: For conflict detection
|
|
82
|
+
- `expirationTimestamp`: Expiration timestamp
|
|
83
|
+
- `minedL2BlockId`: Set when mined (undefined otherwise)
|
|
84
|
+
|
|
85
|
+
State is derived by TxPoolIndices:
|
|
86
|
+
- `mined` if `minedL2BlockId` is set
|
|
87
|
+
- `protected` if in protection map
|
|
88
|
+
- `deleted` if soft-deleted (slot-based or prune-based, evicted but kept in DB)
|
|
89
|
+
- `pending` otherwise
|
|
90
|
+
|
|
91
|
+
## Soft Deletion
|
|
92
|
+
|
|
93
|
+
Deleted transactions are kept in the database for a grace period before being permanently removed. There are two soft-deletion mechanisms:
|
|
94
|
+
|
|
95
|
+
### Slot-Based Soft Deletion
|
|
96
|
+
|
|
97
|
+
When a transaction is deleted from the pool (eviction, validation failure, failed execution) and is **not** from a pruned block, it is "slot-soft-deleted":
|
|
98
|
+
|
|
99
|
+
1. **Soft Delete**: The tx is removed from indices but kept in the database, tagged with the current slot number
|
|
100
|
+
2. **Retrieval**: Slot-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
|
|
101
|
+
3. **Hard Delete**: When `prepareForSlot` advances to a new slot, txs deleted in earlier slots are permanently removed
|
|
102
|
+
4. **Re-addition**: If a slot-soft-deleted tx is re-added to the pool, the slot-deleted tracking is cleared
|
|
103
|
+
|
|
104
|
+
This allows other nodes to still fetch recently-deleted transactions via reqresp during the current slot.
|
|
105
|
+
|
|
106
|
+
### Prune-Based Soft Deletion
|
|
107
|
+
|
|
108
|
+
When a chain reorganization occurs, transactions that were mined in pruned blocks are handled with longer retention:
|
|
109
|
+
|
|
110
|
+
1. **Tracking**: When `handlePrunedBlocks` is called, all un-mined transactions are tracked by their original mined block number
|
|
111
|
+
2. **Soft Delete**: If these transactions are later evicted (failed validation, nullifier conflict, etc.), they are "prune-soft-deleted" - removed from indices but kept in the database
|
|
112
|
+
3. **Retrieval**: Prune-soft-deleted txs can still be retrieved via `getTxByHash` and return status `'deleted'` from `getTxStatus`
|
|
113
|
+
4. **Hard Delete**: When `handleFinalizedBlock` is called and the finalized block number reaches or exceeds the transaction's original mined block, the transaction is permanently removed
|
|
114
|
+
5. **Re-addition**: If a prune-soft-deleted tx is re-added, the `softDeleted` flag is reset to `false` but the prune tracking is preserved, so a subsequent deletion still uses the prune path
|
|
115
|
+
|
|
116
|
+
Prune-soft-deleted transactions are **not** affected by slot cleanup - they survive across slot boundaries until finalized.
|
|
117
|
+
|
|
118
|
+
**Prune example:**
|
|
119
|
+
1. Tx mined at block 10
|
|
120
|
+
2. Chain prunes to block 5 (tx becomes un-mined, tracked as minedAtBlock=10)
|
|
121
|
+
3. Tx fails validation and is prune-soft-deleted
|
|
122
|
+
4. Block 9 finalized → tx still in DB (minedAtBlock=10 > finalized=9)
|
|
123
|
+
5. Block 10 finalized → tx hard-deleted (minedAtBlock=10 ≤ finalized=10)
|
|
124
|
+
|
|
125
|
+
If the tx is re-mined at a higher block before being soft-deleted:
|
|
126
|
+
1. Tx mined at block 10, pruned (tracked as minedAtBlock=10)
|
|
127
|
+
2. Tx re-mined at block 15, pruned again (updated to minedAtBlock=15)
|
|
128
|
+
3. Tx soft-deleted
|
|
129
|
+
4. Block 10 finalized → tx still in DB
|
|
130
|
+
5. Block 15 finalized → tx hard-deleted
|
|
131
|
+
|
|
132
|
+
### Hydration
|
|
133
|
+
|
|
134
|
+
On node restart, slot-soft-deleted transactions are immediately hard-deleted (they are stale by definition). Prune-soft-deleted transactions are loaded from the database and tracked normally.
|
|
135
|
+
|
|
136
|
+
## Architecture: Pre-add vs Post-event Rules
|
|
137
|
+
|
|
138
|
+
**Pre-add rules** (run during `addPendingTxs`):
|
|
139
|
+
- Used for external transactions entering the pool
|
|
140
|
+
- Can reject the incoming tx entirely
|
|
141
|
+
- Can evict lower-priority existing txs to make room
|
|
142
|
+
- Rules: NullifierConflictRule, FeePayerBalancePreAddRule, LowPriorityPreAddRule
|
|
143
|
+
|
|
144
|
+
**Post-event rules** (run after state transitions):
|
|
145
|
+
- Used for internal state changes (block mined, reorg, slot change)
|
|
146
|
+
- Only evict txs already in the pool
|
|
147
|
+
- Rules: InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, FeePayerBalanceEvictionRule, LowPriorityEvictionRule
|
|
148
|
+
|
|
149
|
+
This design choice means restored txs (from protected/mined states) use post-event rules only, because they were already validated on initial submission.
|
|
150
|
+
|
|
151
|
+
## Eviction Rules
|
|
152
|
+
|
|
153
|
+
The pool uses a pluggable rule system for managing transactions.
|
|
154
|
+
|
|
155
|
+
### Pre-Add Rules
|
|
156
|
+
|
|
157
|
+
Checked before adding a transaction to the pending pool:
|
|
158
|
+
|
|
159
|
+
| Rule | Purpose |
|
|
160
|
+
|------|---------|
|
|
161
|
+
| `NullifierConflictRule` | Handles transactions with conflicting nullifiers. Higher priority tx wins. |
|
|
162
|
+
| `FeePayerBalancePreAddRule` | Ensures fee payer has sufficient balance for all their pending txs. |
|
|
163
|
+
| `LowPriorityPreAddRule` | Rejects txs when pool is full and new tx has lowest priority. |
|
|
164
|
+
|
|
165
|
+
### Post-Event Eviction Rules
|
|
166
|
+
|
|
167
|
+
Run after events to clean up the pool:
|
|
168
|
+
|
|
169
|
+
| Rule | Trigger | Purpose |
|
|
170
|
+
|------|---------|---------|
|
|
171
|
+
| `LowPriorityEvictionRule` | `txs_added` | Evicts lowest priority txs when pool exceeds limit. |
|
|
172
|
+
| `FeePayerBalanceEvictionRule` | `txs_added`, `block_mined`, `chain_pruned` | Evicts txs when fee payer has insufficient balance. |
|
|
173
|
+
| `InvalidTxsAfterMiningRule` | `block_mined` | Evicts pending txs with: (1) nullifiers in mined block, (2) expired timestamp. |
|
|
174
|
+
| `InvalidTxsAfterReorgRule` | `chain_pruned` | Evicts txs with invalid anchor blocks after reorg. |
|
|
175
|
+
|
|
176
|
+
## Usage
|
|
177
|
+
|
|
178
|
+
### Creating a Pool
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { AztecKVTxPoolV2 } from './tx_pool_v2.js';
|
|
182
|
+
|
|
183
|
+
const pool = new AztecKVTxPoolV2(txStore, archiveStore, {
|
|
184
|
+
l2BlockSource: archiver,
|
|
185
|
+
worldStateSynchronizer: worldState,
|
|
186
|
+
createTxValidator: () => validator,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
await pool.start();
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Adding Transactions
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// Add to pending pool (validates and runs pre-add rules)
|
|
196
|
+
const result = await pool.addPendingTxs(txs, { source: 'gossip' });
|
|
197
|
+
// result: { accepted: TxHash[], ignored: TxHash[], rejected: TxHash[] }
|
|
198
|
+
|
|
199
|
+
// Check without modifying pool
|
|
200
|
+
const canAdd = await pool.canAddPendingTx(tx);
|
|
201
|
+
// canAdd: 'accepted' | 'ignored' | 'rejected'
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Block Building Flow
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// 1. Proposer protects txs for their block
|
|
208
|
+
await pool.protectTxs(selectedTxHashes, blockHeader);
|
|
209
|
+
|
|
210
|
+
// 2. On successful mining
|
|
211
|
+
await pool.handleMinedBlock(minedTxHashes, blockHeader);
|
|
212
|
+
|
|
213
|
+
// 3. If slot passes without mining
|
|
214
|
+
await pool.prepareForSlot(nextSlotNumber);
|
|
215
|
+
|
|
216
|
+
// 4. On finalization
|
|
217
|
+
await pool.handleFinalizedBlock(finalizedBlockHeader);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Handling Reorgs
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// When blocks are pruned, un-mine affected transactions
|
|
224
|
+
await pool.handlePrunedBlocks(latestValidBlockId);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Configuration
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
await pool.updateConfig({
|
|
231
|
+
maxPendingTxCount: 10000, // 0 = unlimited
|
|
232
|
+
archivedTxLimit: 1000, // 0 = disabled
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Return Values
|
|
237
|
+
|
|
238
|
+
### AddTxsResult
|
|
239
|
+
|
|
240
|
+
When adding pending transactions, each tx is categorized:
|
|
241
|
+
|
|
242
|
+
| Status | Meaning |
|
|
243
|
+
|--------|---------|
|
|
244
|
+
| `accepted` | Successfully added to the pool |
|
|
245
|
+
| `ignored` | Valid but not added (duplicate, lost nullifier conflict, insufficient balance) |
|
|
246
|
+
| `rejected` | Failed validation (invalid proof, expired, etc.) |
|
|
247
|
+
|
|
248
|
+
## Archive
|
|
249
|
+
|
|
250
|
+
Finalized transactions can optionally be archived for historical queries:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
const archivedTx = await pool.getArchivedTxByHash(txHash);
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
The archive uses FIFO eviction when `archivedTxLimit` is reached.
|
|
257
|
+
|
|
258
|
+
## Testing
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Unit tests (177 tests)
|
|
262
|
+
yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts
|
|
263
|
+
|
|
264
|
+
# Deleted pool tests (17 tests)
|
|
265
|
+
yarn test src/mem_pools/tx_pool_v2/deleted_pool.test.ts
|
|
266
|
+
|
|
267
|
+
# Compatibility tests (25 tests)
|
|
268
|
+
yarn test src/mem_pools/tx_pool_v2/tx_pool_v2.compat.test.ts
|
|
269
|
+
|
|
270
|
+
# Eviction rule tests
|
|
271
|
+
yarn test src/mem_pools/tx_pool_v2/eviction/
|
|
272
|
+
|
|
273
|
+
# Benchmarks
|
|
274
|
+
yarn test src/mem_pools/tx_pool_v2/tx_pool_v2_bench.test.ts
|
|
275
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TxArchive } from './tx_archive.js';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
4
|
+
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Manages archived transactions with FIFO eviction.
|
|
8
|
+
* Archived transactions have their proofs stripped to save space.
|
|
9
|
+
*/
|
|
10
|
+
export class TxArchive {
|
|
11
|
+
#store: AztecAsyncKVStore;
|
|
12
|
+
#txs: AztecAsyncMap<string, Buffer>;
|
|
13
|
+
#indices: AztecAsyncMap<number, string>;
|
|
14
|
+
#limit: number;
|
|
15
|
+
#log: Logger;
|
|
16
|
+
|
|
17
|
+
constructor(store: AztecAsyncKVStore, limit: number, log?: Logger) {
|
|
18
|
+
this.#store = store;
|
|
19
|
+
this.#txs = store.openMap('archivedTxs');
|
|
20
|
+
this.#indices = store.openMap('archivedTxIndices');
|
|
21
|
+
this.#limit = limit;
|
|
22
|
+
this.#log = log ?? createLogger('p2p:tx_pool_v2:archive');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Updates the maximum number of archived transactions.
|
|
27
|
+
*/
|
|
28
|
+
updateLimit(limit: number): void {
|
|
29
|
+
this.#limit = limit;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets the current archive limit.
|
|
34
|
+
*/
|
|
35
|
+
getLimit(): number {
|
|
36
|
+
return this.#limit;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Checks if archiving is enabled.
|
|
41
|
+
*/
|
|
42
|
+
isEnabled(): boolean {
|
|
43
|
+
return this.#limit > 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Archives transactions, stripping their proofs.
|
|
48
|
+
* Evicts oldest transactions if the limit is exceeded.
|
|
49
|
+
*/
|
|
50
|
+
async archiveTxs(txs: Tx[]): Promise<void> {
|
|
51
|
+
if (!this.isEnabled() || txs.length === 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
await this.#store.transactionAsync(async () => {
|
|
57
|
+
// Get current head and tail indices
|
|
58
|
+
let headIdx = await this.getHeadIndex();
|
|
59
|
+
let tailIdx = await this.getTailIndex();
|
|
60
|
+
|
|
61
|
+
for (const tx of txs) {
|
|
62
|
+
// Evict oldest entries if at capacity
|
|
63
|
+
while (headIdx - tailIdx >= this.#limit) {
|
|
64
|
+
const txHashToEvict = await this.#indices.getAsync(tailIdx);
|
|
65
|
+
if (txHashToEvict) {
|
|
66
|
+
await this.#txs.delete(txHashToEvict);
|
|
67
|
+
await this.#indices.delete(tailIdx);
|
|
68
|
+
}
|
|
69
|
+
tailIdx++;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Archive the transaction with stripped proof
|
|
73
|
+
const archivedTx = this.stripProof(tx);
|
|
74
|
+
const txHash = tx.getTxHash().toString();
|
|
75
|
+
await this.#txs.set(txHash, archivedTx.toBuffer());
|
|
76
|
+
await this.#indices.set(headIdx, txHash);
|
|
77
|
+
headIdx++;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.#log.debug(`Archived ${txs.length} txs, total: ${headIdx - tailIdx}`);
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
this.#log.error('Error archiving transactions', { error });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves an archived transaction by its hash.
|
|
89
|
+
*/
|
|
90
|
+
async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
91
|
+
const buffer = await this.#txs.getAsync(txHash.toString());
|
|
92
|
+
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets the current count of archived transactions.
|
|
97
|
+
*/
|
|
98
|
+
async getCount(): Promise<number> {
|
|
99
|
+
const head = await this.getHeadIndex();
|
|
100
|
+
const tail = await this.getTailIndex();
|
|
101
|
+
return head - tail;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Strips the proof from a transaction for archival.
|
|
106
|
+
*/
|
|
107
|
+
private stripProof(tx: Tx): Tx {
|
|
108
|
+
return new Tx(tx.txHash, tx.data, ChonkProof.empty(), tx.contractClassLogFields, tx.publicFunctionCalldata);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async getHeadIndex(): Promise<number> {
|
|
112
|
+
const entry = await this.#indices.entriesAsync({ limit: 1, reverse: true }).next();
|
|
113
|
+
return (entry.value?.[0] ?? -1) + 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private async getTailIndex(): Promise<number> {
|
|
117
|
+
const entry = await this.#indices.entriesAsync({ limit: 1 }).next();
|
|
118
|
+
return entry.value?.[0] ?? 0;
|
|
119
|
+
}
|
|
120
|
+
}
|