@aztec/p2p 0.0.0-test.0 → 0.0.1-commit.24de95ac
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.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -9
- package/dest/client/factory.d.ts +13 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -24
- package/dest/client/index.d.ts +1 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +155 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +72 -169
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +365 -174
- package/dest/config.d.ts +123 -103
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +173 -34
- package/dest/enr/generate-enr.d.ts +10 -2
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/index.d.ts +3 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +42 -4
- 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.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +204 -54
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +93 -15
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +10 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +86 -18
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +9 -15
- package/dest/mem_pools/instrumentation.d.ts +7 -11
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +25 -37
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +93 -9
- 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 +469 -97
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +33 -9
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +133 -36
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +64 -8
- 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.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +264 -39
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -0
- 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/block_proposal_validator/block_proposal_validator.d.ts +5 -1
- 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 +61 -12
- 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/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.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.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 +0 -2
- 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 +15 -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 +7 -0
- 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 +7 -3
- 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 +91 -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 +12 -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.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
- package/dest/services/discv5/discV5_service.d.ts +9 -8
- 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 +49 -10
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +25 -6
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +73 -5
- package/dest/services/index.d.ts +4 -0
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +18 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +157 -0
- package/dest/services/libp2p/libp2p_service.d.ts +87 -42
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +500 -218
- 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 +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +11 -2
- package/dest/services/peer-manager/peer_manager.d.ts +126 -15
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +547 -72
- package/dest/services/reqresp/config.d.ts +10 -8
- 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 +1 -1
- 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 +30 -13
- 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 +2 -1
- 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 +72 -23
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +45 -26
- 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 +5 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +28 -5
- 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 +49 -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 +2 -4
- 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 +2 -0
- 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 +0 -2
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +38 -6
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +72 -5
- package/dest/services/reqresp/protocols/tx.d.ts +12 -1
- 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/rate_limiter.d.ts +4 -2
- 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.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +45 -47
- 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 +9 -3
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +22 -18
- 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 +56 -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 +54 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +176 -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 +49 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +210 -0
- package/dest/services/tx_provider_instrumentation.d.ts +13 -0
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_provider_instrumentation.js +34 -0
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +1 -0
- 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.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +32 -4
- 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 +14 -10
- 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.js +96 -25
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +0 -5
- 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 +3 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +22 -15
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +64 -67
- package/dest/versioning.d.ts +3 -3
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +28 -24
- package/src/bootstrap/bootstrap.ts +27 -11
- package/src/client/factory.ts +136 -45
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +195 -0
- package/src/client/p2p_client.ts +460 -327
- package/src/config.ts +288 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +48 -4
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -55
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +117 -20
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +114 -22
- package/src/mem_pools/attestation_pool/mocks.ts +11 -10
- package/src/mem_pools/instrumentation.ts +32 -46
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +549 -108
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +153 -44
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +67 -8
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +217 -34
- package/src/msg_validators/attestation_validator/attestation_validator.ts +55 -10
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +66 -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 +4 -4
- 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 +109 -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 +58 -21
- package/src/msg_validators/tx_validator/phases_validator.ts +114 -0
- package/src/msg_validators/tx_validator/test_utils.ts +43 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +46 -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 +80 -5
- package/src/services/index.ts +4 -0
- package/src/services/libp2p/instrumentation.ts +158 -0
- package/src/services/libp2p/libp2p_service.ts +646 -263
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +16 -1
- package/src/services/peer-manager/peer_manager.ts +652 -78
- 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 +91 -36
- package/src/services/reqresp/metrics.ts +4 -1
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +24 -3
- 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 +117 -5
- package/src/services/reqresp/protocols/tx.ts +35 -6
- 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 +340 -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 +232 -0
- package/src/services/tx_collection/tx_collection.ts +215 -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 +216 -0
- package/src/services/tx_provider_instrumentation.ts +44 -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 +86 -35
- package/src/testbench/p2p_client_testbench_worker.ts +145 -22
- 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 +93 -89
- package/src/versioning.ts +11 -4
|
@@ -2,16 +2,20 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
5
|
-
import { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
5
|
+
import { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
6
6
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
7
7
|
|
|
8
|
-
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
8
|
+
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
9
9
|
import type { AttestationPool } from './attestation_pool.js';
|
|
10
10
|
|
|
11
11
|
export class KvAttestationPool implements AttestationPool {
|
|
12
12
|
private metrics: PoolInstrumentation<BlockAttestation>;
|
|
13
13
|
|
|
14
14
|
private attestations: AztecAsyncMap<string, Buffer>;
|
|
15
|
+
private proposals: AztecAsyncMap<
|
|
16
|
+
/* proposal.payload.archive */ string,
|
|
17
|
+
/* buffer representation of proposal */ Buffer
|
|
18
|
+
>;
|
|
15
19
|
private proposalsForSlot: AztecAsyncMultiMap<string, string>;
|
|
16
20
|
private attestationsForProposal: AztecAsyncMultiMap<string, string>;
|
|
17
21
|
|
|
@@ -21,10 +25,24 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
21
25
|
private log = createLogger('aztec:attestation_pool'),
|
|
22
26
|
) {
|
|
23
27
|
this.attestations = store.openMap('attestations');
|
|
28
|
+
this.proposals = store.openMap('proposals');
|
|
24
29
|
this.proposalsForSlot = store.openMultiMap('proposals_for_slot');
|
|
25
30
|
this.attestationsForProposal = store.openMultiMap('attestations_for_proposal');
|
|
26
31
|
|
|
27
|
-
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL);
|
|
32
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL, this.poolStats);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private poolStats: PoolStatsCallback = async () => {
|
|
36
|
+
return {
|
|
37
|
+
itemCount: await this.attestations.sizeAsync(),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
public async isEmpty(): Promise<boolean> {
|
|
42
|
+
for await (const _ of this.attestations.entriesAsync()) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
28
46
|
}
|
|
29
47
|
|
|
30
48
|
private getProposalKey(slot: number | bigint | Fr | string, proposalId: Fr | string | Buffer): string {
|
|
@@ -33,8 +51,8 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
33
51
|
typeof proposalId === 'string'
|
|
34
52
|
? proposalId
|
|
35
53
|
: Buffer.isBuffer(proposalId)
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
? Fr.fromBuffer(proposalId).toString()
|
|
55
|
+
: proposalId.toString();
|
|
38
56
|
|
|
39
57
|
return `${slotStr}-${proposalIdStr}`;
|
|
40
58
|
}
|
|
@@ -46,9 +64,21 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
46
64
|
public async addAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
47
65
|
await this.store.transactionAsync(async () => {
|
|
48
66
|
for (const attestation of attestations) {
|
|
49
|
-
const slotNumber = attestation.payload.header.
|
|
67
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
50
68
|
const proposalId = attestation.archive;
|
|
51
|
-
const
|
|
69
|
+
const sender = attestation.getSender();
|
|
70
|
+
|
|
71
|
+
// Skip attestations with invalid signatures
|
|
72
|
+
if (!sender) {
|
|
73
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber.toBigInt()}`, {
|
|
74
|
+
signature: attestation.signature.toString(),
|
|
75
|
+
slotNumber,
|
|
76
|
+
proposalId,
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const address = sender.toString();
|
|
52
82
|
|
|
53
83
|
await this.attestations.set(this.getAttestationKey(slotNumber, proposalId, address), attestation.toBuffer());
|
|
54
84
|
|
|
@@ -58,14 +88,29 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
58
88
|
this.getAttestationKey(slotNumber, proposalId, address),
|
|
59
89
|
);
|
|
60
90
|
|
|
61
|
-
this.log.verbose(`Added attestation for slot ${slotNumber} from ${address}
|
|
91
|
+
this.log.verbose(`Added attestation for slot ${slotNumber.toBigInt()} from ${address}`, {
|
|
92
|
+
signature: attestation.signature.toString(),
|
|
93
|
+
slotNumber,
|
|
94
|
+
address,
|
|
95
|
+
proposalId,
|
|
96
|
+
});
|
|
62
97
|
}
|
|
63
98
|
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public async getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]> {
|
|
102
|
+
const slotFr = new Fr(slot);
|
|
103
|
+
const proposalIds = await toArray(this.proposalsForSlot.getValuesAsync(slotFr.toString()));
|
|
104
|
+
const attestations: BlockAttestation[] = [];
|
|
105
|
+
|
|
106
|
+
for (const proposalId of proposalIds) {
|
|
107
|
+
attestations.push(...(await this.getAttestationsForSlotAndProposal(slot, proposalId)));
|
|
108
|
+
}
|
|
64
109
|
|
|
65
|
-
|
|
110
|
+
return attestations;
|
|
66
111
|
}
|
|
67
112
|
|
|
68
|
-
public async
|
|
113
|
+
public async getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
|
|
69
114
|
const attestationIds = await toArray(
|
|
70
115
|
this.attestationsForProposal.getValuesAsync(this.getProposalKey(slot, proposalId)),
|
|
71
116
|
);
|
|
@@ -109,12 +154,12 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
109
154
|
await this.attestations.delete(attestation);
|
|
110
155
|
}
|
|
111
156
|
|
|
157
|
+
await this.proposals.delete(proposalId);
|
|
112
158
|
await this.attestationsForProposal.delete(this.getProposalKey(slotFr, proposalId));
|
|
113
159
|
}
|
|
114
|
-
});
|
|
115
160
|
|
|
116
|
-
|
|
117
|
-
|
|
161
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot}`);
|
|
162
|
+
});
|
|
118
163
|
}
|
|
119
164
|
|
|
120
165
|
public async deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void> {
|
|
@@ -130,22 +175,34 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
130
175
|
await this.attestations.delete(attestation);
|
|
131
176
|
}
|
|
132
177
|
|
|
178
|
+
await this.proposals.delete(proposalId);
|
|
133
179
|
await this.proposalsForSlot.deleteValue(slotString, proposalId);
|
|
134
180
|
await this.attestationsForProposal.delete(this.getProposalKey(slotString, proposalId));
|
|
135
|
-
});
|
|
136
181
|
|
|
137
|
-
|
|
138
|
-
|
|
182
|
+
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot} and proposal ${proposalId}`);
|
|
183
|
+
});
|
|
139
184
|
}
|
|
140
185
|
|
|
141
186
|
public async deleteAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
142
187
|
await this.store.transactionAsync(async () => {
|
|
143
188
|
for (const attestation of attestations) {
|
|
144
|
-
const slotNumber = attestation.payload.header.
|
|
189
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
145
190
|
const proposalId = attestation.archive;
|
|
146
|
-
const
|
|
191
|
+
const sender = attestation.getSender();
|
|
192
|
+
|
|
193
|
+
// Skip attestations with invalid signatures
|
|
194
|
+
if (!sender) {
|
|
195
|
+
this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber.toBigInt()}`);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const address = sender.toString();
|
|
200
|
+
const key = this.getAttestationKey(slotNumber, proposalId, address);
|
|
201
|
+
|
|
202
|
+
if (await this.attestations.hasAsync(key)) {
|
|
203
|
+
await this.attestations.delete(key);
|
|
204
|
+
}
|
|
147
205
|
|
|
148
|
-
await this.attestations.delete(this.getAttestationKey(slotNumber, proposalId, address));
|
|
149
206
|
await this.attestationsForProposal.deleteValue(
|
|
150
207
|
this.getProposalKey(slotNumber, proposalId),
|
|
151
208
|
this.getAttestationKey(slotNumber, proposalId, address),
|
|
@@ -154,6 +211,46 @@ export class KvAttestationPool implements AttestationPool {
|
|
|
154
211
|
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${address}`);
|
|
155
212
|
}
|
|
156
213
|
});
|
|
157
|
-
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public async hasAttestation(attestation: BlockAttestation): Promise<boolean> {
|
|
217
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
218
|
+
const proposalId = attestation.archive;
|
|
219
|
+
const sender = attestation.getSender();
|
|
220
|
+
|
|
221
|
+
// Attestations with invalid signatures are never in the pool
|
|
222
|
+
if (!sender) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const address = sender.toString();
|
|
227
|
+
const key = this.getAttestationKey(slotNumber, proposalId, address);
|
|
228
|
+
|
|
229
|
+
return await this.attestations.hasAsync(key);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public async getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
233
|
+
const buffer = await this.proposals.getAsync(id);
|
|
234
|
+
try {
|
|
235
|
+
if (buffer && buffer.length > 0) {
|
|
236
|
+
return BlockProposal.fromBuffer(buffer);
|
|
237
|
+
}
|
|
238
|
+
} catch {
|
|
239
|
+
return Promise.resolve(undefined);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return Promise.resolve(undefined);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public async hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
246
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
|
|
247
|
+
return await this.proposals.hasAsync(id);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public async addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
251
|
+
await this.store.transactionAsync(async () => {
|
|
252
|
+
await this.proposalsForSlot.set(blockProposal.slotNumber.toString(), blockProposal.archive.toString());
|
|
253
|
+
await this.proposals.set(blockProposal.payload.archive.toString(), blockProposal.toBuffer());
|
|
254
|
+
});
|
|
158
255
|
}
|
|
159
256
|
}
|
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
2
|
+
import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
3
3
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
|
-
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
5
|
+
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
6
6
|
import type { AttestationPool } from './attestation_pool.js';
|
|
7
7
|
|
|
8
8
|
export class InMemoryAttestationPool implements AttestationPool {
|
|
9
9
|
private metrics: PoolInstrumentation<BlockAttestation>;
|
|
10
10
|
|
|
11
11
|
private attestations: Map</*slot=*/ bigint, Map</*proposalId*/ string, Map</*address=*/ string, BlockAttestation>>>;
|
|
12
|
+
private proposals: Map<string, BlockProposal>;
|
|
12
13
|
|
|
13
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
16
|
+
private log = createLogger('p2p:attestation_pool'),
|
|
17
|
+
) {
|
|
14
18
|
this.attestations = new Map();
|
|
15
|
-
this.
|
|
19
|
+
this.proposals = new Map();
|
|
20
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL, this.poolStats);
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
private poolStats: PoolStatsCallback = () => {
|
|
24
|
+
return Promise.resolve({
|
|
25
|
+
itemCount: this.attestations.size,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
public isEmpty(): Promise<boolean> {
|
|
30
|
+
return Promise.resolve(this.attestations.size === 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]> {
|
|
34
|
+
return Promise.resolve(
|
|
35
|
+
Array.from(this.attestations.get(slot)?.values() ?? []).flatMap(proposalAttestationMap =>
|
|
36
|
+
Array.from(proposalAttestationMap.values()),
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]> {
|
|
19
42
|
const slotAttestationMap = this.attestations.get(slot);
|
|
20
43
|
if (slotAttestationMap) {
|
|
21
44
|
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
@@ -26,23 +49,36 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
26
49
|
return Promise.resolve([]);
|
|
27
50
|
}
|
|
28
51
|
|
|
29
|
-
public
|
|
52
|
+
public addAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
30
53
|
for (const attestation of attestations) {
|
|
31
54
|
// Perf: order and group by slot before insertion
|
|
32
|
-
const slotNumber = attestation.payload.header.
|
|
55
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
33
56
|
|
|
34
57
|
const proposalId = attestation.archive.toString();
|
|
35
|
-
const
|
|
58
|
+
const sender = attestation.getSender();
|
|
59
|
+
|
|
60
|
+
// Skip attestations with invalid signatures
|
|
61
|
+
if (!sender) {
|
|
62
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber.toBigInt()}`, {
|
|
63
|
+
signature: attestation.signature.toString(),
|
|
64
|
+
slotNumber,
|
|
65
|
+
proposalId,
|
|
66
|
+
});
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
36
69
|
|
|
37
70
|
const slotAttestationMap = getSlotOrDefault(this.attestations, slotNumber.toBigInt());
|
|
38
71
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
39
|
-
proposalAttestationMap.set(
|
|
40
|
-
|
|
41
|
-
this.log.verbose(`Added attestation for slot ${slotNumber} from ${
|
|
72
|
+
proposalAttestationMap.set(sender.toString(), attestation);
|
|
73
|
+
|
|
74
|
+
this.log.verbose(`Added attestation for slot ${slotNumber.toBigInt()} from ${sender}`, {
|
|
75
|
+
signature: attestation.signature.toString(),
|
|
76
|
+
slotNumber,
|
|
77
|
+
address: sender,
|
|
78
|
+
proposalId,
|
|
79
|
+
});
|
|
42
80
|
}
|
|
43
81
|
|
|
44
|
-
// TODO: set these to pending or something ????
|
|
45
|
-
this.metrics.recordAddedObjects(attestations.length);
|
|
46
82
|
return Promise.resolve();
|
|
47
83
|
}
|
|
48
84
|
|
|
@@ -82,11 +118,18 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
82
118
|
public deleteAttestationsForSlot(slot: bigint): Promise<void> {
|
|
83
119
|
// We count the number of attestations we are removing
|
|
84
120
|
const numberOfAttestations = this.#getNumberOfAttestationsInSlot(slot);
|
|
121
|
+
const proposalIdsToDelete = this.attestations.get(slot)?.keys();
|
|
122
|
+
let proposalIdsToDeleteCount = 0;
|
|
123
|
+
proposalIdsToDelete?.forEach(proposalId => {
|
|
124
|
+
this.proposals.delete(proposalId);
|
|
125
|
+
proposalIdsToDeleteCount++;
|
|
126
|
+
});
|
|
85
127
|
|
|
86
128
|
this.attestations.delete(slot);
|
|
87
|
-
this.log.verbose(
|
|
129
|
+
this.log.verbose(
|
|
130
|
+
`Removed ${numberOfAttestations} attestations and ${proposalIdsToDeleteCount} proposals for slot ${slot}`,
|
|
131
|
+
);
|
|
88
132
|
|
|
89
|
-
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
90
133
|
return Promise.resolve();
|
|
91
134
|
}
|
|
92
135
|
|
|
@@ -99,29 +142,78 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
99
142
|
slotAttestationMap.delete(proposalId);
|
|
100
143
|
|
|
101
144
|
this.log.verbose(`Removed ${numberOfAttestations} attestations for slot ${slot} and proposal ${proposalId}`);
|
|
102
|
-
this.metrics.recordRemovedObjects(numberOfAttestations);
|
|
103
145
|
}
|
|
104
146
|
}
|
|
147
|
+
|
|
148
|
+
this.proposals.delete(proposalId);
|
|
105
149
|
return Promise.resolve();
|
|
106
150
|
}
|
|
107
151
|
|
|
108
|
-
public
|
|
152
|
+
public deleteAttestations(attestations: BlockAttestation[]): Promise<void> {
|
|
109
153
|
for (const attestation of attestations) {
|
|
110
|
-
const slotNumber = attestation.payload.header.
|
|
154
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
111
155
|
const slotAttestationMap = this.attestations.get(slotNumber.toBigInt());
|
|
112
156
|
if (slotAttestationMap) {
|
|
113
157
|
const proposalId = attestation.archive.toString();
|
|
114
158
|
const proposalAttestationMap = getProposalOrDefault(slotAttestationMap, proposalId);
|
|
115
159
|
if (proposalAttestationMap) {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
160
|
+
const sender = attestation.getSender();
|
|
161
|
+
|
|
162
|
+
// Skip attestations with invalid signatures
|
|
163
|
+
if (!sender) {
|
|
164
|
+
this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber.toBigInt()}`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
proposalAttestationMap.delete(sender.toString());
|
|
169
|
+
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${sender}`);
|
|
119
170
|
}
|
|
120
171
|
}
|
|
121
172
|
}
|
|
122
|
-
this.metrics.recordRemovedObjects(attestations.length);
|
|
123
173
|
return Promise.resolve();
|
|
124
174
|
}
|
|
175
|
+
|
|
176
|
+
public hasAttestation(attestation: BlockAttestation): Promise<boolean> {
|
|
177
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
178
|
+
const proposalId = attestation.archive.toString();
|
|
179
|
+
const sender = attestation.getSender();
|
|
180
|
+
|
|
181
|
+
// Attestations with invalid signatures are never in the pool
|
|
182
|
+
if (!sender) {
|
|
183
|
+
return Promise.resolve(false);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const slotAttestationMap = this.attestations.get(slotNumber.toBigInt());
|
|
187
|
+
if (!slotAttestationMap) {
|
|
188
|
+
return Promise.resolve(false);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
192
|
+
if (!proposalAttestationMap) {
|
|
193
|
+
return Promise.resolve(false);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return Promise.resolve(proposalAttestationMap.has(sender.toString()));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
200
|
+
// We initialize slot-proposal mapping if it does not exist
|
|
201
|
+
// This is important to ensure we can delete this proposal if there were not attestations for it
|
|
202
|
+
const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber.toBigInt());
|
|
203
|
+
slotProposalMapping.set(blockProposal.payload.archive.toString(), new Map<string, BlockAttestation>());
|
|
204
|
+
|
|
205
|
+
this.proposals.set(blockProposal.payload.archive.toString(), blockProposal);
|
|
206
|
+
return Promise.resolve();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
210
|
+
return Promise.resolve(this.proposals.get(id));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
214
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
|
|
215
|
+
return Promise.resolve(this.proposals.has(id));
|
|
216
|
+
}
|
|
125
217
|
}
|
|
126
218
|
|
|
127
219
|
/**
|
|
@@ -6,8 +6,7 @@ import {
|
|
|
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, header.state);
|
|
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
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Gossipable } from '@aztec/stdlib/p2p';
|
|
2
2
|
import {
|
|
3
3
|
Attributes,
|
|
4
|
+
type BatchObservableResult,
|
|
4
5
|
type Histogram,
|
|
5
6
|
LmdbMetrics,
|
|
6
7
|
type LmdbStatsCallback,
|
|
8
|
+
type Meter,
|
|
7
9
|
Metrics,
|
|
8
10
|
type MetricsType,
|
|
11
|
+
type ObservableGauge,
|
|
9
12
|
type TelemetryClient,
|
|
10
|
-
type UpDownCounter,
|
|
11
13
|
} from '@aztec/telemetry-client';
|
|
12
14
|
|
|
13
15
|
export enum PoolName {
|
|
@@ -41,86 +43,70 @@ function getMetricsLabels(name: PoolName): MetricsLabels {
|
|
|
41
43
|
throw new Error('Invalid pool type');
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
export type PoolStatsCallback = () => Promise<{
|
|
47
|
+
itemCount: number | Record<string, number>;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
44
50
|
/**
|
|
45
51
|
* Instrumentation class for the Pools (TxPool, AttestationPool, etc).
|
|
46
52
|
*/
|
|
47
53
|
export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
48
54
|
/** The number of txs in the mempool */
|
|
49
|
-
private objectsInMempool:
|
|
55
|
+
private objectsInMempool: ObservableGauge;
|
|
50
56
|
/** Tracks tx size */
|
|
51
57
|
private objectSize: Histogram;
|
|
52
58
|
|
|
53
59
|
private dbMetrics: LmdbMetrics;
|
|
54
60
|
|
|
55
61
|
private defaultAttributes;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
private meter: Meter;
|
|
63
|
+
|
|
64
|
+
constructor(
|
|
65
|
+
telemetry: TelemetryClient,
|
|
66
|
+
name: PoolName,
|
|
67
|
+
private poolStats: PoolStatsCallback,
|
|
68
|
+
dbStats?: LmdbStatsCallback,
|
|
69
|
+
) {
|
|
70
|
+
this.meter = telemetry.getMeter(name);
|
|
59
71
|
this.defaultAttributes = { [Attributes.POOL_NAME]: name };
|
|
60
72
|
|
|
61
73
|
const metricsLabels = getMetricsLabels(name);
|
|
62
74
|
|
|
63
|
-
this.objectsInMempool = meter.
|
|
75
|
+
this.objectsInMempool = this.meter.createObservableGauge(metricsLabels.objectInMempool, {
|
|
64
76
|
description: 'The current number of transactions in the mempool',
|
|
65
77
|
});
|
|
66
78
|
|
|
67
|
-
this.objectSize = meter.createHistogram(metricsLabels.objectSize, {
|
|
79
|
+
this.objectSize = this.meter.createHistogram(metricsLabels.objectSize, {
|
|
68
80
|
unit: 'By',
|
|
69
81
|
description: 'The size of transactions in the mempool',
|
|
70
82
|
});
|
|
71
83
|
|
|
72
84
|
this.dbMetrics = new LmdbMetrics(
|
|
73
|
-
meter,
|
|
85
|
+
this.meter,
|
|
74
86
|
{
|
|
75
87
|
[Attributes.DB_DATA_TYPE]: 'tx-pool',
|
|
76
88
|
},
|
|
77
89
|
dbStats,
|
|
78
90
|
);
|
|
91
|
+
|
|
92
|
+
this.meter.addBatchObservableCallback(this.observeStats, [this.objectsInMempool]);
|
|
79
93
|
}
|
|
80
94
|
|
|
81
95
|
public recordSize(poolObject: PoolObject) {
|
|
82
96
|
this.objectSize.record(poolObject.getSize());
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
if (count === 0) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const attributes = status
|
|
97
|
-
? {
|
|
99
|
+
private observeStats = async (observer: BatchObservableResult) => {
|
|
100
|
+
const { itemCount } = await this.poolStats();
|
|
101
|
+
if (typeof itemCount === 'number') {
|
|
102
|
+
observer.observe(this.objectsInMempool, itemCount, this.defaultAttributes);
|
|
103
|
+
} else {
|
|
104
|
+
for (const [status, count] of Object.entries(itemCount)) {
|
|
105
|
+
observer.observe(this.objectsInMempool, count, {
|
|
98
106
|
...this.defaultAttributes,
|
|
99
107
|
[Attributes.STATUS]: status,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.objectsInMempool.add(count, attributes);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Updates the metrics by removing objects from the mempool.
|
|
108
|
-
* @param count - The number of objects to remove from the mempool
|
|
109
|
-
*/
|
|
110
|
-
public recordRemovedObjects(count = 1, status?: string) {
|
|
111
|
-
if (count < 0) {
|
|
112
|
-
throw new Error('Count must be positive');
|
|
113
|
-
}
|
|
114
|
-
if (count === 0) {
|
|
115
|
-
return;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
116
110
|
}
|
|
117
|
-
|
|
118
|
-
const attributes = status
|
|
119
|
-
? {
|
|
120
|
-
...this.defaultAttributes,
|
|
121
|
-
[Attributes.STATUS]: status,
|
|
122
|
-
}
|
|
123
|
-
: this.defaultAttributes;
|
|
124
|
-
this.objectsInMempool.add(-1 * count, attributes);
|
|
125
|
-
}
|
|
111
|
+
};
|
|
126
112
|
}
|