@aztec/p2p 0.0.1-commit.64b6bbb → 0.0.1-commit.684755437
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +7 -7
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +24 -30
- package/dest/client/interface.d.ts +14 -19
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +9 -18
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +52 -96
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
- package/dest/config.d.ts +31 -15
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +71 -37
- 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/mem_pools/attestation_pool/attestation_pool.d.ts +4 -2
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +10 -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/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/eviction/invalid_txs_after_mining_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +30 -13
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +91 -20
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -2
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +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 +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 +22 -6
- 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 +48 -14
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +100 -17
- 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 +9 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +14 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +300 -142
- 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 +48 -36
- 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/factory.d.ts +114 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +219 -58
- package/dest/msg_validators/tx_validator/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 +58 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
- package/dest/msg_validators/tx_validator/index.d.ts +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 +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +44 -23
- 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/dummy_service.d.ts +4 -4
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +4 -4
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +9 -8
- 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 +16 -13
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +84 -90
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +2 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +19 -46
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +2 -1
- package/dest/services/service.d.ts +5 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +13 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +30 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +39 -33
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +38 -29
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +126 -77
- 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 +49 -16
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/dest/services/tx_collection/slow_tx_collection.d.ts +5 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +17 -12
- package/dest/services/tx_collection/tx_collection.d.ts +9 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +26 -10
- 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 +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/tx_file_store.d.ts +3 -2
- 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 +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 +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +8 -2
- 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 +8 -3
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +7 -1
- 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 +15 -14
- 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 -2
- 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 +41 -49
- package/src/client/interface.ts +17 -20
- package/src/client/p2p_client.ts +60 -126
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +20 -11
- package/src/config.ts +100 -43
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +13 -4
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool/README.md +1 -1
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/README.md +52 -28
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +109 -22
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +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 +1 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +24 -6
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +145 -25
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +21 -7
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +333 -138
- 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 +63 -40
- package/src/msg_validators/tx_validator/README.md +115 -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/factory.ts +353 -77
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +90 -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 +51 -26
- package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
- package/src/services/dummy_service.ts +6 -6
- package/src/services/encoding.ts +7 -7
- 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 +95 -96
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +20 -48
- package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/reqresp.ts +3 -1
- package/src/services/service.ts +11 -2
- package/src/services/tx_collection/config.ts +42 -0
- package/src/services/tx_collection/fast_tx_collection.ts +51 -30
- package/src/services/tx_collection/file_store_tx_collection.ts +143 -93
- package/src/services/tx_collection/file_store_tx_source.ts +64 -17
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
- package/src/services/tx_collection/slow_tx_collection.ts +17 -13
- package/src/services/tx_collection/tx_collection.ts +45 -14
- package/src/services/tx_collection/tx_collection_sink.ts +15 -29
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/tx_file_store.ts +6 -4
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +1 -3
- package/src/test-helpers/mock-pubsub.ts +13 -6
- package/src/test-helpers/reqresp-nodes.ts +3 -6
- package/src/test-helpers/testbench-utils.ts +11 -3
- package/src/testbench/p2p_client_testbench_worker.ts +24 -20
- package/src/testbench/worker_client_manager.ts +13 -5
- package/src/util.ts +8 -2
- 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/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
|
@@ -6,7 +6,8 @@ import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
|
6
6
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
7
7
|
import { TxArchive } from './archive/index.js';
|
|
8
8
|
import { DeletedPool } from './deleted_pool.js';
|
|
9
|
-
import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule } from './eviction/index.js';
|
|
9
|
+
import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule, TxPoolRejectionCode } from './eviction/index.js';
|
|
10
|
+
import { TxPoolV2Instrumentation } from './instrumentation.js';
|
|
10
11
|
import { DEFAULT_TX_POOL_V2_CONFIG } from './interfaces.js';
|
|
11
12
|
import { buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
|
|
12
13
|
import { TxPoolIndices } from './tx_pool_indices.js';
|
|
@@ -29,9 +30,12 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
29
30
|
#archive;
|
|
30
31
|
#deletedPool;
|
|
31
32
|
#evictionManager;
|
|
33
|
+
#dateProvider;
|
|
34
|
+
#instrumentation;
|
|
35
|
+
#evictedTxHashes = new Set();
|
|
32
36
|
#log;
|
|
33
37
|
#callbacks;
|
|
34
|
-
constructor(store, archiveStore, deps, callbacks, config = {}, log){
|
|
38
|
+
constructor(store, archiveStore, deps, callbacks, telemetry, config = {}, dateProvider, log){
|
|
35
39
|
this.#store = store;
|
|
36
40
|
this.#txsDB = store.openMap('txs');
|
|
37
41
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
@@ -43,6 +47,8 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
43
47
|
};
|
|
44
48
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
45
49
|
this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
|
|
50
|
+
this.#dateProvider = dateProvider;
|
|
51
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, ()=>this.#indices.getTotalMetadataBytes());
|
|
46
52
|
this.#log = log;
|
|
47
53
|
this.#callbacks = callbacks;
|
|
48
54
|
// Setup eviction manager with rules
|
|
@@ -112,14 +118,43 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
112
118
|
await this.#txsDB.delete(txHashStr);
|
|
113
119
|
}
|
|
114
120
|
});
|
|
115
|
-
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup
|
|
121
|
+
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`, {
|
|
122
|
+
txHashes: toDelete
|
|
123
|
+
});
|
|
116
124
|
}
|
|
117
125
|
async addPendingTxs(txs, opts) {
|
|
118
126
|
const accepted = [];
|
|
119
127
|
const ignored = [];
|
|
120
128
|
const rejected = [];
|
|
129
|
+
const errors = new Map();
|
|
121
130
|
const acceptedPending = new Set();
|
|
131
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
132
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
133
|
+
const precomputed = new Map();
|
|
134
|
+
const validator = await this.#createTxValidator();
|
|
135
|
+
for (const tx of txs){
|
|
136
|
+
const txHash = tx.getTxHash();
|
|
137
|
+
const txHashStr = txHash.toString();
|
|
138
|
+
const meta = await buildTxMetaData(tx);
|
|
139
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
140
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
141
|
+
let isValid = true;
|
|
142
|
+
if (!minedBlockId) {
|
|
143
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
144
|
+
}
|
|
145
|
+
precomputed.set(txHashStr, {
|
|
146
|
+
meta,
|
|
147
|
+
minedBlockId,
|
|
148
|
+
isValid
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
152
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
122
153
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
154
|
+
const preAddContext = opts.feeComparisonOnly !== undefined ? {
|
|
155
|
+
feeComparisonOnly: opts.feeComparisonOnly,
|
|
156
|
+
priceBumpPercentage: this.#config.priceBumpPercentage
|
|
157
|
+
} : undefined;
|
|
123
158
|
await this.#store.transactionAsync(async ()=>{
|
|
124
159
|
for (const tx of txs){
|
|
125
160
|
const txHash = tx.getTxHash();
|
|
@@ -129,82 +164,112 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
129
164
|
ignored.push(txHash);
|
|
130
165
|
continue;
|
|
131
166
|
}
|
|
132
|
-
|
|
133
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
167
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr);
|
|
134
168
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
135
169
|
if (minedBlockId) {
|
|
136
170
|
// Already mined - add directly (protection already set if pre-protected)
|
|
137
171
|
await this.#addTx(tx, {
|
|
138
172
|
mined: minedBlockId
|
|
139
|
-
}, opts);
|
|
173
|
+
}, opts, meta);
|
|
140
174
|
accepted.push(txHash);
|
|
141
175
|
} else if (preProtectedSlot !== undefined) {
|
|
142
176
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
143
177
|
await this.#addTx(tx, {
|
|
144
178
|
protected: preProtectedSlot
|
|
145
|
-
}, opts);
|
|
179
|
+
}, opts, meta);
|
|
146
180
|
accepted.push(txHash);
|
|
181
|
+
} else if (!isValid) {
|
|
182
|
+
// Failed pre-computed validation
|
|
183
|
+
rejected.push(txHash);
|
|
147
184
|
} else {
|
|
148
|
-
// Regular pending tx -
|
|
149
|
-
const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored);
|
|
185
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
186
|
+
const result = await this.#tryAddRegularPendingTx(tx, meta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
|
|
150
187
|
if (result.status === 'accepted') {
|
|
151
188
|
acceptedPending.add(txHashStr);
|
|
152
|
-
} else if (result.status === 'rejected') {
|
|
153
|
-
rejected.push(txHash);
|
|
154
189
|
} else {
|
|
155
190
|
ignored.push(txHash);
|
|
156
191
|
}
|
|
157
192
|
}
|
|
158
193
|
}
|
|
194
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
195
|
+
if (acceptedPending.size > 0) {
|
|
196
|
+
const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
|
|
197
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
198
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
|
|
199
|
+
...uniqueFeePayers
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
159
202
|
});
|
|
160
203
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
161
204
|
for (const txHashStr of acceptedPending){
|
|
162
205
|
accepted.push(TxHash.fromString(txHashStr));
|
|
163
206
|
}
|
|
164
|
-
//
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
]);
|
|
207
|
+
// Record metrics
|
|
208
|
+
if (ignored.length > 0) {
|
|
209
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
210
|
+
}
|
|
211
|
+
if (rejected.length > 0) {
|
|
212
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
171
213
|
}
|
|
172
214
|
return {
|
|
173
215
|
accepted,
|
|
174
216
|
ignored,
|
|
175
|
-
rejected
|
|
217
|
+
rejected,
|
|
218
|
+
...errors.size > 0 ? {
|
|
219
|
+
errors
|
|
220
|
+
} : {}
|
|
176
221
|
};
|
|
177
222
|
}
|
|
178
|
-
/**
|
|
179
|
-
const
|
|
180
|
-
const txHashStr = txHash.toString();
|
|
181
|
-
// Build metadata and validate using metadata
|
|
182
|
-
const meta = await buildTxMetaData(tx);
|
|
183
|
-
if (!await this.#validateMeta(meta)) {
|
|
184
|
-
return {
|
|
185
|
-
status: 'rejected'
|
|
186
|
-
};
|
|
187
|
-
}
|
|
223
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */ async #tryAddRegularPendingTx(tx, precomputedMeta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
|
|
224
|
+
const txHashStr = tx.getTxHash().toString();
|
|
188
225
|
// Run pre-add rules
|
|
189
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(
|
|
226
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
190
227
|
if (preAddResult.shouldIgnore) {
|
|
191
|
-
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
|
|
228
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
229
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
230
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
231
|
+
}
|
|
192
232
|
return {
|
|
193
233
|
status: 'ignored'
|
|
194
234
|
};
|
|
195
235
|
}
|
|
196
|
-
// Evict conflicts
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
236
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
237
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
238
|
+
const byReason = new Map();
|
|
239
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions){
|
|
240
|
+
const group = byReason.get(reason);
|
|
241
|
+
if (group) {
|
|
242
|
+
group.push(evictHash);
|
|
243
|
+
} else {
|
|
244
|
+
byReason.set(reason, [
|
|
245
|
+
evictHash
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
204
248
|
}
|
|
249
|
+
for (const [reason, hashes] of byReason){
|
|
250
|
+
await this.#evictTxs(hashes, reason);
|
|
251
|
+
}
|
|
252
|
+
for (const evictHashStr of preAddResult.txHashesToEvict){
|
|
253
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
254
|
+
evictedTxHash: evictHashStr,
|
|
255
|
+
replacementTxHash: txHashStr
|
|
256
|
+
});
|
|
257
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
258
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
259
|
+
acceptedPending.delete(evictHashStr);
|
|
260
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
265
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
266
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
267
|
+
return {
|
|
268
|
+
status: 'accepted'
|
|
269
|
+
};
|
|
205
270
|
}
|
|
206
271
|
// Add the transaction
|
|
207
|
-
await this.#addTx(tx, 'pending', opts);
|
|
272
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
208
273
|
return {
|
|
209
274
|
status: 'accepted'
|
|
210
275
|
};
|
|
@@ -215,13 +280,8 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
215
280
|
if (this.#indices.has(txHashStr)) {
|
|
216
281
|
return 'ignored';
|
|
217
282
|
}
|
|
218
|
-
// Build metadata and
|
|
283
|
+
// Build metadata and check pre-add rules
|
|
219
284
|
const meta = await buildTxMetaData(tx);
|
|
220
|
-
const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
|
|
221
|
-
if (validationResult !== true) {
|
|
222
|
-
return 'rejected';
|
|
223
|
-
}
|
|
224
|
-
// Use pre-add rules
|
|
225
285
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
226
286
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
227
287
|
return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
|
|
@@ -257,20 +317,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
257
317
|
}
|
|
258
318
|
});
|
|
259
319
|
}
|
|
260
|
-
protectTxs(txHashes, block) {
|
|
320
|
+
async protectTxs(txHashes, block) {
|
|
261
321
|
const slotNumber = block.globalVariables.slotNumber;
|
|
262
322
|
const missing = [];
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
323
|
+
let softDeletedHits = 0;
|
|
324
|
+
let missingPreviouslyEvicted = 0;
|
|
325
|
+
await this.#store.transactionAsync(async ()=>{
|
|
326
|
+
for (const txHash of txHashes){
|
|
327
|
+
const txHashStr = txHash.toString();
|
|
328
|
+
if (this.#indices.has(txHashStr)) {
|
|
329
|
+
// Update protection for existing tx
|
|
330
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
331
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
332
|
+
// Resurrect soft-deleted tx as protected
|
|
333
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
334
|
+
if (buffer) {
|
|
335
|
+
const tx = Tx.fromBuffer(buffer);
|
|
336
|
+
await this.#addTx(tx, {
|
|
337
|
+
protected: slotNumber
|
|
338
|
+
});
|
|
339
|
+
softDeletedHits++;
|
|
340
|
+
} else {
|
|
341
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
342
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
343
|
+
missing.push(txHash);
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
347
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
348
|
+
missing.push(txHash);
|
|
349
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
350
|
+
missingPreviouslyEvicted++;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
272
353
|
}
|
|
354
|
+
});
|
|
355
|
+
// Record metrics
|
|
356
|
+
if (softDeletedHits > 0) {
|
|
357
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
358
|
+
}
|
|
359
|
+
if (missing.length > 0) {
|
|
360
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
|
|
361
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
362
|
+
}
|
|
363
|
+
if (missingPreviouslyEvicted > 0) {
|
|
364
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
273
365
|
}
|
|
366
|
+
this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
|
|
274
367
|
return missing;
|
|
275
368
|
}
|
|
276
369
|
async addMinedTxs(txs, block, opts) {
|
|
@@ -309,45 +402,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
309
402
|
found.push(meta);
|
|
310
403
|
}
|
|
311
404
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
405
|
+
await this.#store.transactionAsync(async ()=>{
|
|
406
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
407
|
+
for (const meta of found){
|
|
408
|
+
this.#indices.markAsMined(meta, blockId);
|
|
409
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
410
|
+
}
|
|
411
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
412
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
413
|
+
});
|
|
414
|
+
if (found.length > 0) {
|
|
415
|
+
this.#callbacks.onTxsMined(found.map((m)=>m.txHash));
|
|
316
416
|
}
|
|
317
|
-
// Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
|
|
318
|
-
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
319
417
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
320
418
|
}
|
|
321
419
|
async prepareForSlot(slotNumber) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
420
|
+
await this.#store.transactionAsync(async ()=>{
|
|
421
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
422
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
423
|
+
// Step 1: Find expired protected txs
|
|
424
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
425
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
426
|
+
this.#indices.clearProtection(expiredProtected);
|
|
427
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
428
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
429
|
+
if (txsToRestore.length === 0) {
|
|
430
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
434
|
+
// Step 4: Validate for pending pool
|
|
435
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
436
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
437
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
438
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
439
|
+
await this.#deleteTxsBatch(invalid);
|
|
440
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
441
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
442
|
+
if (added.length > 0) {
|
|
443
|
+
const feePayers = added.map((meta)=>meta.feePayer);
|
|
444
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
445
|
+
await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
|
|
446
|
+
...uniqueFeePayers
|
|
447
|
+
]);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
349
450
|
}
|
|
350
|
-
async handlePrunedBlocks(latestBlock) {
|
|
451
|
+
async handlePrunedBlocks(latestBlock, options) {
|
|
351
452
|
// Step 1: Find transactions mined after the prune point
|
|
352
453
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
353
454
|
if (txsToUnmine.length === 0) {
|
|
@@ -355,61 +456,80 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
355
456
|
return;
|
|
356
457
|
}
|
|
357
458
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
459
|
+
await this.#store.transactionAsync(async ()=>{
|
|
460
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
461
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
462
|
+
// when their original mined block is finalized
|
|
463
|
+
await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
|
|
464
|
+
txHash: m.txHash,
|
|
465
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId.number)
|
|
466
|
+
})));
|
|
467
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
468
|
+
for (const meta of txsToUnmine){
|
|
469
|
+
this.#indices.markAsUnmined(meta);
|
|
470
|
+
}
|
|
471
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
472
|
+
if (options?.deleteAllTxs) {
|
|
473
|
+
const allTxHashes = txsToUnmine.map((m)=>m.txHash);
|
|
474
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
475
|
+
this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
479
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
480
|
+
// Step 5: Validate for pending pool
|
|
481
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
482
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
483
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
484
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
485
|
+
await this.#deleteTxsBatch(invalid);
|
|
486
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
487
|
+
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`, {
|
|
488
|
+
txHashesRestored: valid.map((m)=>m.txHash),
|
|
489
|
+
txHashesInvalid: invalid,
|
|
490
|
+
txHashesEvicted: toEvict
|
|
491
|
+
});
|
|
492
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
493
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
494
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
495
|
+
});
|
|
383
496
|
}
|
|
384
497
|
async handleFailedExecution(txHashes) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
498
|
+
await this.#store.transactionAsync(async ()=>{
|
|
499
|
+
await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
|
|
500
|
+
});
|
|
501
|
+
this.#log.info(`Deleted ${txHashes.length} failed txs`, {
|
|
502
|
+
txHashes: txHashes.map((h)=>h.toString())
|
|
503
|
+
});
|
|
388
504
|
}
|
|
389
505
|
async handleFinalizedBlock(block) {
|
|
390
506
|
const blockNumber = block.globalVariables.blockNumber;
|
|
391
507
|
// Step 1: Find mined txs at or before finalized block
|
|
392
508
|
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
509
|
+
await this.#store.transactionAsync(async ()=>{
|
|
510
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
511
|
+
const txsToArchive = [];
|
|
512
|
+
if (this.#archive.isEnabled()) {
|
|
513
|
+
for (const txHashStr of minedTxsToFinalize){
|
|
514
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
515
|
+
if (buffer) {
|
|
516
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
517
|
+
}
|
|
400
518
|
}
|
|
401
519
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
520
|
+
// Step 3: Delete mined txs from active pool
|
|
521
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
522
|
+
// Step 4: Finalize soft-deleted txs
|
|
523
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
524
|
+
// Step 5: Archive mined txs
|
|
525
|
+
if (txsToArchive.length > 0) {
|
|
526
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
411
529
|
if (minedTxsToFinalize.length > 0) {
|
|
412
|
-
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}
|
|
530
|
+
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
531
|
+
txHashes: minedTxsToFinalize
|
|
532
|
+
});
|
|
413
533
|
}
|
|
414
534
|
}
|
|
415
535
|
// === Query Methods ===
|
|
@@ -448,6 +568,12 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
448
568
|
...this.#indices.iteratePendingByPriority('desc')
|
|
449
569
|
].map((hash)=>TxHash.fromString(hash));
|
|
450
570
|
}
|
|
571
|
+
getEligiblePendingTxHashes() {
|
|
572
|
+
const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
|
|
573
|
+
return [
|
|
574
|
+
...this.#indices.iterateEligiblePendingByPriority('desc', maxReceivedAt)
|
|
575
|
+
].map((hash)=>TxHash.fromString(hash));
|
|
576
|
+
}
|
|
451
577
|
getPendingTxCount() {
|
|
452
578
|
return this.#indices.getPendingTxCount();
|
|
453
579
|
}
|
|
@@ -487,6 +613,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
487
613
|
this.#config.archivedTxLimit = config.archivedTxLimit;
|
|
488
614
|
this.#archive.updateLimit(config.archivedTxLimit);
|
|
489
615
|
}
|
|
616
|
+
if (config.minTxPoolAgeMs !== undefined) {
|
|
617
|
+
this.#config.minTxPoolAgeMs = config.minTxPoolAgeMs;
|
|
618
|
+
}
|
|
490
619
|
// Update eviction rules with new config
|
|
491
620
|
this.#evictionManager.updateConfig(config);
|
|
492
621
|
}
|
|
@@ -501,7 +630,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
501
630
|
}
|
|
502
631
|
// === Metrics ===
|
|
503
632
|
countTxs() {
|
|
504
|
-
return
|
|
633
|
+
return {
|
|
634
|
+
...this.#indices.countTxs(),
|
|
635
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount()
|
|
636
|
+
};
|
|
505
637
|
}
|
|
506
638
|
// ============================================================================
|
|
507
639
|
// PRIVATE HELPERS - Transaction Management
|
|
@@ -509,10 +641,12 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
509
641
|
/**
|
|
510
642
|
* Adds a new transaction to the pool with the specified state.
|
|
511
643
|
* Emits onTxsAdded callback immediately after DB write.
|
|
512
|
-
*/ async #addTx(tx, state, opts = {}) {
|
|
644
|
+
*/ async #addTx(tx, state, opts = {}, precomputedMeta) {
|
|
513
645
|
const txHashStr = tx.getTxHash().toString();
|
|
514
|
-
const meta = await buildTxMetaData(tx);
|
|
646
|
+
const meta = precomputedMeta ?? await buildTxMetaData(tx);
|
|
647
|
+
meta.receivedAt = this.#dateProvider.now();
|
|
515
648
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
649
|
+
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
516
650
|
this.#callbacks.onTxsAdded([
|
|
517
651
|
tx
|
|
518
652
|
], opts);
|
|
@@ -525,9 +659,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
525
659
|
this.#indices.addMined(meta);
|
|
526
660
|
}
|
|
527
661
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
528
|
-
this.#log.
|
|
662
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
529
663
|
eventName: 'tx-added-to-pool',
|
|
530
|
-
|
|
664
|
+
txHash: txHashStr,
|
|
665
|
+
state: stateStr,
|
|
666
|
+
source: opts.source
|
|
531
667
|
});
|
|
532
668
|
return meta;
|
|
533
669
|
}
|
|
@@ -550,6 +686,28 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
550
686
|
await this.#deleteTx(txHashStr);
|
|
551
687
|
}
|
|
552
688
|
}
|
|
689
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
|
|
690
|
+
if (txHashes.length === 0) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
694
|
+
for (const txHashStr of txHashes){
|
|
695
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, {
|
|
696
|
+
txHash: txHashStr,
|
|
697
|
+
reason
|
|
698
|
+
});
|
|
699
|
+
this.#addToEvictedCache(txHashStr);
|
|
700
|
+
}
|
|
701
|
+
await this.#deleteTxsBatch(txHashes);
|
|
702
|
+
}
|
|
703
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
|
|
704
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
705
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
706
|
+
const oldest = this.#evictedTxHashes.values().next().value;
|
|
707
|
+
this.#evictedTxHashes.delete(oldest);
|
|
708
|
+
}
|
|
709
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
710
|
+
}
|
|
553
711
|
// ============================================================================
|
|
554
712
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
555
713
|
// ============================================================================
|
|
@@ -688,7 +846,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
688
846
|
if (preAddResult.shouldIgnore) {
|
|
689
847
|
// Transaction rejected - mark for deletion from DB
|
|
690
848
|
rejected.push(meta.txHash);
|
|
691
|
-
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
|
|
849
|
+
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
692
850
|
continue;
|
|
693
851
|
}
|
|
694
852
|
// Evict any conflicting txs identified by pre-add rules
|
|
@@ -724,7 +882,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
724
882
|
getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
|
|
725
883
|
getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
|
|
726
884
|
getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
|
|
727
|
-
deleteTxs: (txHashes)=>this.#
|
|
885
|
+
deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
|
|
728
886
|
};
|
|
729
887
|
}
|
|
730
888
|
#createPreAddPoolAccess() {
|