@aztec/p2p 0.0.1-commit.21ecf947b → 0.0.1-commit.2448fdb
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 +6 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +31 -28
- package/dest/client/interface.d.ts +10 -19
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +7 -18
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +51 -96
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
- package/dest/config.d.ts +29 -10
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +80 -31
- 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/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +4 -4
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
- 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 +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 +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +5 -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 +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 +18 -6
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +3 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +49 -9
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +102 -14
- 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 +21 -12
- 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 +9 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +11 -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 +279 -153
- 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/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 +67 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/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/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 +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 +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 +97 -93
- 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 +5 -9
- 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/tx_validator.js +2 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +17 -9
- package/dest/services/service.d.ts +5 -3
- package/dest/services/service.d.ts.map +1 -1
- 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 +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/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 +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 -4
- 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 +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 +6 -3
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +3 -2
- 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 +13 -12
- 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 +4 -1
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +53 -46
- package/src/client/interface.ts +11 -20
- package/src/client/p2p_client.ts +55 -126
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
- package/src/config.ts +115 -33
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
- package/src/mem_pools/tx_pool/priority.ts +4 -4
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
- package/src/mem_pools/tx_pool_v2/README.md +9 -1
- 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 +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 +2 -2
- 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 +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 +17 -6
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +143 -17
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +25 -14
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +25 -8
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +311 -148
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
- package/src/msg_validators/tx_validator/README.md +119 -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/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 +394 -78
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/services/dummy_service.ts +6 -6
- package/src/services/encoding.ts +16 -8
- 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 +111 -101
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +6 -6
- 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/tx_validator.ts +2 -2
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/reqresp.ts +19 -11
- package/src/services/service.ts +11 -2
- package/src/services/tx_collection/fast_tx_collection.ts +51 -30
- 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/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 +8 -9
- package/src/services/tx_collection/tx_collection.ts +4 -3
- 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 +0 -2
- package/src/test-helpers/mock-pubsub.ts +13 -6
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/test-helpers/testbench-utils.ts +4 -3
- package/src/testbench/p2p_client_testbench_worker.ts +21 -17
- package/src/testbench/worker_client_manager.ts +11 -4
- package/src/util.ts +7 -1
- 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';
|
|
@@ -22,6 +23,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
22
23
|
#l2BlockSource;
|
|
23
24
|
#worldStateSynchronizer;
|
|
24
25
|
#createTxValidator;
|
|
26
|
+
#checkAllowedSetupCalls;
|
|
25
27
|
// === In-Memory Indices ===
|
|
26
28
|
#indices = new TxPoolIndices();
|
|
27
29
|
// === Config & Services ===
|
|
@@ -30,14 +32,17 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
30
32
|
#deletedPool;
|
|
31
33
|
#evictionManager;
|
|
32
34
|
#dateProvider;
|
|
35
|
+
#instrumentation;
|
|
36
|
+
#evictedTxHashes = new Set();
|
|
33
37
|
#log;
|
|
34
38
|
#callbacks;
|
|
35
|
-
constructor(store, archiveStore, deps, callbacks, config = {}, dateProvider, log){
|
|
39
|
+
constructor(store, archiveStore, deps, callbacks, telemetry, config = {}, dateProvider, log){
|
|
36
40
|
this.#store = store;
|
|
37
41
|
this.#txsDB = store.openMap('txs');
|
|
38
42
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
39
43
|
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
40
44
|
this.#createTxValidator = deps.createTxValidator;
|
|
45
|
+
this.#checkAllowedSetupCalls = deps.checkAllowedSetupCalls;
|
|
41
46
|
this.#config = {
|
|
42
47
|
...DEFAULT_TX_POOL_V2_CONFIG,
|
|
43
48
|
...config
|
|
@@ -45,6 +50,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
45
50
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
46
51
|
this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
|
|
47
52
|
this.#dateProvider = dateProvider;
|
|
53
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, ()=>this.#indices.getTotalMetadataBytes());
|
|
48
54
|
this.#log = log;
|
|
49
55
|
this.#callbacks = callbacks;
|
|
50
56
|
// Setup eviction manager with rules
|
|
@@ -122,8 +128,35 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
122
128
|
const accepted = [];
|
|
123
129
|
const ignored = [];
|
|
124
130
|
const rejected = [];
|
|
131
|
+
const errors = new Map();
|
|
125
132
|
const acceptedPending = new Set();
|
|
133
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
134
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
135
|
+
const precomputed = new Map();
|
|
136
|
+
const validator = await this.#createTxValidator();
|
|
137
|
+
for (const tx of txs){
|
|
138
|
+
const txHash = tx.getTxHash();
|
|
139
|
+
const txHashStr = txHash.toString();
|
|
140
|
+
const meta = await buildTxMetaData(tx);
|
|
141
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
142
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
143
|
+
let isValid = true;
|
|
144
|
+
if (!minedBlockId) {
|
|
145
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
146
|
+
}
|
|
147
|
+
precomputed.set(txHashStr, {
|
|
148
|
+
meta,
|
|
149
|
+
minedBlockId,
|
|
150
|
+
isValid
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
154
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
126
155
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
156
|
+
const preAddContext = opts.feeComparisonOnly !== undefined ? {
|
|
157
|
+
feeComparisonOnly: opts.feeComparisonOnly,
|
|
158
|
+
priceBumpPercentage: this.#config.priceBumpPercentage
|
|
159
|
+
} : undefined;
|
|
127
160
|
await this.#store.transactionAsync(async ()=>{
|
|
128
161
|
for (const tx of txs){
|
|
129
162
|
const txHash = tx.getTxHash();
|
|
@@ -133,85 +166,105 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
133
166
|
ignored.push(txHash);
|
|
134
167
|
continue;
|
|
135
168
|
}
|
|
136
|
-
|
|
137
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
169
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr);
|
|
138
170
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
139
171
|
if (minedBlockId) {
|
|
140
172
|
// Already mined - add directly (protection already set if pre-protected)
|
|
141
173
|
await this.#addTx(tx, {
|
|
142
174
|
mined: minedBlockId
|
|
143
|
-
}, opts);
|
|
175
|
+
}, opts, meta);
|
|
144
176
|
accepted.push(txHash);
|
|
145
177
|
} else if (preProtectedSlot !== undefined) {
|
|
146
178
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
147
179
|
await this.#addTx(tx, {
|
|
148
180
|
protected: preProtectedSlot
|
|
149
|
-
}, opts);
|
|
181
|
+
}, opts, meta);
|
|
150
182
|
accepted.push(txHash);
|
|
183
|
+
} else if (!isValid) {
|
|
184
|
+
// Failed pre-computed validation
|
|
185
|
+
rejected.push(txHash);
|
|
151
186
|
} else {
|
|
152
|
-
// Regular pending tx -
|
|
153
|
-
const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored);
|
|
187
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
188
|
+
const result = await this.#tryAddRegularPendingTx(tx, meta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
|
|
154
189
|
if (result.status === 'accepted') {
|
|
155
190
|
acceptedPending.add(txHashStr);
|
|
156
|
-
} else if (result.status === 'rejected') {
|
|
157
|
-
rejected.push(txHash);
|
|
158
191
|
} else {
|
|
159
192
|
ignored.push(txHash);
|
|
160
193
|
}
|
|
161
194
|
}
|
|
162
195
|
}
|
|
196
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
197
|
+
if (acceptedPending.size > 0) {
|
|
198
|
+
const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
|
|
199
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
200
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [
|
|
201
|
+
...uniqueFeePayers
|
|
202
|
+
]);
|
|
203
|
+
}
|
|
163
204
|
});
|
|
164
205
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
165
206
|
for (const txHashStr of acceptedPending){
|
|
166
207
|
accepted.push(TxHash.fromString(txHashStr));
|
|
167
208
|
}
|
|
168
|
-
//
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
]);
|
|
209
|
+
// Record metrics
|
|
210
|
+
if (ignored.length > 0) {
|
|
211
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
212
|
+
}
|
|
213
|
+
if (rejected.length > 0) {
|
|
214
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
175
215
|
}
|
|
176
216
|
return {
|
|
177
217
|
accepted,
|
|
178
218
|
ignored,
|
|
179
|
-
rejected
|
|
219
|
+
rejected,
|
|
220
|
+
...errors.size > 0 ? {
|
|
221
|
+
errors
|
|
222
|
+
} : {}
|
|
180
223
|
};
|
|
181
224
|
}
|
|
182
|
-
/**
|
|
183
|
-
const
|
|
184
|
-
const txHashStr = txHash.toString();
|
|
185
|
-
// Build metadata and validate using metadata
|
|
186
|
-
const meta = await buildTxMetaData(tx);
|
|
187
|
-
if (!await this.#validateMeta(meta)) {
|
|
188
|
-
return {
|
|
189
|
-
status: 'rejected'
|
|
190
|
-
};
|
|
191
|
-
}
|
|
225
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */ async #tryAddRegularPendingTx(tx, precomputedMeta, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
|
|
226
|
+
const txHashStr = tx.getTxHash().toString();
|
|
192
227
|
// Run pre-add rules
|
|
193
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(
|
|
228
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
194
229
|
if (preAddResult.shouldIgnore) {
|
|
195
|
-
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
|
|
230
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
231
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
232
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
233
|
+
}
|
|
196
234
|
return {
|
|
197
235
|
status: 'ignored'
|
|
198
236
|
};
|
|
199
237
|
}
|
|
200
|
-
// Evict conflicts
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
238
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
239
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
240
|
+
const byReason = new Map();
|
|
241
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions){
|
|
242
|
+
const group = byReason.get(reason);
|
|
243
|
+
if (group) {
|
|
244
|
+
group.push(evictHash);
|
|
245
|
+
} else {
|
|
246
|
+
byReason.set(reason, [
|
|
247
|
+
evictHash
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const [reason, hashes] of byReason){
|
|
252
|
+
await this.#evictTxs(hashes, reason);
|
|
253
|
+
}
|
|
254
|
+
for (const evictHashStr of preAddResult.txHashesToEvict){
|
|
255
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
256
|
+
evictedTxHash: evictHashStr,
|
|
257
|
+
replacementTxHash: txHashStr
|
|
258
|
+
});
|
|
259
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
260
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
261
|
+
acceptedPending.delete(evictHashStr);
|
|
262
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
263
|
+
}
|
|
211
264
|
}
|
|
212
265
|
}
|
|
213
266
|
// Add the transaction
|
|
214
|
-
await this.#addTx(tx, 'pending', opts);
|
|
267
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
215
268
|
return {
|
|
216
269
|
status: 'accepted'
|
|
217
270
|
};
|
|
@@ -222,36 +275,35 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
222
275
|
if (this.#indices.has(txHashStr)) {
|
|
223
276
|
return 'ignored';
|
|
224
277
|
}
|
|
225
|
-
// Build metadata and
|
|
278
|
+
// Build metadata and check pre-add rules
|
|
226
279
|
const meta = await buildTxMetaData(tx);
|
|
227
|
-
const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
|
|
228
|
-
if (validationResult !== true) {
|
|
229
|
-
return 'rejected';
|
|
230
|
-
}
|
|
231
|
-
// Use pre-add rules
|
|
232
280
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
233
281
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
234
282
|
return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
|
|
235
283
|
}
|
|
236
284
|
async addProtectedTxs(txs, block, opts) {
|
|
237
285
|
const slotNumber = block.globalVariables.slotNumber;
|
|
286
|
+
// Precompute setup-call allow-list flags outside the store transaction
|
|
287
|
+
const allowedFlags = await Promise.all(txs.map((tx)=>this.#checkAllowedSetupCalls(tx)));
|
|
238
288
|
await this.#store.transactionAsync(async ()=>{
|
|
239
|
-
for
|
|
289
|
+
for(let i = 0; i < txs.length; i++){
|
|
290
|
+
const tx = txs[i];
|
|
240
291
|
const txHash = tx.getTxHash();
|
|
241
292
|
const txHashStr = txHash.toString();
|
|
242
293
|
const isNew = !this.#indices.has(txHashStr);
|
|
243
294
|
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
244
295
|
if (isNew) {
|
|
296
|
+
const meta = await buildTxMetaData(tx, allowedFlags[i]);
|
|
245
297
|
// New tx - add as mined or protected (callback emitted by #addTx)
|
|
246
298
|
if (minedBlockId) {
|
|
247
299
|
await this.#addTx(tx, {
|
|
248
300
|
mined: minedBlockId
|
|
249
|
-
}, opts);
|
|
301
|
+
}, opts, meta);
|
|
250
302
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
251
303
|
} else {
|
|
252
304
|
await this.#addTx(tx, {
|
|
253
305
|
protected: slotNumber
|
|
254
|
-
}, opts);
|
|
306
|
+
}, opts, meta);
|
|
255
307
|
}
|
|
256
308
|
} else {
|
|
257
309
|
// Existing tx - update protection and mined status
|
|
@@ -264,20 +316,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
264
316
|
}
|
|
265
317
|
});
|
|
266
318
|
}
|
|
267
|
-
protectTxs(txHashes, block) {
|
|
319
|
+
async protectTxs(txHashes, block) {
|
|
268
320
|
const slotNumber = block.globalVariables.slotNumber;
|
|
269
321
|
const missing = [];
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
322
|
+
let softDeletedHits = 0;
|
|
323
|
+
let missingPreviouslyEvicted = 0;
|
|
324
|
+
await this.#store.transactionAsync(async ()=>{
|
|
325
|
+
for (const txHash of txHashes){
|
|
326
|
+
const txHashStr = txHash.toString();
|
|
327
|
+
if (this.#indices.has(txHashStr)) {
|
|
328
|
+
// Update protection for existing tx
|
|
329
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
330
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
331
|
+
// Resurrect soft-deleted tx as protected
|
|
332
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
333
|
+
if (buffer) {
|
|
334
|
+
const tx = Tx.fromBuffer(buffer);
|
|
335
|
+
await this.#addTx(tx, {
|
|
336
|
+
protected: slotNumber
|
|
337
|
+
});
|
|
338
|
+
softDeletedHits++;
|
|
339
|
+
} else {
|
|
340
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
341
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
342
|
+
missing.push(txHash);
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
346
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
347
|
+
missing.push(txHash);
|
|
348
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
349
|
+
missingPreviouslyEvicted++;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
279
352
|
}
|
|
353
|
+
});
|
|
354
|
+
// Record metrics
|
|
355
|
+
if (softDeletedHits > 0) {
|
|
356
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
357
|
+
}
|
|
358
|
+
if (missing.length > 0) {
|
|
359
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
|
|
360
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
280
361
|
}
|
|
362
|
+
if (missingPreviouslyEvicted > 0) {
|
|
363
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
364
|
+
}
|
|
365
|
+
this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
|
|
281
366
|
return missing;
|
|
282
367
|
}
|
|
283
368
|
async addMinedTxs(txs, block, opts) {
|
|
@@ -316,47 +401,50 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
316
401
|
found.push(meta);
|
|
317
402
|
}
|
|
318
403
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
404
|
+
await this.#store.transactionAsync(async ()=>{
|
|
405
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
406
|
+
for (const meta of found){
|
|
407
|
+
this.#indices.markAsMined(meta, blockId);
|
|
408
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
409
|
+
}
|
|
410
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
411
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
412
|
+
});
|
|
326
413
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
327
414
|
}
|
|
328
415
|
async prepareForSlot(slotNumber) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
416
|
+
await this.#store.transactionAsync(async ()=>{
|
|
417
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
418
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
419
|
+
// Step 1: Find expired protected txs
|
|
420
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
421
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
422
|
+
this.#indices.clearProtection(expiredProtected);
|
|
423
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
424
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
425
|
+
if (txsToRestore.length === 0) {
|
|
426
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
430
|
+
// Step 4: Validate for pending pool
|
|
431
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
432
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
433
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
434
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
435
|
+
await this.#deleteTxsBatch(invalid);
|
|
436
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
437
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
438
|
+
if (added.length > 0) {
|
|
439
|
+
const feePayers = added.map((meta)=>meta.feePayer);
|
|
440
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
441
|
+
await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
|
|
442
|
+
...uniqueFeePayers
|
|
443
|
+
]);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
358
446
|
}
|
|
359
|
-
async handlePrunedBlocks(latestBlock) {
|
|
447
|
+
async handlePrunedBlocks(latestBlock, options) {
|
|
360
448
|
// Step 1: Find transactions mined after the prune point
|
|
361
449
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
362
450
|
if (txsToUnmine.length === 0) {
|
|
@@ -364,40 +452,48 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
364
452
|
return;
|
|
365
453
|
}
|
|
366
454
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
455
|
+
await this.#store.transactionAsync(async ()=>{
|
|
456
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
457
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
458
|
+
// when their original mined block is finalized
|
|
459
|
+
await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
|
|
460
|
+
txHash: m.txHash,
|
|
461
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId.number)
|
|
462
|
+
})));
|
|
463
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
464
|
+
for (const meta of txsToUnmine){
|
|
465
|
+
this.#indices.markAsUnmined(meta);
|
|
466
|
+
}
|
|
467
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
468
|
+
if (options?.deleteAllTxs) {
|
|
469
|
+
const allTxHashes = txsToUnmine.map((m)=>m.txHash);
|
|
470
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
471
|
+
this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
475
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
476
|
+
// Step 5: Validate for pending pool
|
|
477
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
478
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
479
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
480
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
481
|
+
await this.#deleteTxsBatch(invalid);
|
|
482
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
483
|
+
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`, {
|
|
484
|
+
txHashesRestored: valid.map((m)=>m.txHash),
|
|
485
|
+
txHashesInvalid: invalid,
|
|
486
|
+
txHashesEvicted: toEvict
|
|
487
|
+
});
|
|
488
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
489
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
490
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
393
491
|
});
|
|
394
|
-
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
395
|
-
// This handles cases like existing pending txs with invalid fee payer balances
|
|
396
|
-
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
397
492
|
}
|
|
398
493
|
async handleFailedExecution(txHashes) {
|
|
399
|
-
|
|
400
|
-
|
|
494
|
+
await this.#store.transactionAsync(async ()=>{
|
|
495
|
+
await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
|
|
496
|
+
});
|
|
401
497
|
this.#log.info(`Deleted ${txHashes.length} failed txs`, {
|
|
402
498
|
txHashes: txHashes.map((h)=>h.toString())
|
|
403
499
|
});
|
|
@@ -406,24 +502,26 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
406
502
|
const blockNumber = block.globalVariables.blockNumber;
|
|
407
503
|
// Step 1: Find mined txs at or before finalized block
|
|
408
504
|
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
505
|
+
await this.#store.transactionAsync(async ()=>{
|
|
506
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
507
|
+
const txsToArchive = [];
|
|
508
|
+
if (this.#archive.isEnabled()) {
|
|
509
|
+
for (const txHashStr of minedTxsToFinalize){
|
|
510
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
511
|
+
if (buffer) {
|
|
512
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
513
|
+
}
|
|
416
514
|
}
|
|
417
515
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
516
|
+
// Step 3: Delete mined txs from active pool
|
|
517
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
518
|
+
// Step 4: Finalize soft-deleted txs
|
|
519
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
520
|
+
// Step 5: Archive mined txs
|
|
521
|
+
if (txsToArchive.length > 0) {
|
|
522
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
427
525
|
if (minedTxsToFinalize.length > 0) {
|
|
428
526
|
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
429
527
|
txHashes: minedTxsToFinalize
|
|
@@ -528,7 +626,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
528
626
|
}
|
|
529
627
|
// === Metrics ===
|
|
530
628
|
countTxs() {
|
|
531
|
-
return
|
|
629
|
+
return {
|
|
630
|
+
...this.#indices.countTxs(),
|
|
631
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount()
|
|
632
|
+
};
|
|
532
633
|
}
|
|
533
634
|
// ============================================================================
|
|
534
635
|
// PRIVATE HELPERS - Transaction Management
|
|
@@ -536,9 +637,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
536
637
|
/**
|
|
537
638
|
* Adds a new transaction to the pool with the specified state.
|
|
538
639
|
* Emits onTxsAdded callback immediately after DB write.
|
|
539
|
-
*/ async #addTx(tx, state, opts = {}) {
|
|
640
|
+
*/ async #addTx(tx, state, opts = {}, precomputedMeta) {
|
|
540
641
|
const txHashStr = tx.getTxHash().toString();
|
|
541
|
-
const meta = await buildTxMetaData(tx);
|
|
642
|
+
const meta = precomputedMeta ?? await buildTxMetaData(tx);
|
|
542
643
|
meta.receivedAt = this.#dateProvider.now();
|
|
543
644
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
544
645
|
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
@@ -554,9 +655,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
554
655
|
this.#indices.addMined(meta);
|
|
555
656
|
}
|
|
556
657
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
557
|
-
this.#log.
|
|
658
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
558
659
|
eventName: 'tx-added-to-pool',
|
|
559
|
-
|
|
660
|
+
txHash: txHashStr,
|
|
661
|
+
state: stateStr,
|
|
662
|
+
source: opts.source
|
|
560
663
|
});
|
|
561
664
|
return meta;
|
|
562
665
|
}
|
|
@@ -579,6 +682,28 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
579
682
|
await this.#deleteTx(txHashStr);
|
|
580
683
|
}
|
|
581
684
|
}
|
|
685
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
|
|
686
|
+
if (txHashes.length === 0) {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
690
|
+
for (const txHashStr of txHashes){
|
|
691
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, {
|
|
692
|
+
txHash: txHashStr,
|
|
693
|
+
reason
|
|
694
|
+
});
|
|
695
|
+
this.#addToEvictedCache(txHashStr);
|
|
696
|
+
}
|
|
697
|
+
await this.#deleteTxsBatch(txHashes);
|
|
698
|
+
}
|
|
699
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
|
|
700
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
701
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
702
|
+
const oldest = this.#evictedTxHashes.values().next().value;
|
|
703
|
+
this.#evictedTxHashes.delete(oldest);
|
|
704
|
+
}
|
|
705
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
706
|
+
}
|
|
582
707
|
// ============================================================================
|
|
583
708
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
584
709
|
// ============================================================================
|
|
@@ -669,7 +794,8 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
669
794
|
}
|
|
670
795
|
try {
|
|
671
796
|
const tx = Tx.fromBuffer(buffer);
|
|
672
|
-
const
|
|
797
|
+
const allowedSetupCalls = await this.#checkAllowedSetupCalls(tx);
|
|
798
|
+
const meta = await buildTxMetaData(tx, allowedSetupCalls);
|
|
673
799
|
loaded.push({
|
|
674
800
|
tx,
|
|
675
801
|
meta
|
|
@@ -717,7 +843,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
717
843
|
if (preAddResult.shouldIgnore) {
|
|
718
844
|
// Transaction rejected - mark for deletion from DB
|
|
719
845
|
rejected.push(meta.txHash);
|
|
720
|
-
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
|
|
846
|
+
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
721
847
|
continue;
|
|
722
848
|
}
|
|
723
849
|
// Evict any conflicting txs identified by pre-add rules
|
|
@@ -753,7 +879,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
753
879
|
getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
|
|
754
880
|
getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
|
|
755
881
|
getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
|
|
756
|
-
deleteTxs: (txHashes)=>this.#
|
|
882
|
+
deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
|
|
757
883
|
};
|
|
758
884
|
}
|
|
759
885
|
#createPreAddPoolAccess() {
|