@aztec/p2p 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c
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 +53 -14
- package/dest/client/interface.d.ts +58 -25
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +46 -51
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +601 -259
- 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 +35 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -9
- 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 +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +5 -14
- 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 +15 -10
- 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 +91 -50
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -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 +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.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/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- 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_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 +97 -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 +152 -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 +896 -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 +3 -3
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- 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 +8 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +21 -11
- 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 +3 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
- 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/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/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 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +51 -0
- 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 +106 -33
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +984 -317
- package/dest/services/peer-manager/metrics.d.ts +2 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +21 -26
- 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 +0 -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 +562 -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 +54 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/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 +55 -3
- 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 +5 -5
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +5 -4
- 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 -127
- 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 +96 -24
- package/src/client/interface.ts +76 -25
- package/src/client/p2p_client.ts +269 -290
- 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 +49 -13
- 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 +10 -18
- package/src/mem_pools/interface.ts +4 -4
- package/src/mem_pools/tx_pool/README.md +29 -14
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
- 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 +3 -3
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- 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 +242 -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 +1069 -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/aggregate_tx_validator.ts +2 -2
- 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 +64 -23
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +18 -7
- 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 +68 -1
- 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 +651 -301
- package/src/services/peer-manager/metrics.ts +22 -26
- package/src/services/peer-manager/peer_manager.ts +1 -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 +706 -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 +205 -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 +72 -4
- 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 +10 -9
- 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 -123
- 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/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
- 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/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
- 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,1069 @@
|
|
|
1
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
5
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
6
|
+
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
7
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
+
import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
|
|
9
|
+
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
10
|
+
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
11
|
+
import { BlockHeader, Tx, TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
12
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
13
|
+
|
|
14
|
+
import { TxArchive } from './archive/index.js';
|
|
15
|
+
import { DeletedPool } from './deleted_pool.js';
|
|
16
|
+
import {
|
|
17
|
+
EvictionManager,
|
|
18
|
+
FeePayerBalanceEvictionRule,
|
|
19
|
+
FeePayerBalancePreAddRule,
|
|
20
|
+
InvalidTxsAfterMiningRule,
|
|
21
|
+
InvalidTxsAfterReorgRule,
|
|
22
|
+
LowPriorityEvictionRule,
|
|
23
|
+
LowPriorityPreAddRule,
|
|
24
|
+
NullifierConflictRule,
|
|
25
|
+
type PoolOperations,
|
|
26
|
+
type PreAddContext,
|
|
27
|
+
type PreAddPoolAccess,
|
|
28
|
+
TxPoolRejectionCode,
|
|
29
|
+
type TxPoolRejectionError,
|
|
30
|
+
} from './eviction/index.js';
|
|
31
|
+
import { TxPoolV2Instrumentation } from './instrumentation.js';
|
|
32
|
+
import {
|
|
33
|
+
type AddTxsResult,
|
|
34
|
+
DEFAULT_TX_POOL_V2_CONFIG,
|
|
35
|
+
type PoolReadAccess,
|
|
36
|
+
type TxPoolV2Config,
|
|
37
|
+
type TxPoolV2Dependencies,
|
|
38
|
+
} from './interfaces.js';
|
|
39
|
+
import { type TxMetaData, type TxState, buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
|
|
40
|
+
import { TxPoolIndices } from './tx_pool_indices.js';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Callbacks for the implementation to notify the outer class about events and metrics.
|
|
44
|
+
*/
|
|
45
|
+
export interface TxPoolV2Callbacks {
|
|
46
|
+
onTxsAdded: (txs: Tx[], opts: { source?: string }) => void;
|
|
47
|
+
onTxsRemoved: (txHashes: string[] | bigint[]) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Implementation of TxPoolV2 logic.
|
|
52
|
+
*
|
|
53
|
+
* This class contains all the actual transaction pool logic.
|
|
54
|
+
*/
|
|
55
|
+
export class TxPoolV2Impl {
|
|
56
|
+
// === Persistence ===
|
|
57
|
+
#store: AztecAsyncKVStore;
|
|
58
|
+
#txsDB: AztecAsyncMap<string, Buffer>;
|
|
59
|
+
|
|
60
|
+
// === Dependencies ===
|
|
61
|
+
#l2BlockSource: L2BlockSource;
|
|
62
|
+
#worldStateSynchronizer: WorldStateSynchronizer;
|
|
63
|
+
#createTxValidator: TxPoolV2Dependencies['createTxValidator'];
|
|
64
|
+
|
|
65
|
+
// === In-Memory Indices ===
|
|
66
|
+
#indices: TxPoolIndices = new TxPoolIndices();
|
|
67
|
+
|
|
68
|
+
// === Config & Services ===
|
|
69
|
+
#config: TxPoolV2Config;
|
|
70
|
+
#archive: TxArchive;
|
|
71
|
+
#deletedPool: DeletedPool;
|
|
72
|
+
#evictionManager: EvictionManager;
|
|
73
|
+
#dateProvider: DateProvider;
|
|
74
|
+
#instrumentation: TxPoolV2Instrumentation;
|
|
75
|
+
#evictedTxHashes: Set<string> = new Set();
|
|
76
|
+
#log: Logger;
|
|
77
|
+
#callbacks: TxPoolV2Callbacks;
|
|
78
|
+
|
|
79
|
+
constructor(
|
|
80
|
+
store: AztecAsyncKVStore,
|
|
81
|
+
archiveStore: AztecAsyncKVStore,
|
|
82
|
+
deps: TxPoolV2Dependencies,
|
|
83
|
+
callbacks: TxPoolV2Callbacks,
|
|
84
|
+
telemetry: TelemetryClient,
|
|
85
|
+
config: Partial<TxPoolV2Config> = {},
|
|
86
|
+
dateProvider: DateProvider,
|
|
87
|
+
log: Logger,
|
|
88
|
+
) {
|
|
89
|
+
this.#store = store;
|
|
90
|
+
this.#txsDB = store.openMap('txs');
|
|
91
|
+
|
|
92
|
+
this.#l2BlockSource = deps.l2BlockSource;
|
|
93
|
+
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
94
|
+
this.#createTxValidator = deps.createTxValidator;
|
|
95
|
+
|
|
96
|
+
this.#config = { ...DEFAULT_TX_POOL_V2_CONFIG, ...config };
|
|
97
|
+
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
98
|
+
this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
|
|
99
|
+
this.#dateProvider = dateProvider;
|
|
100
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, () => this.#indices.getTotalMetadataBytes());
|
|
101
|
+
this.#log = log;
|
|
102
|
+
this.#callbacks = callbacks;
|
|
103
|
+
|
|
104
|
+
// Setup eviction manager with rules
|
|
105
|
+
this.#evictionManager = new EvictionManager(this.#createPoolOperations(), log);
|
|
106
|
+
|
|
107
|
+
// Pre-add rules (run during addPendingTxs) - work with TxMetaData
|
|
108
|
+
this.#evictionManager.registerPreAddRule(new NullifierConflictRule());
|
|
109
|
+
this.#evictionManager.registerPreAddRule(new FeePayerBalancePreAddRule());
|
|
110
|
+
this.#evictionManager.registerPreAddRule(
|
|
111
|
+
new LowPriorityPreAddRule({ maxPoolSize: this.#config.maxPendingTxCount }),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Post-event eviction rules (run after events to check ALL pending txs)
|
|
115
|
+
this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
|
|
116
|
+
this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(deps.worldStateSynchronizer));
|
|
117
|
+
this.#evictionManager.registerRule(new FeePayerBalanceEvictionRule(deps.worldStateSynchronizer));
|
|
118
|
+
// LowPriorityEvictionRule handles cases where txs become pending via prepareForSlot (unprotect)
|
|
119
|
+
// The pre-add rule handles the addPendingTxs case, but post-event is needed for unprotect
|
|
120
|
+
this.#evictionManager.registerRule(new LowPriorityEvictionRule({ maxPoolSize: this.#config.maxPendingTxCount }));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ============================================================================
|
|
124
|
+
// PUBLIC IMPLEMENTATION METHODS
|
|
125
|
+
// ============================================================================
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Hydrates the in-memory state from the database on startup.
|
|
129
|
+
* Pipeline: Load → Check Mined Status → Partition → Validate Non-Mined → Rebuild Pending Pool → Delete Invalid
|
|
130
|
+
*
|
|
131
|
+
* Note: Protected status is lost on restart. All non-mined txs are rebuilt as pending
|
|
132
|
+
* by running pre-add rules to resolve nullifier conflicts, balance checks, and pool size limits.
|
|
133
|
+
*/
|
|
134
|
+
async hydrateFromDatabase(): Promise<void> {
|
|
135
|
+
// Step 0: Hydrate deleted pool state
|
|
136
|
+
await this.#deletedPool.hydrateFromDatabase();
|
|
137
|
+
|
|
138
|
+
// Step 1: Load all transactions from DB (excluding soft-deleted)
|
|
139
|
+
const { loaded, errors: deserializationErrors } = await this.#loadAllTxsFromDb();
|
|
140
|
+
|
|
141
|
+
// Step 2: Check mined status for each tx
|
|
142
|
+
await this.#markMinedStatusBatch(loaded.map(l => l.meta));
|
|
143
|
+
|
|
144
|
+
// Step 3: Partition by mined status
|
|
145
|
+
const mined: TxMetaData[] = [];
|
|
146
|
+
const nonMined: { tx: Tx; meta: TxMetaData }[] = [];
|
|
147
|
+
for (const entry of loaded) {
|
|
148
|
+
if (entry.meta.minedL2BlockId !== undefined) {
|
|
149
|
+
mined.push(entry.meta);
|
|
150
|
+
} else {
|
|
151
|
+
nonMined.push(entry);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Step 4: Validate non-mined transactions
|
|
156
|
+
const { valid, invalid } = await this.#revalidateMetadata(
|
|
157
|
+
nonMined.map(e => e.meta),
|
|
158
|
+
'on startup',
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// Step 5: Populate mined indices (these don't need conflict resolution)
|
|
162
|
+
for (const meta of mined) {
|
|
163
|
+
this.#indices.addMined(meta);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Step 6: Rebuild pending pool by running pre-add rules for each tx
|
|
167
|
+
// This resolves nullifier conflicts, fee payer balance issues, and pool size limits
|
|
168
|
+
const { rejected } = await this.#rebuildPendingPool(valid);
|
|
169
|
+
|
|
170
|
+
// Step 7: Delete invalid and rejected txs from DB only (indices were never populated for these)
|
|
171
|
+
const toDelete = [...deserializationErrors, ...invalid, ...rejected];
|
|
172
|
+
if (toDelete.length === 0) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
await this.#store.transactionAsync(async () => {
|
|
176
|
+
for (const txHashStr of toDelete) {
|
|
177
|
+
await this.#txsDB.delete(txHashStr);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`, { txHashes: toDelete });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async addPendingTxs(txs: Tx[], opts: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult> {
|
|
184
|
+
const accepted: TxHash[] = [];
|
|
185
|
+
const ignored: TxHash[] = [];
|
|
186
|
+
const rejected: TxHash[] = [];
|
|
187
|
+
const errors = new Map<string, TxPoolRejectionError>();
|
|
188
|
+
const acceptedPending = new Set<string>();
|
|
189
|
+
|
|
190
|
+
const poolAccess = this.#createPreAddPoolAccess();
|
|
191
|
+
const preAddContext: PreAddContext | undefined =
|
|
192
|
+
opts.feeComparisonOnly !== undefined ? { feeComparisonOnly: opts.feeComparisonOnly } : undefined;
|
|
193
|
+
|
|
194
|
+
await this.#store.transactionAsync(async () => {
|
|
195
|
+
for (const tx of txs) {
|
|
196
|
+
const txHash = tx.getTxHash();
|
|
197
|
+
const txHashStr = txHash.toString();
|
|
198
|
+
|
|
199
|
+
// Skip duplicates
|
|
200
|
+
if (this.#indices.has(txHashStr)) {
|
|
201
|
+
ignored.push(txHash);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Check mined status first (applies to all paths)
|
|
206
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
207
|
+
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
208
|
+
|
|
209
|
+
if (minedBlockId) {
|
|
210
|
+
// Already mined - add directly (protection already set if pre-protected)
|
|
211
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
212
|
+
accepted.push(txHash);
|
|
213
|
+
} else if (preProtectedSlot !== undefined) {
|
|
214
|
+
// Pre-protected and not mined - add as protected (bypass validation)
|
|
215
|
+
await this.#addTx(tx, { protected: preProtectedSlot }, opts);
|
|
216
|
+
accepted.push(txHash);
|
|
217
|
+
} else {
|
|
218
|
+
// Regular pending tx - validate and run pre-add rules
|
|
219
|
+
const result = await this.#tryAddRegularPendingTx(
|
|
220
|
+
tx,
|
|
221
|
+
opts,
|
|
222
|
+
poolAccess,
|
|
223
|
+
acceptedPending,
|
|
224
|
+
ignored,
|
|
225
|
+
errors,
|
|
226
|
+
preAddContext,
|
|
227
|
+
);
|
|
228
|
+
if (result.status === 'accepted') {
|
|
229
|
+
acceptedPending.add(txHashStr);
|
|
230
|
+
} else if (result.status === 'rejected') {
|
|
231
|
+
rejected.push(txHash);
|
|
232
|
+
} else {
|
|
233
|
+
ignored.push(txHash);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
239
|
+
if (acceptedPending.size > 0) {
|
|
240
|
+
const feePayers = Array.from(acceptedPending).map(txHash => this.#indices.getMetadata(txHash)!.feePayer);
|
|
241
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
242
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [...uniqueFeePayers]);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
247
|
+
for (const txHashStr of acceptedPending) {
|
|
248
|
+
accepted.push(TxHash.fromString(txHashStr));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Record metrics
|
|
252
|
+
if (ignored.length > 0) {
|
|
253
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
254
|
+
}
|
|
255
|
+
if (rejected.length > 0) {
|
|
256
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return { accepted, ignored, rejected, ...(errors.size > 0 ? { errors } : {}) };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Validates and adds a regular pending tx. Returns status. */
|
|
263
|
+
async #tryAddRegularPendingTx(
|
|
264
|
+
tx: Tx,
|
|
265
|
+
opts: { source?: string },
|
|
266
|
+
poolAccess: PreAddPoolAccess,
|
|
267
|
+
acceptedPending: Set<string>,
|
|
268
|
+
ignored: TxHash[],
|
|
269
|
+
errors: Map<string, TxPoolRejectionError>,
|
|
270
|
+
preAddContext?: PreAddContext,
|
|
271
|
+
): Promise<{ status: 'accepted' | 'ignored' | 'rejected' }> {
|
|
272
|
+
const txHash = tx.getTxHash();
|
|
273
|
+
const txHashStr = txHash.toString();
|
|
274
|
+
|
|
275
|
+
// Build metadata and validate using metadata
|
|
276
|
+
const meta = await buildTxMetaData(tx);
|
|
277
|
+
if (!(await this.#validateMeta(meta))) {
|
|
278
|
+
return { status: 'rejected' };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Run pre-add rules
|
|
282
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess, preAddContext);
|
|
283
|
+
|
|
284
|
+
if (preAddResult.shouldIgnore) {
|
|
285
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
286
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
287
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
288
|
+
}
|
|
289
|
+
return { status: 'ignored' };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
293
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
294
|
+
const byReason = new Map<string, string[]>();
|
|
295
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions) {
|
|
296
|
+
const group = byReason.get(reason);
|
|
297
|
+
if (group) {
|
|
298
|
+
group.push(evictHash);
|
|
299
|
+
} else {
|
|
300
|
+
byReason.set(reason, [evictHash]);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
for (const [reason, hashes] of byReason) {
|
|
304
|
+
await this.#evictTxs(hashes, reason);
|
|
305
|
+
}
|
|
306
|
+
for (const evictHashStr of preAddResult.txHashesToEvict) {
|
|
307
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
308
|
+
evictedTxHash: evictHashStr,
|
|
309
|
+
replacementTxHash: txHashStr,
|
|
310
|
+
});
|
|
311
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
312
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
313
|
+
acceptedPending.delete(evictHashStr);
|
|
314
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
320
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
321
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
322
|
+
return { status: 'accepted' };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Add the transaction
|
|
326
|
+
await this.#addTx(tx, 'pending', opts);
|
|
327
|
+
return { status: 'accepted' };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored' | 'rejected'> {
|
|
331
|
+
const txHashStr = tx.getTxHash().toString();
|
|
332
|
+
|
|
333
|
+
// Check if already in pool
|
|
334
|
+
if (this.#indices.has(txHashStr)) {
|
|
335
|
+
return 'ignored';
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Build metadata and validate using metadata
|
|
339
|
+
const meta = await buildTxMetaData(tx);
|
|
340
|
+
const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
|
|
341
|
+
if (validationResult !== true) {
|
|
342
|
+
return 'rejected';
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Use pre-add rules
|
|
346
|
+
const poolAccess = this.#createPreAddPoolAccess();
|
|
347
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
348
|
+
|
|
349
|
+
return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
|
|
353
|
+
const slotNumber = block.globalVariables.slotNumber;
|
|
354
|
+
|
|
355
|
+
await this.#store.transactionAsync(async () => {
|
|
356
|
+
for (const tx of txs) {
|
|
357
|
+
const txHash = tx.getTxHash();
|
|
358
|
+
const txHashStr = txHash.toString();
|
|
359
|
+
const isNew = !this.#indices.has(txHashStr);
|
|
360
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
361
|
+
|
|
362
|
+
if (isNew) {
|
|
363
|
+
// New tx - add as mined or protected (callback emitted by #addTx)
|
|
364
|
+
if (minedBlockId) {
|
|
365
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
366
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
367
|
+
} else {
|
|
368
|
+
await this.#addTx(tx, { protected: slotNumber }, opts);
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
// Existing tx - update protection and mined status
|
|
372
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
373
|
+
if (minedBlockId) {
|
|
374
|
+
const meta = this.#indices.getMetadata(txHashStr)!;
|
|
375
|
+
this.#indices.markAsMined(meta, minedBlockId);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async protectTxs(txHashes: TxHash[], block: BlockHeader): Promise<TxHash[]> {
|
|
383
|
+
const slotNumber = block.globalVariables.slotNumber;
|
|
384
|
+
const missing: TxHash[] = [];
|
|
385
|
+
let softDeletedHits = 0;
|
|
386
|
+
let missingPreviouslyEvicted = 0;
|
|
387
|
+
|
|
388
|
+
await this.#store.transactionAsync(async () => {
|
|
389
|
+
for (const txHash of txHashes) {
|
|
390
|
+
const txHashStr = txHash.toString();
|
|
391
|
+
|
|
392
|
+
if (this.#indices.has(txHashStr)) {
|
|
393
|
+
// Update protection for existing tx
|
|
394
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
395
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
396
|
+
// Resurrect soft-deleted tx as protected
|
|
397
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
398
|
+
if (buffer) {
|
|
399
|
+
const tx = Tx.fromBuffer(buffer);
|
|
400
|
+
await this.#addTx(tx, { protected: slotNumber });
|
|
401
|
+
softDeletedHits++;
|
|
402
|
+
} else {
|
|
403
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
404
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
405
|
+
missing.push(txHash);
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
409
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
410
|
+
missing.push(txHash);
|
|
411
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
412
|
+
missingPreviouslyEvicted++;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// Record metrics
|
|
419
|
+
if (softDeletedHits > 0) {
|
|
420
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
421
|
+
}
|
|
422
|
+
if (missing.length > 0) {
|
|
423
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map(h => h.toString()).join(', ')}`);
|
|
424
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
425
|
+
}
|
|
426
|
+
if (missingPreviouslyEvicted > 0) {
|
|
427
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
this.#log.info(
|
|
431
|
+
`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`,
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
return missing;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
async addMinedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
|
|
438
|
+
// Step 1: Build block ID
|
|
439
|
+
const blockId = await this.#buildBlockId(block);
|
|
440
|
+
|
|
441
|
+
await this.#store.transactionAsync(async () => {
|
|
442
|
+
for (const tx of txs) {
|
|
443
|
+
const txHashStr = tx.getTxHash().toString();
|
|
444
|
+
const existingMeta = this.#indices.getMetadata(txHashStr);
|
|
445
|
+
|
|
446
|
+
if (existingMeta) {
|
|
447
|
+
// Mark existing tx as mined
|
|
448
|
+
this.#indices.markAsMined(existingMeta, blockId);
|
|
449
|
+
} else {
|
|
450
|
+
// Add new mined tx (callback emitted by #addTx)
|
|
451
|
+
await this.#addTx(tx, { mined: blockId }, opts);
|
|
452
|
+
}
|
|
453
|
+
await this.#deletedPool.clearIfMinedHigher(txHashStr, blockId.number);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
async handleMinedBlock(block: L2Block): Promise<void> {
|
|
459
|
+
// Step 1: Build block ID
|
|
460
|
+
const blockId = await this.#buildBlockId(block.header);
|
|
461
|
+
|
|
462
|
+
// Step 2: Extract tx hashes and nullifiers directly from the block
|
|
463
|
+
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
464
|
+
const nullifiers = block.body.txEffects.flatMap(tx => tx.nullifiers.map(n => n.toString()));
|
|
465
|
+
|
|
466
|
+
// Step 3: Collect fee payers from txs we have in the pool (for balance-based eviction)
|
|
467
|
+
const feePayers: string[] = [];
|
|
468
|
+
const found: TxMetaData[] = [];
|
|
469
|
+
for (const txHash of txHashes) {
|
|
470
|
+
const meta = this.#indices.getMetadata(txHash.toString());
|
|
471
|
+
if (meta) {
|
|
472
|
+
feePayers.push(meta.feePayer);
|
|
473
|
+
found.push(meta);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
await this.#store.transactionAsync(async () => {
|
|
478
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
479
|
+
for (const meta of found) {
|
|
480
|
+
this.#indices.markAsMined(meta, blockId);
|
|
481
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
485
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
async prepareForSlot(slotNumber: SlotNumber): Promise<void> {
|
|
492
|
+
await this.#store.transactionAsync(async () => {
|
|
493
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
494
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
495
|
+
|
|
496
|
+
// Step 1: Find expired protected txs
|
|
497
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
498
|
+
|
|
499
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
500
|
+
this.#indices.clearProtection(expiredProtected);
|
|
501
|
+
|
|
502
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
503
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
504
|
+
if (txsToRestore.length === 0) {
|
|
505
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
510
|
+
|
|
511
|
+
// Step 4: Validate for pending pool
|
|
512
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
513
|
+
|
|
514
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
515
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
516
|
+
|
|
517
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
518
|
+
await this.#deleteTxsBatch(invalid);
|
|
519
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
520
|
+
|
|
521
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
522
|
+
if (added.length > 0) {
|
|
523
|
+
const feePayers = added.map(meta => meta.feePayer);
|
|
524
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
525
|
+
await this.#evictionManager.evictAfterNewTxs(
|
|
526
|
+
added.map(m => m.txHash),
|
|
527
|
+
[...uniqueFeePayers],
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
async handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void> {
|
|
534
|
+
// Step 1: Find transactions mined after the prune point
|
|
535
|
+
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
536
|
+
if (txsToUnmine.length === 0) {
|
|
537
|
+
this.#log.debug(`No transactions to un-mine for prune to block ${latestBlock.number}`);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
542
|
+
|
|
543
|
+
await this.#store.transactionAsync(async () => {
|
|
544
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
545
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
546
|
+
// when their original mined block is finalized
|
|
547
|
+
await this.#deletedPool.markFromPrunedBlock(
|
|
548
|
+
txsToUnmine.map(m => ({
|
|
549
|
+
txHash: m.txHash,
|
|
550
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId!.number),
|
|
551
|
+
})),
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
555
|
+
for (const meta of txsToUnmine) {
|
|
556
|
+
this.#indices.markAsUnmined(meta);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
560
|
+
if (options?.deleteAllTxs) {
|
|
561
|
+
const allTxHashes = txsToUnmine.map(m => m.txHash);
|
|
562
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
563
|
+
this.#log.info(
|
|
564
|
+
`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`,
|
|
565
|
+
);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
570
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
571
|
+
|
|
572
|
+
// Step 5: Validate for pending pool
|
|
573
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
574
|
+
|
|
575
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
576
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
577
|
+
|
|
578
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
579
|
+
await this.#deleteTxsBatch(invalid);
|
|
580
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
581
|
+
|
|
582
|
+
this.#log.info(
|
|
583
|
+
`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`,
|
|
584
|
+
{ txHashesRestored: valid.map(m => m.txHash), txHashesInvalid: invalid, txHashesEvicted: toEvict },
|
|
585
|
+
);
|
|
586
|
+
|
|
587
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
588
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
589
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
594
|
+
await this.#store.transactionAsync(async () => {
|
|
595
|
+
await this.#deleteTxsBatch(txHashes.map(h => h.toString()));
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
this.#log.info(`Deleted ${txHashes.length} failed txs`, { txHashes: txHashes.map(h => h.toString()) });
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
async handleFinalizedBlock(block: BlockHeader): Promise<void> {
|
|
602
|
+
const blockNumber = block.globalVariables.blockNumber;
|
|
603
|
+
|
|
604
|
+
// Step 1: Find mined txs at or before finalized block
|
|
605
|
+
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
606
|
+
|
|
607
|
+
await this.#store.transactionAsync(async () => {
|
|
608
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
609
|
+
const txsToArchive: Tx[] = [];
|
|
610
|
+
if (this.#archive.isEnabled()) {
|
|
611
|
+
for (const txHashStr of minedTxsToFinalize) {
|
|
612
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
613
|
+
if (buffer) {
|
|
614
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Step 3: Delete mined txs from active pool
|
|
620
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
621
|
+
|
|
622
|
+
// Step 4: Finalize soft-deleted txs
|
|
623
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
624
|
+
|
|
625
|
+
// Step 5: Archive mined txs
|
|
626
|
+
if (txsToArchive.length > 0) {
|
|
627
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
if (minedTxsToFinalize.length > 0) {
|
|
632
|
+
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
633
|
+
txHashes: minedTxsToFinalize,
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// === Query Methods ===
|
|
639
|
+
|
|
640
|
+
async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
641
|
+
const buffer = await this.#txsDB.getAsync(txHash.toString());
|
|
642
|
+
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
async getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
646
|
+
const results: (Tx | undefined)[] = [];
|
|
647
|
+
for (const h of txHashes) {
|
|
648
|
+
const buffer = await this.#txsDB.getAsync(h.toString());
|
|
649
|
+
results.push(buffer ? Tx.fromBuffer(buffer) : undefined);
|
|
650
|
+
}
|
|
651
|
+
return results;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
hasTxs(txHashes: TxHash[]): boolean[] {
|
|
655
|
+
return txHashes.map(h => {
|
|
656
|
+
const hashStr = h.toString();
|
|
657
|
+
return this.#indices.has(hashStr) || this.#deletedPool.isSoftDeleted(hashStr);
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
getTxStatus(txHash: TxHash): TxState | undefined {
|
|
662
|
+
const txHashStr = txHash.toString();
|
|
663
|
+
const meta = this.#indices.getMetadata(txHashStr);
|
|
664
|
+
if (meta) {
|
|
665
|
+
return this.#indices.getTxState(meta);
|
|
666
|
+
}
|
|
667
|
+
// Check if soft-deleted
|
|
668
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
669
|
+
return 'deleted';
|
|
670
|
+
}
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
getPendingTxHashes(): TxHash[] {
|
|
675
|
+
return [...this.#indices.iteratePendingByPriority('desc')].map(hash => TxHash.fromString(hash));
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
getEligiblePendingTxHashes(): TxHash[] {
|
|
679
|
+
const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
|
|
680
|
+
return [...this.#indices.iterateEligiblePendingByPriority('desc', maxReceivedAt)].map(hash =>
|
|
681
|
+
TxHash.fromString(hash),
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
getPendingTxCount(): number {
|
|
686
|
+
return this.#indices.getPendingTxCount();
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
getMinedTxHashes(): [TxHash, L2BlockId][] {
|
|
690
|
+
return this.#indices.getMinedTxs().map(([hash, blockId]) => [TxHash.fromString(hash), blockId]);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
getMinedTxCount(): number {
|
|
694
|
+
let count = 0;
|
|
695
|
+
for (const [, meta] of this.#indices.iterateMetadata()) {
|
|
696
|
+
if (meta.minedL2BlockId !== undefined) {
|
|
697
|
+
count++;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return count;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
isEmpty(): boolean {
|
|
704
|
+
return this.#indices.isEmpty();
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
getTxCount(): number {
|
|
708
|
+
return this.#indices.getTxCount();
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
712
|
+
return this.#archive.getTxByHash(txHash);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
getLowestPriorityPending(limit: number): TxHash[] {
|
|
716
|
+
return this.#indices.getLowestPriorityPending(limit).map(h => TxHash.fromString(h));
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// === Configuration ===
|
|
720
|
+
|
|
721
|
+
updateConfig(config: Partial<TxPoolV2Config>): void {
|
|
722
|
+
if (config.maxPendingTxCount !== undefined) {
|
|
723
|
+
this.#config.maxPendingTxCount = config.maxPendingTxCount;
|
|
724
|
+
}
|
|
725
|
+
if (config.archivedTxLimit !== undefined) {
|
|
726
|
+
this.#config.archivedTxLimit = config.archivedTxLimit;
|
|
727
|
+
this.#archive.updateLimit(config.archivedTxLimit);
|
|
728
|
+
}
|
|
729
|
+
if (config.minTxPoolAgeMs !== undefined) {
|
|
730
|
+
this.#config.minTxPoolAgeMs = config.minTxPoolAgeMs;
|
|
731
|
+
}
|
|
732
|
+
// Update eviction rules with new config
|
|
733
|
+
this.#evictionManager.updateConfig(config);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// === Pool Read Access ===
|
|
737
|
+
|
|
738
|
+
getPoolReadAccess(): PoolReadAccess {
|
|
739
|
+
return {
|
|
740
|
+
getMetadata: (txHash: string) => this.#indices.getMetadata(txHash),
|
|
741
|
+
getTxHashByNullifier: (nullifier: string) => this.#indices.getTxHashByNullifier(nullifier),
|
|
742
|
+
getTxHashesByFeePayer: (feePayer: string) => this.#indices.getTxHashesByFeePayer(feePayer),
|
|
743
|
+
getPendingTxCount: () => this.#indices.getPendingTxCount(),
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// === Metrics ===
|
|
748
|
+
|
|
749
|
+
countTxs(): {
|
|
750
|
+
pending: number;
|
|
751
|
+
protected: number;
|
|
752
|
+
mined: number;
|
|
753
|
+
softDeleted: number;
|
|
754
|
+
totalMetadataBytes: number;
|
|
755
|
+
} {
|
|
756
|
+
return {
|
|
757
|
+
...this.#indices.countTxs(),
|
|
758
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount(),
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// ============================================================================
|
|
763
|
+
// PRIVATE HELPERS - Transaction Management
|
|
764
|
+
// ============================================================================
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Adds a new transaction to the pool with the specified state.
|
|
768
|
+
* Emits onTxsAdded callback immediately after DB write.
|
|
769
|
+
*/
|
|
770
|
+
async #addTx(
|
|
771
|
+
tx: Tx,
|
|
772
|
+
state: 'pending' | { protected: SlotNumber } | { mined: L2BlockId },
|
|
773
|
+
opts: { source?: string } = {},
|
|
774
|
+
): Promise<TxMetaData> {
|
|
775
|
+
const txHashStr = tx.getTxHash().toString();
|
|
776
|
+
const meta = await buildTxMetaData(tx);
|
|
777
|
+
meta.receivedAt = this.#dateProvider.now();
|
|
778
|
+
|
|
779
|
+
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
780
|
+
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
781
|
+
this.#callbacks.onTxsAdded([tx], opts);
|
|
782
|
+
|
|
783
|
+
if (state === 'pending') {
|
|
784
|
+
this.#indices.addPending(meta);
|
|
785
|
+
} else if ('protected' in state) {
|
|
786
|
+
this.#indices.addProtected(meta, state.protected);
|
|
787
|
+
} else {
|
|
788
|
+
meta.minedL2BlockId = state.mined;
|
|
789
|
+
this.#indices.addMined(meta);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
793
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
794
|
+
eventName: 'tx-added-to-pool',
|
|
795
|
+
txHash: txHashStr,
|
|
796
|
+
state: stateStr,
|
|
797
|
+
source: opts.source,
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
return meta;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Deletes a transaction from both indices and DB.
|
|
805
|
+
* Emits onTxsRemoved callback immediately after DB delete.
|
|
806
|
+
*/
|
|
807
|
+
/**
|
|
808
|
+
* Deletes a transaction from the pool.
|
|
809
|
+
* Delegates to DeletedPool which decides soft vs hard delete based on whether
|
|
810
|
+
* the tx is from a pruned block.
|
|
811
|
+
*/
|
|
812
|
+
async #deleteTx(txHashStr: string): Promise<void> {
|
|
813
|
+
this.#indices.remove(txHashStr);
|
|
814
|
+
this.#callbacks.onTxsRemoved([txHashStr]);
|
|
815
|
+
await this.#deletedPool.deleteTx(txHashStr);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/** Deletes a batch of transactions, emitting callbacks individually for each. */
|
|
819
|
+
async #deleteTxsBatch(txHashes: string[]): Promise<void> {
|
|
820
|
+
for (const txHashStr of txHashes) {
|
|
821
|
+
await this.#deleteTx(txHashStr);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */
|
|
826
|
+
async #evictTxs(txHashes: string[], reason: string): Promise<void> {
|
|
827
|
+
if (txHashes.length === 0) {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
831
|
+
for (const txHashStr of txHashes) {
|
|
832
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, { txHash: txHashStr, reason });
|
|
833
|
+
this.#addToEvictedCache(txHashStr);
|
|
834
|
+
}
|
|
835
|
+
await this.#deleteTxsBatch(txHashes);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */
|
|
839
|
+
#addToEvictedCache(txHashStr: string): void {
|
|
840
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
841
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
842
|
+
const oldest = this.#evictedTxHashes.values().next().value!;
|
|
843
|
+
this.#evictedTxHashes.delete(oldest);
|
|
844
|
+
}
|
|
845
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// ============================================================================
|
|
849
|
+
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
850
|
+
// ============================================================================
|
|
851
|
+
|
|
852
|
+
/** Validates transaction metadata, returning true if valid */
|
|
853
|
+
async #validateMeta(meta: TxMetaData, validator?: TxValidator<TxMetaData>, context?: string): Promise<boolean> {
|
|
854
|
+
const txValidator = validator ?? (await this.#createTxValidator());
|
|
855
|
+
const result = await txValidator.validateTx(meta);
|
|
856
|
+
if (result.result !== 'valid') {
|
|
857
|
+
const contextStr = context ? ` ${context}` : '';
|
|
858
|
+
this.#log.info(`Tx ${meta.txHash}${contextStr} failed validation: ${result.reason?.join(', ')}`);
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/** Validates metadata directly */
|
|
865
|
+
async #revalidateMetadata(
|
|
866
|
+
metas: TxMetaData[],
|
|
867
|
+
context?: string,
|
|
868
|
+
): Promise<{ valid: TxMetaData[]; invalid: string[] }> {
|
|
869
|
+
const valid: TxMetaData[] = [];
|
|
870
|
+
const invalid: string[] = [];
|
|
871
|
+
const validator = await this.#createTxValidator();
|
|
872
|
+
for (const meta of metas) {
|
|
873
|
+
if (await this.#validateMeta(meta, validator, context)) {
|
|
874
|
+
valid.push(meta);
|
|
875
|
+
} else {
|
|
876
|
+
invalid.push(meta.txHash);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return { valid, invalid };
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Resolves nullifier conflicts between incoming txs and existing pending txs.
|
|
884
|
+
* Modifies the pending indices during iteration to maintain consistent state
|
|
885
|
+
* for subsequent conflict checks within the same batch.
|
|
886
|
+
*/
|
|
887
|
+
#applyNullifierConflictResolution(txs: TxMetaData[]): { added: TxMetaData[]; toEvict: string[] } {
|
|
888
|
+
const added: TxMetaData[] = [];
|
|
889
|
+
const toEvict: string[] = [];
|
|
890
|
+
|
|
891
|
+
for (const meta of txs) {
|
|
892
|
+
const conflict = checkNullifierConflict(
|
|
893
|
+
meta,
|
|
894
|
+
nullifier => this.#indices.getTxHashByNullifier(nullifier),
|
|
895
|
+
txHash => this.#indices.getMetadata(txHash),
|
|
896
|
+
);
|
|
897
|
+
if (conflict.shouldIgnore) {
|
|
898
|
+
// Lower priority than existing - don't add, mark for deletion
|
|
899
|
+
toEvict.push(meta.txHash);
|
|
900
|
+
} else {
|
|
901
|
+
// Higher priority - evict existing conflicts
|
|
902
|
+
toEvict.push(...conflict.txHashesToEvict);
|
|
903
|
+
// Remove evicted from indices immediately for subsequent checks
|
|
904
|
+
for (const evictHash of conflict.txHashesToEvict) {
|
|
905
|
+
const evictMeta = this.#indices.getMetadata(evictHash);
|
|
906
|
+
if (evictMeta) {
|
|
907
|
+
this.#indices.removeFromPendingIndices(evictMeta);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
// Add to pending indices immediately so subsequent txs in the batch see this tx
|
|
911
|
+
this.#indices.addToPendingIndices(meta);
|
|
912
|
+
added.push(meta);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
return { added, toEvict };
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// ============================================================================
|
|
920
|
+
// PRIVATE HELPERS - Block & Hydration
|
|
921
|
+
// ============================================================================
|
|
922
|
+
|
|
923
|
+
async #buildBlockId(block: BlockHeader): Promise<L2BlockId> {
|
|
924
|
+
return {
|
|
925
|
+
number: block.globalVariables.blockNumber,
|
|
926
|
+
hash: (await block.hash()).toString(),
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** Checks if a tx is already mined and returns its block ID if so */
|
|
931
|
+
async #getMinedBlockId(txHash: TxHash): Promise<L2BlockId | undefined> {
|
|
932
|
+
const txEffect = await this.#l2BlockSource.getTxEffect(txHash);
|
|
933
|
+
if (!txEffect) {
|
|
934
|
+
return undefined;
|
|
935
|
+
}
|
|
936
|
+
return {
|
|
937
|
+
number: txEffect.l2BlockNumber,
|
|
938
|
+
hash: txEffect.l2BlockHash.toString(),
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/** Loads all transactions from the database, returning loaded txs and deserialization errors */
|
|
943
|
+
async #loadAllTxsFromDb(): Promise<{
|
|
944
|
+
loaded: { tx: Tx; meta: TxMetaData }[];
|
|
945
|
+
errors: string[];
|
|
946
|
+
}> {
|
|
947
|
+
const loaded: { tx: Tx; meta: TxMetaData }[] = [];
|
|
948
|
+
const errors: string[] = [];
|
|
949
|
+
|
|
950
|
+
for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()) {
|
|
951
|
+
// Skip soft-deleted transactions - they stay in DB but not in indices
|
|
952
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
try {
|
|
957
|
+
const tx = Tx.fromBuffer(buffer);
|
|
958
|
+
const meta = await buildTxMetaData(tx);
|
|
959
|
+
loaded.push({ tx, meta });
|
|
960
|
+
} catch (err) {
|
|
961
|
+
this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, { err });
|
|
962
|
+
errors.push(txHashStr);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
return { loaded, errors };
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/** Queries block source and marks mined status on transaction metadata */
|
|
970
|
+
async #markMinedStatusBatch(metas: TxMetaData[]): Promise<void> {
|
|
971
|
+
for (const meta of metas) {
|
|
972
|
+
try {
|
|
973
|
+
const txEffect = await this.#l2BlockSource.getTxEffect(TxHash.fromString(meta.txHash));
|
|
974
|
+
if (txEffect) {
|
|
975
|
+
meta.minedL2BlockId = {
|
|
976
|
+
number: txEffect.l2BlockNumber,
|
|
977
|
+
hash: txEffect.l2BlockHash.toString(),
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
} catch (err) {
|
|
981
|
+
this.#log.warn(`Failed to check mined status for tx ${meta.txHash}`, { err });
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* Rebuilds the pending pool by processing each tx through pre-add rules.
|
|
988
|
+
* Starts with an empty pending pool and adds txs one by one, resolving conflicts.
|
|
989
|
+
* Returns the list of accepted and rejected tx hashes.
|
|
990
|
+
*/
|
|
991
|
+
async #rebuildPendingPool(metas: TxMetaData[]): Promise<{ accepted: string[]; rejected: string[] }> {
|
|
992
|
+
const accepted = new Set<string>();
|
|
993
|
+
const rejected: string[] = [];
|
|
994
|
+
const poolAccess = this.#createPreAddPoolAccess();
|
|
995
|
+
|
|
996
|
+
for (const meta of metas) {
|
|
997
|
+
// Run pre-add rules against current pending pool state (metadata not yet in pool)
|
|
998
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
999
|
+
|
|
1000
|
+
if (preAddResult.shouldIgnore) {
|
|
1001
|
+
// Transaction rejected - mark for deletion from DB
|
|
1002
|
+
rejected.push(meta.txHash);
|
|
1003
|
+
this.#log.debug(
|
|
1004
|
+
`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`,
|
|
1005
|
+
);
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// Evict any conflicting txs identified by pre-add rules
|
|
1010
|
+
for (const evictHashStr of preAddResult.txHashesToEvict) {
|
|
1011
|
+
const evictMeta = this.#indices.getMetadata(evictHashStr);
|
|
1012
|
+
if (evictMeta) {
|
|
1013
|
+
this.#indices.removeFromPendingIndices(evictMeta);
|
|
1014
|
+
this.#indices.remove(evictHashStr);
|
|
1015
|
+
rejected.push(evictHashStr);
|
|
1016
|
+
accepted.delete(evictHashStr);
|
|
1017
|
+
this.#log.debug(`Evicted tx ${evictHashStr} during rebuild due to conflict with ${meta.txHash}`);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// Add to indices
|
|
1022
|
+
this.#indices.addPending(meta);
|
|
1023
|
+
accepted.add(meta.txHash);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
this.#log.info(`Rebuilt pending pool: ${accepted.size} accepted, ${rejected.length} rejected`);
|
|
1027
|
+
return { accepted: [...accepted], rejected };
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// ============================================================================
|
|
1031
|
+
// PRIVATE HELPERS - Pool Access Adapters
|
|
1032
|
+
// ============================================================================
|
|
1033
|
+
|
|
1034
|
+
#createPoolOperations(): PoolOperations {
|
|
1035
|
+
return {
|
|
1036
|
+
getPendingTxs: () => this.#indices.getPendingTxs(),
|
|
1037
|
+
getPendingFeePayers: () => this.#indices.getPendingFeePayers(),
|
|
1038
|
+
getFeePayerPendingTxs: (feePayer: string) => this.#indices.getFeePayerPendingTxs(feePayer),
|
|
1039
|
+
getPendingTxCount: () => this.#indices.getPendingTxCount(),
|
|
1040
|
+
getLowestPriorityPending: (limit: number) => this.#indices.getLowestPriorityPending(limit),
|
|
1041
|
+
deleteTxs: (txHashes: string[], reason?: string) => this.#evictTxs(txHashes, reason ?? 'unknown'),
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
#createPreAddPoolAccess(): PreAddPoolAccess {
|
|
1046
|
+
return {
|
|
1047
|
+
getMetadata: (txHashStr: string) => {
|
|
1048
|
+
const meta = this.#indices.getMetadata(txHashStr);
|
|
1049
|
+
if (!meta || this.#indices.getTxState(meta) !== 'pending') {
|
|
1050
|
+
return undefined;
|
|
1051
|
+
}
|
|
1052
|
+
return meta;
|
|
1053
|
+
},
|
|
1054
|
+
getTxHashByNullifier: (nullifier: string) => this.#indices.getTxHashByNullifier(nullifier),
|
|
1055
|
+
getFeePayerBalance: async (feePayer: string) => {
|
|
1056
|
+
const db = this.#worldStateSynchronizer.getCommitted();
|
|
1057
|
+
const publicStateSource = new DatabasePublicStateSource(db);
|
|
1058
|
+
const balance = await publicStateSource.storageRead(
|
|
1059
|
+
ProtocolContractAddress.FeeJuice,
|
|
1060
|
+
await computeFeePayerBalanceStorageSlot(AztecAddress.fromString(feePayer)),
|
|
1061
|
+
);
|
|
1062
|
+
return balance.toBigInt();
|
|
1063
|
+
},
|
|
1064
|
+
getFeePayerPendingTxs: (feePayer: string) => this.#indices.getFeePayerPendingTxs(feePayer),
|
|
1065
|
+
getPendingTxCount: () => this.#indices.getPendingTxCount(),
|
|
1066
|
+
getLowestPriorityPendingTx: () => this.#indices.getLowestPriorityPendingTx(),
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
}
|