@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.0208eb9
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 +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +26 -13
- package/dest/client/factory.d.ts +15 -5
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +63 -25
- package/dest/client/index.d.ts +2 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +170 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +77 -193
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +769 -229
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +160 -125
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +184 -34
- package/dest/enr/generate-enr.d.ts +11 -3
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +4 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +104 -25
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +299 -174
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +29 -11
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +168 -62
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +24 -10
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +133 -82
- package/dest/mem_pools/attestation_pool/mocks.d.ts +234 -11
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +19 -21
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +16 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +56 -41
- 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 +75 -16
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +493 -142
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -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 +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -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 +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -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 +78 -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/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +7 -2
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +72 -11
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +276 -45
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +7 -5
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +79 -10
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +76 -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/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -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 +5 -4
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +7 -6
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +60 -87
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +3 -4
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +24 -29
- package/dest/msg_validators/tx_validator/factory.d.ts +21 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +84 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +12 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +110 -0
- package/dest/msg_validators/tx_validator/index.d.ts +9 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +8 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +10 -5
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +40 -21
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +15 -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/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -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 +14 -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 +9 -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 +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +8 -7
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +10 -6
- 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 +64 -37
- package/dest/services/dummy_service.d.ts +66 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +130 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +75 -6
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +6 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +5 -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 +122 -0
- package/dest/services/libp2p/libp2p_service.d.ts +107 -95
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +1328 -313
- 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 +12 -3
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +44 -12
- package/dest/services/peer-manager/peer_manager.d.ts +103 -23
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +551 -82
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +43 -2
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +47 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +566 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +50 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +37 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +151 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- 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 +23 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +73 -10
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +32 -17
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +154 -84
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- 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 +75 -24
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +46 -27
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -21
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +6 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +30 -6
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +34 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +87 -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 +52 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +59 -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 +105 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +3 -1
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +1 -3
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +40 -7
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +76 -5
- package/dest/services/reqresp/protocols/tx.d.ts +14 -4
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +29 -66
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +753 -248
- 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 +40 -20
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +28 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +66 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +311 -0
- package/dest/services/tx_collection/index.d.ts +4 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +3 -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 +31 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +48 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +177 -0
- package/dest/services/tx_collection/tx_collection.d.ts +110 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +128 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +111 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_file_store/config.d.ts +18 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +26 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +149 -0
- package/dest/services/tx_provider.d.ts +51 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +219 -0
- package/dest/services/tx_provider_instrumentation.d.ts +16 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +4 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +3 -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/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +158 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +297 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +259 -90
- 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 +51 -11
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +232 -53
- 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 +34 -15
- package/src/client/factory.ts +139 -53
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +213 -0
- package/src/client/p2p_client.ts +481 -383
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +336 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +311 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +119 -24
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +352 -201
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +233 -72
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +199 -96
- package/src/mem_pools/attestation_pool/mocks.ts +24 -17
- package/src/mem_pools/instrumentation.ts +72 -48
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +580 -143
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -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 +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +9 -2
- package/src/mem_pools/tx_pool/tx_pool.ts +75 -10
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +225 -36
- package/src/msg_validators/attestation_validator/attestation_validator.ts +72 -14
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +94 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -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 +10 -9
- package/src/msg_validators/tx_validator/data_validator.ts +95 -71
- package/src/msg_validators/tx_validator/double_spend_validator.ts +23 -20
- package/src/msg_validators/tx_validator/factory.ts +151 -0
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +123 -0
- package/src/msg_validators/tx_validator/index.ts +8 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +72 -24
- package/src/msg_validators/tx_validator/phases_validator.ts +118 -0
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +52 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +22 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +14 -8
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +85 -39
- package/src/services/dummy_service.ts +198 -9
- package/src/services/encoding.ts +82 -6
- package/src/services/index.ts +5 -0
- package/src/services/libp2p/instrumentation.ts +126 -0
- package/src/services/libp2p/libp2p_service.ts +1170 -353
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +55 -12
- package/src/services/peer-manager/peer_manager.ts +657 -80
- package/src/services/peer-manager/peer_scoring.ts +45 -3
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +57 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +209 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +77 -10
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +166 -95
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +95 -37
- package/src/services/reqresp/metrics.ts +40 -28
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +26 -4
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +106 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +67 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +121 -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 +121 -5
- package/src/services/reqresp/protocols/tx.ts +36 -8
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +12 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +21 -1
- package/src/services/reqresp/reqresp.ts +449 -271
- package/src/services/reqresp/status.ts +12 -3
- package/src/services/service.ts +65 -22
- package/src/services/tx_collection/config.ts +98 -0
- package/src/services/tx_collection/fast_tx_collection.ts +364 -0
- package/src/services/tx_collection/index.ts +7 -0
- package/src/services/tx_collection/instrumentation.ts +35 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +114 -0
- package/src/services/tx_collection/slow_tx_collection.ts +233 -0
- package/src/services/tx_collection/tx_collection.ts +216 -0
- package/src/services/tx_collection/tx_collection_sink.ts +129 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_file_store/config.ts +43 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +173 -0
- package/src/services/tx_provider.ts +232 -0
- package/src/services/tx_provider_instrumentation.ts +54 -0
- package/src/test-helpers/index.ts +3 -0
- package/src/test-helpers/make-enrs.ts +4 -5
- package/src/test-helpers/make-test-p2p-clients.ts +111 -21
- package/src/test-helpers/mock-pubsub.ts +188 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +87 -36
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +374 -0
- package/src/testbench/p2p_client_testbench_worker.ts +434 -89
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +315 -59
- package/src/types/index.ts +2 -0
- package/src/util.ts +105 -91
- package/src/versioning.ts +11 -4
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -56
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -141
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -8
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -21
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -174
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -29
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
package/src/client/p2p_client.ts
CHANGED
|
@@ -1,165 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
4
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
+
import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
6
|
+
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
7
|
+
import {
|
|
8
|
+
type EthAddress,
|
|
9
|
+
type L2Block,
|
|
10
|
+
type L2BlockSource,
|
|
11
|
+
L2BlockStream,
|
|
12
|
+
type L2BlockStreamEvent,
|
|
13
|
+
type L2Tips,
|
|
14
|
+
type L2TipsStore,
|
|
15
|
+
} from '@aztec/stdlib/block';
|
|
16
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
17
|
+
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
18
|
+
import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
|
|
8
19
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from '@aztec/telemetry-client';
|
|
20
|
+
type BlockProposal,
|
|
21
|
+
CheckpointAttestation,
|
|
22
|
+
type CheckpointProposal,
|
|
23
|
+
type P2PClientType,
|
|
24
|
+
} from '@aztec/stdlib/p2p';
|
|
25
|
+
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
26
|
+
import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
16
27
|
|
|
17
|
-
import type {
|
|
28
|
+
import type { PeerId } from '@libp2p/interface';
|
|
29
|
+
import type { ENR } from '@nethermindeth/enr';
|
|
18
30
|
|
|
19
31
|
import { type P2PConfig, getP2PDefaultConfig } from '../config.js';
|
|
20
32
|
import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
21
33
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
22
34
|
import type { TxPool } from '../mem_pools/tx_pool/index.js';
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The synchronization status of the P2P client.
|
|
38
|
-
*/
|
|
39
|
-
export interface P2PSyncState {
|
|
40
|
-
/**
|
|
41
|
-
* The current state of the p2p client.
|
|
42
|
-
*/
|
|
43
|
-
state: P2PClientState;
|
|
44
|
-
/**
|
|
45
|
-
* The block number that the p2p client is synced to.
|
|
46
|
-
*/
|
|
47
|
-
syncedToL2Block: L2BlockId;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Interface of a P2P client.
|
|
52
|
-
**/
|
|
53
|
-
export type P2P<T extends P2PClientType = P2PClientType.Full> = ProverCoordination &
|
|
54
|
-
P2PApi<T> & {
|
|
55
|
-
/**
|
|
56
|
-
* Broadcasts a block proposal to other peers.
|
|
57
|
-
*
|
|
58
|
-
* @param proposal - the block proposal
|
|
59
|
-
*/
|
|
60
|
-
broadcastProposal(proposal: BlockProposal): void;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Registers a callback from the validator client that determines how to behave when
|
|
64
|
-
* foreign block proposals are received
|
|
65
|
-
*
|
|
66
|
-
* @param handler - A function taking a received block proposal and producing an attestation
|
|
67
|
-
*/
|
|
68
|
-
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
69
|
-
// ^ This pattern is not my favorite (md)
|
|
70
|
-
registerBlockProposalHandler(handler: (block: BlockProposal) => Promise<BlockAttestation | undefined>): void;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Request a list of transactions from another peer by their tx hashes.
|
|
74
|
-
* @param txHashes - Hashes of the txs to query.
|
|
75
|
-
* @returns A list of transactions or undefined if the transactions are not found.
|
|
76
|
-
*/
|
|
77
|
-
requestTxs(txHashes: TxHash[]): Promise<(Tx | undefined)[]>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Request a transaction from another peer by its tx hash.
|
|
81
|
-
* @param txHash - Hash of the tx to query.
|
|
82
|
-
*/
|
|
83
|
-
requestTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers.
|
|
87
|
-
* @param tx - The transaction.
|
|
88
|
-
**/
|
|
89
|
-
sendTx(tx: Tx): Promise<void>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Deletes 'txs' from the pool, given hashes.
|
|
93
|
-
* NOT used if we use sendTx as reconcileTxPool will handle this.
|
|
94
|
-
* @param txHashes - Hashes to check.
|
|
95
|
-
**/
|
|
96
|
-
deleteTxs(txHashes: TxHash[]): Promise<void>;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Returns a transaction in the transaction pool by its hash.
|
|
100
|
-
* @param txHash - Hash of tx to return.
|
|
101
|
-
* @returns A single tx or undefined.
|
|
102
|
-
*/
|
|
103
|
-
getTxByHashFromPool(txHash: TxHash): Promise<Tx | undefined>;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Returns a transaction in the transaction pool by its hash, requesting it from the network if it is not found.
|
|
107
|
-
* @param txHash - Hash of tx to return.
|
|
108
|
-
* @returns A single tx or undefined.
|
|
109
|
-
*/
|
|
110
|
-
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Returns an archived transaction from the transaction pool by its hash.
|
|
114
|
-
* @param txHash - Hash of tx to return.
|
|
115
|
-
* @returns A single tx or undefined.
|
|
116
|
-
*/
|
|
117
|
-
getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Returns whether the given tx hash is flagged as pending or mined.
|
|
121
|
-
* @param txHash - Hash of the tx to query.
|
|
122
|
-
* @returns Pending or mined depending on its status, or undefined if not found.
|
|
123
|
-
*/
|
|
124
|
-
getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined>;
|
|
125
|
-
|
|
126
|
-
/** Returns an iterator over pending txs on the mempool. */
|
|
127
|
-
iteratePendingTxs(): AsyncIterableIterator<Tx>;
|
|
128
|
-
|
|
129
|
-
/** Returns the number of pending txs in the mempool. */
|
|
130
|
-
getPendingTxCount(): Promise<number>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Starts the p2p client.
|
|
134
|
-
* @returns A promise signalling the completion of the block sync.
|
|
135
|
-
*/
|
|
136
|
-
start(): Promise<void>;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Stops the p2p client.
|
|
140
|
-
* @returns A promise signalling the completion of the stop process.
|
|
141
|
-
*/
|
|
142
|
-
stop(): Promise<void>;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Indicates if the p2p client is ready for transaction submission.
|
|
146
|
-
* @returns A boolean flag indicating readiness.
|
|
147
|
-
*/
|
|
148
|
-
isReady(): boolean;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Returns the current status of the p2p client.
|
|
152
|
-
*/
|
|
153
|
-
getStatus(): Promise<P2PSyncState>;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Returns the ENR of this node, if any.
|
|
157
|
-
*/
|
|
158
|
-
getEnr(): ENR | undefined;
|
|
159
|
-
|
|
160
|
-
/** Identifies a p2p client. */
|
|
161
|
-
isP2PClient(): true;
|
|
162
|
-
};
|
|
35
|
+
import type { AuthRequest, StatusMessage } from '../services/index.js';
|
|
36
|
+
import {
|
|
37
|
+
ReqRespSubProtocol,
|
|
38
|
+
type ReqRespSubProtocolHandler,
|
|
39
|
+
type ReqRespSubProtocolValidators,
|
|
40
|
+
} from '../services/reqresp/interface.js';
|
|
41
|
+
import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
|
|
42
|
+
import type { P2PBlockReceivedCallback, P2PCheckpointReceivedCallback, P2PService } from '../services/service.js';
|
|
43
|
+
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
44
|
+
import type { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
|
|
45
|
+
import { TxProvider } from '../services/tx_provider.js';
|
|
46
|
+
import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
163
47
|
|
|
164
48
|
/**
|
|
165
49
|
* The P2P client implementation.
|
|
@@ -176,20 +60,21 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
176
60
|
private syncResolve?: () => void = undefined;
|
|
177
61
|
private latestBlockNumberAtStart = -1;
|
|
178
62
|
private provenBlockNumberAtStart = -1;
|
|
63
|
+
private finalizedBlockNumberAtStart = -1;
|
|
179
64
|
|
|
180
|
-
private
|
|
181
|
-
private
|
|
182
|
-
private synchedProvenBlockNumber: AztecAsyncSingleton<number>;
|
|
65
|
+
private l2Tips: L2TipsStore;
|
|
66
|
+
private synchedLatestSlot: AztecAsyncSingleton<bigint>;
|
|
183
67
|
|
|
184
68
|
private txPool: TxPool;
|
|
185
|
-
private attestationPool:
|
|
69
|
+
private attestationPool: AttestationPool;
|
|
70
|
+
|
|
71
|
+
private config: P2PConfig;
|
|
186
72
|
|
|
187
|
-
|
|
188
|
-
private keepAttestationsInPoolFor: number;
|
|
189
|
-
/** How many slots to keep proven txs for. */
|
|
190
|
-
private keepProvenTxsFor: number;
|
|
73
|
+
private blockStream: L2BlockStream | undefined;
|
|
191
74
|
|
|
192
|
-
private
|
|
75
|
+
private txProvider: TxProvider;
|
|
76
|
+
|
|
77
|
+
private validatorAddresses: EthAddress[] = [];
|
|
193
78
|
|
|
194
79
|
/**
|
|
195
80
|
* In-memory P2P client constructor.
|
|
@@ -197,107 +82,130 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
197
82
|
* @param l2BlockSource - P2P client's source for fetching existing blocks.
|
|
198
83
|
* @param txPool - The client's instance of a transaction pool. Defaults to in-memory implementation.
|
|
199
84
|
* @param p2pService - The concrete instance of p2p networking to use.
|
|
200
|
-
* @param keepProvenTxsFor - How many blocks have to pass after a block is proven before its txs are deleted (zero to delete immediately once proven).
|
|
201
85
|
* @param log - A logger.
|
|
202
86
|
*/
|
|
203
87
|
constructor(
|
|
204
88
|
_clientType: T,
|
|
205
|
-
store: AztecAsyncKVStore,
|
|
206
|
-
private l2BlockSource: L2BlockSource,
|
|
207
|
-
mempools: MemPools
|
|
89
|
+
private store: AztecAsyncKVStore,
|
|
90
|
+
private l2BlockSource: L2BlockSource & ContractDataSource,
|
|
91
|
+
mempools: MemPools,
|
|
208
92
|
private p2pService: P2PService,
|
|
93
|
+
private txCollection: TxCollection,
|
|
94
|
+
private txFileStore: TxFileStore | undefined,
|
|
209
95
|
config: Partial<P2PConfig> = {},
|
|
210
|
-
|
|
96
|
+
private _dateProvider: DateProvider = new DateProvider(),
|
|
97
|
+
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
211
98
|
private log = createLogger('p2p'),
|
|
212
99
|
) {
|
|
213
100
|
super(telemetry, 'P2PClient');
|
|
214
101
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
102
|
+
this.config = { ...getP2PDefaultConfig(), ...config };
|
|
103
|
+
this.txPool = mempools.txPool;
|
|
104
|
+
this.attestationPool = mempools.attestationPool;
|
|
105
|
+
|
|
106
|
+
this.txProvider = new TxProvider(
|
|
107
|
+
this.txCollection,
|
|
108
|
+
this.txPool,
|
|
109
|
+
this,
|
|
110
|
+
this.log.createChild('tx-provider'),
|
|
111
|
+
this.telemetry,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Default to collecting all txs when we see a valid proposal
|
|
115
|
+
// This can be overridden by the validator client to validate, and it will call getTxsForBlockProposal on its own
|
|
116
|
+
// Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
117
|
+
// TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
|
|
118
|
+
// validator-client code into here so we can validate a proposal is reasonable.
|
|
119
|
+
this.registerBlockProposalHandler(async (block, sender) => {
|
|
120
|
+
this.log.debug(`Received block proposal from ${sender.toString()}`);
|
|
121
|
+
// TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
|
|
122
|
+
const constants = this.txCollection.getConstants();
|
|
123
|
+
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
|
|
124
|
+
const deadline = new Date(nextSlotTimestampSeconds * 1000);
|
|
125
|
+
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
|
|
126
|
+
if (!parentBlock) {
|
|
127
|
+
this.log.debug(`Cannot collect txs for proposal as parent block not found`);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
|
|
131
|
+
await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
|
|
132
|
+
return true;
|
|
227
133
|
});
|
|
228
134
|
|
|
229
|
-
this.
|
|
230
|
-
this.
|
|
231
|
-
|
|
135
|
+
this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
|
|
136
|
+
this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
|
|
137
|
+
}
|
|
232
138
|
|
|
233
|
-
|
|
234
|
-
this.
|
|
139
|
+
public registerThisValidatorAddresses(addresses: EthAddress[]): void {
|
|
140
|
+
this.validatorAddresses = [...addresses];
|
|
141
|
+
this.p2pService.registerThisValidatorAddresses(this.validatorAddresses);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public clear(): Promise<void> {
|
|
145
|
+
return this.store.clear();
|
|
235
146
|
}
|
|
236
147
|
|
|
237
148
|
public isP2PClient(): true {
|
|
238
149
|
return true;
|
|
239
150
|
}
|
|
240
151
|
|
|
152
|
+
public getTxProvider(): TxProvider {
|
|
153
|
+
return this.txProvider;
|
|
154
|
+
}
|
|
155
|
+
|
|
241
156
|
public getPeers(includePending?: boolean): Promise<PeerInfo[]> {
|
|
242
157
|
return Promise.resolve(this.p2pService.getPeers(includePending));
|
|
243
158
|
}
|
|
244
159
|
|
|
245
|
-
public getL2BlockHash(number:
|
|
246
|
-
return this.
|
|
160
|
+
public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
161
|
+
return this.l2Tips.getL2BlockHash(number);
|
|
247
162
|
}
|
|
248
163
|
|
|
249
|
-
public
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (latestBlockNumber > 0) {
|
|
256
|
-
latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
|
|
257
|
-
if (typeof latestBlockHash === 'undefined') {
|
|
258
|
-
this.log.warn(`Block hash for latest block ${latestBlockNumber} not found`);
|
|
259
|
-
throw new Error();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (provenBlockNumber > 0) {
|
|
264
|
-
provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
|
|
265
|
-
if (typeof provenBlockHash === 'undefined') {
|
|
266
|
-
this.log.warn(`Block hash for proven block ${provenBlockNumber} not found`);
|
|
267
|
-
throw new Error();
|
|
268
|
-
}
|
|
269
|
-
}
|
|
164
|
+
public updateP2PConfig(config: Partial<P2PConfig>): Promise<void> {
|
|
165
|
+
this.txPool.updateConfig(config);
|
|
166
|
+
this.p2pService.updateConfig(config);
|
|
167
|
+
return Promise.resolve();
|
|
168
|
+
}
|
|
270
169
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
proven: { hash: provenBlockHash!, number: provenBlockNumber },
|
|
274
|
-
finalized: { hash: provenBlockHash!, number: provenBlockNumber },
|
|
275
|
-
});
|
|
170
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
171
|
+
return this.l2Tips.getL2Tips();
|
|
276
172
|
}
|
|
277
173
|
|
|
278
174
|
public async handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
|
|
279
175
|
this.log.debug(`Handling block stream event ${event.type}`);
|
|
176
|
+
|
|
280
177
|
switch (event.type) {
|
|
281
178
|
case 'blocks-added':
|
|
282
179
|
await this.handleLatestL2Blocks(event.blocks);
|
|
283
180
|
break;
|
|
284
|
-
case 'chain-finalized':
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
181
|
+
case 'chain-finalized': {
|
|
182
|
+
const oldFinalizedBlockNum = await this.getSyncedFinalizedBlockNum();
|
|
183
|
+
const from = BlockNumber(oldFinalizedBlockNum + 1);
|
|
184
|
+
const limit = event.block.number - from + 1;
|
|
185
|
+
if (limit > 0) {
|
|
186
|
+
const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
|
|
187
|
+
await this.handleFinalizedL2Blocks(oldBlocks);
|
|
188
|
+
}
|
|
291
189
|
break;
|
|
292
190
|
}
|
|
191
|
+
case 'chain-proven':
|
|
192
|
+
this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
|
|
193
|
+
break;
|
|
293
194
|
case 'chain-pruned':
|
|
294
|
-
|
|
195
|
+
this.txCollection.stopCollectingForBlocksAfter(event.block.number);
|
|
196
|
+
await this.handlePruneL2Blocks(event.block.number);
|
|
197
|
+
break;
|
|
198
|
+
case 'chain-checkpointed':
|
|
295
199
|
break;
|
|
296
200
|
default: {
|
|
297
201
|
const _: never = event;
|
|
298
202
|
break;
|
|
299
203
|
}
|
|
300
204
|
}
|
|
205
|
+
|
|
206
|
+
// Pass the event through to our l2 tips store
|
|
207
|
+
await this.l2Tips.handleBlockStreamEvent(event);
|
|
208
|
+
await this.startServiceIfSynched();
|
|
301
209
|
}
|
|
302
210
|
|
|
303
211
|
#assertIsReady() {
|
|
@@ -320,123 +228,195 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
320
228
|
}
|
|
321
229
|
|
|
322
230
|
// get the current latest block numbers
|
|
323
|
-
|
|
324
|
-
this.
|
|
231
|
+
const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
|
|
232
|
+
this.latestBlockNumberAtStart = latestBlockNumbers.proposed.number;
|
|
233
|
+
this.provenBlockNumberAtStart = latestBlockNumbers.proven.block.number;
|
|
234
|
+
this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.block.number;
|
|
325
235
|
|
|
326
236
|
const syncedLatestBlock = (await this.getSyncedLatestBlockNum()) + 1;
|
|
327
237
|
const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
|
|
238
|
+
const syncedFinalizedBlock = (await this.getSyncedFinalizedBlockNum()) + 1;
|
|
328
239
|
|
|
329
|
-
|
|
330
|
-
|
|
240
|
+
if ((await this.txPool.isEmpty()) && (await this.attestationPool.isEmpty())) {
|
|
241
|
+
// if mempools are empty, we don't care about syncing prior blocks
|
|
242
|
+
this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
|
|
243
|
+
this.setCurrentState(P2PClientState.RUNNING);
|
|
244
|
+
this.syncPromise = Promise.resolve();
|
|
245
|
+
await this.p2pService.start();
|
|
246
|
+
this.log.info(`Starting p2p client from block ${this.latestBlockNumberAtStart} with empty mempools`);
|
|
247
|
+
} else if (
|
|
248
|
+
syncedLatestBlock <= this.latestBlockNumberAtStart ||
|
|
249
|
+
syncedProvenBlock <= this.provenBlockNumberAtStart ||
|
|
250
|
+
syncedFinalizedBlock <= this.finalizedBlockNumberAtStart
|
|
251
|
+
) {
|
|
252
|
+
// if there are blocks to be retrieved, go to a synching state
|
|
253
|
+
// this gets resolved on `startServiceIfSynched`
|
|
254
|
+
this.initBlockStream();
|
|
331
255
|
this.setCurrentState(P2PClientState.SYNCHING);
|
|
332
256
|
this.syncPromise = new Promise(resolve => {
|
|
333
257
|
this.syncResolve = resolve;
|
|
334
258
|
});
|
|
335
|
-
this.log.
|
|
259
|
+
this.log.info(`Initiating p2p sync from ${syncedLatestBlock}`, {
|
|
260
|
+
syncedLatestBlock,
|
|
261
|
+
syncedProvenBlock,
|
|
262
|
+
syncedFinalizedBlock,
|
|
263
|
+
});
|
|
336
264
|
} else {
|
|
337
265
|
// if no blocks to be retrieved, go straight to running
|
|
266
|
+
this.initBlockStream();
|
|
338
267
|
this.setCurrentState(P2PClientState.RUNNING);
|
|
339
268
|
this.syncPromise = Promise.resolve();
|
|
340
269
|
await this.p2pService.start();
|
|
341
|
-
this.log.
|
|
270
|
+
this.log.info(`Starting P2P client synced to ${syncedLatestBlock}`, {
|
|
271
|
+
syncedLatestBlock,
|
|
272
|
+
syncedProvenBlock,
|
|
273
|
+
syncedFinalizedBlock,
|
|
274
|
+
});
|
|
342
275
|
}
|
|
343
276
|
|
|
344
|
-
this.blockStream
|
|
345
|
-
this.
|
|
346
|
-
|
|
277
|
+
this.blockStream!.start();
|
|
278
|
+
await this.txCollection.start();
|
|
279
|
+
this.txFileStore?.start();
|
|
347
280
|
return this.syncPromise;
|
|
348
281
|
}
|
|
349
282
|
|
|
283
|
+
addReqRespSubProtocol(
|
|
284
|
+
subProtocol: ReqRespSubProtocol,
|
|
285
|
+
handler: ReqRespSubProtocolHandler,
|
|
286
|
+
validator: ReqRespSubProtocolValidators[ReqRespSubProtocol],
|
|
287
|
+
): Promise<void> {
|
|
288
|
+
return this.p2pService.addReqRespSubProtocol(subProtocol, handler, validator);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private initBlockStream(startingBlock?: BlockNumber) {
|
|
292
|
+
if (!this.blockStream) {
|
|
293
|
+
const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
|
|
294
|
+
this.blockStream = new L2BlockStream(
|
|
295
|
+
this.l2BlockSource,
|
|
296
|
+
this,
|
|
297
|
+
this,
|
|
298
|
+
createLogger(`${this.log.module}:l2-block-stream`),
|
|
299
|
+
{ batchSize, pollIntervalMS, startingBlock },
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
350
304
|
/**
|
|
351
305
|
* Allows consumers to stop the instance of the P2P client.
|
|
352
306
|
* 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
|
|
353
307
|
*/
|
|
354
308
|
public async stop() {
|
|
355
309
|
this.log.debug('Stopping p2p client...');
|
|
310
|
+
await tryStop(this.txCollection);
|
|
311
|
+
this.log.debug('Stopped tx collection service');
|
|
312
|
+
await this.txFileStore?.stop();
|
|
313
|
+
this.log.debug('Stopped tx file store');
|
|
356
314
|
await this.p2pService.stop();
|
|
357
315
|
this.log.debug('Stopped p2p service');
|
|
358
|
-
await this.blockStream
|
|
316
|
+
await this.blockStream?.stop();
|
|
359
317
|
this.log.debug('Stopped block downloader');
|
|
360
318
|
await this.runningPromise;
|
|
361
319
|
this.setCurrentState(P2PClientState.STOPPED);
|
|
362
|
-
this.log.info('P2P client stopped
|
|
320
|
+
this.log.info('P2P client stopped');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Triggers a sync to the archiver. Used for testing. */
|
|
324
|
+
public async sync() {
|
|
325
|
+
this.initBlockStream();
|
|
326
|
+
await this.blockStream!.sync();
|
|
363
327
|
}
|
|
364
328
|
|
|
365
329
|
@trackSpan('p2pClient.broadcastProposal', async proposal => ({
|
|
366
|
-
[Attributes.
|
|
367
|
-
[Attributes.SLOT_NUMBER]: proposal.slotNumber.toNumber(),
|
|
330
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
368
331
|
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
369
|
-
[Attributes.P2P_ID]: (await proposal.
|
|
332
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
370
333
|
}))
|
|
371
|
-
public broadcastProposal(proposal: BlockProposal): void {
|
|
372
|
-
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber
|
|
334
|
+
public async broadcastProposal(proposal: BlockProposal): Promise<void> {
|
|
335
|
+
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
|
|
336
|
+
// Store our own proposal so we can respond to req/resp requests for it
|
|
337
|
+
await this.attestationPool.addBlockProposal(proposal);
|
|
373
338
|
return this.p2pService.propagate(proposal);
|
|
374
339
|
}
|
|
375
340
|
|
|
376
|
-
|
|
377
|
-
|
|
341
|
+
@trackSpan('p2pClient.broadcastCheckpointProposal', async proposal => ({
|
|
342
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
343
|
+
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
344
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
345
|
+
}))
|
|
346
|
+
public async broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
|
|
347
|
+
this.log.verbose(`Broadcasting checkpoint proposal for slot ${proposal.slotNumber} to peers`);
|
|
348
|
+
const blockProposal = proposal.getBlockProposal();
|
|
349
|
+
if (blockProposal) {
|
|
350
|
+
// Store our own last-block proposal so we can respond to req/resp requests for it.
|
|
351
|
+
await this.attestationPool.addBlockProposal(blockProposal);
|
|
352
|
+
}
|
|
353
|
+
return this.p2pService.propagate(proposal);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
public async broadcastCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
357
|
+
this.log.verbose(`Broadcasting ${attestations.length} checkpoint attestations to peers`);
|
|
358
|
+
await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
public async getCheckpointAttestationsForSlot(
|
|
362
|
+
slot: SlotNumber,
|
|
363
|
+
proposalId?: string,
|
|
364
|
+
): Promise<CheckpointAttestation[]> {
|
|
365
|
+
return await (proposalId
|
|
366
|
+
? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalId)
|
|
367
|
+
: this.attestationPool.getCheckpointAttestationsForSlot(slot));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
public addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
371
|
+
return this.attestationPool.addCheckpointAttestations(attestations);
|
|
378
372
|
}
|
|
379
373
|
|
|
380
374
|
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
381
375
|
// ^ This pattern is not my favorite (md)
|
|
382
|
-
public registerBlockProposalHandler(handler:
|
|
376
|
+
public registerBlockProposalHandler(handler: P2PBlockReceivedCallback): void {
|
|
383
377
|
this.p2pService.registerBlockReceivedCallback(handler);
|
|
384
378
|
}
|
|
385
379
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
*
|
|
389
|
-
* If a transaction can be retrieved, it will be returned, if not an undefined
|
|
390
|
-
* will be returned. In place.
|
|
391
|
-
*
|
|
392
|
-
* @param txHashes - The hashes of the transactions to request.
|
|
393
|
-
* @returns A promise that resolves to an array of transactions or undefined.
|
|
394
|
-
*/
|
|
395
|
-
public async requestTxs(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
396
|
-
const res = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes);
|
|
397
|
-
return Promise.resolve(res ?? []);
|
|
380
|
+
public registerCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
|
|
381
|
+
this.p2pService.registerCheckpointReceivedCallback(handler);
|
|
398
382
|
}
|
|
399
383
|
|
|
400
384
|
/**
|
|
401
|
-
* Uses the Request Response protocol to request a
|
|
402
|
-
*
|
|
403
|
-
* If the underlying request response protocol fails, then we return undefined.
|
|
404
|
-
* If it succeeds then we add the transaction to our transaction pool and return.
|
|
405
|
-
*
|
|
406
|
-
* @param txHash - The hash of the transaction to request.
|
|
407
|
-
* @returns A promise that resolves to a transaction or undefined.
|
|
385
|
+
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
408
386
|
*/
|
|
409
|
-
public async
|
|
410
|
-
const
|
|
387
|
+
public async requestTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<Tx[]> {
|
|
388
|
+
const timeoutMs = 8000; // Longer timeout for now
|
|
389
|
+
const maxRetryAttempts = 10; // Keep retrying within the timeout
|
|
390
|
+
const requests = chunkTxHashesRequest(txHashes);
|
|
391
|
+
const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
|
|
392
|
+
|
|
393
|
+
const txBatches = await this.p2pService.sendBatchRequest(
|
|
394
|
+
ReqRespSubProtocol.TX,
|
|
395
|
+
requests,
|
|
396
|
+
pinnedPeerId,
|
|
397
|
+
timeoutMs,
|
|
398
|
+
maxPeers,
|
|
399
|
+
maxRetryAttempts,
|
|
400
|
+
);
|
|
411
401
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
await this.txPool.addTxs(
|
|
415
|
-
} else {
|
|
416
|
-
this.log.debug(`Failed to receive tx ${txHash.toString()} from peer`);
|
|
402
|
+
const txs = txBatches.flat();
|
|
403
|
+
if (txs.length > 0) {
|
|
404
|
+
await this.txPool.addTxs(txs);
|
|
417
405
|
}
|
|
418
406
|
|
|
419
|
-
return tx;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
424
|
-
*/
|
|
425
|
-
public async requestTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
|
|
426
|
-
const txs = (await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes)) ?? [];
|
|
427
|
-
await this.txPool.addTxs(txs);
|
|
428
407
|
const txHashesStr = txHashes.map(tx => tx.toString()).join(', ');
|
|
429
|
-
this.log.debug(`
|
|
430
|
-
|
|
408
|
+
this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
|
|
409
|
+
|
|
410
|
+
// We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
|
|
411
|
+
return txs;
|
|
431
412
|
}
|
|
432
413
|
|
|
433
|
-
public getPendingTxs(): Promise<Tx[]> {
|
|
434
|
-
return
|
|
414
|
+
public getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
|
|
415
|
+
return this.getTxs('pending', limit, after);
|
|
435
416
|
}
|
|
436
417
|
|
|
437
|
-
public
|
|
438
|
-
|
|
439
|
-
return pendingTxs.length;
|
|
418
|
+
public getPendingTxCount(): Promise<number> {
|
|
419
|
+
return this.txPool.getPendingTxCount();
|
|
440
420
|
}
|
|
441
421
|
|
|
442
422
|
public async *iteratePendingTxs(): AsyncIterableIterator<Tx> {
|
|
@@ -450,23 +430,60 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
450
430
|
|
|
451
431
|
/**
|
|
452
432
|
* Returns all transactions in the transaction pool.
|
|
433
|
+
* @param filter - The type of txs to return
|
|
434
|
+
* @param limit - How many txs to return
|
|
435
|
+
* @param after - If paginating, the last known tx hash. Will return txs after this hash
|
|
453
436
|
* @returns An array of Txs.
|
|
454
437
|
*/
|
|
455
|
-
public async getTxs(filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
|
|
438
|
+
public async getTxs(filter: 'all' | 'pending' | 'mined', limit?: number, after?: TxHash): Promise<Tx[]> {
|
|
439
|
+
if (limit !== undefined && limit <= 0) {
|
|
440
|
+
throw new TypeError('limit must be greater than 0');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
let txs: Tx[] | undefined = undefined;
|
|
444
|
+
let txHashes: TxHash[];
|
|
445
|
+
|
|
456
446
|
if (filter === 'all') {
|
|
457
|
-
|
|
447
|
+
txs = await this.txPool.getAllTxs();
|
|
448
|
+
txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
|
|
458
449
|
} else if (filter === 'mined') {
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
return minedTx.filter((tx): tx is Tx => !!tx);
|
|
450
|
+
const minedTxHashes = await this.txPool.getMinedTxHashes();
|
|
451
|
+
txHashes = minedTxHashes.map(([txHash]) => txHash);
|
|
462
452
|
} else if (filter === 'pending') {
|
|
463
|
-
|
|
464
|
-
const pendingTxs = await Promise.all(pendingHashses.map(txHash => this.txPool.getTxByHash(txHash)));
|
|
465
|
-
return pendingTxs.filter((tx): tx is Tx => !!tx);
|
|
453
|
+
txHashes = await this.txPool.getPendingTxHashes();
|
|
466
454
|
} else {
|
|
467
455
|
const _: never = filter;
|
|
468
456
|
throw new Error(`Unknown filter ${filter}`);
|
|
469
457
|
}
|
|
458
|
+
|
|
459
|
+
let startIndex = 0;
|
|
460
|
+
let endIndex: number | undefined = undefined;
|
|
461
|
+
|
|
462
|
+
if (after) {
|
|
463
|
+
startIndex = txHashes.findIndex(txHash => after.equals(txHash));
|
|
464
|
+
|
|
465
|
+
// if we can't find the last tx in our set then return an empty array as pagination is no longer valid.
|
|
466
|
+
if (startIndex === -1) {
|
|
467
|
+
return [];
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// increment by one because we don't want to return the same tx again
|
|
471
|
+
startIndex++;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (limit !== undefined) {
|
|
475
|
+
endIndex = startIndex + limit;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
txHashes = txHashes.slice(startIndex, endIndex);
|
|
479
|
+
if (txs) {
|
|
480
|
+
txs = txs.slice(startIndex, endIndex);
|
|
481
|
+
} else {
|
|
482
|
+
const maybeTxs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
|
|
483
|
+
txs = maybeTxs.filter((tx): tx is Tx => !!tx);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return txs;
|
|
470
487
|
}
|
|
471
488
|
|
|
472
489
|
/**
|
|
@@ -479,26 +496,25 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
479
496
|
}
|
|
480
497
|
|
|
481
498
|
/**
|
|
482
|
-
* Returns
|
|
483
|
-
*
|
|
484
|
-
* @
|
|
485
|
-
* @returns A single tx or undefined.
|
|
499
|
+
* Returns transactions in the transaction pool by hash.
|
|
500
|
+
* @param txHashes - Hashes of the transactions to look for.
|
|
501
|
+
* @returns The txs found, in the same order as the requested hashes. If a tx is not found, it will be undefined.
|
|
486
502
|
*/
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
return this.
|
|
503
|
+
getTxsByHashFromPool(txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
504
|
+
return this.txPool.getTxsByHash(txHashes);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]> {
|
|
508
|
+
return this.txPool.hasTxs(txHashes);
|
|
493
509
|
}
|
|
494
510
|
|
|
495
511
|
/**
|
|
496
512
|
* Returns transactions in the transaction pool by hash.
|
|
497
513
|
* If a transaction is not in the pool, it will be requested from the network.
|
|
498
514
|
* @param txHashes - Hashes of the transactions to look for.
|
|
499
|
-
* @returns The txs found, not
|
|
515
|
+
* @returns The txs found, or undefined if not found in the order requested.
|
|
500
516
|
*/
|
|
501
|
-
async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
|
|
517
|
+
async getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]> {
|
|
502
518
|
const txs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
|
|
503
519
|
const missingTxHashes = txs
|
|
504
520
|
.map((tx, index) => [tx, index] as const)
|
|
@@ -509,8 +525,30 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
509
525
|
return txs as Tx[];
|
|
510
526
|
}
|
|
511
527
|
|
|
512
|
-
const missingTxs = await this.requestTxsByHash(missingTxHashes);
|
|
513
|
-
|
|
528
|
+
const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
|
|
529
|
+
// TODO: optimize
|
|
530
|
+
// Merge the found txs in order
|
|
531
|
+
const mergingTxs = txHashes.map(txHash => {
|
|
532
|
+
// Is it in the txs list from the mempool?
|
|
533
|
+
for (const tx of txs) {
|
|
534
|
+
if (tx !== undefined && tx.getTxHash().equals(txHash)) {
|
|
535
|
+
return tx;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// Is it in the fetched missing txs?
|
|
540
|
+
// Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
|
|
541
|
+
for (const tx of missingTxs) {
|
|
542
|
+
if (tx.getTxHash().equals(txHash)) {
|
|
543
|
+
return tx;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Otherwise return undefined
|
|
548
|
+
return undefined;
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
return mergingTxs;
|
|
514
552
|
}
|
|
515
553
|
|
|
516
554
|
/**
|
|
@@ -528,9 +566,20 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
528
566
|
* @returns Empty promise.
|
|
529
567
|
**/
|
|
530
568
|
public async sendTx(tx: Tx): Promise<void> {
|
|
569
|
+
const addedCount = await this.addTxsToPool([tx]);
|
|
570
|
+
const txAddedSuccessfully = addedCount === 1;
|
|
571
|
+
if (txAddedSuccessfully) {
|
|
572
|
+
await this.p2pService.propagate(tx);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Adds transactions to the pool. Does not send to peers or validate the txs.
|
|
578
|
+
* @param txs - The transactions.
|
|
579
|
+
**/
|
|
580
|
+
public async addTxsToPool(txs: Tx[]): Promise<number> {
|
|
531
581
|
this.#assertIsReady();
|
|
532
|
-
await this.txPool.addTxs(
|
|
533
|
-
this.p2pService.propagate(tx);
|
|
582
|
+
return await this.txPool.addTxs(txs);
|
|
534
583
|
}
|
|
535
584
|
|
|
536
585
|
/**
|
|
@@ -538,7 +587,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
538
587
|
* @param txHash - Hash of the tx to query.
|
|
539
588
|
* @returns Pending or mined depending on its status, or undefined if not found.
|
|
540
589
|
*/
|
|
541
|
-
public getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
|
|
590
|
+
public getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined> {
|
|
542
591
|
return this.txPool.getTxStatus(txHash);
|
|
543
592
|
}
|
|
544
593
|
|
|
@@ -573,16 +622,28 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
573
622
|
* Public function to check the latest block number that the P2P client is synced to.
|
|
574
623
|
* @returns Block number of latest L2 Block we've synced with.
|
|
575
624
|
*/
|
|
576
|
-
public async getSyncedLatestBlockNum(): Promise<
|
|
577
|
-
|
|
625
|
+
public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
|
|
626
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
627
|
+
return tips.proposed.number;
|
|
578
628
|
}
|
|
579
629
|
|
|
580
630
|
/**
|
|
581
631
|
* Public function to check the latest proven block number that the P2P client is synced to.
|
|
582
632
|
* @returns Block number of latest proven L2 Block we've synced with.
|
|
583
633
|
*/
|
|
584
|
-
public async getSyncedProvenBlockNum(): Promise<
|
|
585
|
-
|
|
634
|
+
public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
|
|
635
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
636
|
+
return tips.proven.block.number;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
|
|
640
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
641
|
+
return tips.finalized.block.number;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** Returns latest L2 slot for which we have seen an L2 block. */
|
|
645
|
+
public async getSyncedLatestSlot(): Promise<bigint> {
|
|
646
|
+
return (await this.synchedLatestSlot.getAsync()) ?? BigInt(0);
|
|
586
647
|
}
|
|
587
648
|
|
|
588
649
|
/**
|
|
@@ -593,7 +654,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
593
654
|
const blockNumber = await this.getSyncedLatestBlockNum();
|
|
594
655
|
const blockHash =
|
|
595
656
|
blockNumber === 0
|
|
596
|
-
?
|
|
657
|
+
? GENESIS_BLOCK_HEADER_HASH.toString()
|
|
597
658
|
: await this.l2BlockSource
|
|
598
659
|
.getBlockHeader(blockNumber)
|
|
599
660
|
.then(header => header?.hash())
|
|
@@ -601,8 +662,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
601
662
|
|
|
602
663
|
return {
|
|
603
664
|
state: this.currentState,
|
|
604
|
-
syncedToL2Block: { number: blockNumber, hash: blockHash },
|
|
605
|
-
}
|
|
665
|
+
syncedToL2Block: { number: blockNumber, hash: blockHash! },
|
|
666
|
+
};
|
|
606
667
|
}
|
|
607
668
|
|
|
608
669
|
/**
|
|
@@ -613,20 +674,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
613
674
|
private async markTxsAsMinedFromBlocks(blocks: L2Block[]): Promise<void> {
|
|
614
675
|
for (const block of blocks) {
|
|
615
676
|
const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
|
|
616
|
-
await this.txPool.markAsMined(txHashes, block.
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Deletes txs from these blocks.
|
|
622
|
-
* @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
|
|
623
|
-
* @returns Empty promise.
|
|
624
|
-
*/
|
|
625
|
-
private async deleteTxsFromBlocks(blocks: L2Block[]): Promise<void> {
|
|
626
|
-
this.log.debug(`Deleting txs from blocks ${blocks[0].number} to ${blocks[blocks.length - 1].number}`);
|
|
627
|
-
for (const block of blocks) {
|
|
628
|
-
const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
|
|
629
|
-
await this.txPool.deleteTxs(txHashes);
|
|
677
|
+
await this.txPool.markAsMined(txHashes, block.header);
|
|
630
678
|
}
|
|
631
679
|
}
|
|
632
680
|
|
|
@@ -641,99 +689,133 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
641
689
|
}
|
|
642
690
|
|
|
643
691
|
await this.markTxsAsMinedFromBlocks(blocks);
|
|
644
|
-
|
|
645
|
-
await
|
|
646
|
-
|
|
647
|
-
)
|
|
648
|
-
await this.
|
|
649
|
-
this.log.verbose(`Synched to latest block ${
|
|
650
|
-
|
|
692
|
+
await this.txPool.clearNonEvictableTxs();
|
|
693
|
+
await this.startCollectingMissingTxs(blocks);
|
|
694
|
+
|
|
695
|
+
const lastBlock = blocks.at(-1)!;
|
|
696
|
+
await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
|
|
697
|
+
this.log.verbose(`Synched to latest block ${lastBlock.number}`);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/** Request txs for unproven blocks so the prover node has more chances to get them. */
|
|
701
|
+
private async startCollectingMissingTxs(blocks: L2Block[]): Promise<void> {
|
|
702
|
+
try {
|
|
703
|
+
// TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
|
|
704
|
+
// be much lower than the actual one, and it does not update until the pending chain is
|
|
705
|
+
// fully synced. This could lead to a ton of tx collection requests for blocks that
|
|
706
|
+
// are already proven, but the archiver has not yet updated its state. Until this is properly
|
|
707
|
+
// fixed, it is mitigated by the expiration date of collection requests, which depends on
|
|
708
|
+
// the slot number of the block.
|
|
709
|
+
const provenBlockNumber = await this.l2BlockSource.getProvenBlockNumber();
|
|
710
|
+
const unprovenBlocks = blocks.filter(block => block.number > provenBlockNumber);
|
|
711
|
+
for (const block of unprovenBlocks) {
|
|
712
|
+
const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
|
|
713
|
+
const missingTxHashes = await this.txPool
|
|
714
|
+
.hasTxs(txHashes)
|
|
715
|
+
.then(availability => txHashes.filter((_, index) => !availability[index]));
|
|
716
|
+
if (missingTxHashes.length > 0) {
|
|
717
|
+
this.log.verbose(
|
|
718
|
+
`Starting collection of ${missingTxHashes.length} missing txs for unproven mined block ${block.number}`,
|
|
719
|
+
{ missingTxHashes, blockNumber: block.number, blockHash: await block.hash().then(h => h.toString()) },
|
|
720
|
+
);
|
|
721
|
+
this.txCollection.startCollecting(block, missingTxHashes);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
} catch (err) {
|
|
725
|
+
this.log.error(`Error while starting collection of missing txs for unproven blocks`, err);
|
|
726
|
+
}
|
|
651
727
|
}
|
|
652
728
|
|
|
653
729
|
/**
|
|
654
|
-
* Handles new
|
|
655
|
-
* @param blocks - A list of
|
|
730
|
+
* Handles new finalized blocks by deleting the txs and attestations in them.
|
|
731
|
+
* @param blocks - A list of finalized L2 blocks.
|
|
656
732
|
* @returns Empty promise.
|
|
657
733
|
*/
|
|
658
|
-
private async
|
|
734
|
+
private async handleFinalizedL2Blocks(blocks: L2Block[]): Promise<void> {
|
|
659
735
|
if (!blocks.length) {
|
|
660
736
|
return Promise.resolve();
|
|
661
737
|
}
|
|
738
|
+
this.log.debug(`Handling finalized blocks ${blocks.length} up to ${blocks.at(-1)?.number}`);
|
|
662
739
|
|
|
663
|
-
const firstBlockNum = blocks[0].number;
|
|
664
740
|
const lastBlockNum = blocks[blocks.length - 1].number;
|
|
665
|
-
const lastBlockSlot = blocks[blocks.length - 1].header.
|
|
666
|
-
|
|
667
|
-
// If keepProvenTxsFor is 0, we delete all txs from all proven blocks.
|
|
668
|
-
if (this.keepProvenTxsFor === 0) {
|
|
669
|
-
await this.deleteTxsFromBlocks(blocks);
|
|
670
|
-
} else if (lastBlockNum - this.keepProvenTxsFor >= INITIAL_L2_BLOCK_NUM) {
|
|
671
|
-
const fromBlock = Math.max(INITIAL_L2_BLOCK_NUM, firstBlockNum - this.keepProvenTxsFor);
|
|
672
|
-
const toBlock = lastBlockNum - this.keepProvenTxsFor;
|
|
673
|
-
const limit = toBlock - fromBlock + 1;
|
|
674
|
-
const blocksToDeleteTxsFrom = await this.l2BlockSource.getBlocks(fromBlock, limit, true);
|
|
675
|
-
await this.deleteTxsFromBlocks(blocksToDeleteTxsFrom);
|
|
676
|
-
}
|
|
741
|
+
const lastBlockSlot = blocks[blocks.length - 1].header.getSlot();
|
|
677
742
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
743
|
+
const txHashes = blocks.flatMap(block => block.body.txEffects.map(txEffect => txEffect.txHash));
|
|
744
|
+
this.log.debug(`Deleting ${txHashes.length} txs from pool from finalized blocks up to ${lastBlockNum}`);
|
|
745
|
+
await this.txPool.deleteTxs(txHashes, { permanently: true });
|
|
746
|
+
await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
|
|
683
747
|
|
|
684
|
-
await this.
|
|
685
|
-
this.log.debug(`Synched to proven block ${lastBlockNum}`);
|
|
748
|
+
await this.attestationPool.deleteCheckpointAttestationsOlderThan(lastBlockSlot);
|
|
686
749
|
|
|
687
|
-
|
|
750
|
+
this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
|
|
688
751
|
}
|
|
689
752
|
|
|
690
753
|
/**
|
|
691
754
|
* Updates the tx pool after a chain prune.
|
|
692
755
|
* @param latestBlock - The block number the chain was pruned to.
|
|
693
756
|
*/
|
|
694
|
-
private async handlePruneL2Blocks(latestBlock:
|
|
695
|
-
const txsToDelete
|
|
757
|
+
private async handlePruneL2Blocks(latestBlock: BlockNumber): Promise<void> {
|
|
758
|
+
const txsToDelete = new Map<string, TxHash>();
|
|
759
|
+
const minedTxs = await this.txPool.getMinedTxHashes();
|
|
760
|
+
|
|
761
|
+
// Find transactions that reference pruned blocks in their historical header
|
|
696
762
|
for (const tx of await this.txPool.getAllTxs()) {
|
|
697
763
|
// every tx that's been generated against a block that has now been pruned is no longer valid
|
|
698
|
-
if (tx.data.constants.
|
|
699
|
-
|
|
764
|
+
if (tx.data.constants.anchorBlockHeader.globalVariables.blockNumber > latestBlock) {
|
|
765
|
+
const txHash = tx.getTxHash();
|
|
766
|
+
txsToDelete.set(txHash.toString(), txHash);
|
|
700
767
|
}
|
|
701
768
|
}
|
|
702
769
|
|
|
703
|
-
this.log.info(
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
);
|
|
770
|
+
this.log.info(`Detected chain prune. Removing ${txsToDelete.size} txs built against pruned blocks.`, {
|
|
771
|
+
newLatestBlock: latestBlock,
|
|
772
|
+
previousLatestBlock: await this.getSyncedLatestBlockNum(),
|
|
773
|
+
txsToDelete: Array.from(txsToDelete.keys()),
|
|
774
|
+
});
|
|
708
775
|
|
|
709
776
|
// delete invalid txs (both pending and mined)
|
|
710
|
-
await this.txPool.deleteTxs(txsToDelete);
|
|
777
|
+
await this.txPool.deleteTxs(Array.from(txsToDelete.values()));
|
|
711
778
|
|
|
712
779
|
// everything left in the mined set was built against a block on the proven chain so its still valid
|
|
713
|
-
// move back to pending the txs that were reorged out of the chain
|
|
780
|
+
// move back to pending the txs that were reorged out of the chain, unless txPoolDeleteTxsAfterReorg is set,
|
|
781
|
+
// in which case we clean them up to avoid potential reorg loops
|
|
714
782
|
// NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
|
|
715
783
|
// (see this.keepProvenTxsFor)
|
|
716
|
-
const
|
|
717
|
-
for (const [txHash, blockNumber] of
|
|
718
|
-
|
|
719
|
-
|
|
784
|
+
const minedTxsFromReorg: TxHash[] = [];
|
|
785
|
+
for (const [txHash, blockNumber] of minedTxs) {
|
|
786
|
+
// We keep the txsToDelete out of this list as they have already been deleted above
|
|
787
|
+
if (blockNumber > latestBlock && !txsToDelete.has(txHash.toString())) {
|
|
788
|
+
minedTxsFromReorg.push(txHash);
|
|
720
789
|
}
|
|
721
790
|
}
|
|
722
791
|
|
|
723
|
-
this.
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
792
|
+
if (this.config.txPoolDeleteTxsAfterReorg) {
|
|
793
|
+
this.log.info(`Deleting ${minedTxsFromReorg.length} mined txs from reorg`);
|
|
794
|
+
await this.txPool.deleteTxs(minedTxsFromReorg);
|
|
795
|
+
} else {
|
|
796
|
+
await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
|
|
797
|
+
}
|
|
728
798
|
}
|
|
729
799
|
|
|
730
800
|
private async startServiceIfSynched() {
|
|
801
|
+
if (this.currentState !== P2PClientState.SYNCHING) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
805
|
+
const syncedFinalizedBlock = tips.finalized.block.number;
|
|
806
|
+
const syncedProvenBlock = tips.proven.block.number;
|
|
807
|
+
const syncedLatestBlock = tips.proposed.number;
|
|
808
|
+
|
|
731
809
|
if (
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
810
|
+
syncedLatestBlock >= this.latestBlockNumberAtStart &&
|
|
811
|
+
syncedProvenBlock >= this.provenBlockNumberAtStart &&
|
|
812
|
+
syncedFinalizedBlock >= this.finalizedBlockNumberAtStart
|
|
735
813
|
) {
|
|
736
|
-
this.log.
|
|
814
|
+
this.log.info(`Completed P2P client sync to block ${syncedLatestBlock}. Starting service.`, {
|
|
815
|
+
syncedLatestBlock,
|
|
816
|
+
syncedProvenBlock,
|
|
817
|
+
syncedFinalizedBlock,
|
|
818
|
+
});
|
|
737
819
|
this.setCurrentState(P2PClientState.RUNNING);
|
|
738
820
|
if (this.syncResolve !== undefined) {
|
|
739
821
|
this.syncResolve();
|
|
@@ -751,4 +833,20 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
751
833
|
this.currentState = newState;
|
|
752
834
|
this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
|
|
753
835
|
}
|
|
836
|
+
|
|
837
|
+
public validate(txs: Tx[]): Promise<void> {
|
|
838
|
+
return this.p2pService.validate(txs);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Marks transactions as non-evictable in the pool.
|
|
843
|
+
* @param txHashes - Hashes of the transactions to mark as non-evictable.
|
|
844
|
+
*/
|
|
845
|
+
public markTxsAsNonEvictable(txHashes: TxHash[]): Promise<void> {
|
|
846
|
+
return this.txPool.markTxsAsNonEvictable(txHashes);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
public handleAuthRequestFromPeer(authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage> {
|
|
850
|
+
return this.p2pService.handleAuthRequestFromPeer(authRequest, peerId);
|
|
851
|
+
}
|
|
754
852
|
}
|