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