@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -3
- package/dest/client/factory.d.ts +9 -9
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +52 -14
- package/dest/client/interface.d.ts +47 -34
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +39 -51
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +164 -224
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +20 -10
- package/dest/config.d.ts +52 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +100 -37
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +21 -12
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +75 -40
- 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 +57 -57
- 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 -2
- 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_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 +7 -3
- 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 +54 -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 +16 -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 +3 -3
- 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 +30 -12
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +78 -15
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +144 -19
- 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 +50 -45
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -5
- 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 +17 -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 +364 -189
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +4 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/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/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- 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 +133 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +247 -60
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- 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 +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -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 +12 -6
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +12 -5
- package/dest/services/encoding.d.ts +7 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +18 -11
- 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 +37 -23
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +274 -173
- 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 +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +24 -9
- package/dest/services/peer-manager/peer_scoring.d.ts +5 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +28 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
- 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 +83 -106
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -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 +31 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -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 +52 -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/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +30 -14
- package/dest/services/service.d.ts +26 -4
- 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 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +80 -76
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +100 -0
- package/dest/services/tx_collection/index.d.ts +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/proposal_tx_collector.d.ts +7 -7
- 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/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +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 -13
- 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 +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +26 -7
- package/dest/services/tx_file_store/config.d.ts +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 +115 -38
- 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 +57 -27
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -3
- package/dest/util.d.ts +3 -3
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +102 -25
- package/src/client/interface.ts +52 -34
- package/src/client/p2p_client.ts +190 -266
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +33 -14
- package/src/config.ts +149 -43
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +104 -50
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +61 -57
- 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 +1 -1
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +85 -11
- 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 +7 -3
- 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 +59 -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 +33 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -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 +32 -12
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +209 -27
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +34 -8
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +410 -187
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
- package/src/msg_validators/clock_tolerance.ts +4 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
- package/src/msg_validators/tx_validator/README.md +119 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +394 -78
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +18 -7
- package/src/services/encoding.ts +18 -10
- 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 +288 -198
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +28 -9
- package/src/services/peer-manager/peer_scoring.ts +21 -5
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +79 -112
- package/src/services/reqresp/batch-tx-requester/interface.ts +3 -6
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -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/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/reqresp.ts +35 -15
- package/src/services/service.ts +37 -3
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +83 -76
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +1 -0
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +66 -33
- package/src/services/tx_collection/tx_collection.ts +114 -19
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +28 -8
- package/src/services/tx_file_store/config.ts +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 +4 -6
- package/src/test-helpers/mock-pubsub.ts +146 -9
- package/src/test-helpers/reqresp-nodes.ts +3 -6
- package/src/test-helpers/testbench-utils.ts +137 -43
- package/src/testbench/p2p_client_testbench_worker.ts +63 -30
- package/src/testbench/worker_client_manager.ts +13 -6
- package/src/util.ts +8 -2
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
2
3
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
3
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
5
6
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
6
7
|
import { TxArchive } from './archive/index.js';
|
|
7
|
-
import {
|
|
8
|
+
import { DeletedPool } from './deleted_pool.js';
|
|
9
|
+
import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule, TxPoolRejectionCode } from './eviction/index.js';
|
|
10
|
+
import { TxPoolV2Instrumentation } from './instrumentation.js';
|
|
8
11
|
import { DEFAULT_TX_POOL_V2_CONFIG } from './interfaces.js';
|
|
9
12
|
import { buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
|
|
10
13
|
import { TxPoolIndices } from './tx_pool_indices.js';
|
|
@@ -19,26 +22,35 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
19
22
|
// === Dependencies ===
|
|
20
23
|
#l2BlockSource;
|
|
21
24
|
#worldStateSynchronizer;
|
|
22
|
-
#
|
|
25
|
+
#createTxValidator;
|
|
26
|
+
#checkAllowedSetupCalls;
|
|
23
27
|
// === In-Memory Indices ===
|
|
24
28
|
#indices = new TxPoolIndices();
|
|
25
29
|
// === Config & Services ===
|
|
26
30
|
#config;
|
|
27
31
|
#archive;
|
|
32
|
+
#deletedPool;
|
|
28
33
|
#evictionManager;
|
|
34
|
+
#dateProvider;
|
|
35
|
+
#instrumentation;
|
|
36
|
+
#evictedTxHashes = new Set();
|
|
29
37
|
#log;
|
|
30
38
|
#callbacks;
|
|
31
|
-
constructor(store, archiveStore, deps, callbacks, config = {}, log){
|
|
39
|
+
constructor(store, archiveStore, deps, callbacks, telemetry, config = {}, dateProvider, log){
|
|
32
40
|
this.#store = store;
|
|
33
41
|
this.#txsDB = store.openMap('txs');
|
|
34
42
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
35
43
|
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
36
|
-
this.#
|
|
44
|
+
this.#createTxValidator = deps.createTxValidator;
|
|
45
|
+
this.#checkAllowedSetupCalls = deps.checkAllowedSetupCalls;
|
|
37
46
|
this.#config = {
|
|
38
47
|
...DEFAULT_TX_POOL_V2_CONFIG,
|
|
39
48
|
...config
|
|
40
49
|
};
|
|
41
50
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
51
|
+
this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
|
|
52
|
+
this.#dateProvider = dateProvider;
|
|
53
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, ()=>this.#indices.getTotalMetadataBytes());
|
|
42
54
|
this.#log = log;
|
|
43
55
|
this.#callbacks = callbacks;
|
|
44
56
|
// Setup eviction manager with rules
|
|
@@ -69,7 +81,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
69
81
|
* Note: Protected status is lost on restart. All non-mined txs are rebuilt as pending
|
|
70
82
|
* by running pre-add rules to resolve nullifier conflicts, balance checks, and pool size limits.
|
|
71
83
|
*/ async hydrateFromDatabase() {
|
|
72
|
-
// Step
|
|
84
|
+
// Step 0: Hydrate deleted pool state
|
|
85
|
+
await this.#deletedPool.hydrateFromDatabase();
|
|
86
|
+
// Step 1: Load all transactions from DB (excluding soft-deleted)
|
|
73
87
|
const { loaded, errors: deserializationErrors } = await this.#loadAllTxsFromDb();
|
|
74
88
|
// Step 2: Check mined status for each tx
|
|
75
89
|
await this.#markMinedStatusBatch(loaded.map((l)=>l.meta));
|
|
@@ -84,7 +98,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
84
98
|
}
|
|
85
99
|
}
|
|
86
100
|
// Step 4: Validate non-mined transactions
|
|
87
|
-
const { valid, invalid } = await this.#
|
|
101
|
+
const { valid, invalid } = await this.#revalidateMetadata(nonMined.map((e)=>e.meta), 'on startup');
|
|
88
102
|
// Step 5: Populate mined indices (these don't need conflict resolution)
|
|
89
103
|
for (const meta of mined){
|
|
90
104
|
this.#indices.addMined(meta);
|
|
@@ -106,14 +120,43 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
106
120
|
await this.#txsDB.delete(txHashStr);
|
|
107
121
|
}
|
|
108
122
|
});
|
|
109
|
-
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup
|
|
123
|
+
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`, {
|
|
124
|
+
txHashes: toDelete
|
|
125
|
+
});
|
|
110
126
|
}
|
|
111
127
|
async addPendingTxs(txs, opts) {
|
|
112
128
|
const accepted = [];
|
|
113
129
|
const ignored = [];
|
|
114
130
|
const rejected = [];
|
|
131
|
+
const errors = new Map();
|
|
115
132
|
const acceptedPending = new Set();
|
|
133
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
134
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
135
|
+
const precomputed = new Map();
|
|
136
|
+
const validator = await this.#createTxValidator();
|
|
137
|
+
for (const tx of txs){
|
|
138
|
+
const txHash = tx.getTxHash();
|
|
139
|
+
const txHashStr = txHash.toString();
|
|
140
|
+
const meta = await buildTxMetaData(tx);
|
|
141
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
142
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
143
|
+
let isValid = true;
|
|
144
|
+
if (!minedBlockId) {
|
|
145
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
146
|
+
}
|
|
147
|
+
precomputed.set(txHashStr, {
|
|
148
|
+
meta,
|
|
149
|
+
minedBlockId,
|
|
150
|
+
isValid
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
154
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
116
155
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
156
|
+
const preAddContext = opts.feeComparisonOnly !== undefined ? {
|
|
157
|
+
feeComparisonOnly: opts.feeComparisonOnly,
|
|
158
|
+
priceBumpPercentage: this.#config.priceBumpPercentage
|
|
159
|
+
} : undefined;
|
|
117
160
|
await this.#store.transactionAsync(async ()=>{
|
|
118
161
|
for (const tx of txs){
|
|
119
162
|
const txHash = tx.getTxHash();
|
|
@@ -123,82 +166,112 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
123
166
|
ignored.push(txHash);
|
|
124
167
|
continue;
|
|
125
168
|
}
|
|
126
|
-
|
|
127
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
169
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr);
|
|
128
170
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
129
171
|
if (minedBlockId) {
|
|
130
172
|
// Already mined - add directly (protection already set if pre-protected)
|
|
131
173
|
await this.#addTx(tx, {
|
|
132
174
|
mined: minedBlockId
|
|
133
|
-
}, opts);
|
|
175
|
+
}, opts, meta);
|
|
134
176
|
accepted.push(txHash);
|
|
135
177
|
} else if (preProtectedSlot !== undefined) {
|
|
136
178
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
137
179
|
await this.#addTx(tx, {
|
|
138
180
|
protected: preProtectedSlot
|
|
139
|
-
}, opts);
|
|
181
|
+
}, opts, meta);
|
|
140
182
|
accepted.push(txHash);
|
|
183
|
+
} else if (!isValid) {
|
|
184
|
+
// Failed pre-computed validation
|
|
185
|
+
rejected.push(txHash);
|
|
141
186
|
} else {
|
|
142
|
-
// Regular pending tx -
|
|
143
|
-
const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored);
|
|
187
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
188
|
+
const result = await this.#tryAddRegularPendingTx(tx, meta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
|
|
144
189
|
if (result.status === 'accepted') {
|
|
145
190
|
acceptedPending.add(txHashStr);
|
|
146
|
-
} else if (result.status === 'rejected') {
|
|
147
|
-
rejected.push(txHash);
|
|
148
191
|
} else {
|
|
149
192
|
ignored.push(txHash);
|
|
150
193
|
}
|
|
151
194
|
}
|
|
152
195
|
}
|
|
196
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
197
|
+
if (acceptedPending.size > 0) {
|
|
198
|
+
const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
|
|
199
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
200
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
|
|
201
|
+
...uniqueFeePayers
|
|
202
|
+
]);
|
|
203
|
+
}
|
|
153
204
|
});
|
|
154
205
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
155
206
|
for (const txHashStr of acceptedPending){
|
|
156
207
|
accepted.push(TxHash.fromString(txHashStr));
|
|
157
208
|
}
|
|
158
|
-
//
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
]);
|
|
209
|
+
// Record metrics
|
|
210
|
+
if (ignored.length > 0) {
|
|
211
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
212
|
+
}
|
|
213
|
+
if (rejected.length > 0) {
|
|
214
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
165
215
|
}
|
|
166
216
|
return {
|
|
167
217
|
accepted,
|
|
168
218
|
ignored,
|
|
169
|
-
rejected
|
|
219
|
+
rejected,
|
|
220
|
+
...errors.size > 0 ? {
|
|
221
|
+
errors
|
|
222
|
+
} : {}
|
|
170
223
|
};
|
|
171
224
|
}
|
|
172
|
-
/**
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!await this.#validateTx(tx)) {
|
|
177
|
-
return {
|
|
178
|
-
status: 'rejected'
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
// Build metadata and run pre-add rules
|
|
182
|
-
const meta = await buildTxMetaData(tx);
|
|
183
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
225
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */ async #tryAddRegularPendingTx(tx, precomputedMeta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
|
|
226
|
+
const txHashStr = tx.getTxHash().toString();
|
|
227
|
+
// Run pre-add rules
|
|
228
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
184
229
|
if (preAddResult.shouldIgnore) {
|
|
185
|
-
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
|
|
230
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
231
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
232
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
233
|
+
}
|
|
186
234
|
return {
|
|
187
235
|
status: 'ignored'
|
|
188
236
|
};
|
|
189
237
|
}
|
|
190
|
-
// Evict conflicts
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
238
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
239
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
240
|
+
const byReason = new Map();
|
|
241
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions){
|
|
242
|
+
const group = byReason.get(reason);
|
|
243
|
+
if (group) {
|
|
244
|
+
group.push(evictHash);
|
|
245
|
+
} else {
|
|
246
|
+
byReason.set(reason, [
|
|
247
|
+
evictHash
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const [reason, hashes] of byReason){
|
|
252
|
+
await this.#evictTxs(hashes, reason);
|
|
253
|
+
}
|
|
254
|
+
for (const evictHashStr of preAddResult.txHashesToEvict){
|
|
255
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
256
|
+
evictedTxHash: evictHashStr,
|
|
257
|
+
replacementTxHash: txHashStr
|
|
258
|
+
});
|
|
259
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
260
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
261
|
+
acceptedPending.delete(evictHashStr);
|
|
262
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
263
|
+
}
|
|
198
264
|
}
|
|
199
265
|
}
|
|
266
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
267
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
268
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
269
|
+
return {
|
|
270
|
+
status: 'accepted'
|
|
271
|
+
};
|
|
272
|
+
}
|
|
200
273
|
// Add the transaction
|
|
201
|
-
await this.#addTx(tx, 'pending', opts);
|
|
274
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
202
275
|
return {
|
|
203
276
|
status: 'accepted'
|
|
204
277
|
};
|
|
@@ -207,38 +280,44 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
207
280
|
const txHashStr = tx.getTxHash().toString();
|
|
208
281
|
// Check if already in pool
|
|
209
282
|
if (this.#indices.has(txHashStr)) {
|
|
283
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
|
|
210
284
|
return 'ignored';
|
|
211
285
|
}
|
|
212
|
-
//
|
|
213
|
-
const validationResult = await this.#pendingTxValidator.validateTx(tx);
|
|
214
|
-
if (validationResult.result !== 'valid') {
|
|
215
|
-
return 'rejected';
|
|
216
|
-
}
|
|
217
|
-
// Build metadata and use pre-add rules
|
|
286
|
+
// Build metadata and check pre-add rules
|
|
218
287
|
const meta = await buildTxMetaData(tx);
|
|
219
288
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
220
289
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
221
|
-
|
|
290
|
+
if (preAddResult.shouldIgnore) {
|
|
291
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
|
|
292
|
+
reason: preAddResult.reason?.message ?? 'no reason provided'
|
|
293
|
+
});
|
|
294
|
+
return 'ignored';
|
|
295
|
+
}
|
|
296
|
+
return 'accepted';
|
|
222
297
|
}
|
|
223
298
|
async addProtectedTxs(txs, block, opts) {
|
|
224
299
|
const slotNumber = block.globalVariables.slotNumber;
|
|
300
|
+
// Precompute setup-call allow-list flags outside the store transaction
|
|
301
|
+
const allowedFlags = await Promise.all(txs.map((tx)=>this.#checkAllowedSetupCalls(tx)));
|
|
225
302
|
await this.#store.transactionAsync(async ()=>{
|
|
226
|
-
for
|
|
303
|
+
for(let i = 0; i < txs.length; i++){
|
|
304
|
+
const tx = txs[i];
|
|
227
305
|
const txHash = tx.getTxHash();
|
|
228
306
|
const txHashStr = txHash.toString();
|
|
229
307
|
const isNew = !this.#indices.has(txHashStr);
|
|
230
308
|
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
231
309
|
if (isNew) {
|
|
310
|
+
const meta = await buildTxMetaData(tx, allowedFlags[i]);
|
|
232
311
|
// New tx - add as mined or protected (callback emitted by #addTx)
|
|
233
312
|
if (minedBlockId) {
|
|
234
313
|
await this.#addTx(tx, {
|
|
235
314
|
mined: minedBlockId
|
|
236
|
-
}, opts);
|
|
315
|
+
}, opts, meta);
|
|
237
316
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
238
317
|
} else {
|
|
239
318
|
await this.#addTx(tx, {
|
|
240
319
|
protected: slotNumber
|
|
241
|
-
}, opts);
|
|
320
|
+
}, opts, meta);
|
|
242
321
|
}
|
|
243
322
|
} else {
|
|
244
323
|
// Existing tx - update protection and mined status
|
|
@@ -251,20 +330,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
251
330
|
}
|
|
252
331
|
});
|
|
253
332
|
}
|
|
254
|
-
protectTxs(txHashes, block) {
|
|
333
|
+
async protectTxs(txHashes, block) {
|
|
255
334
|
const slotNumber = block.globalVariables.slotNumber;
|
|
256
335
|
const missing = [];
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
336
|
+
let softDeletedHits = 0;
|
|
337
|
+
let missingPreviouslyEvicted = 0;
|
|
338
|
+
await this.#store.transactionAsync(async ()=>{
|
|
339
|
+
for (const txHash of txHashes){
|
|
340
|
+
const txHashStr = txHash.toString();
|
|
341
|
+
if (this.#indices.has(txHashStr)) {
|
|
342
|
+
// Update protection for existing tx
|
|
343
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
344
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
345
|
+
// Resurrect soft-deleted tx as protected
|
|
346
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
347
|
+
if (buffer) {
|
|
348
|
+
const tx = Tx.fromBuffer(buffer);
|
|
349
|
+
await this.#addTx(tx, {
|
|
350
|
+
protected: slotNumber
|
|
351
|
+
});
|
|
352
|
+
softDeletedHits++;
|
|
353
|
+
} else {
|
|
354
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
355
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
356
|
+
missing.push(txHash);
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
360
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
361
|
+
missing.push(txHash);
|
|
362
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
363
|
+
missingPreviouslyEvicted++;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
266
366
|
}
|
|
367
|
+
});
|
|
368
|
+
// Record metrics
|
|
369
|
+
if (softDeletedHits > 0) {
|
|
370
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
371
|
+
}
|
|
372
|
+
if (missing.length > 0) {
|
|
373
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
|
|
374
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
375
|
+
}
|
|
376
|
+
if (missingPreviouslyEvicted > 0) {
|
|
377
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
267
378
|
}
|
|
379
|
+
this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
|
|
268
380
|
return missing;
|
|
269
381
|
}
|
|
270
382
|
async addMinedTxs(txs, block, opts) {
|
|
@@ -283,6 +395,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
283
395
|
mined: blockId
|
|
284
396
|
}, opts);
|
|
285
397
|
}
|
|
398
|
+
await this.#deletedPool.clearIfMinedHigher(txHashStr, blockId.number);
|
|
286
399
|
}
|
|
287
400
|
});
|
|
288
401
|
}
|
|
@@ -302,44 +415,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
302
415
|
found.push(meta);
|
|
303
416
|
}
|
|
304
417
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
418
|
+
await this.#store.transactionAsync(async ()=>{
|
|
419
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
420
|
+
for (const meta of found){
|
|
421
|
+
this.#indices.markAsMined(meta, blockId);
|
|
422
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
423
|
+
}
|
|
424
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
425
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
426
|
+
});
|
|
427
|
+
if (found.length > 0) {
|
|
428
|
+
this.#callbacks.onTxsMined(found.map((m)=>m.txHash));
|
|
308
429
|
}
|
|
309
|
-
// Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
|
|
310
|
-
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
311
430
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
312
431
|
}
|
|
313
432
|
async prepareForSlot(slotNumber) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
433
|
+
await this.#store.transactionAsync(async ()=>{
|
|
434
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
435
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
436
|
+
// Step 1: Find expired protected txs
|
|
437
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
438
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
439
|
+
this.#indices.clearProtection(expiredProtected);
|
|
440
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
441
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
442
|
+
if (txsToRestore.length === 0) {
|
|
443
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
447
|
+
// Step 4: Validate for pending pool
|
|
448
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
449
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
450
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
451
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
452
|
+
await this.#deleteTxsBatch(invalid);
|
|
453
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
454
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
455
|
+
if (added.length > 0) {
|
|
456
|
+
const feePayers = added.map((meta)=>meta.feePayer);
|
|
457
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
458
|
+
await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
|
|
459
|
+
...uniqueFeePayers
|
|
460
|
+
]);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
341
463
|
}
|
|
342
|
-
async handlePrunedBlocks(latestBlock) {
|
|
464
|
+
async handlePrunedBlocks(latestBlock, options) {
|
|
343
465
|
// Step 1: Find transactions mined after the prune point
|
|
344
466
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
345
467
|
if (txsToUnmine.length === 0) {
|
|
@@ -347,54 +469,81 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
347
469
|
return;
|
|
348
470
|
}
|
|
349
471
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
472
|
+
await this.#store.transactionAsync(async ()=>{
|
|
473
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
474
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
475
|
+
// when their original mined block is finalized
|
|
476
|
+
await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
|
|
477
|
+
txHash: m.txHash,
|
|
478
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId.number)
|
|
479
|
+
})));
|
|
480
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
481
|
+
for (const meta of txsToUnmine){
|
|
482
|
+
this.#indices.markAsUnmined(meta);
|
|
483
|
+
}
|
|
484
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
485
|
+
if (options?.deleteAllTxs) {
|
|
486
|
+
const allTxHashes = txsToUnmine.map((m)=>m.txHash);
|
|
487
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
488
|
+
this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
492
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
493
|
+
// Step 5: Validate for pending pool
|
|
494
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
495
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
496
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
497
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
498
|
+
await this.#deleteTxsBatch(invalid);
|
|
499
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
500
|
+
this.#log.info(`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`, {
|
|
501
|
+
txHashesRestored: valid.map((m)=>m.txHash),
|
|
502
|
+
txHashesInvalid: invalid,
|
|
503
|
+
txHashesEvicted: toEvict
|
|
504
|
+
});
|
|
505
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
506
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
507
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
508
|
+
});
|
|
368
509
|
}
|
|
369
510
|
async handleFailedExecution(txHashes) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
511
|
+
await this.#store.transactionAsync(async ()=>{
|
|
512
|
+
await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
|
|
513
|
+
});
|
|
514
|
+
this.#log.info(`Deleted ${txHashes.length} failed txs`, {
|
|
515
|
+
txHashes: txHashes.map((h)=>h.toString())
|
|
516
|
+
});
|
|
373
517
|
}
|
|
374
518
|
async handleFinalizedBlock(block) {
|
|
375
519
|
const blockNumber = block.globalVariables.blockNumber;
|
|
376
|
-
// Step 1: Find txs
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
520
|
+
// Step 1: Find mined txs at or before finalized block
|
|
521
|
+
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
522
|
+
await this.#store.transactionAsync(async ()=>{
|
|
523
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
524
|
+
const txsToArchive = [];
|
|
525
|
+
if (this.#archive.isEnabled()) {
|
|
526
|
+
for (const txHashStr of minedTxsToFinalize){
|
|
527
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
528
|
+
if (buffer) {
|
|
529
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
530
|
+
}
|
|
388
531
|
}
|
|
389
532
|
}
|
|
533
|
+
// Step 3: Delete mined txs from active pool
|
|
534
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
535
|
+
// Step 4: Finalize soft-deleted txs
|
|
536
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
537
|
+
// Step 5: Archive mined txs
|
|
538
|
+
if (txsToArchive.length > 0) {
|
|
539
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
if (minedTxsToFinalize.length > 0) {
|
|
543
|
+
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
544
|
+
txHashes: minedTxsToFinalize
|
|
545
|
+
});
|
|
390
546
|
}
|
|
391
|
-
// Step 3: Delete from active pool
|
|
392
|
-
await this.#deleteTxsBatch(txsToFinalize);
|
|
393
|
-
// Step 4: Archive
|
|
394
|
-
if (txsToArchive.length > 0) {
|
|
395
|
-
await this.#archive.archiveTxs(txsToArchive);
|
|
396
|
-
}
|
|
397
|
-
this.#log.info(`Finalized ${txsToFinalize.length} txs from blocks up to ${blockNumber}`);
|
|
398
547
|
}
|
|
399
548
|
// === Query Methods ===
|
|
400
549
|
async getTxByHash(txHash) {
|
|
@@ -410,20 +559,34 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
410
559
|
return results;
|
|
411
560
|
}
|
|
412
561
|
hasTxs(txHashes) {
|
|
413
|
-
return txHashes.map((h)=>
|
|
562
|
+
return txHashes.map((h)=>{
|
|
563
|
+
const hashStr = h.toString();
|
|
564
|
+
return this.#indices.has(hashStr) || this.#deletedPool.isSoftDeleted(hashStr);
|
|
565
|
+
});
|
|
414
566
|
}
|
|
415
567
|
getTxStatus(txHash) {
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
568
|
+
const txHashStr = txHash.toString();
|
|
569
|
+
const meta = this.#indices.getMetadata(txHashStr);
|
|
570
|
+
if (meta) {
|
|
571
|
+
return this.#indices.getTxState(meta);
|
|
572
|
+
}
|
|
573
|
+
// Check if soft-deleted
|
|
574
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
575
|
+
return 'deleted';
|
|
419
576
|
}
|
|
420
|
-
return
|
|
577
|
+
return undefined;
|
|
421
578
|
}
|
|
422
579
|
getPendingTxHashes() {
|
|
423
580
|
return [
|
|
424
581
|
...this.#indices.iteratePendingByPriority('desc')
|
|
425
582
|
].map((hash)=>TxHash.fromString(hash));
|
|
426
583
|
}
|
|
584
|
+
getEligiblePendingTxHashes() {
|
|
585
|
+
const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
|
|
586
|
+
return [
|
|
587
|
+
...this.#indices.iterateEligiblePendingByPriority('desc', maxReceivedAt)
|
|
588
|
+
].map((hash)=>TxHash.fromString(hash));
|
|
589
|
+
}
|
|
427
590
|
getPendingTxCount() {
|
|
428
591
|
return this.#indices.getPendingTxCount();
|
|
429
592
|
}
|
|
@@ -463,6 +626,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
463
626
|
this.#config.archivedTxLimit = config.archivedTxLimit;
|
|
464
627
|
this.#archive.updateLimit(config.archivedTxLimit);
|
|
465
628
|
}
|
|
629
|
+
if (config.minTxPoolAgeMs !== undefined) {
|
|
630
|
+
this.#config.minTxPoolAgeMs = config.minTxPoolAgeMs;
|
|
631
|
+
}
|
|
466
632
|
// Update eviction rules with new config
|
|
467
633
|
this.#evictionManager.updateConfig(config);
|
|
468
634
|
}
|
|
@@ -477,7 +643,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
477
643
|
}
|
|
478
644
|
// === Metrics ===
|
|
479
645
|
countTxs() {
|
|
480
|
-
return
|
|
646
|
+
return {
|
|
647
|
+
...this.#indices.countTxs(),
|
|
648
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount()
|
|
649
|
+
};
|
|
481
650
|
}
|
|
482
651
|
// ============================================================================
|
|
483
652
|
// PRIVATE HELPERS - Transaction Management
|
|
@@ -485,10 +654,12 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
485
654
|
/**
|
|
486
655
|
* Adds a new transaction to the pool with the specified state.
|
|
487
656
|
* Emits onTxsAdded callback immediately after DB write.
|
|
488
|
-
*/ async #addTx(tx, state, opts = {}) {
|
|
657
|
+
*/ async #addTx(tx, state, opts = {}, precomputedMeta) {
|
|
489
658
|
const txHashStr = tx.getTxHash().toString();
|
|
490
|
-
const meta = await buildTxMetaData(tx);
|
|
659
|
+
const meta = precomputedMeta ?? await buildTxMetaData(tx);
|
|
660
|
+
meta.receivedAt = this.#dateProvider.now();
|
|
491
661
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
662
|
+
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
492
663
|
this.#callbacks.onTxsAdded([
|
|
493
664
|
tx
|
|
494
665
|
], opts);
|
|
@@ -501,64 +672,74 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
501
672
|
this.#indices.addMined(meta);
|
|
502
673
|
}
|
|
503
674
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
504
|
-
this.#log.
|
|
675
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
505
676
|
eventName: 'tx-added-to-pool',
|
|
506
|
-
|
|
677
|
+
txHash: txHashStr,
|
|
678
|
+
state: stateStr,
|
|
679
|
+
source: opts.source
|
|
507
680
|
});
|
|
508
681
|
return meta;
|
|
509
682
|
}
|
|
510
683
|
/**
|
|
511
684
|
* Deletes a transaction from both indices and DB.
|
|
512
685
|
* Emits onTxsRemoved callback immediately after DB delete.
|
|
686
|
+
*/ /**
|
|
687
|
+
* Deletes a transaction from the pool.
|
|
688
|
+
* Delegates to DeletedPool which decides soft vs hard delete based on whether
|
|
689
|
+
* the tx is from a pruned block.
|
|
513
690
|
*/ async #deleteTx(txHashStr) {
|
|
514
691
|
this.#indices.remove(txHashStr);
|
|
515
|
-
await this.#txsDB.delete(txHashStr);
|
|
516
692
|
this.#callbacks.onTxsRemoved([
|
|
517
693
|
txHashStr
|
|
518
694
|
]);
|
|
695
|
+
await this.#deletedPool.deleteTx(txHashStr);
|
|
519
696
|
}
|
|
520
697
|
/** Deletes a batch of transactions, emitting callbacks individually for each. */ async #deleteTxsBatch(txHashes) {
|
|
521
698
|
for (const txHashStr of txHashes){
|
|
522
699
|
await this.#deleteTx(txHashStr);
|
|
523
700
|
}
|
|
524
701
|
}
|
|
702
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
|
|
703
|
+
if (txHashes.length === 0) {
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
707
|
+
for (const txHashStr of txHashes){
|
|
708
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, {
|
|
709
|
+
txHash: txHashStr,
|
|
710
|
+
reason
|
|
711
|
+
});
|
|
712
|
+
this.#addToEvictedCache(txHashStr);
|
|
713
|
+
}
|
|
714
|
+
await this.#deleteTxsBatch(txHashes);
|
|
715
|
+
}
|
|
716
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
|
|
717
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
718
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
719
|
+
const oldest = this.#evictedTxHashes.values().next().value;
|
|
720
|
+
this.#evictedTxHashes.delete(oldest);
|
|
721
|
+
}
|
|
722
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
723
|
+
}
|
|
525
724
|
// ============================================================================
|
|
526
725
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
527
726
|
// ============================================================================
|
|
528
|
-
/** Validates
|
|
529
|
-
const
|
|
727
|
+
/** Validates transaction metadata, returning true if valid */ async #validateMeta(meta, validator, context) {
|
|
728
|
+
const txValidator = validator ?? await this.#createTxValidator();
|
|
729
|
+
const result = await txValidator.validateTx(meta);
|
|
530
730
|
if (result.result !== 'valid') {
|
|
531
731
|
const contextStr = context ? ` ${context}` : '';
|
|
532
|
-
this.#log.info(`Tx ${
|
|
732
|
+
this.#log.info(`Tx ${meta.txHash}${contextStr} failed validation: ${result.reason?.join(', ')}`);
|
|
533
733
|
return false;
|
|
534
734
|
}
|
|
535
735
|
return true;
|
|
536
736
|
}
|
|
537
|
-
/**
|
|
538
|
-
const loaded = [];
|
|
539
|
-
const missing = [];
|
|
540
|
-
for (const meta of metas){
|
|
541
|
-
const buffer = await this.#txsDB.getAsync(meta.txHash);
|
|
542
|
-
if (!buffer) {
|
|
543
|
-
this.#log.warn(`Tx ${meta.txHash} not found in DB`);
|
|
544
|
-
missing.push(meta.txHash);
|
|
545
|
-
continue;
|
|
546
|
-
}
|
|
547
|
-
loaded.push({
|
|
548
|
-
tx: Tx.fromBuffer(buffer),
|
|
549
|
-
meta
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
return {
|
|
553
|
-
loaded,
|
|
554
|
-
missing
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
/** Validates a batch of transactions, returning valid and invalid groups */ async #validateTxBatch(txs, context) {
|
|
737
|
+
/** Validates metadata directly */ async #revalidateMetadata(metas, context) {
|
|
558
738
|
const valid = [];
|
|
559
739
|
const invalid = [];
|
|
560
|
-
|
|
561
|
-
|
|
740
|
+
const validator = await this.#createTxValidator();
|
|
741
|
+
for (const meta of metas){
|
|
742
|
+
if (await this.#validateMeta(meta, validator, context)) {
|
|
562
743
|
valid.push(meta);
|
|
563
744
|
} else {
|
|
564
745
|
invalid.push(meta.txHash);
|
|
@@ -569,17 +750,6 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
569
750
|
invalid
|
|
570
751
|
};
|
|
571
752
|
}
|
|
572
|
-
/** Loads transactions from DB and validates them */ async #loadAndValidateTxs(metas, context) {
|
|
573
|
-
const { loaded, missing } = await this.#loadTxsFromDb(metas);
|
|
574
|
-
const { valid, invalid } = await this.#validateTxBatch(loaded, context);
|
|
575
|
-
return {
|
|
576
|
-
valid,
|
|
577
|
-
invalid: [
|
|
578
|
-
...missing,
|
|
579
|
-
...invalid
|
|
580
|
-
]
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
753
|
/**
|
|
584
754
|
* Resolves nullifier conflicts between incoming txs and existing pending txs.
|
|
585
755
|
* Modifies the pending indices during iteration to maintain consistent state
|
|
@@ -635,9 +805,14 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
635
805
|
const loaded = [];
|
|
636
806
|
const errors = [];
|
|
637
807
|
for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()){
|
|
808
|
+
// Skip soft-deleted transactions - they stay in DB but not in indices
|
|
809
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
638
812
|
try {
|
|
639
813
|
const tx = Tx.fromBuffer(buffer);
|
|
640
|
-
const
|
|
814
|
+
const allowedSetupCalls = await this.#checkAllowedSetupCalls(tx);
|
|
815
|
+
const meta = await buildTxMetaData(tx, allowedSetupCalls);
|
|
641
816
|
loaded.push({
|
|
642
817
|
tx,
|
|
643
818
|
meta
|
|
@@ -685,7 +860,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
685
860
|
if (preAddResult.shouldIgnore) {
|
|
686
861
|
// Transaction rejected - mark for deletion from DB
|
|
687
862
|
rejected.push(meta.txHash);
|
|
688
|
-
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
|
|
863
|
+
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
689
864
|
continue;
|
|
690
865
|
}
|
|
691
866
|
// Evict any conflicting txs identified by pre-add rules
|
|
@@ -721,7 +896,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
721
896
|
getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
|
|
722
897
|
getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
|
|
723
898
|
getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
|
|
724
|
-
deleteTxs: (txHashes)=>this.#
|
|
899
|
+
deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
|
|
725
900
|
};
|
|
726
901
|
}
|
|
727
902
|
#createPreAddPoolAccess() {
|