@aztec/p2p 0.0.0-test.1 → 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
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
5
|
-
import { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
6
|
+
import { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
6
7
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
|
|
10
|
+
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
9
11
|
import type { AttestationPool } from './attestation_pool.js';
|
|
10
12
|
|
|
13
|
+
export const MAX_PROPOSALS_PER_SLOT = 5;
|
|
14
|
+
export const ATTESTATION_CAP_BUFFER = 10;
|
|
15
|
+
|
|
11
16
|
export class KvAttestationPool implements AttestationPool {
|
|
12
17
|
private metrics: PoolInstrumentation<BlockAttestation>;
|
|
13
18
|
|
|
14
19
|
private attestations: AztecAsyncMap<string, Buffer>;
|
|
15
|
-
private
|
|
20
|
+
private proposals: AztecAsyncMap<
|
|
21
|
+
/* proposal.payload.archive */ string,
|
|
22
|
+
/* buffer representation of proposal */ Buffer
|
|
23
|
+
>;
|
|
24
|
+
private proposalsForSlot: AztecAsyncMultiMap<number, string>;
|
|
16
25
|
private attestationsForProposal: AztecAsyncMultiMap<string, string>;
|
|
17
26
|
|
|
18
27
|
constructor(
|
|
@@ -21,10 +30,24 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
21
30
|
private log = createLogger('aztec:attestation_pool'),
|
|
22
31
|
) {
|
|
23
32
|
this.attestations = store.openMap('attestations');
|
|
33
|
+
this.proposals = store.openMap('proposals');
|
|
24
34
|
this.proposalsForSlot = store.openMultiMap('proposals_for_slot');
|
|
25
35
|
this.attestationsForProposal = store.openMultiMap('attestations_for_proposal');
|
|
26
36
|
|
|
27
|
-
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL);
|
|
37
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL, this.poolStats);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private poolStats: PoolStatsCallback = async () => {
|
|
41
|
+
return {
|
|
42
|
+
itemCount: await this.attestations.sizeAsync(),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
public async isEmpty(): Promise<boolean> {
|
|
47
|
+
for await (const _ of this.attestations.entriesAsync()) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
28
51
|
}
|
|
29
52
|
|
|
30
53
|
private getProposalKey(slot: number | bigint | Fr | string, proposalId: Fr | string | Buffer): string {
|
|
@@ -33,8 +56,8 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
33
56
|
typeof proposalId === 'string'
|
|
34
57
|
? proposalId
|
|
35
58
|
: Buffer.isBuffer(proposalId)
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
? Fr.fromBuffer(proposalId).toString()
|
|
60
|
+
: proposalId.toString();
|
|
38
61
|
|
|
39
62
|
return `${slotStr}-${proposalIdStr}`;
|
|
40
63
|
}
|
|
@@ -46,26 +69,52 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
46
69
|
public async addAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
47
70
|
await this.store.transactionAsync(async () => {
|
|
48
71
|
for (const attestation of attestations) {
|
|
49
|
-
const slotNumber = attestation.payload.header.
|
|
72
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
50
73
|
const proposalId = attestation.archive;
|
|
51
|
-
const
|
|
74
|
+
const sender = attestation.getSender();
|
|
75
|
+
|
|
76
|
+
// Skip attestations with invalid signatures
|
|
77
|
+
if (!sender) {
|
|
78
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber}`, {
|
|
79
|
+
signature: attestation.signature.toString(),
|
|
80
|
+
slotNumber,
|
|
81
|
+
proposalId,
|
|
82
|
+
});
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const address = sender.toString();
|
|
52
87
|
|
|
53
88
|
await this.attestations.set(this.getAttestationKey(slotNumber, proposalId, address), attestation.toBuffer());
|
|
54
89
|
|
|
55
|
-
await this.proposalsForSlot.set(slotNumber
|
|
90
|
+
await this.proposalsForSlot.set(slotNumber, proposalId.toString());
|
|
56
91
|
await this.attestationsForProposal.set(
|
|
57
92
|
this.getProposalKey(slotNumber, proposalId),
|
|
58
93
|
this.getAttestationKey(slotNumber, proposalId, address),
|
|
59
94
|
);
|
|
60
95
|
|
|
61
|
-
this.log.verbose(`Added attestation for slot ${slotNumber} from ${address}
|
|
96
|
+
this.log.verbose(`Added attestation for slot ${slotNumber} from ${address}`, {
|
|
97
|
+
signature: attestation.signature.toString(),
|
|
98
|
+
slotNumber,
|
|
99
|
+
address,
|
|
100
|
+
proposalId,
|
|
101
|
+
});
|
|
62
102
|
}
|
|
63
103
|
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public async getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]> {
|
|
107
|
+
const proposalIds = await toArray(this.proposalsForSlot.getValuesAsync(slot));
|
|
108
|
+
const attestations: BlockAttestation[] = [];
|
|
64
109
|
|
|
65
|
-
|
|
110
|
+
for (const proposalId of proposalIds) {
|
|
111
|
+
attestations.push(...(await this.getAttestationsForSlotAndProposal(slot, proposalId)));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return attestations;
|
|
66
115
|
}
|
|
67
116
|
|
|
68
|
-
public async
|
|
117
|
+
public async getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]> {
|
|
69
118
|
const attestationIds = await toArray(
|
|
70
119
|
this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)),
|
|
71
120
|
);
|
|
@@ -87,21 +136,20 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
87
136
|
return attestations;
|
|
88
137
|
}
|
|
89
138
|
|
|
90
|
-
public async deleteAttestationsOlderThan(oldestSlot:
|
|
91
|
-
const olderThan = await toArray(this.proposalsForSlot.keysAsync({ end:
|
|
139
|
+
public async deleteAttestationsOlderThan(oldestSlot: SlotNumber): Promise<void> {
|
|
140
|
+
const olderThan = await toArray(this.proposalsForSlot.keysAsync({ end: oldestSlot }));
|
|
92
141
|
for (const oldSlot of olderThan) {
|
|
93
|
-
await this.deleteAttestationsForSlot(
|
|
142
|
+
await this.deleteAttestationsForSlot(SlotNumber(oldSlot));
|
|
94
143
|
}
|
|
95
144
|
}
|
|
96
145
|
|
|
97
|
-
public async deleteAttestationsForSlot(slot:
|
|
98
|
-
const slotFr = new Fr(slot);
|
|
146
|
+
public async deleteAttestationsForSlot(slot: SlotNumber): Promise<void> {
|
|
99
147
|
let numberOfAttestations = 0;
|
|
100
148
|
await this.store.transactionAsync(async () => {
|
|
101
|
-
const proposalIds = await toArray(this.proposalsForSlot.getValuesAsync(
|
|
149
|
+
const proposalIds = await toArray(this.proposalsForSlot.getValuesAsync(slot));
|
|
102
150
|
for (const proposalId of proposalIds) {
|
|
103
151
|
const attestations = await toArray(
|
|
104
|
-
this.attestationsForProposal.getValuesAsync(this.getProposalKey(
|
|
152
|
+
this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)),
|
|
105
153
|
);
|
|
106
154
|
|
|
107
155
|
numberOfAttestations += attestations.length;
|
|
@@ -109,18 +157,20 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
109
157
|
await this.attestations.delete(attestation);
|
|
110
158
|
}
|
|
111
159
|
|
|
112
|
-
await this.
|
|
160
|
+
await this.proposals.delete(proposalId);
|
|
161
|
+
await this.attestationsForProposal.delete(this.getProposalKey(slot, proposalId));
|
|
113
162
|
}
|
|
114
|
-
});
|
|
115
163
|
|
|
116
|
-
|
|
117
|
-
|
|
164
|
+
// Delete from proposalsForSlot
|
|
165
|
+
await this.proposalsForSlot.delete(slot);
|
|
166
|
+
|
|
167
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot}`);
|
|
168
|
+
});
|
|
118
169
|
}
|
|
119
170
|
|
|
120
|
-
public async deleteAttestationsForSlotAndProposal(slot:
|
|
171
|
+
public async deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void> {
|
|
121
172
|
let numberOfAttestations = 0;
|
|
122
173
|
await this.store.transactionAsync(async () => {
|
|
123
|
-
const slotString = new Fr(slot).toString();
|
|
124
174
|
const attestations = await toArray(
|
|
125
175
|
this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)),
|
|
126
176
|
);
|
|
@@ -130,22 +180,34 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
130
180
|
await this.attestations.delete(attestation);
|
|
131
181
|
}
|
|
132
182
|
|
|
133
|
-
await this.
|
|
134
|
-
await this.
|
|
135
|
-
|
|
183
|
+
await this.proposals.delete(proposalId);
|
|
184
|
+
await this.proposalsForSlot.deleteValue(slot, proposalId);
|
|
185
|
+
await this.attestationsForProposal.delete(this.getProposalKey(slot, proposalId));
|
|
136
186
|
|
|
137
|
-
|
|
138
|
-
|
|
187
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot} and proposal ${proposalId}`);
|
|
188
|
+
});
|
|
139
189
|
}
|
|
140
190
|
|
|
141
191
|
public async deleteAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
142
192
|
await this.store.transactionAsync(async () => {
|
|
143
193
|
for (const attestation of attestations) {
|
|
144
|
-
const slotNumber = attestation.payload.header.
|
|
194
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
145
195
|
const proposalId = attestation.archive;
|
|
146
|
-
const
|
|
196
|
+
const sender = attestation.getSender();
|
|
197
|
+
|
|
198
|
+
// Skip attestations with invalid signatures
|
|
199
|
+
if (!sender) {
|
|
200
|
+
this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber}`);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const address = sender.toString();
|
|
205
|
+
const key = this.getAttestationKey(slotNumber, proposalId, address);
|
|
206
|
+
|
|
207
|
+
if (await this.attestations.hasAsync(key)) {
|
|
208
|
+
await this.attestations.delete(key);
|
|
209
|
+
}
|
|
147
210
|
|
|
148
|
-
await this.attestations.delete(this.getAttestationKey(slotNumber, proposalId, address));
|
|
149
211
|
await this.attestationsForProposal.deleteValue(
|
|
150
212
|
this.getProposalKey(slotNumber, proposalId),
|
|
151
213
|
this.getAttestationKey(slotNumber, proposalId, address),
|
|
@@ -154,6 +216,83 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
154
216
|
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${address}`);
|
|
155
217
|
}
|
|
156
218
|
});
|
|
157
|
-
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public async hasAttestation(attestation: BlockAttestation): Promise<boolean> {
|
|
222
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
223
|
+
const proposalId = attestation.archive;
|
|
224
|
+
const sender = attestation.getSender();
|
|
225
|
+
|
|
226
|
+
// Attestations with invalid signatures are never in the pool
|
|
227
|
+
if (!sender) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const address = sender.toString();
|
|
232
|
+
const key = this.getAttestationKey(slotNumber, proposalId, address);
|
|
233
|
+
|
|
234
|
+
return await this.attestations.hasAsync(key);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public async getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
238
|
+
const buffer = await this.proposals.getAsync(id);
|
|
239
|
+
try {
|
|
240
|
+
if (buffer && buffer.length > 0) {
|
|
241
|
+
return BlockProposal.fromBuffer(buffer);
|
|
242
|
+
}
|
|
243
|
+
} catch {
|
|
244
|
+
return Promise.resolve(undefined);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return Promise.resolve(undefined);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public async hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
251
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
|
|
252
|
+
return await this.proposals.hasAsync(id);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public async addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
256
|
+
await this.store.transactionAsync(async () => {
|
|
257
|
+
const slotKey = blockProposal.slotNumber;
|
|
258
|
+
const proposalId = blockProposal.archive.toString();
|
|
259
|
+
|
|
260
|
+
if (!(await this.canAddProposal(blockProposal))) {
|
|
261
|
+
throw new ProposalSlotCapExceededError(
|
|
262
|
+
`Maximum proposals per slot reached: slot=${slotKey} cap=${MAX_PROPOSALS_PER_SLOT} proposal=${proposalId}`,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
await this.proposalsForSlot.set(slotKey, proposalId);
|
|
267
|
+
// Always update the stored proposal buffer so re-adds overwrite with latest data
|
|
268
|
+
await this.proposals.set(proposalId, blockProposal.toBuffer());
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public async hasReachedProposalCap(slot: SlotNumber): Promise<boolean> {
|
|
273
|
+
const uniqueProposalCount = await this.proposalsForSlot.getValueCountAsync(slot);
|
|
274
|
+
return uniqueProposalCount >= MAX_PROPOSALS_PER_SLOT;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public async hasReachedAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean> {
|
|
278
|
+
const limit = committeeSize + ATTESTATION_CAP_BUFFER;
|
|
279
|
+
return (await this.attestationsForProposal.getValueCountAsync(this.getProposalKey(slot, proposalId))) >= limit;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public async canAddProposal(block: BlockProposal): Promise<boolean> {
|
|
283
|
+
return (
|
|
284
|
+
(await this.proposals.hasAsync(block.archive.toString())) || !(await this.hasReachedProposalCap(block.slotNumber))
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
public async canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean> {
|
|
289
|
+
return (
|
|
290
|
+
(await this.hasAttestation(attestation)) ||
|
|
291
|
+
!(await this.hasReachedAttestationCap(
|
|
292
|
+
attestation.payload.header.slotNumber,
|
|
293
|
+
attestation.archive.toString(),
|
|
294
|
+
committeeSize,
|
|
295
|
+
))
|
|
296
|
+
);
|
|
158
297
|
}
|
|
159
298
|
}
|
|
@@ -1,21 +1,50 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
3
|
+
import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
3
4
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
5
|
|
|
5
|
-
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
6
|
+
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
6
7
|
import type { AttestationPool } from './attestation_pool.js';
|
|
8
|
+
import { ATTESTATION_CAP_BUFFER, MAX_PROPOSALS_PER_SLOT } from './kv_attestation_pool.js';
|
|
7
9
|
|
|
8
10
|
export class InMemoryAttestationPool implements AttestationPool {
|
|
9
11
|
private metrics: PoolInstrumentation<BlockAttestation>;
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
14
|
+
private attestations: Map<
|
|
15
|
+
/*slot=*/ SlotNumber,
|
|
16
|
+
Map</*proposalId*/ string, Map</*address=*/ string, BlockAttestation>>
|
|
17
|
+
>;
|
|
18
|
+
private proposals: Map<string, BlockProposal>;
|
|
12
19
|
|
|
13
|
-
constructor(
|
|
20
|
+
constructor(
|
|
21
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
22
|
+
private log = createLogger('p2p:attestation_pool'),
|
|
23
|
+
) {
|
|
14
24
|
this.attestations = new Map();
|
|
15
|
-
this.
|
|
25
|
+
this.proposals = new Map();
|
|
26
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL, this.poolStats);
|
|
16
27
|
}
|
|
17
28
|
|
|
18
|
-
|
|
29
|
+
private poolStats: PoolStatsCallback = () => {
|
|
30
|
+
return Promise.resolve({
|
|
31
|
+
itemCount: this.attestations.size,
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
public isEmpty(): Promise<boolean> {
|
|
36
|
+
return Promise.resolve(this.attestations.size === 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public getAttestationsForSlot(slot: SlotNumber): Promise<BlockAttestation[]> {
|
|
40
|
+
return Promise.resolve(
|
|
41
|
+
Array.from(this.attestations.get(slot)?.values() ?? []).flatMap(proposalAttestationMap =>
|
|
42
|
+
Array.from(proposalAttestationMap.values()),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public getAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<BlockAttestation[]> {
|
|
19
48
|
const slotAttestationMap = this.attestations.get(slot);
|
|
20
49
|
if (slotAttestationMap) {
|
|
21
50
|
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
@@ -26,27 +55,40 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
26
55
|
return Promise.resolve([]);
|
|
27
56
|
}
|
|
28
57
|
|
|
29
|
-
public
|
|
58
|
+
public addAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
30
59
|
for (const attestation of attestations) {
|
|
31
60
|
// Perf: order and group by slot before insertion
|
|
32
|
-
const slotNumber = attestation.payload.header.
|
|
61
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
33
62
|
|
|
34
63
|
const proposalId = attestation.archive.toString();
|
|
35
|
-
const
|
|
64
|
+
const sender = attestation.getSender();
|
|
36
65
|
|
|
37
|
-
|
|
66
|
+
// Skip attestations with invalid signatures
|
|
67
|
+
if (!sender) {
|
|
68
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber}`, {
|
|
69
|
+
signature: attestation.signature.toString(),
|
|
70
|
+
slotNumber,
|
|
71
|
+
proposalId,
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber);
|
|
38
77
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
39
|
-
proposalAttestationMap.set(
|
|
78
|
+
proposalAttestationMap.set(sender.toString(), attestation);
|
|
40
79
|
|
|
41
|
-
this.log.verbose(`Added attestation for slot ${slotNumber} from ${
|
|
80
|
+
this.log.verbose(`Added attestation for slot ${slotNumber} from ${sender}`, {
|
|
81
|
+
signature: attestation.signature.toString(),
|
|
82
|
+
slotNumber,
|
|
83
|
+
address: sender,
|
|
84
|
+
proposalId,
|
|
85
|
+
});
|
|
42
86
|
}
|
|
43
87
|
|
|
44
|
-
// TODO: set these to pending or something ????
|
|
45
|
-
this.metrics.recordAddedObjects(attestations.length);
|
|
46
88
|
return Promise.resolve();
|
|
47
89
|
}
|
|
48
90
|
|
|
49
|
-
#getNumberOfAttestationsInSlot(slot:
|
|
91
|
+
#getNumberOfAttestationsInSlot(slot: SlotNumber): number {
|
|
50
92
|
let total = 0;
|
|
51
93
|
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
52
94
|
|
|
@@ -58,7 +100,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
58
100
|
return total;
|
|
59
101
|
}
|
|
60
102
|
|
|
61
|
-
public async deleteAttestationsOlderThan(oldestSlot:
|
|
103
|
+
public async deleteAttestationsOlderThan(oldestSlot: SlotNumber): Promise<void> {
|
|
62
104
|
const olderThan = [];
|
|
63
105
|
|
|
64
106
|
// Entries are iterated in insertion order, so we can break as soon as we find a slot that is older than the oldestSlot.
|
|
@@ -79,18 +121,25 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
79
121
|
return Promise.resolve();
|
|
80
122
|
}
|
|
81
123
|
|
|
82
|
-
public deleteAttestationsForSlot(slot:
|
|
124
|
+
public deleteAttestationsForSlot(slot: SlotNumber): Promise<void> {
|
|
83
125
|
// We count the number of attestations we are removing
|
|
84
126
|
const numberOfAttestations = this.#getNumberOfAttestationsInSlot(slot);
|
|
127
|
+
const proposalIdsToDelete = this.attestations.get(slot)?.keys();
|
|
128
|
+
let proposalIdsToDeleteCount = 0;
|
|
129
|
+
proposalIdsToDelete?.forEach(proposalId => {
|
|
130
|
+
this.proposals.delete(proposalId);
|
|
131
|
+
proposalIdsToDeleteCount++;
|
|
132
|
+
});
|
|
85
133
|
|
|
86
134
|
this.attestations.delete(slot);
|
|
87
|
-
this.log.verbose(
|
|
135
|
+
this.log.verbose(
|
|
136
|
+
`Removed ${numberOfAttestations} attestations and ${proposalIdsToDeleteCount} proposals for slot ${slot}`,
|
|
137
|
+
);
|
|
88
138
|
|
|
89
|
-
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
90
139
|
return Promise.resolve();
|
|
91
140
|
}
|
|
92
141
|
|
|
93
|
-
public deleteAttestationsForSlotAndProposal(slot:
|
|
142
|
+
public deleteAttestationsForSlotAndProposal(slot: SlotNumber, proposalId: string): Promise<void> {
|
|
94
143
|
const slotAttestationMap = getSlotOrDefault(this.attestations, slot);
|
|
95
144
|
if (slotAttestationMap) {
|
|
96
145
|
if (slotAttestationMap.has(proposalId)) {
|
|
@@ -99,29 +148,105 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
99
148
|
slotAttestationMap.delete(proposalId);
|
|
100
149
|
|
|
101
150
|
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot} and proposal ${proposalId}`);
|
|
102
|
-
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
103
151
|
}
|
|
104
152
|
}
|
|
153
|
+
|
|
154
|
+
this.proposals.delete(proposalId);
|
|
105
155
|
return Promise.resolve();
|
|
106
156
|
}
|
|
107
157
|
|
|
108
|
-
public
|
|
158
|
+
public deleteAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
109
159
|
for (const attestation of attestations) {
|
|
110
|
-
const slotNumber = attestation.payload.header.
|
|
111
|
-
const slotAttestationMap = this.attestations.get(slotNumber
|
|
160
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
161
|
+
const slotAttestationMap = this.attestations.get(slotNumber);
|
|
112
162
|
if (slotAttestationMap) {
|
|
113
163
|
const proposalId = attestation.archive.toString();
|
|
114
164
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
115
165
|
if (proposalAttestationMap) {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
166
|
+
const sender = attestation.getSender();
|
|
167
|
+
|
|
168
|
+
// Skip attestations with invalid signatures
|
|
169
|
+
if (!sender) {
|
|
170
|
+
this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber}`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
proposalAttestationMap.delete(sender.toString());
|
|
175
|
+
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${sender}`);
|
|
119
176
|
}
|
|
120
177
|
}
|
|
121
178
|
}
|
|
122
|
-
this.metrics.recordRemovedObjects(attestations.length);
|
|
123
179
|
return Promise.resolve();
|
|
124
180
|
}
|
|
181
|
+
|
|
182
|
+
public hasAttestation(attestation: BlockAttestation): Promise<boolean> {
|
|
183
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
184
|
+
const proposalId = attestation.archive.toString();
|
|
185
|
+
const sender = attestation.getSender();
|
|
186
|
+
|
|
187
|
+
// Attestations with invalid signatures are never in the pool
|
|
188
|
+
if (!sender) {
|
|
189
|
+
return Promise.resolve(false);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const slotAttestationMap = this.attestations.get(slotNumber);
|
|
193
|
+
if (!slotAttestationMap) {
|
|
194
|
+
return Promise.resolve(false);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
198
|
+
if (!proposalAttestationMap) {
|
|
199
|
+
return Promise.resolve(false);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return Promise.resolve(proposalAttestationMap.has(sender.toString()));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
public addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
206
|
+
// We initialize slot-proposal mapping if it does not exist
|
|
207
|
+
// This is important to ensure we can delete this proposal if there were not attestations for it
|
|
208
|
+
const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber);
|
|
209
|
+
slotProposalMapping.set(blockProposal.payload.archive.toString(), new Map<string, BlockAttestation>());
|
|
210
|
+
|
|
211
|
+
this.proposals.set(blockProposal.payload.archive.toString(), blockProposal);
|
|
212
|
+
return Promise.resolve();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
216
|
+
return Promise.resolve(this.proposals.get(id));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
220
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
|
|
221
|
+
return Promise.resolve(this.proposals.has(id));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public hasReachedProposalCap(slot: SlotNumber): Promise<boolean> {
|
|
225
|
+
const slotAttestationMap = this.attestations.get(slot);
|
|
226
|
+
const proposalCount = slotAttestationMap?.size ?? 0;
|
|
227
|
+
return Promise.resolve(proposalCount >= MAX_PROPOSALS_PER_SLOT);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public hasReachedAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean> {
|
|
231
|
+
const limit = committeeSize + ATTESTATION_CAP_BUFFER;
|
|
232
|
+
const count = this.attestations.get(slot)?.get(proposalId)?.size ?? 0;
|
|
233
|
+
return Promise.resolve(limit <= 0 || count >= limit);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public async canAddProposal(block: BlockProposal): Promise<boolean> {
|
|
237
|
+
return this.proposals.has(block.archive.toString()) || !(await this.hasReachedProposalCap(block.slotNumber));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public async canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean> {
|
|
241
|
+
const sender = attestation.getSender();
|
|
242
|
+
const slot = attestation.payload.header.slotNumber;
|
|
243
|
+
const pid = attestation.archive.toString();
|
|
244
|
+
return (
|
|
245
|
+
!!sender &&
|
|
246
|
+
((this.attestations.get(slot)?.get(pid)?.has(sender.toString()) ?? false) ||
|
|
247
|
+
!(await this.hasReachedAttestationCap(slot, pid, committeeSize)))
|
|
248
|
+
);
|
|
249
|
+
}
|
|
125
250
|
}
|
|
126
251
|
|
|
127
252
|
/**
|
|
@@ -133,8 +258,9 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
133
258
|
* @returns The slot mapping
|
|
134
259
|
*/
|
|
135
260
|
function getSlotOrDefault(
|
|
136
|
-
|
|
137
|
-
|
|
261
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
262
|
+
map: Map<SlotNumber, Map<string, Map<string, BlockAttestation>>>,
|
|
263
|
+
slot: SlotNumber,
|
|
138
264
|
): Map<string, Map<string, BlockAttestation>> {
|
|
139
265
|
if (!map.has(slot)) {
|
|
140
266
|
map.set(slot, new Map<string, Map<string, BlockAttestation>>());
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import {
|
|
4
4
|
BlockAttestation,
|
|
5
5
|
ConsensusPayload,
|
|
6
6
|
SignatureDomainSeparator,
|
|
7
7
|
getHashedSignaturePayloadEthSignedMessage,
|
|
8
8
|
} from '@aztec/stdlib/p2p';
|
|
9
|
-
import {
|
|
10
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
9
|
+
import { makeL2BlockHeader } from '@aztec/stdlib/testing';
|
|
11
10
|
|
|
12
11
|
import { type LocalAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
13
12
|
|
|
@@ -27,18 +26,20 @@ export const generateAccount = (): LocalAccount => {
|
|
|
27
26
|
* @param slot The slot number the attestation is for
|
|
28
27
|
* @returns A Block Attestation
|
|
29
28
|
*/
|
|
30
|
-
export const mockAttestation =
|
|
29
|
+
export const mockAttestation = (
|
|
31
30
|
signer: Secp256k1Signer,
|
|
32
31
|
slot: number = 0,
|
|
33
32
|
archive: Fr = Fr.random(),
|
|
34
|
-
|
|
35
|
-
): Promise<BlockAttestation> => {
|
|
33
|
+
): BlockAttestation => {
|
|
36
34
|
// Use arbitrary numbers for all other than slot
|
|
37
|
-
const header =
|
|
38
|
-
const payload = new ConsensusPayload(header, archive
|
|
35
|
+
const header = makeL2BlockHeader(1, 2, slot);
|
|
36
|
+
const payload = new ConsensusPayload(header.toCheckpointHeader(), archive);
|
|
39
37
|
|
|
40
|
-
const
|
|
41
|
-
const
|
|
38
|
+
const attestationHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation);
|
|
39
|
+
const attestationSignature = signer.sign(attestationHash);
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
|
|
42
|
+
const proposerSignature = signer.sign(proposalHash);
|
|
43
|
+
|
|
44
|
+
return new BlockAttestation(payload, attestationSignature, proposerSignature);
|
|
44
45
|
};
|