@aztec/p2p 0.0.1-commit.6d63667d → 0.0.1-commit.7ac86ea28
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 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +46 -11
- package/dest/client/interface.d.ts +43 -23
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +38 -42
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +145 -145
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -6
- package/dest/config.d.ts +23 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -1
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -88
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +353 -87
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -2
- package/dest/mem_pools/index.d.ts +3 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/interface.d.ts +5 -5
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +4 -1
- 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 +10 -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 +48 -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 +5 -3
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +1 -1
- 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 +8 -4
- 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 +14 -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 +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +16 -4
- 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 +31 -5
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +62 -5
- 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 +27 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +8 -3
- 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 +11 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +12 -4
- 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 +239 -109
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/dummy_service.d.ts +12 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +9 -0
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +4 -3
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +346 -0
- package/dest/services/libp2p/libp2p_service.d.ts +85 -35
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +370 -267
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +25 -2
- 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/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +11 -4
- package/dest/services/service.d.ts +38 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +19 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +46 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +56 -36
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +90 -0
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/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 +7 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +60 -26
- package/dest/services/tx_collection/tx_collection.d.ts +23 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +75 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +26 -29
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +9 -6
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +5 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +29 -2
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +103 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -1
- package/dest/test-helpers/testbench-utils.d.ts +43 -38
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +128 -59
- 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 +10 -10
- 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 +86 -15
- package/src/client/interface.ts +59 -23
- package/src/client/p2p_client.ts +184 -167
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -9
- package/src/config.ts +34 -2
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +496 -91
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +442 -102
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/index.ts +4 -1
- package/src/mem_pools/interface.ts +4 -4
- 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 +76 -10
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +4 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +15 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +49 -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 +3 -3
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +8 -7
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +24 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +3 -3
- package/src/mem_pools/tx_pool_v2/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +16 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +90 -9
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +32 -5
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +17 -6
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +274 -104
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +17 -1
- package/src/services/encoding.ts +4 -3
- package/src/services/gossipsub/README.md +641 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +487 -0
- package/src/services/libp2p/libp2p_service.ts +367 -271
- package/src/services/peer-manager/peer_scoring.ts +25 -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/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +4 -3
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +13 -3
- package/src/services/service.ts +50 -1
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +65 -32
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +1 -0
- 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 +66 -33
- package/src/services/tx_collection/tx_collection.ts +113 -16
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +10 -8
- package/src/services/tx_provider.ts +8 -7
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +143 -3
- package/src/test-helpers/reqresp-nodes.ts +2 -1
- package/src/test-helpers/testbench-utils.ts +127 -71
- package/src/testbench/p2p_client_testbench_worker.ts +22 -15
- package/src/util.ts +7 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
2
3
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
3
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
5
6
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
6
7
|
import { TxArchive } from './archive/index.js';
|
|
7
|
-
import {
|
|
8
|
+
import { DeletedPool } from './deleted_pool.js';
|
|
9
|
+
import { EvictionManager, FeePayerBalanceEvictionRule, FeePayerBalancePreAddRule, InvalidTxsAfterMiningRule, InvalidTxsAfterReorgRule, LowPriorityEvictionRule, LowPriorityPreAddRule, NullifierConflictRule, TxPoolRejectionCode } from './eviction/index.js';
|
|
10
|
+
import { TxPoolV2Instrumentation } from './instrumentation.js';
|
|
8
11
|
import { DEFAULT_TX_POOL_V2_CONFIG } from './interfaces.js';
|
|
9
12
|
import { buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
|
|
10
13
|
import { TxPoolIndices } from './tx_pool_indices.js';
|
|
@@ -19,26 +22,33 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
19
22
|
// === Dependencies ===
|
|
20
23
|
#l2BlockSource;
|
|
21
24
|
#worldStateSynchronizer;
|
|
22
|
-
#
|
|
25
|
+
#createTxValidator;
|
|
23
26
|
// === In-Memory Indices ===
|
|
24
27
|
#indices = new TxPoolIndices();
|
|
25
28
|
// === Config & Services ===
|
|
26
29
|
#config;
|
|
27
30
|
#archive;
|
|
31
|
+
#deletedPool;
|
|
28
32
|
#evictionManager;
|
|
33
|
+
#dateProvider;
|
|
34
|
+
#instrumentation;
|
|
35
|
+
#evictedTxHashes = new Set();
|
|
29
36
|
#log;
|
|
30
37
|
#callbacks;
|
|
31
|
-
constructor(store, archiveStore, deps, callbacks, config = {}, log){
|
|
38
|
+
constructor(store, archiveStore, deps, callbacks, telemetry, config = {}, dateProvider, log){
|
|
32
39
|
this.#store = store;
|
|
33
40
|
this.#txsDB = store.openMap('txs');
|
|
34
41
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
35
42
|
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
36
|
-
this.#
|
|
43
|
+
this.#createTxValidator = deps.createTxValidator;
|
|
37
44
|
this.#config = {
|
|
38
45
|
...DEFAULT_TX_POOL_V2_CONFIG,
|
|
39
46
|
...config
|
|
40
47
|
};
|
|
41
48
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
49
|
+
this.#deletedPool = new DeletedPool(store, this.#txsDB, log);
|
|
50
|
+
this.#dateProvider = dateProvider;
|
|
51
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, ()=>this.#indices.getTotalMetadataBytes());
|
|
42
52
|
this.#log = log;
|
|
43
53
|
this.#callbacks = callbacks;
|
|
44
54
|
// Setup eviction manager with rules
|
|
@@ -69,7 +79,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
69
79
|
* Note: Protected status is lost on restart. All non-mined txs are rebuilt as pending
|
|
70
80
|
* by running pre-add rules to resolve nullifier conflicts, balance checks, and pool size limits.
|
|
71
81
|
*/ async hydrateFromDatabase() {
|
|
72
|
-
// Step
|
|
82
|
+
// Step 0: Hydrate deleted pool state
|
|
83
|
+
await this.#deletedPool.hydrateFromDatabase();
|
|
84
|
+
// Step 1: Load all transactions from DB (excluding soft-deleted)
|
|
73
85
|
const { loaded, errors: deserializationErrors } = await this.#loadAllTxsFromDb();
|
|
74
86
|
// Step 2: Check mined status for each tx
|
|
75
87
|
await this.#markMinedStatusBatch(loaded.map((l)=>l.meta));
|
|
@@ -84,7 +96,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
98
|
// Step 4: Validate non-mined transactions
|
|
87
|
-
const { valid, invalid } = await this.#
|
|
99
|
+
const { valid, invalid } = await this.#revalidateMetadata(nonMined.map((e)=>e.meta), 'on startup');
|
|
88
100
|
// Step 5: Populate mined indices (these don't need conflict resolution)
|
|
89
101
|
for (const meta of mined){
|
|
90
102
|
this.#indices.addMined(meta);
|
|
@@ -106,14 +118,20 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
106
118
|
await this.#txsDB.delete(txHashStr);
|
|
107
119
|
}
|
|
108
120
|
});
|
|
109
|
-
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
|
+
});
|
|
110
124
|
}
|
|
111
125
|
async addPendingTxs(txs, opts) {
|
|
112
126
|
const accepted = [];
|
|
113
127
|
const ignored = [];
|
|
114
128
|
const rejected = [];
|
|
129
|
+
const errors = new Map();
|
|
115
130
|
const acceptedPending = new Set();
|
|
116
131
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
132
|
+
const preAddContext = opts.feeComparisonOnly !== undefined ? {
|
|
133
|
+
feeComparisonOnly: opts.feeComparisonOnly
|
|
134
|
+
} : undefined;
|
|
117
135
|
await this.#store.transactionAsync(async ()=>{
|
|
118
136
|
for (const tx of txs){
|
|
119
137
|
const txHash = tx.getTxHash();
|
|
@@ -140,7 +158,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
140
158
|
accepted.push(txHash);
|
|
141
159
|
} else {
|
|
142
160
|
// Regular pending tx - validate and run pre-add rules
|
|
143
|
-
const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored);
|
|
161
|
+
const result = await this.#tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored, errors, preAddContext);
|
|
144
162
|
if (result.status === 'accepted') {
|
|
145
163
|
acceptedPending.add(txHashStr);
|
|
146
164
|
} else if (result.status === 'rejected') {
|
|
@@ -155,6 +173,13 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
155
173
|
for (const txHashStr of acceptedPending){
|
|
156
174
|
accepted.push(TxHash.fromString(txHashStr));
|
|
157
175
|
}
|
|
176
|
+
// Record metrics
|
|
177
|
+
if (ignored.length > 0) {
|
|
178
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
179
|
+
}
|
|
180
|
+
if (rejected.length > 0) {
|
|
181
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
182
|
+
}
|
|
158
183
|
// Run post-add eviction rules for pending txs
|
|
159
184
|
if (acceptedPending.size > 0) {
|
|
160
185
|
const feePayers = Array.from(acceptedPending).map((txHash)=>this.#indices.getMetadata(txHash).feePayer);
|
|
@@ -166,35 +191,59 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
166
191
|
return {
|
|
167
192
|
accepted,
|
|
168
193
|
ignored,
|
|
169
|
-
rejected
|
|
194
|
+
rejected,
|
|
195
|
+
...errors.size > 0 ? {
|
|
196
|
+
errors
|
|
197
|
+
} : {}
|
|
170
198
|
};
|
|
171
199
|
}
|
|
172
|
-
/** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored) {
|
|
200
|
+
/** Validates and adds a regular pending tx. Returns status. */ async #tryAddRegularPendingTx(tx, opts, poolAccess, acceptedPending, ignored, errors, preAddContext) {
|
|
173
201
|
const txHash = tx.getTxHash();
|
|
174
202
|
const txHashStr = txHash.toString();
|
|
175
|
-
//
|
|
176
|
-
|
|
203
|
+
// Build metadata and validate using metadata
|
|
204
|
+
const meta = await buildTxMetaData(tx);
|
|
205
|
+
if (!await this.#validateMeta(meta)) {
|
|
177
206
|
return {
|
|
178
207
|
status: 'rejected'
|
|
179
208
|
};
|
|
180
209
|
}
|
|
181
|
-
//
|
|
182
|
-
const
|
|
183
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
210
|
+
// Run pre-add rules
|
|
211
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess, preAddContext);
|
|
184
212
|
if (preAddResult.shouldIgnore) {
|
|
185
|
-
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
|
|
213
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
214
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
215
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
216
|
+
}
|
|
186
217
|
return {
|
|
187
218
|
status: 'ignored'
|
|
188
219
|
};
|
|
189
220
|
}
|
|
190
|
-
// Evict conflicts
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
221
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
222
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
223
|
+
const byReason = new Map();
|
|
224
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions){
|
|
225
|
+
const group = byReason.get(reason);
|
|
226
|
+
if (group) {
|
|
227
|
+
group.push(evictHash);
|
|
228
|
+
} else {
|
|
229
|
+
byReason.set(reason, [
|
|
230
|
+
evictHash
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
for (const [reason, hashes] of byReason){
|
|
235
|
+
await this.#evictTxs(hashes, reason);
|
|
236
|
+
}
|
|
237
|
+
for (const evictHashStr of preAddResult.txHashesToEvict){
|
|
238
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
239
|
+
evictedTxHash: evictHashStr,
|
|
240
|
+
replacementTxHash: txHashStr
|
|
241
|
+
});
|
|
242
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
243
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
244
|
+
acceptedPending.delete(evictHashStr);
|
|
245
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
246
|
+
}
|
|
198
247
|
}
|
|
199
248
|
}
|
|
200
249
|
// Add the transaction
|
|
@@ -209,13 +258,13 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
209
258
|
if (this.#indices.has(txHashStr)) {
|
|
210
259
|
return 'ignored';
|
|
211
260
|
}
|
|
212
|
-
//
|
|
213
|
-
const
|
|
214
|
-
|
|
261
|
+
// Build metadata and validate using metadata
|
|
262
|
+
const meta = await buildTxMetaData(tx);
|
|
263
|
+
const validationResult = await this.#validateMeta(meta, undefined, 'can add pending');
|
|
264
|
+
if (validationResult !== true) {
|
|
215
265
|
return 'rejected';
|
|
216
266
|
}
|
|
217
|
-
//
|
|
218
|
-
const meta = await buildTxMetaData(tx);
|
|
267
|
+
// Use pre-add rules
|
|
219
268
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
220
269
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
221
270
|
return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
|
|
@@ -251,20 +300,51 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
251
300
|
}
|
|
252
301
|
});
|
|
253
302
|
}
|
|
254
|
-
protectTxs(txHashes, block) {
|
|
303
|
+
async protectTxs(txHashes, block) {
|
|
255
304
|
const slotNumber = block.globalVariables.slotNumber;
|
|
256
305
|
const missing = [];
|
|
306
|
+
let softDeletedHits = 0;
|
|
307
|
+
let missingPreviouslyEvicted = 0;
|
|
257
308
|
for (const txHash of txHashes){
|
|
258
309
|
const txHashStr = txHash.toString();
|
|
259
310
|
if (this.#indices.has(txHashStr)) {
|
|
260
311
|
// Update protection for existing tx
|
|
261
312
|
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
313
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
314
|
+
// Resurrect soft-deleted tx as protected
|
|
315
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
316
|
+
if (buffer) {
|
|
317
|
+
const tx = Tx.fromBuffer(buffer);
|
|
318
|
+
await this.#addTx(tx, {
|
|
319
|
+
protected: slotNumber
|
|
320
|
+
});
|
|
321
|
+
softDeletedHits++;
|
|
322
|
+
} else {
|
|
323
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
324
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
325
|
+
missing.push(txHash);
|
|
326
|
+
}
|
|
262
327
|
} else {
|
|
263
|
-
//
|
|
328
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
264
329
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
265
330
|
missing.push(txHash);
|
|
331
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
332
|
+
missingPreviouslyEvicted++;
|
|
333
|
+
}
|
|
266
334
|
}
|
|
267
335
|
}
|
|
336
|
+
// Record metrics
|
|
337
|
+
if (softDeletedHits > 0) {
|
|
338
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
339
|
+
}
|
|
340
|
+
if (missing.length > 0) {
|
|
341
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
|
|
342
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
343
|
+
}
|
|
344
|
+
if (missingPreviouslyEvicted > 0) {
|
|
345
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
346
|
+
}
|
|
347
|
+
this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
|
|
268
348
|
return missing;
|
|
269
349
|
}
|
|
270
350
|
async addMinedTxs(txs, block, opts) {
|
|
@@ -283,6 +363,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
283
363
|
mined: blockId
|
|
284
364
|
}, opts);
|
|
285
365
|
}
|
|
366
|
+
await this.#deletedPool.clearIfMinedHigher(txHashStr, blockId.number);
|
|
286
367
|
}
|
|
287
368
|
});
|
|
288
369
|
}
|
|
@@ -305,12 +386,15 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
305
386
|
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
306
387
|
for (const meta of found){
|
|
307
388
|
this.#indices.markAsMined(meta, blockId);
|
|
389
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
308
390
|
}
|
|
309
391
|
// Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
|
|
310
392
|
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
311
393
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
312
394
|
}
|
|
313
395
|
async prepareForSlot(slotNumber) {
|
|
396
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
397
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
314
398
|
// Step 1: Find expired protected txs
|
|
315
399
|
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
316
400
|
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
@@ -318,18 +402,17 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
318
402
|
// Step 3: Filter to only txs that have metadata and are not mined
|
|
319
403
|
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
320
404
|
if (txsToRestore.length === 0) {
|
|
405
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
321
406
|
return;
|
|
322
407
|
}
|
|
323
408
|
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
324
409
|
// Step 4: Validate for pending pool
|
|
325
|
-
const { valid, invalid } = await this.#
|
|
410
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
326
411
|
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
327
412
|
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
328
|
-
// Step 6: Delete invalid and
|
|
329
|
-
await this.#deleteTxsBatch(
|
|
330
|
-
|
|
331
|
-
...toEvict
|
|
332
|
-
]);
|
|
413
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
414
|
+
await this.#deleteTxsBatch(invalid);
|
|
415
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
333
416
|
// Step 7: Run eviction rules (enforce pool size limit)
|
|
334
417
|
if (added.length > 0) {
|
|
335
418
|
const feePayers = added.map((meta)=>meta.feePayer);
|
|
@@ -339,7 +422,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
339
422
|
]);
|
|
340
423
|
}
|
|
341
424
|
}
|
|
342
|
-
async handlePrunedBlocks(latestBlock) {
|
|
425
|
+
async handlePrunedBlocks(latestBlock, options) {
|
|
343
426
|
// Step 1: Find transactions mined after the prune point
|
|
344
427
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
345
428
|
if (txsToUnmine.length === 0) {
|
|
@@ -347,54 +430,76 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
347
430
|
return;
|
|
348
431
|
}
|
|
349
432
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
350
|
-
// Step 2:
|
|
433
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
434
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
435
|
+
// when their original mined block is finalized
|
|
436
|
+
await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
|
|
437
|
+
txHash: m.txHash,
|
|
438
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId.number)
|
|
439
|
+
})));
|
|
440
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
351
441
|
for (const meta of txsToUnmine){
|
|
352
442
|
this.#indices.markAsUnmined(meta);
|
|
353
443
|
}
|
|
354
|
-
//
|
|
444
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
445
|
+
if (options?.deleteAllTxs) {
|
|
446
|
+
const allTxHashes = txsToUnmine.map((m)=>m.txHash);
|
|
447
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
448
|
+
this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
355
452
|
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
356
|
-
// Step
|
|
357
|
-
const { valid, invalid } = await this.#
|
|
358
|
-
// Step
|
|
453
|
+
// Step 5: Validate for pending pool
|
|
454
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
455
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
359
456
|
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
360
|
-
// Step
|
|
361
|
-
await this.#deleteTxsBatch(
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
457
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
458
|
+
await this.#deleteTxsBatch(invalid);
|
|
459
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
460
|
+
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`, {
|
|
461
|
+
txHashesRestored: valid.map((m)=>m.txHash),
|
|
462
|
+
txHashesInvalid: invalid,
|
|
463
|
+
txHashesEvicted: toEvict
|
|
464
|
+
});
|
|
465
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
366
466
|
// This handles cases like existing pending txs with invalid fee payer balances
|
|
367
467
|
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
368
468
|
}
|
|
369
469
|
async handleFailedExecution(txHashes) {
|
|
370
470
|
// Delete failed txs
|
|
371
471
|
await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
|
|
372
|
-
this.#log.info(`Deleted ${txHashes.length} failed txs
|
|
472
|
+
this.#log.info(`Deleted ${txHashes.length} failed txs`, {
|
|
473
|
+
txHashes: txHashes.map((h)=>h.toString())
|
|
474
|
+
});
|
|
373
475
|
}
|
|
374
476
|
async handleFinalizedBlock(block) {
|
|
375
477
|
const blockNumber = block.globalVariables.blockNumber;
|
|
376
|
-
// Step 1: Find txs
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
// Step 2: Collect txs for archiving (before deletion)
|
|
478
|
+
// Step 1: Find mined txs at or before finalized block
|
|
479
|
+
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
480
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
382
481
|
const txsToArchive = [];
|
|
383
482
|
if (this.#archive.isEnabled()) {
|
|
384
|
-
for (const txHashStr of
|
|
483
|
+
for (const txHashStr of minedTxsToFinalize){
|
|
385
484
|
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
386
485
|
if (buffer) {
|
|
387
486
|
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
388
487
|
}
|
|
389
488
|
}
|
|
390
489
|
}
|
|
391
|
-
// Step 3: Delete from active pool
|
|
392
|
-
await this.#deleteTxsBatch(
|
|
393
|
-
// Step 4:
|
|
490
|
+
// Step 3: Delete mined txs from active pool
|
|
491
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
492
|
+
// Step 4: Finalize soft-deleted txs
|
|
493
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
494
|
+
// Step 5: Archive mined txs
|
|
394
495
|
if (txsToArchive.length > 0) {
|
|
395
496
|
await this.#archive.archiveTxs(txsToArchive);
|
|
396
497
|
}
|
|
397
|
-
|
|
498
|
+
if (minedTxsToFinalize.length > 0) {
|
|
499
|
+
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
500
|
+
txHashes: minedTxsToFinalize
|
|
501
|
+
});
|
|
502
|
+
}
|
|
398
503
|
}
|
|
399
504
|
// === Query Methods ===
|
|
400
505
|
async getTxByHash(txHash) {
|
|
@@ -410,20 +515,34 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
410
515
|
return results;
|
|
411
516
|
}
|
|
412
517
|
hasTxs(txHashes) {
|
|
413
|
-
return txHashes.map((h)=>
|
|
518
|
+
return txHashes.map((h)=>{
|
|
519
|
+
const hashStr = h.toString();
|
|
520
|
+
return this.#indices.has(hashStr) || this.#deletedPool.isSoftDeleted(hashStr);
|
|
521
|
+
});
|
|
414
522
|
}
|
|
415
523
|
getTxStatus(txHash) {
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
524
|
+
const txHashStr = txHash.toString();
|
|
525
|
+
const meta = this.#indices.getMetadata(txHashStr);
|
|
526
|
+
if (meta) {
|
|
527
|
+
return this.#indices.getTxState(meta);
|
|
419
528
|
}
|
|
420
|
-
|
|
529
|
+
// Check if soft-deleted
|
|
530
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
531
|
+
return 'deleted';
|
|
532
|
+
}
|
|
533
|
+
return undefined;
|
|
421
534
|
}
|
|
422
535
|
getPendingTxHashes() {
|
|
423
536
|
return [
|
|
424
537
|
...this.#indices.iteratePendingByPriority('desc')
|
|
425
538
|
].map((hash)=>TxHash.fromString(hash));
|
|
426
539
|
}
|
|
540
|
+
getEligiblePendingTxHashes() {
|
|
541
|
+
const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
|
|
542
|
+
return [
|
|
543
|
+
...this.#indices.iterateEligiblePendingByPriority('desc', maxReceivedAt)
|
|
544
|
+
].map((hash)=>TxHash.fromString(hash));
|
|
545
|
+
}
|
|
427
546
|
getPendingTxCount() {
|
|
428
547
|
return this.#indices.getPendingTxCount();
|
|
429
548
|
}
|
|
@@ -463,6 +582,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
463
582
|
this.#config.archivedTxLimit = config.archivedTxLimit;
|
|
464
583
|
this.#archive.updateLimit(config.archivedTxLimit);
|
|
465
584
|
}
|
|
585
|
+
if (config.minTxPoolAgeMs !== undefined) {
|
|
586
|
+
this.#config.minTxPoolAgeMs = config.minTxPoolAgeMs;
|
|
587
|
+
}
|
|
466
588
|
// Update eviction rules with new config
|
|
467
589
|
this.#evictionManager.updateConfig(config);
|
|
468
590
|
}
|
|
@@ -477,7 +599,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
477
599
|
}
|
|
478
600
|
// === Metrics ===
|
|
479
601
|
countTxs() {
|
|
480
|
-
return
|
|
602
|
+
return {
|
|
603
|
+
...this.#indices.countTxs(),
|
|
604
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount()
|
|
605
|
+
};
|
|
481
606
|
}
|
|
482
607
|
// ============================================================================
|
|
483
608
|
// PRIVATE HELPERS - Transaction Management
|
|
@@ -488,7 +613,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
488
613
|
*/ async #addTx(tx, state, opts = {}) {
|
|
489
614
|
const txHashStr = tx.getTxHash().toString();
|
|
490
615
|
const meta = await buildTxMetaData(tx);
|
|
616
|
+
meta.receivedAt = this.#dateProvider.now();
|
|
491
617
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
618
|
+
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
492
619
|
this.#callbacks.onTxsAdded([
|
|
493
620
|
tx
|
|
494
621
|
], opts);
|
|
@@ -501,64 +628,74 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
501
628
|
this.#indices.addMined(meta);
|
|
502
629
|
}
|
|
503
630
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
504
|
-
this.#log.
|
|
631
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
505
632
|
eventName: 'tx-added-to-pool',
|
|
506
|
-
|
|
633
|
+
txHash: txHashStr,
|
|
634
|
+
state: stateStr,
|
|
635
|
+
source: opts.source
|
|
507
636
|
});
|
|
508
637
|
return meta;
|
|
509
638
|
}
|
|
510
639
|
/**
|
|
511
640
|
* Deletes a transaction from both indices and DB.
|
|
512
641
|
* Emits onTxsRemoved callback immediately after DB delete.
|
|
642
|
+
*/ /**
|
|
643
|
+
* Deletes a transaction from the pool.
|
|
644
|
+
* Delegates to DeletedPool which decides soft vs hard delete based on whether
|
|
645
|
+
* the tx is from a pruned block.
|
|
513
646
|
*/ async #deleteTx(txHashStr) {
|
|
514
647
|
this.#indices.remove(txHashStr);
|
|
515
|
-
await this.#txsDB.delete(txHashStr);
|
|
516
648
|
this.#callbacks.onTxsRemoved([
|
|
517
649
|
txHashStr
|
|
518
650
|
]);
|
|
651
|
+
await this.#deletedPool.deleteTx(txHashStr);
|
|
519
652
|
}
|
|
520
653
|
/** Deletes a batch of transactions, emitting callbacks individually for each. */ async #deleteTxsBatch(txHashes) {
|
|
521
654
|
for (const txHashStr of txHashes){
|
|
522
655
|
await this.#deleteTx(txHashStr);
|
|
523
656
|
}
|
|
524
657
|
}
|
|
658
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
|
|
659
|
+
if (txHashes.length === 0) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
663
|
+
for (const txHashStr of txHashes){
|
|
664
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, {
|
|
665
|
+
txHash: txHashStr,
|
|
666
|
+
reason
|
|
667
|
+
});
|
|
668
|
+
this.#addToEvictedCache(txHashStr);
|
|
669
|
+
}
|
|
670
|
+
await this.#deleteTxsBatch(txHashes);
|
|
671
|
+
}
|
|
672
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
|
|
673
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
674
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
675
|
+
const oldest = this.#evictedTxHashes.values().next().value;
|
|
676
|
+
this.#evictedTxHashes.delete(oldest);
|
|
677
|
+
}
|
|
678
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
679
|
+
}
|
|
525
680
|
// ============================================================================
|
|
526
681
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
527
682
|
// ============================================================================
|
|
528
|
-
/** Validates
|
|
529
|
-
const
|
|
683
|
+
/** Validates transaction metadata, returning true if valid */ async #validateMeta(meta, validator, context) {
|
|
684
|
+
const txValidator = validator ?? await this.#createTxValidator();
|
|
685
|
+
const result = await txValidator.validateTx(meta);
|
|
530
686
|
if (result.result !== 'valid') {
|
|
531
687
|
const contextStr = context ? ` ${context}` : '';
|
|
532
|
-
this.#log.info(`Tx ${
|
|
688
|
+
this.#log.info(`Tx ${meta.txHash}${contextStr} failed validation: ${result.reason?.join(', ')}`);
|
|
533
689
|
return false;
|
|
534
690
|
}
|
|
535
691
|
return true;
|
|
536
692
|
}
|
|
537
|
-
/**
|
|
538
|
-
const loaded = [];
|
|
539
|
-
const missing = [];
|
|
540
|
-
for (const meta of metas){
|
|
541
|
-
const buffer = await this.#txsDB.getAsync(meta.txHash);
|
|
542
|
-
if (!buffer) {
|
|
543
|
-
this.#log.warn(`Tx ${meta.txHash} not found in DB`);
|
|
544
|
-
missing.push(meta.txHash);
|
|
545
|
-
continue;
|
|
546
|
-
}
|
|
547
|
-
loaded.push({
|
|
548
|
-
tx: Tx.fromBuffer(buffer),
|
|
549
|
-
meta
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
return {
|
|
553
|
-
loaded,
|
|
554
|
-
missing
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
/** Validates a batch of transactions, returning valid and invalid groups */ async #validateTxBatch(txs, context) {
|
|
693
|
+
/** Validates metadata directly */ async #revalidateMetadata(metas, context) {
|
|
558
694
|
const valid = [];
|
|
559
695
|
const invalid = [];
|
|
560
|
-
|
|
561
|
-
|
|
696
|
+
const validator = await this.#createTxValidator();
|
|
697
|
+
for (const meta of metas){
|
|
698
|
+
if (await this.#validateMeta(meta, validator, context)) {
|
|
562
699
|
valid.push(meta);
|
|
563
700
|
} else {
|
|
564
701
|
invalid.push(meta.txHash);
|
|
@@ -569,17 +706,6 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
569
706
|
invalid
|
|
570
707
|
};
|
|
571
708
|
}
|
|
572
|
-
/** Loads transactions from DB and validates them */ async #loadAndValidateTxs(metas, context) {
|
|
573
|
-
const { loaded, missing } = await this.#loadTxsFromDb(metas);
|
|
574
|
-
const { valid, invalid } = await this.#validateTxBatch(loaded, context);
|
|
575
|
-
return {
|
|
576
|
-
valid,
|
|
577
|
-
invalid: [
|
|
578
|
-
...missing,
|
|
579
|
-
...invalid
|
|
580
|
-
]
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
709
|
/**
|
|
584
710
|
* Resolves nullifier conflicts between incoming txs and existing pending txs.
|
|
585
711
|
* Modifies the pending indices during iteration to maintain consistent state
|
|
@@ -635,6 +761,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
635
761
|
const loaded = [];
|
|
636
762
|
const errors = [];
|
|
637
763
|
for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()){
|
|
764
|
+
// Skip soft-deleted transactions - they stay in DB but not in indices
|
|
765
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
638
768
|
try {
|
|
639
769
|
const tx = Tx.fromBuffer(buffer);
|
|
640
770
|
const meta = await buildTxMetaData(tx);
|
|
@@ -685,7 +815,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
685
815
|
if (preAddResult.shouldIgnore) {
|
|
686
816
|
// Transaction rejected - mark for deletion from DB
|
|
687
817
|
rejected.push(meta.txHash);
|
|
688
|
-
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
|
|
818
|
+
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
689
819
|
continue;
|
|
690
820
|
}
|
|
691
821
|
// Evict any conflicting txs identified by pre-add rules
|
|
@@ -721,7 +851,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
721
851
|
getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
|
|
722
852
|
getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
|
|
723
853
|
getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
|
|
724
|
-
deleteTxs: (txHashes)=>this.#
|
|
854
|
+
deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
|
|
725
855
|
};
|
|
726
856
|
}
|
|
727
857
|
#createPreAddPoolAccess() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
2
|
import { type CheckpointAttestation, type ValidationResult } from '@aztec/stdlib/p2p';
|
|
3
3
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
-
import type {
|
|
4
|
+
import type { AttestationPoolApi } from '../../mem_pools/attestation_pool/attestation_pool.js';
|
|
5
5
|
import { CheckpointAttestationValidator } from './attestation_validator.js';
|
|
6
6
|
/**
|
|
7
7
|
* FishermanAttestationValidator extends the base AttestationValidator to add
|
|
@@ -14,7 +14,7 @@ import { CheckpointAttestationValidator } from './attestation_validator.js';
|
|
|
14
14
|
export declare class FishermanAttestationValidator extends CheckpointAttestationValidator {
|
|
15
15
|
private attestationPool;
|
|
16
16
|
private invalidAttestationCounter;
|
|
17
|
-
constructor(epochCache: EpochCacheInterface, attestationPool:
|
|
17
|
+
constructor(epochCache: EpochCacheInterface, attestationPool: AttestationPoolApi, telemetryClient: TelemetryClient);
|
|
18
18
|
validate(message: CheckpointAttestation): Promise<ValidationResult>;
|
|
19
19
|
}
|
|
20
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlzaGVybWFuX2F0dGVzdGF0aW9uX3ZhbGlkYXRvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21zZ192YWxpZGF0b3JzL2F0dGVzdGF0aW9uX3ZhbGlkYXRvci9maXNoZXJtYW5fYXR0ZXN0YXRpb25fdmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDOUQsT0FBTyxFQUFFLEtBQUsscUJBQXFCLEVBQXFCLEtBQUssZ0JBQWdCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUN6RyxPQUFPLEVBQXVCLEtBQUssZUFBZSxFQUFrQyxNQUFNLHlCQUF5QixDQUFDO0FBRXBILE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sc0RBQXNELENBQUM7QUFDL0YsT0FBTyxFQUFFLDhCQUE4QixFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFFNUU7Ozs7Ozs7R0FPRztBQUNILHFCQUFhLDZCQUE4QixTQUFRLDhCQUE4QjtJQUs3RSxPQUFPLENBQUMsZUFBZTtJQUp6QixPQUFPLENBQUMseUJBQXlCLENBQUM7SUFFbEMsWUFDRSxVQUFVLEVBQUUsbUJBQW1CLEVBQ3ZCLGVBQWUsRUFBRSxrQkFBa0IsRUFDM0MsZUFBZSxFQUFFLGVBQWUsRUFhakM7SUFFYyxRQUFRLENBQUMsT0FBTyxFQUFFLHFCQUFxQixHQUFHLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBQyxDQXdEakY7Q0FDRiJ9
|