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