@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f81dbcf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +8 -8
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +42 -13
- package/dest/client/interface.d.ts +39 -33
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +37 -50
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +144 -223
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +6 -7
- package/dest/config.d.ts +47 -11
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +94 -31
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +21 -12
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +67 -37
- 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 +53 -53
- 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 +2 -2
- package/dest/mem_pools/index.d.ts +2 -1
- package/dest/mem_pools/index.d.ts.map +1 -1
- 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/eviction/invalid_txs_after_mining_rule.js +3 -3
- package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +4 -4
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +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 +5 -2
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +12 -4
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +54 -5
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +8 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +7 -5
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +14 -6
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +16 -4
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +3 -3
- package/dest/mem_pools/tx_pool_v2/index.d.ts +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 +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +22 -8
- 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 +68 -11
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +132 -17
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +12 -3
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +36 -14
- 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 +11 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +13 -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 +336 -185
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +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 +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/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/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/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 +125 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +233 -59
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +44 -23
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/dummy_service.d.ts +9 -5
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +7 -4
- package/dest/services/encoding.d.ts +3 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +11 -10
- 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 +25 -14
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +158 -123
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -3
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +5 -9
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +2 -6
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +10 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +25 -46
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +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_reqresp.d.ts +7 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +11 -4
- package/dest/services/service.d.ts +22 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +19 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +46 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +56 -36
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +90 -0
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +2 -1
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +7 -6
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/dest/services/tx_collection/slow_tx_collection.d.ts +7 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +60 -26
- package/dest/services/tx_collection/tx_collection.d.ts +23 -10
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +75 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +26 -29
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +9 -6
- package/dest/services/tx_provider.d.ts +4 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +9 -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 +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +30 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +105 -4
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +35 -24
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +95 -36
- 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 +16 -15
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +4 -1
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +77 -23
- package/src/client/interface.ts +43 -33
- package/src/client/p2p_client.ts +165 -265
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +19 -10
- package/src/config.ts +139 -33
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +95 -44
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +57 -53
- package/src/mem_pools/attestation_pool/index.ts +3 -3
- package/src/mem_pools/attestation_pool/mocks.ts +2 -1
- package/src/mem_pools/index.ts +3 -0
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool/README.md +1 -1
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +3 -3
- package/src/mem_pools/tx_pool/priority.ts +4 -4
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
- package/src/mem_pools/tx_pool_v2/README.md +85 -11
- 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 +5 -2
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +18 -4
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +4 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +59 -4
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +5 -5
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +14 -9
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +33 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +4 -3
- package/src/mem_pools/tx_pool_v2/index.ts +2 -1
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +23 -8
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +189 -23
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +43 -16
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +18 -7
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +379 -182
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
- package/src/msg_validators/tx_validator/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +5 -5
- 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/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +373 -77
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +51 -26
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +12 -6
- package/src/services/encoding.ts +9 -9
- 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 +170 -132
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +6 -6
- package/src/services/reqresp/batch-tx-requester/interface.ts +1 -5
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +23 -71
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +13 -3
- package/src/services/service.ts +31 -2
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +65 -32
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +1 -0
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +8 -7
- package/src/services/tx_collection/slow_tx_collection.ts +66 -33
- package/src/services/tx_collection/tx_collection.ts +113 -16
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +10 -8
- package/src/services/tx_provider.ts +10 -9
- package/src/test-helpers/make-test-p2p-clients.ts +3 -5
- package/src/test-helpers/mock-pubsub.ts +146 -9
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/test-helpers/testbench-utils.ts +109 -40
- package/src/testbench/p2p_client_testbench_worker.ts +24 -20
- package/src/testbench/worker_client_manager.ts +11 -4
- package/src/util.ts +7 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
|
@@ -5,7 +5,7 @@ import { EvictionEvent } from './interfaces.js';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Eviction rule that removes low-priority transactions when the pool exceeds configured limits.
|
|
8
|
-
*
|
|
8
|
+
* Triggers on TXS_ADDED and CHAIN_PRUNED events.
|
|
9
9
|
*/
|
|
10
10
|
export class LowPriorityEvictionRule implements EvictionRule {
|
|
11
11
|
public readonly name = 'LowPriorityEviction';
|
|
@@ -18,7 +18,7 @@ export class LowPriorityEvictionRule implements EvictionRule {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
async evict(context: EvictionContext, pool: PoolOperations): Promise<EvictionResult> {
|
|
21
|
-
if (context.event !== EvictionEvent.TXS_ADDED) {
|
|
21
|
+
if (context.event !== EvictionEvent.TXS_ADDED && context.event !== EvictionEvent.CHAIN_PRUNED) {
|
|
22
22
|
return {
|
|
23
23
|
reason: 'low_priority',
|
|
24
24
|
success: true,
|
|
@@ -48,19 +48,24 @@ export class LowPriorityEvictionRule implements EvictionRule {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
this.log.
|
|
52
|
-
`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${this.maxPoolSize}`,
|
|
53
|
-
);
|
|
51
|
+
this.log.info(`Evicting low priority txs. Pending tx count above limit: ${currentTxCount} > ${this.maxPoolSize}`);
|
|
54
52
|
const numberToEvict = currentTxCount - this.maxPoolSize;
|
|
55
53
|
const txsToEvict = pool.getLowestPriorityPending(numberToEvict);
|
|
56
54
|
|
|
57
55
|
if (txsToEvict.length > 0) {
|
|
58
|
-
|
|
56
|
+
if (context.event === EvictionEvent.TXS_ADDED) {
|
|
57
|
+
const toEvictSet = new Set(txsToEvict);
|
|
58
|
+
const numNewTxsEvicted = context.newTxHashes.filter(newTxHash => toEvictSet.has(newTxHash)).length;
|
|
59
|
+
this.log.info(`Evicted ${txsToEvict.length} low priority txs, including ${numNewTxsEvicted} newly added txs`);
|
|
60
|
+
} else {
|
|
61
|
+
this.log.info(`Evicted ${txsToEvict.length} low priority txs after chain prune`);
|
|
62
|
+
}
|
|
63
|
+
await pool.deleteTxs(txsToEvict, this.name);
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
this.log.debug(`Evicted ${txsToEvict.length} low priority txs`, {
|
|
67
|
+
txHashes: txsToEvict,
|
|
68
|
+
});
|
|
64
69
|
|
|
65
70
|
return {
|
|
66
71
|
reason: 'low_priority',
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
|
-
import type
|
|
4
|
-
import
|
|
3
|
+
import { type TxMetaData, comparePriority, getMinimumPriceBumpFee } from '../tx_metadata.js';
|
|
4
|
+
import {
|
|
5
|
+
type EvictionConfig,
|
|
6
|
+
type PreAddContext,
|
|
7
|
+
type PreAddPoolAccess,
|
|
8
|
+
type PreAddResult,
|
|
9
|
+
type PreAddRule,
|
|
10
|
+
TxPoolRejectionCode,
|
|
11
|
+
} from './interfaces.js';
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* Pre-add rule that checks if the pool is at capacity and handles low-priority eviction.
|
|
@@ -20,7 +27,7 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
20
27
|
this.maxPoolSize = config.maxPoolSize;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
|
|
30
|
+
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, context?: PreAddContext): Promise<PreAddResult> {
|
|
24
31
|
// Skip if max pool size is disabled (0 = unlimited)
|
|
25
32
|
if (this.maxPoolSize === 0) {
|
|
26
33
|
return Promise.resolve({ shouldIgnore: false, txHashesToEvict: [] });
|
|
@@ -40,8 +47,18 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
40
47
|
return Promise.resolve({ shouldIgnore: false, txHashesToEvict: [] });
|
|
41
48
|
}
|
|
42
49
|
|
|
43
|
-
//
|
|
44
|
-
|
|
50
|
+
// Compare incoming tx against lowest priority tx.
|
|
51
|
+
// feeOnly mode (RPC): use strict fee comparison only — avoids churn from hash ordering.
|
|
52
|
+
// When price bump is also set, require the bumped fee threshold.
|
|
53
|
+
// Default (gossip): use full comparePriority (fee + tx hash tiebreaker) for determinism.
|
|
54
|
+
const isHigherPriority = context?.feeComparisonOnly
|
|
55
|
+
? context.priceBumpPercentage !== undefined
|
|
56
|
+
? incomingMeta.priorityFee >=
|
|
57
|
+
getMinimumPriceBumpFee(lowestPriorityMeta.priorityFee, context.priceBumpPercentage)
|
|
58
|
+
: incomingMeta.priorityFee > lowestPriorityMeta.priorityFee
|
|
59
|
+
: comparePriority(incomingMeta, lowestPriorityMeta) > 0;
|
|
60
|
+
|
|
61
|
+
if (isHigherPriority) {
|
|
45
62
|
this.log.debug(
|
|
46
63
|
`Pool at capacity (${currentCount}/${this.maxPoolSize}), evicting ${lowestPriorityMeta.txHash} ` +
|
|
47
64
|
`(priority ${lowestPriorityMeta.priorityFee}) for ${incomingMeta.txHash} (priority ${incomingMeta.priorityFee})`,
|
|
@@ -53,6 +70,11 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
53
70
|
}
|
|
54
71
|
|
|
55
72
|
// Incoming tx has equal or lower priority - ignore it (it would be evicted anyway)
|
|
73
|
+
const minimumFee =
|
|
74
|
+
context?.feeComparisonOnly && context.priceBumpPercentage !== undefined
|
|
75
|
+
? getMinimumPriceBumpFee(lowestPriorityMeta.priorityFee, context.priceBumpPercentage)
|
|
76
|
+
: lowestPriorityMeta.priorityFee + 1n;
|
|
77
|
+
|
|
56
78
|
this.log.debug(
|
|
57
79
|
`Pool at capacity (${currentCount}/${this.maxPoolSize}), ignoring ${incomingMeta.txHash} ` +
|
|
58
80
|
`(priority ${incomingMeta.priorityFee}) - lower than existing minimum (priority ${lowestPriorityMeta.priorityFee})`,
|
|
@@ -60,7 +82,12 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
60
82
|
return Promise.resolve({
|
|
61
83
|
shouldIgnore: true,
|
|
62
84
|
txHashesToEvict: [],
|
|
63
|
-
reason:
|
|
85
|
+
reason: {
|
|
86
|
+
code: TxPoolRejectionCode.LOW_PRIORITY_FEE,
|
|
87
|
+
message: `Tx does not meet minimum priority fee. Required: ${minimumFee}, got: ${incomingMeta.priorityFee}`,
|
|
88
|
+
minimumPriorityFee: minimumFee,
|
|
89
|
+
txPriorityFee: incomingMeta.priorityFee,
|
|
90
|
+
},
|
|
64
91
|
});
|
|
65
92
|
}
|
|
66
93
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
3
|
import { type TxMetaData, checkNullifierConflict } from '../tx_metadata.js';
|
|
4
|
-
import type { PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
|
|
4
|
+
import type { PreAddContext, PreAddPoolAccess, PreAddResult, PreAddRule } from './interfaces.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Pre-add rule that checks for nullifier conflicts between incoming and existing transactions.
|
|
@@ -15,15 +15,16 @@ export class NullifierConflictRule implements PreAddRule {
|
|
|
15
15
|
|
|
16
16
|
private log = createLogger('p2p:tx_pool_v2:nullifier_conflict_rule');
|
|
17
17
|
|
|
18
|
-
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess): Promise<PreAddResult> {
|
|
18
|
+
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, context?: PreAddContext): Promise<PreAddResult> {
|
|
19
19
|
const result = checkNullifierConflict(
|
|
20
20
|
incomingMeta,
|
|
21
21
|
nullifier => poolAccess.getTxHashByNullifier(nullifier),
|
|
22
22
|
txHash => poolAccess.getMetadata(txHash),
|
|
23
|
+
context?.priceBumpPercentage,
|
|
23
24
|
);
|
|
24
25
|
|
|
25
26
|
if (result.shouldIgnore) {
|
|
26
|
-
this.log.debug(`Ignoring tx ${incomingMeta.txHash}: ${result.reason}`);
|
|
27
|
+
this.log.debug(`Ignoring tx ${incomingMeta.txHash}: ${result.reason?.message}`);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
return Promise.resolve(result);
|
|
@@ -7,5 +7,6 @@ export {
|
|
|
7
7
|
type PoolReadAccess,
|
|
8
8
|
DEFAULT_TX_POOL_V2_CONFIG,
|
|
9
9
|
} from './interfaces.js';
|
|
10
|
-
export { type TxMetaData, type TxState, buildTxMetaData, comparePriority } from './tx_metadata.js';
|
|
10
|
+
export { type TxMetaData, type TxState, buildTxMetaData, comparePriority, stubTxMetaData } from './tx_metadata.js';
|
|
11
11
|
export { TxArchive } from './archive/index.js';
|
|
12
|
+
export { DeletedPool } from './deleted_pool.js';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Attributes,
|
|
3
|
+
type Meter,
|
|
4
|
+
Metrics,
|
|
5
|
+
type ObservableGauge,
|
|
6
|
+
type ObservableResult,
|
|
7
|
+
type TelemetryClient,
|
|
8
|
+
type UpDownCounter,
|
|
9
|
+
createUpDownCounterWithDefault,
|
|
10
|
+
} from '@aztec/telemetry-client';
|
|
11
|
+
|
|
12
|
+
/** Callback that returns the current estimated metadata memory in bytes. */
|
|
13
|
+
export type MetadataMemoryCallback = () => number;
|
|
14
|
+
|
|
15
|
+
/** Instrumentation for TxPoolV2Impl internal operations. */
|
|
16
|
+
export class TxPoolV2Instrumentation {
|
|
17
|
+
#evictedCounter: UpDownCounter;
|
|
18
|
+
#ignoredCounter: UpDownCounter;
|
|
19
|
+
#rejectedCounter: UpDownCounter;
|
|
20
|
+
#softDeletedHitsCounter: UpDownCounter;
|
|
21
|
+
#missingOnProtectCounter: UpDownCounter;
|
|
22
|
+
#missingPreviouslyEvictedCounter: UpDownCounter;
|
|
23
|
+
#metadataMemoryGauge: ObservableGauge;
|
|
24
|
+
|
|
25
|
+
constructor(telemetry: TelemetryClient, metadataMemoryCallback: MetadataMemoryCallback) {
|
|
26
|
+
const meter: Meter = telemetry.getMeter('TxPoolV2Impl');
|
|
27
|
+
|
|
28
|
+
this.#evictedCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_EVICTED_COUNT);
|
|
29
|
+
this.#ignoredCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_IGNORED_COUNT);
|
|
30
|
+
this.#rejectedCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_REJECTED_COUNT);
|
|
31
|
+
this.#softDeletedHitsCounter = createUpDownCounterWithDefault(meter, Metrics.MEMPOOL_TX_POOL_V2_SOFT_DELETED_HITS);
|
|
32
|
+
this.#missingOnProtectCounter = createUpDownCounterWithDefault(
|
|
33
|
+
meter,
|
|
34
|
+
Metrics.MEMPOOL_TX_POOL_V2_MISSING_ON_PROTECT,
|
|
35
|
+
);
|
|
36
|
+
this.#missingPreviouslyEvictedCounter = createUpDownCounterWithDefault(
|
|
37
|
+
meter,
|
|
38
|
+
Metrics.MEMPOOL_TX_POOL_V2_MISSING_PREVIOUSLY_EVICTED,
|
|
39
|
+
);
|
|
40
|
+
this.#metadataMemoryGauge = meter.createObservableGauge(Metrics.MEMPOOL_TX_POOL_V2_METADATA_MEMORY);
|
|
41
|
+
this.#metadataMemoryGauge.addCallback((result: ObservableResult) => {
|
|
42
|
+
result.observe(metadataMemoryCallback());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
recordEvictions(count: number, reason: string) {
|
|
47
|
+
this.#evictedCounter.add(count, { [Attributes.TX_POOL_EVICTION_REASON]: reason });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
recordIgnored(count: number) {
|
|
51
|
+
this.#ignoredCounter.add(count);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
recordRejected(count: number) {
|
|
55
|
+
this.#rejectedCounter.add(count);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
recordSoftDeletedHits(count: number) {
|
|
59
|
+
this.#softDeletedHitsCounter.add(count);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
recordMissingOnProtect(count: number) {
|
|
63
|
+
this.#missingOnProtectCounter.add(count);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
recordMissingPreviouslyEvicted(count: number) {
|
|
67
|
+
this.#missingPreviouslyEvictedCounter.add(count);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -4,6 +4,7 @@ import type { L2Block, L2BlockId, L2BlockSource } from '@aztec/stdlib/block';
|
|
|
4
4
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import type { BlockHeader, Tx, TxHash, TxValidator } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
|
+
import type { TxPoolRejectionError } from './eviction/interfaces.js';
|
|
7
8
|
import type { TxMetaData, TxState } from './tx_metadata.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -17,6 +18,8 @@ export type AddTxsResult = {
|
|
|
17
18
|
ignored: TxHash[];
|
|
18
19
|
/** Transactions rejected because they failed validation (e.g., invalid proof, expired timestamp) */
|
|
19
20
|
rejected: TxHash[];
|
|
21
|
+
/** Optional rejection errors, only present when there are rejections with structured errors. */
|
|
22
|
+
errors?: Map<string, TxPoolRejectionError>;
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
/**
|
|
@@ -37,6 +40,12 @@ export type TxPoolV2Config = {
|
|
|
37
40
|
maxPendingTxCount: number;
|
|
38
41
|
/** Maximum number of archived transactions to retain (0 = disabled) */
|
|
39
42
|
archivedTxLimit: number;
|
|
43
|
+
/** Minimum age (ms) a transaction must have been in the pool before it's eligible for block building */
|
|
44
|
+
minTxPoolAgeMs: number;
|
|
45
|
+
/** Maximum number of evicted tx hashes to remember for metrics tracking */
|
|
46
|
+
evictedTxCacheSize: number;
|
|
47
|
+
/** Minimum percentage fee increase required to replace an existing tx via RPC (0 = no bump). */
|
|
48
|
+
priceBumpPercentage: bigint;
|
|
40
49
|
};
|
|
41
50
|
|
|
42
51
|
/**
|
|
@@ -45,6 +54,9 @@ export type TxPoolV2Config = {
|
|
|
45
54
|
export const DEFAULT_TX_POOL_V2_CONFIG: TxPoolV2Config = {
|
|
46
55
|
maxPendingTxCount: 0, // 0 = disabled
|
|
47
56
|
archivedTxLimit: 0, // 0 = disabled
|
|
57
|
+
minTxPoolAgeMs: 2_000,
|
|
58
|
+
evictedTxCacheSize: 10_000,
|
|
59
|
+
priceBumpPercentage: 10n,
|
|
48
60
|
};
|
|
49
61
|
|
|
50
62
|
/**
|
|
@@ -55,8 +67,8 @@ export type TxPoolV2Dependencies = {
|
|
|
55
67
|
l2BlockSource: L2BlockSource;
|
|
56
68
|
/** World state synchronizer for validating transactions after chain prunes */
|
|
57
69
|
worldStateSynchronizer: WorldStateSynchronizer;
|
|
58
|
-
/**
|
|
59
|
-
|
|
70
|
+
/** Factory that creates a validator for re-validating pool transactions using metadata */
|
|
71
|
+
createTxValidator: () => Promise<TxValidator<TxMetaData>>;
|
|
60
72
|
};
|
|
61
73
|
|
|
62
74
|
/**
|
|
@@ -95,15 +107,15 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
95
107
|
* @param opts - Optional metadata (e.g., source for logging)
|
|
96
108
|
* @returns Result categorizing each transaction as accepted, rejected, or ignored
|
|
97
109
|
*/
|
|
98
|
-
addPendingTxs(txs: Tx[], opts?: { source?: string }): Promise<AddTxsResult>;
|
|
110
|
+
addPendingTxs(txs: Tx[], opts?: { source?: string; feeComparisonOnly?: boolean }): Promise<AddTxsResult>;
|
|
99
111
|
|
|
100
112
|
/**
|
|
101
|
-
* Checks if
|
|
102
|
-
*
|
|
113
|
+
* Checks if the pool would accept a transaction without modifying state.
|
|
114
|
+
* Used as a pre-check before expensive proof verification.
|
|
103
115
|
* @param tx - Transaction to check
|
|
104
|
-
* @returns
|
|
116
|
+
* @returns 'accepted' if the pool would accept, 'ignored' if already in pool or undesirable
|
|
105
117
|
*/
|
|
106
|
-
canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'
|
|
118
|
+
canAddPendingTx(tx: Tx): Promise<'accepted' | 'ignored'>;
|
|
107
119
|
|
|
108
120
|
/**
|
|
109
121
|
* Adds transactions as immediately protected for a given slot.
|
|
@@ -156,7 +168,7 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
156
168
|
* and validates them before returning to pending.
|
|
157
169
|
* @param latestBlock - The latest valid block ID after the prune
|
|
158
170
|
*/
|
|
159
|
-
handlePrunedBlocks(latestBlock: L2BlockId): Promise<void>;
|
|
171
|
+
handlePrunedBlocks(latestBlock: L2BlockId, options?: { deleteAllTxs?: boolean }): Promise<void>;
|
|
160
172
|
|
|
161
173
|
/**
|
|
162
174
|
* Handles failed transaction execution.
|
|
@@ -187,6 +199,9 @@ export interface TxPoolV2 extends TypedEventEmitter<TxPoolV2Events> {
|
|
|
187
199
|
/** Gets pending transaction hashes sorted by priority (highest first) */
|
|
188
200
|
getPendingTxHashes(): Promise<TxHash[]>;
|
|
189
201
|
|
|
202
|
+
/** Gets pending transaction hashes that have been in the pool long enough per minTxPoolAgeMs, sorted by priority (highest first) */
|
|
203
|
+
getEligiblePendingTxHashes(): Promise<TxHash[]>;
|
|
204
|
+
|
|
190
205
|
/** Gets the count of pending transactions */
|
|
191
206
|
getPendingTxCount(): Promise<number>;
|
|
192
207
|
|
|
@@ -1,11 +1,32 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import type
|
|
4
|
-
import
|
|
4
|
+
import { BlockHash, type L2BlockId } from '@aztec/stdlib/block';
|
|
5
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
6
|
+
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
7
|
|
|
6
8
|
import { getFeePayerBalanceDelta } from '../../msg_validators/tx_validator/fee_payer_balance.js';
|
|
7
9
|
import { getTxPriorityFee } from '../tx_pool/priority.js';
|
|
8
|
-
import type
|
|
10
|
+
import { type PreAddResult, TxPoolRejectionCode } from './eviction/interfaces.js';
|
|
11
|
+
|
|
12
|
+
/** Validator-compatible data interface, mirroring the subset of PrivateKernelTailCircuitPublicInputs used by validators. */
|
|
13
|
+
export type TxMetaValidationData = {
|
|
14
|
+
getNonEmptyNullifiers(): Fr[];
|
|
15
|
+
expirationTimestamp: bigint;
|
|
16
|
+
/** Whether the tx has public calls. Used to select the correct L2 gas minimum. */
|
|
17
|
+
forPublic?: unknown;
|
|
18
|
+
constants: {
|
|
19
|
+
anchorBlockHeader: {
|
|
20
|
+
hash(): Promise<BlockHash>;
|
|
21
|
+
globalVariables: {
|
|
22
|
+
blockNumber: BlockNumber;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
txContext: {
|
|
26
|
+
gasSettings: { gasLimits: Gas };
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
9
30
|
|
|
10
31
|
/**
|
|
11
32
|
* Lightweight in-memory representation of a transaction.
|
|
@@ -19,6 +40,9 @@ export type TxMetaData = {
|
|
|
19
40
|
/** The transaction hash as hex string */
|
|
20
41
|
readonly txHash: string;
|
|
21
42
|
|
|
43
|
+
/** The transaction hash as bigint (for efficient Fr conversion in comparisons) */
|
|
44
|
+
readonly txHashBigInt: bigint;
|
|
45
|
+
|
|
22
46
|
/** Block ID (number and hash) in which the transaction was mined (undefined if not mined) */
|
|
23
47
|
minedL2BlockId?: L2BlockId;
|
|
24
48
|
|
|
@@ -41,40 +65,100 @@ export type TxMetaData = {
|
|
|
41
65
|
readonly nullifiers: readonly string[];
|
|
42
66
|
|
|
43
67
|
/** Timestamp by which the transaction must be included (for expiration checks) */
|
|
44
|
-
readonly
|
|
68
|
+
readonly expirationTimestamp: bigint;
|
|
69
|
+
|
|
70
|
+
/** Validator-compatible data, providing the same access patterns as Tx.data */
|
|
71
|
+
readonly data: TxMetaValidationData;
|
|
72
|
+
|
|
73
|
+
/** Timestamp (ms) when the tx was received into the pool. 0 for hydrated txs (always eligible). */
|
|
74
|
+
receivedAt: number;
|
|
75
|
+
|
|
76
|
+
/** Estimated memory footprint of this metadata object in bytes */
|
|
77
|
+
readonly estimatedSizeBytes: number;
|
|
45
78
|
};
|
|
46
79
|
|
|
47
80
|
/** Transaction state derived from TxMetaData fields and pool protection status */
|
|
48
|
-
export type TxState = 'pending' | 'protected' | 'mined';
|
|
81
|
+
export type TxState = 'pending' | 'protected' | 'mined' | 'deleted';
|
|
49
82
|
|
|
50
83
|
/**
|
|
51
84
|
* Builds TxMetaData from a full Tx object.
|
|
52
85
|
* Extracts all relevant fields for efficient in-memory storage and querying.
|
|
86
|
+
* Fr values are captured in closures for zero-cost re-validation.
|
|
53
87
|
*/
|
|
54
88
|
export async function buildTxMetaData(tx: Tx): Promise<TxMetaData> {
|
|
55
|
-
const
|
|
56
|
-
const
|
|
89
|
+
const txHashObj = tx.getTxHash();
|
|
90
|
+
const txHash = txHashObj.toString();
|
|
91
|
+
const txHashBigInt = txHashObj.toBigInt();
|
|
92
|
+
const nullifierFrs = tx.data.getNonEmptyNullifiers();
|
|
93
|
+
const nullifiers = nullifierFrs.map(n => n.toString());
|
|
94
|
+
const anchorBlockHeaderHashFr = await tx.data.constants.anchorBlockHeader.hash();
|
|
95
|
+
const anchorBlockHeaderHash = anchorBlockHeaderHashFr.toString();
|
|
96
|
+
const expirationTimestamp = tx.data.expirationTimestamp;
|
|
97
|
+
const anchorBlockNumber = tx.data.constants.anchorBlockHeader.globalVariables.blockNumber;
|
|
57
98
|
const priorityFee = getTxPriorityFee(tx);
|
|
58
99
|
const feePayer = tx.data.feePayer.toString();
|
|
59
|
-
const nullifiers = tx.data.getNonEmptyNullifiers().map(n => n.toString());
|
|
60
|
-
const includeByTimestamp = tx.data.includeByTimestamp;
|
|
61
100
|
|
|
62
101
|
const { feeLimit, claimAmount } = await getFeePayerBalanceDelta(tx, ProtocolContractAddress.FeeJuice);
|
|
63
102
|
|
|
103
|
+
const estimatedSizeBytes = estimateTxMetaDataSize(nullifiers.length);
|
|
104
|
+
|
|
64
105
|
return {
|
|
65
106
|
txHash,
|
|
107
|
+
txHashBigInt,
|
|
66
108
|
anchorBlockHeaderHash,
|
|
67
109
|
priorityFee,
|
|
68
110
|
feePayer,
|
|
69
111
|
claimAmount,
|
|
70
112
|
feeLimit,
|
|
71
113
|
nullifiers,
|
|
72
|
-
|
|
114
|
+
expirationTimestamp,
|
|
115
|
+
receivedAt: 0,
|
|
116
|
+
estimatedSizeBytes,
|
|
117
|
+
data: {
|
|
118
|
+
getNonEmptyNullifiers: () => nullifierFrs,
|
|
119
|
+
expirationTimestamp,
|
|
120
|
+
forPublic: !!tx.data.forPublic,
|
|
121
|
+
constants: {
|
|
122
|
+
anchorBlockHeader: {
|
|
123
|
+
hash: () => Promise.resolve(anchorBlockHeaderHashFr),
|
|
124
|
+
globalVariables: { blockNumber: anchorBlockNumber },
|
|
125
|
+
},
|
|
126
|
+
txContext: {
|
|
127
|
+
gasSettings: { gasLimits: tx.data.constants.txContext.gasSettings.gasLimits },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
73
131
|
};
|
|
74
132
|
}
|
|
75
133
|
|
|
134
|
+
// V8 JS object overhead (~64 bytes for a plain object with hidden class).
|
|
135
|
+
// String overhead: ~32 bytes header + 1 byte per ASCII char (V8 one-byte strings).
|
|
136
|
+
// Hex string (0x + 64 hex chars = 66 chars): ~98 bytes per string.
|
|
137
|
+
// bigint: ~32 bytes. number: 8 bytes. Fr: ~80 bytes (32 data + object overhead).
|
|
138
|
+
const OBJECT_OVERHEAD = 64;
|
|
139
|
+
const HEX_STRING_BYTES = 98;
|
|
140
|
+
const BIGINT_BYTES = 32;
|
|
141
|
+
const FR_BYTES = 80;
|
|
142
|
+
// Fixed cost: object shell + txHash + anchorBlockHeaderHash + feePayer (3 hex strings)
|
|
143
|
+
// + txHashBigInt + priorityFee + claimAmount + feeLimit + includeByTimestamp (5 bigints)
|
|
144
|
+
// + receivedAt (number, 8 bytes) + estimatedSizeBytes (number, 8 bytes)
|
|
145
|
+
// + data closure object (~OBJECT_OVERHEAD + anchorBlockHeaderHashFr Fr + anchorBlockNumber number)
|
|
146
|
+
const FIXED_METADATA_BYTES =
|
|
147
|
+
OBJECT_OVERHEAD + 3 * HEX_STRING_BYTES + 5 * BIGINT_BYTES + 8 + 8 + OBJECT_OVERHEAD + FR_BYTES + 8;
|
|
148
|
+
|
|
149
|
+
/** Estimates the in-memory size of a TxMetaData object based on the number of nullifiers. */
|
|
150
|
+
function estimateTxMetaDataSize(nullifierCount: number): number {
|
|
151
|
+
// Per nullifier: one hex string in nullifiers[] + one Fr in the captured nullifierFrs[]
|
|
152
|
+
return FIXED_METADATA_BYTES + nullifierCount * (HEX_STRING_BYTES + FR_BYTES);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Converts a txHash bigint back to the canonical 0x-prefixed 64-char hex string. */
|
|
156
|
+
export function txHashFromBigInt(value: bigint): string {
|
|
157
|
+
return TxHash.fromBigInt(value).toString();
|
|
158
|
+
}
|
|
159
|
+
|
|
76
160
|
/** Minimal fields required for priority comparison. */
|
|
77
|
-
type PriorityComparable = Pick<TxMetaData, '
|
|
161
|
+
type PriorityComparable = Pick<TxMetaData, 'txHashBigInt' | 'priorityFee'>;
|
|
78
162
|
|
|
79
163
|
/**
|
|
80
164
|
* Compares two priority fees in ascending order.
|
|
@@ -89,10 +173,8 @@ export function compareFee(a: bigint, b: bigint): number {
|
|
|
89
173
|
* Uses field element comparison for deterministic ordering.
|
|
90
174
|
* Returns negative if a < b, positive if a > b, 0 if equal.
|
|
91
175
|
*/
|
|
92
|
-
export function compareTxHash(a:
|
|
93
|
-
|
|
94
|
-
const fieldB = Fr.fromHexString(b);
|
|
95
|
-
return fieldA.cmp(fieldB);
|
|
176
|
+
export function compareTxHash(a: bigint, b: bigint): number {
|
|
177
|
+
return Fr.cmpAsBigInt(a, b);
|
|
96
178
|
}
|
|
97
179
|
|
|
98
180
|
/**
|
|
@@ -105,24 +187,41 @@ export function comparePriority(a: PriorityComparable, b: PriorityComparable): n
|
|
|
105
187
|
if (feeComparison !== 0) {
|
|
106
188
|
return feeComparison;
|
|
107
189
|
}
|
|
108
|
-
return compareTxHash(a.
|
|
190
|
+
return compareTxHash(a.txHashBigInt, b.txHashBigInt);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Returns the minimum fee required to replace an existing tx with the given price bump percentage.
|
|
195
|
+
* Uses integer arithmetic: `existingFee + existingFee * priceBumpPercentage / 100`.
|
|
196
|
+
*/
|
|
197
|
+
export function getMinimumPriceBumpFee(existingFee: bigint, priceBumpPercentage: bigint): bigint {
|
|
198
|
+
const bump = (existingFee * priceBumpPercentage) / 100n;
|
|
199
|
+
// Ensure the minimum bump is at least 1, so that replacement always requires
|
|
200
|
+
// paying strictly more — even with 0% bump or zero existing fee.
|
|
201
|
+
const effectiveBump = bump > 0n ? bump : 1n;
|
|
202
|
+
return existingFee + effectiveBump;
|
|
109
203
|
}
|
|
110
204
|
|
|
111
205
|
/**
|
|
112
206
|
* Checks for nullifier conflicts between an incoming transaction and existing pool state.
|
|
113
207
|
*
|
|
114
208
|
* When the incoming tx shares nullifiers with existing pending txs:
|
|
115
|
-
* - If the incoming tx
|
|
116
|
-
* -
|
|
209
|
+
* - If the incoming tx meets or exceeds the required priority, mark conflicting txs for eviction
|
|
210
|
+
* - Otherwise, ignore the incoming tx
|
|
211
|
+
*
|
|
212
|
+
* When `priceBumpPercentage` is provided (RPC path), uses fee-only comparison with the
|
|
213
|
+
* percentage bump instead of `comparePriority`.
|
|
117
214
|
*
|
|
118
215
|
* @param incomingMeta - Metadata for the incoming transaction
|
|
119
216
|
* @param getTxHashByNullifier - Accessor to find which tx uses a nullifier
|
|
120
217
|
* @param getMetadata - Accessor to get metadata for a tx hash
|
|
218
|
+
* @param priceBumpPercentage - Optional percentage bump required for fee-based replacement
|
|
121
219
|
*/
|
|
122
220
|
export function checkNullifierConflict(
|
|
123
221
|
incomingMeta: TxMetaData,
|
|
124
222
|
getTxHashByNullifier: (nullifier: string) => string | undefined,
|
|
125
223
|
getMetadata: (txHash: string) => TxMetaData | undefined,
|
|
224
|
+
priceBumpPercentage?: bigint,
|
|
126
225
|
): PreAddResult {
|
|
127
226
|
const txHashesToEvict: string[] = [];
|
|
128
227
|
|
|
@@ -143,19 +242,86 @@ export function checkNullifierConflict(
|
|
|
143
242
|
continue;
|
|
144
243
|
}
|
|
145
244
|
|
|
146
|
-
//
|
|
147
|
-
// Otherwise,
|
|
148
|
-
|
|
149
|
-
|
|
245
|
+
// When price bump is set (RPC path), require the incoming fee to meet the bumped threshold.
|
|
246
|
+
// Otherwise (P2P path), use full comparePriority with tx hash tiebreaker.
|
|
247
|
+
const isHigherPriority =
|
|
248
|
+
priceBumpPercentage !== undefined
|
|
249
|
+
? incomingMeta.priorityFee >= getMinimumPriceBumpFee(conflictingMeta.priorityFee, priceBumpPercentage)
|
|
250
|
+
: comparePriority(incomingMeta, conflictingMeta) > 0;
|
|
251
|
+
|
|
252
|
+
if (isHigherPriority) {
|
|
150
253
|
txHashesToEvict.push(conflictingHashStr);
|
|
151
254
|
} else {
|
|
255
|
+
const minimumFee =
|
|
256
|
+
priceBumpPercentage !== undefined
|
|
257
|
+
? getMinimumPriceBumpFee(conflictingMeta.priorityFee, priceBumpPercentage)
|
|
258
|
+
: undefined;
|
|
152
259
|
return {
|
|
153
260
|
shouldIgnore: true,
|
|
154
261
|
txHashesToEvict: [],
|
|
155
|
-
reason:
|
|
262
|
+
reason: {
|
|
263
|
+
code: TxPoolRejectionCode.NULLIFIER_CONFLICT,
|
|
264
|
+
message:
|
|
265
|
+
minimumFee !== undefined
|
|
266
|
+
? `Nullifier conflict with existing tx ${conflictingHashStr}. Minimum required fee: ${minimumFee}, got: ${incomingMeta.priorityFee}`
|
|
267
|
+
: `Nullifier conflict with existing tx ${conflictingHashStr}`,
|
|
268
|
+
conflictingTxHash: conflictingHashStr,
|
|
269
|
+
minimumPriceBumpFee: minimumFee,
|
|
270
|
+
txPriorityFee: minimumFee !== undefined ? incomingMeta.priorityFee : undefined,
|
|
271
|
+
},
|
|
156
272
|
};
|
|
157
273
|
}
|
|
158
274
|
}
|
|
159
275
|
|
|
160
276
|
return { shouldIgnore: false, txHashesToEvict };
|
|
161
277
|
}
|
|
278
|
+
|
|
279
|
+
/** Creates a stub TxMetaValidationData for tests that don't exercise validators. */
|
|
280
|
+
export function stubTxMetaValidationData(overrides: { expirationTimestamp?: bigint } = {}): TxMetaValidationData {
|
|
281
|
+
return {
|
|
282
|
+
getNonEmptyNullifiers: () => [],
|
|
283
|
+
expirationTimestamp: overrides.expirationTimestamp ?? 0n,
|
|
284
|
+
constants: {
|
|
285
|
+
anchorBlockHeader: {
|
|
286
|
+
hash: () => Promise.resolve(new BlockHash(Fr.ZERO)),
|
|
287
|
+
globalVariables: { blockNumber: BlockNumber(0) },
|
|
288
|
+
},
|
|
289
|
+
txContext: {
|
|
290
|
+
gasSettings: { gasLimits: Gas.empty() },
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Creates a stub TxMetaData for tests. All fields have sensible defaults and can be overridden. */
|
|
297
|
+
export function stubTxMetaData(
|
|
298
|
+
txHash: string,
|
|
299
|
+
overrides: {
|
|
300
|
+
priorityFee?: bigint;
|
|
301
|
+
feePayer?: string;
|
|
302
|
+
claimAmount?: bigint;
|
|
303
|
+
feeLimit?: bigint;
|
|
304
|
+
nullifiers?: string[];
|
|
305
|
+
expirationTimestamp?: bigint;
|
|
306
|
+
anchorBlockHeaderHash?: string;
|
|
307
|
+
} = {},
|
|
308
|
+
): TxMetaData {
|
|
309
|
+
const txHashBigInt = Fr.fromHexString(txHash).toBigInt();
|
|
310
|
+
// Normalize to canonical zero-padded hex so txHashFromBigInt(txHashBigInt) === normalizedTxHash
|
|
311
|
+
const normalizedTxHash = txHashFromBigInt(txHashBigInt);
|
|
312
|
+
const expirationTimestamp = overrides.expirationTimestamp ?? 0n;
|
|
313
|
+
return {
|
|
314
|
+
txHash: normalizedTxHash,
|
|
315
|
+
txHashBigInt,
|
|
316
|
+
anchorBlockHeaderHash: overrides.anchorBlockHeaderHash ?? '0x1234',
|
|
317
|
+
priorityFee: overrides.priorityFee ?? 100n,
|
|
318
|
+
feePayer: overrides.feePayer ?? '0xfeepayer',
|
|
319
|
+
claimAmount: overrides.claimAmount ?? 0n,
|
|
320
|
+
feeLimit: overrides.feeLimit ?? 100n,
|
|
321
|
+
nullifiers: overrides.nullifiers ?? [`0x${normalizedTxHash.slice(2)}null1`],
|
|
322
|
+
expirationTimestamp,
|
|
323
|
+
receivedAt: 0,
|
|
324
|
+
estimatedSizeBytes: 0,
|
|
325
|
+
data: stubTxMetaValidationData({ expirationTimestamp }),
|
|
326
|
+
};
|
|
327
|
+
}
|