@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.03f7ef2
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 +157 -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 -190
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +381 -183
- package/dest/config.d.ts +151 -125
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +183 -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 +68 -8
- 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 +216 -65
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -6
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +127 -26
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +19 -6
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +111 -21
- package/dest/mem_pools/attestation_pool/mocks.d.ts +227 -7
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +10 -16
- 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 +57 -35
- 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 +64 -14
- 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 +472 -97
- package/dest/mem_pools/tx_pool/index.d.ts +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +36 -11
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +137 -36
- package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +67 -10
- 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 +273 -42
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
- 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 +67 -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/block_proposal_validator/block_proposal_validator.d.ts +6 -2
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
- package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
- package/dest/msg_validators/index.d.ts +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/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 +50 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +74 -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 +164 -0
- package/dest/services/libp2p/libp2p_service.d.ts +78 -89
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +695 -248
- 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 +6 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +22 -2
- package/dest/services/peer-manager/peer_manager.d.ts +102 -22
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +549 -72
- 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 +40 -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/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 +73 -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 +298 -207
- 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 +23 -19
- 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 +34 -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 +217 -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 +47 -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 +103 -29
- 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 +11 -19
- 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 +198 -0
- package/src/client/p2p_client.ts +484 -348
- package/src/config.ts +305 -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 +75 -7
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +266 -67
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +174 -35
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
- package/src/mem_pools/attestation_pool/mocks.ts +13 -12
- package/src/mem_pools/instrumentation.ts +70 -40
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +555 -110
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +160 -46
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +69 -9
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +224 -35
- package/src/msg_validators/attestation_validator/attestation_validator.ts +54 -11
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -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 +81 -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 +59 -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 +47 -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 +147 -9
- package/src/services/encoding.ts +81 -6
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +167 -0
- package/src/services/libp2p/libp2p_service.ts +865 -298
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +26 -1
- package/src/services/peer-manager/peer_manager.ts +654 -78
- package/src/services/peer-manager/peer_scoring.ts +46 -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 +148 -95
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +92 -37
- package/src/services/reqresp/metrics.ts +4 -1
- 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 +118 -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 +45 -21
- 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 +43 -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 +229 -0
- package/src/services/tx_provider_instrumentation.ts +61 -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 +151 -25
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +17 -23
- package/src/types/index.ts +2 -0
- package/src/util.ts +105 -91
- package/src/versioning.ts +11 -4
|
@@ -1,30 +1,69 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
+
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
6
|
+
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
7
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
8
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
9
|
+
import type { MerkleTreeReadOperations, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
10
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
5
11
|
import type { TxAddedToPoolStats } from '@aztec/stdlib/stats';
|
|
6
|
-
import {
|
|
12
|
+
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
13
|
+
import { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
7
14
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
8
15
|
|
|
9
|
-
import
|
|
16
|
+
import assert from 'assert';
|
|
17
|
+
import EventEmitter from 'node:events';
|
|
18
|
+
|
|
19
|
+
import { ArchiveCache } from '../../msg_validators/tx_validator/archive_cache.js';
|
|
20
|
+
import { GasTxValidator } from '../../msg_validators/tx_validator/gas_validator.js';
|
|
21
|
+
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
10
22
|
import { getPendingTxPriority } from './priority.js';
|
|
11
|
-
import type { TxPool } from './tx_pool.js';
|
|
23
|
+
import type { TxPool, TxPoolEvents, TxPoolOptions } from './tx_pool.js';
|
|
12
24
|
|
|
13
25
|
/**
|
|
14
26
|
* KV implementation of the Transaction Pool.
|
|
15
27
|
*/
|
|
16
|
-
export class AztecKVTxPool implements TxPool {
|
|
28
|
+
export class AztecKVTxPool extends (EventEmitter as new () => TypedEventEmitter<TxPoolEvents>) implements TxPool {
|
|
17
29
|
#store: AztecAsyncKVStore;
|
|
18
30
|
|
|
19
31
|
/** Our tx pool, stored as a Map, with K: tx hash and V: the transaction. */
|
|
20
32
|
#txs: AztecAsyncMap<string, Buffer>;
|
|
21
33
|
|
|
34
|
+
/** The maximum cumulative tx size that the pending txs in the pool take up. */
|
|
35
|
+
#maxTxPoolSize: number = 0;
|
|
36
|
+
|
|
37
|
+
/** The tx evicion logic will kick after pool size is greater than maxTxPoolSize * txPoolOverflowFactor */
|
|
38
|
+
txPoolOverflowFactor: number = 1;
|
|
39
|
+
|
|
22
40
|
/** Index from tx hash to the block number in which they were mined, filtered by mined txs. */
|
|
23
|
-
#minedTxHashToBlock: AztecAsyncMap<string,
|
|
41
|
+
#minedTxHashToBlock: AztecAsyncMap<string, BlockNumber>;
|
|
24
42
|
|
|
25
43
|
/** Index from tx priority (stored as hex) to its tx hash, filtered by pending txs. */
|
|
26
44
|
#pendingTxPriorityToHash: AztecAsyncMultiMap<string, string>;
|
|
27
45
|
|
|
46
|
+
/** Index from tx hash to its tx size (in bytes), filtered by pending txs. */
|
|
47
|
+
#pendingTxHashToSize: AztecAsyncMap<string, number>;
|
|
48
|
+
|
|
49
|
+
/** Index from tx hash to its header hash, filtered by pending txs. */
|
|
50
|
+
#pendingTxHashToHeaderHash: AztecAsyncMap<string, string>;
|
|
51
|
+
|
|
52
|
+
/** Map from tx hash to the block number it was originally mined in (for soft-deleted txs). */
|
|
53
|
+
#deletedMinedTxHashes: AztecAsyncMap<string, BlockNumber>;
|
|
54
|
+
|
|
55
|
+
/** MultiMap from block number to deleted mined tx hashes for efficient cleanup. */
|
|
56
|
+
#blockToDeletedMinedTxHash: AztecAsyncMultiMap<BlockNumber, string>;
|
|
57
|
+
|
|
58
|
+
/** The cumulative tx size in bytes that the pending txs in the pool take up. */
|
|
59
|
+
#pendingTxSize: AztecAsyncSingleton<number>;
|
|
60
|
+
|
|
61
|
+
/** In-memory mapping of pending tx hashes to the hydrated pending tx in the pool. */
|
|
62
|
+
#pendingTxs: Map<string, Tx>;
|
|
63
|
+
|
|
64
|
+
/** In-memory set of txs that should not be evicted from the pool. */
|
|
65
|
+
#nonEvictableTxs: Set<string>;
|
|
66
|
+
|
|
28
67
|
/** KV store for archived txs. */
|
|
29
68
|
#archive: AztecAsyncKVStore;
|
|
30
69
|
|
|
@@ -35,7 +74,10 @@ export class AztecKVTxPool implements TxPool {
|
|
|
35
74
|
#archivedTxIndices: AztecAsyncMap<number, string>;
|
|
36
75
|
|
|
37
76
|
/** Number of txs to archive. */
|
|
38
|
-
#archivedTxLimit: number;
|
|
77
|
+
#archivedTxLimit: number = 0;
|
|
78
|
+
|
|
79
|
+
/** The world state synchronizer used in the node. */
|
|
80
|
+
#worldStateSynchronizer: WorldStateSynchronizer;
|
|
39
81
|
|
|
40
82
|
#log: Logger;
|
|
41
83
|
|
|
@@ -52,85 +94,160 @@ export class AztecKVTxPool implements TxPool {
|
|
|
52
94
|
constructor(
|
|
53
95
|
store: AztecAsyncKVStore,
|
|
54
96
|
archive: AztecAsyncKVStore,
|
|
97
|
+
worldStateSynchronizer: WorldStateSynchronizer,
|
|
55
98
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
56
|
-
|
|
99
|
+
config: TxPoolOptions = {},
|
|
57
100
|
log = createLogger('p2p:tx_pool'),
|
|
58
101
|
) {
|
|
102
|
+
super();
|
|
103
|
+
|
|
104
|
+
this.#log = log;
|
|
105
|
+
this.updateConfig(config);
|
|
106
|
+
|
|
59
107
|
this.#txs = store.openMap('txs');
|
|
60
108
|
this.#minedTxHashToBlock = store.openMap('txHashToBlockMined');
|
|
61
109
|
this.#pendingTxPriorityToHash = store.openMultiMap('pendingTxFeeToHash');
|
|
110
|
+
this.#pendingTxHashToSize = store.openMap('pendingTxHashToSize');
|
|
111
|
+
this.#pendingTxHashToHeaderHash = store.openMap('pendingTxHashToHeaderHash');
|
|
112
|
+
this.#pendingTxSize = store.openSingleton('pendingTxSize');
|
|
113
|
+
this.#deletedMinedTxHashes = store.openMap('deletedMinedTxHashes');
|
|
114
|
+
this.#blockToDeletedMinedTxHash = store.openMultiMap('blockToDeletedMinedTxHash');
|
|
115
|
+
|
|
116
|
+
this.#pendingTxs = new Map<string, Tx>();
|
|
117
|
+
this.#nonEvictableTxs = new Set<string>();
|
|
62
118
|
|
|
63
119
|
this.#archivedTxs = archive.openMap('archivedTxs');
|
|
64
120
|
this.#archivedTxIndices = archive.openMap('archivedTxIndices');
|
|
65
|
-
this.#archivedTxLimit = archivedTxLimit;
|
|
66
121
|
|
|
67
122
|
this.#store = store;
|
|
68
123
|
this.#archive = archive;
|
|
69
|
-
this.#
|
|
70
|
-
this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, () => store.estimateSize());
|
|
124
|
+
this.#worldStateSynchronizer = worldStateSynchronizer;
|
|
125
|
+
this.#metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, this.countTxs, () => store.estimateSize());
|
|
71
126
|
}
|
|
72
127
|
|
|
73
|
-
|
|
128
|
+
private countTxs: PoolStatsCallback = async () => {
|
|
129
|
+
const [pending = 0, mined = 0] = await Promise.all([this.getPendingTxCount(), this.getMinedTxCount()]);
|
|
130
|
+
|
|
131
|
+
return Promise.resolve({
|
|
132
|
+
itemCount: {
|
|
133
|
+
pending,
|
|
134
|
+
mined,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
public async isEmpty(): Promise<boolean> {
|
|
140
|
+
for await (const _ of this.#txs.entriesAsync()) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Marks transactions as mined in a block and updates the pool state accordingly.
|
|
147
|
+
* Removes the transactions from the pending set and adds them to the mined set.
|
|
148
|
+
* Also evicts any transactions that become invalid after the block is mined.
|
|
149
|
+
* @param txHashes - Array of transaction hashes that were mined
|
|
150
|
+
* @param blockHeader - The header of the block the transactions were mined in
|
|
151
|
+
*/
|
|
152
|
+
public async markAsMined(txHashes: TxHash[], blockHeader: BlockHeader): Promise<void> {
|
|
74
153
|
if (txHashes.length === 0) {
|
|
75
154
|
return Promise.resolve();
|
|
76
155
|
}
|
|
77
156
|
|
|
78
|
-
|
|
79
|
-
|
|
157
|
+
const minedNullifiers = new Set<string>();
|
|
158
|
+
const minedFeePayers = new Set<string>();
|
|
159
|
+
|
|
160
|
+
await this.#store.transactionAsync(async () => {
|
|
161
|
+
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
80
162
|
for (const hash of txHashes) {
|
|
81
163
|
const key = hash.toString();
|
|
82
|
-
await this.#minedTxHashToBlock.set(key, blockNumber);
|
|
83
164
|
|
|
84
|
-
|
|
165
|
+
// If this tx was previously soft-deleted, remove it from the deleted sets
|
|
166
|
+
if (await this.#deletedMinedTxHashes.hasAsync(key)) {
|
|
167
|
+
const originalBlock = await this.#deletedMinedTxHashes.getAsync(key);
|
|
168
|
+
await this.#deletedMinedTxHashes.delete(key);
|
|
169
|
+
// Remove from block-to-hash mapping
|
|
170
|
+
if (originalBlock !== undefined) {
|
|
171
|
+
await this.#blockToDeletedMinedTxHash.deleteValue(originalBlock, key);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
await this.#minedTxHashToBlock.set(key, blockHeader.globalVariables.blockNumber);
|
|
176
|
+
|
|
177
|
+
const tx = await this.getPendingTxByHash(hash);
|
|
85
178
|
if (tx) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
179
|
+
const nullifiers = tx.data.getNonEmptyNullifiers();
|
|
180
|
+
nullifiers.forEach(nullifier => minedNullifiers.add(nullifier.toString()));
|
|
181
|
+
minedFeePayers.add(tx.data.feePayer.toString());
|
|
182
|
+
pendingTxSize -= tx.getSize();
|
|
183
|
+
await this.removePendingTxIndices(tx, key);
|
|
89
184
|
}
|
|
90
185
|
}
|
|
91
|
-
this.#
|
|
92
|
-
|
|
186
|
+
await this.#pendingTxSize.set(pendingTxSize);
|
|
187
|
+
|
|
188
|
+
await this.evictInvalidTxsAfterMining(txHashes, blockHeader, minedNullifiers, minedFeePayers);
|
|
93
189
|
});
|
|
190
|
+
this.#metrics.transactionsRemoved(txHashes);
|
|
191
|
+
// We update this after the transaction above. This ensures that the non-evictable transactions are not evicted
|
|
192
|
+
// until any that have been mined are marked as such.
|
|
193
|
+
// The non-evictable set is not considered when evicting transactions that are invalid after a block is mined.
|
|
194
|
+
this.#nonEvictableTxs.clear();
|
|
94
195
|
}
|
|
95
196
|
|
|
96
|
-
public markMinedAsPending(txHashes: TxHash[]): Promise<void> {
|
|
197
|
+
public async markMinedAsPending(txHashes: TxHash[]): Promise<void> {
|
|
97
198
|
if (txHashes.length === 0) {
|
|
98
199
|
return Promise.resolve();
|
|
99
200
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return this.#store.transactionAsync(async () => {
|
|
201
|
+
await this.#store.transactionAsync(async () => {
|
|
202
|
+
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
103
203
|
for (const hash of txHashes) {
|
|
104
204
|
const key = hash.toString();
|
|
105
205
|
await this.#minedTxHashToBlock.delete(key);
|
|
106
206
|
|
|
107
|
-
|
|
207
|
+
// Rehydrate the tx in the in-memory pending txs mapping
|
|
208
|
+
const tx = await this.getPendingTxByHash(hash);
|
|
108
209
|
if (tx) {
|
|
109
|
-
await this
|
|
110
|
-
|
|
210
|
+
await this.addPendingTxIndices(tx, key);
|
|
211
|
+
pendingTxSize += tx.getSize();
|
|
111
212
|
}
|
|
112
213
|
}
|
|
113
214
|
|
|
114
|
-
this.#
|
|
115
|
-
this.#metrics.recordRemovedObjects(markedAsPending, 'mined');
|
|
215
|
+
await this.#pendingTxSize.set(pendingTxSize);
|
|
116
216
|
});
|
|
217
|
+
|
|
218
|
+
await this.evictInvalidTxsAfterReorg(txHashes);
|
|
219
|
+
await this.evictLowPriorityTxs(txHashes);
|
|
117
220
|
}
|
|
118
221
|
|
|
119
222
|
public async getPendingTxHashes(): Promise<TxHash[]> {
|
|
120
223
|
const vals = await toArray(this.#pendingTxPriorityToHash.valuesAsync({ reverse: true }));
|
|
121
|
-
return vals.map(
|
|
224
|
+
return vals.map(TxHash.fromString);
|
|
122
225
|
}
|
|
123
226
|
|
|
124
|
-
public async getMinedTxHashes(): Promise<[TxHash,
|
|
227
|
+
public async getMinedTxHashes(): Promise<[TxHash, BlockNumber][]> {
|
|
125
228
|
const vals = await toArray(this.#minedTxHashToBlock.entriesAsync());
|
|
126
229
|
return vals.map(([txHash, blockNumber]) => [TxHash.fromString(txHash), blockNumber]);
|
|
127
230
|
}
|
|
128
231
|
|
|
129
|
-
public async
|
|
130
|
-
|
|
131
|
-
|
|
232
|
+
public async getPendingTxCount(): Promise<number> {
|
|
233
|
+
return (await this.#pendingTxHashToHeaderHash.sizeAsync()) ?? 0;
|
|
234
|
+
}
|
|
132
235
|
|
|
133
|
-
|
|
236
|
+
public async getMinedTxCount(): Promise<number> {
|
|
237
|
+
return (await this.#minedTxHashToBlock.sizeAsync()) ?? 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public async getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined> {
|
|
241
|
+
const key = txHash.toString();
|
|
242
|
+
const [isMined, isKnown, isDeleted] = await Promise.all([
|
|
243
|
+
this.#minedTxHashToBlock.hasAsync(key),
|
|
244
|
+
this.#txs.hasAsync(key),
|
|
245
|
+
this.#deletedMinedTxHashes.hasAsync(key),
|
|
246
|
+
]);
|
|
247
|
+
|
|
248
|
+
if (isDeleted) {
|
|
249
|
+
return 'deleted';
|
|
250
|
+
} else if (isMined) {
|
|
134
251
|
return 'mined';
|
|
135
252
|
} else if (isKnown) {
|
|
136
253
|
return 'pending';
|
|
@@ -146,12 +263,21 @@ export class AztecKVTxPool implements TxPool {
|
|
|
146
263
|
*/
|
|
147
264
|
public async getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
148
265
|
const buffer = await this.#txs.getAsync(txHash.toString());
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return undefined;
|
|
266
|
+
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async getTxsByHash(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
270
|
+
const txs = await Promise.all(txHashes.map(txHash => this.#txs.getAsync(txHash.toString())));
|
|
271
|
+
return txs.map(buffer => (buffer ? Tx.fromBuffer(buffer) : undefined));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async hasTxs(txHashes: TxHash[]): Promise<boolean[]> {
|
|
275
|
+
return await Promise.all(txHashes.map(txHash => this.#txs.hasAsync(txHash.toString())));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async hasTx(txHash: TxHash): Promise<boolean> {
|
|
279
|
+
const result = await this.hasTxs([txHash]);
|
|
280
|
+
return result[0];
|
|
155
281
|
}
|
|
156
282
|
|
|
157
283
|
/**
|
|
@@ -161,12 +287,7 @@ export class AztecKVTxPool implements TxPool {
|
|
|
161
287
|
*/
|
|
162
288
|
public async getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
163
289
|
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;
|
|
290
|
+
return buffer ? Tx.fromBuffer(buffer) : undefined;
|
|
170
291
|
}
|
|
171
292
|
|
|
172
293
|
/**
|
|
@@ -174,75 +295,99 @@ export class AztecKVTxPool implements TxPool {
|
|
|
174
295
|
* @param txs - An array of txs to be added to the pool.
|
|
175
296
|
* @returns Empty promise.
|
|
176
297
|
*/
|
|
177
|
-
public async addTxs(txs: Tx[]): Promise<
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
);
|
|
298
|
+
public async addTxs(txs: Tx[], opts: { source?: string } = {}): Promise<number> {
|
|
299
|
+
const addedTxs: Tx[] = [];
|
|
300
|
+
const hashesAndStats = txs.map(tx => ({ txHash: tx.getTxHash(), txStats: tx.getStats() }));
|
|
181
301
|
await this.#store.transactionAsync(async () => {
|
|
182
|
-
let
|
|
302
|
+
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
183
303
|
await Promise.all(
|
|
184
304
|
txs.map(async (tx, i) => {
|
|
185
305
|
const { txHash, txStats } = hashesAndStats[i];
|
|
306
|
+
const key = txHash.toString();
|
|
307
|
+
if (await this.#txs.hasAsync(key)) {
|
|
308
|
+
this.#log.debug(`Tx ${txHash.toString()} already exists in the pool`);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
186
312
|
this.#log.verbose(`Adding tx ${txHash.toString()} to pool`, {
|
|
187
313
|
eventName: 'tx-added-to-pool',
|
|
188
314
|
...txStats,
|
|
189
315
|
} satisfies TxAddedToPoolStats);
|
|
190
316
|
|
|
191
|
-
const key = txHash.toString();
|
|
192
317
|
await this.#txs.set(key, tx.toBuffer());
|
|
318
|
+
addedTxs.push(tx as Tx);
|
|
193
319
|
|
|
194
320
|
if (!(await this.#minedTxHashToBlock.hasAsync(key))) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), key);
|
|
321
|
+
pendingTxSize += tx.getSize();
|
|
322
|
+
await this.addPendingTxIndices(tx, key);
|
|
198
323
|
this.#metrics.recordSize(tx);
|
|
199
324
|
}
|
|
200
325
|
}),
|
|
201
326
|
);
|
|
202
327
|
|
|
203
|
-
this.#
|
|
328
|
+
await this.#pendingTxSize.set(pendingTxSize);
|
|
329
|
+
await this.evictLowPriorityTxs(hashesAndStats.map(({ txHash }) => txHash));
|
|
204
330
|
});
|
|
331
|
+
|
|
332
|
+
if (addedTxs.length > 0) {
|
|
333
|
+
this.#metrics.transactionsAdded(addedTxs);
|
|
334
|
+
this.emit('txs-added', { ...opts, txs: addedTxs });
|
|
335
|
+
}
|
|
336
|
+
return addedTxs.length;
|
|
205
337
|
}
|
|
206
338
|
|
|
207
339
|
/**
|
|
208
340
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
209
|
-
*
|
|
341
|
+
* Mined transactions are soft-deleted with a timestamp, pending transactions are permanently deleted.
|
|
342
|
+
* @param txHashes - An array of tx hashes to be deleted from the tx pool.
|
|
210
343
|
* @returns Empty promise.
|
|
211
344
|
*/
|
|
212
|
-
public deleteTxs(txHashes: TxHash[]): Promise<void> {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
345
|
+
public deleteTxs(txHashes: TxHash[], opts: { eviction?: boolean; permanently?: boolean } = {}): Promise<void> {
|
|
346
|
+
if (txHashes.length === 0) {
|
|
347
|
+
return Promise.resolve();
|
|
348
|
+
}
|
|
216
349
|
const deletedTxs: Tx[] = [];
|
|
217
350
|
const poolDbTx = this.#store.transactionAsync(async () => {
|
|
351
|
+
let pendingTxSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
218
352
|
for (const hash of txHashes) {
|
|
219
353
|
const key = hash.toString();
|
|
220
354
|
const tx = await this.getTxByHash(hash);
|
|
221
355
|
|
|
222
356
|
if (tx) {
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
357
|
+
const minedBlockNumber = await this.#minedTxHashToBlock.getAsync(key);
|
|
358
|
+
|
|
359
|
+
if (minedBlockNumber !== undefined) {
|
|
360
|
+
await this.#minedTxHashToBlock.delete(key);
|
|
361
|
+
if (opts.permanently) {
|
|
362
|
+
// Permanently delete mined transactions if specified
|
|
363
|
+
this.#log.trace(`Deleting mined tx ${key} from pool`);
|
|
364
|
+
await this.#txs.delete(key);
|
|
365
|
+
} else {
|
|
366
|
+
// Soft-delete mined transactions: remove from mined set but keep in storage
|
|
367
|
+
this.#log.trace(`Soft-deleting mined tx ${key} from pool`);
|
|
368
|
+
await this.#deletedMinedTxHashes.set(key, minedBlockNumber);
|
|
369
|
+
await this.#blockToDeletedMinedTxHash.set(minedBlockNumber, key);
|
|
370
|
+
}
|
|
229
371
|
} else {
|
|
230
|
-
|
|
372
|
+
// Permanently delete pending transactions
|
|
373
|
+
this.#log.trace(`Deleting pending tx ${key} from pool`);
|
|
374
|
+
pendingTxSize -= tx.getSize();
|
|
375
|
+
await this.removePendingTxIndices(tx, key);
|
|
376
|
+
await this.#txs.delete(key);
|
|
231
377
|
}
|
|
232
378
|
|
|
233
|
-
if (this.#archivedTxLimit) {
|
|
379
|
+
if (!opts.eviction && this.#archivedTxLimit) {
|
|
234
380
|
deletedTxs.push(tx);
|
|
235
381
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
await this.#minedTxHashToBlock.delete(key);
|
|
382
|
+
} else {
|
|
383
|
+
this.#log.trace(`Skipping deletion of missing tx ${key} from pool`);
|
|
239
384
|
}
|
|
240
385
|
}
|
|
241
386
|
|
|
242
|
-
this.#
|
|
243
|
-
this.#metrics.recordRemovedObjects(minedDeleted, 'mined');
|
|
387
|
+
await this.#pendingTxSize.set(pendingTxSize);
|
|
244
388
|
});
|
|
245
|
-
|
|
389
|
+
this.#metrics.transactionsRemoved(txHashes);
|
|
390
|
+
this.#log.debug(`Deleted ${txHashes.length} txs from pool`, { txHashes });
|
|
246
391
|
return this.#archivedTxLimit ? poolDbTx.then(() => this.archiveTxs(deletedTxs)) : poolDbTx;
|
|
247
392
|
}
|
|
248
393
|
|
|
@@ -251,12 +396,8 @@ export class AztecKVTxPool implements TxPool {
|
|
|
251
396
|
* @returns Array of tx objects in the order they were added to the pool.
|
|
252
397
|
*/
|
|
253
398
|
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
|
-
});
|
|
399
|
+
const vals = await toArray(this.#txs.valuesAsync());
|
|
400
|
+
return vals.map(buffer => Tx.fromBuffer(buffer));
|
|
260
401
|
}
|
|
261
402
|
|
|
262
403
|
/**
|
|
@@ -268,42 +409,346 @@ export class AztecKVTxPool implements TxPool {
|
|
|
268
409
|
return vals.map(x => TxHash.fromString(x));
|
|
269
410
|
}
|
|
270
411
|
|
|
412
|
+
public updateConfig({ maxTxPoolSize, txPoolOverflowFactor, archivedTxLimit }: TxPoolOptions): void {
|
|
413
|
+
if (typeof maxTxPoolSize === 'number') {
|
|
414
|
+
assert(maxTxPoolSize >= 0, 'maxTxPoolSize must be greater or equal to 0');
|
|
415
|
+
this.#maxTxPoolSize = maxTxPoolSize;
|
|
416
|
+
|
|
417
|
+
if (maxTxPoolSize === 0) {
|
|
418
|
+
this.#log.info(`Disabling maximum tx mempool size. Tx eviction stopped`);
|
|
419
|
+
} else {
|
|
420
|
+
this.#log.info(`Setting maximum tx mempool size`, { maxTxPoolSize });
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (typeof txPoolOverflowFactor === 'number') {
|
|
425
|
+
assert(txPoolOverflowFactor >= 1, 'txPoolOveflowFactor must be greater or equal to 1');
|
|
426
|
+
this.txPoolOverflowFactor = txPoolOverflowFactor;
|
|
427
|
+
this.#log.info(`Allowing tx pool size to grow above limit`, { maxTxPoolSize, txPoolOverflowFactor });
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (typeof archivedTxLimit === 'number') {
|
|
431
|
+
assert(archivedTxLimit >= 0, 'archivedTxLimit must be greater or equal to 0');
|
|
432
|
+
this.#archivedTxLimit = archivedTxLimit;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// deletedMinedCleanupThresholdMs is no longer used in block-based cleanup
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
public markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void> {
|
|
439
|
+
txHashes.forEach(txHash => this.#nonEvictableTxs.add(txHash.toString()));
|
|
440
|
+
return Promise.resolve();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Permanently deletes deleted mined transactions from blocks up to and including the specified block number.
|
|
445
|
+
* @param blockNumber - Block number threshold. Deleted mined txs from this block or earlier will be permanently deleted.
|
|
446
|
+
* @returns The number of transactions permanently deleted.
|
|
447
|
+
*/
|
|
448
|
+
public async cleanupDeletedMinedTxs(blockNumber: BlockNumber): Promise<number> {
|
|
449
|
+
let deletedCount = 0;
|
|
450
|
+
const txHashesToDelete: string[] = [];
|
|
451
|
+
const blocksToDelete: BlockNumber[] = [];
|
|
452
|
+
|
|
453
|
+
await this.#store.transactionAsync(async () => {
|
|
454
|
+
// Iterate through all entries and check block numbers
|
|
455
|
+
for await (const [block, txHash] of this.#blockToDeletedMinedTxHash.entriesAsync()) {
|
|
456
|
+
if (block <= blockNumber) {
|
|
457
|
+
// Permanently delete the transaction
|
|
458
|
+
await this.#txs.delete(txHash);
|
|
459
|
+
await this.#deletedMinedTxHashes.delete(txHash);
|
|
460
|
+
txHashesToDelete.push(txHash);
|
|
461
|
+
if (!blocksToDelete.includes(block)) {
|
|
462
|
+
blocksToDelete.push(block);
|
|
463
|
+
}
|
|
464
|
+
deletedCount++;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Clean up block-to-hash mapping - delete all values for each block
|
|
469
|
+
for (const block of blocksToDelete) {
|
|
470
|
+
const txHashesForBlock = await toArray(this.#blockToDeletedMinedTxHash.getValuesAsync(block));
|
|
471
|
+
for (const txHash of txHashesForBlock) {
|
|
472
|
+
await this.#blockToDeletedMinedTxHash.deleteValue(block, txHash);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
if (deletedCount > 0) {
|
|
478
|
+
this.#log.debug(`Permanently deleted ${deletedCount} deleted mined txs from blocks up to ${blockNumber}`);
|
|
479
|
+
}
|
|
480
|
+
return deletedCount;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Creates a GasTxValidator instance.
|
|
485
|
+
* @param db - DB for the validator to use
|
|
486
|
+
* @returns A GasTxValidator instance
|
|
487
|
+
*/
|
|
488
|
+
protected createGasTxValidator(db: MerkleTreeReadOperations): GasTxValidator {
|
|
489
|
+
return new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, GasFees.empty());
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Creates an ArchiveCache instance.
|
|
494
|
+
* @param db - DB for the cache to use
|
|
495
|
+
* @returns An ArchiveCache instance
|
|
496
|
+
*/
|
|
497
|
+
protected createArchiveCache(db: MerkleTreeReadOperations): ArchiveCache {
|
|
498
|
+
return new ArchiveCache(db);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Checks if a cached transaction exists in the in-memory pending tx pool and returns it.
|
|
503
|
+
* Otherwise, it checks the tx pool, updates the pending tx pool, and returns the tx.
|
|
504
|
+
* @param txHash - The generated tx hash.
|
|
505
|
+
* @returns The transaction, if found, 'undefined' otherwise.
|
|
506
|
+
*/
|
|
507
|
+
private async getPendingTxByHash(txHash: TxHash | string): Promise<Tx | undefined> {
|
|
508
|
+
let key;
|
|
509
|
+
if (typeof txHash === 'string') {
|
|
510
|
+
key = txHash;
|
|
511
|
+
txHash = TxHash.fromString(txHash);
|
|
512
|
+
} else {
|
|
513
|
+
key = txHash.toString();
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (this.#pendingTxs.has(key)) {
|
|
517
|
+
return this.#pendingTxs.get(key);
|
|
518
|
+
}
|
|
519
|
+
const tx = await this.getTxByHash(txHash);
|
|
520
|
+
if (tx) {
|
|
521
|
+
this.#pendingTxs.set(key, tx);
|
|
522
|
+
return tx;
|
|
523
|
+
}
|
|
524
|
+
return undefined;
|
|
525
|
+
}
|
|
526
|
+
|
|
271
527
|
/**
|
|
272
528
|
* Archives a list of txs for future reference. The number of archived txs is limited by the specified archivedTxLimit.
|
|
273
529
|
* @param txs - The list of transactions to archive.
|
|
274
530
|
* @returns Empty promise.
|
|
275
531
|
*/
|
|
276
532
|
private async archiveTxs(txs: Tx[]): Promise<void> {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
533
|
+
if (txs.length === 0) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
try {
|
|
537
|
+
const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
|
|
538
|
+
await this.#archive.transactionAsync(async () => {
|
|
539
|
+
// calculate the head and tail indices of the archived txs by insertion order.
|
|
540
|
+
let headIdx =
|
|
541
|
+
((await this.#archivedTxIndices.entriesAsync({ limit: 1, reverse: true }).next()).value?.[0] ?? -1) + 1;
|
|
542
|
+
let tailIdx = (await this.#archivedTxIndices.entriesAsync({ limit: 1 }).next()).value?.[0] ?? 0;
|
|
543
|
+
|
|
544
|
+
for (let i = 0; i < txs.length; i++) {
|
|
545
|
+
const tx = txs[i];
|
|
546
|
+
while (headIdx - tailIdx >= this.#archivedTxLimit) {
|
|
547
|
+
const txHash = await this.#archivedTxIndices.getAsync(tailIdx);
|
|
548
|
+
if (txHash) {
|
|
549
|
+
await this.#archivedTxs.delete(txHash);
|
|
550
|
+
await this.#archivedTxIndices.delete(tailIdx);
|
|
551
|
+
}
|
|
552
|
+
tailIdx++;
|
|
291
553
|
}
|
|
292
|
-
|
|
554
|
+
|
|
555
|
+
const archivedTx: Tx = new Tx(
|
|
556
|
+
tx.txHash,
|
|
557
|
+
tx.data,
|
|
558
|
+
ChonkProof.empty(),
|
|
559
|
+
tx.contractClassLogFields,
|
|
560
|
+
tx.publicFunctionCalldata,
|
|
561
|
+
);
|
|
562
|
+
const txHash = txHashes[i].toString();
|
|
563
|
+
await this.#archivedTxs.set(txHash, archivedTx.toBuffer());
|
|
564
|
+
await this.#archivedTxIndices.set(headIdx, txHash);
|
|
565
|
+
headIdx++;
|
|
566
|
+
}
|
|
567
|
+
this.#log.debug(`Archived ${txs.length} txs`, { txHashes });
|
|
568
|
+
this.#log.debug(`Total archived txs: ${headIdx - tailIdx}`);
|
|
569
|
+
});
|
|
570
|
+
} catch (error) {
|
|
571
|
+
this.#log.error(`Error archiving txs`, { error });
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Evicts pending txs with the lowest priority fees from the pool to accomodate the max tx count and cumulative max tx size
|
|
577
|
+
* after new txs are added.
|
|
578
|
+
*
|
|
579
|
+
* @param newTxHashes - The tx hashes of the new txs added to the pool.
|
|
580
|
+
* @returns The total number of txs evicted from the pool and the number of new txs that were evicted.
|
|
581
|
+
*/
|
|
582
|
+
private async evictLowPriorityTxs(
|
|
583
|
+
newTxHashes: TxHash[],
|
|
584
|
+
): Promise<{ numLowPriorityTxsEvicted: number; numNewTxsEvicted: number }> {
|
|
585
|
+
if (this.#maxTxPoolSize === undefined || this.#maxTxPoolSize === 0) {
|
|
586
|
+
return { numLowPriorityTxsEvicted: 0, numNewTxsEvicted: 0 };
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
let numNewTxsEvicted = 0;
|
|
590
|
+
const txsToEvict: TxHash[] = [];
|
|
591
|
+
|
|
592
|
+
let pendingTxsSize = (await this.#pendingTxSize.getAsync()) ?? 0;
|
|
593
|
+
if (pendingTxsSize > this.#maxTxPoolSize * this.txPoolOverflowFactor) {
|
|
594
|
+
for await (const txHash of this.#pendingTxPriorityToHash.valuesAsync()) {
|
|
595
|
+
if (this.#nonEvictableTxs.has(txHash.toString())) {
|
|
596
|
+
continue;
|
|
293
597
|
}
|
|
598
|
+
const txSize =
|
|
599
|
+
(await this.#pendingTxHashToSize.getAsync(txHash.toString())) ??
|
|
600
|
+
(await this.getPendingTxByHash(txHash))?.getSize();
|
|
294
601
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
602
|
+
this.#log.verbose(`Evicting tx ${txHash} from pool due to low priority to satisfy max tx size limit`, {
|
|
603
|
+
txHash,
|
|
604
|
+
txSize,
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
txsToEvict.push(TxHash.fromString(txHash));
|
|
608
|
+
|
|
609
|
+
if (txSize) {
|
|
610
|
+
pendingTxsSize -= txSize;
|
|
611
|
+
if (pendingTxsSize <= this.#maxTxPoolSize) {
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
numNewTxsEvicted += newTxHashes.filter(txHash => txsToEvict.includes(txHash)).length;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (txsToEvict.length > 0) {
|
|
620
|
+
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
numLowPriorityTxsEvicted: txsToEvict.length,
|
|
624
|
+
numNewTxsEvicted,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Evicts invalid pending txs from the pool after a txs from a block are mined.
|
|
630
|
+
* Eviction criteria includes:
|
|
631
|
+
* - txs with nullifiers that are already included in the mined block
|
|
632
|
+
* - txs with an insufficient fee payer balance
|
|
633
|
+
* - txs with an expiration timestamp lower than that of the mined block
|
|
634
|
+
*
|
|
635
|
+
* @param minedTxHashes - The tx hashes of the txs mined in the block.
|
|
636
|
+
* @param blockHeader - The header of the mined block.
|
|
637
|
+
* @returns The total number of txs evicted from the pool.
|
|
638
|
+
*/
|
|
639
|
+
private async evictInvalidTxsAfterMining(
|
|
640
|
+
minedTxHashes: TxHash[],
|
|
641
|
+
blockHeader: BlockHeader,
|
|
642
|
+
minedNullifiers: Set<string>,
|
|
643
|
+
minedFeePayers: Set<string>,
|
|
644
|
+
): Promise<number> {
|
|
645
|
+
if (minedTxHashes.length === 0) {
|
|
646
|
+
return 0;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const { blockNumber, timestamp } = blockHeader.globalVariables;
|
|
650
|
+
|
|
651
|
+
// Wait for world state to be synced to at least the mined block number
|
|
652
|
+
await this.#worldStateSynchronizer.syncImmediate(blockNumber);
|
|
653
|
+
|
|
654
|
+
const db = this.#worldStateSynchronizer.getCommitted();
|
|
655
|
+
const gasTxValidator = this.createGasTxValidator(db);
|
|
656
|
+
|
|
657
|
+
const txsToEvict: TxHash[] = [];
|
|
658
|
+
for await (const txHash of this.#pendingTxPriorityToHash.valuesAsync()) {
|
|
659
|
+
const tx = await this.getPendingTxByHash(txHash);
|
|
660
|
+
if (!tx) {
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// Evict pending txs that share nullifiers with mined txs
|
|
665
|
+
const txNullifiers = tx.data.getNonEmptyNullifiers();
|
|
666
|
+
if (txNullifiers.some(nullifier => minedNullifiers.has(nullifier.toString()))) {
|
|
667
|
+
this.#log.verbose(`Evicting tx ${txHash} from pool due to a duplicate nullifier with a mined tx`);
|
|
668
|
+
txsToEvict.push(TxHash.fromString(txHash));
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// Evict pending txs with an insufficient fee payer balance
|
|
673
|
+
if (
|
|
674
|
+
minedFeePayers.has(tx.data.feePayer.toString()) &&
|
|
675
|
+
(await gasTxValidator.validateTxFee(tx)).result === 'invalid'
|
|
676
|
+
) {
|
|
677
|
+
this.#log.verbose(`Evicting tx ${txHash} from pool due to an insufficient fee payer balance`);
|
|
678
|
+
txsToEvict.push(TxHash.fromString(txHash));
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Evict pending txs with an expiration timestamp less than or equal to the mined block timestamp
|
|
683
|
+
const includeByTimestamp = tx.data.includeByTimestamp;
|
|
684
|
+
if (includeByTimestamp <= timestamp) {
|
|
685
|
+
this.#log.verbose(
|
|
686
|
+
`Evicting tx ${txHash} from pool due to the tx being expired (includeByTimestamp: ${includeByTimestamp}, mined block timestamp: ${timestamp})`,
|
|
301
687
|
);
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
await this.#archivedTxIndices.set(headIdx, txHash);
|
|
305
|
-
headIdx++;
|
|
688
|
+
txsToEvict.push(TxHash.fromString(txHash));
|
|
689
|
+
continue;
|
|
306
690
|
}
|
|
307
|
-
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
if (txsToEvict.length > 0) {
|
|
694
|
+
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
695
|
+
}
|
|
696
|
+
return txsToEvict.length;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Evicts pending txs that no longer have valid archive roots or fee payer balances from the pool after a reorg.
|
|
701
|
+
*
|
|
702
|
+
* @param txHashes - The tx hashes of the txs that were moved from mined to pending.
|
|
703
|
+
* @returns The total number of txs evicted from the pool.
|
|
704
|
+
*/
|
|
705
|
+
private async evictInvalidTxsAfterReorg(txHashes: TxHash[]): Promise<number> {
|
|
706
|
+
if (txHashes.length === 0) {
|
|
707
|
+
return 0;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
await this.#worldStateSynchronizer.syncImmediate();
|
|
711
|
+
const db = this.#worldStateSynchronizer.getCommitted();
|
|
712
|
+
const archiveCache = this.createArchiveCache(db);
|
|
713
|
+
const gasTxValidator = this.createGasTxValidator(db);
|
|
714
|
+
|
|
715
|
+
const txsToEvict: TxHash[] = [];
|
|
716
|
+
|
|
717
|
+
for await (const [txHash, headerHash] of this.#pendingTxHashToHeaderHash.entriesAsync()) {
|
|
718
|
+
const tx = await this.getPendingTxByHash(txHash);
|
|
719
|
+
if (!tx) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const [index] = await archiveCache.getArchiveIndices([Fr.fromString(headerHash)]);
|
|
724
|
+
if (index === undefined) {
|
|
725
|
+
this.#log.verbose(`Evicting tx ${txHash} from pool due to an invalid archive root`);
|
|
726
|
+
txsToEvict.push(TxHash.fromString(txHash));
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if ((await gasTxValidator.validateTxFee(tx)).result === 'invalid') {
|
|
731
|
+
this.#log.verbose(`Evicting tx ${txHash} from pool due to an insufficient fee payer balance`);
|
|
732
|
+
txsToEvict.push(TxHash.fromString(txHash));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
if (txsToEvict.length > 0) {
|
|
737
|
+
await this.deleteTxs(txsToEvict, { eviction: true });
|
|
738
|
+
}
|
|
739
|
+
return txsToEvict.length;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
private async addPendingTxIndices(tx: Tx, txHash: string): Promise<void> {
|
|
743
|
+
await this.#pendingTxPriorityToHash.set(getPendingTxPriority(tx), txHash);
|
|
744
|
+
await this.#pendingTxHashToSize.set(txHash, tx.getSize());
|
|
745
|
+
await this.#pendingTxHashToHeaderHash.set(txHash, (await tx.data.constants.anchorBlockHeader.hash()).toString());
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
private async removePendingTxIndices(tx: Tx, txHash: string): Promise<void> {
|
|
749
|
+
await this.#pendingTxPriorityToHash.deleteValue(getPendingTxPriority(tx), txHash);
|
|
750
|
+
await this.#pendingTxHashToSize.delete(txHash);
|
|
751
|
+
await this.#pendingTxHashToHeaderHash.delete(txHash);
|
|
752
|
+
this.#pendingTxs.delete(txHash);
|
|
308
753
|
}
|
|
309
754
|
}
|