@aztec/p2p 0.0.1-commit.4ad48494d → 0.0.1-commit.4d3c002
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 +7 -7
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +33 -29
- package/dest/client/interface.d.ts +18 -20
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +9 -19
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +72 -102
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +20 -10
- package/dest/config.d.ts +34 -15
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +86 -37
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +4 -4
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +11 -6
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
- 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 +1 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +3 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +9 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +18 -9
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +5 -4
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +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 +4 -4
- 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 +24 -10
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +4 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +54 -15
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +111 -19
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +5 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +38 -46
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +9 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +12 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +12 -5
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +296 -153
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +4 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +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/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/discv5/discV5_service.d.ts +1 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +5 -2
- package/dest/services/dummy_service.d.ts +7 -5
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +9 -5
- package/dest/services/encoding.d.ts +6 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +16 -9
- package/dest/services/gossipsub/topic_score_params.d.ts +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 +30 -22
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +241 -151
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +24 -9
- package/dest/services/peer-manager/peer_scoring.d.ts +5 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +28 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +83 -106
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/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 +19 -10
- package/dest/services/service.d.ts +11 -4
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +65 -75
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_collection.js +4 -2
- package/dest/services/tx_collection/file_store_tx_source.d.ts +16 -6
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/file_store_tx_source.js +50 -9
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +2 -2
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +10 -8
- package/dest/services/tx_collection/tx_collection.d.ts +5 -7
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.d.ts +6 -5
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +13 -22
- package/dest/services/tx_collection/tx_source.d.ts +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +26 -7
- package/dest/services/tx_file_store/tx_file_store.js +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +11 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +16 -3
- 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 +7 -3
- 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 +23 -4
- package/dest/testbench/p2p_client_testbench_worker.d.ts +2 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +56 -26
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -3
- package/dest/util.d.ts +9 -5
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +2 -10
- package/package.json +14 -14
- package/src/client/factory.ts +56 -48
- package/src/client/interface.ts +20 -21
- package/src/client/p2p_client.ts +78 -132
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +33 -14
- package/src/config.ts +125 -43
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +0 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +12 -9
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/index.ts +0 -3
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool_v2/README.md +10 -2
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +11 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +21 -8
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +5 -4
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +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 +4 -4
- 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 +24 -10
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +159 -27
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -46
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +28 -8
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +330 -149
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
- package/src/msg_validators/clock_tolerance.ts +4 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
- package/src/msg_validators/tx_validator/README.md +119 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +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/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/msg_validators/tx_validator/timestamp_validator.ts +7 -7
- package/src/services/discv5/discV5_service.ts +5 -2
- package/src/services/dummy_service.ts +12 -7
- 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 +262 -176
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +28 -9
- package/src/services/peer-manager/peer_scoring.ts +21 -5
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +79 -112
- package/src/services/reqresp/batch-tx-requester/interface.ts +3 -6
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/reqresp.ts +22 -12
- package/src/services/service.ts +20 -3
- package/src/services/tx_collection/fast_tx_collection.ts +71 -76
- package/src/services/tx_collection/file_store_tx_collection.ts +7 -3
- package/src/services/tx_collection/file_store_tx_source.ts +65 -9
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +8 -9
- package/src/services/tx_collection/tx_collection.ts +5 -6
- package/src/services/tx_collection/tx_collection_sink.ts +15 -29
- package/src/services/tx_collection/tx_source.ts +28 -8
- package/src/services/tx_file_store/tx_file_store.ts +1 -1
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +1 -3
- package/src/test-helpers/mock-pubsub.ts +20 -6
- package/src/test-helpers/reqresp-nodes.ts +7 -6
- package/src/test-helpers/testbench-utils.ts +32 -6
- package/src/testbench/p2p_client_testbench_worker.ts +62 -29
- package/src/testbench/worker_client_manager.ts +13 -6
- package/src/util.ts +15 -16
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
|
@@ -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,112 @@ 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);
|
|
211
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
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
267
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
268
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
269
|
+
return {
|
|
270
|
+
status: 'accepted'
|
|
271
|
+
};
|
|
212
272
|
}
|
|
213
273
|
// Add the transaction
|
|
214
|
-
await this.#addTx(tx, 'pending', opts);
|
|
274
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
215
275
|
return {
|
|
216
276
|
status: 'accepted'
|
|
217
277
|
};
|
|
@@ -220,38 +280,44 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
220
280
|
const txHashStr = tx.getTxHash().toString();
|
|
221
281
|
// Check if already in pool
|
|
222
282
|
if (this.#indices.has(txHashStr)) {
|
|
283
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
|
|
223
284
|
return 'ignored';
|
|
224
285
|
}
|
|
225
|
-
// Build metadata and
|
|
286
|
+
// Build metadata and check pre-add rules
|
|
226
287
|
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
288
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
233
289
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
234
|
-
|
|
290
|
+
if (preAddResult.shouldIgnore) {
|
|
291
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
|
|
292
|
+
reason: preAddResult.reason?.message ?? 'no reason provided'
|
|
293
|
+
});
|
|
294
|
+
return 'ignored';
|
|
295
|
+
}
|
|
296
|
+
return 'accepted';
|
|
235
297
|
}
|
|
236
298
|
async addProtectedTxs(txs, block, opts) {
|
|
237
299
|
const slotNumber = block.globalVariables.slotNumber;
|
|
300
|
+
// Precompute setup-call allow-list flags outside the store transaction
|
|
301
|
+
const allowedFlags = await Promise.all(txs.map((tx)=>this.#checkAllowedSetupCalls(tx)));
|
|
238
302
|
await this.#store.transactionAsync(async ()=>{
|
|
239
|
-
for
|
|
303
|
+
for(let i = 0; i < txs.length; i++){
|
|
304
|
+
const tx = txs[i];
|
|
240
305
|
const txHash = tx.getTxHash();
|
|
241
306
|
const txHashStr = txHash.toString();
|
|
242
307
|
const isNew = !this.#indices.has(txHashStr);
|
|
243
308
|
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
244
309
|
if (isNew) {
|
|
310
|
+
const meta = await buildTxMetaData(tx, allowedFlags[i]);
|
|
245
311
|
// New tx - add as mined or protected (callback emitted by #addTx)
|
|
246
312
|
if (minedBlockId) {
|
|
247
313
|
await this.#addTx(tx, {
|
|
248
314
|
mined: minedBlockId
|
|
249
|
-
}, opts);
|
|
315
|
+
}, opts, meta);
|
|
250
316
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
251
317
|
} else {
|
|
252
318
|
await this.#addTx(tx, {
|
|
253
319
|
protected: slotNumber
|
|
254
|
-
}, opts);
|
|
320
|
+
}, opts, meta);
|
|
255
321
|
}
|
|
256
322
|
} else {
|
|
257
323
|
// Existing tx - update protection and mined status
|
|
@@ -264,20 +330,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
264
330
|
}
|
|
265
331
|
});
|
|
266
332
|
}
|
|
267
|
-
protectTxs(txHashes, block) {
|
|
333
|
+
async protectTxs(txHashes, block) {
|
|
268
334
|
const slotNumber = block.globalVariables.slotNumber;
|
|
269
335
|
const missing = [];
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
336
|
+
let softDeletedHits = 0;
|
|
337
|
+
let missingPreviouslyEvicted = 0;
|
|
338
|
+
await this.#store.transactionAsync(async ()=>{
|
|
339
|
+
for (const txHash of txHashes){
|
|
340
|
+
const txHashStr = txHash.toString();
|
|
341
|
+
if (this.#indices.has(txHashStr)) {
|
|
342
|
+
// Update protection for existing tx
|
|
343
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
344
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
345
|
+
// Resurrect soft-deleted tx as protected
|
|
346
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
347
|
+
if (buffer) {
|
|
348
|
+
const tx = Tx.fromBuffer(buffer);
|
|
349
|
+
await this.#addTx(tx, {
|
|
350
|
+
protected: slotNumber
|
|
351
|
+
});
|
|
352
|
+
softDeletedHits++;
|
|
353
|
+
} else {
|
|
354
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
355
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
356
|
+
missing.push(txHash);
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
360
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
361
|
+
missing.push(txHash);
|
|
362
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
363
|
+
missingPreviouslyEvicted++;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
279
366
|
}
|
|
367
|
+
});
|
|
368
|
+
// Record metrics
|
|
369
|
+
if (softDeletedHits > 0) {
|
|
370
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
280
371
|
}
|
|
372
|
+
if (missing.length > 0) {
|
|
373
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map((h)=>h.toString()).join(', ')}`);
|
|
374
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
375
|
+
}
|
|
376
|
+
if (missingPreviouslyEvicted > 0) {
|
|
377
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
378
|
+
}
|
|
379
|
+
this.#log.info(`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`);
|
|
281
380
|
return missing;
|
|
282
381
|
}
|
|
283
382
|
async addMinedTxs(txs, block, opts) {
|
|
@@ -316,47 +415,53 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
316
415
|
found.push(meta);
|
|
317
416
|
}
|
|
318
417
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
418
|
+
await this.#store.transactionAsync(async ()=>{
|
|
419
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
420
|
+
for (const meta of found){
|
|
421
|
+
this.#indices.markAsMined(meta, blockId);
|
|
422
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
423
|
+
}
|
|
424
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
425
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
426
|
+
});
|
|
427
|
+
if (found.length > 0) {
|
|
428
|
+
this.#callbacks.onTxsMined(found.map((m)=>m.txHash));
|
|
323
429
|
}
|
|
324
|
-
// Step 5: Run eviction rules (remove pending txs with conflicting nullifiers/expired timestamps)
|
|
325
|
-
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
326
430
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
327
431
|
}
|
|
328
432
|
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
|
-
|
|
433
|
+
await this.#store.transactionAsync(async ()=>{
|
|
434
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
435
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
436
|
+
// Step 1: Find expired protected txs
|
|
437
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
438
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
439
|
+
this.#indices.clearProtection(expiredProtected);
|
|
440
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
441
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
442
|
+
if (txsToRestore.length === 0) {
|
|
443
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
447
|
+
// Step 4: Validate for pending pool
|
|
448
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, 'during prepareForSlot');
|
|
449
|
+
// Step 5: Resolve nullifier conflicts and add winners to pending indices
|
|
450
|
+
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
451
|
+
// Step 6: Delete invalid txs and evict conflict losers
|
|
452
|
+
await this.#deleteTxsBatch(invalid);
|
|
453
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
454
|
+
// Step 7: Run eviction rules (enforce pool size limit)
|
|
455
|
+
if (added.length > 0) {
|
|
456
|
+
const feePayers = added.map((meta)=>meta.feePayer);
|
|
457
|
+
const uniqueFeePayers = new Set(feePayers);
|
|
458
|
+
await this.#evictionManager.evictAfterNewTxs(added.map((m)=>m.txHash), [
|
|
459
|
+
...uniqueFeePayers
|
|
460
|
+
]);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
358
463
|
}
|
|
359
|
-
async handlePrunedBlocks(latestBlock) {
|
|
464
|
+
async handlePrunedBlocks(latestBlock, options) {
|
|
360
465
|
// Step 1: Find transactions mined after the prune point
|
|
361
466
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
362
467
|
if (txsToUnmine.length === 0) {
|
|
@@ -364,40 +469,48 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
364
469
|
return;
|
|
365
470
|
}
|
|
366
471
|
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
|
-
|
|
472
|
+
await this.#store.transactionAsync(async ()=>{
|
|
473
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
474
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
475
|
+
// when their original mined block is finalized
|
|
476
|
+
await this.#deletedPool.markFromPrunedBlock(txsToUnmine.map((m)=>({
|
|
477
|
+
txHash: m.txHash,
|
|
478
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId.number)
|
|
479
|
+
})));
|
|
480
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
481
|
+
for (const meta of txsToUnmine){
|
|
482
|
+
this.#indices.markAsUnmined(meta);
|
|
483
|
+
}
|
|
484
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
485
|
+
if (options?.deleteAllTxs) {
|
|
486
|
+
const allTxHashes = txsToUnmine.map((m)=>m.txHash);
|
|
487
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
488
|
+
this.#log.info(`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
492
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
493
|
+
// Step 5: Validate for pending pool
|
|
494
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
495
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
496
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
497
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
498
|
+
await this.#deleteTxsBatch(invalid);
|
|
499
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
500
|
+
this.#log.info(`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`, {
|
|
501
|
+
txHashesRestored: valid.map((m)=>m.txHash),
|
|
502
|
+
txHashesInvalid: invalid,
|
|
503
|
+
txHashesEvicted: toEvict
|
|
504
|
+
});
|
|
505
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
506
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
507
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
393
508
|
});
|
|
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
509
|
}
|
|
398
510
|
async handleFailedExecution(txHashes) {
|
|
399
|
-
|
|
400
|
-
|
|
511
|
+
await this.#store.transactionAsync(async ()=>{
|
|
512
|
+
await this.#deleteTxsBatch(txHashes.map((h)=>h.toString()));
|
|
513
|
+
});
|
|
401
514
|
this.#log.info(`Deleted ${txHashes.length} failed txs`, {
|
|
402
515
|
txHashes: txHashes.map((h)=>h.toString())
|
|
403
516
|
});
|
|
@@ -406,24 +519,26 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
406
519
|
const blockNumber = block.globalVariables.blockNumber;
|
|
407
520
|
// Step 1: Find mined txs at or before finalized block
|
|
408
521
|
const minedTxsToFinalize = this.#indices.findTxsMinedAtOrBefore(blockNumber);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
522
|
+
await this.#store.transactionAsync(async ()=>{
|
|
523
|
+
// Step 2: Collect mined txs for archiving (before deletion)
|
|
524
|
+
const txsToArchive = [];
|
|
525
|
+
if (this.#archive.isEnabled()) {
|
|
526
|
+
for (const txHashStr of minedTxsToFinalize){
|
|
527
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
528
|
+
if (buffer) {
|
|
529
|
+
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
530
|
+
}
|
|
416
531
|
}
|
|
417
532
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
533
|
+
// Step 3: Delete mined txs from active pool
|
|
534
|
+
await this.#deleteTxsBatch(minedTxsToFinalize);
|
|
535
|
+
// Step 4: Finalize soft-deleted txs
|
|
536
|
+
await this.#deletedPool.finalizeBlock(blockNumber);
|
|
537
|
+
// Step 5: Archive mined txs
|
|
538
|
+
if (txsToArchive.length > 0) {
|
|
539
|
+
await this.#archive.archiveTxs(txsToArchive);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
427
542
|
if (minedTxsToFinalize.length > 0) {
|
|
428
543
|
this.#log.info(`Finalized ${minedTxsToFinalize.length} mined txs from blocks up to ${blockNumber}`, {
|
|
429
544
|
txHashes: minedTxsToFinalize
|
|
@@ -528,7 +643,10 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
528
643
|
}
|
|
529
644
|
// === Metrics ===
|
|
530
645
|
countTxs() {
|
|
531
|
-
return
|
|
646
|
+
return {
|
|
647
|
+
...this.#indices.countTxs(),
|
|
648
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount()
|
|
649
|
+
};
|
|
532
650
|
}
|
|
533
651
|
// ============================================================================
|
|
534
652
|
// PRIVATE HELPERS - Transaction Management
|
|
@@ -536,9 +654,9 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
536
654
|
/**
|
|
537
655
|
* Adds a new transaction to the pool with the specified state.
|
|
538
656
|
* Emits onTxsAdded callback immediately after DB write.
|
|
539
|
-
*/ async #addTx(tx, state, opts = {}) {
|
|
657
|
+
*/ async #addTx(tx, state, opts = {}, precomputedMeta) {
|
|
540
658
|
const txHashStr = tx.getTxHash().toString();
|
|
541
|
-
const meta = await buildTxMetaData(tx);
|
|
659
|
+
const meta = precomputedMeta ?? await buildTxMetaData(tx);
|
|
542
660
|
meta.receivedAt = this.#dateProvider.now();
|
|
543
661
|
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
544
662
|
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
@@ -554,9 +672,11 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
554
672
|
this.#indices.addMined(meta);
|
|
555
673
|
}
|
|
556
674
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
557
|
-
this.#log.
|
|
675
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
558
676
|
eventName: 'tx-added-to-pool',
|
|
559
|
-
|
|
677
|
+
txHash: txHashStr,
|
|
678
|
+
state: stateStr,
|
|
679
|
+
source: opts.source
|
|
560
680
|
});
|
|
561
681
|
return meta;
|
|
562
682
|
}
|
|
@@ -579,6 +699,28 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
579
699
|
await this.#deleteTx(txHashStr);
|
|
580
700
|
}
|
|
581
701
|
}
|
|
702
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */ async #evictTxs(txHashes, reason) {
|
|
703
|
+
if (txHashes.length === 0) {
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
707
|
+
for (const txHashStr of txHashes){
|
|
708
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, {
|
|
709
|
+
txHash: txHashStr,
|
|
710
|
+
reason
|
|
711
|
+
});
|
|
712
|
+
this.#addToEvictedCache(txHashStr);
|
|
713
|
+
}
|
|
714
|
+
await this.#deleteTxsBatch(txHashes);
|
|
715
|
+
}
|
|
716
|
+
/** Adds a tx hash to the bounded evicted cache, evicting the oldest entry if at capacity. */ #addToEvictedCache(txHashStr) {
|
|
717
|
+
if (this.#evictedTxHashes.size >= this.#config.evictedTxCacheSize) {
|
|
718
|
+
// FIFO eviction: remove the first (oldest) entry
|
|
719
|
+
const oldest = this.#evictedTxHashes.values().next().value;
|
|
720
|
+
this.#evictedTxHashes.delete(oldest);
|
|
721
|
+
}
|
|
722
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
723
|
+
}
|
|
582
724
|
// ============================================================================
|
|
583
725
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
584
726
|
// ============================================================================
|
|
@@ -669,7 +811,8 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
669
811
|
}
|
|
670
812
|
try {
|
|
671
813
|
const tx = Tx.fromBuffer(buffer);
|
|
672
|
-
const
|
|
814
|
+
const allowedSetupCalls = await this.#checkAllowedSetupCalls(tx);
|
|
815
|
+
const meta = await buildTxMetaData(tx, allowedSetupCalls);
|
|
673
816
|
loaded.push({
|
|
674
817
|
tx,
|
|
675
818
|
meta
|
|
@@ -717,7 +860,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
717
860
|
if (preAddResult.shouldIgnore) {
|
|
718
861
|
// Transaction rejected - mark for deletion from DB
|
|
719
862
|
rejected.push(meta.txHash);
|
|
720
|
-
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason}`);
|
|
863
|
+
this.#log.debug(`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
721
864
|
continue;
|
|
722
865
|
}
|
|
723
866
|
// Evict any conflicting txs identified by pre-add rules
|
|
@@ -753,7 +896,7 @@ import { TxPoolIndices } from './tx_pool_indices.js';
|
|
|
753
896
|
getFeePayerPendingTxs: (feePayer)=>this.#indices.getFeePayerPendingTxs(feePayer),
|
|
754
897
|
getPendingTxCount: ()=>this.#indices.getPendingTxCount(),
|
|
755
898
|
getLowestPriorityPending: (limit)=>this.#indices.getLowestPriorityPending(limit),
|
|
756
|
-
deleteTxs: (txHashes)=>this.#
|
|
899
|
+
deleteTxs: (txHashes, reason)=>this.#evictTxs(txHashes, reason ?? 'unknown')
|
|
757
900
|
};
|
|
758
901
|
}
|
|
759
902
|
#createPreAddPoolAccess() {
|