@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f504929
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +8 -8
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +37 -13
- package/dest/client/interface.d.ts +39 -33
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +37 -50
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +138 -199
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
- package/dest/config.d.ts +29 -15
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +39 -35
- 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 +21 -12
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +72 -38
- 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 +53 -53
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -2
- package/dest/mem_pools/index.d.ts +2 -1
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +48 -5
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +14 -4
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +3 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +2 -1
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -8
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +56 -8
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +108 -10
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +36 -14
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +14 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +344 -184
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +10 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +166 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +25 -10
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +219 -58
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +25 -24
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/dummy_service.d.ts +9 -5
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +7 -4
- package/dest/services/encoding.d.ts +3 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +11 -10
- package/dest/services/gossipsub/topic_score_params.d.ts +18 -6
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +32 -10
- package/dest/services/libp2p/libp2p_service.d.ts +25 -14
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +143 -114
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +2 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +13 -5
- package/dest/services/service.d.ts +22 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +19 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +46 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +56 -36
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +90 -0
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +60 -26
- package/dest/services/tx_collection/tx_collection.d.ts +23 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +75 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +26 -29
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +9 -6
- package/dest/services/tx_provider.d.ts +4 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +9 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +30 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +105 -4
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +35 -24
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +93 -35
- package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +14 -14
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +71 -23
- package/src/client/interface.ts +43 -33
- package/src/client/p2p_client.ts +164 -243
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
- package/src/config.ts +60 -42
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +100 -48
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +57 -53
- package/src/mem_pools/attestation_pool/index.ts +3 -3
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/index.ts +3 -0
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool/README.md +1 -1
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/README.md +76 -10
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/index.ts +2 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +23 -8
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +153 -17
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +21 -7
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +388 -182
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +1 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +1 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +15 -1
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +144 -1
- 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/allowed_public_setup.ts +27 -13
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +353 -77
- package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +25 -29
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +12 -6
- package/src/services/encoding.ts +9 -9
- package/src/services/gossipsub/README.md +29 -14
- package/src/services/gossipsub/topic_score_params.ts +49 -13
- package/src/services/libp2p/libp2p_service.ts +153 -123
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
- package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +16 -4
- package/src/services/service.ts +31 -2
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +65 -32
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +1 -0
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
- package/src/services/tx_collection/slow_tx_collection.ts +66 -33
- package/src/services/tx_collection/tx_collection.ts +113 -16
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +10 -8
- package/src/services/tx_provider.ts +10 -9
- package/src/test-helpers/make-test-p2p-clients.ts +3 -5
- package/src/test-helpers/mock-pubsub.ts +146 -9
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/test-helpers/testbench-utils.ts +108 -40
- package/src/testbench/p2p_client_testbench_worker.ts +23 -20
- package/src/util.ts +7 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
4
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
5
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
6
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
@@ -8,8 +9,10 @@ import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
|
|
|
8
9
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
10
|
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
10
11
|
import { BlockHeader, Tx, TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
12
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
11
13
|
|
|
12
14
|
import { TxArchive } from './archive/index.js';
|
|
15
|
+
import { DeletedPool } from './deleted_pool.js';
|
|
13
16
|
import {
|
|
14
17
|
EvictionManager,
|
|
15
18
|
FeePayerBalanceEvictionRule,
|
|
@@ -20,8 +23,12 @@ import {
|
|
|
20
23
|
LowPriorityPreAddRule,
|
|
21
24
|
NullifierConflictRule,
|
|
22
25
|
type PoolOperations,
|
|
26
|
+
type PreAddContext,
|
|
23
27
|
type PreAddPoolAccess,
|
|
28
|
+
TxPoolRejectionCode,
|
|
29
|
+
type TxPoolRejectionError,
|
|
24
30
|
} from './eviction/index.js';
|
|
31
|
+
import { TxPoolV2Instrumentation } from './instrumentation.js';
|
|
25
32
|
import {
|
|
26
33
|
type AddTxsResult,
|
|
27
34
|
DEFAULT_TX_POOL_V2_CONFIG,
|
|
@@ -38,6 +45,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
38
45
|
export interface TxPoolV2Callbacks {
|
|
39
46
|
onTxsAdded: (txs: Tx[], opts: { source?: string }) => void;
|
|
40
47
|
onTxsRemoved: (txHashes: string[] | bigint[]) => void;
|
|
48
|
+
onTxsMined: (txHashes: string[]) => void;
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
/**
|
|
@@ -53,7 +61,7 @@ export class TxPoolV2Impl {
|
|
|
53
61
|
// === Dependencies ===
|
|
54
62
|
#l2BlockSource: L2BlockSource;
|
|
55
63
|
#worldStateSynchronizer: WorldStateSynchronizer;
|
|
56
|
-
#
|
|
64
|
+
#createTxValidator: TxPoolV2Dependencies['createTxValidator'];
|
|
57
65
|
|
|
58
66
|
// === In-Memory Indices ===
|
|
59
67
|
#indices: TxPoolIndices = new TxPoolIndices();
|
|
@@ -61,7 +69,11 @@ export class TxPoolV2Impl {
|
|
|
61
69
|
// === Config & Services ===
|
|
62
70
|
#config: TxPoolV2Config;
|
|
63
71
|
#archive: TxArchive;
|
|
72
|
+
#deletedPool: DeletedPool;
|
|
64
73
|
#evictionManager: EvictionManager;
|
|
74
|
+
#dateProvider: DateProvider;
|
|
75
|
+
#instrumentation: TxPoolV2Instrumentation;
|
|
76
|
+
#evictedTxHashes: Set<string> = new Set();
|
|
65
77
|
#log: Logger;
|
|
66
78
|
#callbacks: TxPoolV2Callbacks;
|
|
67
79
|
|
|
@@ -70,7 +82,9 @@ export class TxPoolV2Impl {
|
|
|
70
82
|
archiveStore: AztecAsyncKVStore,
|
|
71
83
|
deps: TxPoolV2Dependencies,
|
|
72
84
|
callbacks: TxPoolV2Callbacks,
|
|
85
|
+
telemetry: TelemetryClient,
|
|
73
86
|
config: Partial<TxPoolV2Config> = {},
|
|
87
|
+
dateProvider: DateProvider,
|
|
74
88
|
log: Logger,
|
|
75
89
|
) {
|
|
76
90
|
this.#store = store;
|
|
@@ -78,10 +92,13 @@ export class TxPoolV2Impl {
|
|
|
78
92
|
|
|
79
93
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
80
94
|
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
81
|
-
this.#
|
|
95
|
+
this.#createTxValidator = deps.createTxValidator;
|
|
82
96
|
|
|
83
97
|
this.#config = { ...DEFAULT_TX_POOL_V2_CONFIG, ...config };
|
|
84
98
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
99
|
+
this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
|
|
100
|
+
this.#dateProvider = dateProvider;
|
|
101
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, () => this.#indices.getTotalMetadataBytes());
|
|
85
102
|
this.#log = log;
|
|
86
103
|
this.#callbacks = callbacks;
|
|
87
104
|
|
|
@@ -116,7 +133,10 @@ export class TxPoolV2Impl {
|
|
|
116
133
|
* by running pre-add rules to resolve nullifier conflicts, balance checks, and pool size limits.
|
|
117
134
|
*/
|
|
118
135
|
async hydrateFromDatabase(): Promise<void> {
|
|
119
|
-
// Step
|
|
136
|
+
// Step 0: Hydrate deleted pool state
|
|
137
|
+
await this.#deletedPool.hydrateFromDatabase();
|
|
138
|
+
|
|
139
|
+
// Step 1: Load all transactions from DB (excluding soft-deleted)
|
|
120
140
|
const { loaded, errors: deserializationErrors } = await this.#loadAllTxsFromDb();
|
|
121
141
|
|
|
122
142
|
// Step 2: Check mined status for each tx
|
|
@@ -134,7 +154,10 @@ export class TxPoolV2Impl {
|
|
|
134
154
|
}
|
|
135
155
|
|
|
136
156
|
// Step 4: Validate non-mined transactions
|
|
137
|
-
const { valid, invalid } = await this.#
|
|
157
|
+
const { valid, invalid } = await this.#revalidateMetadata(
|
|
158
|
+
nonMined.map(e => e.meta),
|
|
159
|
+
'on startup',
|
|
160
|
+
);
|
|
138
161
|
|
|
139
162
|
// Step 5: Populate mined indices (these don't need conflict resolution)
|
|
140
163
|
for (const meta of mined) {
|
|
@@ -155,16 +178,43 @@ export class TxPoolV2Impl {
|
|
|
155
178
|
await this.#txsDB.delete(txHashStr);
|
|
156
179
|
}
|
|
157
180
|
});
|
|
158
|
-
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup
|
|
181
|
+
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`, { txHashes: toDelete });
|
|
159
182
|
}
|
|
160
183
|
|
|
161
|
-
async addPendingTxs(txs: Tx[], opts: { source?: string }): Promise<AddTxsResult> {
|
|
184
|
+
async addPendingTxs(txs: Tx[], opts: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult> {
|
|
162
185
|
const accepted: TxHash[] = [];
|
|
163
186
|
const ignored: TxHash[] = [];
|
|
164
187
|
const rejected: TxHash[] = [];
|
|
188
|
+
const errors = new Map<string, TxPoolRejectionError>();
|
|
165
189
|
const acceptedPending = new Set<string>();
|
|
166
190
|
|
|
191
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
192
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
193
|
+
const precomputed = new Map<string, { meta: TxMetaData; minedBlockId: L2BlockId | undefined; isValid: boolean }>();
|
|
194
|
+
|
|
195
|
+
const validator = await this.#createTxValidator();
|
|
196
|
+
|
|
197
|
+
for (const tx of txs) {
|
|
198
|
+
const txHash = tx.getTxHash();
|
|
199
|
+
const txHashStr = txHash.toString();
|
|
200
|
+
|
|
201
|
+
const meta = await buildTxMetaData(tx);
|
|
202
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
203
|
+
|
|
204
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
205
|
+
let isValid = true;
|
|
206
|
+
if (!minedBlockId) {
|
|
207
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
precomputed.set(txHashStr, { meta, minedBlockId, isValid });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
214
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
167
215
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
216
|
+
const preAddContext: PreAddContext | undefined =
|
|
217
|
+
opts.feeComparisonOnly !== undefined ? { feeComparisonOnly: opts.feeComparisonOnly } : undefined;
|
|
168
218
|
|
|
169
219
|
await this.#store.transactionAsync(async () => {
|
|
170
220
|
for (const tx of txs) {
|
|
@@ -177,30 +227,46 @@ export class TxPoolV2Impl {
|
|
|
177
227
|
continue;
|
|
178
228
|
}
|
|
179
229
|
|
|
180
|
-
|
|
181
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
230
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr)!;
|
|
182
231
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
183
232
|
|
|
184
233
|
if (minedBlockId) {
|
|
185
234
|
// Already mined - add directly (protection already set if pre-protected)
|
|
186
|
-
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
235
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
|
|
187
236
|
accepted.push(txHash);
|
|
188
237
|
} else if (preProtectedSlot !== undefined) {
|
|
189
238
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
190
|
-
await this.#addTx(tx, { protected: preProtectedSlot }, opts);
|
|
239
|
+
await this.#addTx(tx, { protected: preProtectedSlot }, opts, meta);
|
|
191
240
|
accepted.push(txHash);
|
|
241
|
+
} else if (!isValid) {
|
|
242
|
+
// Failed pre-computed validation
|
|
243
|
+
rejected.push(txHash);
|
|
192
244
|
} else {
|
|
193
|
-
// Regular pending tx -
|
|
194
|
-
const result = await this.#tryAddRegularPendingTx(
|
|
245
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
246
|
+
const result = await this.#tryAddRegularPendingTx(
|
|
247
|
+
tx,
|
|
248
|
+
meta,
|
|
249
|
+
opts,
|
|
250
|
+
poolAccess,
|
|
251
|
+
acceptedPending,
|
|
252
|
+
ignored,
|
|
253
|
+
errors,
|
|
254
|
+
preAddContext,
|
|
255
|
+
);
|
|
195
256
|
if (result.status === 'accepted') {
|
|
196
257
|
acceptedPending.add(txHashStr);
|
|
197
|
-
} else if (result.status === 'rejected') {
|
|
198
|
-
rejected.push(txHash);
|
|
199
258
|
} else {
|
|
200
259
|
ignored.push(txHash);
|
|
201
260
|
}
|
|
202
261
|
}
|
|
203
262
|
}
|
|
263
|
+
|
|
264
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
265
|
+
if (acceptedPending.size > 0) {
|
|
266
|
+
const feePayers = Array.from(acceptedPending).map(txHash => this.#indices.getMetadata(txHash)!.feePayer);
|
|
267
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
268
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [...uniqueFeePayers]);
|
|
269
|
+
}
|
|
204
270
|
});
|
|
205
271
|
|
|
206
272
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
@@ -208,58 +274,80 @@ export class TxPoolV2Impl {
|
|
|
208
274
|
accepted.push(TxHash.fromString(txHashStr));
|
|
209
275
|
}
|
|
210
276
|
|
|
211
|
-
//
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
277
|
+
// Record metrics
|
|
278
|
+
if (ignored.length > 0) {
|
|
279
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
280
|
+
}
|
|
281
|
+
if (rejected.length > 0) {
|
|
282
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
216
283
|
}
|
|
217
284
|
|
|
218
|
-
return { accepted, ignored, rejected };
|
|
285
|
+
return { accepted, ignored, rejected, ...(errors.size > 0 ? { errors } : {}) };
|
|
219
286
|
}
|
|
220
287
|
|
|
221
|
-
/**
|
|
288
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */
|
|
222
289
|
async #tryAddRegularPendingTx(
|
|
223
290
|
tx: Tx,
|
|
291
|
+
precomputedMeta: TxMetaData,
|
|
224
292
|
opts: { source?: string },
|
|
225
293
|
poolAccess: PreAddPoolAccess,
|
|
226
294
|
acceptedPending: Set<string>,
|
|
227
295
|
ignored: TxHash[],
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// Validate transaction
|
|
233
|
-
if (!(await this.#validateTx(tx))) {
|
|
234
|
-
return { status: 'rejected' };
|
|
235
|
-
}
|
|
296
|
+
errors: Map<string, TxPoolRejectionError>,
|
|
297
|
+
preAddContext?: PreAddContext,
|
|
298
|
+
): Promise<{ status: 'accepted' | 'ignored' }> {
|
|
299
|
+
const txHashStr = tx.getTxHash().toString();
|
|
236
300
|
|
|
237
|
-
//
|
|
238
|
-
const
|
|
239
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
301
|
+
// Run pre-add rules
|
|
302
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
240
303
|
|
|
241
304
|
if (preAddResult.shouldIgnore) {
|
|
242
|
-
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
|
|
305
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
306
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
307
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
308
|
+
}
|
|
243
309
|
return { status: 'ignored' };
|
|
244
310
|
}
|
|
245
311
|
|
|
246
|
-
// Evict conflicts
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
312
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
313
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
314
|
+
const byReason = new Map<string, string[]>();
|
|
315
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions) {
|
|
316
|
+
const group = byReason.get(reason);
|
|
317
|
+
if (group) {
|
|
318
|
+
group.push(evictHash);
|
|
319
|
+
} else {
|
|
320
|
+
byReason.set(reason, [evictHash]);
|
|
321
|
+
}
|
|
254
322
|
}
|
|
323
|
+
for (const [reason, hashes] of byReason) {
|
|
324
|
+
await this.#evictTxs(hashes, reason);
|
|
325
|
+
}
|
|
326
|
+
for (const evictHashStr of preAddResult.txHashesToEvict) {
|
|
327
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
328
|
+
evictedTxHash: evictHashStr,
|
|
329
|
+
replacementTxHash: txHashStr,
|
|
330
|
+
});
|
|
331
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
332
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
333
|
+
acceptedPending.delete(evictHashStr);
|
|
334
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
340
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
341
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
342
|
+
return { status: 'accepted' };
|
|
255
343
|
}
|
|
256
344
|
|
|
257
345
|
// Add the transaction
|
|
258
|
-
await this.#addTx(tx, 'pending', opts);
|
|
346
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
259
347
|
return { status: 'accepted' };
|
|
260
348
|
}
|
|
261
349
|
|
|
262
|
-
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'
|
|
350
|
+
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'> {
|
|
263
351
|
const txHashStr = tx.getTxHash().toString();
|
|
264
352
|
|
|
265
353
|
// Check if already in pool
|
|
@@ -267,13 +355,7 @@ export class TxPoolV2Impl {
|
|
|
267
355
|
return 'ignored';
|
|
268
356
|
}
|
|
269
357
|
|
|
270
|
-
//
|
|
271
|
-
const validationResult = await this.#pendingTxValidator.validateTx(tx);
|
|
272
|
-
if (validationResult.result !== 'valid') {
|
|
273
|
-
return 'rejected';
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Build metadata and use pre-add rules
|
|
358
|
+
// Build metadata and check pre-add rules
|
|
277
359
|
const meta = await buildTxMetaData(tx);
|
|
278
360
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
279
361
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
@@ -311,22 +393,57 @@ export class TxPoolV2Impl {
|
|
|
311
393
|
});
|
|
312
394
|
}
|
|
313
395
|
|
|
314
|
-
protectTxs(txHashes: TxHash[], block: BlockHeader): TxHash[] {
|
|
396
|
+
async protectTxs(txHashes: TxHash[], block: BlockHeader): Promise<TxHash[]> {
|
|
315
397
|
const slotNumber = block.globalVariables.slotNumber;
|
|
316
398
|
const missing: TxHash[] = [];
|
|
399
|
+
let softDeletedHits = 0;
|
|
400
|
+
let missingPreviouslyEvicted = 0;
|
|
317
401
|
|
|
318
|
-
|
|
319
|
-
const
|
|
402
|
+
await this.#store.transactionAsync(async () => {
|
|
403
|
+
for (const txHash of txHashes) {
|
|
404
|
+
const txHashStr = txHash.toString();
|
|
320
405
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
406
|
+
if (this.#indices.has(txHashStr)) {
|
|
407
|
+
// Update protection for existing tx
|
|
408
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
409
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
410
|
+
// Resurrect soft-deleted tx as protected
|
|
411
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
412
|
+
if (buffer) {
|
|
413
|
+
const tx = Tx.fromBuffer(buffer);
|
|
414
|
+
await this.#addTx(tx, { protected: slotNumber });
|
|
415
|
+
softDeletedHits++;
|
|
416
|
+
} else {
|
|
417
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
418
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
419
|
+
missing.push(txHash);
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
423
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
424
|
+
missing.push(txHash);
|
|
425
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
426
|
+
missingPreviouslyEvicted++;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
328
429
|
}
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// Record metrics
|
|
433
|
+
if (softDeletedHits > 0) {
|
|
434
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
329
435
|
}
|
|
436
|
+
if (missing.length > 0) {
|
|
437
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map(h => h.toString()).join(', ')}`);
|
|
438
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
439
|
+
}
|
|
440
|
+
if (missingPreviouslyEvicted > 0) {
|
|
441
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
this.#log.info(
|
|
445
|
+
`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`,
|
|
446
|
+
);
|
|
330
447
|
|
|
331
448
|
return missing;
|
|
332
449
|
}
|
|
@@ -347,6 +464,7 @@ export class TxPoolV2Impl {
|
|
|
347
464
|
// Add new mined tx (callback emitted by #addTx)
|
|
348
465
|
await this.#addTx(tx, { mined: blockId }, opts);
|
|
349
466
|
}
|
|
467
|
+
await this.#deletedPool.clearIfMinedHigher(txHashStr, blockId.number);
|
|
350
468
|
}
|
|
351
469
|
});
|
|
352
470
|
}
|
|
@@ -370,53 +488,67 @@ export class TxPoolV2Impl {
|
|
|
370
488
|
}
|
|
371
489
|
}
|
|
372
490
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
491
|
+
await this.#store.transactionAsync(async () => {
|
|
492
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
493
|
+
for (const meta of found) {
|
|
494
|
+
this.#indices.markAsMined(meta, blockId);
|
|
495
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
499
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
500
|
+
});
|
|
377
501
|
|
|
378
|
-
|
|
379
|
-
|
|
502
|
+
if (found.length > 0) {
|
|
503
|
+
this.#callbacks.onTxsMined(found.map(m => m.txHash));
|
|
504
|
+
}
|
|
380
505
|
|
|
381
506
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
382
507
|
}
|
|
383
508
|
|
|
384
509
|
async prepareForSlot(slotNumber: SlotNumber): Promise<void> {
|
|
385
|
-
|
|
386
|
-
|
|
510
|
+
await this.#store.transactionAsync(async () => {
|
|
511
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
512
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
387
513
|
|
|
388
|
-
|
|
389
|
-
|
|
514
|
+
// Step 1: Find expired protected txs
|
|
515
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
390
516
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
if (txsToRestore.length === 0) {
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
517
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
518
|
+
this.#indices.clearProtection(expiredProtected);
|
|
396
519
|
|
|
397
|
-
|
|
520
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
521
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
522
|
+
if (txsToRestore.length === 0) {
|
|
523
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
398
526
|
|
|
399
|
-
|
|
400
|
-
const { valid, invalid } = await this.#loadAndValidateTxs(txsToRestore, 'during prepareForSlot');
|
|
527
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
401
528
|
|
|
402
|
-
|
|
403
|
-
|
|
529
|
+
// Step 4: Validate for pending pool
|
|
530
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
404
531
|
|
|
405
|
-
|
|
406
|
-
|
|
532
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
533
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
407
534
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
535
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
536
|
+
await this.#deleteTxsBatch(invalid);
|
|
537
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
538
|
+
|
|
539
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
540
|
+
if (added.length > 0) {
|
|
541
|
+
const feePayers = added.map(meta => meta.feePayer);
|
|
542
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
543
|
+
await this.#evictionManager.evictAfterNewTxs(
|
|
544
|
+
added.map(m => m.txHash),
|
|
545
|
+
[...uniqueFeePayers],
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
});
|
|
417
549
|
}
|
|
418
550
|
|
|
419
|
-
async handlePrunedBlocks(latestBlock: L2BlockId): Promise<void> {
|
|
551
|
+
async handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void> {
|
|
420
552
|
// Step 1: Find transactions mined after the prune point
|
|
421
553
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
422
554
|
if (txsToUnmine.length === 0) {
|
|
@@ -426,64 +558,99 @@ export class TxPoolV2Impl {
|
|
|
426
558
|
|
|
427
559
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
428
560
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
561
|
+
await this.#store.transactionAsync(async () => {
|
|
562
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
563
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
564
|
+
// when their original mined block is finalized
|
|
565
|
+
await this.#deletedPool.markFromPrunedBlock(
|
|
566
|
+
txsToUnmine.map(m => ({
|
|
567
|
+
txHash: m.txHash,
|
|
568
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId!.number),
|
|
569
|
+
})),
|
|
570
|
+
);
|
|
433
571
|
|
|
434
|
-
|
|
435
|
-
|
|
572
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
573
|
+
for (const meta of txsToUnmine) {
|
|
574
|
+
this.#indices.markAsUnmined(meta);
|
|
575
|
+
}
|
|
436
576
|
|
|
437
|
-
|
|
438
|
-
|
|
577
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
578
|
+
if (options?.deleteAllTxs) {
|
|
579
|
+
const allTxHashes = txsToUnmine.map(m => m.txHash);
|
|
580
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
581
|
+
this.#log.info(
|
|
582
|
+
`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`,
|
|
583
|
+
);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
588
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
439
589
|
|
|
440
|
-
|
|
441
|
-
|
|
590
|
+
// Step 5: Validate for pending pool
|
|
591
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
442
592
|
|
|
443
|
-
|
|
444
|
-
|
|
593
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
594
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
445
595
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
596
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
597
|
+
await this.#deleteTxsBatch(invalid);
|
|
598
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
599
|
+
|
|
600
|
+
this.#log.info(
|
|
601
|
+
`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`,
|
|
602
|
+
{ txHashesRestored: valid.map(m => m.txHash), txHashesInvalid: invalid, txHashesEvicted: toEvict },
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
606
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
607
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
608
|
+
});
|
|
449
609
|
}
|
|
450
610
|
|
|
451
611
|
async handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
452
|
-
|
|
453
|
-
|
|
612
|
+
await this.#store.transactionAsync(async () => {
|
|
613
|
+
await this.#deleteTxsBatch(txHashes.map(h => h.toString()));
|
|
614
|
+
});
|
|
454
615
|
|
|
455
|
-
this.#log.info(`Deleted ${txHashes.length} failed txs
|
|
616
|
+
this.#log.info(`Deleted ${txHashes.length} failed txs`, { txHashes: txHashes.map(h => h.toString()) });
|
|
456
617
|
}
|
|
457
618
|
|
|
458
619
|
async handleFinalizedBlock(block: BlockHeader): Promise<void> {
|
|
459
620
|
const blockNumber = block.globalVariables.blockNumber;
|
|
460
621
|
|
|
461
|
-
// Step 1: Find txs
|
|
462
|
-
const
|
|
463
|
-
if (txsToFinalize.length === 0) {
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
622
|
+
// Step 1: Find mined txs at or before finalized block
|
|
623
|
+
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
466
624
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
625
|
+
await this.#store.transactionAsync(async () => {
|
|
626
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
627
|
+
const txsToArchive: Tx[] = [];
|
|
628
|
+
if (this.#archive.isEnabled()) {
|
|
629
|
+
for (const txHashStr of minedTxsToFinalize) {
|
|
630
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
631
|
+
if (buffer) {
|
|
632
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
633
|
+
}
|
|
474
634
|
}
|
|
475
635
|
}
|
|
476
|
-
}
|
|
477
636
|
|
|
478
|
-
|
|
479
|
-
|
|
637
|
+
// Step 3: Delete mined txs from active pool
|
|
638
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
480
639
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
640
|
+
// Step 4: Finalize soft-deleted txs
|
|
641
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
642
|
+
|
|
643
|
+
// Step 5: Archive mined txs
|
|
644
|
+
if (txsToArchive.length > 0) {
|
|
645
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
646
|
+
}
|
|
647
|
+
});
|
|
485
648
|
|
|
486
|
-
|
|
649
|
+
if (minedTxsToFinalize.length > 0) {
|
|
650
|
+
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
651
|
+
txHashes: minedTxsToFinalize,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
487
654
|
}
|
|
488
655
|
|
|
489
656
|
// === Query Methods ===
|
|
@@ -503,21 +670,36 @@ export class TxPoolV2Impl {
|
|
|
503
670
|
}
|
|
504
671
|
|
|
505
672
|
hasTxs(txHashes: TxHash[]): boolean[] {
|
|
506
|
-
return txHashes.map(h =>
|
|
673
|
+
return txHashes.map(h => {
|
|
674
|
+
const hashStr = h.toString();
|
|
675
|
+
return this.#indices.has(hashStr) || this.#deletedPool.isSoftDeleted(hashStr);
|
|
676
|
+
});
|
|
507
677
|
}
|
|
508
678
|
|
|
509
679
|
getTxStatus(txHash: TxHash): TxState | undefined {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
680
|
+
const txHashStr = txHash.toString();
|
|
681
|
+
const meta = this.#indices.getMetadata(txHashStr);
|
|
682
|
+
if (meta) {
|
|
683
|
+
return this.#indices.getTxState(meta);
|
|
513
684
|
}
|
|
514
|
-
|
|
685
|
+
// Check if soft-deleted
|
|
686
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
687
|
+
return 'deleted';
|
|
688
|
+
}
|
|
689
|
+
return undefined;
|
|
515
690
|
}
|
|
516
691
|
|
|
517
692
|
getPendingTxHashes(): TxHash[] {
|
|
518
693
|
return [...this.#indices.iteratePendingByPriority('desc')].map(hash => TxHash.fromString(hash));
|
|
519
694
|
}
|
|
520
695
|
|
|
696
|
+
getEligiblePendingTxHashes(): TxHash[] {
|
|
697
|
+
const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
|
|
698
|
+
return [...this.#indices.iterateEligiblePendingByPriority('desc', maxReceivedAt)].map(hash =>
|
|
699
|
+
TxHash.fromString(hash),
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
|
|
521
703
|
getPendingTxCount(): number {
|
|
522
704
|
return this.#indices.getPendingTxCount();
|
|
523
705
|
}
|
|
@@ -562,6 +744,9 @@ export class TxPoolV2Impl {
|
|
|
562
744
|
this.#config.archivedTxLimit = config.archivedTxLimit;
|
|
563
745
|
this.#archive.updateLimit(config.archivedTxLimit);
|
|
564
746
|
}
|
|
747
|
+
if (config.minTxPoolAgeMs !== undefined) {
|
|
748
|
+
this.#config.minTxPoolAgeMs = config.minTxPoolAgeMs;
|
|
749
|
+
}
|
|
565
750
|
// Update eviction rules with new config
|
|
566
751
|
this.#evictionManager.updateConfig(config);
|
|
567
752
|
}
|
|
@@ -579,8 +764,17 @@ export class TxPoolV2Impl {
|
|
|
579
764
|
|
|
580
765
|
// === Metrics ===
|
|
581
766
|
|
|
582
|
-
countTxs(): {
|
|
583
|
-
|
|
767
|
+
countTxs(): {
|
|
768
|
+
pending: number;
|
|
769
|
+
protected: number;
|
|
770
|
+
mined: number;
|
|
771
|
+
softDeleted: number;
|
|
772
|
+
totalMetadataBytes: number;
|
|
773
|
+
} {
|
|
774
|
+
return {
|
|
775
|
+
...this.#indices.countTxs(),
|
|
776
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount(),
|
|
777
|
+
};
|
|
584
778
|
}
|
|
585
779
|
|
|
586
780
|
// ============================================================================
|
|
@@ -595,11 +789,14 @@ export class TxPoolV2Impl {
|
|
|
595
789
|
tx: Tx,
|
|
596
790
|
state: 'pending' | { protected: SlotNumber } | { mined: L2BlockId },
|
|
597
791
|
opts: { source?: string } = {},
|
|
792
|
+
precomputedMeta?: TxMetaData,
|
|
598
793
|
): Promise<TxMetaData> {
|
|
599
794
|
const txHashStr = tx.getTxHash().toString();
|
|
600
|
-
const meta = await buildTxMetaData(tx);
|
|
795
|
+
const meta = precomputedMeta ?? (await buildTxMetaData(tx));
|
|
796
|
+
meta.receivedAt = this.#dateProvider.now();
|
|
601
797
|
|
|
602
798
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
799
|
+
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
603
800
|
this.#callbacks.onTxsAdded([tx], opts);
|
|
604
801
|
|
|
605
802
|
if (state === 'pending') {
|
|
@@ -612,9 +809,11 @@ export class TxPoolV2Impl {
|
|
|
612
809
|
}
|
|
613
810
|
|
|
614
811
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
615
|
-
this.#log.
|
|
812
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
616
813
|
eventName: 'tx-added-to-pool',
|
|
814
|
+
txHash: txHashStr,
|
|
617
815
|
state: stateStr,
|
|
816
|
+
source: opts.source,
|
|
618
817
|
});
|
|
619
818
|
|
|
620
819
|
return meta;
|
|
@@ -624,10 +823,15 @@ export class TxPoolV2Impl {
|
|
|
624
823
|
* Deletes a transaction from both indices and DB.
|
|
625
824
|
* Emits onTxsRemoved callback immediately after DB delete.
|
|
626
825
|
*/
|
|
826
|
+
/**
|
|
827
|
+
* Deletes a transaction from the pool.
|
|
828
|
+
* Delegates to DeletedPool which decides soft vs hard delete based on whether
|
|
829
|
+
* the tx is from a pruned block.
|
|
830
|
+
*/
|
|
627
831
|
async #deleteTx(txHashStr: string): Promise<void> {
|
|
628
832
|
this.#indices.remove(txHashStr);
|
|
629
|
-
await this.#txsDB.delete(txHashStr);
|
|
630
833
|
this.#callbacks.onTxsRemoved([txHashStr]);
|
|
834
|
+
await this.#deletedPool.deleteTx(txHashStr);
|
|
631
835
|
}
|
|
632
836
|
|
|
633
837
|
/** Deletes a batch of transactions, emitting callbacks individually for each. */
|
|
@@ -637,68 +841,63 @@ export class TxPoolV2Impl {
|
|
|
637
841
|
}
|
|
638
842
|
}
|
|
639
843
|
|
|
844
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */
|
|
845
|
+
async #evictTxs(txHashes: string[], reason: string): Promise<void> {
|
|
846
|
+
if (txHashes.length === 0) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
850
|
+
for (const txHashStr of txHashes) {
|
|
851
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, { txHash: txHashStr, reason });
|
|
852
|
+
this.#addToEvictedCache(txHashStr);
|
|
853
|
+
}
|
|
854
|
+
await this.#deleteTxsBatch(txHashes);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */
|
|
858
|
+
#addToEvictedCache(txHashStr: string): void {
|
|
859
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
860
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
861
|
+
const oldest = this.#evictedTxHashes.values().next().value!;
|
|
862
|
+
this.#evictedTxHashes.delete(oldest);
|
|
863
|
+
}
|
|
864
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
865
|
+
}
|
|
866
|
+
|
|
640
867
|
// ============================================================================
|
|
641
868
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
642
869
|
// ============================================================================
|
|
643
870
|
|
|
644
|
-
/** Validates
|
|
645
|
-
async #
|
|
646
|
-
const
|
|
871
|
+
/** Validates transaction metadata, returning true if valid */
|
|
872
|
+
async #validateMeta(meta: TxMetaData, validator?: TxValidator<TxMetaData>, context?: string): Promise<boolean> {
|
|
873
|
+
const txValidator = validator ?? (await this.#createTxValidator());
|
|
874
|
+
const result = await txValidator.validateTx(meta);
|
|
647
875
|
if (result.result !== 'valid') {
|
|
648
876
|
const contextStr = context ? ` ${context}` : '';
|
|
649
|
-
this.#log.info(`Tx ${
|
|
877
|
+
this.#log.info(`Tx ${meta.txHash}${contextStr} failed validation: ${result.reason?.join(', ')}`);
|
|
650
878
|
return false;
|
|
651
879
|
}
|
|
652
880
|
return true;
|
|
653
881
|
}
|
|
654
882
|
|
|
655
|
-
/**
|
|
656
|
-
async #
|
|
657
|
-
|
|
658
|
-
const missing: string[] = [];
|
|
659
|
-
|
|
660
|
-
for (const meta of metas) {
|
|
661
|
-
const buffer = await this.#txsDB.getAsync(meta.txHash);
|
|
662
|
-
if (!buffer) {
|
|
663
|
-
this.#log.warn(`Tx ${meta.txHash} not found in DB`);
|
|
664
|
-
missing.push(meta.txHash);
|
|
665
|
-
continue;
|
|
666
|
-
}
|
|
667
|
-
loaded.push({ tx: Tx.fromBuffer(buffer), meta });
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
return { loaded, missing };
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/** Validates a batch of transactions, returning valid and invalid groups */
|
|
674
|
-
async #validateTxBatch(
|
|
675
|
-
txs: { tx: Tx; meta: TxMetaData }[],
|
|
883
|
+
/** Validates metadata directly */
|
|
884
|
+
async #revalidateMetadata(
|
|
885
|
+
metas: TxMetaData[],
|
|
676
886
|
context?: string,
|
|
677
887
|
): Promise<{ valid: TxMetaData[]; invalid: string[] }> {
|
|
678
888
|
const valid: TxMetaData[] = [];
|
|
679
889
|
const invalid: string[] = [];
|
|
680
|
-
|
|
681
|
-
for (const
|
|
682
|
-
if (await this.#
|
|
890
|
+
const validator = await this.#createTxValidator();
|
|
891
|
+
for (const meta of metas) {
|
|
892
|
+
if (await this.#validateMeta(meta, validator, context)) {
|
|
683
893
|
valid.push(meta);
|
|
684
894
|
} else {
|
|
685
895
|
invalid.push(meta.txHash);
|
|
686
896
|
}
|
|
687
897
|
}
|
|
688
|
-
|
|
689
898
|
return { valid, invalid };
|
|
690
899
|
}
|
|
691
900
|
|
|
692
|
-
/** Loads transactions from DB and validates them */
|
|
693
|
-
async #loadAndValidateTxs(
|
|
694
|
-
metas: TxMetaData[],
|
|
695
|
-
context?: string,
|
|
696
|
-
): Promise<{ valid: TxMetaData[]; invalid: string[] }> {
|
|
697
|
-
const { loaded, missing } = await this.#loadTxsFromDb(metas);
|
|
698
|
-
const { valid, invalid } = await this.#validateTxBatch(loaded, context);
|
|
699
|
-
return { valid, invalid: [...missing, ...invalid] };
|
|
700
|
-
}
|
|
701
|
-
|
|
702
901
|
/**
|
|
703
902
|
* Resolves nullifier conflicts between incoming txs and existing pending txs.
|
|
704
903
|
* Modifies the pending indices during iteration to maintain consistent state
|
|
@@ -768,6 +967,11 @@ export class TxPoolV2Impl {
|
|
|
768
967
|
const errors: string[] = [];
|
|
769
968
|
|
|
770
969
|
for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()) {
|
|
970
|
+
// Skip soft-deleted transactions - they stay in DB but not in indices
|
|
971
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
|
|
771
975
|
try {
|
|
772
976
|
const tx = Tx.fromBuffer(buffer);
|
|
773
977
|
const meta = await buildTxMetaData(tx);
|
|
@@ -815,7 +1019,9 @@ export class TxPoolV2Impl {
|
|
|
815
1019
|
if (preAddResult.shouldIgnore) {
|
|
816
1020
|
// Transaction rejected - mark for deletion from DB
|
|
817
1021
|
rejected.push(meta.txHash);
|
|
818
|
-
this.#log.debug(
|
|
1022
|
+
this.#log.debug(
|
|
1023
|
+
`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`,
|
|
1024
|
+
);
|
|
819
1025
|
continue;
|
|
820
1026
|
}
|
|
821
1027
|
|
|
@@ -851,7 +1057,7 @@ export class TxPoolV2Impl {
|
|
|
851
1057
|
getFeePayerPendingTxs: (feePayer: string) => this.#indices.getFeePayerPendingTxs(feePayer),
|
|
852
1058
|
getPendingTxCount: () => this.#indices.getPendingTxCount(),
|
|
853
1059
|
getLowestPriorityPending: (limit: number) => this.#indices.getLowestPriorityPending(limit),
|
|
854
|
-
deleteTxs: (txHashes: string[]) => this.#
|
|
1060
|
+
deleteTxs: (txHashes: string[], reason?: string) => this.#evictTxs(txHashes, reason ?? 'unknown'),
|
|
855
1061
|
};
|
|
856
1062
|
}
|
|
857
1063
|
|