@aztec/p2p 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -3
- package/dest/client/factory.d.ts +9 -9
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +52 -14
- package/dest/client/interface.d.ts +47 -34
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +39 -51
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +164 -224
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +20 -10
- package/dest/config.d.ts +52 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +100 -37
- package/dest/errors/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +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 +21 -12
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +75 -40
- 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 +57 -57
- 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 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -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 +7 -3
- 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 +30 -12
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +5 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +78 -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 +144 -19
- 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 +50 -45
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +12 -5
- 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 +17 -6
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +14 -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 +364 -189
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
- package/dest/msg_validators/clock_tolerance.d.ts +1 -1
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
- package/dest/msg_validators/clock_tolerance.js +4 -3
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +53 -41
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +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/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -2
- package/dest/msg_validators/tx_validator/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 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +247 -60
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +67 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +104 -37
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +22 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +72 -24
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +6 -6
- package/dest/services/dummy_service.d.ts +12 -6
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +12 -5
- package/dest/services/encoding.d.ts +7 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +18 -11
- 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 +37 -23
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +274 -173
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +6 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +24 -9
- package/dest/services/peer-manager/peer_scoring.d.ts +5 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +28 -10
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +12 -8
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +83 -106
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +4 -7
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +11 -13
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +31 -46
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +19 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +52 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/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/rate-limiter/rate_limiter.d.ts +5 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -8
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +30 -14
- package/dest/services/service.d.ts +26 -4
- 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 -4
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +80 -76
- 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 +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 +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/proposal_tx_collector.d.ts +7 -7
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +5 -4
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +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 -13
- 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 +13 -7
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +26 -7
- package/dest/services/tx_file_store/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 +115 -38
- 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 +57 -27
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -3
- package/dest/util.d.ts +3 -3
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +102 -25
- package/src/client/interface.ts +52 -34
- package/src/client/p2p_client.ts +190 -266
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +33 -14
- package/src/config.ts +149 -43
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +104 -50
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +61 -57
- 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 +1 -1
- package/src/mem_pools/instrumentation.ts +17 -13
- 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/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 +7 -3
- 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 +32 -12
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +209 -27
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +58 -45
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +34 -8
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +410 -187
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
- package/src/msg_validators/clock_tolerance.ts +4 -3
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +69 -45
- package/src/msg_validators/tx_validator/README.md +119 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +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/data_validator.ts +42 -1
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/factory.ts +394 -78
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -27
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +82 -27
- package/src/msg_validators/tx_validator/timestamp_validator.ts +23 -18
- package/src/services/dummy_service.ts +18 -7
- package/src/services/encoding.ts +18 -10
- 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 +288 -198
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +28 -9
- package/src/services/peer-manager/peer_scoring.ts +21 -5
- package/src/services/reqresp/README.md +229 -0
- package/src/services/reqresp/batch-tx-requester/README.md +46 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +79 -112
- package/src/services/reqresp/batch-tx-requester/interface.ts +3 -6
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +30 -71
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +68 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/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/rate-limiter/rate_limiter.ts +13 -9
- package/src/services/reqresp/reqresp.ts +35 -15
- package/src/services/service.ts +37 -3
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +83 -76
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +1 -0
- package/src/services/tx_collection/instrumentation.ts +7 -1
- package/src/services/tx_collection/proposal_tx_collector.ts +9 -13
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/slow_tx_collection.ts +66 -33
- package/src/services/tx_collection/tx_collection.ts +114 -19
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +28 -8
- 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 +4 -6
- package/src/test-helpers/mock-pubsub.ts +146 -9
- package/src/test-helpers/reqresp-nodes.ts +3 -6
- package/src/test-helpers/testbench-utils.ts +137 -43
- package/src/testbench/p2p_client_testbench_worker.ts +63 -30
- package/src/testbench/worker_client_manager.ts +13 -6
- package/src/util.ts +8 -2
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +0 -125
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +0 -596
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +0 -32
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +0 -112
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +0 -157
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +0 -52
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +0 -16
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +0 -122
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +0 -17
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +0 -19
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +0 -78
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +0 -26
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +0 -84
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +0 -25
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +0 -57
- package/dest/mem_pools/tx_pool/index.d.ts +0 -3
- package/dest/mem_pools/tx_pool/index.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/index.js +0 -2
- package/dest/mem_pools/tx_pool/priority.d.ts +0 -12
- package/dest/mem_pools/tx_pool/priority.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/priority.js +0 -15
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +0 -127
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +0 -3
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +0 -7
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +0 -400
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/src/mem_pools/tx_pool/README.md +0 -270
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +0 -746
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +0 -132
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +0 -208
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +0 -162
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +0 -104
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +0 -93
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +0 -106
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +0 -75
- package/src/mem_pools/tx_pool/index.ts +0 -2
- package/src/mem_pools/tx_pool/priority.ts +0 -20
- package/src/mem_pools/tx_pool/tx_pool.ts +0 -141
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +0 -319
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
|
@@ -1,746 +0,0 @@
|
|
|
1
|
-
import { insertIntoSortedArray } from '@aztec/foundation/array';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
5
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
7
|
-
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
8
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import type { MerkleTreeReadOperations, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
11
|
-
import type { TxAddedToPoolStats } from '@aztec/stdlib/stats';
|
|
12
|
-
import { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
13
|
-
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
|
-
|
|
15
|
-
import assert from 'assert';
|
|
16
|
-
import EventEmitter from 'node:events';
|
|
17
|
-
|
|
18
|
-
import { ArchiveCache } from '../../msg_validators/tx_validator/archive_cache.js';
|
|
19
|
-
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
20
|
-
import { EvictionManager } from './eviction/eviction_manager.js';
|
|
21
|
-
import {
|
|
22
|
-
FeePayerTxInfo,
|
|
23
|
-
type PendingTxInfo,
|
|
24
|
-
type PreAddPoolAccess,
|
|
25
|
-
type TxBlockReference,
|
|
26
|
-
type TxPoolOperations,
|
|
27
|
-
} from './eviction/eviction_strategy.js';
|
|
28
|
-
import { FeePayerBalanceEvictionRule } from './eviction/fee_payer_balance_eviction_rule.js';
|
|
29
|
-
import { InvalidTxsAfterMiningRule } from './eviction/invalid_txs_after_mining_rule.js';
|
|
30
|
-
import { InvalidTxsAfterReorgRule } from './eviction/invalid_txs_after_reorg_rule.js';
|
|
31
|
-
import { LowPriorityEvictionRule } from './eviction/low_priority_eviction_rule.js';
|
|
32
|
-
import { NullifierConflictPreAddRule } from './eviction/nullifier_conflict_pre_add_rule.js';
|
|
33
|
-
import { getPendingTxPriority } from './priority.js';
|
|
34
|
-
import type { TxPool, TxPoolEvents, TxPoolOptions } from './tx_pool.js';
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* KV implementation of the Transaction Pool.
|
|
38
|
-
*/
|
|
39
|
-
export class AztecKVTxPool
|
|
40
|
-
extends (EventEmitter as new () => TypedEventEmitter<TxPoolEvents>)
|
|
41
|
-
implements TxPool, TxPoolOperations
|
|
42
|
-
{
|
|
43
|
-
#store: AztecAsyncKVStore;
|
|
44
|
-
|
|
45
|
-
/** Our tx pool, stored as a Map, with K: tx hash and V: the transaction. */
|
|
46
|
-
#txs: AztecAsyncMap<string, Buffer>;
|
|
47
|
-
|
|
48
|
-
/** Holds the historical block for each tx */
|
|
49
|
-
#pendingTxHashToHistoricalBlockHeaderHash: AztecAsyncMap<string, string>;
|
|
50
|
-
|
|
51
|
-
/** Index from tx hash to the block number in which they were mined, filtered by mined txs. */
|
|
52
|
-
#minedTxHashToBlock: AztecAsyncMap<string, BlockNumber>;
|
|
53
|
-
|
|
54
|
-
/** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */
|
|
55
|
-
#pendingTxPriorityToHash: AztecAsyncMultiMap<string, string>;
|
|
56
|
-
|
|
57
|
-
/** Map from tx hash to the block number it was originally mined in (for soft-deleted txs). */
|
|
58
|
-
#deletedMinedTxHashes: AztecAsyncMap<string, BlockNumber>;
|
|
59
|
-
|
|
60
|
-
/** MultiMap from block number to deleted mined tx hashes for efficient cleanup. */
|
|
61
|
-
#blockToDeletedMinedTxHash: AztecAsyncMultiMap<BlockNumber, string>;
|
|
62
|
-
|
|
63
|
-
#historicalHeaderToTxHash: AztecAsyncMultiMap<string, string>;
|
|
64
|
-
|
|
65
|
-
#feePayerToBalanceEntry: AztecAsyncMultiMap<string, Buffer>;
|
|
66
|
-
|
|
67
|
-
/** Index from nullifier to pending tx hash */
|
|
68
|
-
#pendingNullifierToTxHash: AztecAsyncMap<string, string>;
|
|
69
|
-
|
|
70
|
-
/** In-memory set of txs that should not be evicted from the pool. */
|
|
71
|
-
#nonEvictableTxs: Set<string>;
|
|
72
|
-
|
|
73
|
-
/** KV store for archived txs. */
|
|
74
|
-
#archive: AztecAsyncKVStore;
|
|
75
|
-
|
|
76
|
-
/** Archived txs map for future lookup. */
|
|
77
|
-
#archivedTxs: AztecAsyncMap<string, Buffer>;
|
|
78
|
-
|
|
79
|
-
/** Indexes of the archived txs by insertion order. */
|
|
80
|
-
#archivedTxIndices: AztecAsyncMap<number, string>;
|
|
81
|
-
|
|
82
|
-
/** Number of txs to archive. */
|
|
83
|
-
#archivedTxLimit: number = 0;
|
|
84
|
-
|
|
85
|
-
#evictionManager: EvictionManager;
|
|
86
|
-
|
|
87
|
-
#log: Logger;
|
|
88
|
-
|
|
89
|
-
#metrics: PoolInstrumentation<Tx>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Class constructor for KV TxPool. Initiates our transaction pool as an AztecMap.
|
|
93
|
-
* @param store - A KV store for live txs in the pool.
|
|
94
|
-
* @param archive - A KV store for archived txs.
|
|
95
|
-
* @param telemetry - A telemetry client.
|
|
96
|
-
* @param archivedTxLimit - The number of txs to archive.
|
|
97
|
-
* @param log - A logger.
|
|
98
|
-
*/
|
|
99
|
-
constructor(
|
|
100
|
-
store: AztecAsyncKVStore,
|
|
101
|
-
archive: AztecAsyncKVStore,
|
|
102
|
-
worldState: WorldStateSynchronizer,
|
|
103
|
-
telemetry: TelemetryClient = getTelemetryClient(),
|
|
104
|
-
config: TxPoolOptions = {},
|
|
105
|
-
log = createLogger('p2p:tx_pool'),
|
|
106
|
-
) {
|
|
107
|
-
super();
|
|
108
|
-
|
|
109
|
-
this.#log = log;
|
|
110
|
-
|
|
111
|
-
this.#evictionManager = new EvictionManager(this);
|
|
112
|
-
this.#evictionManager.registerRule(new InvalidTxsAfterMiningRule());
|
|
113
|
-
this.#evictionManager.registerRule(new InvalidTxsAfterReorgRule(worldState));
|
|
114
|
-
this.#evictionManager.registerRule(new FeePayerBalanceEvictionRule(worldState));
|
|
115
|
-
this.#evictionManager.registerRule(
|
|
116
|
-
new LowPriorityEvictionRule({
|
|
117
|
-
//NOTE: 0 effectively disables low priority eviction
|
|
118
|
-
maxPoolSize: config.maxPendingTxCount ?? 0,
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
this.#evictionManager.registerPreAddRule(new NullifierConflictPreAddRule());
|
|
122
|
-
|
|
123
|
-
this.updateConfig(config);
|
|
124
|
-
|
|
125
|
-
this.#txs = store.openMap('txs');
|
|
126
|
-
this.#minedTxHashToBlock = store.openMap('txHashToBlockMined');
|
|
127
|
-
this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash');
|
|
128
|
-
this.#deletedMinedTxHashes = store.openMap('deletedMinedTxHashes');
|
|
129
|
-
this.#blockToDeletedMinedTxHash = store.openMultiMap('blockToDeletedMinedTxHash');
|
|
130
|
-
|
|
131
|
-
this.#pendingTxHashToHistoricalBlockHeaderHash = store.openMap('txHistoricalBlock');
|
|
132
|
-
this.#historicalHeaderToTxHash = store.openMultiMap('historicalHeaderToPendingTxHash');
|
|
133
|
-
this.#feePayerToBalanceEntry = store.openMultiMap('feePayerToBalanceEntry');
|
|
134
|
-
this.#pendingNullifierToTxHash = store.openMap('pendingNullifierToTxHash');
|
|
135
|
-
|
|
136
|
-
this.#nonEvictableTxs = new Set<string>();
|
|
137
|
-
|
|
138
|
-
this.#archivedTxs = archive.openMap('archivedTxs');
|
|
139
|
-
this.#archivedTxIndices = archive.openMap('archivedTxIndices');
|
|
140
|
-
|
|
141
|
-
this.#store = store;
|
|
142
|
-
this.#archive = archive;
|
|
143
|
-
|
|
144
|
-
this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, this.countTxs, () => store.estimateSize());
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private countTxs: PoolStatsCallback = async () => {
|
|
148
|
-
const [pending = 0, mined = 0] = await Promise.all([this.getPendingTxCount(), this.getMinedTxCount()]);
|
|
149
|
-
|
|
150
|
-
return Promise.resolve({
|
|
151
|
-
itemCount: {
|
|
152
|
-
pending,
|
|
153
|
-
mined,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
public async isEmpty(): Promise<boolean> {
|
|
159
|
-
for await (const _ of this.#txs.entriesAsync()) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Marks transactions as mined in a block and updates the pool state accordingly.
|
|
167
|
-
* Removes the transactions from the pending set and adds them to the mined set.
|
|
168
|
-
* Also evicts any transactions that become invalid after the block is mined.
|
|
169
|
-
* @param txHashes - Array of transaction hashes that were mined
|
|
170
|
-
* @param blockHeader - The header of the block the transactions were mined in
|
|
171
|
-
*/
|
|
172
|
-
public async markAsMined(txHashes: TxHash[], blockHeader: BlockHeader): Promise<void> {
|
|
173
|
-
if (txHashes.length === 0) {
|
|
174
|
-
return Promise.resolve();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const uniqueMinedNullifiers: Fr[] = [];
|
|
178
|
-
const uniqueMinedFeePayers: AztecAddress[] = [];
|
|
179
|
-
|
|
180
|
-
try {
|
|
181
|
-
await this.#store.transactionAsync(async () => {
|
|
182
|
-
for (const hash of txHashes) {
|
|
183
|
-
const key = hash.toString();
|
|
184
|
-
await this.#minedTxHashToBlock.set(key, blockHeader.globalVariables.blockNumber);
|
|
185
|
-
|
|
186
|
-
const tx = await this.getTxByHash(hash);
|
|
187
|
-
if (tx) {
|
|
188
|
-
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
189
|
-
|
|
190
|
-
nullifiers.forEach(nullifier => insertIntoSortedArray(uniqueMinedNullifiers, nullifier, Fr.cmp, false));
|
|
191
|
-
insertIntoSortedArray(
|
|
192
|
-
uniqueMinedFeePayers,
|
|
193
|
-
tx.data.feePayer,
|
|
194
|
-
(a, b) => a.toField().cmp(b.toField()),
|
|
195
|
-
false,
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
await this.removePendingTxIndicesInDbTx(tx, key);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// If this tx was previously soft-deleted, remove it from the deleted sets
|
|
202
|
-
if (await this.#deletedMinedTxHashes.hasAsync(key)) {
|
|
203
|
-
const originalBlock = await this.#deletedMinedTxHashes.getAsync(key);
|
|
204
|
-
await this.#deletedMinedTxHashes.delete(key);
|
|
205
|
-
// Remove from block-to-hash mapping
|
|
206
|
-
if (originalBlock !== undefined) {
|
|
207
|
-
await this.#blockToDeletedMinedTxHash.deleteValue(originalBlock, key);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
await this.#evictionManager.evictAfterNewBlock(blockHeader, uniqueMinedNullifiers, uniqueMinedFeePayers);
|
|
214
|
-
|
|
215
|
-
this.#metrics.transactionsRemoved(txHashes.map(hash => hash.toBigInt()));
|
|
216
|
-
} catch (err) {
|
|
217
|
-
this.#log.warn('Unexpected error when marking txs as mined', { err });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public async markMinedAsPending(txHashes: TxHash[], latestBlock: BlockNumber): Promise<void> {
|
|
222
|
-
if (txHashes.length === 0) {
|
|
223
|
-
return Promise.resolve();
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
await this.#store.transactionAsync(async () => {
|
|
227
|
-
for (const hash of txHashes) {
|
|
228
|
-
const key = hash.toString();
|
|
229
|
-
await this.#minedTxHashToBlock.delete(key);
|
|
230
|
-
|
|
231
|
-
// Clear soft-delete metadata if this tx was previously soft-deleted,
|
|
232
|
-
// so cleanupDeletedMinedTxs won't later hard-delete it while it's pending
|
|
233
|
-
const deletedBlock = await this.#deletedMinedTxHashes.getAsync(key);
|
|
234
|
-
if (deletedBlock !== undefined) {
|
|
235
|
-
await this.#deletedMinedTxHashes.delete(key);
|
|
236
|
-
await this.#blockToDeletedMinedTxHash.deleteValue(deletedBlock, key);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Rehydrate the tx in the in-memory pending txs mapping
|
|
240
|
-
const tx = await this.getTxByHash(hash);
|
|
241
|
-
if (tx) {
|
|
242
|
-
await this.addPendingTxIndicesInDbTx(tx, key);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
await this.#evictionManager.evictAfterChainPrune(latestBlock);
|
|
248
|
-
} catch (err) {
|
|
249
|
-
this.#log.warn('Unexpected error when marking mined txs as pending', { err });
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
public async getPendingTxHashes(): Promise<TxHash[]> {
|
|
254
|
-
const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync({ reverse: true }));
|
|
255
|
-
return vals.map(TxHash.fromString);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Checks if a transaction exists in the pool and returns it.
|
|
260
|
-
* @param txHash - The generated tx hash.
|
|
261
|
-
* @returns The transaction, if found, 'undefined' otherwise.
|
|
262
|
-
*/
|
|
263
|
-
public async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
264
|
-
const buffer = await this.#txs.getAsync(txHash.toString());
|
|
265
|
-
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
async getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
269
|
-
const txs = await Promise.all(txHashes.map(txHash => this.#txs.getAsync(txHash.toString())));
|
|
270
|
-
return txs.map(buffer => (buffer ? Tx.fromBuffer(buffer) : undefined));
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
async hasTxs(txHashes: TxHash[]): Promise<boolean[]> {
|
|
274
|
-
return await Promise.all(txHashes.map(txHash => this.#txs.hasAsync(txHash.toString())));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
async hasTx(txHash: TxHash): Promise<boolean> {
|
|
278
|
-
const result = await this.hasTxs([txHash]);
|
|
279
|
-
return result[0];
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Checks if an archived tx exists and returns it.
|
|
284
|
-
* @param txHash - The tx hash.
|
|
285
|
-
* @returns The transaction metadata, if found, 'undefined' otherwise.
|
|
286
|
-
*/
|
|
287
|
-
public async getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
288
|
-
const buffer = await this.#archivedTxs.getAsync(txHash.toString());
|
|
289
|
-
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
294
|
-
* Handles nullifier deduplication: if an incoming tx has a nullifier conflict with
|
|
295
|
-
* existing pending txs, it will either replace them (if higher fee) or be rejected.
|
|
296
|
-
* @param txs - An array of txs to be added to the pool.
|
|
297
|
-
* @returns count of added transactions
|
|
298
|
-
*/
|
|
299
|
-
public async addTxs(txs: Tx[], opts: { source?: string } = {}): Promise<number> {
|
|
300
|
-
if (txs.length === 0) {
|
|
301
|
-
return Promise.resolve(0);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const addedTxs: Tx[] = [];
|
|
305
|
-
const uniqueFeePayers: AztecAddress[] = [];
|
|
306
|
-
const replacedTxHashes: TxHash[] = [];
|
|
307
|
-
const hashesAndStats = txs.map(tx => ({ txHash: tx.getTxHash(), txStats: tx.getStats() }));
|
|
308
|
-
try {
|
|
309
|
-
await this.#store.transactionAsync(async () => {
|
|
310
|
-
for (let i = 0; i < txs.length; i++) {
|
|
311
|
-
const tx = txs[i];
|
|
312
|
-
const { txHash, txStats } = hashesAndStats[i];
|
|
313
|
-
const key = txHash.toString();
|
|
314
|
-
if (await this.#txs.hasAsync(key)) {
|
|
315
|
-
this.#log.debug(`Tx ${key} already exists in the pool`);
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const poolAccess = this.getPreAddPoolAccess();
|
|
320
|
-
const { shouldReject, txHashesToEvict } = await this.#evictionManager.runPreAddRules(tx, poolAccess);
|
|
321
|
-
if (shouldReject) {
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
for (const txHashToEvict of txHashesToEvict) {
|
|
326
|
-
const txToDelete = await this.getTxByHash(txHashToEvict);
|
|
327
|
-
if (txToDelete) {
|
|
328
|
-
const evictedKey = txHashToEvict.toString();
|
|
329
|
-
await this.deletePendingTxInDbTx(txToDelete, evictedKey);
|
|
330
|
-
replacedTxHashes.push(txHashToEvict);
|
|
331
|
-
this.#log.verbose(`Evicted tx ${evictedKey} due to higher-fee tx ${key}`);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
this.#log.verbose(`Adding tx ${key} to pool`, {
|
|
336
|
-
eventName: 'tx-added-to-pool',
|
|
337
|
-
...txStats,
|
|
338
|
-
} satisfies TxAddedToPoolStats);
|
|
339
|
-
|
|
340
|
-
await this.#txs.set(key, tx.toBuffer());
|
|
341
|
-
addedTxs.push(tx);
|
|
342
|
-
insertIntoSortedArray(uniqueFeePayers, tx.data.feePayer, (a, b) => a.toField().cmp(b.toField()), false);
|
|
343
|
-
|
|
344
|
-
await this.#pendingTxHashToHistoricalBlockHeaderHash.set(
|
|
345
|
-
key,
|
|
346
|
-
(await tx.data.constants.anchorBlockHeader.hash()).toString(),
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
if (!(await this.#minedTxHashToBlock.hasAsync(key))) {
|
|
350
|
-
await this.addPendingTxIndicesInDbTx(tx, key);
|
|
351
|
-
this.#metrics.recordSize(tx);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
await this.#evictionManager.evictAfterNewTxs(
|
|
357
|
-
addedTxs.map(({ txHash }) => txHash),
|
|
358
|
-
uniqueFeePayers,
|
|
359
|
-
);
|
|
360
|
-
} catch (err) {
|
|
361
|
-
this.#log.warn('Unexpected error when adding txs', { err });
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (replacedTxHashes.length > 0) {
|
|
365
|
-
this.#metrics.transactionsRemoved(replacedTxHashes.map(hash => hash.toBigInt()));
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (addedTxs.length > 0) {
|
|
369
|
-
this.#metrics.transactionsAdded(addedTxs);
|
|
370
|
-
this.emit('txs-added', { ...opts, txs: addedTxs });
|
|
371
|
-
}
|
|
372
|
-
return addedTxs.length;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
377
|
-
* Mined transactions are soft-deleted with a timestamp, pending transactions are permanently deleted.
|
|
378
|
-
* @param txHashes - An array of tx hashes to be deleted from the tx pool.
|
|
379
|
-
* @returns Empty promise.
|
|
380
|
-
*/
|
|
381
|
-
public deleteTxs(txHashes: TxHash[], opts?: { permanently?: boolean }): Promise<void> {
|
|
382
|
-
if (txHashes.length === 0) {
|
|
383
|
-
return Promise.resolve();
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const deletedTxs: Tx[] = [];
|
|
387
|
-
const poolDbTx = this.#store.transactionAsync(async () => {
|
|
388
|
-
for (const hash of txHashes) {
|
|
389
|
-
const key = hash.toString();
|
|
390
|
-
const tx = await this.getTxByHash(hash);
|
|
391
|
-
if (!tx) {
|
|
392
|
-
this.#log.trace(`Skipping deletion of missing tx ${key} from pool`);
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const minedBlockNumber = await this.#minedTxHashToBlock.getAsync(key);
|
|
397
|
-
const txIsPending = minedBlockNumber === undefined;
|
|
398
|
-
if (txIsPending) {
|
|
399
|
-
await this.deletePendingTxInDbTx(tx, key);
|
|
400
|
-
} else {
|
|
401
|
-
await this.deleteMinedTx(key, minedBlockNumber!, opts?.permanently ?? false);
|
|
402
|
-
const shouldArchiveTx = this.#archivedTxLimit && !opts?.permanently;
|
|
403
|
-
if (shouldArchiveTx) {
|
|
404
|
-
deletedTxs.push(tx);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
this.#metrics.transactionsRemoved(txHashes.map(hash => hash.toBigInt()));
|
|
410
|
-
this.#log.debug(`Deleted ${txHashes.length} txs from pool`, { txHashes });
|
|
411
|
-
|
|
412
|
-
return this.#archivedTxLimit ? poolDbTx.then(() => this.archiveTxs(deletedTxs)) : poolDbTx;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
private async deleteMinedTx(txHash: `0x${string}`, minedBlockNumber: BlockNumber, permanently: boolean) {
|
|
416
|
-
await this.#minedTxHashToBlock.delete(txHash);
|
|
417
|
-
if (permanently) {
|
|
418
|
-
this.#log.trace(`Deleting mined tx ${txHash} from pool`);
|
|
419
|
-
await this.#txs.delete(txHash);
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// Soft-delete mined transactions: remove from mined set but keep in storage
|
|
424
|
-
this.#log.trace(`Soft-deleting mined tx ${txHash} from pool`);
|
|
425
|
-
await this.#deletedMinedTxHashes.set(txHash, minedBlockNumber);
|
|
426
|
-
await this.#blockToDeletedMinedTxHash.set(minedBlockNumber, txHash);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// Assumes being called within a DB transaction
|
|
430
|
-
private async deletePendingTxInDbTx(tx: Tx, txHash: `0x${string}`) {
|
|
431
|
-
// We always permanently delete pending transactions
|
|
432
|
-
this.#log.trace(`Deleting pending tx ${txHash} from pool`);
|
|
433
|
-
await this.removePendingTxIndicesInDbTx(tx, txHash);
|
|
434
|
-
await this.#txs.delete(txHash);
|
|
435
|
-
await this.#pendingTxHashToHistoricalBlockHeaderHash.delete(txHash);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Gets all the transactions stored in the pool.
|
|
440
|
-
* @returns Array of tx objects in the order they were added to the pool.
|
|
441
|
-
*/
|
|
442
|
-
public async getAllTxs(): Promise<Tx[]> {
|
|
443
|
-
const vals = await toArray(this.#txs.valuesAsync());
|
|
444
|
-
return vals.map(buffer => Tx.fromBuffer(buffer));
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Gets the hashes of all transactions currently in the tx pool.
|
|
449
|
-
* @returns An array of transaction hashes found in the tx pool.
|
|
450
|
-
*/
|
|
451
|
-
public async getAllTxHashes(): Promise<TxHash[]> {
|
|
452
|
-
const vals = await toArray(this.#txs.keysAsync());
|
|
453
|
-
return vals.map(x => TxHash.fromString(x));
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
public async getPendingTxInfos(): Promise<PendingTxInfo[]> {
|
|
457
|
-
const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync());
|
|
458
|
-
const results = await Promise.all(vals.map(val => this.getPendingTxInfo(TxHash.fromString(val))));
|
|
459
|
-
return results.filter((info): info is PendingTxInfo => info !== undefined);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
private async getPendingTxInfo(txHash: TxHash): Promise<PendingTxInfo | undefined> {
|
|
463
|
-
let historicalBlockHash = await this.#pendingTxHashToHistoricalBlockHeaderHash.getAsync(txHash.toString());
|
|
464
|
-
// Not all tx might have this index created.
|
|
465
|
-
if (!historicalBlockHash) {
|
|
466
|
-
const tx = await this.getTxByHash(txHash);
|
|
467
|
-
if (!tx) {
|
|
468
|
-
this.#log.warn(`PendingTxInfo:tx ${txHash} not found`);
|
|
469
|
-
return undefined;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
historicalBlockHash = (await tx.data.constants.anchorBlockHeader.hash()).toString();
|
|
473
|
-
await this.#pendingTxHashToHistoricalBlockHeaderHash.set(txHash.toString(), historicalBlockHash);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
return {
|
|
477
|
-
txHash,
|
|
478
|
-
blockHash: Fr.fromString(historicalBlockHash),
|
|
479
|
-
isEvictable: !this.#nonEvictableTxs.has(txHash.toString()),
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
public async getPendingTxsReferencingBlocks(blockHashes: Fr[]): Promise<TxBlockReference[]> {
|
|
484
|
-
const result: TxBlockReference[] = [];
|
|
485
|
-
for (const blockHash of blockHashes) {
|
|
486
|
-
const chunk = await toArray(this.#historicalHeaderToTxHash.getValuesAsync(blockHash.toString()));
|
|
487
|
-
result.push(
|
|
488
|
-
...chunk.map(txHash => ({
|
|
489
|
-
txHash: TxHash.fromString(txHash),
|
|
490
|
-
blockHash,
|
|
491
|
-
isEvictable: !this.#nonEvictableTxs.has(txHash),
|
|
492
|
-
})),
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
return result;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
public async getPendingFeePayers(): Promise<AztecAddress[]> {
|
|
500
|
-
const feePayers: AztecAddress[] = [];
|
|
501
|
-
for await (const feePayer of this.#feePayerToBalanceEntry.keysAsync()) {
|
|
502
|
-
const address = AztecAddress.fromString(feePayer);
|
|
503
|
-
insertIntoSortedArray(feePayers, address, (a, b) => a.toField().cmp(b.toField()), false);
|
|
504
|
-
}
|
|
505
|
-
return feePayers;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
public async *getFeePayerTxInfos(feePayer: AztecAddress): AsyncIterable<FeePayerTxInfo> {
|
|
509
|
-
for await (const value of this.#feePayerToBalanceEntry.getValuesAsync(feePayer.toString())) {
|
|
510
|
-
const info = FeePayerTxInfo.decode(value);
|
|
511
|
-
info.isEvictable = !this.#nonEvictableTxs.has(info.txHash.toString());
|
|
512
|
-
yield info;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
public async getMinedTxHashes(): Promise<[TxHash, BlockNumber][]> {
|
|
517
|
-
const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
|
|
518
|
-
return vals.map(([txHash, blockNumber]) => [TxHash.fromString(txHash), blockNumber]);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
public async getPendingTxCount(): Promise<number> {
|
|
522
|
-
return (await this.#pendingTxPriorityToHash.sizeAsync()) ?? 0;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
public async getMinedTxCount(): Promise<number> {
|
|
526
|
-
return (await this.#minedTxHashToBlock.sizeAsync()) ?? 0;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
public async getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined> {
|
|
530
|
-
const key = txHash.toString();
|
|
531
|
-
const [isMined, isKnown, isDeleted] = await Promise.all([
|
|
532
|
-
this.#minedTxHashToBlock.hasAsync(key),
|
|
533
|
-
this.#txs.hasAsync(key),
|
|
534
|
-
this.#deletedMinedTxHashes.hasAsync(key),
|
|
535
|
-
]);
|
|
536
|
-
|
|
537
|
-
if (isDeleted) {
|
|
538
|
-
return 'deleted';
|
|
539
|
-
} else if (isMined) {
|
|
540
|
-
return 'mined';
|
|
541
|
-
} else if (isKnown) {
|
|
542
|
-
return 'pending';
|
|
543
|
-
} else {
|
|
544
|
-
return undefined;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
public updateConfig(cfg: TxPoolOptions): void {
|
|
549
|
-
if (typeof cfg.archivedTxLimit === 'number') {
|
|
550
|
-
assert(cfg.archivedTxLimit >= 0, 'archivedTxLimit must be greater or equal to 0');
|
|
551
|
-
this.#archivedTxLimit = cfg.archivedTxLimit;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
if (this.#evictionManager) {
|
|
555
|
-
this.#evictionManager.updateConfig(cfg);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
public markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void> {
|
|
560
|
-
txHashes.forEach(txHash => this.#nonEvictableTxs.add(txHash.toString()));
|
|
561
|
-
return Promise.resolve();
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
public clearNonEvictableTxs(): Promise<void> {
|
|
565
|
-
// Clear the non-evictable set after completing the DB updates above.
|
|
566
|
-
// This ensures pinned (non-evictable) txs are protected while we mark mined txs,
|
|
567
|
-
// but they won't remain pinned indefinitely across blocks. Note that eviction rules
|
|
568
|
-
// (including post-mining invalidation) respect the non-evictable flag while it is set.
|
|
569
|
-
this.#nonEvictableTxs.clear();
|
|
570
|
-
return Promise.resolve();
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
|
|
575
|
-
* @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
|
|
576
|
-
* @returns The number of transactions permanently deleted.
|
|
577
|
-
*/
|
|
578
|
-
public async cleanupDeletedMinedTxs(blockNumber: BlockNumber): Promise<number> {
|
|
579
|
-
let deletedCount = 0;
|
|
580
|
-
await this.#store.transactionAsync(async () => {
|
|
581
|
-
const txHashesToDelete: string[] = [];
|
|
582
|
-
const blocksToDelete: BlockNumber[] = [];
|
|
583
|
-
|
|
584
|
-
// Iterate through all entries and check block numbers
|
|
585
|
-
for await (const [block, txHash] of this.#blockToDeletedMinedTxHash.entriesAsync()) {
|
|
586
|
-
if (block <= blockNumber) {
|
|
587
|
-
// Permanently delete the transaction
|
|
588
|
-
await this.#txs.delete(txHash);
|
|
589
|
-
await this.#deletedMinedTxHashes.delete(txHash);
|
|
590
|
-
txHashesToDelete.push(txHash);
|
|
591
|
-
if (!blocksToDelete.includes(block)) {
|
|
592
|
-
blocksToDelete.push(block);
|
|
593
|
-
}
|
|
594
|
-
deletedCount++;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
this.#metrics.transactionsRemoved(txHashesToDelete);
|
|
598
|
-
|
|
599
|
-
// Clean up block-to-hash mapping - delete all values for each block
|
|
600
|
-
for (const block of blocksToDelete) {
|
|
601
|
-
const txHashesForBlock = await toArray(this.#blockToDeletedMinedTxHash.getValuesAsync(block));
|
|
602
|
-
for (const txHash of txHashesForBlock) {
|
|
603
|
-
await this.#blockToDeletedMinedTxHash.deleteValue(block, txHash);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
if (deletedCount > 0) {
|
|
609
|
-
this.#log.debug(`Permanently deleted ${deletedCount} deleted mined txs from blocks up to ${blockNumber}`);
|
|
610
|
-
}
|
|
611
|
-
return deletedCount;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* Creates an ArchiveCache instance.
|
|
616
|
-
* @param db - DB for the cache to use
|
|
617
|
-
* @returns An ArchiveCache instance
|
|
618
|
-
*/
|
|
619
|
-
protected createArchiveCache(db: MerkleTreeReadOperations): ArchiveCache {
|
|
620
|
-
return new ArchiveCache(db);
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
|
|
625
|
-
* Note: Pending txs should not be archived, only finalized txs
|
|
626
|
-
* @param txs - The list of transactions to archive.
|
|
627
|
-
* @returns Empty promise.
|
|
628
|
-
*/
|
|
629
|
-
private async archiveTxs(txs: Tx[]): Promise<void> {
|
|
630
|
-
if (txs.length === 0) {
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
if (this.#archivedTxLimit === 0) {
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
try {
|
|
638
|
-
const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
|
|
639
|
-
await this.#archive.transactionAsync(async () => {
|
|
640
|
-
// calculate the head and tail indices of the archived txs by insertion order.
|
|
641
|
-
let headIdx =
|
|
642
|
-
((await this.#archivedTxIndices.entriesAsync({ limit: 1, reverse: true }).next()).value?.[0] ?? -1) + 1;
|
|
643
|
-
let tailIdx = (await this.#archivedTxIndices.entriesAsync({ limit: 1 }).next()).value?.[0] ?? 0;
|
|
644
|
-
|
|
645
|
-
for (let i = 0; i < txs.length; i++) {
|
|
646
|
-
const tx = txs[i];
|
|
647
|
-
while (headIdx - tailIdx >= this.#archivedTxLimit) {
|
|
648
|
-
const txHash = await this.#archivedTxIndices.getAsync(tailIdx);
|
|
649
|
-
if (txHash) {
|
|
650
|
-
await this.#archivedTxs.delete(txHash);
|
|
651
|
-
await this.#archivedTxIndices.delete(tailIdx);
|
|
652
|
-
}
|
|
653
|
-
tailIdx++;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
const archivedTx: Tx = new Tx(
|
|
657
|
-
tx.txHash,
|
|
658
|
-
tx.data,
|
|
659
|
-
ChonkProof.empty(),
|
|
660
|
-
tx.contractClassLogFields,
|
|
661
|
-
tx.publicFunctionCalldata,
|
|
662
|
-
);
|
|
663
|
-
const txHash = txHashes[i].toString();
|
|
664
|
-
await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
|
|
665
|
-
await this.#archivedTxIndices.set(headIdx, txHash);
|
|
666
|
-
headIdx++;
|
|
667
|
-
}
|
|
668
|
-
this.#log.debug(`Archived ${txs.length} txs`, { txHashes });
|
|
669
|
-
this.#log.debug(`Total archived txs: ${headIdx - tailIdx}`);
|
|
670
|
-
});
|
|
671
|
-
} catch (error) {
|
|
672
|
-
this.#log.error(`Error archiving txs`, { error });
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// Assumes being called within a DB transaction
|
|
677
|
-
private async addPendingTxIndicesInDbTx(tx: Tx, txHash: string): Promise<void> {
|
|
678
|
-
await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), txHash);
|
|
679
|
-
await this.#historicalHeaderToTxHash.set((await tx.data.constants.anchorBlockHeader.hash()).toString(), txHash);
|
|
680
|
-
await this.#feePayerToBalanceEntry.set(tx.data.feePayer.toString(), await FeePayerTxInfo.encode(tx, txHash));
|
|
681
|
-
|
|
682
|
-
// Add nullifier entries for conflict detection
|
|
683
|
-
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
684
|
-
for (const nullifier of nullifiers) {
|
|
685
|
-
await this.#pendingNullifierToTxHash.set(nullifier.toString(), txHash);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// Assumes being called within a DB transaction
|
|
690
|
-
private async removePendingTxIndicesInDbTx(tx: Tx, txHash: string): Promise<void> {
|
|
691
|
-
await this.#pendingTxPriorityToHash.deleteValue(getPendingTxPriority(tx), txHash);
|
|
692
|
-
await this.#historicalHeaderToTxHash.deleteValue(
|
|
693
|
-
(await tx.data.constants.anchorBlockHeader.hash()).toString(),
|
|
694
|
-
txHash,
|
|
695
|
-
);
|
|
696
|
-
await this.#feePayerToBalanceEntry.deleteValue(
|
|
697
|
-
tx.data.feePayer.toString(),
|
|
698
|
-
await FeePayerTxInfo.encode(tx, txHash),
|
|
699
|
-
);
|
|
700
|
-
|
|
701
|
-
// Remove nullifier entries
|
|
702
|
-
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
703
|
-
for (const nullifier of nullifiers) {
|
|
704
|
-
await this.#pendingNullifierToTxHash.delete(nullifier.toString());
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Returns up to `limit` lowest-priority evictable pending tx hashes without hydrating transactions.
|
|
710
|
-
* Iterates the priority index in ascending order and skips non-evictable txs.
|
|
711
|
-
*/
|
|
712
|
-
public async getLowestPriorityEvictable(limit: number): Promise<TxHash[]> {
|
|
713
|
-
const txsToEvict: TxHash[] = [];
|
|
714
|
-
if (limit <= 0) {
|
|
715
|
-
return txsToEvict;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
for await (const txHashStr of this.#pendingTxPriorityToHash.valuesAsync()) {
|
|
719
|
-
if (this.#nonEvictableTxs.has(txHashStr)) {
|
|
720
|
-
continue;
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
txsToEvict.push(TxHash.fromString(txHashStr));
|
|
724
|
-
if (txsToEvict.length >= limit) {
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
return txsToEvict;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
/**
|
|
733
|
-
* Creates a PreAddPoolAccess object for use by pre-add eviction rules.
|
|
734
|
-
* Provides read-only access to pool state during addTxs transaction.
|
|
735
|
-
*/
|
|
736
|
-
private getPreAddPoolAccess(): PreAddPoolAccess {
|
|
737
|
-
return {
|
|
738
|
-
getTxHashByNullifier: async nullifier => {
|
|
739
|
-
const hashStr = await this.#pendingNullifierToTxHash.getAsync(nullifier.toString());
|
|
740
|
-
return hashStr ? TxHash.fromString(hashStr) : undefined;
|
|
741
|
-
},
|
|
742
|
-
getPendingTxByHash: this.getTxByHash.bind(this),
|
|
743
|
-
getTxPriority: getPendingTxPriority,
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
}
|