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