@aztec/p2p 0.0.1-commit.0c875d939 → 0.0.1-commit.0dc957cde
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 +8 -7
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +34 -29
- package/dest/client/interface.d.ts +18 -20
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +9 -19
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +81 -104
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +23 -10
- package/dest/config.d.ts +126 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +93 -39
- 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 +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +7 -5
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +16 -9
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- package/dest/mem_pools/index.d.ts +1 -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/tx_pool_v2/deleted_pool.d.ts +3 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -4
- 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 +3 -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 +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +62 -0
- 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 +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -7
- 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 +12 -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 +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -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 +27 -10
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +57 -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 +115 -20
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
- 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 +38 -46
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +12 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +12 -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 +297 -153
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +5 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +20 -11
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +2 -2
- package/dest/msg_validators/clock_tolerance.d.ts +12 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +54 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +7 -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 +7 -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 +15 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +67 -47
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- 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/archive_cache.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/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 +99 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
- 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 +2 -2
- 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/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/dummy_service.d.ts +8 -5
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +10 -5
- package/dest/services/encoding.d.ts +6 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +16 -9
- package/dest/services/gossipsub/topic_score_params.d.ts +30 -7
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +53 -14
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +14 -0
- package/dest/services/libp2p/libp2p_service.d.ts +32 -37
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +241 -212
- 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 +39 -11
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -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/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/interface.d.ts +14 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +10 -11
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- 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/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
- package/dest/services/reqresp/reqresp.d.ts +4 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +30 -12
- package/dest/services/service.d.ts +9 -4
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +65 -75
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
- package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -6
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +50 -9
- 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 +2 -2
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +10 -8
- package/dest/services/tx_collection/tx_collection.d.ts +5 -7
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +13 -22
- 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/tx_file_store.js +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +4 -2
- package/dest/test-helpers/mock-pubsub.d.ts +14 -6
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +43 -12
- 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 +6 -4
- package/dest/test-helpers/testbench-utils.d.ts +6 -3
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +24 -4
- 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 +83 -26
- package/dest/testbench/worker_client_manager.d.ts +10 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +55 -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 +62 -49
- package/src/client/interface.ts +20 -21
- package/src/client/p2p_client.ts +89 -135
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +35 -14
- package/src/config.ts +139 -45
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +17 -12
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool_v2/README.md +10 -2
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -4
- 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 +5 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +65 -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 +4 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -8
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +12 -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 +1 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +27 -10
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +166 -28
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -46
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +28 -8
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +332 -149
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +21 -9
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +4 -1
- package/src/msg_validators/clock_tolerance.ts +72 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +17 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +23 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +79 -49
- package/src/msg_validators/tx_validator/README.md +127 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
- 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/archive_cache.ts +1 -1
- 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/factory.ts +396 -78
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +199 -54
- 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 +7 -7
- package/src/services/data_store.ts +5 -13
- package/src/services/dummy_service.ts +13 -7
- package/src/services/encoding.ts +16 -8
- package/src/services/gossipsub/README.md +29 -14
- package/src/services/gossipsub/topic_score_params.ts +85 -17
- package/src/services/libp2p/instrumentation.ts +14 -0
- package/src/services/libp2p/libp2p_service.ts +259 -238
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +45 -11
- package/src/services/peer-manager/peer_scoring.ts +27 -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/config.ts +2 -2
- package/src/services/reqresp/interface.ts +21 -11
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +40 -13
- package/src/services/service.ts +17 -3
- package/src/services/tx_collection/fast_tx_collection.ts +71 -76
- package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
- package/src/services/tx_collection/file_store_tx_source.ts +65 -9
- 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 +8 -9
- package/src/services/tx_collection/tx_collection.ts +5 -6
- package/src/services/tx_collection/tx_collection_sink.ts +15 -29
- package/src/services/tx_collection/tx_source.ts +28 -8
- package/src/services/tx_file_store/tx_file_store.ts +1 -1
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +47 -11
- package/src/test-helpers/reqresp-nodes.ts +7 -8
- package/src/test-helpers/testbench-utils.ts +33 -6
- package/src/testbench/p2p_client_testbench_worker.ts +92 -29
- package/src/testbench/worker_client_manager.ts +68 -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/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- 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
- package/src/services/reqresp/protocols/block.ts +0 -37
|
@@ -9,6 +9,7 @@ import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
|
|
|
9
9
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
10
10
|
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
11
11
|
import { BlockHeader, Tx, TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
12
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
12
13
|
|
|
13
14
|
import { TxArchive } from './archive/index.js';
|
|
14
15
|
import { DeletedPool } from './deleted_pool.js';
|
|
@@ -16,14 +17,19 @@ import {
|
|
|
16
17
|
EvictionManager,
|
|
17
18
|
FeePayerBalanceEvictionRule,
|
|
18
19
|
FeePayerBalancePreAddRule,
|
|
20
|
+
InsufficientFeePerGasEvictionRule,
|
|
19
21
|
InvalidTxsAfterMiningRule,
|
|
20
22
|
InvalidTxsAfterReorgRule,
|
|
21
23
|
LowPriorityEvictionRule,
|
|
22
24
|
LowPriorityPreAddRule,
|
|
23
25
|
NullifierConflictRule,
|
|
24
26
|
type PoolOperations,
|
|
27
|
+
type PreAddContext,
|
|
25
28
|
type PreAddPoolAccess,
|
|
29
|
+
TxPoolRejectionCode,
|
|
30
|
+
type TxPoolRejectionError,
|
|
26
31
|
} from './eviction/index.js';
|
|
32
|
+
import { TxPoolV2Instrumentation } from './instrumentation.js';
|
|
27
33
|
import {
|
|
28
34
|
type AddTxsResult,
|
|
29
35
|
DEFAULT_TX_POOL_V2_CONFIG,
|
|
@@ -40,6 +46,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
40
46
|
export interface TxPoolV2Callbacks {
|
|
41
47
|
onTxsAdded: (txs: Tx[], opts: { source?: string }) => void;
|
|
42
48
|
onTxsRemoved: (txHashes: string[] | bigint[]) => void;
|
|
49
|
+
onTxsMined: (txHashes: string[]) => void;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
/**
|
|
@@ -56,6 +63,7 @@ export class TxPoolV2Impl {
|
|
|
56
63
|
#l2BlockSource: L2BlockSource;
|
|
57
64
|
#worldStateSynchronizer: WorldStateSynchronizer;
|
|
58
65
|
#createTxValidator: TxPoolV2Dependencies['createTxValidator'];
|
|
66
|
+
#checkAllowedSetupCalls: TxPoolV2Dependencies['checkAllowedSetupCalls'];
|
|
59
67
|
|
|
60
68
|
// === In-Memory Indices ===
|
|
61
69
|
#indices: TxPoolIndices = new TxPoolIndices();
|
|
@@ -66,6 +74,8 @@ export class TxPoolV2Impl {
|
|
|
66
74
|
#deletedPool: DeletedPool;
|
|
67
75
|
#evictionManager: EvictionManager;
|
|
68
76
|
#dateProvider: DateProvider;
|
|
77
|
+
#instrumentation: TxPoolV2Instrumentation;
|
|
78
|
+
#evictedTxHashes: Set<string> = new Set();
|
|
69
79
|
#log: Logger;
|
|
70
80
|
#callbacks: TxPoolV2Callbacks;
|
|
71
81
|
|
|
@@ -74,6 +84,7 @@ export class TxPoolV2Impl {
|
|
|
74
84
|
archiveStore: AztecAsyncKVStore,
|
|
75
85
|
deps: TxPoolV2Dependencies,
|
|
76
86
|
callbacks: TxPoolV2Callbacks,
|
|
87
|
+
telemetry: TelemetryClient,
|
|
77
88
|
config: Partial<TxPoolV2Config> = {},
|
|
78
89
|
dateProvider: DateProvider,
|
|
79
90
|
log: Logger,
|
|
@@ -84,11 +95,13 @@ export class TxPoolV2Impl {
|
|
|
84
95
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
85
96
|
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
86
97
|
this.#createTxValidator = deps.createTxValidator;
|
|
98
|
+
this.#checkAllowedSetupCalls = deps.checkAllowedSetupCalls;
|
|
87
99
|
|
|
88
100
|
this.#config = { ...DEFAULT_TX_POOL_V2_CONFIG, ...config };
|
|
89
101
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
90
102
|
this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
|
|
91
103
|
this.#dateProvider = dateProvider;
|
|
104
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, () => this.#indices.getTotalMetadataBytes());
|
|
92
105
|
this.#log = log;
|
|
93
106
|
this.#callbacks = callbacks;
|
|
94
107
|
|
|
@@ -104,6 +117,7 @@ export class TxPoolV2Impl {
|
|
|
104
117
|
|
|
105
118
|
// Post-event eviction rules (run after events to check ALL pending txs)
|
|
106
119
|
this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
|
|
120
|
+
this.#evictionManager.registerRule(new InsufficientFeePerGasEvictionRule(deps.blockMinFeesProvider));
|
|
107
121
|
this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(deps.worldStateSynchronizer));
|
|
108
122
|
this.#evictionManager.registerRule(new FeePayerBalanceEvictionRule(deps.worldStateSynchronizer));
|
|
109
123
|
// LowPriorityEvictionRule handles cases where txs become pending via prepareForSlot (unprotect)
|
|
@@ -171,13 +185,42 @@ export class TxPoolV2Impl {
|
|
|
171
185
|
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`, { txHashes: toDelete });
|
|
172
186
|
}
|
|
173
187
|
|
|
174
|
-
async addPendingTxs(txs: Tx[], opts: { source?: string }): Promise<AddTxsResult> {
|
|
188
|
+
async addPendingTxs(txs: Tx[], opts: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult> {
|
|
175
189
|
const accepted: TxHash[] = [];
|
|
176
190
|
const ignored: TxHash[] = [];
|
|
177
191
|
const rejected: TxHash[] = [];
|
|
192
|
+
const errors = new Map<string, TxPoolRejectionError>();
|
|
178
193
|
const acceptedPending = new Set<string>();
|
|
179
194
|
|
|
195
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
196
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
197
|
+
const precomputed = new Map<string, { meta: TxMetaData; minedBlockId: L2BlockId | undefined; isValid: boolean }>();
|
|
198
|
+
|
|
199
|
+
const validator = await this.#createTxValidator();
|
|
200
|
+
|
|
201
|
+
for (const tx of txs) {
|
|
202
|
+
const txHash = tx.getTxHash();
|
|
203
|
+
const txHashStr = txHash.toString();
|
|
204
|
+
|
|
205
|
+
const meta = await buildTxMetaData(tx);
|
|
206
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
207
|
+
|
|
208
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
209
|
+
let isValid = true;
|
|
210
|
+
if (!minedBlockId) {
|
|
211
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
precomputed.set(txHashStr, { meta, minedBlockId, isValid });
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
218
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
180
219
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
220
|
+
const preAddContext: PreAddContext | undefined =
|
|
221
|
+
opts.feeComparisonOnly !== undefined
|
|
222
|
+
? { feeComparisonOnly: opts.feeComparisonOnly, priceBumpPercentage: this.#config.priceBumpPercentage }
|
|
223
|
+
: undefined;
|
|
181
224
|
|
|
182
225
|
await this.#store.transactionAsync(async () => {
|
|
183
226
|
for (const tx of txs) {
|
|
@@ -190,30 +233,46 @@ export class TxPoolV2Impl {
|
|
|
190
233
|
continue;
|
|
191
234
|
}
|
|
192
235
|
|
|
193
|
-
|
|
194
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
236
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr)!;
|
|
195
237
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
196
238
|
|
|
197
239
|
if (minedBlockId) {
|
|
198
240
|
// Already mined - add directly (protection already set if pre-protected)
|
|
199
|
-
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
241
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
|
|
200
242
|
accepted.push(txHash);
|
|
201
243
|
} else if (preProtectedSlot !== undefined) {
|
|
202
244
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
203
|
-
await this.#addTx(tx, { protected: preProtectedSlot }, opts);
|
|
245
|
+
await this.#addTx(tx, { protected: preProtectedSlot }, opts, meta);
|
|
204
246
|
accepted.push(txHash);
|
|
247
|
+
} else if (!isValid) {
|
|
248
|
+
// Failed pre-computed validation
|
|
249
|
+
rejected.push(txHash);
|
|
205
250
|
} else {
|
|
206
|
-
// Regular pending tx -
|
|
207
|
-
const result = await this.#tryAddRegularPendingTx(
|
|
251
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
252
|
+
const result = await this.#tryAddRegularPendingTx(
|
|
253
|
+
tx,
|
|
254
|
+
meta,
|
|
255
|
+
opts,
|
|
256
|
+
poolAccess,
|
|
257
|
+
acceptedPending,
|
|
258
|
+
ignored,
|
|
259
|
+
errors,
|
|
260
|
+
preAddContext,
|
|
261
|
+
);
|
|
208
262
|
if (result.status === 'accepted') {
|
|
209
263
|
acceptedPending.add(txHashStr);
|
|
210
|
-
} else if (result.status === 'rejected') {
|
|
211
|
-
rejected.push(txHash);
|
|
212
264
|
} else {
|
|
213
265
|
ignored.push(txHash);
|
|
214
266
|
}
|
|
215
267
|
}
|
|
216
268
|
}
|
|
269
|
+
|
|
270
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
271
|
+
if (acceptedPending.size > 0) {
|
|
272
|
+
const feePayers = Array.from(acceptedPending).map(txHash => this.#indices.getMetadata(txHash)!.feePayer);
|
|
273
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
274
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [...uniqueFeePayers]);
|
|
275
|
+
}
|
|
217
276
|
});
|
|
218
277
|
|
|
219
278
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
@@ -221,99 +280,124 @@ export class TxPoolV2Impl {
|
|
|
221
280
|
accepted.push(TxHash.fromString(txHashStr));
|
|
222
281
|
}
|
|
223
282
|
|
|
224
|
-
//
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
283
|
+
// Record metrics
|
|
284
|
+
if (ignored.length > 0) {
|
|
285
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
286
|
+
}
|
|
287
|
+
if (rejected.length > 0) {
|
|
288
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
229
289
|
}
|
|
230
290
|
|
|
231
|
-
return { accepted, ignored, rejected };
|
|
291
|
+
return { accepted, ignored, rejected, ...(errors.size > 0 ? { errors } : {}) };
|
|
232
292
|
}
|
|
233
293
|
|
|
234
|
-
/**
|
|
294
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */
|
|
235
295
|
async #tryAddRegularPendingTx(
|
|
236
296
|
tx: Tx,
|
|
297
|
+
precomputedMeta: TxMetaData,
|
|
237
298
|
opts: { source?: string },
|
|
238
299
|
poolAccess: PreAddPoolAccess,
|
|
239
300
|
acceptedPending: Set<string>,
|
|
240
301
|
ignored: TxHash[],
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// Build metadata and validate using metadata
|
|
246
|
-
const meta = await buildTxMetaData(tx);
|
|
247
|
-
if (!(await this.#validateMeta(meta))) {
|
|
248
|
-
return { status: 'rejected' };
|
|
249
|
-
}
|
|
302
|
+
errors: Map<string, TxPoolRejectionError>,
|
|
303
|
+
preAddContext?: PreAddContext,
|
|
304
|
+
): Promise<{ status: 'accepted' | 'ignored' }> {
|
|
305
|
+
const txHashStr = tx.getTxHash().toString();
|
|
250
306
|
|
|
251
307
|
// Run pre-add rules
|
|
252
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(
|
|
308
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
253
309
|
|
|
254
310
|
if (preAddResult.shouldIgnore) {
|
|
255
|
-
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
|
|
311
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
312
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
313
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
314
|
+
}
|
|
256
315
|
return { status: 'ignored' };
|
|
257
316
|
}
|
|
258
317
|
|
|
259
|
-
// Evict conflicts
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
ignored.push(TxHash.fromString(evictHashStr));
|
|
318
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
319
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
320
|
+
const byReason = new Map<string, string[]>();
|
|
321
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions) {
|
|
322
|
+
const group = byReason.get(reason);
|
|
323
|
+
if (group) {
|
|
324
|
+
group.push(evictHash);
|
|
325
|
+
} else {
|
|
326
|
+
byReason.set(reason, [evictHash]);
|
|
327
|
+
}
|
|
270
328
|
}
|
|
329
|
+
for (const [reason, hashes] of byReason) {
|
|
330
|
+
await this.#evictTxs(hashes, reason);
|
|
331
|
+
}
|
|
332
|
+
for (const evictHashStr of preAddResult.txHashesToEvict) {
|
|
333
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
334
|
+
evictedTxHash: evictHashStr,
|
|
335
|
+
replacementTxHash: txHashStr,
|
|
336
|
+
});
|
|
337
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
338
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
339
|
+
acceptedPending.delete(evictHashStr);
|
|
340
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
346
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
347
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
348
|
+
return { status: 'accepted' };
|
|
271
349
|
}
|
|
272
350
|
|
|
273
351
|
// Add the transaction
|
|
274
|
-
await this.#addTx(tx, 'pending', opts);
|
|
352
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
275
353
|
return { status: 'accepted' };
|
|
276
354
|
}
|
|
277
355
|
|
|
278
|
-
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'
|
|
356
|
+
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'> {
|
|
279
357
|
const txHashStr = tx.getTxHash().toString();
|
|
280
358
|
|
|
281
359
|
// Check if already in pool
|
|
282
360
|
if (this.#indices.has(txHashStr)) {
|
|
361
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
|
|
283
362
|
return 'ignored';
|
|
284
363
|
}
|
|
285
364
|
|
|
286
|
-
// Build metadata and
|
|
365
|
+
// Build metadata and check pre-add rules
|
|
287
366
|
const meta = await buildTxMetaData(tx);
|
|
288
|
-
const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
|
|
289
|
-
if (validationResult !== true) {
|
|
290
|
-
return 'rejected';
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// Use pre-add rules
|
|
294
367
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
295
368
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
296
369
|
|
|
297
|
-
|
|
370
|
+
if (preAddResult.shouldIgnore) {
|
|
371
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
|
|
372
|
+
reason: preAddResult.reason?.message ?? 'no reason provided',
|
|
373
|
+
});
|
|
374
|
+
return 'ignored';
|
|
375
|
+
}
|
|
376
|
+
return 'accepted';
|
|
298
377
|
}
|
|
299
378
|
|
|
300
379
|
async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
|
|
301
380
|
const slotNumber = block.globalVariables.slotNumber;
|
|
302
381
|
|
|
382
|
+
// Precompute setup-call allow-list flags outside the store transaction
|
|
383
|
+
const allowedFlags = await Promise.all(txs.map(tx => this.#checkAllowedSetupCalls(tx)));
|
|
384
|
+
|
|
303
385
|
await this.#store.transactionAsync(async () => {
|
|
304
|
-
for (
|
|
386
|
+
for (let i = 0; i < txs.length; i++) {
|
|
387
|
+
const tx = txs[i];
|
|
305
388
|
const txHash = tx.getTxHash();
|
|
306
389
|
const txHashStr = txHash.toString();
|
|
307
390
|
const isNew = !this.#indices.has(txHashStr);
|
|
308
391
|
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
309
392
|
|
|
310
393
|
if (isNew) {
|
|
394
|
+
const meta = await buildTxMetaData(tx, allowedFlags[i]);
|
|
311
395
|
// New tx - add as mined or protected (callback emitted by #addTx)
|
|
312
396
|
if (minedBlockId) {
|
|
313
|
-
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
397
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
|
|
314
398
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
315
399
|
} else {
|
|
316
|
-
await this.#addTx(tx, { protected: slotNumber }, opts);
|
|
400
|
+
await this.#addTx(tx, { protected: slotNumber }, opts, meta);
|
|
317
401
|
}
|
|
318
402
|
} else {
|
|
319
403
|
// Existing tx - update protection and mined status
|
|
@@ -327,23 +411,58 @@ export class TxPoolV2Impl {
|
|
|
327
411
|
});
|
|
328
412
|
}
|
|
329
413
|
|
|
330
|
-
protectTxs(txHashes: TxHash[], block: BlockHeader): TxHash[] {
|
|
414
|
+
async protectTxs(txHashes: TxHash[], block: BlockHeader): Promise<TxHash[]> {
|
|
331
415
|
const slotNumber = block.globalVariables.slotNumber;
|
|
332
416
|
const missing: TxHash[] = [];
|
|
417
|
+
let softDeletedHits = 0;
|
|
418
|
+
let missingPreviouslyEvicted = 0;
|
|
333
419
|
|
|
334
|
-
|
|
335
|
-
const
|
|
420
|
+
await this.#store.transactionAsync(async () => {
|
|
421
|
+
for (const txHash of txHashes) {
|
|
422
|
+
const txHashStr = txHash.toString();
|
|
336
423
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
424
|
+
if (this.#indices.has(txHashStr)) {
|
|
425
|
+
// Update protection for existing tx
|
|
426
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
427
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
428
|
+
// Resurrect soft-deleted tx as protected
|
|
429
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
430
|
+
if (buffer) {
|
|
431
|
+
const tx = Tx.fromBuffer(buffer);
|
|
432
|
+
await this.#addTx(tx, { protected: slotNumber });
|
|
433
|
+
softDeletedHits++;
|
|
434
|
+
} else {
|
|
435
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
436
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
437
|
+
missing.push(txHash);
|
|
438
|
+
}
|
|
439
|
+
} else {
|
|
440
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
441
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
442
|
+
missing.push(txHash);
|
|
443
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
444
|
+
missingPreviouslyEvicted++;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
344
447
|
}
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// Record metrics
|
|
451
|
+
if (softDeletedHits > 0) {
|
|
452
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
453
|
+
}
|
|
454
|
+
if (missing.length > 0) {
|
|
455
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map(h => h.toString()).join(', ')}`);
|
|
456
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
457
|
+
}
|
|
458
|
+
if (missingPreviouslyEvicted > 0) {
|
|
459
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
345
460
|
}
|
|
346
461
|
|
|
462
|
+
this.#log.info(
|
|
463
|
+
`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`,
|
|
464
|
+
);
|
|
465
|
+
|
|
347
466
|
return missing;
|
|
348
467
|
}
|
|
349
468
|
|
|
@@ -387,57 +506,67 @@ export class TxPoolV2Impl {
|
|
|
387
506
|
}
|
|
388
507
|
}
|
|
389
508
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
509
|
+
await this.#store.transactionAsync(async () => {
|
|
510
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
511
|
+
for (const meta of found) {
|
|
512
|
+
this.#indices.markAsMined(meta, blockId);
|
|
513
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
517
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
518
|
+
});
|
|
395
519
|
|
|
396
|
-
|
|
397
|
-
|
|
520
|
+
if (found.length > 0) {
|
|
521
|
+
this.#callbacks.onTxsMined(found.map(m => m.txHash));
|
|
522
|
+
}
|
|
398
523
|
|
|
399
524
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
400
525
|
}
|
|
401
526
|
|
|
402
527
|
async prepareForSlot(slotNumber: SlotNumber): Promise<void> {
|
|
403
|
-
|
|
404
|
-
|
|
528
|
+
await this.#store.transactionAsync(async () => {
|
|
529
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
530
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
405
531
|
|
|
406
|
-
|
|
407
|
-
|
|
532
|
+
// Step 1: Find expired protected txs
|
|
533
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
408
534
|
|
|
409
|
-
|
|
410
|
-
|
|
535
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
536
|
+
this.#indices.clearProtection(expiredProtected);
|
|
411
537
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
538
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
539
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
540
|
+
if (txsToRestore.length === 0) {
|
|
541
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
417
544
|
|
|
418
|
-
|
|
545
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
419
546
|
|
|
420
|
-
|
|
421
|
-
|
|
547
|
+
// Step 4: Validate for pending pool
|
|
548
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
422
549
|
|
|
423
|
-
|
|
424
|
-
|
|
550
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
551
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
425
552
|
|
|
426
|
-
|
|
427
|
-
|
|
553
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
554
|
+
await this.#deleteTxsBatch(invalid);
|
|
555
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
428
556
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
557
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
558
|
+
if (added.length > 0) {
|
|
559
|
+
const feePayers = added.map(meta => meta.feePayer);
|
|
560
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
561
|
+
await this.#evictionManager.evictAfterNewTxs(
|
|
562
|
+
added.map(m => m.txHash),
|
|
563
|
+
[...uniqueFeePayers],
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
438
567
|
}
|
|
439
568
|
|
|
440
|
-
async handlePrunedBlocks(latestBlock: L2BlockId): Promise<void> {
|
|
569
|
+
async handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void> {
|
|
441
570
|
// Step 1: Find transactions mined after the prune point
|
|
442
571
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
443
572
|
if (txsToUnmine.length === 0) {
|
|
@@ -447,46 +576,60 @@ export class TxPoolV2Impl {
|
|
|
447
576
|
|
|
448
577
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
449
578
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
579
|
+
await this.#store.transactionAsync(async () => {
|
|
580
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
581
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
582
|
+
// when their original mined block is finalized
|
|
583
|
+
await this.#deletedPool.markFromPrunedBlock(
|
|
584
|
+
txsToUnmine.map(m => ({
|
|
585
|
+
txHash: m.txHash,
|
|
586
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId!.number),
|
|
587
|
+
})),
|
|
588
|
+
);
|
|
459
589
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
590
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
591
|
+
for (const meta of txsToUnmine) {
|
|
592
|
+
this.#indices.markAsUnmined(meta);
|
|
593
|
+
}
|
|
464
594
|
|
|
465
|
-
|
|
466
|
-
|
|
595
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
596
|
+
if (options?.deleteAllTxs) {
|
|
597
|
+
const allTxHashes = txsToUnmine.map(m => m.txHash);
|
|
598
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
599
|
+
this.#log.info(
|
|
600
|
+
`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`,
|
|
601
|
+
);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
467
604
|
|
|
468
|
-
|
|
469
|
-
|
|
605
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
606
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
470
607
|
|
|
471
|
-
|
|
472
|
-
|
|
608
|
+
// Step 5: Validate for pending pool
|
|
609
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
473
610
|
|
|
474
|
-
|
|
475
|
-
|
|
611
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
612
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
476
613
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
614
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
615
|
+
await this.#deleteTxsBatch(invalid);
|
|
616
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
617
|
+
|
|
618
|
+
this.#log.info(
|
|
619
|
+
`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`,
|
|
620
|
+
{ txHashesRestored: valid.map(m => m.txHash), txHashesInvalid: invalid, txHashesEvicted: toEvict },
|
|
621
|
+
);
|
|
481
622
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
623
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
624
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
625
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
626
|
+
});
|
|
485
627
|
}
|
|
486
628
|
|
|
487
629
|
async handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
488
|
-
|
|
489
|
-
|
|
630
|
+
await this.#store.transactionAsync(async () => {
|
|
631
|
+
await this.#deleteTxsBatch(txHashes.map(h => h.toString()));
|
|
632
|
+
});
|
|
490
633
|
|
|
491
634
|
this.#log.info(`Deleted ${txHashes.length} failed txs`, { txHashes: txHashes.map(h => h.toString()) });
|
|
492
635
|
}
|
|
@@ -497,27 +640,29 @@ export class TxPoolV2Impl {
|
|
|
497
640
|
// Step 1: Find mined txs at or before finalized block
|
|
498
641
|
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
499
642
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
643
|
+
await this.#store.transactionAsync(async () => {
|
|
644
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
645
|
+
const txsToArchive: Tx[] = [];
|
|
646
|
+
if (this.#archive.isEnabled()) {
|
|
647
|
+
for (const txHashStr of minedTxsToFinalize) {
|
|
648
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
649
|
+
if (buffer) {
|
|
650
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
651
|
+
}
|
|
507
652
|
}
|
|
508
653
|
}
|
|
509
|
-
}
|
|
510
654
|
|
|
511
|
-
|
|
512
|
-
|
|
655
|
+
// Step 3: Delete mined txs from active pool
|
|
656
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
513
657
|
|
|
514
|
-
|
|
515
|
-
|
|
658
|
+
// Step 4: Finalize soft-deleted txs
|
|
659
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
516
660
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
661
|
+
// Step 5: Archive mined txs
|
|
662
|
+
if (txsToArchive.length > 0) {
|
|
663
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
521
666
|
|
|
522
667
|
if (minedTxsToFinalize.length > 0) {
|
|
523
668
|
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
@@ -637,8 +782,17 @@ export class TxPoolV2Impl {
|
|
|
637
782
|
|
|
638
783
|
// === Metrics ===
|
|
639
784
|
|
|
640
|
-
countTxs(): {
|
|
641
|
-
|
|
785
|
+
countTxs(): {
|
|
786
|
+
pending: number;
|
|
787
|
+
protected: number;
|
|
788
|
+
mined: number;
|
|
789
|
+
softDeleted: number;
|
|
790
|
+
totalMetadataBytes: number;
|
|
791
|
+
} {
|
|
792
|
+
return {
|
|
793
|
+
...this.#indices.countTxs(),
|
|
794
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount(),
|
|
795
|
+
};
|
|
642
796
|
}
|
|
643
797
|
|
|
644
798
|
// ============================================================================
|
|
@@ -653,9 +807,10 @@ export class TxPoolV2Impl {
|
|
|
653
807
|
tx: Tx,
|
|
654
808
|
state: 'pending' | { protected: SlotNumber } | { mined: L2BlockId },
|
|
655
809
|
opts: { source?: string } = {},
|
|
810
|
+
precomputedMeta?: TxMetaData,
|
|
656
811
|
): Promise<TxMetaData> {
|
|
657
812
|
const txHashStr = tx.getTxHash().toString();
|
|
658
|
-
const meta = await buildTxMetaData(tx);
|
|
813
|
+
const meta = precomputedMeta ?? (await buildTxMetaData(tx));
|
|
659
814
|
meta.receivedAt = this.#dateProvider.now();
|
|
660
815
|
|
|
661
816
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
@@ -672,9 +827,11 @@ export class TxPoolV2Impl {
|
|
|
672
827
|
}
|
|
673
828
|
|
|
674
829
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
675
|
-
this.#log.
|
|
830
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
676
831
|
eventName: 'tx-added-to-pool',
|
|
832
|
+
txHash: txHashStr,
|
|
677
833
|
state: stateStr,
|
|
834
|
+
source: opts.source,
|
|
678
835
|
});
|
|
679
836
|
|
|
680
837
|
return meta;
|
|
@@ -702,6 +859,29 @@ export class TxPoolV2Impl {
|
|
|
702
859
|
}
|
|
703
860
|
}
|
|
704
861
|
|
|
862
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */
|
|
863
|
+
async #evictTxs(txHashes: string[], reason: string): Promise<void> {
|
|
864
|
+
if (txHashes.length === 0) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
868
|
+
for (const txHashStr of txHashes) {
|
|
869
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, { txHash: txHashStr, reason });
|
|
870
|
+
this.#addToEvictedCache(txHashStr);
|
|
871
|
+
}
|
|
872
|
+
await this.#deleteTxsBatch(txHashes);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */
|
|
876
|
+
#addToEvictedCache(txHashStr: string): void {
|
|
877
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
878
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
879
|
+
const oldest = this.#evictedTxHashes.values().next().value!;
|
|
880
|
+
this.#evictedTxHashes.delete(oldest);
|
|
881
|
+
}
|
|
882
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
883
|
+
}
|
|
884
|
+
|
|
705
885
|
// ============================================================================
|
|
706
886
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
707
887
|
// ============================================================================
|
|
@@ -812,7 +992,8 @@ export class TxPoolV2Impl {
|
|
|
812
992
|
|
|
813
993
|
try {
|
|
814
994
|
const tx = Tx.fromBuffer(buffer);
|
|
815
|
-
const
|
|
995
|
+
const allowedSetupCalls = await this.#checkAllowedSetupCalls(tx);
|
|
996
|
+
const meta = await buildTxMetaData(tx, allowedSetupCalls);
|
|
816
997
|
loaded.push({ tx, meta });
|
|
817
998
|
} catch (err) {
|
|
818
999
|
this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, { err });
|
|
@@ -857,7 +1038,9 @@ export class TxPoolV2Impl {
|
|
|
857
1038
|
if (preAddResult.shouldIgnore) {
|
|
858
1039
|
// Transaction rejected - mark for deletion from DB
|
|
859
1040
|
rejected.push(meta.txHash);
|
|
860
|
-
this.#log.debug(
|
|
1041
|
+
this.#log.debug(
|
|
1042
|
+
`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`,
|
|
1043
|
+
);
|
|
861
1044
|
continue;
|
|
862
1045
|
}
|
|
863
1046
|
|
|
@@ -893,7 +1076,7 @@ export class TxPoolV2Impl {
|
|
|
893
1076
|
getFeePayerPendingTxs: (feePayer: string) => this.#indices.getFeePayerPendingTxs(feePayer),
|
|
894
1077
|
getPendingTxCount: () => this.#indices.getPendingTxCount(),
|
|
895
1078
|
getLowestPriorityPending: (limit: number) => this.#indices.getLowestPriorityPending(limit),
|
|
896
|
-
deleteTxs: (txHashes: string[]) => this.#
|
|
1079
|
+
deleteTxs: (txHashes: string[], reason?: string) => this.#evictTxs(txHashes, reason ?? 'unknown'),
|
|
897
1080
|
};
|
|
898
1081
|
}
|
|
899
1082
|
|