@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
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 +130 -3
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -6
- package/dest/client/factory.d.ts +11 -10
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +64 -17
- package/dest/client/interface.d.ts +86 -40
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +67 -64
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +251 -251
- package/dest/config.d.ts +173 -94
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +158 -44
- 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/reqresp.error.d.ts +9 -16
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +10 -17
- 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 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +106 -55
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +302 -195
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- 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 +274 -115
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +7 -5
- package/dest/mem_pools/index.d.ts +2 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +12 -5
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +38 -17
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +10 -5
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +29 -20
- 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 +8 -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 +15 -5
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +3 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +2 -1
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +64 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +6 -5
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +9 -8
- 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 +15 -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 +3 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +2 -1
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +25 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +67 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +62 -16
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +81 -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 +147 -19
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +26 -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 +79 -43
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +27 -7
- 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 +94 -32
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +62 -9
- 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 +537 -246
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +10 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +38 -15
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +4 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +11 -3
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +12 -5
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +23 -3
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +36 -9
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +130 -48
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +4 -4
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +11 -18
- 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 +25 -21
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/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/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -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 +2 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +36 -2
- 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/factory.d.ts +133 -7
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +261 -61
- 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 +104 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +137 -53
- package/dest/msg_validators/tx_validator/index.d.ts +5 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +4 -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 +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/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +5 -5
- package/dest/services/discv5/discV5_service.d.ts +13 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +119 -23
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +25 -19
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +28 -20
- package/dest/services/encoding.d.ts +24 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +43 -26
- package/dest/services/gossipsub/topic_score_params.d.ts +23 -17
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -1
- package/dest/services/gossipsub/topic_score_params.js +36 -24
- package/dest/services/libp2p/instrumentation.d.ts +6 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +21 -0
- package/dest/services/libp2p/libp2p_service.d.ts +71 -60
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +602 -407
- 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 +31 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +127 -26
- package/dest/services/peer-manager/peer_scoring.d.ts +34 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +102 -13
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +5 -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 +95 -127
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +11 -11
- 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.d.ts +5 -14
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +6 -20
- package/dest/services/reqresp/config.d.ts +15 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +11 -0
- package/dest/services/reqresp/interface.d.ts +25 -18
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +23 -19
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +0 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +4 -3
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -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_handler.js +31 -28
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +18 -7
- 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 +57 -24
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +21 -3
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +3 -13
- package/dest/services/reqresp/reqresp.d.ts +7 -29
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +85 -219
- package/dest/services/service.d.ts +63 -19
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +11 -14
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +26 -33
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -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 +127 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -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 +100 -0
- package/dest/services/tx_collection/index.d.ts +3 -3
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -1
- package/dest/services/tx_collection/instrumentation.js +1 -2
- 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/tx_collection.d.ts +45 -51
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +296 -68
- package/dest/services/tx_collection/tx_collection_sink.d.ts +19 -9
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +28 -31
- 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 +29 -7
- 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 -5
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +13 -20
- package/dest/services/tx_provider.d.ts +6 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +12 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -8
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +5 -3
- package/dest/test-helpers/mock-pubsub.d.ts +56 -6
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +128 -14
- package/dest/test-helpers/reqresp-nodes.d.ts +5 -7
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +17 -19
- package/dest/test-helpers/test_tx_provider.d.ts +3 -1
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -1
- package/dest/test-helpers/test_tx_provider.js +3 -0
- package/dest/test-helpers/testbench-utils.d.ts +49 -37
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +142 -50
- package/dest/testbench/p2p_client_testbench_worker.d.ts +3 -5
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +112 -49
- package/dest/testbench/worker_client_manager.d.ts +12 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +57 -11
- package/dest/util.d.ts +13 -8
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +35 -14
- package/dest/versioning.d.ts +3 -6
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +3 -24
- package/package.json +17 -17
- package/src/bootstrap/bootstrap.ts +17 -3
- package/src/client/factory.ts +129 -28
- package/src/client/interface.ts +88 -48
- package/src/client/p2p_client.ts +284 -317
- package/src/client/test/{tx_proposal_collector/README.md → p2p_client.batch_tx_requester.bench.README.md} +23 -53
- package/src/config.ts +280 -49
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +13 -19
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +373 -236
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +298 -119
- package/src/mem_pools/attestation_pool/index.ts +3 -3
- package/src/mem_pools/attestation_pool/mocks.ts +14 -8
- package/src/mem_pools/index.ts +1 -1
- package/src/mem_pools/instrumentation.ts +27 -17
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +85 -11
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +30 -20
- 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 +6 -4
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +21 -6
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +5 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +67 -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 -6
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +8 -10
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -10
- 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 +2 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +96 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +63 -16
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +215 -27
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +91 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +122 -33
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +602 -242
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +46 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +15 -7
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +26 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +43 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +155 -49
- package/src/msg_validators/tx_validator/README.md +129 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +8 -17
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +44 -1
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +413 -80
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +195 -54
- package/src/msg_validators/tx_validator/index.ts +4 -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 +23 -18
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +101 -0
- package/src/services/data_store.ts +5 -13
- package/src/services/discv5/discV5_service.ts +126 -14
- package/src/services/discv5/persisted_enr_store.ts +158 -0
- package/src/services/dummy_service.ts +38 -46
- package/src/services/encoding.ts +42 -26
- package/src/services/gossipsub/README.md +59 -22
- package/src/services/gossipsub/topic_score_params.ts +58 -31
- package/src/services/libp2p/instrumentation.ts +22 -0
- package/src/services/libp2p/libp2p_service.ts +687 -466
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +140 -25
- package/src/services/peer-manager/peer_scoring.ts +102 -8
- package/src/services/reqresp/README.md +194 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +92 -138
- package/src/services/reqresp/batch-tx-requester/interface.ts +14 -10
- 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 +12 -25
- package/src/services/reqresp/config.ts +19 -2
- package/src/services/reqresp/interface.ts +45 -46
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +36 -32
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +64 -20
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +23 -3
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/rate-limiter/rate_limits.ts +3 -13
- package/src/services/reqresp/reqresp.ts +100 -263
- package/src/services/service.ts +80 -35
- package/src/services/tx_collection/config.ts +40 -49
- package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +2 -6
- package/src/services/tx_collection/instrumentation.ts +1 -1
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/tx_collection.ts +362 -110
- package/src/services/tx_collection/tx_collection_sink.ts +32 -36
- package/src/services/tx_collection/tx_source.ts +29 -8
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +15 -25
- package/src/services/tx_provider.ts +15 -9
- package/src/test-helpers/make-test-p2p-clients.ts +7 -6
- package/src/test-helpers/mock-pubsub.ts +152 -14
- package/src/test-helpers/reqresp-nodes.ts +15 -28
- package/src/test-helpers/test_tx_provider.ts +5 -0
- package/src/test-helpers/testbench-utils.ts +171 -68
- package/src/testbench/p2p_client_testbench_worker.ts +121 -64
- package/src/testbench/worker_client_manager.ts +72 -25
- package/src/util.ts +40 -19
- package/src/versioning.ts +3 -33
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +0 -2
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +0 -305
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +0 -73
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +0 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +0 -8
- 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/clock_tolerance.d.ts +0 -21
- package/dest/msg_validators/clock_tolerance.d.ts.map +0 -1
- package/dest/msg_validators/clock_tolerance.js +0 -37
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +0 -64
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +0 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +0 -151
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/dest/services/tx_collection/fast_tx_collection.d.ts +0 -52
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/fast_tx_collection.js +0 -307
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +0 -48
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +0 -49
- package/dest/services/tx_collection/slow_tx_collection.d.ts +0 -53
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +0 -1
- package/dest/services/tx_collection/slow_tx_collection.js +0 -177
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +0 -336
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +0 -43
- 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/clock_tolerance.ts +0 -51
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +0 -161
- package/src/services/reqresp/protocols/block.ts +0 -37
- package/src/services/tx_collection/fast_tx_collection.ts +0 -354
- package/src/services/tx_collection/proposal_tx_collector.ts +0 -112
- package/src/services/tx_collection/slow_tx_collection.ts +0 -233
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
2
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
5
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
6
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
7
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
@@ -8,20 +10,27 @@ import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
|
|
|
8
10
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
11
|
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
10
12
|
import { BlockHeader, Tx, TxHash, type TxValidator } from '@aztec/stdlib/tx';
|
|
13
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
11
14
|
|
|
12
15
|
import { TxArchive } from './archive/index.js';
|
|
16
|
+
import { DeletedPool } from './deleted_pool.js';
|
|
13
17
|
import {
|
|
14
18
|
EvictionManager,
|
|
15
19
|
FeePayerBalanceEvictionRule,
|
|
16
20
|
FeePayerBalancePreAddRule,
|
|
21
|
+
InsufficientFeePerGasEvictionRule,
|
|
17
22
|
InvalidTxsAfterMiningRule,
|
|
18
23
|
InvalidTxsAfterReorgRule,
|
|
19
24
|
LowPriorityEvictionRule,
|
|
20
25
|
LowPriorityPreAddRule,
|
|
21
26
|
NullifierConflictRule,
|
|
22
27
|
type PoolOperations,
|
|
28
|
+
type PreAddContext,
|
|
23
29
|
type PreAddPoolAccess,
|
|
30
|
+
TxPoolRejectionCode,
|
|
31
|
+
type TxPoolRejectionError,
|
|
24
32
|
} from './eviction/index.js';
|
|
33
|
+
import { TxPoolV2Instrumentation } from './instrumentation.js';
|
|
25
34
|
import {
|
|
26
35
|
type AddTxsResult,
|
|
27
36
|
DEFAULT_TX_POOL_V2_CONFIG,
|
|
@@ -32,12 +41,29 @@ import {
|
|
|
32
41
|
import { type TxMetaData, type TxState, buildTxMetaData, checkNullifierConflict } from './tx_metadata.js';
|
|
33
42
|
import { TxPoolIndices } from './tx_pool_indices.js';
|
|
34
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Maximum number of finalized txs to archive or hard-delete per serial-queue item. Bounds both
|
|
46
|
+
* peak memory (~23k txs/epoch at 10 TPS would otherwise OOM the node) and, more importantly, how
|
|
47
|
+
* long finalization occupies the pool's serial queue per item: gossip tx validation waits on that
|
|
48
|
+
* queue, so each item must stay well under the gossipsub mcache eviction window.
|
|
49
|
+
*/
|
|
50
|
+
export const FINALIZE_BLOCK_CHUNK_SIZE = 16;
|
|
51
|
+
|
|
35
52
|
/**
|
|
36
53
|
* Callbacks for the implementation to notify the outer class about events and metrics.
|
|
37
54
|
*/
|
|
55
|
+
/** A tx that has just transitioned to mined, with the time it spent in the pool. */
|
|
56
|
+
export interface MinedTxInfo {
|
|
57
|
+
txHash: string;
|
|
58
|
+
/** Wall-clock ms from receipt into the pool to being marked mined. Undefined when the
|
|
59
|
+
* receive time is unknown (e.g. a tx hydrated from the DB on restart, receivedAt === 0). */
|
|
60
|
+
minedDelayMs?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
38
63
|
export interface TxPoolV2Callbacks {
|
|
39
64
|
onTxsAdded: (txs: Tx[], opts: { source?: string }) => void;
|
|
40
65
|
onTxsRemoved: (txHashes: string[] | bigint[]) => void;
|
|
66
|
+
onTxsMined: (minedTxs: MinedTxInfo[]) => void;
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
/**
|
|
@@ -48,12 +74,16 @@ export interface TxPoolV2Callbacks {
|
|
|
48
74
|
export class TxPoolV2Impl {
|
|
49
75
|
// === Persistence ===
|
|
50
76
|
#store: AztecAsyncKVStore;
|
|
77
|
+
/** Tx data without its proof. Proofs live in #proofsDB so a tx can be read without loading its proof. */
|
|
51
78
|
#txsDB: AztecAsyncMap<string, Buffer>;
|
|
79
|
+
/** Tx proofs, keyed by tx hash. Written and deleted in lockstep with #txsDB. */
|
|
80
|
+
#proofsDB: AztecAsyncMap<string, Buffer>;
|
|
52
81
|
|
|
53
82
|
// === Dependencies ===
|
|
54
83
|
#l2BlockSource: L2BlockSource;
|
|
55
84
|
#worldStateSynchronizer: WorldStateSynchronizer;
|
|
56
|
-
#
|
|
85
|
+
#createTxValidator: TxPoolV2Dependencies['createTxValidator'];
|
|
86
|
+
#checkAllowedSetupCalls: TxPoolV2Dependencies['checkAllowedSetupCalls'];
|
|
57
87
|
|
|
58
88
|
// === In-Memory Indices ===
|
|
59
89
|
#indices: TxPoolIndices = new TxPoolIndices();
|
|
@@ -61,7 +91,11 @@ export class TxPoolV2Impl {
|
|
|
61
91
|
// === Config & Services ===
|
|
62
92
|
#config: TxPoolV2Config;
|
|
63
93
|
#archive: TxArchive;
|
|
94
|
+
#deletedPool: DeletedPool;
|
|
64
95
|
#evictionManager: EvictionManager;
|
|
96
|
+
#dateProvider: DateProvider;
|
|
97
|
+
#instrumentation: TxPoolV2Instrumentation;
|
|
98
|
+
#evictedTxHashes: FifoSet<string>;
|
|
65
99
|
#log: Logger;
|
|
66
100
|
#callbacks: TxPoolV2Callbacks;
|
|
67
101
|
|
|
@@ -70,18 +104,26 @@ export class TxPoolV2Impl {
|
|
|
70
104
|
archiveStore: AztecAsyncKVStore,
|
|
71
105
|
deps: TxPoolV2Dependencies,
|
|
72
106
|
callbacks: TxPoolV2Callbacks,
|
|
107
|
+
telemetry: TelemetryClient,
|
|
73
108
|
config: Partial<TxPoolV2Config> = {},
|
|
109
|
+
dateProvider: DateProvider,
|
|
74
110
|
log: Logger,
|
|
75
111
|
) {
|
|
76
112
|
this.#store = store;
|
|
77
113
|
this.#txsDB = store.openMap('txs');
|
|
114
|
+
this.#proofsDB = store.openMap('tx_proofs');
|
|
78
115
|
|
|
79
116
|
this.#l2BlockSource = deps.l2BlockSource;
|
|
80
117
|
this.#worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
81
|
-
this.#
|
|
118
|
+
this.#createTxValidator = deps.createTxValidator;
|
|
119
|
+
this.#checkAllowedSetupCalls = deps.checkAllowedSetupCalls;
|
|
82
120
|
|
|
83
121
|
this.#config = { ...DEFAULT_TX_POOL_V2_CONFIG, ...config };
|
|
122
|
+
this.#evictedTxHashes = FifoSet.withLimit<string>(this.#config.evictedTxCacheSize);
|
|
84
123
|
this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
|
|
124
|
+
this.#deletedPool = new DeletedPool(store, txHashStr => this.#deleteTxData(txHashStr), log);
|
|
125
|
+
this.#dateProvider = dateProvider;
|
|
126
|
+
this.#instrumentation = new TxPoolV2Instrumentation(telemetry, () => this.#indices.getTotalMetadataBytes());
|
|
85
127
|
this.#log = log;
|
|
86
128
|
this.#callbacks = callbacks;
|
|
87
129
|
|
|
@@ -97,6 +139,7 @@ export class TxPoolV2Impl {
|
|
|
97
139
|
|
|
98
140
|
// Post-event eviction rules (run after events to check ALL pending txs)
|
|
99
141
|
this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
|
|
142
|
+
this.#evictionManager.registerRule(new InsufficientFeePerGasEvictionRule(deps.blockMinFeesProvider));
|
|
100
143
|
this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(deps.worldStateSynchronizer));
|
|
101
144
|
this.#evictionManager.registerRule(new FeePayerBalanceEvictionRule(deps.worldStateSynchronizer));
|
|
102
145
|
// LowPriorityEvictionRule handles cases where txs become pending via prepareForSlot (unprotect)
|
|
@@ -116,55 +159,118 @@ export class TxPoolV2Impl {
|
|
|
116
159
|
* by running pre-add rules to resolve nullifier conflicts, balance checks, and pool size limits.
|
|
117
160
|
*/
|
|
118
161
|
async hydrateFromDatabase(): Promise<void> {
|
|
119
|
-
// Step
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// Step
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
|
|
162
|
+
// Step 0: Hydrate deleted pool state
|
|
163
|
+
await this.#deletedPool.hydrateFromDatabase();
|
|
164
|
+
|
|
165
|
+
// Step 1: Stream txs from DB, building metadata and mined status one at a time.
|
|
166
|
+
const minedMetas: TxMetaData[] = [];
|
|
167
|
+
const pendingMetas: TxMetaData[] = [];
|
|
168
|
+
const deserializationErrors: string[] = [];
|
|
169
|
+
|
|
170
|
+
for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()) {
|
|
171
|
+
// Skip soft-deleted transactions - they stay in DB but not in indices
|
|
172
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let meta: TxMetaData;
|
|
177
|
+
let txEffect: Awaited<ReturnType<L2BlockSource['getTxEffect']>>;
|
|
178
|
+
try {
|
|
179
|
+
const tx = Tx.fromBuffer(buffer);
|
|
180
|
+
// Resolve allowed-setup-calls and the tx effect concurrently
|
|
181
|
+
// getTxEffect failures are non-fatal (we just treat the tx as not-yet-mined), so
|
|
182
|
+
// its rejection is swallowed before the Promise.all so it can't fail-fast the batch.
|
|
183
|
+
const txEffectPromise = this.#l2BlockSource.getTxEffect(tx.getTxHash()).catch(err => {
|
|
184
|
+
this.#log.warn(`Failed to check mined status for tx ${txHashStr}`, { err });
|
|
185
|
+
return undefined;
|
|
186
|
+
});
|
|
187
|
+
const [allowedSetupCalls, fetchedTxEffect] = await Promise.all([
|
|
188
|
+
this.#checkAllowedSetupCalls(tx),
|
|
189
|
+
txEffectPromise,
|
|
190
|
+
]);
|
|
191
|
+
meta = await buildTxMetaData(tx, allowedSetupCalls);
|
|
192
|
+
txEffect = fetchedTxEffect;
|
|
193
|
+
} catch (err) {
|
|
194
|
+
this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, { err });
|
|
195
|
+
deserializationErrors.push(txHashStr);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (txEffect) {
|
|
200
|
+
meta.minedL2BlockId = {
|
|
201
|
+
number: txEffect.l2BlockNumber,
|
|
202
|
+
hash: txEffect.l2BlockHash.toString(),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (meta.minedL2BlockId !== undefined) {
|
|
207
|
+
minedMetas.push(meta);
|
|
131
208
|
} else {
|
|
132
|
-
|
|
209
|
+
pendingMetas.push(meta);
|
|
133
210
|
}
|
|
134
211
|
}
|
|
135
212
|
|
|
136
|
-
// Step
|
|
137
|
-
const { valid, invalid } = await this.#
|
|
213
|
+
// Step 2: Validate non-mined transactions
|
|
214
|
+
const { valid, invalid } = await this.#revalidateMetadata(pendingMetas, 'on startup');
|
|
138
215
|
|
|
139
|
-
// Step
|
|
140
|
-
for (const meta of
|
|
216
|
+
// Step 3: Populate mined indices (these don't need conflict resolution)
|
|
217
|
+
for (const meta of minedMetas) {
|
|
141
218
|
this.#indices.addMined(meta);
|
|
142
219
|
}
|
|
143
220
|
|
|
144
|
-
// Step
|
|
221
|
+
// Step 4: Rebuild pending pool by running pre-add rules for each tx
|
|
145
222
|
// This resolves nullifier conflicts, fee payer balance issues, and pool size limits
|
|
146
223
|
const { rejected } = await this.#rebuildPendingPool(valid);
|
|
147
224
|
|
|
148
|
-
// Step
|
|
225
|
+
// Step 5: Delete invalid and rejected txs from DB only (indices were never populated for these)
|
|
149
226
|
const toDelete = [...deserializationErrors, ...invalid, ...rejected];
|
|
150
227
|
if (toDelete.length === 0) {
|
|
151
228
|
return;
|
|
152
229
|
}
|
|
153
230
|
await this.#store.transactionAsync(async () => {
|
|
154
231
|
for (const txHashStr of toDelete) {
|
|
155
|
-
await this.#
|
|
232
|
+
await this.#deleteTxData(txHashStr);
|
|
156
233
|
}
|
|
157
234
|
});
|
|
158
|
-
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup
|
|
235
|
+
this.#log.info(`Deleted ${toDelete.length} invalid/rejected transactions on startup`, { txHashes: toDelete });
|
|
159
236
|
}
|
|
160
237
|
|
|
161
|
-
async addPendingTxs(txs: Tx[], opts: { source?: string }): Promise<AddTxsResult> {
|
|
238
|
+
async addPendingTxs(txs: Tx[], opts: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult> {
|
|
162
239
|
const accepted: TxHash[] = [];
|
|
163
240
|
const ignored: TxHash[] = [];
|
|
164
241
|
const rejected: TxHash[] = [];
|
|
242
|
+
const errors = new Map<string, TxPoolRejectionError>();
|
|
165
243
|
const acceptedPending = new Set<string>();
|
|
166
244
|
|
|
245
|
+
// Phase 1: Pre-compute all throwable I/O outside the transaction.
|
|
246
|
+
// If any pre-computation throws, the entire call fails before mutations happen.
|
|
247
|
+
const precomputed = new Map<string, { meta: TxMetaData; minedBlockId: L2BlockId | undefined; isValid: boolean }>();
|
|
248
|
+
|
|
249
|
+
const validator = await this.#createTxValidator();
|
|
250
|
+
|
|
251
|
+
for (const tx of txs) {
|
|
252
|
+
const txHash = tx.getTxHash();
|
|
253
|
+
const txHashStr = txHash.toString();
|
|
254
|
+
|
|
255
|
+
const meta = await buildTxMetaData(tx);
|
|
256
|
+
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
257
|
+
|
|
258
|
+
// Validate non-mined txs (mined and pre-protected txs bypass validation inside the transaction)
|
|
259
|
+
let isValid = true;
|
|
260
|
+
if (!minedBlockId) {
|
|
261
|
+
isValid = await this.#validateMeta(meta, validator);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
precomputed.set(txHashStr, { meta, minedBlockId, isValid });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Phase 2: Apply mutations inside the transaction using only pre-computed results,
|
|
268
|
+
// in-memory reads, and buffered DB writes. Nothing here can throw an unhandled exception.
|
|
167
269
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
270
|
+
const preAddContext: PreAddContext | undefined =
|
|
271
|
+
opts.feeComparisonOnly !== undefined
|
|
272
|
+
? { feeComparisonOnly: opts.feeComparisonOnly, priceBumpPercentage: this.#config.priceBumpPercentage }
|
|
273
|
+
: undefined;
|
|
168
274
|
|
|
169
275
|
await this.#store.transactionAsync(async () => {
|
|
170
276
|
for (const tx of txs) {
|
|
@@ -177,30 +283,46 @@ export class TxPoolV2Impl {
|
|
|
177
283
|
continue;
|
|
178
284
|
}
|
|
179
285
|
|
|
180
|
-
|
|
181
|
-
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
286
|
+
const { meta, minedBlockId, isValid } = precomputed.get(txHashStr)!;
|
|
182
287
|
const preProtectedSlot = this.#indices.getProtectionSlot(txHashStr);
|
|
183
288
|
|
|
184
289
|
if (minedBlockId) {
|
|
185
290
|
// Already mined - add directly (protection already set if pre-protected)
|
|
186
|
-
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
291
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
|
|
187
292
|
accepted.push(txHash);
|
|
188
293
|
} else if (preProtectedSlot !== undefined) {
|
|
189
294
|
// Pre-protected and not mined - add as protected (bypass validation)
|
|
190
|
-
await this.#addTx(tx, { protected: preProtectedSlot }, opts);
|
|
295
|
+
await this.#addTx(tx, { protected: preProtectedSlot }, opts, meta);
|
|
191
296
|
accepted.push(txHash);
|
|
297
|
+
} else if (!isValid) {
|
|
298
|
+
// Failed pre-computed validation
|
|
299
|
+
rejected.push(txHash);
|
|
192
300
|
} else {
|
|
193
|
-
// Regular pending tx -
|
|
194
|
-
const result = await this.#tryAddRegularPendingTx(
|
|
301
|
+
// Regular pending tx - run pre-add rules using pre-computed metadata
|
|
302
|
+
const result = await this.#tryAddRegularPendingTx(
|
|
303
|
+
tx,
|
|
304
|
+
meta,
|
|
305
|
+
opts,
|
|
306
|
+
poolAccess,
|
|
307
|
+
acceptedPending,
|
|
308
|
+
ignored,
|
|
309
|
+
errors,
|
|
310
|
+
preAddContext,
|
|
311
|
+
);
|
|
195
312
|
if (result.status === 'accepted') {
|
|
196
313
|
acceptedPending.add(txHashStr);
|
|
197
|
-
} else if (result.status === 'rejected') {
|
|
198
|
-
rejected.push(txHash);
|
|
199
314
|
} else {
|
|
200
315
|
ignored.push(txHash);
|
|
201
316
|
}
|
|
202
317
|
}
|
|
203
318
|
}
|
|
319
|
+
|
|
320
|
+
// Run post-add eviction rules for pending txs (inside transaction for atomicity)
|
|
321
|
+
if (acceptedPending.size > 0) {
|
|
322
|
+
const feePayers = Array.from(acceptedPending).map(txHash => this.#indices.getMetadata(txHash)!.feePayer);
|
|
323
|
+
const uniqueFeePayers = new Set<string>(feePayers);
|
|
324
|
+
await this.#evictionManager.evictAfterNewTxs(Array.from(acceptedPending), [...uniqueFeePayers]);
|
|
325
|
+
}
|
|
204
326
|
});
|
|
205
327
|
|
|
206
328
|
// Build final accepted list for pending txs (excludes intra-batch evictions)
|
|
@@ -208,96 +330,124 @@ export class TxPoolV2Impl {
|
|
|
208
330
|
accepted.push(TxHash.fromString(txHashStr));
|
|
209
331
|
}
|
|
210
332
|
|
|
211
|
-
//
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
333
|
+
// Record metrics
|
|
334
|
+
if (ignored.length > 0) {
|
|
335
|
+
this.#instrumentation.recordIgnored(ignored.length);
|
|
336
|
+
}
|
|
337
|
+
if (rejected.length > 0) {
|
|
338
|
+
this.#instrumentation.recordRejected(rejected.length);
|
|
216
339
|
}
|
|
217
340
|
|
|
218
|
-
return { accepted, ignored, rejected };
|
|
341
|
+
return { accepted, ignored, rejected, ...(errors.size > 0 ? { errors } : {}) };
|
|
219
342
|
}
|
|
220
343
|
|
|
221
|
-
/**
|
|
344
|
+
/** Adds a validated pending tx, running pre-add rules and evicting conflicts. */
|
|
222
345
|
async #tryAddRegularPendingTx(
|
|
223
346
|
tx: Tx,
|
|
347
|
+
precomputedMeta: TxMetaData,
|
|
224
348
|
opts: { source?: string },
|
|
225
349
|
poolAccess: PreAddPoolAccess,
|
|
226
350
|
acceptedPending: Set<string>,
|
|
227
351
|
ignored: TxHash[],
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
352
|
+
errors: Map<string, TxPoolRejectionError>,
|
|
353
|
+
preAddContext?: PreAddContext,
|
|
354
|
+
): Promise<{ status: 'accepted' | 'ignored' }> {
|
|
355
|
+
const txHashStr = tx.getTxHash().toString();
|
|
231
356
|
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
return { status: 'rejected' };
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Build metadata and run pre-add rules
|
|
238
|
-
const meta = await buildTxMetaData(tx);
|
|
239
|
-
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
357
|
+
// Run pre-add rules
|
|
358
|
+
const preAddResult = await this.#evictionManager.runPreAddRules(precomputedMeta, poolAccess, preAddContext);
|
|
240
359
|
|
|
241
360
|
if (preAddResult.shouldIgnore) {
|
|
242
|
-
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason}`);
|
|
361
|
+
this.#log.debug(`Ignoring tx ${txHashStr}: ${preAddResult.reason?.message ?? 'unknown reason'}`);
|
|
362
|
+
if (preAddResult.reason && preAddResult.reason.code !== TxPoolRejectionCode.INTERNAL_ERROR) {
|
|
363
|
+
errors.set(txHashStr, preAddResult.reason);
|
|
364
|
+
}
|
|
243
365
|
return { status: 'ignored' };
|
|
244
366
|
}
|
|
245
367
|
|
|
246
|
-
// Evict conflicts
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
368
|
+
// Evict conflicts, grouped by rule name for metrics
|
|
369
|
+
if (preAddResult.evictions && preAddResult.evictions.length > 0) {
|
|
370
|
+
const byReason = new Map<string, string[]>();
|
|
371
|
+
for (const { txHash: evictHash, reason } of preAddResult.evictions) {
|
|
372
|
+
const group = byReason.get(reason);
|
|
373
|
+
if (group) {
|
|
374
|
+
group.push(evictHash);
|
|
375
|
+
} else {
|
|
376
|
+
byReason.set(reason, [evictHash]);
|
|
377
|
+
}
|
|
254
378
|
}
|
|
379
|
+
for (const [reason, hashes] of byReason) {
|
|
380
|
+
await this.#evictTxs(hashes, reason);
|
|
381
|
+
}
|
|
382
|
+
for (const evictHashStr of preAddResult.txHashesToEvict) {
|
|
383
|
+
this.#log.debug(`Evicted tx ${evictHashStr} due to higher-fee tx ${txHashStr}`, {
|
|
384
|
+
evictedTxHash: evictHashStr,
|
|
385
|
+
replacementTxHash: txHashStr,
|
|
386
|
+
});
|
|
387
|
+
if (acceptedPending.has(evictHashStr)) {
|
|
388
|
+
// Evicted tx was from this batch - mark as ignored in result
|
|
389
|
+
acceptedPending.delete(evictHashStr);
|
|
390
|
+
ignored.push(TxHash.fromString(evictHashStr));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Randomly drop the transaction for testing purposes (report as accepted so it propagates)
|
|
396
|
+
if (this.#config.dropTransactionsProbability > 0 && Math.random() < this.#config.dropTransactionsProbability) {
|
|
397
|
+
this.#log.debug(`Dropping tx ${txHashStr} (simulated drop for testing)`);
|
|
398
|
+
return { status: 'accepted' };
|
|
255
399
|
}
|
|
256
400
|
|
|
257
401
|
// Add the transaction
|
|
258
|
-
await this.#addTx(tx, 'pending', opts);
|
|
402
|
+
await this.#addTx(tx, 'pending', opts, precomputedMeta);
|
|
259
403
|
return { status: 'accepted' };
|
|
260
404
|
}
|
|
261
405
|
|
|
262
|
-
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'
|
|
406
|
+
async canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'> {
|
|
263
407
|
const txHashStr = tx.getTxHash().toString();
|
|
264
408
|
|
|
265
409
|
// Check if already in pool
|
|
266
410
|
if (this.#indices.has(txHashStr)) {
|
|
411
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
|
|
267
412
|
return 'ignored';
|
|
268
413
|
}
|
|
269
414
|
|
|
270
|
-
//
|
|
271
|
-
const validationResult = await this.#pendingTxValidator.validateTx(tx);
|
|
272
|
-
if (validationResult.result !== 'valid') {
|
|
273
|
-
return 'rejected';
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Build metadata and use pre-add rules
|
|
415
|
+
// Build metadata and check pre-add rules
|
|
277
416
|
const meta = await buildTxMetaData(tx);
|
|
278
417
|
const poolAccess = this.#createPreAddPoolAccess();
|
|
279
418
|
const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
|
|
280
419
|
|
|
281
|
-
|
|
420
|
+
if (preAddResult.shouldIgnore) {
|
|
421
|
+
this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
|
|
422
|
+
reason: preAddResult.reason?.message ?? 'no reason provided',
|
|
423
|
+
});
|
|
424
|
+
return 'ignored';
|
|
425
|
+
}
|
|
426
|
+
return 'accepted';
|
|
282
427
|
}
|
|
283
428
|
|
|
284
429
|
async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
|
|
285
430
|
const slotNumber = block.globalVariables.slotNumber;
|
|
286
431
|
|
|
432
|
+
// Precompute setup-call allow-list flags outside the store transaction
|
|
433
|
+
const allowedFlags = await Promise.all(txs.map(tx => this.#checkAllowedSetupCalls(tx)));
|
|
434
|
+
|
|
287
435
|
await this.#store.transactionAsync(async () => {
|
|
288
|
-
for (
|
|
436
|
+
for (let i = 0; i < txs.length; i++) {
|
|
437
|
+
const tx = txs[i];
|
|
289
438
|
const txHash = tx.getTxHash();
|
|
290
439
|
const txHashStr = txHash.toString();
|
|
291
440
|
const isNew = !this.#indices.has(txHashStr);
|
|
292
441
|
const minedBlockId = await this.#getMinedBlockId(txHash);
|
|
293
442
|
|
|
294
443
|
if (isNew) {
|
|
444
|
+
const meta = await buildTxMetaData(tx, allowedFlags[i]);
|
|
295
445
|
// New tx - add as mined or protected (callback emitted by #addTx)
|
|
296
446
|
if (minedBlockId) {
|
|
297
|
-
await this.#addTx(tx, { mined: minedBlockId }, opts);
|
|
447
|
+
await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
|
|
298
448
|
this.#indices.setProtection(txHashStr, slotNumber);
|
|
299
449
|
} else {
|
|
300
|
-
await this.#addTx(tx, { protected: slotNumber }, opts);
|
|
450
|
+
await this.#addTx(tx, { protected: slotNumber }, opts, meta);
|
|
301
451
|
}
|
|
302
452
|
} else {
|
|
303
453
|
// Existing tx - update protection and mined status
|
|
@@ -311,23 +461,59 @@ export class TxPoolV2Impl {
|
|
|
311
461
|
});
|
|
312
462
|
}
|
|
313
463
|
|
|
314
|
-
protectTxs(txHashes: TxHash[], block: BlockHeader): TxHash[] {
|
|
464
|
+
async protectTxs(txHashes: TxHash[], block: BlockHeader): Promise<TxHash[]> {
|
|
315
465
|
const slotNumber = block.globalVariables.slotNumber;
|
|
316
466
|
const missing: TxHash[] = [];
|
|
467
|
+
let softDeletedHits = 0;
|
|
468
|
+
let missingPreviouslyEvicted = 0;
|
|
317
469
|
|
|
318
|
-
|
|
319
|
-
const
|
|
470
|
+
await this.#store.transactionAsync(async () => {
|
|
471
|
+
for (const txHash of txHashes) {
|
|
472
|
+
const txHashStr = txHash.toString();
|
|
320
473
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
474
|
+
if (this.#indices.has(txHashStr)) {
|
|
475
|
+
// Update protection for existing tx
|
|
476
|
+
this.#indices.updateProtection(txHashStr, slotNumber);
|
|
477
|
+
} else if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
478
|
+
// Resurrect soft-deleted tx as protected. Load the proof too: #addTx rewrites both entries, so re-adding
|
|
479
|
+
// a proofless tx would wipe the stored proof.
|
|
480
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
481
|
+
if (buffer) {
|
|
482
|
+
const tx = await this.#loadTxWithProof(txHashStr, buffer);
|
|
483
|
+
await this.#addTx(tx, { protected: slotNumber });
|
|
484
|
+
softDeletedHits++;
|
|
485
|
+
} else {
|
|
486
|
+
// Data missing despite soft-delete flag — treat as truly missing
|
|
487
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
488
|
+
missing.push(txHash);
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
// Truly missing — pre-record protection for tx we don't have yet
|
|
492
|
+
this.#indices.setProtection(txHashStr, slotNumber);
|
|
493
|
+
missing.push(txHash);
|
|
494
|
+
if (this.#evictedTxHashes.has(txHashStr)) {
|
|
495
|
+
missingPreviouslyEvicted++;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
328
498
|
}
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// Record metrics
|
|
502
|
+
if (softDeletedHits > 0) {
|
|
503
|
+
this.#instrumentation.recordSoftDeletedHits(softDeletedHits);
|
|
504
|
+
}
|
|
505
|
+
if (missing.length > 0) {
|
|
506
|
+
this.#log.debug(`protectTxs missing tx hashes: ${missing.map(h => h.toString()).join(', ')}`);
|
|
507
|
+
this.#instrumentation.recordMissingOnProtect(missing.length);
|
|
508
|
+
}
|
|
509
|
+
if (missingPreviouslyEvicted > 0) {
|
|
510
|
+
this.#instrumentation.recordMissingPreviouslyEvicted(missingPreviouslyEvicted);
|
|
329
511
|
}
|
|
330
512
|
|
|
513
|
+
this.#log.info(
|
|
514
|
+
`Protected ${txHashes.length} txs, missing: ${missing.length}, soft-deleted hits: ${softDeletedHits}`,
|
|
515
|
+
);
|
|
516
|
+
|
|
331
517
|
return missing;
|
|
332
518
|
}
|
|
333
519
|
|
|
@@ -347,6 +533,7 @@ export class TxPoolV2Impl {
|
|
|
347
533
|
// Add new mined tx (callback emitted by #addTx)
|
|
348
534
|
await this.#addTx(tx, { mined: blockId }, opts);
|
|
349
535
|
}
|
|
536
|
+
await this.#deletedPool.clearIfMinedHigher(txHashStr, blockId.number);
|
|
350
537
|
}
|
|
351
538
|
});
|
|
352
539
|
}
|
|
@@ -370,42 +557,97 @@ export class TxPoolV2Impl {
|
|
|
370
557
|
}
|
|
371
558
|
}
|
|
372
559
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
560
|
+
await this.#store.transactionAsync(async () => {
|
|
561
|
+
// Step 4: Mark txs as mined (only those we have in the pool)
|
|
562
|
+
for (const meta of found) {
|
|
563
|
+
this.#indices.markAsMined(meta, blockId);
|
|
564
|
+
await this.#deletedPool.clearIfMinedHigher(meta.txHash, blockId.number);
|
|
565
|
+
}
|
|
377
566
|
|
|
378
|
-
|
|
379
|
-
|
|
567
|
+
// Step 5: Run post-event eviction rules (inside transaction for atomicity)
|
|
568
|
+
await this.#evictionManager.evictAfterNewBlock(block.header, nullifiers, feePayers);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
if (found.length > 0) {
|
|
572
|
+
// receivedAt is 0 for txs hydrated from the DB on restart (true receive time lost) — leave
|
|
573
|
+
// their delay undefined so the metric isn't polluted by epoch-sized values.
|
|
574
|
+
const now = this.#dateProvider.now();
|
|
575
|
+
this.#callbacks.onTxsMined(
|
|
576
|
+
found.map(m => ({
|
|
577
|
+
txHash: m.txHash,
|
|
578
|
+
minedDelayMs: m.receivedAt > 0 ? now - m.receivedAt : undefined,
|
|
579
|
+
})),
|
|
580
|
+
);
|
|
581
|
+
}
|
|
380
582
|
|
|
381
583
|
this.#log.info(`Marked ${found.length} txs as mined in block ${blockId.number}`);
|
|
382
584
|
}
|
|
383
585
|
|
|
384
586
|
async prepareForSlot(slotNumber: SlotNumber): Promise<void> {
|
|
385
|
-
|
|
386
|
-
|
|
587
|
+
await this.#store.transactionAsync(async () => {
|
|
588
|
+
// Step 0: Clean up slot-deleted txs from previous slots
|
|
589
|
+
await this.#deletedPool.cleanupSlotDeleted(slotNumber);
|
|
387
590
|
|
|
388
|
-
|
|
389
|
-
|
|
591
|
+
// Step 1: Find expired protected txs
|
|
592
|
+
const expiredProtected = this.#indices.findExpiredProtectedTxs(slotNumber);
|
|
390
593
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
594
|
+
// Step 2: Clear protection for all expired entries (including those without metadata)
|
|
595
|
+
this.#indices.clearProtection(expiredProtected);
|
|
596
|
+
|
|
597
|
+
// Step 3: Filter to only txs that have metadata and are not mined
|
|
598
|
+
const txsToRestore = this.#indices.filterRestorable(expiredProtected);
|
|
599
|
+
if (txsToRestore.length === 0) {
|
|
600
|
+
this.#log.debug(`Preparing for slot ${slotNumber}, no txs to unprotect`);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
this.#log.info(`Preparing for slot ${slotNumber}: unprotecting ${txsToRestore.length} txs`);
|
|
605
|
+
await this.#restoreUnprotectedToPending(txsToRestore, 'during prepareForSlot');
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
async unprotectTxs(txHashes: TxHash[], slotNumber: SlotNumber): Promise<void> {
|
|
610
|
+
const hashStrs = txHashes.map(h => h.toString());
|
|
611
|
+
|
|
612
|
+
await this.#store.transactionAsync(async () => {
|
|
613
|
+
// Only release entries still recorded at this exact slot. A tx that another, still-live proposal
|
|
614
|
+
// raised to a higher slot via updateProtection must keep that protection. Mined txs have no
|
|
615
|
+
// protection entry and so are never matched here.
|
|
616
|
+
const matching = this.#indices.findProtectedTxsAtSlot(hashStrs, slotNumber);
|
|
617
|
+
if (matching.length === 0) {
|
|
618
|
+
this.#log.debug(`Unprotecting txs for slot ${slotNumber}: no matching protections to release`);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
396
621
|
|
|
397
|
-
|
|
622
|
+
this.#indices.clearProtection(matching);
|
|
398
623
|
|
|
399
|
-
|
|
400
|
-
|
|
624
|
+
const txsToRestore = this.#indices.filterRestorable(matching);
|
|
625
|
+
if (txsToRestore.length === 0) {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
401
628
|
|
|
402
|
-
|
|
629
|
+
this.#log.info(`Unprotecting ${txsToRestore.length} txs from failed proposal at slot ${slotNumber}`);
|
|
630
|
+
await this.#restoreUnprotectedToPending(txsToRestore, 'during unprotectTxs');
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Returns just-unprotected txs to the pending pool: revalidates them, resolves nullifier
|
|
636
|
+
* conflicts, deletes losers, then enforces the pool size limit. Must run inside a store
|
|
637
|
+
* transaction; callers clear the protection entries before invoking.
|
|
638
|
+
*/
|
|
639
|
+
async #restoreUnprotectedToPending(txsToRestore: TxMetaData[], context: string): Promise<void> {
|
|
640
|
+
// Step 1: Validate for pending pool
|
|
641
|
+
const { valid, invalid } = await this.#revalidateMetadata(txsToRestore, context);
|
|
642
|
+
|
|
643
|
+
// Step 2: Resolve nullifier conflicts and add winners to pending indices
|
|
403
644
|
const { added, toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
404
645
|
|
|
405
|
-
// Step
|
|
406
|
-
await this.#deleteTxsBatch(
|
|
646
|
+
// Step 3: Delete invalid txs and evict conflict losers
|
|
647
|
+
await this.#deleteTxsBatch(invalid);
|
|
648
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
407
649
|
|
|
408
|
-
// Step
|
|
650
|
+
// Step 4: Run eviction rules (enforce pool size limit)
|
|
409
651
|
if (added.length > 0) {
|
|
410
652
|
const feePayers = added.map(meta => meta.feePayer);
|
|
411
653
|
const uniqueFeePayers = new Set<string>(feePayers);
|
|
@@ -416,7 +658,7 @@ export class TxPoolV2Impl {
|
|
|
416
658
|
}
|
|
417
659
|
}
|
|
418
660
|
|
|
419
|
-
async handlePrunedBlocks(latestBlock: L2BlockId): Promise<void> {
|
|
661
|
+
async handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void> {
|
|
420
662
|
// Step 1: Find transactions mined after the prune point
|
|
421
663
|
const txsToUnmine = this.#indices.findTxsMinedAfter(latestBlock.number);
|
|
422
664
|
if (txsToUnmine.length === 0) {
|
|
@@ -426,102 +668,240 @@ export class TxPoolV2Impl {
|
|
|
426
668
|
|
|
427
669
|
this.#log.info(`Handling prune to block ${latestBlock.number}: un-mining ${txsToUnmine.length} txs`);
|
|
428
670
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
671
|
+
await this.#store.transactionAsync(async () => {
|
|
672
|
+
// Step 2: Mark ALL un-mined txs with their original mined block number
|
|
673
|
+
// This ensures they get soft-deleted if removed later, and only hard-deleted
|
|
674
|
+
// when their original mined block is finalized
|
|
675
|
+
await this.#deletedPool.markFromPrunedBlock(
|
|
676
|
+
txsToUnmine.map(m => ({
|
|
677
|
+
txHash: m.txHash,
|
|
678
|
+
minedAtBlock: BlockNumber(m.minedL2BlockId!.number),
|
|
679
|
+
})),
|
|
680
|
+
);
|
|
433
681
|
|
|
434
|
-
|
|
435
|
-
|
|
682
|
+
// Step 3: Unmine - clear mined status from metadata
|
|
683
|
+
for (const meta of txsToUnmine) {
|
|
684
|
+
this.#indices.markAsUnmined(meta);
|
|
685
|
+
}
|
|
436
686
|
|
|
437
|
-
|
|
438
|
-
|
|
687
|
+
// If deleteAllTxs is set (epoch prune), delete all un-mined txs and return early
|
|
688
|
+
if (options?.deleteAllTxs) {
|
|
689
|
+
const allTxHashes = txsToUnmine.map(m => m.txHash);
|
|
690
|
+
await this.#deleteTxsBatch(allTxHashes);
|
|
691
|
+
this.#log.info(
|
|
692
|
+
`Handled prune to block ${latestBlock.number} with deleteAllTxs: deleted ${allTxHashes.length} txs`,
|
|
693
|
+
);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// Step 4: Filter out protected txs (they'll be handled by prepareForSlot)
|
|
698
|
+
const unprotectedTxs = this.#indices.filterUnprotected(txsToUnmine);
|
|
699
|
+
|
|
700
|
+
// Step 5: Validate for pending pool
|
|
701
|
+
const { valid, invalid } = await this.#revalidateMetadata(unprotectedTxs, 'during handlePrunedBlocks');
|
|
439
702
|
|
|
440
|
-
|
|
441
|
-
|
|
703
|
+
// Step 6: Resolve nullifier conflicts and add winners to pending indices
|
|
704
|
+
const { toEvict } = this.#applyNullifierConflictResolution(valid);
|
|
442
705
|
|
|
443
|
-
|
|
444
|
-
|
|
706
|
+
// Step 7: Delete invalid txs and evict conflict losers
|
|
707
|
+
await this.#deleteTxsBatch(invalid);
|
|
708
|
+
await this.#evictTxs(toEvict, 'NullifierConflict');
|
|
445
709
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
710
|
+
this.#log.info(
|
|
711
|
+
`Handled prune to block ${latestBlock.number}: ${valid.length} txs restored to pending, ${invalid.length} invalid, ${toEvict.length} evicted due to nullifier conflicts`,
|
|
712
|
+
{ txHashesRestored: valid.map(m => m.txHash), txHashesInvalid: invalid, txHashesEvicted: toEvict },
|
|
713
|
+
);
|
|
714
|
+
|
|
715
|
+
// Step 8: Run eviction rules for ALL pending txs (not just restored ones)
|
|
716
|
+
// This handles cases like existing pending txs with invalid fee payer balances
|
|
717
|
+
await this.#evictionManager.evictAfterChainPrune(latestBlock.number);
|
|
718
|
+
});
|
|
449
719
|
}
|
|
450
720
|
|
|
451
721
|
async handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
452
|
-
|
|
453
|
-
|
|
722
|
+
await this.#store.transactionAsync(async () => {
|
|
723
|
+
await this.#deleteTxsBatch(txHashes.map(h => h.toString()));
|
|
724
|
+
});
|
|
454
725
|
|
|
455
|
-
this.#log.info(`Deleted ${txHashes.length} failed txs
|
|
726
|
+
this.#log.info(`Deleted ${txHashes.length} failed txs`, { txHashes: txHashes.map(h => h.toString()) });
|
|
456
727
|
}
|
|
457
728
|
|
|
458
|
-
|
|
459
|
-
|
|
729
|
+
/**
|
|
730
|
+
* Resolves what a finalized block event should process: the cutoff block and the mined txs at or
|
|
731
|
+
* before it. The wrapper feeds the result to archiveFinalizedTxs / finalizeTxs in chunks, each as
|
|
732
|
+
* its own serial-queue item, so gossip-driven pool operations can interleave with finalization
|
|
733
|
+
* instead of stalling behind an entire epoch's worth of tx processing.
|
|
734
|
+
*/
|
|
735
|
+
async prepareFinalization(block: BlockHeader): Promise<{ cutoffBlock: BlockNumber; txHashes: string[] }> {
|
|
736
|
+
// Hold finalized txs for a configurable margin behind the finalized tip so a prover still
|
|
737
|
+
// proving an epoch with already-finalized blocks isn't starved of its txs. 0 deletes at the finalized tip.
|
|
738
|
+
const cutoffBlock = await this.#finalizationCutoffBlock(block);
|
|
739
|
+
return { cutoffBlock, txHashes: this.#indices.findTxsMinedAtOrBefore(cutoffBlock) };
|
|
740
|
+
}
|
|
460
741
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
742
|
+
/**
|
|
743
|
+
* Copies the given finalized txs into the archive. The pool stores txs proof-stripped, which is
|
|
744
|
+
* exactly the archive format, so buffers are copied as-is without deserialization.
|
|
745
|
+
*/
|
|
746
|
+
async archiveFinalizedTxs(txHashes: string[]): Promise<void> {
|
|
747
|
+
if (!this.#archive.isEnabled()) {
|
|
464
748
|
return;
|
|
465
749
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
472
|
-
if (buffer) {
|
|
473
|
-
txsToArchive.push(Tx.fromBuffer(buffer));
|
|
474
|
-
}
|
|
750
|
+
const entries: { txHash: string; buffer: Buffer }[] = [];
|
|
751
|
+
for (const txHash of txHashes) {
|
|
752
|
+
const buffer = await this.#txsDB.getAsync(txHash);
|
|
753
|
+
if (buffer) {
|
|
754
|
+
entries.push({ txHash, buffer });
|
|
475
755
|
}
|
|
476
756
|
}
|
|
757
|
+
await this.#archive.archiveTxBuffers(entries);
|
|
758
|
+
}
|
|
477
759
|
|
|
478
|
-
|
|
479
|
-
|
|
760
|
+
/**
|
|
761
|
+
* Deletes a batch of finalized mined txs from the active pool. Callers may invoke this in
|
|
762
|
+
* chunks: a crash between chunks leaves some finalized txs mined, and the next finalized-block
|
|
763
|
+
* event lists and deletes them again (the operation is idempotent), so per-chunk atomicity is
|
|
764
|
+
* sufficient. Since other pool operations may interleave between the finalization plan being
|
|
765
|
+
* computed and this call, each tx is re-checked to still be mined at or before the cutoff.
|
|
766
|
+
*/
|
|
767
|
+
async deleteFinalizedTxs(txHashes: string[], cutoffBlock: BlockNumber): Promise<void> {
|
|
768
|
+
const stillFinalized = txHashes.filter(txHash => {
|
|
769
|
+
const minedBlock = this.#indices.getMetadata(txHash)?.minedL2BlockId?.number;
|
|
770
|
+
return minedBlock !== undefined && minedBlock <= cutoffBlock;
|
|
771
|
+
});
|
|
772
|
+
if (stillFinalized.length === 0) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
await this.#store.transactionAsync(async () => {
|
|
776
|
+
await this.#deleteTxsBatch(stillFinalized);
|
|
777
|
+
});
|
|
778
|
+
}
|
|
480
779
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
780
|
+
/** Finalizes soft-deleted txs up to the cutoff and logs the completed finalization. */
|
|
781
|
+
async completeFinalization(
|
|
782
|
+
txHashes: string[],
|
|
783
|
+
cutoffBlock: BlockNumber,
|
|
784
|
+
finalizedBlockNumber: BlockNumber,
|
|
785
|
+
): Promise<void> {
|
|
786
|
+
await this.#store.transactionAsync(async () => {
|
|
787
|
+
await this.#deletedPool.finalizeBlock(cutoffBlock);
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
if (txHashes.length > 0) {
|
|
791
|
+
this.#log.info(`Finalized ${txHashes.length} mined txs from blocks up to ${cutoffBlock}`, {
|
|
792
|
+
txHashes,
|
|
793
|
+
finalizedBlockNumber,
|
|
794
|
+
cutoffBlock,
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Resolves the block up to which finalized txs may be deleted, given `keepFinalizedTxsForSlots`.
|
|
801
|
+
* With a margin of 0 this is just the finalized block. Otherwise we keep txs whose block is within
|
|
802
|
+
* the margin (in slots) of the finalized tip: take the target slot `finalizedSlot - margin`, find the
|
|
803
|
+
* latest checkpoint at or before it with a single reverse range query (`limit: 1`), and use that
|
|
804
|
+
* checkpoint's last block as the cutoff. This rounds to a checkpoint boundary, so it can retain slightly
|
|
805
|
+
* more than the configured margin but never less, and never deletes past the finalized block.
|
|
806
|
+
*/
|
|
807
|
+
async #finalizationCutoffBlock(block: BlockHeader): Promise<BlockNumber> {
|
|
808
|
+
const keepSlots = this.#config.keepFinalizedTxsForSlots;
|
|
809
|
+
if (keepSlots <= 0) {
|
|
810
|
+
return block.globalVariables.blockNumber;
|
|
484
811
|
}
|
|
485
812
|
|
|
486
|
-
|
|
813
|
+
// The goal here really is to ensure we keep transactions long enough for them to be proven.
|
|
814
|
+
// So we could be smart and calculate the number of slots until the end of the proof submission window.
|
|
815
|
+
// Our approach here is a lot simpler however and we just keep transactions for the configured number
|
|
816
|
+
// of slots past L1 finalisation. This means we may keep transactions in the mined pool for longer
|
|
817
|
+
// than strictly necessary.
|
|
818
|
+
const targetSlot = block.getSlot() - keepSlots;
|
|
819
|
+
if (targetSlot < 0) {
|
|
820
|
+
// The margin reaches past genesis: keep everything.
|
|
821
|
+
return BlockNumber(0);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const [checkpoint] = await this.#l2BlockSource.getCheckpointsData({
|
|
825
|
+
fromSlot: SlotNumber(targetSlot),
|
|
826
|
+
limit: 1,
|
|
827
|
+
reverse: true,
|
|
828
|
+
});
|
|
829
|
+
// No checkpoint at or before the target slot (e.g. early chain): keep everything.
|
|
830
|
+
return checkpoint ? BlockNumber(checkpoint.startBlock + checkpoint.blockCount - 1) : BlockNumber(0);
|
|
487
831
|
}
|
|
488
832
|
|
|
489
833
|
// === Query Methods ===
|
|
490
834
|
|
|
491
|
-
async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
492
|
-
const
|
|
493
|
-
|
|
835
|
+
async getTxByHash(txHash: TxHash, opts: { includeProof?: boolean } = {}): Promise<Tx | undefined> {
|
|
836
|
+
const txHashStr = txHash.toString();
|
|
837
|
+
const buffer = await this.#txsDB.getAsync(txHashStr);
|
|
838
|
+
if (!buffer) {
|
|
839
|
+
return undefined;
|
|
840
|
+
}
|
|
841
|
+
return opts.includeProof === false ? Tx.fromBuffer(buffer) : this.#loadTxWithProof(txHashStr, buffer);
|
|
494
842
|
}
|
|
495
843
|
|
|
496
|
-
async getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
844
|
+
async getTxsByHash(txHashes: TxHash[], opts: { includeProof?: boolean } = {}): Promise<(Tx | undefined)[]> {
|
|
497
845
|
const results: (Tx | undefined)[] = [];
|
|
498
846
|
for (const h of txHashes) {
|
|
499
|
-
|
|
500
|
-
results.push(buffer ? Tx.fromBuffer(buffer) : undefined);
|
|
847
|
+
results.push(await this.getTxByHash(h, opts));
|
|
501
848
|
}
|
|
502
849
|
return results;
|
|
503
850
|
}
|
|
504
851
|
|
|
852
|
+
/** Deserializes a tx blob loaded from #txsDB together with its separately-stored proof. */
|
|
853
|
+
async #loadTxWithProof(txHashStr: string, buffer: Buffer): Promise<Tx> {
|
|
854
|
+
const proofBuffer = await this.#proofsDB.getAsync(txHashStr);
|
|
855
|
+
if (!proofBuffer) {
|
|
856
|
+
// #addTx always writes a proof entry (an empty proof serializes to a 4-byte sentinel), so a missing entry
|
|
857
|
+
// means the blob/proof invariant is broken. Return the proofless tx but flag it, since a consumer that needs
|
|
858
|
+
// the proof (eg serving peers) would otherwise fail far away from the root cause.
|
|
859
|
+
this.#log.warn(`Missing stored proof for tx ${txHashStr}`, { txHash: txHashStr });
|
|
860
|
+
return Tx.fromBuffer(buffer);
|
|
861
|
+
}
|
|
862
|
+
return Tx.fromBuffers(buffer, proofBuffer);
|
|
863
|
+
}
|
|
864
|
+
|
|
505
865
|
hasTxs(txHashes: TxHash[]): boolean[] {
|
|
506
|
-
return txHashes.map(h =>
|
|
866
|
+
return txHashes.map(h => {
|
|
867
|
+
const hashStr = h.toString();
|
|
868
|
+
return this.#indices.has(hashStr) || this.#deletedPool.isSoftDeleted(hashStr);
|
|
869
|
+
});
|
|
507
870
|
}
|
|
508
871
|
|
|
509
872
|
getTxStatus(txHash: TxHash): TxState | undefined {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
873
|
+
const txHashStr = txHash.toString();
|
|
874
|
+
const meta = this.#indices.getMetadata(txHashStr);
|
|
875
|
+
if (meta) {
|
|
876
|
+
return this.#indices.getTxState(meta);
|
|
877
|
+
}
|
|
878
|
+
// Check if soft-deleted
|
|
879
|
+
if (this.#deletedPool.isSoftDeleted(txHashStr)) {
|
|
880
|
+
return 'deleted';
|
|
513
881
|
}
|
|
514
|
-
return
|
|
882
|
+
return undefined;
|
|
515
883
|
}
|
|
516
884
|
|
|
517
885
|
getPendingTxHashes(): TxHash[] {
|
|
518
886
|
return [...this.#indices.iteratePendingByPriority('desc')].map(hash => TxHash.fromString(hash));
|
|
519
887
|
}
|
|
520
888
|
|
|
889
|
+
getEligiblePendingTxHashes(): TxHash[] {
|
|
890
|
+
const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
|
|
891
|
+
return [...this.#indices.iterateEligiblePendingByPriority('desc', maxReceivedAt)].map(hash =>
|
|
892
|
+
TxHash.fromString(hash),
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
|
|
521
896
|
getPendingTxCount(): number {
|
|
522
897
|
return this.#indices.getPendingTxCount();
|
|
523
898
|
}
|
|
524
899
|
|
|
900
|
+
hasEligiblePendingTxs(minCount: number): boolean {
|
|
901
|
+
const maxReceivedAt = this.#dateProvider.now() - this.#config.minTxPoolAgeMs;
|
|
902
|
+
return this.#indices.hasEligiblePendingTxs(maxReceivedAt, minCount);
|
|
903
|
+
}
|
|
904
|
+
|
|
525
905
|
getMinedTxHashes(): [TxHash, L2BlockId][] {
|
|
526
906
|
return this.#indices.getMinedTxs().map(([hash, blockId]) => [TxHash.fromString(hash), blockId]);
|
|
527
907
|
}
|
|
@@ -562,6 +942,12 @@ export class TxPoolV2Impl {
|
|
|
562
942
|
this.#config.archivedTxLimit = config.archivedTxLimit;
|
|
563
943
|
this.#archive.updateLimit(config.archivedTxLimit);
|
|
564
944
|
}
|
|
945
|
+
if (config.minTxPoolAgeMs !== undefined) {
|
|
946
|
+
this.#config.minTxPoolAgeMs = config.minTxPoolAgeMs;
|
|
947
|
+
}
|
|
948
|
+
if (config.keepFinalizedTxsForSlots !== undefined) {
|
|
949
|
+
this.#config.keepFinalizedTxsForSlots = config.keepFinalizedTxsForSlots;
|
|
950
|
+
}
|
|
565
951
|
// Update eviction rules with new config
|
|
566
952
|
this.#evictionManager.updateConfig(config);
|
|
567
953
|
}
|
|
@@ -579,8 +965,17 @@ export class TxPoolV2Impl {
|
|
|
579
965
|
|
|
580
966
|
// === Metrics ===
|
|
581
967
|
|
|
582
|
-
countTxs(): {
|
|
583
|
-
|
|
968
|
+
countTxs(): {
|
|
969
|
+
pending: number;
|
|
970
|
+
protected: number;
|
|
971
|
+
mined: number;
|
|
972
|
+
softDeleted: number;
|
|
973
|
+
totalMetadataBytes: number;
|
|
974
|
+
} {
|
|
975
|
+
return {
|
|
976
|
+
...this.#indices.countTxs(),
|
|
977
|
+
softDeleted: this.#deletedPool.getSoftDeletedCount(),
|
|
978
|
+
};
|
|
584
979
|
}
|
|
585
980
|
|
|
586
981
|
// ============================================================================
|
|
@@ -595,11 +990,15 @@ export class TxPoolV2Impl {
|
|
|
595
990
|
tx: Tx,
|
|
596
991
|
state: 'pending' | { protected: SlotNumber } | { mined: L2BlockId },
|
|
597
992
|
opts: { source?: string } = {},
|
|
993
|
+
precomputedMeta?: TxMetaData,
|
|
598
994
|
): Promise<TxMetaData> {
|
|
599
995
|
const txHashStr = tx.getTxHash().toString();
|
|
600
|
-
const meta = await buildTxMetaData(tx);
|
|
996
|
+
const meta = precomputedMeta ?? (await buildTxMetaData(tx));
|
|
997
|
+
meta.receivedAt = this.#dateProvider.now();
|
|
601
998
|
|
|
602
|
-
await this.#txsDB.set(txHashStr, tx.toBuffer());
|
|
999
|
+
await this.#txsDB.set(txHashStr, tx.withoutProof().toBuffer());
|
|
1000
|
+
await this.#proofsDB.set(txHashStr, tx.chonkProof.toBuffer());
|
|
1001
|
+
await this.#deletedPool.clearSoftDeleted(txHashStr);
|
|
603
1002
|
this.#callbacks.onTxsAdded([tx], opts);
|
|
604
1003
|
|
|
605
1004
|
if (state === 'pending') {
|
|
@@ -612,9 +1011,11 @@ export class TxPoolV2Impl {
|
|
|
612
1011
|
}
|
|
613
1012
|
|
|
614
1013
|
const stateStr = typeof state === 'string' ? state : Object.keys(state)[0];
|
|
615
|
-
this.#log.
|
|
1014
|
+
this.#log.debug(`Added tx ${txHashStr} as ${stateStr}`, {
|
|
616
1015
|
eventName: 'tx-added-to-pool',
|
|
1016
|
+
txHash: txHashStr,
|
|
617
1017
|
state: stateStr,
|
|
1018
|
+
source: opts.source,
|
|
618
1019
|
});
|
|
619
1020
|
|
|
620
1021
|
return meta;
|
|
@@ -624,10 +1025,21 @@ export class TxPoolV2Impl {
|
|
|
624
1025
|
* Deletes a transaction from both indices and DB.
|
|
625
1026
|
* Emits onTxsRemoved callback immediately after DB delete.
|
|
626
1027
|
*/
|
|
1028
|
+
/**
|
|
1029
|
+
* Deletes a transaction from the pool.
|
|
1030
|
+
* Delegates to DeletedPool which decides soft vs hard delete based on whether
|
|
1031
|
+
* the tx is from a pruned block.
|
|
1032
|
+
*/
|
|
627
1033
|
async #deleteTx(txHashStr: string): Promise<void> {
|
|
628
1034
|
this.#indices.remove(txHashStr);
|
|
629
|
-
await this.#txsDB.delete(txHashStr);
|
|
630
1035
|
this.#callbacks.onTxsRemoved([txHashStr]);
|
|
1036
|
+
await this.#deletedPool.deleteTx(txHashStr);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/** Hard-deletes a tx's stored data (tx blob and proof) from the DB. */
|
|
1040
|
+
async #deleteTxData(txHashStr: string): Promise<void> {
|
|
1041
|
+
await this.#txsDB.delete(txHashStr);
|
|
1042
|
+
await this.#proofsDB.delete(txHashStr);
|
|
631
1043
|
}
|
|
632
1044
|
|
|
633
1045
|
/** Deletes a batch of transactions, emitting callbacks individually for each. */
|
|
@@ -637,68 +1049,53 @@ export class TxPoolV2Impl {
|
|
|
637
1049
|
}
|
|
638
1050
|
}
|
|
639
1051
|
|
|
1052
|
+
/** Evicts transactions: records eviction metric with reason, caches hashes, then deletes. */
|
|
1053
|
+
async #evictTxs(txHashes: string[], reason: string): Promise<void> {
|
|
1054
|
+
if (txHashes.length === 0) {
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
this.#instrumentation.recordEvictions(txHashes.length, reason);
|
|
1058
|
+
for (const txHashStr of txHashes) {
|
|
1059
|
+
this.#log.debug(`Evicting tx ${txHashStr}`, { txHash: txHashStr, reason });
|
|
1060
|
+
this.#evictedTxHashes.add(txHashStr);
|
|
1061
|
+
}
|
|
1062
|
+
await this.#deleteTxsBatch(txHashes);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
640
1065
|
// ============================================================================
|
|
641
1066
|
// PRIVATE HELPERS - Validation & Conflict Resolution
|
|
642
1067
|
// ============================================================================
|
|
643
1068
|
|
|
644
|
-
/** Validates
|
|
645
|
-
async #
|
|
646
|
-
const
|
|
1069
|
+
/** Validates transaction metadata, returning true if valid */
|
|
1070
|
+
async #validateMeta(meta: TxMetaData, validator?: TxValidator<TxMetaData>, context?: string): Promise<boolean> {
|
|
1071
|
+
const txValidator = validator ?? (await this.#createTxValidator());
|
|
1072
|
+
const result = await txValidator.validateTx(meta);
|
|
647
1073
|
if (result.result !== 'valid') {
|
|
648
1074
|
const contextStr = context ? ` ${context}` : '';
|
|
649
|
-
this.#log.info(`Tx ${
|
|
1075
|
+
this.#log.info(`Tx ${meta.txHash}${contextStr} failed validation: ${result.reason?.join(', ')}`);
|
|
650
1076
|
return false;
|
|
651
1077
|
}
|
|
652
1078
|
return true;
|
|
653
1079
|
}
|
|
654
1080
|
|
|
655
|
-
/**
|
|
656
|
-
async #
|
|
657
|
-
|
|
658
|
-
const missing: string[] = [];
|
|
659
|
-
|
|
660
|
-
for (const meta of metas) {
|
|
661
|
-
const buffer = await this.#txsDB.getAsync(meta.txHash);
|
|
662
|
-
if (!buffer) {
|
|
663
|
-
this.#log.warn(`Tx ${meta.txHash} not found in DB`);
|
|
664
|
-
missing.push(meta.txHash);
|
|
665
|
-
continue;
|
|
666
|
-
}
|
|
667
|
-
loaded.push({ tx: Tx.fromBuffer(buffer), meta });
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
return { loaded, missing };
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/** Validates a batch of transactions, returning valid and invalid groups */
|
|
674
|
-
async #validateTxBatch(
|
|
675
|
-
txs: { tx: Tx; meta: TxMetaData }[],
|
|
1081
|
+
/** Validates metadata directly */
|
|
1082
|
+
async #revalidateMetadata(
|
|
1083
|
+
metas: TxMetaData[],
|
|
676
1084
|
context?: string,
|
|
677
1085
|
): Promise<{ valid: TxMetaData[]; invalid: string[] }> {
|
|
678
1086
|
const valid: TxMetaData[] = [];
|
|
679
1087
|
const invalid: string[] = [];
|
|
680
|
-
|
|
681
|
-
for (const
|
|
682
|
-
if (await this.#
|
|
1088
|
+
const validator = await this.#createTxValidator();
|
|
1089
|
+
for (const meta of metas) {
|
|
1090
|
+
if (await this.#validateMeta(meta, validator, context)) {
|
|
683
1091
|
valid.push(meta);
|
|
684
1092
|
} else {
|
|
685
1093
|
invalid.push(meta.txHash);
|
|
686
1094
|
}
|
|
687
1095
|
}
|
|
688
|
-
|
|
689
1096
|
return { valid, invalid };
|
|
690
1097
|
}
|
|
691
1098
|
|
|
692
|
-
/** Loads transactions from DB and validates them */
|
|
693
|
-
async #loadAndValidateTxs(
|
|
694
|
-
metas: TxMetaData[],
|
|
695
|
-
context?: string,
|
|
696
|
-
): Promise<{ valid: TxMetaData[]; invalid: string[] }> {
|
|
697
|
-
const { loaded, missing } = await this.#loadTxsFromDb(metas);
|
|
698
|
-
const { valid, invalid } = await this.#validateTxBatch(loaded, context);
|
|
699
|
-
return { valid, invalid: [...missing, ...invalid] };
|
|
700
|
-
}
|
|
701
|
-
|
|
702
1099
|
/**
|
|
703
1100
|
* Resolves nullifier conflicts between incoming txs and existing pending txs.
|
|
704
1101
|
* Modifies the pending indices during iteration to maintain consistent state
|
|
@@ -759,45 +1156,6 @@ export class TxPoolV2Impl {
|
|
|
759
1156
|
};
|
|
760
1157
|
}
|
|
761
1158
|
|
|
762
|
-
/** Loads all transactions from the database, returning loaded txs and deserialization errors */
|
|
763
|
-
async #loadAllTxsFromDb(): Promise<{
|
|
764
|
-
loaded: { tx: Tx; meta: TxMetaData }[];
|
|
765
|
-
errors: string[];
|
|
766
|
-
}> {
|
|
767
|
-
const loaded: { tx: Tx; meta: TxMetaData }[] = [];
|
|
768
|
-
const errors: string[] = [];
|
|
769
|
-
|
|
770
|
-
for await (const [txHashStr, buffer] of this.#txsDB.entriesAsync()) {
|
|
771
|
-
try {
|
|
772
|
-
const tx = Tx.fromBuffer(buffer);
|
|
773
|
-
const meta = await buildTxMetaData(tx);
|
|
774
|
-
loaded.push({ tx, meta });
|
|
775
|
-
} catch (err) {
|
|
776
|
-
this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, { err });
|
|
777
|
-
errors.push(txHashStr);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
return { loaded, errors };
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
/** Queries block source and marks mined status on transaction metadata */
|
|
785
|
-
async #markMinedStatusBatch(metas: TxMetaData[]): Promise<void> {
|
|
786
|
-
for (const meta of metas) {
|
|
787
|
-
try {
|
|
788
|
-
const txEffect = await this.#l2BlockSource.getTxEffect(TxHash.fromString(meta.txHash));
|
|
789
|
-
if (txEffect) {
|
|
790
|
-
meta.minedL2BlockId = {
|
|
791
|
-
number: txEffect.l2BlockNumber,
|
|
792
|
-
hash: txEffect.l2BlockHash.toString(),
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
} catch (err) {
|
|
796
|
-
this.#log.warn(`Failed to check mined status for tx ${meta.txHash}`, { err });
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
|
|
801
1159
|
/**
|
|
802
1160
|
* Rebuilds the pending pool by processing each tx through pre-add rules.
|
|
803
1161
|
* Starts with an empty pending pool and adds txs one by one, resolving conflicts.
|
|
@@ -815,7 +1173,9 @@ export class TxPoolV2Impl {
|
|
|
815
1173
|
if (preAddResult.shouldIgnore) {
|
|
816
1174
|
// Transaction rejected - mark for deletion from DB
|
|
817
1175
|
rejected.push(meta.txHash);
|
|
818
|
-
this.#log.debug(
|
|
1176
|
+
this.#log.debug(
|
|
1177
|
+
`Rejected tx ${meta.txHash} during rebuild: ${preAddResult.reason?.message ?? 'unknown reason'}`,
|
|
1178
|
+
);
|
|
819
1179
|
continue;
|
|
820
1180
|
}
|
|
821
1181
|
|
|
@@ -851,7 +1211,7 @@ export class TxPoolV2Impl {
|
|
|
851
1211
|
getFeePayerPendingTxs: (feePayer: string) => this.#indices.getFeePayerPendingTxs(feePayer),
|
|
852
1212
|
getPendingTxCount: () => this.#indices.getPendingTxCount(),
|
|
853
1213
|
getLowestPriorityPending: (limit: number) => this.#indices.getLowestPriorityPending(limit),
|
|
854
|
-
deleteTxs: (txHashes: string[]) => this.#
|
|
1214
|
+
deleteTxs: (txHashes: string[], reason?: string) => this.#evictTxs(txHashes, reason ?? 'unknown'),
|
|
855
1215
|
};
|
|
856
1216
|
}
|
|
857
1217
|
|
|
@@ -870,7 +1230,7 @@ export class TxPoolV2Impl {
|
|
|
870
1230
|
const publicStateSource = new DatabasePublicStateSource(db);
|
|
871
1231
|
const balance = await publicStateSource.storageRead(
|
|
872
1232
|
ProtocolContractAddress.FeeJuice,
|
|
873
|
-
await computeFeePayerBalanceStorageSlot(AztecAddress.
|
|
1233
|
+
await computeFeePayerBalanceStorageSlot(AztecAddress.fromStringUnsafe(feePayer)),
|
|
874
1234
|
);
|
|
875
1235
|
return balance.toBigInt();
|
|
876
1236
|
},
|