@aztec-labs/p2p 6.0.0-nightly.20260829
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/README.md +134 -0
- package/dest/bootstrap/bootstrap.d.ts +39 -0
- package/dest/bootstrap/bootstrap.d.ts.map +1 -0
- package/dest/bootstrap/bootstrap.js +152 -0
- package/dest/client/factory.d.ts +32 -0
- package/dest/client/factory.d.ts.map +1 -0
- package/dest/client/factory.js +125 -0
- package/dest/client/index.d.ts +4 -0
- package/dest/client/index.d.ts.map +1 -0
- package/dest/client/index.js +3 -0
- package/dest/client/interface.d.ts +223 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +202 -0
- package/dest/client/p2p_client.d.ts.map +1 -0
- package/dest/client/p2p_client.js +1051 -0
- package/dest/config.d.ts +295 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +458 -0
- package/dest/enr/generate-enr.d.ts +17 -0
- package/dest/enr/generate-enr.d.ts.map +1 -0
- package/dest/enr/generate-enr.js +52 -0
- package/dest/enr/index.d.ts +2 -0
- package/dest/enr/index.d.ts.map +1 -0
- package/dest/enr/index.js +1 -0
- 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/p2p-service.error.d.ts +9 -0
- package/dest/errors/p2p-service.error.d.ts.map +1 -0
- package/dest/errors/p2p-service.error.js +10 -0
- package/dest/errors/reqresp.error.d.ts +21 -0
- package/dest/errors/reqresp.error.d.ts.map +1 -0
- package/dest/errors/reqresp.error.js +23 -0
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +11 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +9 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +194 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.js +521 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +3 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +745 -0
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -0
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/index.js +1 -0
- package/dest/mem_pools/attestation_pool/mocks.d.ts +242 -0
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/mocks.js +33 -0
- package/dest/mem_pools/index.d.ts +4 -0
- package/dest/mem_pools/index.d.ts.map +1 -0
- package/dest/mem_pools/index.js +1 -0
- package/dest/mem_pools/instrumentation.d.ts +41 -0
- package/dest/mem_pools/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/instrumentation.js +120 -0
- package/dest/mem_pools/interface.d.ts +10 -0
- package/dest/mem_pools/interface.d.ts.map +1 -0
- package/dest/mem_pools/interface.js +3 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +48 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +112 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +94 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +99 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +12 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.js +64 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +180 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +64 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +92 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +79 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +75 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +5 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +25 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +67 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +243 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +11 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +137 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +223 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +122 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +368 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +75 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +218 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +122 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +1039 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +17 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.js +111 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +24 -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 +75 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +3 -0
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/index.js +2 -0
- package/dest/msg_validators/index.d.ts +4 -0
- package/dest/msg_validators/index.d.ts.map +1 -0
- package/dest/msg_validators/index.js +3 -0
- 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 +16 -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 +14 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +16 -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 +26 -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 +40 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +186 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +7 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +25 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +4 -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 +31 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -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 +25 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/block_header_validator.js +27 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/cached_tx_validator.js +19 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +9 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/data_validator.js +114 -0
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +21 -0
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/double_spend_validator.js +36 -0
- package/dest/msg_validators/tx_validator/factory.d.ts +148 -0
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/factory.js +302 -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 +24 -0
- package/dest/msg_validators/tx_validator/gas_limits_validator.d.ts +73 -0
- package/dest/msg_validators/tx_validator/gas_limits_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_limits_validator.js +107 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +65 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/gas_validator.js +107 -0
- package/dest/msg_validators/tx_validator/index.d.ts +20 -0
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/index.js +19 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +15 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.js +63 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +35 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +141 -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 +30 -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 +11 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +28 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts +48 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_validation_cache.js +68 -0
- package/dest/services/data_store.d.ts +27 -0
- package/dest/services/data_store.d.ts.map +1 -0
- package/dest/services/data_store.js +192 -0
- package/dest/services/discv5/discV5_service.d.ts +54 -0
- package/dest/services/discv5/discV5_service.d.ts.map +1 -0
- package/dest/services/discv5/discV5_service.js +337 -0
- package/dest/services/discv5/persisted_enr_store.d.ts +38 -0
- package/dest/services/discv5/persisted_enr_store.d.ts.map +1 -0
- package/dest/services/discv5/persisted_enr_store.js +145 -0
- package/dest/services/dummy_service.d.ts +150 -0
- package/dest/services/dummy_service.d.ts.map +1 -0
- package/dest/services/dummy_service.js +228 -0
- package/dest/services/encoding.d.ts +67 -0
- package/dest/services/encoding.d.ts.map +1 -0
- package/dest/services/encoding.js +152 -0
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +25 -0
- package/dest/services/gossipsub/scoring.d.ts.map +1 -0
- package/dest/services/gossipsub/scoring.js +27 -0
- package/dest/services/gossipsub/topic_score_params.d.ts +167 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +336 -0
- package/dest/services/index.d.ts +8 -0
- package/dest/services/index.d.ts.map +1 -0
- package/dest/services/index.js +7 -0
- package/dest/services/libp2p/instrumentation.d.ts +25 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +143 -0
- package/dest/services/libp2p/libp2p_service.d.ts +250 -0
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -0
- package/dest/services/libp2p/libp2p_service.js +1983 -0
- 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 +23 -0
- package/dest/services/peer-manager/metrics.d.ts.map +1 -0
- package/dest/services/peer-manager/metrics.js +71 -0
- package/dest/services/peer-manager/peer_manager.d.ts +202 -0
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -0
- package/dest/services/peer-manager/peer_manager.js +1015 -0
- package/dest/services/peer-manager/peer_scoring.d.ts +65 -0
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -0
- package/dest/services/peer-manager/peer_scoring.js +239 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +44 -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 +534 -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 +35 -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 +136 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +62 -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 +176 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +11 -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 +7 -0
- package/dest/services/reqresp/config.d.ts +30 -0
- package/dest/services/reqresp/config.d.ts.map +1 -0
- package/dest/services/reqresp/config.js +45 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +76 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -0
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +251 -0
- 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 +7 -0
- package/dest/services/reqresp/index.d.ts.map +1 -0
- package/dest/services/reqresp/index.js +5 -0
- package/dest/services/reqresp/interface.d.ts +174 -0
- package/dest/services/reqresp/interface.d.ts.map +1 -0
- package/dest/services/reqresp/interface.js +107 -0
- package/dest/services/reqresp/metrics.d.ts +16 -0
- package/dest/services/reqresp/metrics.d.ts.map +1 -0
- package/dest/services/reqresp/metrics.js +50 -0
- 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_txs/bitvector.d.ts +35 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +88 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +13 -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 +60 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +75 -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 +139 -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 +49 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/goodbye.js +87 -0
- package/dest/services/reqresp/protocols/index.d.ts +10 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/index.js +8 -0
- package/dest/services/reqresp/protocols/ping.d.ts +7 -0
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/ping.js +7 -0
- package/dest/services/reqresp/protocols/status.d.ts +42 -0
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/status.js +78 -0
- package/dest/services/reqresp/protocols/tx.d.ts +29 -0
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/tx.js +66 -0
- package/dest/services/reqresp/rate-limiter/index.d.ts +2 -0
- package/dest/services/reqresp/rate-limiter/index.d.ts.map +1 -0
- package/dest/services/reqresp/rate-limiter/index.js +1 -0
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +105 -0
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -0
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +194 -0
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +3 -0
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -0
- package/dest/services/reqresp/rate-limiter/rate_limits.js +64 -0
- package/dest/services/reqresp/reqresp.d.ts +107 -0
- package/dest/services/reqresp/reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/reqresp.js +887 -0
- package/dest/services/reqresp/status.d.ts +37 -0
- package/dest/services/reqresp/status.d.ts.map +1 -0
- package/dest/services/reqresp/status.js +58 -0
- package/dest/services/service.d.ts +168 -0
- package/dest/services/service.d.ts.map +1 -0
- package/dest/services/service.js +5 -0
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +59 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +127 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +38 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +100 -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 +30 -0
- package/dest/services/tx_collection/request_tracker.d.ts +53 -0
- package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/request_tracker.js +84 -0
- package/dest/services/tx_collection/tx_collection.d.ts +104 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +356 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +40 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +108 -0
- package/dest/services/tx_collection/tx_source.d.ts +24 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +56 -0
- package/dest/services/tx_file_store/config.d.ts +16 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +22 -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 +46 -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 +142 -0
- package/dest/services/tx_provider.d.ts +53 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +223 -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 +7 -0
- package/dest/test-helpers/generate-peer-id-private-keys.d.ts.map +1 -0
- package/dest/test-helpers/generate-peer-id-private-keys.js +13 -0
- package/dest/test-helpers/get-ports.d.ts +7 -0
- package/dest/test-helpers/get-ports.d.ts.map +1 -0
- package/dest/test-helpers/get-ports.js +8 -0
- package/dest/test-helpers/index.d.ts +9 -0
- package/dest/test-helpers/index.d.ts.map +1 -0
- package/dest/test-helpers/index.js +8 -0
- package/dest/test-helpers/make-enrs.d.ts +16 -0
- package/dest/test-helpers/make-enrs.d.ts.map +1 -0
- package/dest/test-helpers/make-enrs.js +31 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +63 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -0
- package/dest/test-helpers/make-test-p2p-clients.js +140 -0
- package/dest/test-helpers/mock-pubsub.d.ts +109 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +244 -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 +68 -0
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -0
- package/dest/test-helpers/reqresp-nodes.js +240 -0
- package/dest/test-helpers/test_tx_provider.d.ts +42 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +44 -0
- package/dest/test-helpers/testbench-utils.d.ts +164 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +401 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +26 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -0
- package/dest/testbench/p2p_client_testbench_worker.js +364 -0
- package/dest/testbench/parse_log_file.d.ts +2 -0
- package/dest/testbench/parse_log_file.d.ts.map +1 -0
- package/dest/testbench/parse_log_file.js +131 -0
- package/dest/testbench/testbench.d.ts +2 -0
- package/dest/testbench/testbench.d.ts.map +1 -0
- package/dest/testbench/testbench.js +62 -0
- package/dest/testbench/worker_client_manager.d.ts +102 -0
- package/dest/testbench/worker_client_manager.d.ts.map +1 -0
- package/dest/testbench/worker_client_manager.js +492 -0
- package/dest/types/index.d.ts +34 -0
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +30 -0
- package/dest/util.d.ts +66 -0
- package/dest/util.d.ts.map +1 -0
- package/dest/util.js +167 -0
- package/dest/versioning.d.ts +9 -0
- package/dest/versioning.d.ts.map +1 -0
- package/dest/versioning.js +17 -0
- package/package.json +131 -0
- package/src/bootstrap/bootstrap.ts +178 -0
- package/src/client/factory.ts +282 -0
- package/src/client/index.ts +3 -0
- package/src/client/interface.ts +264 -0
- package/src/client/p2p_client.ts +846 -0
- package/src/client/test/p2p_client.batch_tx_requester.bench.README.md +197 -0
- package/src/config.ts +787 -0
- package/src/enr/generate-enr.ts +71 -0
- package/src/enr/index.ts +1 -0
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/errors/p2p-service.error.ts +11 -0
- package/src/errors/reqresp.error.ts +29 -0
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +11 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +648 -0
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +896 -0
- package/src/mem_pools/attestation_pool/index.ts +9 -0
- package/src/mem_pools/attestation_pool/mocks.ts +56 -0
- package/src/mem_pools/index.ts +3 -0
- package/src/mem_pools/instrumentation.ts +160 -0
- package/src/mem_pools/interface.ts +10 -0
- package/src/mem_pools/tx_pool_v2/README.md +283 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +130 -0
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +120 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +126 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +28 -0
- package/src/mem_pools/tx_pool_v2/eviction/insufficient_fee_per_gas_eviction_rule.ts +67 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +219 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +72 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +99 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +90 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +99 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +32 -0
- package/src/mem_pools/tx_pool_v2/index.ts +12 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +96 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +274 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +349 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +465 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +300 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1242 -0
- package/src/msg_validators/attestation_validator/README.md +49 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +116 -0
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +107 -0
- package/src/msg_validators/attestation_validator/index.ts +2 -0
- package/src/msg_validators/index.ts +3 -0
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/proposal_validator/README.md +123 -0
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +37 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +49 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +198 -0
- package/src/msg_validators/tx_validator/README.md +137 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +24 -0
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +30 -0
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +38 -0
- package/src/msg_validators/tx_validator/cached_tx_validator.ts +31 -0
- package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
- package/src/msg_validators/tx_validator/data_validator.ts +173 -0
- package/src/msg_validators/tx_validator/double_spend_validator.ts +46 -0
- package/src/msg_validators/tx_validator/factory.ts +490 -0
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +44 -0
- package/src/msg_validators/tx_validator/gas_limits_validator.ts +148 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +149 -0
- package/src/msg_validators/tx_validator/index.ts +19 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +104 -0
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +173 -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 +61 -0
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +22 -0
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +26 -0
- package/src/msg_validators/tx_validator/tx_validation_cache.ts +100 -0
- package/src/services/data_store.ts +229 -0
- package/src/services/discv5/discV5_service.ts +413 -0
- package/src/services/discv5/persisted_enr_store.ts +157 -0
- package/src/services/dummy_service.ts +320 -0
- package/src/services/encoding.ts +170 -0
- package/src/services/gossipsub/README.md +663 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +37 -0
- package/src/services/gossipsub/topic_score_params.ts +477 -0
- package/src/services/index.ts +7 -0
- package/src/services/libp2p/instrumentation.ts +147 -0
- package/src/services/libp2p/libp2p_service.ts +1972 -0
- package/src/services/peer-manager/interface.ts +28 -0
- package/src/services/peer-manager/metrics.ts +90 -0
- package/src/services/peer-manager/peer_manager.ts +1221 -0
- package/src/services/peer-manager/peer_scoring.ts +265 -0
- package/src/services/reqresp/README.md +194 -0
- package/src/services/reqresp/batch-tx-requester/README.md +344 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +659 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +60 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +167 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +248 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +24 -0
- package/src/services/reqresp/config.ts +69 -0
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +287 -0
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/index.ts +6 -0
- package/src/services/reqresp/interface.ts +241 -0
- package/src/services/reqresp/metrics.ts +68 -0
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +107 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +79 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +170 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +102 -0
- package/src/services/reqresp/protocols/index.ts +9 -0
- package/src/services/reqresp/protocols/ping.ts +8 -0
- package/src/services/reqresp/protocols/status.ts +123 -0
- package/src/services/reqresp/protocols/tx.ts +76 -0
- package/src/services/reqresp/rate-limiter/index.ts +1 -0
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +240 -0
- package/src/services/reqresp/rate-limiter/rate_limits.ts +65 -0
- package/src/services/reqresp/reqresp.ts +675 -0
- package/src/services/reqresp/status.ts +68 -0
- package/src/services/service.ts +219 -0
- package/src/services/tx_collection/config.ts +89 -0
- package/src/services/tx_collection/file_store_tx_collection.ts +153 -0
- package/src/services/tx_collection/file_store_tx_source.ts +129 -0
- package/src/services/tx_collection/index.ts +3 -0
- package/src/services/tx_collection/instrumentation.ts +35 -0
- package/src/services/tx_collection/request_tracker.ts +127 -0
- package/src/services/tx_collection/tx_collection.ts +467 -0
- package/src/services/tx_collection/tx_collection_sink.ts +124 -0
- package/src/services/tx_collection/tx_source.ts +61 -0
- package/src/services/tx_file_store/config.ts +37 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +42 -0
- package/src/services/tx_file_store/tx_file_store.ts +163 -0
- package/src/services/tx_provider.ts +237 -0
- package/src/services/tx_provider_instrumentation.ts +54 -0
- package/src/test-helpers/generate-peer-id-private-keys.ts +15 -0
- package/src/test-helpers/get-ports.ts +8 -0
- package/src/test-helpers/index.ts +8 -0
- package/src/test-helpers/make-enrs.ts +42 -0
- package/src/test-helpers/make-test-p2p-clients.ts +213 -0
- package/src/test-helpers/mock-pubsub.ts +325 -0
- package/src/test-helpers/mock-tx-helpers.ts +24 -0
- package/src/test-helpers/reqresp-nodes.ts +327 -0
- package/src/test-helpers/test_tx_provider.ts +68 -0
- package/src/test-helpers/testbench-utils.ts +465 -0
- package/src/testbench/README.md +20 -0
- package/src/testbench/p2p_client_testbench_worker.ts +553 -0
- package/src/testbench/parse_log_file.ts +174 -0
- package/src/testbench/testbench.ts +66 -0
- package/src/testbench/worker_client_manager.ts +621 -0
- package/src/types/index.ts +38 -0
- package/src/util.ts +230 -0
- package/src/versioning.ts +26 -0
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec-labs/epoch-cache';
|
|
2
|
+
import {
|
|
3
|
+
BlockNumber,
|
|
4
|
+
CheckpointNumber,
|
|
5
|
+
type CheckpointProposalHash,
|
|
6
|
+
SlotNumber,
|
|
7
|
+
} from '@aztec-labs/foundation/branded-types';
|
|
8
|
+
import { createLogger } from '@aztec-labs/foundation/log';
|
|
9
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec-labs/foundation/promise';
|
|
10
|
+
import { DateProvider } from '@aztec-labs/foundation/timer';
|
|
11
|
+
import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec-labs/kv-store';
|
|
12
|
+
import { L2TipsKVStore } from '@aztec-labs/kv-store/stores';
|
|
13
|
+
import {
|
|
14
|
+
type BlockData,
|
|
15
|
+
type BlockHash,
|
|
16
|
+
type CheckpointId,
|
|
17
|
+
type EthAddress,
|
|
18
|
+
EventDrivenL2BlockStream,
|
|
19
|
+
type L2Block,
|
|
20
|
+
type L2BlockId,
|
|
21
|
+
type L2BlockSource,
|
|
22
|
+
type L2BlockStreamEvent,
|
|
23
|
+
type L2TipsStore,
|
|
24
|
+
type LocalL2Tips,
|
|
25
|
+
} from '@aztec-labs/stdlib/block';
|
|
26
|
+
import type { ContractDataSource } from '@aztec-labs/stdlib/contract';
|
|
27
|
+
import { getTimestampForSlot } from '@aztec-labs/stdlib/epoch-helpers';
|
|
28
|
+
import {
|
|
29
|
+
type GetTxByHashOptions,
|
|
30
|
+
type P2PConnectivity,
|
|
31
|
+
type PeerInfo,
|
|
32
|
+
tryStop,
|
|
33
|
+
} from '@aztec-labs/stdlib/interfaces/server';
|
|
34
|
+
import {
|
|
35
|
+
type BlockProposal,
|
|
36
|
+
CheckpointAttestation,
|
|
37
|
+
type CheckpointProposal,
|
|
38
|
+
type TopicType,
|
|
39
|
+
} from '@aztec-labs/stdlib/p2p';
|
|
40
|
+
import type { BlockHeader, Tx, TxHash } from '@aztec-labs/stdlib/tx';
|
|
41
|
+
import {
|
|
42
|
+
Attributes,
|
|
43
|
+
type TelemetryClient,
|
|
44
|
+
WithTracer,
|
|
45
|
+
getTelemetryClient,
|
|
46
|
+
trackSpan,
|
|
47
|
+
} from '@aztec-labs/telemetry-client';
|
|
48
|
+
import type { PeerId } from '@libp2p/interface';
|
|
49
|
+
import type { ENR } from '@nethermindeth/enr';
|
|
50
|
+
|
|
51
|
+
import { type P2PConfig, getP2PDefaultConfig } from '../config.js';
|
|
52
|
+
import { TxPoolError } from '../errors/tx-pool.error.js';
|
|
53
|
+
import type { AttestationPoolApi, ProposalsForSlot } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
54
|
+
import type { MemPools } from '../mem_pools/interface.js';
|
|
55
|
+
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
56
|
+
import type { AuthRequest, StatusMessage } from '../services/index.js';
|
|
57
|
+
import { ReqRespSubProtocol, type ReqRespSubProtocolHandler } from '../services/reqresp/interface.js';
|
|
58
|
+
import type {
|
|
59
|
+
DuplicateAttestationInfo,
|
|
60
|
+
DuplicateProposalInfo,
|
|
61
|
+
OversizedProposalInfo,
|
|
62
|
+
P2PBlockReceivedCallback,
|
|
63
|
+
P2PCheckpointReceivedCallback,
|
|
64
|
+
P2PService,
|
|
65
|
+
} from '../services/service.js';
|
|
66
|
+
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
67
|
+
import type { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
|
|
68
|
+
import { TxProvider } from '../services/tx_provider.js';
|
|
69
|
+
import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The P2P client implementation.
|
|
73
|
+
*/
|
|
74
|
+
export class P2PClient extends WithTracer implements P2P {
|
|
75
|
+
/** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */
|
|
76
|
+
private runningPromise!: Promise<void>;
|
|
77
|
+
|
|
78
|
+
private currentState = P2PClientState.IDLE;
|
|
79
|
+
private syncPromise = Promise.resolve();
|
|
80
|
+
private syncResolvers?: PromiseWithResolvers<void> = undefined;
|
|
81
|
+
private latestBlockNumberAtStart = -1;
|
|
82
|
+
private provenBlockNumberAtStart = -1;
|
|
83
|
+
private finalizedBlockNumberAtStart = -1;
|
|
84
|
+
|
|
85
|
+
private l2Tips: L2TipsStore;
|
|
86
|
+
private synchedLatestSlot: AztecAsyncSingleton<bigint>;
|
|
87
|
+
|
|
88
|
+
private txPool: TxPoolV2;
|
|
89
|
+
private attestationPool: AttestationPoolApi;
|
|
90
|
+
|
|
91
|
+
private config: P2PConfig;
|
|
92
|
+
|
|
93
|
+
private blockStream: EventDrivenL2BlockStream | undefined;
|
|
94
|
+
|
|
95
|
+
private txProvider: TxProvider;
|
|
96
|
+
|
|
97
|
+
private validatorAddresses: EthAddress[] = [];
|
|
98
|
+
|
|
99
|
+
/** Tracks the last slot for which we called prepareForSlot */
|
|
100
|
+
private lastSlotProcessed: SlotNumber = SlotNumber.ZERO;
|
|
101
|
+
|
|
102
|
+
constructor(
|
|
103
|
+
private store: AztecAsyncKVStore,
|
|
104
|
+
private l2BlockSource: L2BlockSource & ContractDataSource,
|
|
105
|
+
mempools: MemPools,
|
|
106
|
+
private p2pService: P2PService,
|
|
107
|
+
private txCollection: TxCollection,
|
|
108
|
+
private txFileStore: TxFileStore | undefined,
|
|
109
|
+
private epochCache: EpochCacheInterface,
|
|
110
|
+
config: Partial<P2PConfig> = {},
|
|
111
|
+
private _dateProvider: DateProvider = new DateProvider(),
|
|
112
|
+
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
113
|
+
private log = createLogger('p2p'),
|
|
114
|
+
initialBlockHash: BlockHash,
|
|
115
|
+
) {
|
|
116
|
+
super(telemetry, 'P2PClient');
|
|
117
|
+
|
|
118
|
+
this.config = { ...getP2PDefaultConfig(), ...config };
|
|
119
|
+
this.txPool = mempools.txPool;
|
|
120
|
+
this.attestationPool = mempools.attestationPool;
|
|
121
|
+
|
|
122
|
+
this.txProvider = new TxProvider(
|
|
123
|
+
this.txCollection,
|
|
124
|
+
this.txPool,
|
|
125
|
+
this,
|
|
126
|
+
this.log.createChild('tx-provider'),
|
|
127
|
+
this.telemetry,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
this.l2Tips = new L2TipsKVStore(store, 'p2p_client', initialBlockHash);
|
|
131
|
+
this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public registerThisValidatorAddresses(addresses: EthAddress[]): void {
|
|
135
|
+
this.validatorAddresses = [...addresses];
|
|
136
|
+
this.p2pService.registerThisValidatorAddresses(this.validatorAddresses);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public clear(): Promise<void> {
|
|
140
|
+
return this.store.clear();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public isP2PClient(): true {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public getTxProvider(): TxProvider {
|
|
148
|
+
return this.txProvider;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public getPeers(includePending?: boolean): Promise<PeerInfo[]> {
|
|
152
|
+
return Promise.resolve(this.p2pService.getPeers(includePending));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public getP2PConnectivity(): Promise<P2PConnectivity> {
|
|
156
|
+
return Promise.resolve(this.p2pService.getP2PConnectivity());
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public getGossipMeshPeerCount(topicType: TopicType): Promise<number> {
|
|
160
|
+
return Promise.resolve(this.p2pService.getGossipMeshPeerCount(topicType));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public getL2BlockHash(number: BlockNumber): Promise<string | undefined> {
|
|
164
|
+
return this.l2Tips.getL2BlockHash(number);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public async updateP2PConfig(config: Partial<P2PConfig>): Promise<void> {
|
|
168
|
+
await this.txPool.updateConfig(config);
|
|
169
|
+
this.p2pService.updateConfig(config);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public getL2Tips(): Promise<LocalL2Tips> {
|
|
173
|
+
return this.l2Tips.getL2Tips();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public async handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
|
|
177
|
+
this.log.debug(`Handling block stream event ${event.type}`);
|
|
178
|
+
|
|
179
|
+
switch (event.type) {
|
|
180
|
+
case 'blocks-added':
|
|
181
|
+
await this.handleLatestL2Blocks(event.blocks);
|
|
182
|
+
break;
|
|
183
|
+
case 'chain-finalized': {
|
|
184
|
+
const oldFinalizedBlockNum = await this.getSyncedFinalizedBlockNum();
|
|
185
|
+
const from = BlockNumber(oldFinalizedBlockNum + 1);
|
|
186
|
+
const limit = event.block.number - from + 1;
|
|
187
|
+
if (limit > 0) {
|
|
188
|
+
const oldBlocks = await this.l2BlockSource.getBlocksData({ from, limit });
|
|
189
|
+
await this.handleFinalizedL2Blocks(oldBlocks);
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case 'chain-proven':
|
|
194
|
+
this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
|
|
195
|
+
break;
|
|
196
|
+
case 'chain-pruned':
|
|
197
|
+
this.txCollection.stopCollectingForBlocksAfter(event.block.number);
|
|
198
|
+
await this.handlePruneL2Blocks(event.block, event.checkpointed.checkpoint);
|
|
199
|
+
break;
|
|
200
|
+
case 'chain-checkpointed':
|
|
201
|
+
break;
|
|
202
|
+
case 'chain-proposed':
|
|
203
|
+
break;
|
|
204
|
+
default: {
|
|
205
|
+
const _: never = event;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Pass the event through to our l2 tips store
|
|
211
|
+
await this.l2Tips.handleBlockStreamEvent(event);
|
|
212
|
+
await this.startServiceIfSynched();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#assertIsReady() {
|
|
216
|
+
if (!this.isReady()) {
|
|
217
|
+
throw new Error('P2P client not ready');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Starts the P2P client.
|
|
223
|
+
* @returns An empty promise signalling the synching process.
|
|
224
|
+
*/
|
|
225
|
+
public async start() {
|
|
226
|
+
if (this.currentState === P2PClientState.STOPPED) {
|
|
227
|
+
throw new Error('P2P client already stopped');
|
|
228
|
+
}
|
|
229
|
+
if (this.currentState !== P2PClientState.IDLE) {
|
|
230
|
+
return this.syncPromise;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Start the tx pool first, as it needs to hydrate state from persistence
|
|
234
|
+
await this.txPool.start();
|
|
235
|
+
|
|
236
|
+
// get the current latest block numbers
|
|
237
|
+
const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
|
|
238
|
+
this.latestBlockNumberAtStart = latestBlockNumbers.proposed.number;
|
|
239
|
+
this.provenBlockNumberAtStart = latestBlockNumbers.proven.block.number;
|
|
240
|
+
this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.block.number;
|
|
241
|
+
|
|
242
|
+
const syncedLatestBlock = (await this.getSyncedLatestBlockNum()) + 1;
|
|
243
|
+
const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
|
|
244
|
+
const syncedFinalizedBlock = (await this.getSyncedFinalizedBlockNum()) + 1;
|
|
245
|
+
|
|
246
|
+
if ((await this.txPool.isEmpty()) && (await this.attestationPool.isEmpty())) {
|
|
247
|
+
// if mempools are empty, we don't care about syncing prior blocks
|
|
248
|
+
this.initBlockStream(BlockNumber(this.latestBlockNumberAtStart));
|
|
249
|
+
this.setCurrentState(P2PClientState.RUNNING);
|
|
250
|
+
this.syncPromise = Promise.resolve();
|
|
251
|
+
await this.p2pService.start();
|
|
252
|
+
this.log.info(`Starting p2p client from block ${this.latestBlockNumberAtStart} with empty mempools`);
|
|
253
|
+
} else if (
|
|
254
|
+
syncedLatestBlock <= this.latestBlockNumberAtStart ||
|
|
255
|
+
syncedProvenBlock <= this.provenBlockNumberAtStart ||
|
|
256
|
+
syncedFinalizedBlock <= this.finalizedBlockNumberAtStart
|
|
257
|
+
) {
|
|
258
|
+
// if there are blocks to be retrieved, go to a synching state
|
|
259
|
+
// this gets resolved on `startServiceIfSynched`
|
|
260
|
+
this.initBlockStream();
|
|
261
|
+
this.setCurrentState(P2PClientState.SYNCHING);
|
|
262
|
+
this.syncResolvers = promiseWithResolvers<void>();
|
|
263
|
+
this.syncPromise = this.syncResolvers.promise;
|
|
264
|
+
this.log.info(`Initiating p2p sync from ${syncedLatestBlock}`, {
|
|
265
|
+
syncedLatestBlock,
|
|
266
|
+
syncedProvenBlock,
|
|
267
|
+
syncedFinalizedBlock,
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
// if no blocks to be retrieved, go straight to running
|
|
271
|
+
this.initBlockStream();
|
|
272
|
+
this.setCurrentState(P2PClientState.RUNNING);
|
|
273
|
+
this.syncPromise = Promise.resolve();
|
|
274
|
+
await this.p2pService.start();
|
|
275
|
+
this.log.info(`Starting P2P client synced to ${syncedLatestBlock}`, {
|
|
276
|
+
syncedLatestBlock,
|
|
277
|
+
syncedProvenBlock,
|
|
278
|
+
syncedFinalizedBlock,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Should never happen: all branches above call initBlockStream()
|
|
283
|
+
if (!this.blockStream) {
|
|
284
|
+
throw new Error('Block stream not initialized');
|
|
285
|
+
}
|
|
286
|
+
this.blockStream.start();
|
|
287
|
+
this.txFileStore?.start();
|
|
288
|
+
|
|
289
|
+
return this.syncPromise;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
addReqRespSubProtocol(subProtocol: ReqRespSubProtocol, handler: ReqRespSubProtocolHandler): Promise<void> {
|
|
293
|
+
return this.p2pService.addReqRespSubProtocol(subProtocol, handler);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private initBlockStream(startingBlock?: BlockNumber) {
|
|
297
|
+
if (!this.blockStream) {
|
|
298
|
+
const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
|
|
299
|
+
this.blockStream = new EventDrivenL2BlockStream(
|
|
300
|
+
this.l2BlockSource,
|
|
301
|
+
this,
|
|
302
|
+
this,
|
|
303
|
+
createLogger(`${this.log.module}:l2-block-stream`),
|
|
304
|
+
{ batchSize, pollIntervalMS, startingBlock },
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Allows consumers to stop the instance of the P2P client.
|
|
311
|
+
* 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
|
|
312
|
+
*/
|
|
313
|
+
public async stop() {
|
|
314
|
+
this.log.debug('Stopping p2p client...');
|
|
315
|
+
await tryStop(this.txCollection);
|
|
316
|
+
this.log.debug('Stopped tx collection service');
|
|
317
|
+
await this.txFileStore?.stop();
|
|
318
|
+
this.log.debug('Stopped tx file store');
|
|
319
|
+
await this.p2pService.stop();
|
|
320
|
+
this.log.debug('Stopped p2p service');
|
|
321
|
+
await this.blockStream?.stop();
|
|
322
|
+
this.log.debug('Stopped block downloader');
|
|
323
|
+
await this.txPool.stop();
|
|
324
|
+
this.log.debug('Stopped tx pool');
|
|
325
|
+
await this.runningPromise;
|
|
326
|
+
this.setCurrentState(P2PClientState.STOPPED);
|
|
327
|
+
this.log.info('P2P client stopped');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Triggers a sync to the archiver. Used for testing. */
|
|
331
|
+
public async sync() {
|
|
332
|
+
this.initBlockStream();
|
|
333
|
+
// Should never happen: initBlockStream() creates blockStream if absent
|
|
334
|
+
if (!this.blockStream) {
|
|
335
|
+
throw new Error('Block stream not initialized');
|
|
336
|
+
}
|
|
337
|
+
await this.blockStream.sync();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
@trackSpan('p2pClient.broadcastProposal', async proposal => ({
|
|
341
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
342
|
+
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
343
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
344
|
+
}))
|
|
345
|
+
public async broadcastProposal(proposal: BlockProposal): Promise<void> {
|
|
346
|
+
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
|
|
347
|
+
// Store our own proposal so we can respond to req/resp requests for it
|
|
348
|
+
const { count } = await this.attestationPool.tryAddBlockProposal(proposal);
|
|
349
|
+
if (count > 1) {
|
|
350
|
+
if (this.config.broadcastEquivocatedProposals) {
|
|
351
|
+
this.log.warn(`Broadcasting equivocated block proposal for slot ${proposal.slotNumber}`, {
|
|
352
|
+
slot: proposal.slotNumber,
|
|
353
|
+
archive: proposal.archive.toString(),
|
|
354
|
+
count,
|
|
355
|
+
});
|
|
356
|
+
} else {
|
|
357
|
+
throw new Error(`Attempted to broadcast a duplicate block proposal for slot ${proposal.slotNumber}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return this.p2pService.propagate(proposal);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
@trackSpan('p2pClient.broadcastCheckpointProposal', async proposal => ({
|
|
364
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
365
|
+
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
366
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString(),
|
|
367
|
+
}))
|
|
368
|
+
public async broadcastCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
|
|
369
|
+
this.log.verbose(`Broadcasting checkpoint proposal for slot ${proposal.slotNumber} to peers`);
|
|
370
|
+
const blockProposal = proposal.getBlockProposal();
|
|
371
|
+
if (blockProposal) {
|
|
372
|
+
// Store our own last-block proposal so we can respond to req/resp requests for it.
|
|
373
|
+
await this.attestationPool.tryAddBlockProposal(blockProposal);
|
|
374
|
+
}
|
|
375
|
+
const checkpointCore = proposal.toCore();
|
|
376
|
+
const { count } = await this.attestationPool.tryAddCheckpointProposal(checkpointCore);
|
|
377
|
+
if (count > 1) {
|
|
378
|
+
if (this.config.broadcastEquivocatedProposals) {
|
|
379
|
+
this.log.warn(`Broadcasting equivocated checkpoint proposal for slot ${proposal.slotNumber}`, {
|
|
380
|
+
slot: proposal.slotNumber,
|
|
381
|
+
archive: proposal.archive.toString(),
|
|
382
|
+
count,
|
|
383
|
+
});
|
|
384
|
+
} else {
|
|
385
|
+
throw new Error(`Attempted to broadcast a duplicate checkpoint proposal for slot ${proposal.slotNumber}`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return this.p2pService.propagate(proposal);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
public async broadcastCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
392
|
+
this.log.verbose(`Broadcasting ${attestations.length} checkpoint attestations to peers`);
|
|
393
|
+
await Promise.all(attestations.map(att => this.p2pService.propagate(att)));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
public async getCheckpointAttestationsForSlot(
|
|
397
|
+
slot: SlotNumber,
|
|
398
|
+
proposalPayloadHash?: CheckpointProposalHash,
|
|
399
|
+
): Promise<CheckpointAttestation[]> {
|
|
400
|
+
return await (proposalPayloadHash
|
|
401
|
+
? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalPayloadHash)
|
|
402
|
+
: this.attestationPool.getCheckpointAttestationsForSlot(slot));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
public addOwnCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
406
|
+
return this.attestationPool.addOwnCheckpointAttestations(attestations);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public getProposalsForSlot(slot: SlotNumber): Promise<ProposalsForSlot> {
|
|
410
|
+
return this.attestationPool.getProposalsForSlot(slot);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
public hasBlockProposalsForSlot(slot: SlotNumber): Promise<boolean> {
|
|
414
|
+
return this.attestationPool.hasBlockProposalsForSlot(slot);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
public hasCheckpointProposalForSlot(slot: SlotNumber): Promise<boolean> {
|
|
418
|
+
return this.attestationPool.hasCheckpointProposalForSlot(slot);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
422
|
+
// ^ This pattern is not my favorite (md)
|
|
423
|
+
public registerBlockProposalHandler(handler: P2PBlockReceivedCallback): void {
|
|
424
|
+
this.p2pService.registerBlockReceivedCallback(handler);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
public registerValidatorCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
|
|
428
|
+
this.p2pService.registerValidatorCheckpointReceivedCallback(handler);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
public registerAllNodesCheckpointProposalHandler(handler: P2PCheckpointReceivedCallback): void {
|
|
432
|
+
this.p2pService.registerAllNodesCheckpointReceivedCallback(handler);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
public registerDuplicateProposalCallback(callback: (info: DuplicateProposalInfo) => void): void {
|
|
436
|
+
this.p2pService.registerDuplicateProposalCallback(callback);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
public registerOversizedProposalCallback(callback: (info: OversizedProposalInfo) => void): void {
|
|
440
|
+
this.p2pService.registerOversizedProposalCallback(callback);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
public registerDuplicateAttestationCallback(callback: (info: DuplicateAttestationInfo) => void): void {
|
|
444
|
+
this.p2pService.registerDuplicateAttestationCallback(callback);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
public registerCheckpointAttestationCallback(callback: (attestation: CheckpointAttestation) => void): void {
|
|
448
|
+
this.p2pService.registerCheckpointAttestationCallback(callback);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
public async getPendingTxs(limit?: number, after?: TxHash, options?: GetTxByHashOptions): Promise<Tx[]> {
|
|
452
|
+
if (limit !== undefined && limit <= 0) {
|
|
453
|
+
throw new TypeError('limit must be greater than 0');
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
let txHashes = await this.txPool.getPendingTxHashes();
|
|
457
|
+
|
|
458
|
+
let startIndex = 0;
|
|
459
|
+
if (after) {
|
|
460
|
+
startIndex = txHashes.findIndex(txHash => after.equals(txHash));
|
|
461
|
+
if (startIndex === -1) {
|
|
462
|
+
return [];
|
|
463
|
+
}
|
|
464
|
+
startIndex++;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const endIndex = limit !== undefined ? startIndex + limit : undefined;
|
|
468
|
+
txHashes = txHashes.slice(startIndex, endIndex);
|
|
469
|
+
|
|
470
|
+
// This is a public-facing API (exposed via both the node and the p2p RPC), so proofs are opt-in.
|
|
471
|
+
const includeProof = !!options?.includeProof;
|
|
472
|
+
const maybeTxs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash, { includeProof })));
|
|
473
|
+
return maybeTxs.filter((tx): tx is Tx => !!tx);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
public getPendingTxCount(): Promise<number> {
|
|
477
|
+
return this.txPool.getPendingTxCount();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
public hasEligiblePendingTxs(minCount: number): Promise<boolean> {
|
|
481
|
+
return this.txPool.hasEligiblePendingTxs(minCount);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
public async *iteratePendingTxs(opts?: { includeProof?: boolean }): AsyncIterableIterator<Tx> {
|
|
485
|
+
for (const txHash of await this.txPool.getPendingTxHashes()) {
|
|
486
|
+
const tx = await this.txPool.getTxByHash(txHash, opts);
|
|
487
|
+
if (tx) {
|
|
488
|
+
yield tx;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
public async *iterateEligiblePendingTxs(opts?: { includeProof?: boolean }): AsyncIterableIterator<Tx> {
|
|
494
|
+
for (const txHash of await this.txPool.getEligiblePendingTxHashes()) {
|
|
495
|
+
const tx = await this.txPool.getTxByHash(txHash, opts);
|
|
496
|
+
if (tx) {
|
|
497
|
+
yield tx;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Returns a transaction in the transaction pool by its hash.
|
|
504
|
+
* @param txHash - Hash of the transaction to look for in the pool.
|
|
505
|
+
* @param opts - Set `includeProof: false` to skip loading the tx proof from the DB.
|
|
506
|
+
* @returns A single tx or undefined.
|
|
507
|
+
*/
|
|
508
|
+
getTxByHashFromPool(txHash: TxHash, opts?: { includeProof?: boolean }): Promise<Tx | undefined> {
|
|
509
|
+
return this.txPool.getTxByHash(txHash, opts);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Returns transactions in the transaction pool by hash.
|
|
514
|
+
* @param txHashes - Hashes of the transactions to look for.
|
|
515
|
+
* @param opts - Set `includeProof: false` to skip loading tx proofs from the DB.
|
|
516
|
+
* @returns The txs found, in the same order as the requested hashes. If a tx is not found, it will be undefined.
|
|
517
|
+
*/
|
|
518
|
+
getTxsByHashFromPool(txHashes: TxHash[], opts?: { includeProof?: boolean }): Promise<(Tx | undefined)[]> {
|
|
519
|
+
return this.txPool.getTxsByHash(txHashes, opts);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
hasTxsInPool(txHashes: TxHash[]): Promise<boolean[]> {
|
|
523
|
+
return this.txPool.hasTxs(txHashes);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Returns an archived transaction in the transaction pool by its hash.
|
|
528
|
+
* @param txHash - Hash of the archived transaction to look for.
|
|
529
|
+
* @returns A single tx or undefined.
|
|
530
|
+
*/
|
|
531
|
+
getArchivedTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
532
|
+
return this.txPool.getArchivedTxByHash(txHash);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Accepts a transaction, adds it to local tx pool and forwards it to other peers.
|
|
537
|
+
* @param tx - The tx to send.
|
|
538
|
+
* @returns Empty promise.
|
|
539
|
+
**/
|
|
540
|
+
public async sendTx(tx: Tx): Promise<void> {
|
|
541
|
+
this.#assertIsReady();
|
|
542
|
+
const result = await this.txPool.addPendingTxs([tx], { feeComparisonOnly: true });
|
|
543
|
+
if (result.accepted.length === 1) {
|
|
544
|
+
await this.p2pService.propagate(tx);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const txHashStr = tx.getTxHash().toString();
|
|
549
|
+
const reason = result.errors?.get(txHashStr);
|
|
550
|
+
if (reason) {
|
|
551
|
+
this.log.warn(`Tx ${txHashStr} not added to pool: ${reason.message}`);
|
|
552
|
+
throw new TxPoolError(reason);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
this.log.warn(
|
|
556
|
+
`Tx ${txHashStr} not propagated: accepted=${result.accepted.length} ignored=${result.ignored.length} rejected=${result.rejected.length}`,
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Returns whether the given tx hash is flagged as pending or mined.
|
|
562
|
+
* @param txHash - Hash of the tx to query.
|
|
563
|
+
* @returns Pending or mined depending on its status, or undefined if not found.
|
|
564
|
+
*/
|
|
565
|
+
public async getTxStatus(txHash: TxHash): Promise<'pending' | 'mined' | 'deleted' | undefined> {
|
|
566
|
+
const status = await this.txPool.getTxStatus(txHash);
|
|
567
|
+
return status === 'protected' ? 'pending' : status;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
public getEnr(): ENR | undefined {
|
|
571
|
+
return this.p2pService.getEnr();
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
public getEncodedEnr(): Promise<string | undefined> {
|
|
575
|
+
return Promise.resolve(this.p2pService.getEnr()?.encodeTxt());
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Handles failed transaction execution by removing txs from the pool.
|
|
580
|
+
* @param txHashes - Hashes of the transactions that failed execution.
|
|
581
|
+
**/
|
|
582
|
+
public async handleFailedExecution(txHashes: TxHash[]): Promise<void> {
|
|
583
|
+
this.#assertIsReady();
|
|
584
|
+
await this.txPool.handleFailedExecution(txHashes);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Public function to check if the p2p client is fully synced and ready to receive txs.
|
|
589
|
+
* @returns True if the P2P client is ready to receive txs.
|
|
590
|
+
*/
|
|
591
|
+
public isReady() {
|
|
592
|
+
return this.currentState === P2PClientState.RUNNING;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Public function to check the latest block number that the P2P client is synced to.
|
|
597
|
+
* @returns Block number of latest L2 Block we've synced with.
|
|
598
|
+
*/
|
|
599
|
+
public async getSyncedLatestBlockNum(): Promise<BlockNumber> {
|
|
600
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
601
|
+
return tips.proposed.number;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Public function to check the latest proven block number that the P2P client is synced to.
|
|
606
|
+
* @returns Block number of latest proven L2 Block we've synced with.
|
|
607
|
+
*/
|
|
608
|
+
public async getSyncedProvenBlockNum(): Promise<BlockNumber> {
|
|
609
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
610
|
+
return tips.proven.block.number;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
public async getSyncedFinalizedBlockNum(): Promise<BlockNumber> {
|
|
614
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
615
|
+
return tips.finalized.block.number;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/** Returns latest L2 slot for which we have seen an L2 block. */
|
|
619
|
+
public async getSyncedLatestSlot(): Promise<bigint> {
|
|
620
|
+
return (await this.synchedLatestSlot.getAsync()) ?? BigInt(0);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Method to check the status the p2p client.
|
|
625
|
+
* @returns Information about p2p client status: state & syncedToBlockNum.
|
|
626
|
+
*/
|
|
627
|
+
public async getStatus(): Promise<P2PSyncState> {
|
|
628
|
+
const blockNumber = await this.getSyncedLatestBlockNum();
|
|
629
|
+
const blockHash = await this.l2BlockSource
|
|
630
|
+
.getBlockData({ number: blockNumber })
|
|
631
|
+
.then(data => data?.header.hash())
|
|
632
|
+
.then(hash => hash?.toString());
|
|
633
|
+
|
|
634
|
+
return {
|
|
635
|
+
state: this.currentState,
|
|
636
|
+
syncedToL2Block: { number: blockNumber, hash: blockHash! },
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Handles mined blocks by marking the txs in them as mined.
|
|
642
|
+
* @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
|
|
643
|
+
* @returns Empty promise.
|
|
644
|
+
*/
|
|
645
|
+
private async handleMinedBlocks(blocks: L2Block[]): Promise<void> {
|
|
646
|
+
for (const block of blocks) {
|
|
647
|
+
await this.txPool.handleMinedBlock(block);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Handles new mined blocks by marking the txs in them as mined.
|
|
653
|
+
* @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
|
|
654
|
+
* @returns Empty promise.
|
|
655
|
+
*/
|
|
656
|
+
private async handleLatestL2Blocks(blocks: L2Block[]): Promise<void> {
|
|
657
|
+
if (!blocks.length) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const lastBlock = blocks.at(-1)!;
|
|
662
|
+
const lastSlot = lastBlock.header.getSlot();
|
|
663
|
+
|
|
664
|
+
// Mark txs mined before releasing protections: a block landing at this slot supersedes any
|
|
665
|
+
// protection for txs it includes, so mined-marking must run first to keep just-landed txs from
|
|
666
|
+
// being unprotected into pending where they could be evicted before they are recorded as mined.
|
|
667
|
+
await this.handleMinedBlocks(blocks);
|
|
668
|
+
await this.maybeCallPrepareForSlot(lastSlot);
|
|
669
|
+
await this.collectingMissingTxs(blocks);
|
|
670
|
+
await this.synchedLatestSlot.set(BigInt(lastSlot));
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** Request txs for unproven blocks so the prover node can prove. */
|
|
674
|
+
private async collectingMissingTxs(blocks: L2Block[]): Promise<void> {
|
|
675
|
+
try {
|
|
676
|
+
// TODO(#15435): If the archiver has lagged behind L1, the reported proven block number may
|
|
677
|
+
// be much lower than the actual one, and it does not update until the pending chain is
|
|
678
|
+
// fully synced. This could lead to a ton of tx collection requests for blocks that
|
|
679
|
+
// are already proven, but the archiver has not yet updated its state. Until this is properly
|
|
680
|
+
// fixed, it is mitigated by the expiration date of collection requests, which depends on
|
|
681
|
+
// the slot number of the block.
|
|
682
|
+
const provenBlockNumber = (await this.l2BlockSource.getBlockNumber({ tag: 'proven' })) ?? BlockNumber.ZERO;
|
|
683
|
+
const unprovenBlocks = blocks.filter(block => block.number > provenBlockNumber);
|
|
684
|
+
for (const block of unprovenBlocks) {
|
|
685
|
+
const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
|
|
686
|
+
const missingTxHashes = await this.txPool
|
|
687
|
+
.hasTxs(txHashes)
|
|
688
|
+
.then(availability => txHashes.filter((_, index) => !availability[index]));
|
|
689
|
+
if (missingTxHashes.length > 0) {
|
|
690
|
+
this.log.verbose(
|
|
691
|
+
`Starting collection of ${missingTxHashes.length} missing txs for unproven mined block ${block.number}`,
|
|
692
|
+
{ missingTxHashes, blockNumber: block.number, blockHash: await block.hash().then(h => h.toString()) },
|
|
693
|
+
);
|
|
694
|
+
// Both `slashDataWithholdingToleranceSlots` and `p2pMissingTxCollectionDeadlineSlots`
|
|
695
|
+
// count *full slots after the block slot* — value N means collection runs until
|
|
696
|
+
// `slotStart(block.slot + N + 1)`. Take the larger of the two so collection never
|
|
697
|
+
// gives up before the data-withholding slash verdict is rendered.
|
|
698
|
+
const blockSlot = block.header.getSlot();
|
|
699
|
+
const toleranceSlots = this.config.slashDataWithholdingToleranceSlots;
|
|
700
|
+
const configuredSlots = this.config.p2pMissingTxCollectionDeadlineSlots ?? 0;
|
|
701
|
+
const deadlineSlot = SlotNumber(blockSlot + Math.max(toleranceSlots, configuredSlots) + 1);
|
|
702
|
+
const deadlineSeconds = getTimestampForSlot(deadlineSlot, this.epochCache.getL1Constants());
|
|
703
|
+
const deadline = new Date(Number(deadlineSeconds) * 1000);
|
|
704
|
+
await this.txCollection.collectFastForBlock(block, missingTxHashes, { deadline });
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
} catch (err) {
|
|
708
|
+
this.log.error(`Error while starting collection of missing txs for unproven blocks`, err);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Handles new finalized blocks by deleting the txs and attestations in them.
|
|
714
|
+
* @param blocks - A list of finalized L2 blocks.
|
|
715
|
+
* @returns Empty promise.
|
|
716
|
+
*/
|
|
717
|
+
private async handleFinalizedL2Blocks(blocks: BlockData[]): Promise<void> {
|
|
718
|
+
if (!blocks.length) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// Finalization is monotonic, so we only need to call with the last block
|
|
723
|
+
const lastBlock = blocks.at(-1)!;
|
|
724
|
+
await this.txPool.handleFinalizedBlock(lastBlock.header);
|
|
725
|
+
await this.attestationPool.deleteOlderThan(lastBlock.header.getSlot());
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Updates the tx pool after a chain prune.
|
|
730
|
+
* Detects epoch prunes (checkpoint number changed) and deletes all txs in that case.
|
|
731
|
+
* @param latestBlock - The block ID the chain was pruned to.
|
|
732
|
+
* @param newCheckpoint - The checkpoint ID after the prune.
|
|
733
|
+
*/
|
|
734
|
+
private async handlePruneL2Blocks(latestBlock: L2BlockId, newCheckpoint: CheckpointId): Promise<void> {
|
|
735
|
+
const deleteAllTxs = this.config.txPoolDeleteTxsAfterReorg && (await this.isEpochPrune(newCheckpoint));
|
|
736
|
+
await this.txPool.handlePrunedBlocks(latestBlock, { deleteAllTxs });
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Returns true if the prune is an epoch prune (new checkpoint number is less than old).
|
|
741
|
+
* If the checkpoint number stays the same or increases, the prune is within a checkpoint.
|
|
742
|
+
*/
|
|
743
|
+
private async isEpochPrune(newCheckpoint: CheckpointId): Promise<boolean> {
|
|
744
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
745
|
+
const oldCheckpointNumber = tips.checkpointed.checkpoint.number;
|
|
746
|
+
if (oldCheckpointNumber <= CheckpointNumber.INITIAL) {
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
const newCheckpointNumber = newCheckpoint.number;
|
|
750
|
+
// We check that the new checkpoint number is less than the old checkpoint number in order to consider it an epoch prune.
|
|
751
|
+
// To be more certain that it is an epoch prune, we will check that at least 2 checkpoints were removed.
|
|
752
|
+
// This means we should avoid thinking checkpoints removed by L1 re-orgs are epoch prunes
|
|
753
|
+
const thresholdForEpochPrune = CheckpointNumber(oldCheckpointNumber - 2);
|
|
754
|
+
const isEpochPrune = newCheckpointNumber <= thresholdForEpochPrune;
|
|
755
|
+
if (isEpochPrune) {
|
|
756
|
+
this.log.info(`Detected epoch prune to ${newCheckpointNumber}`, {
|
|
757
|
+
oldCheckpointNumber,
|
|
758
|
+
newCheckpointNumber,
|
|
759
|
+
thresholdForEpochPrune,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
return isEpochPrune;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/** Calls prepareForSlot for the given slot if it advances past the last slot we prepared for. */
|
|
766
|
+
private async maybeCallPrepareForSlot(slot: SlotNumber): Promise<void> {
|
|
767
|
+
if (slot <= this.lastSlotProcessed) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
this.lastSlotProcessed = slot;
|
|
771
|
+
await this.txPool.prepareForSlot(slot);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
private async startServiceIfSynched() {
|
|
775
|
+
if (this.currentState !== P2PClientState.SYNCHING) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
779
|
+
const syncedFinalizedBlock = tips.finalized.block.number;
|
|
780
|
+
const syncedProvenBlock = tips.proven.block.number;
|
|
781
|
+
const syncedLatestBlock = tips.proposed.number;
|
|
782
|
+
|
|
783
|
+
if (
|
|
784
|
+
syncedLatestBlock >= this.latestBlockNumberAtStart &&
|
|
785
|
+
syncedProvenBlock >= this.provenBlockNumberAtStart &&
|
|
786
|
+
syncedFinalizedBlock >= this.finalizedBlockNumberAtStart
|
|
787
|
+
) {
|
|
788
|
+
this.log.info(`Completed P2P client sync to block ${syncedLatestBlock}. Starting service.`, {
|
|
789
|
+
syncedLatestBlock,
|
|
790
|
+
syncedProvenBlock,
|
|
791
|
+
syncedFinalizedBlock,
|
|
792
|
+
});
|
|
793
|
+
this.setCurrentState(P2PClientState.RUNNING);
|
|
794
|
+
if (this.syncResolvers !== undefined) {
|
|
795
|
+
// A throw here would be swallowed by the block stream event handler, so we reject the promise returned by
|
|
796
|
+
// start instead, which makes node startup fail rather than run on with a dead p2p stack.
|
|
797
|
+
try {
|
|
798
|
+
await this.p2pService.start();
|
|
799
|
+
} catch (err) {
|
|
800
|
+
this.log.fatal(`Failed to start p2p service`, { err, syncedLatestBlock });
|
|
801
|
+
this.syncResolvers.reject(err);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
this.syncResolvers.resolve();
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Method to set the value of the current state.
|
|
811
|
+
* @param newState - New state value.
|
|
812
|
+
*/
|
|
813
|
+
private setCurrentState(newState: P2PClientState) {
|
|
814
|
+
const oldState = this.currentState;
|
|
815
|
+
this.currentState = newState;
|
|
816
|
+
this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
public validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
820
|
+
return this.p2pService.validateTxsReceivedInBlockProposal(txs);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Protects existing transactions by hash for a given slot.
|
|
825
|
+
* Returns hashes of transactions that weren't found in the pool.
|
|
826
|
+
* @param txHashes - Hashes of the transactions to protect.
|
|
827
|
+
* @param blockHeader - The block header providing slot context.
|
|
828
|
+
* @returns Hashes of transactions not found in the pool.
|
|
829
|
+
*/
|
|
830
|
+
public protectTxs(txHashes: TxHash[], blockHeader: BlockHeader): Promise<TxHash[]> {
|
|
831
|
+
return this.txPool.protectTxs(txHashes, blockHeader);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Prepares the pool for a new slot.
|
|
836
|
+
* Unprotects transactions from earlier slots and validates them.
|
|
837
|
+
* @param slotNumber - The slot number to prepare for
|
|
838
|
+
*/
|
|
839
|
+
public async prepareForSlot(slotNumber: SlotNumber): Promise<void> {
|
|
840
|
+
await this.txPool.prepareForSlot(slotNumber);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
public handleAuthRequestFromPeer(authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage> {
|
|
844
|
+
return this.p2pService.handleAuthRequestFromPeer(authRequest, peerId);
|
|
845
|
+
}
|
|
846
|
+
}
|