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