@aztec/p2p 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
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 +14 -4
- package/dest/client/factory.d.ts +3 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +9 -5
- package/dest/client/index.d.ts +1 -1
- package/dest/client/interface.d.ts +8 -6
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +12 -35
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +457 -61
- package/dest/config.d.ts +67 -61
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +28 -15
- package/dest/enr/generate-enr.d.ts +2 -2
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +1 -1
- 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 +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +43 -6
- 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 +72 -46
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +15 -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 +73 -18
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +13 -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 +69 -11
- package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +9 -7
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +9 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +38 -2
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +39 -58
- 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 +314 -317
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +56 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +5 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +76 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +28 -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 +155 -25
- 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 +32 -5
- 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 +5 -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 +44 -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 +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
- 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 +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- 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/double_spend_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +1 -1
- package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +11 -5
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +3 -6
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +6 -24
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +13 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.js +32 -0
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- 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/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 +3 -3
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +2 -2
- package/dest/services/dummy_service.d.ts +2 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/encoding.d.ts +25 -4
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +74 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +9 -2
- package/dest/services/libp2p/libp2p_service.d.ts +32 -72
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +796 -171
- package/dest/services/peer-manager/interface.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts +8 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +28 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -32
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +412 -21
- 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 +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/index.d.ts +1 -1
- package/dest/services/reqresp/interface.d.ts +2 -11
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +1 -18
- 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 +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +1 -1
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/ping.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +6 -5
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -3
- package/dest/services/reqresp/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts +1 -41
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +416 -34
- package/dest/services/reqresp/status.d.ts +2 -2
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/service.d.ts +2 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +1 -1
- package/dest/services/tx_collection/config.js +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +6 -1
- package/dest/services/tx_collection/index.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -7
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +2 -1
- package/dest/services/tx_collection/tx_collection.d.ts +12 -11
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +3 -2
- package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +34 -4
- package/dest/services/tx_collection/tx_source.d.ts +1 -1
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +2 -2
- package/dest/services/tx_provider.d.ts +6 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +19 -6
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +14 -1
- 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 +1 -1
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.js +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- 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 +3 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +4 -3
- package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +17 -9
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +2 -2
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/types/index.d.ts +1 -1
- package/dest/util.d.ts +2 -1
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +11 -2
- package/dest/versioning.d.ts +2 -2
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +2 -2
- package/package.json +21 -21
- package/src/bootstrap/bootstrap.ts +15 -4
- package/src/client/factory.ts +21 -12
- package/src/client/interface.ts +8 -5
- package/src/client/p2p_client.ts +97 -88
- package/src/config.ts +42 -21
- package/src/enr/generate-enr.ts +1 -1
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +46 -5
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +89 -48
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +107 -24
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +98 -19
- package/src/mem_pools/attestation_pool/mocks.ts +11 -8
- package/src/mem_pools/instrumentation.ts +46 -0
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +255 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +368 -360
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +91 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +28 -8
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +131 -18
- package/src/msg_validators/attestation_validator/attestation_validator.ts +41 -6
- 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 +53 -12
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
- package/src/msg_validators/tx_validator/double_spend_validator.ts +1 -1
- package/src/msg_validators/tx_validator/factory.ts +13 -6
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +8 -42
- package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +47 -0
- package/src/services/discv5/discV5_service.ts +2 -2
- package/src/services/dummy_service.ts +1 -1
- package/src/services/encoding.ts +81 -6
- package/src/services/libp2p/instrumentation.ts +10 -1
- package/src/services/libp2p/libp2p_service.ts +430 -165
- package/src/services/peer-manager/metrics.ts +32 -0
- package/src/services/peer-manager/peer_manager.ts +24 -14
- package/src/services/peer-manager/peer_scoring.ts +46 -3
- package/src/services/reqresp/interface.ts +1 -22
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +9 -8
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/reqresp/reqresp.ts +15 -11
- package/src/services/service.ts +1 -1
- package/src/services/tx_collection/config.ts +1 -1
- package/src/services/tx_collection/fast_tx_collection.ts +8 -5
- package/src/services/tx_collection/slow_tx_collection.ts +7 -6
- package/src/services/tx_collection/tx_collection.ts +12 -10
- package/src/services/tx_collection/tx_collection_sink.ts +34 -3
- package/src/services/tx_collection/tx_source.ts +2 -2
- package/src/services/tx_provider.ts +26 -9
- package/src/services/tx_provider_instrumentation.ts +19 -2
- package/src/test-helpers/make-enrs.ts +1 -1
- package/src/test-helpers/mock-pubsub.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +4 -3
- package/src/testbench/p2p_client_testbench_worker.ts +14 -6
- package/src/testbench/testbench.ts +2 -2
- package/src/util.ts +12 -2
- package/src/versioning.ts +3 -3
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -68
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -160
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -199
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
3
4
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
5
|
|
|
5
6
|
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
6
7
|
import type { AttestationPool } from './attestation_pool.js';
|
|
8
|
+
import { ATTESTATION_CAP_BUFFER, MAX_PROPOSALS_PER_SLOT } from './kv_attestation_pool.js';
|
|
7
9
|
|
|
8
10
|
export class InMemoryAttestationPool implements AttestationPool {
|
|
9
11
|
private metrics: PoolInstrumentation<BlockAttestation>;
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
14
|
+
private attestations: Map<
|
|
15
|
+
/*slot=*/ SlotNumber,
|
|
16
|
+
Map</*proposalId*/ string, Map</*address=*/ string, BlockAttestation>>
|
|
17
|
+
>;
|
|
12
18
|
private proposals: Map<string, BlockProposal>;
|
|
13
19
|
|
|
14
20
|
constructor(
|
|
@@ -30,7 +36,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
30
36
|
return Promise.resolve(this.attestations.size === 0);
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
public getAttestationsForSlot(slot:
|
|
39
|
+
public getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]> {
|
|
34
40
|
return Promise.resolve(
|
|
35
41
|
Array.from(this.attestations.get(slot)?.values() ?? []).flatMap(proposalAttestationMap =>
|
|
36
42
|
Array.from(proposalAttestationMap.values()),
|
|
@@ -38,7 +44,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
38
44
|
);
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
public getAttestationsForSlotAndProposal(slot:
|
|
47
|
+
public getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]> {
|
|
42
48
|
const slotAttestationMap = this.attestations.get(slot);
|
|
43
49
|
if (slotAttestationMap) {
|
|
44
50
|
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
@@ -55,16 +61,26 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
55
61
|
const slotNumber = attestation.payload.header.slotNumber;
|
|
56
62
|
|
|
57
63
|
const proposalId = attestation.archive.toString();
|
|
58
|
-
const
|
|
64
|
+
const sender = attestation.getSender();
|
|
59
65
|
|
|
60
|
-
|
|
66
|
+
// Skip attestations with invalid signatures
|
|
67
|
+
if (!sender) {
|
|
68
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber}`, {
|
|
69
|
+
signature: attestation.signature.toString(),
|
|
70
|
+
slotNumber,
|
|
71
|
+
proposalId,
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber);
|
|
61
77
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
62
|
-
proposalAttestationMap.set(
|
|
78
|
+
proposalAttestationMap.set(sender.toString(), attestation);
|
|
63
79
|
|
|
64
|
-
this.log.verbose(`Added attestation for slot ${slotNumber
|
|
80
|
+
this.log.verbose(`Added attestation for slot ${slotNumber} from ${sender}`, {
|
|
65
81
|
signature: attestation.signature.toString(),
|
|
66
82
|
slotNumber,
|
|
67
|
-
address,
|
|
83
|
+
address: sender,
|
|
68
84
|
proposalId,
|
|
69
85
|
});
|
|
70
86
|
}
|
|
@@ -72,7 +88,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
72
88
|
return Promise.resolve();
|
|
73
89
|
}
|
|
74
90
|
|
|
75
|
-
#getNumberOfAttestationsInSlot(slot:
|
|
91
|
+
#getNumberOfAttestationsInSlot(slot: SlotNumber): number {
|
|
76
92
|
let total = 0;
|
|
77
93
|
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
78
94
|
|
|
@@ -84,7 +100,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
84
100
|
return total;
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
public async deleteAttestationsOlderThan(oldestSlot:
|
|
103
|
+
public async deleteAttestationsOlderThan(oldestSlot: SlotNumber): Promise<void> {
|
|
88
104
|
const olderThan = [];
|
|
89
105
|
|
|
90
106
|
// Entries are iterated in insertion order, so we can break as soon as we find a slot that is older than the oldestSlot.
|
|
@@ -105,7 +121,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
105
121
|
return Promise.resolve();
|
|
106
122
|
}
|
|
107
123
|
|
|
108
|
-
public deleteAttestationsForSlot(slot:
|
|
124
|
+
public deleteAttestationsForSlot(slot: SlotNumber): Promise<void> {
|
|
109
125
|
// We count the number of attestations we are removing
|
|
110
126
|
const numberOfAttestations = this.#getNumberOfAttestationsInSlot(slot);
|
|
111
127
|
const proposalIdsToDelete = this.attestations.get(slot)?.keys();
|
|
@@ -123,7 +139,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
123
139
|
return Promise.resolve();
|
|
124
140
|
}
|
|
125
141
|
|
|
126
|
-
public deleteAttestationsForSlotAndProposal(slot:
|
|
142
|
+
public deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void> {
|
|
127
143
|
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
128
144
|
if (slotAttestationMap) {
|
|
129
145
|
if (slotAttestationMap.has(proposalId)) {
|
|
@@ -142,24 +158,54 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
142
158
|
public deleteAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
143
159
|
for (const attestation of attestations) {
|
|
144
160
|
const slotNumber = attestation.payload.header.slotNumber;
|
|
145
|
-
const slotAttestationMap = this.attestations.get(slotNumber
|
|
161
|
+
const slotAttestationMap = this.attestations.get(slotNumber);
|
|
146
162
|
if (slotAttestationMap) {
|
|
147
163
|
const proposalId = attestation.archive.toString();
|
|
148
164
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
149
165
|
if (proposalAttestationMap) {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
const sender = attestation.getSender();
|
|
167
|
+
|
|
168
|
+
// Skip attestations with invalid signatures
|
|
169
|
+
if (!sender) {
|
|
170
|
+
this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber}`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
proposalAttestationMap.delete(sender.toString());
|
|
175
|
+
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${sender}`);
|
|
153
176
|
}
|
|
154
177
|
}
|
|
155
178
|
}
|
|
156
179
|
return Promise.resolve();
|
|
157
180
|
}
|
|
158
181
|
|
|
182
|
+
public hasAttestation(attestation: BlockAttestation): Promise<boolean> {
|
|
183
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
184
|
+
const proposalId = attestation.archive.toString();
|
|
185
|
+
const sender = attestation.getSender();
|
|
186
|
+
|
|
187
|
+
// Attestations with invalid signatures are never in the pool
|
|
188
|
+
if (!sender) {
|
|
189
|
+
return Promise.resolve(false);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const slotAttestationMap = this.attestations.get(slotNumber);
|
|
193
|
+
if (!slotAttestationMap) {
|
|
194
|
+
return Promise.resolve(false);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
198
|
+
if (!proposalAttestationMap) {
|
|
199
|
+
return Promise.resolve(false);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return Promise.resolve(proposalAttestationMap.has(sender.toString()));
|
|
203
|
+
}
|
|
204
|
+
|
|
159
205
|
public addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
160
206
|
// We initialize slot-proposal mapping if it does not exist
|
|
161
207
|
// This is important to ensure we can delete this proposal if there were not attestations for it
|
|
162
|
-
const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber
|
|
208
|
+
const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber);
|
|
163
209
|
slotProposalMapping.set(blockProposal.payload.archive.toString(), new Map<string, BlockAttestation>());
|
|
164
210
|
|
|
165
211
|
this.proposals.set(blockProposal.payload.archive.toString(), blockProposal);
|
|
@@ -169,6 +215,38 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
169
215
|
public getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
170
216
|
return Promise.resolve(this.proposals.get(id));
|
|
171
217
|
}
|
|
218
|
+
|
|
219
|
+
public hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
220
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
|
|
221
|
+
return Promise.resolve(this.proposals.has(id));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public hasReachedProposalCap(slot: SlotNumber): Promise<boolean> {
|
|
225
|
+
const slotAttestationMap = this.attestations.get(slot);
|
|
226
|
+
const proposalCount = slotAttestationMap?.size ?? 0;
|
|
227
|
+
return Promise.resolve(proposalCount >= MAX_PROPOSALS_PER_SLOT);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public hasReachedAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean> {
|
|
231
|
+
const limit = committeeSize + ATTESTATION_CAP_BUFFER;
|
|
232
|
+
const count = this.attestations.get(slot)?.get(proposalId)?.size ?? 0;
|
|
233
|
+
return Promise.resolve(limit <= 0 || count >= limit);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public async canAddProposal(block: BlockProposal): Promise<boolean> {
|
|
237
|
+
return this.proposals.has(block.archive.toString()) || !(await this.hasReachedProposalCap(block.slotNumber));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public async canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean> {
|
|
241
|
+
const sender = attestation.getSender();
|
|
242
|
+
const slot = attestation.payload.header.slotNumber;
|
|
243
|
+
const pid = attestation.archive.toString();
|
|
244
|
+
return (
|
|
245
|
+
!!sender &&
|
|
246
|
+
((this.attestations.get(slot)?.get(pid)?.has(sender.toString()) ?? false) ||
|
|
247
|
+
!(await this.hasReachedAttestationCap(slot, pid, committeeSize)))
|
|
248
|
+
);
|
|
249
|
+
}
|
|
172
250
|
}
|
|
173
251
|
|
|
174
252
|
/**
|
|
@@ -180,8 +258,9 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
180
258
|
* @returns The slot mapping
|
|
181
259
|
*/
|
|
182
260
|
function getSlotOrDefault(
|
|
183
|
-
|
|
184
|
-
|
|
261
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
262
|
+
map: Map<SlotNumber, Map<string, Map<string, BlockAttestation>>>,
|
|
263
|
+
slot: SlotNumber,
|
|
185
264
|
): Map<string, Map<string, BlockAttestation>> {
|
|
186
265
|
if (!map.has(slot)) {
|
|
187
266
|
map.set(slot, new Map<string, Map<string, BlockAttestation>>());
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import {
|
|
4
4
|
BlockAttestation,
|
|
5
5
|
ConsensusPayload,
|
|
6
6
|
SignatureDomainSeparator,
|
|
7
7
|
getHashedSignaturePayloadEthSignedMessage,
|
|
8
8
|
} from '@aztec/stdlib/p2p';
|
|
9
|
-
import {
|
|
9
|
+
import { makeL2BlockHeader } from '@aztec/stdlib/testing';
|
|
10
10
|
|
|
11
11
|
import { type LocalAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
12
12
|
|
|
@@ -32,11 +32,14 @@ export const mockAttestation = (
|
|
|
32
32
|
archive: Fr = Fr.random(),
|
|
33
33
|
): BlockAttestation => {
|
|
34
34
|
// Use arbitrary numbers for all other than slot
|
|
35
|
-
const header =
|
|
36
|
-
const payload = new ConsensusPayload(header.
|
|
35
|
+
const header = makeL2BlockHeader(1, 2, slot);
|
|
36
|
+
const payload = new ConsensusPayload(header.toCheckpointHeader(), archive);
|
|
37
37
|
|
|
38
|
-
const
|
|
39
|
-
const
|
|
38
|
+
const attestationHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
|
|
39
|
+
const attestationSignature = signer.sign(attestationHash);
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
|
|
42
|
+
const proposerSignature = signer.sign(proposalHash);
|
|
43
|
+
|
|
44
|
+
return new BlockAttestation(payload, attestationSignature, proposerSignature);
|
|
42
45
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Gossipable } from '@aztec/stdlib/p2p';
|
|
2
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
2
3
|
import {
|
|
3
4
|
Attributes,
|
|
4
5
|
type BatchObservableResult,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
type MetricsType,
|
|
11
12
|
type ObservableGauge,
|
|
12
13
|
type TelemetryClient,
|
|
14
|
+
type UpDownCounter,
|
|
13
15
|
} from '@aztec/telemetry-client';
|
|
14
16
|
|
|
15
17
|
export enum PoolName {
|
|
@@ -20,6 +22,8 @@ export enum PoolName {
|
|
|
20
22
|
type MetricsLabels = {
|
|
21
23
|
objectInMempool: MetricsType;
|
|
22
24
|
objectSize: MetricsType;
|
|
25
|
+
itemsAdded: MetricsType;
|
|
26
|
+
itemMinedDelay: MetricsType;
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -32,11 +36,15 @@ function getMetricsLabels(name: PoolName): MetricsLabels {
|
|
|
32
36
|
return {
|
|
33
37
|
objectInMempool: Metrics.MEMPOOL_TX_COUNT,
|
|
34
38
|
objectSize: Metrics.MEMPOOL_TX_SIZE,
|
|
39
|
+
itemsAdded: Metrics.MEMPOOL_TX_ADDED_COUNT,
|
|
40
|
+
itemMinedDelay: Metrics.MEMPOOL_TX_MINED_DELAY,
|
|
35
41
|
};
|
|
36
42
|
} else if (name === PoolName.ATTESTATION_POOL) {
|
|
37
43
|
return {
|
|
38
44
|
objectInMempool: Metrics.MEMPOOL_ATTESTATIONS_COUNT,
|
|
39
45
|
objectSize: Metrics.MEMPOOL_ATTESTATIONS_SIZE,
|
|
46
|
+
itemsAdded: Metrics.MEMPOOL_ATTESTATIONS_ADDED_COUNT,
|
|
47
|
+
itemMinedDelay: Metrics.MEMPOOL_ATTESTATIONS_MINED_DELAY,
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
|
|
@@ -53,14 +61,19 @@ export type PoolStatsCallback = () => Promise<{
|
|
|
53
61
|
export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
54
62
|
/** The number of txs in the mempool */
|
|
55
63
|
private objectsInMempool: ObservableGauge;
|
|
64
|
+
private addObjectCounter: UpDownCounter;
|
|
56
65
|
/** Tracks tx size */
|
|
57
66
|
private objectSize: Histogram;
|
|
67
|
+
/** Track delay between transaction added and evicted */
|
|
68
|
+
private minedDelay: Histogram;
|
|
58
69
|
|
|
59
70
|
private dbMetrics: LmdbMetrics;
|
|
60
71
|
|
|
61
72
|
private defaultAttributes;
|
|
62
73
|
private meter: Meter;
|
|
63
74
|
|
|
75
|
+
private txAddedTimestamp: Map<bigint, number> = new Map<bigint, number>();
|
|
76
|
+
|
|
64
77
|
constructor(
|
|
65
78
|
telemetry: TelemetryClient,
|
|
66
79
|
name: PoolName,
|
|
@@ -89,6 +102,14 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
89
102
|
dbStats,
|
|
90
103
|
);
|
|
91
104
|
|
|
105
|
+
this.addObjectCounter = this.meter.createUpDownCounter(metricsLabels.itemsAdded, {
|
|
106
|
+
description: 'The number of transactions added to the mempool',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
this.minedDelay = this.meter.createHistogram(metricsLabels.itemMinedDelay, {
|
|
110
|
+
description: 'Delay between transaction added and evicted from the mempool',
|
|
111
|
+
});
|
|
112
|
+
|
|
92
113
|
this.meter.addBatchObservableCallback(this.observeStats, [this.objectsInMempool]);
|
|
93
114
|
}
|
|
94
115
|
|
|
@@ -96,6 +117,31 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
96
117
|
this.objectSize.record(poolObject.getSize());
|
|
97
118
|
}
|
|
98
119
|
|
|
120
|
+
public incrementAddedObjects(count: number) {
|
|
121
|
+
this.addObjectCounter.add(count);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public transactionsAdded(transactions: Tx[]) {
|
|
125
|
+
const timestamp = Date.now();
|
|
126
|
+
for (const transaction of transactions) {
|
|
127
|
+
this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
|
|
132
|
+
const timestamp = Date.now();
|
|
133
|
+
for (const hash of hashes) {
|
|
134
|
+
const key = BigInt(hash);
|
|
135
|
+
const addedAt = this.txAddedTimestamp.get(key);
|
|
136
|
+
if (addedAt !== undefined) {
|
|
137
|
+
this.txAddedTimestamp.delete(key);
|
|
138
|
+
if (addedAt < timestamp) {
|
|
139
|
+
this.minedDelay.record(timestamp - addedAt);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
99
145
|
private observeStats = async (observer: BatchObservableResult) => {
|
|
100
146
|
const { itemCount } = await this.poolStats();
|
|
101
147
|
if (typeof itemCount === 'number') {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
2
|
-
|
|
3
1
|
import type { AttestationPool } from './attestation_pool/attestation_pool.js';
|
|
4
2
|
import type { TxPool } from './tx_pool/tx_pool.js';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* A interface the combines all mempools
|
|
8
6
|
*/
|
|
9
|
-
export type MemPools
|
|
7
|
+
export type MemPools = {
|
|
10
8
|
txPool: TxPool;
|
|
11
|
-
attestationPool
|
|
9
|
+
attestationPool: AttestationPool;
|
|
12
10
|
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Transaction Pool (Mempool)
|
|
2
|
+
|
|
3
|
+
This module implements the transaction pool (mempool) for the Aztec P2P network. The mempool holds unconfirmed transactions awaiting inclusion in a block.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The transaction pool serves as a staging area for transactions before they are included in blocks. It manages the lifecycle of transactions from initial submission through mining, handling duplicates, priority ordering, and eviction of invalid or low-priority transactions.
|
|
8
|
+
|
|
9
|
+
## Interface: `TxPool`
|
|
10
|
+
|
|
11
|
+
The [`TxPool`](tx_pool.ts) interface defines the contract that all transaction pool implementations must fulfill:
|
|
12
|
+
|
|
13
|
+
### Transaction Lifecycle
|
|
14
|
+
|
|
15
|
+
The lifecycle of transactions in the pool is summarised in the following table:
|
|
16
|
+
|
|
17
|
+
| State | Meaning | Possible Future States |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| Pending | Available to be added to a block, can be evicted | Protected, Mined, Soft Deleted |
|
|
20
|
+
| Protected | Added to a proposal, must not be evicted | Mined, Pending |
|
|
21
|
+
| Mined | Confirmed as added to a block | Soft Deleted, Pending |
|
|
22
|
+
| Soft Deleted | Awaiting full deletion once state has been finalised on L1 | Pending, Deleted |
|
|
23
|
+
| Deleted | Removed from the pool | N/A |
|
|
24
|
+
|
|
25
|
+
**Note on why Soft Delete:**
|
|
26
|
+
Mined transactions are soft-deleted rather than permanently removed to support:
|
|
27
|
+
1. Reorg handling — If a chain reorganization occurs, soft-deleted transactions are still available in the mempool
|
|
28
|
+
2. Slash condition detection — The epoch prune watcher needs access to transactions from pruned epochs to correctly identify data withholding slash conditions. Without soft-delete, transactions invalidated by reorgs (e.g., built on removed blocks) would be lost, causing false positives for data withholding violations.
|
|
29
|
+
|
|
30
|
+
Mined transactions are permanently deleted via `cleanupDeletedMinedTxs()` once their original block is finalized on L1, ensuring theyremain available during the uncertainty window.
|
|
31
|
+
Alternatively, mined transactions can be permanently deleted immediately by passing the `permanent: true` option to `deleteTxs()`.
|
|
32
|
+
|
|
33
|
+
#### Transaction Lifecycle Methods
|
|
34
|
+
|
|
35
|
+
| Method | Description |
|
|
36
|
+
|--------|-------------|
|
|
37
|
+
| `addTxs(txs, opts?)` | Adds transactions to the pool. Duplicates are ignored. Returns count of newly added txs. |
|
|
38
|
+
| `deleteTxs(txHashes, opts?)` | Removes transactions from the pool. Supports soft-delete for mined txs. |
|
|
39
|
+
| `markAsMined(txHashes, blockHeader)` | Marks transactions as included in a block. |
|
|
40
|
+
| `markMinedAsPending(txHashes, blockNumber)` | Reverts mined transactions to pending (used during reorgs). |
|
|
41
|
+
| `getArchivedTxByHash(txHash)` | Retrieves archived (historical) transactions. |
|
|
42
|
+
| `getTxStatus(txHash)` | Returns status: `'pending'`, `'mined'`, `'deleted'`, or `undefined`. |
|
|
43
|
+
|
|
44
|
+
### Transaction Fetching
|
|
45
|
+
|
|
46
|
+
| Method | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `hasTx(txHash)` / `hasTxs(txHashes)` | Checks if transaction(s) exist in the pool. |
|
|
49
|
+
| `getTxByHash(txHash)` | Retrieves a transaction by its hash. |
|
|
50
|
+
| `getTxsByHash(txHashes)` | Batch retrieval of transactions by hash. |
|
|
51
|
+
| `getAllTxs()` / `getAllTxHashes()` | Returns all transactions or their hashes. |
|
|
52
|
+
| `getPendingTxHashes()` | Returns pending tx hashes **sorted by priority** (highest first). |
|
|
53
|
+
| `getPendingTxCount()` | Returns count of pending transactions. |
|
|
54
|
+
| `getMinedTxHashes()` | Returns mined tx hashes with their block numbers. |
|
|
55
|
+
|
|
56
|
+
### Pool Management
|
|
57
|
+
|
|
58
|
+
| Method | Description |
|
|
59
|
+
|--------|-------------|
|
|
60
|
+
| `updateConfig(config)` | Updates pool configuration (max size, archive limit). |
|
|
61
|
+
| `markTxsAsNonEvictable(txHashes)` | Protects transactions from eviction. |
|
|
62
|
+
| `clearNonEvictableTxs()` | Clears non-evictable flag from all transactions. |
|
|
63
|
+
| `cleanupDeletedMinedTxs(blockNumber)` | Permanently removes soft-deleted txs from blocks ≤ blockNumber. |
|
|
64
|
+
| `isEmpty()` | Checks if the pool has no transactions. |
|
|
65
|
+
|
|
66
|
+
### Events
|
|
67
|
+
|
|
68
|
+
The pool emits a `txs-added` event when new transactions are successfully added, allowing subscribers to react to pool changes.
|
|
69
|
+
|
|
70
|
+
## `AztecKVTxPool`
|
|
71
|
+
|
|
72
|
+
The [`AztecKVTxPool`](aztec_kv_tx_pool.ts) is the production-grade implementation backed by a persistent key-value store. It provides:
|
|
73
|
+
|
|
74
|
+
- **Persistent storage** via `AztecAsyncKVStore`
|
|
75
|
+
- **Multiple indexes** for efficient queries
|
|
76
|
+
- **Automatic eviction** of invalid and low-priority transactions
|
|
77
|
+
- **Transaction archival** for historical lookups
|
|
78
|
+
- **Soft-delete semantics** for mined transactions
|
|
79
|
+
|
|
80
|
+
#### Storage Structure
|
|
81
|
+
|
|
82
|
+
The pool maintains several KV maps and indexes:
|
|
83
|
+
|
|
84
|
+
| Store | Purpose |
|
|
85
|
+
|-------|---------|
|
|
86
|
+
| `#txs` | Primary storage: tx hash → serialized tx buffer |
|
|
87
|
+
| `#minedTxHashToBlock` | Index of mined txs: tx hash → block number |
|
|
88
|
+
| `#pendingTxPriorityToHash` | Priority-ordered index of pending txs |
|
|
89
|
+
| `#deletedMinedTxHashes` | Soft-deleted mined txs: tx hash → original block number |
|
|
90
|
+
| `#blockToDeletedMinedTxHash` | Reverse index for cleanup: block → deleted tx hashes |
|
|
91
|
+
| `#txHashToHistoricalBlockHeaderHash` | Anchor block reference for each tx |
|
|
92
|
+
| `#historicalHeaderToTxHash` | Index from historical block → tx hashes |
|
|
93
|
+
| `#feePayerToTxHash` | Index from fee payer address → tx hashes |
|
|
94
|
+
| `#archivedTxs` | Archived transactions for historical lookup |
|
|
95
|
+
|
|
96
|
+
#### In-Memory Caches
|
|
97
|
+
|
|
98
|
+
| Cache | Purpose |
|
|
99
|
+
|-------|---------|
|
|
100
|
+
| `#pendingTxs` | Hydrated pending transactions for fast access |
|
|
101
|
+
| `#nonEvictableTxs` | Set of tx hashes protected from eviction |
|
|
102
|
+
|
|
103
|
+
## Transaction Priority
|
|
104
|
+
|
|
105
|
+
Transactions are prioritized based on their **total priority fees** (see [`priority.ts`](priority.ts)):
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
priorityFee = maxPriorityFeesPerGas.feePerDaGas + maxPriorityFeesPerGas.feePerL2Gas
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The priority is stored as a hex string derived from a 32-byte buffer representation of the fee amount, enabling lexicographic ordering in the KV store. Pending transactions are returned in **descending priority order** (highest fees first).
|
|
112
|
+
|
|
113
|
+
## Transaction Lifecycle in AztecKVTxPool
|
|
114
|
+
|
|
115
|
+
### 1. Adding Transactions
|
|
116
|
+
|
|
117
|
+
When `addTxs()` is called:
|
|
118
|
+
|
|
119
|
+
1. Check for duplicates (skip if tx already exists)
|
|
120
|
+
2. Store the serialized tx in `#txs`
|
|
121
|
+
3. Index the tx by its anchor block hash
|
|
122
|
+
4. If not already mined, add to pending indexes:
|
|
123
|
+
- Priority-to-hash index (for ordering)
|
|
124
|
+
- Historical header index (for reorg handling)
|
|
125
|
+
- Fee payer index (for balance validation)
|
|
126
|
+
5. Record metrics
|
|
127
|
+
6. Trigger eviction rules for `TXS_ADDED` event
|
|
128
|
+
7. Emit `txs-added` event
|
|
129
|
+
|
|
130
|
+
### 2. Marking as Mined
|
|
131
|
+
|
|
132
|
+
When a block is finalized, `markAsMined()`:
|
|
133
|
+
|
|
134
|
+
1. Move tx from pending to mined status
|
|
135
|
+
2. If previously soft-deleted, restore to mined status
|
|
136
|
+
3. Trigger eviction rules for `BLOCK_MINED` event
|
|
137
|
+
|
|
138
|
+
### 3. Handling Reorgs
|
|
139
|
+
|
|
140
|
+
When blocks are pruned, `markMinedAsPending()`:
|
|
141
|
+
|
|
142
|
+
1. Remove tx from mined index
|
|
143
|
+
2. Rehydrate pending indexes
|
|
144
|
+
3. Trigger eviction rules for `CHAIN_PRUNED` event
|
|
145
|
+
|
|
146
|
+
### 4. Deleting Transactions
|
|
147
|
+
|
|
148
|
+
The `deleteTxs()` method handles two cases:
|
|
149
|
+
|
|
150
|
+
- **Pending transactions**: Permanently deleted (transactions and all indexes to the transaction)
|
|
151
|
+
- **Mined transactions**: Soft-deleted by default (moved to `#deletedMinedTxHashes`), with option for permanent deletion
|
|
152
|
+
|
|
153
|
+
Soft-deleted mined transactions are retained for potential future reference and can be permanently cleaned up later via `cleanupDeletedMinedTxs()`.
|
|
154
|
+
|
|
155
|
+
## Eviction System
|
|
156
|
+
|
|
157
|
+
The eviction system automatically removes invalid or low-priority transactions based on configurable rules. See the [`eviction/`](eviction/) subdirectory for implementation details.
|
|
158
|
+
|
|
159
|
+
### Architecture
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
163
|
+
│ EvictionManager │
|
|
164
|
+
│ Orchestrates eviction rules based on pool events │
|
|
165
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
166
|
+
│ │
|
|
167
|
+
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
|
|
168
|
+
│ │EvictionRule #1 │ │EvictionRule #2 │ │EvictionRule #N │ │
|
|
169
|
+
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
|
|
170
|
+
│ │
|
|
171
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
172
|
+
│
|
|
173
|
+
▼
|
|
174
|
+
┌─────────────────┐
|
|
175
|
+
│ TxPoolOperations│
|
|
176
|
+
│ (interface) │
|
|
177
|
+
└─────────────────┘
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
The [`EvictionManager`](eviction/eviction_manager.ts) coordinates eviction by:
|
|
181
|
+
|
|
182
|
+
1. Registering multiple `EvictionRule` implementations
|
|
183
|
+
2. Calling each rule when tx pool events occur
|
|
184
|
+
3. Propagating configuration updates to all rules
|
|
185
|
+
|
|
186
|
+
### Eviction Events
|
|
187
|
+
|
|
188
|
+
| Event | Trigger | Purpose |
|
|
189
|
+
|-------|---------|---------|
|
|
190
|
+
| `TXS_ADDED` | New transactions added | Enforce pool size limits |
|
|
191
|
+
| `BLOCK_MINED` | Block finalized | Remove invalidated transactions |
|
|
192
|
+
| `CHAIN_PRUNED` | Chain reorganization | Remove txs referencing pruned blocks |
|
|
193
|
+
|
|
194
|
+
### Eviction Rules
|
|
195
|
+
|
|
196
|
+
#### 1. `InvalidTxsAfterMiningRule`
|
|
197
|
+
|
|
198
|
+
**Triggers on:** `BLOCK_MINED`
|
|
199
|
+
|
|
200
|
+
Evicts transactions that become invalid after a block is mined:
|
|
201
|
+
|
|
202
|
+
- Duplicate nullifiers: Txs with nullifiers already included in the mined block
|
|
203
|
+
- Expired transactions: Txs with `includeByTimestamp` ≤ mined block timestamp
|
|
204
|
+
|
|
205
|
+
#### 2. `InvalidTxsAfterReorgRule`
|
|
206
|
+
|
|
207
|
+
**Triggers on:** `CHAIN_PRUNED`
|
|
208
|
+
|
|
209
|
+
Evicts transactions that reference blocks no longer in the canonical chain:
|
|
210
|
+
|
|
211
|
+
- Checks each pending tx's anchor block hash against the archive tree
|
|
212
|
+
- Removes txs whose anchor blocks are not found (pruned)
|
|
213
|
+
|
|
214
|
+
#### 3. `InsufficientFeePayerBalanceRule`
|
|
215
|
+
|
|
216
|
+
**Triggers on:** `BLOCK_MINED`, `CHAIN_PRUNED`
|
|
217
|
+
|
|
218
|
+
Evicts transactions whose fee payer no longer has sufficient balance:
|
|
219
|
+
|
|
220
|
+
- Uses `GasTxValidator` to check fee payer balances against current world state
|
|
221
|
+
|
|
222
|
+
#### 4. `LowPriorityEvictionRule`
|
|
223
|
+
|
|
224
|
+
**Triggers on:** `TXS_ADDED`
|
|
225
|
+
|
|
226
|
+
Enforces maximum pool size by evicting lowest-priority (by fee) transactions:
|
|
227
|
+
|
|
228
|
+
- Configured via `maxPendingTxCount` option (0 = disabled)
|
|
229
|
+
- Uses `getLowestPriorityEvictable()` to find txs to evict
|
|
230
|
+
|
|
231
|
+
### Non-Evictable Transactions
|
|
232
|
+
|
|
233
|
+
Transactions can be marked as non-evictable via `markTxsAsNonEvictable()`. This protects them from all eviction rules, typically used during block building to ensure transactions being processed aren't evicted mid-operation. The flag is cleared after block processing via `clearNonEvictableTxs()`.
|
|
234
|
+
The `clearNonEvictableTxs` is called upon getting new L2 block.
|
|
235
|
+
|
|
236
|
+
## Configuration
|
|
237
|
+
|
|
238
|
+
The pool accepts configuration via `TxPoolOptions`:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
type TxPoolOptions = {
|
|
242
|
+
maxPendingTxCount?: number; // Max pending txs (0 = unlimited)
|
|
243
|
+
archivedTxLimit?: number; // Number of archived txs to retain
|
|
244
|
+
};
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Configuration can be updated at runtime via `updateConfig()`.
|
|
248
|
+
|
|
249
|
+
## Telemetry
|
|
250
|
+
|
|
251
|
+
The pool integrates with the telemetry system to report:
|
|
252
|
+
|
|
253
|
+
- Transaction counts (pending vs mined)
|
|
254
|
+
- Transaction sizes
|
|
255
|
+
- Store size estimates
|