@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
1
|
+
import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* An Attestation Pool contains attestations collected by a validator
|
|
@@ -8,7 +8,30 @@ import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
|
8
8
|
*/
|
|
9
9
|
export interface AttestationPool {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Adds new block proposal to the pool
|
|
12
|
+
*/
|
|
13
|
+
addBlockProposal(blockProposal: BlockProposal): Promise<void>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get block proposal by it's ID
|
|
17
|
+
*
|
|
18
|
+
* @param id - The ID of the block proposal to retrieve. The ID is proposal.payload.archive
|
|
19
|
+
*
|
|
20
|
+
* @return The block proposal if it exists, otherwise undefined.
|
|
21
|
+
*/
|
|
22
|
+
getBlockProposal(id: string): Promise<BlockProposal | undefined>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Check if a block proposal exists in the pool
|
|
26
|
+
*
|
|
27
|
+
* @param idOrProposal - The ID of the block proposal or the block proposal itself to check. The ID is proposal.payload.archive
|
|
28
|
+
*
|
|
29
|
+
* @return True if the block proposal exists, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* AddAttestations
|
|
12
35
|
*
|
|
13
36
|
* @param attestations - Attestations to add into the pool
|
|
14
37
|
*/
|
|
@@ -50,7 +73,17 @@ export interface AttestationPool {
|
|
|
50
73
|
deleteAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<void>;
|
|
51
74
|
|
|
52
75
|
/**
|
|
53
|
-
* Get Attestations for slot
|
|
76
|
+
* Get all Attestations for all proposals for a given slot
|
|
77
|
+
*
|
|
78
|
+
* Retrieve all of the attestations observed pertaining to a given slot
|
|
79
|
+
*
|
|
80
|
+
* @param slot - The slot to query
|
|
81
|
+
* @return BlockAttestations
|
|
82
|
+
*/
|
|
83
|
+
getAttestationsForSlot(slot: bigint): Promise<BlockAttestation[]>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get Attestations for slot and given proposal
|
|
54
87
|
*
|
|
55
88
|
* Retrieve all of the attestations observed pertaining to a given slot
|
|
56
89
|
*
|
|
@@ -58,5 +91,16 @@ export interface AttestationPool {
|
|
|
58
91
|
* @param proposalId - The proposal to query
|
|
59
92
|
* @return BlockAttestations
|
|
60
93
|
*/
|
|
61
|
-
|
|
94
|
+
getAttestationsForSlotAndProposal(slot: bigint, proposalId: string): Promise<BlockAttestation[]>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Check if a specific attestation exists in the pool
|
|
98
|
+
*
|
|
99
|
+
* @param attestation - The attestation to check
|
|
100
|
+
* @return True if the attestation exists, false otherwise
|
|
101
|
+
*/
|
|
102
|
+
hasAttestation(attestation: BlockAttestation): Promise<boolean>;
|
|
103
|
+
|
|
104
|
+
/** Returns whether the pool is empty. */
|
|
105
|
+
isEmpty(): Promise<boolean>;
|
|
62
106
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
3
|
+
import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
|
|
4
|
+
import {
|
|
5
|
+
BlockProposal as BlockProposalClass,
|
|
6
|
+
ConsensusPayload,
|
|
7
|
+
SignatureDomainSeparator,
|
|
8
|
+
getHashedSignaturePayloadEthSignedMessage,
|
|
9
|
+
} from '@aztec/stdlib/p2p';
|
|
10
|
+
import { makeL2BlockHeader } from '@aztec/stdlib/testing';
|
|
4
11
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
12
|
|
|
6
13
|
import { jest } from '@jest/globals';
|
|
@@ -30,7 +37,19 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
|
|
|
30
37
|
|
|
31
38
|
const createAttestationsForSlot = (slotNumber: number) => {
|
|
32
39
|
const archive = Fr.random();
|
|
33
|
-
return
|
|
40
|
+
return signers.map(signer => mockAttestation(signer, slotNumber, archive));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const mockBlockProposal = (signer: Secp256k1Signer, slotNumber: number, archive: Fr = Fr.random()): BlockProposal => {
|
|
44
|
+
const header = makeL2BlockHeader(1, 2, slotNumber);
|
|
45
|
+
const payload = new ConsensusPayload(header.toCheckpointHeader(), archive, header.state);
|
|
46
|
+
|
|
47
|
+
const hash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockProposal);
|
|
48
|
+
const signature = signer.sign(hash);
|
|
49
|
+
|
|
50
|
+
const txHashes = [TxHash.random(), TxHash.random()]; // Mock tx hashes
|
|
51
|
+
|
|
52
|
+
return new BlockProposalClass(payload, signature, txHashes);
|
|
34
53
|
};
|
|
35
54
|
|
|
36
55
|
// We compare buffers as the objects can have cached values attached to them which are not serialised
|
|
@@ -45,155 +64,181 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
|
|
|
45
64
|
it('should add attestations to pool', async () => {
|
|
46
65
|
const slotNumber = 420;
|
|
47
66
|
const archive = Fr.random();
|
|
48
|
-
const attestations =
|
|
67
|
+
const attestations = signers.slice(0, -1).map(signer => mockAttestation(signer, slotNumber, archive));
|
|
49
68
|
|
|
50
69
|
await ap.addAttestations(attestations);
|
|
51
70
|
|
|
52
|
-
|
|
53
|
-
expect(
|
|
71
|
+
const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
|
|
72
|
+
expect(retrievedAttestations.length).toBe(attestations.length);
|
|
73
|
+
compareAttestations(retrievedAttestations, attestations);
|
|
54
74
|
|
|
55
|
-
|
|
75
|
+
// Check hasAttestation for added attestations
|
|
76
|
+
for (const attestation of attestations) {
|
|
77
|
+
expect(await ap.hasAttestation(attestation)).toBe(true);
|
|
78
|
+
}
|
|
56
79
|
|
|
57
|
-
|
|
80
|
+
const retrievedAttestationsForSlot = await ap.getAttestationsForSlot(BigInt(slotNumber));
|
|
81
|
+
expect(retrievedAttestationsForSlot.length).toBe(attestations.length);
|
|
82
|
+
compareAttestations(retrievedAttestationsForSlot, attestations);
|
|
58
83
|
|
|
59
|
-
|
|
84
|
+
// Add another one
|
|
85
|
+
const newAttestation = mockAttestation(signers[NUMBER_OF_SIGNERS_PER_TEST - 1], slotNumber, archive);
|
|
86
|
+
await ap.addAttestations([newAttestation]);
|
|
87
|
+
const retrievedAttestationsAfterAdd = await ap.getAttestationsForSlotAndProposal(
|
|
88
|
+
BigInt(slotNumber),
|
|
89
|
+
archive.toString(),
|
|
90
|
+
);
|
|
91
|
+
expect(retrievedAttestationsAfterAdd.length).toBe(attestations.length + 1);
|
|
92
|
+
compareAttestations(retrievedAttestationsAfterAdd, [...attestations, newAttestation]);
|
|
93
|
+
expect(await ap.hasAttestation(newAttestation)).toBe(true);
|
|
94
|
+
const retrievedAttestationsForSlotAfterAdd = await ap.getAttestationsForSlot(BigInt(slotNumber));
|
|
95
|
+
expect(retrievedAttestationsForSlotAfterAdd.length).toBe(attestations.length + 1);
|
|
96
|
+
compareAttestations(retrievedAttestationsForSlotAfterAdd, [...attestations, newAttestation]);
|
|
60
97
|
|
|
61
98
|
// Delete by slot
|
|
62
99
|
await ap.deleteAttestationsForSlot(BigInt(slotNumber));
|
|
63
100
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
101
|
+
const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(
|
|
102
|
+
BigInt(slotNumber),
|
|
103
|
+
archive.toString(),
|
|
104
|
+
);
|
|
67
105
|
expect(retreivedAttestationsAfterDelete.length).toBe(0);
|
|
106
|
+
// Check hasAttestation after deletion
|
|
107
|
+
for (const attestation of attestations) {
|
|
108
|
+
expect(await ap.hasAttestation(attestation)).toBe(false);
|
|
109
|
+
}
|
|
110
|
+
expect(await ap.hasAttestation(newAttestation)).toBe(false);
|
|
68
111
|
});
|
|
69
112
|
|
|
70
|
-
it('
|
|
113
|
+
it('should handle duplicate proposals in a slot', async () => {
|
|
71
114
|
const slotNumber = 420;
|
|
72
115
|
const archive = Fr.random();
|
|
73
|
-
const txs = [0, 1, 2, 3, 4, 5].map(() => TxHash.random());
|
|
74
116
|
|
|
75
117
|
// Use the same signer for all attestations
|
|
76
118
|
const attestations: BlockAttestation[] = [];
|
|
77
119
|
const signer = signers[0];
|
|
78
120
|
for (let i = 0; i < NUMBER_OF_SIGNERS_PER_TEST; i++) {
|
|
79
|
-
attestations.push(
|
|
121
|
+
attestations.push(mockAttestation(signer, slotNumber, archive));
|
|
80
122
|
}
|
|
81
123
|
|
|
124
|
+
// Add them to store and check we end up with only one
|
|
82
125
|
await ap.addAttestations(attestations);
|
|
83
126
|
|
|
84
|
-
const retreivedAttestations = await ap.
|
|
127
|
+
const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString());
|
|
85
128
|
expect(retreivedAttestations.length).toBe(1);
|
|
86
129
|
expect(retreivedAttestations[0].toBuffer()).toEqual(attestations[0].toBuffer());
|
|
87
|
-
expect(retreivedAttestations[0].
|
|
88
|
-
|
|
130
|
+
expect(retreivedAttestations[0].getSender()?.toString()).toEqual(signer.address.toString());
|
|
131
|
+
|
|
132
|
+
// Try adding them on another operation and check they are still not duplicated
|
|
133
|
+
await ap.addAttestations([attestations[0]]);
|
|
134
|
+
expect(await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), archive.toString())).toHaveLength(1);
|
|
89
135
|
});
|
|
90
136
|
|
|
91
|
-
it('
|
|
137
|
+
it('should store attestations by differing slot', async () => {
|
|
92
138
|
const slotNumbers = [1, 2, 3, 4];
|
|
93
|
-
const attestations =
|
|
139
|
+
const attestations = signers.map((signer, i) => mockAttestation(signer, slotNumbers[i]));
|
|
94
140
|
|
|
95
141
|
await ap.addAttestations(attestations);
|
|
96
142
|
|
|
97
143
|
for (const attestation of attestations) {
|
|
98
|
-
const slot = attestation.payload.header.
|
|
144
|
+
const slot = attestation.payload.header.slotNumber;
|
|
99
145
|
const archive = attestation.archive.toString();
|
|
100
146
|
|
|
101
|
-
const retreivedAttestations = await ap.
|
|
147
|
+
const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), archive);
|
|
102
148
|
expect(retreivedAttestations.length).toBe(1);
|
|
103
149
|
expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
|
|
104
|
-
expect(retreivedAttestations[0].payload.header.
|
|
150
|
+
expect(retreivedAttestations[0].payload.header.slotNumber).toEqual(slot);
|
|
105
151
|
}
|
|
106
152
|
});
|
|
107
153
|
|
|
108
|
-
it('
|
|
154
|
+
it('should store attestations by differing slot and archive', async () => {
|
|
109
155
|
const slotNumbers = [1, 1, 2, 3];
|
|
110
156
|
const archives = [Fr.random(), Fr.random(), Fr.random(), Fr.random()];
|
|
111
|
-
const attestations =
|
|
112
|
-
signers.map((signer, i) => mockAttestation(signer, slotNumbers[i], archives[i])),
|
|
113
|
-
);
|
|
157
|
+
const attestations = signers.map((signer, i) => mockAttestation(signer, slotNumbers[i], archives[i]));
|
|
114
158
|
|
|
115
159
|
await ap.addAttestations(attestations);
|
|
116
160
|
|
|
117
161
|
for (const attestation of attestations) {
|
|
118
|
-
const slot = attestation.payload.header.
|
|
162
|
+
const slot = attestation.payload.header.slotNumber;
|
|
119
163
|
const proposalId = attestation.archive.toString();
|
|
120
164
|
|
|
121
|
-
const retreivedAttestations = await ap.
|
|
165
|
+
const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(slot.toBigInt(), proposalId);
|
|
122
166
|
expect(retreivedAttestations.length).toBe(1);
|
|
123
167
|
expect(retreivedAttestations[0].toBuffer()).toEqual(attestation.toBuffer());
|
|
124
|
-
expect(retreivedAttestations[0].payload.header.
|
|
168
|
+
expect(retreivedAttestations[0].payload.header.slotNumber).toEqual(slot);
|
|
125
169
|
}
|
|
126
170
|
});
|
|
127
171
|
|
|
128
|
-
it('
|
|
172
|
+
it('should delete attestations', async () => {
|
|
129
173
|
const slotNumber = 420;
|
|
130
174
|
const archive = Fr.random();
|
|
131
|
-
const attestations =
|
|
175
|
+
const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
|
|
132
176
|
const proposalId = attestations[0].archive.toString();
|
|
133
177
|
|
|
134
178
|
await ap.addAttestations(attestations);
|
|
135
179
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
|
|
180
|
+
const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
139
181
|
expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
|
|
140
182
|
compareAttestations(retreivedAttestations, attestations);
|
|
141
183
|
|
|
142
|
-
|
|
184
|
+
// Check hasAttestation before deletion
|
|
185
|
+
for (const attestation of attestations) {
|
|
186
|
+
expect(await ap.hasAttestation(attestation)).toBe(true);
|
|
187
|
+
}
|
|
143
188
|
|
|
144
|
-
|
|
189
|
+
await ap.deleteAttestations(attestations);
|
|
145
190
|
|
|
146
|
-
const gottenAfterDelete = await ap.
|
|
191
|
+
const gottenAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
147
192
|
expect(gottenAfterDelete.length).toBe(0);
|
|
193
|
+
|
|
194
|
+
// Check hasAttestation after deletion
|
|
195
|
+
for (const attestation of attestations) {
|
|
196
|
+
expect(await ap.hasAttestation(attestation)).toBe(false);
|
|
197
|
+
}
|
|
148
198
|
});
|
|
149
199
|
|
|
150
|
-
it('
|
|
200
|
+
it('should blanket delete attestations per slot', async () => {
|
|
151
201
|
const slotNumber = 420;
|
|
152
202
|
const archive = Fr.random();
|
|
153
|
-
const attestations =
|
|
203
|
+
const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
|
|
154
204
|
const proposalId = attestations[0].archive.toString();
|
|
155
205
|
|
|
156
206
|
await ap.addAttestations(attestations);
|
|
157
207
|
|
|
158
|
-
const retreivedAttestations = await ap.
|
|
208
|
+
const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
159
209
|
expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
|
|
160
210
|
compareAttestations(retreivedAttestations, attestations);
|
|
161
211
|
|
|
162
212
|
await ap.deleteAttestationsForSlot(BigInt(slotNumber));
|
|
163
213
|
|
|
164
|
-
const retreivedAttestationsAfterDelete = await ap.
|
|
214
|
+
const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
165
215
|
expect(retreivedAttestationsAfterDelete.length).toBe(0);
|
|
166
216
|
});
|
|
167
217
|
|
|
168
|
-
it('
|
|
218
|
+
it('should blanket delete attestations per slot and proposal', async () => {
|
|
169
219
|
const slotNumber = 420;
|
|
170
220
|
const archive = Fr.random();
|
|
171
|
-
const attestations =
|
|
221
|
+
const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
|
|
172
222
|
const proposalId = attestations[0].archive.toString();
|
|
173
223
|
|
|
174
224
|
// Add another set of attestations with a different proposalId, yet the same slot
|
|
175
225
|
const archive2 = Fr.random();
|
|
176
|
-
const attestations2 =
|
|
226
|
+
const attestations2 = signers.map(signer => mockAttestation(signer, slotNumber, archive2));
|
|
177
227
|
const proposalId2 = attestations2[0].archive.toString();
|
|
178
228
|
|
|
179
229
|
await ap.addAttestations(attestations);
|
|
180
230
|
await ap.addAttestations(attestations2);
|
|
181
231
|
|
|
182
|
-
|
|
183
|
-
expect(metricsMock.recordAddedObjects).toHaveBeenCalledWith(attestations2.length);
|
|
184
|
-
|
|
185
|
-
const retreivedAttestations = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
|
|
232
|
+
const retreivedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
186
233
|
expect(retreivedAttestations.length).toBe(NUMBER_OF_SIGNERS_PER_TEST);
|
|
187
234
|
compareAttestations(retreivedAttestations, attestations);
|
|
188
235
|
|
|
189
236
|
await ap.deleteAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
190
237
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlot(BigInt(slotNumber), proposalId);
|
|
238
|
+
const retreivedAttestationsAfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
194
239
|
expect(retreivedAttestationsAfterDelete.length).toBe(0);
|
|
195
240
|
|
|
196
|
-
const retreivedAttestationsAfterDeleteForOtherProposal = await ap.
|
|
241
|
+
const retreivedAttestationsAfterDeleteForOtherProposal = await ap.getAttestationsForSlotAndProposal(
|
|
197
242
|
BigInt(slotNumber),
|
|
198
243
|
proposalId2,
|
|
199
244
|
);
|
|
@@ -201,7 +246,7 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
|
|
|
201
246
|
compareAttestations(retreivedAttestationsAfterDeleteForOtherProposal, attestations2);
|
|
202
247
|
});
|
|
203
248
|
|
|
204
|
-
it('
|
|
249
|
+
it('should delete attestations older than a given slot', async () => {
|
|
205
250
|
const slotNumbers = [1, 2, 3, 69, 72, 74, 88, 420];
|
|
206
251
|
const attestations = (
|
|
207
252
|
await Promise.all(slotNumbers.map(slotNumber => createAttestationsForSlot(slotNumber)))
|
|
@@ -210,14 +255,14 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
|
|
|
210
255
|
|
|
211
256
|
await ap.addAttestations(attestations);
|
|
212
257
|
|
|
213
|
-
const attestationsForSlot1 = await ap.
|
|
258
|
+
const attestationsForSlot1 = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
|
|
214
259
|
expect(attestationsForSlot1.length).toBe(signers.length);
|
|
215
260
|
|
|
216
261
|
const deleteAttestationsSpy = jest.spyOn(ap, 'deleteAttestationsForSlot');
|
|
217
262
|
|
|
218
263
|
await ap.deleteAttestationsOlderThan(BigInt(73));
|
|
219
264
|
|
|
220
|
-
const attestationsForSlot1AfterDelete = await ap.
|
|
265
|
+
const attestationsForSlot1AfterDelete = await ap.getAttestationsForSlotAndProposal(BigInt(1), proposalId);
|
|
221
266
|
expect(attestationsForSlot1AfterDelete.length).toBe(0);
|
|
222
267
|
|
|
223
268
|
expect(deleteAttestationsSpy).toHaveBeenCalledTimes(5);
|
|
@@ -227,4 +272,145 @@ export function describeAttestationPool(getAttestationPool: () => AttestationPoo
|
|
|
227
272
|
expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(69));
|
|
228
273
|
expect(deleteAttestationsSpy).toHaveBeenCalledWith(BigInt(72));
|
|
229
274
|
});
|
|
275
|
+
|
|
276
|
+
describe('BlockProposal in attestation pool', () => {
|
|
277
|
+
it('should add and retrieve block proposal', async () => {
|
|
278
|
+
const slotNumber = 420;
|
|
279
|
+
const archive = Fr.random();
|
|
280
|
+
const proposal = mockBlockProposal(signers[0], slotNumber, archive);
|
|
281
|
+
const proposalId = proposal.archive.toString();
|
|
282
|
+
|
|
283
|
+
await ap.addBlockProposal(proposal);
|
|
284
|
+
|
|
285
|
+
const retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
286
|
+
|
|
287
|
+
expect(retrievedProposal).toBeDefined();
|
|
288
|
+
expect(retrievedProposal!).toEqual(proposal);
|
|
289
|
+
|
|
290
|
+
// Check hasBlockProposal with both id and object
|
|
291
|
+
expect(await ap.hasBlockProposal(proposalId)).toBe(true);
|
|
292
|
+
expect(await ap.hasBlockProposal(proposal)).toBe(true);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('should return undefined for non-existent block proposal', async () => {
|
|
296
|
+
const nonExistentId = Fr.random().toString();
|
|
297
|
+
const retrievedProposal = await ap.getBlockProposal(nonExistentId);
|
|
298
|
+
expect(retrievedProposal).toBeUndefined();
|
|
299
|
+
|
|
300
|
+
// Check hasBlockProposal returns false for non-existent proposal
|
|
301
|
+
expect(await ap.hasBlockProposal(nonExistentId)).toBe(false);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('should update block proposal if added twice with same id', async () => {
|
|
305
|
+
const slotNumber = 420;
|
|
306
|
+
const archive = Fr.random();
|
|
307
|
+
const proposal1 = mockBlockProposal(signers[0], slotNumber, archive);
|
|
308
|
+
const proposalId = proposal1.archive.toString();
|
|
309
|
+
|
|
310
|
+
await ap.addBlockProposal(proposal1);
|
|
311
|
+
|
|
312
|
+
// Create a new proposal with same archive but different signer
|
|
313
|
+
const proposal2 = mockBlockProposal(signers[1], slotNumber, archive);
|
|
314
|
+
|
|
315
|
+
await ap.addBlockProposal(proposal2);
|
|
316
|
+
|
|
317
|
+
const retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
318
|
+
expect(retrievedProposal).toBeDefined();
|
|
319
|
+
// Should have the second proposal
|
|
320
|
+
expect(retrievedProposal!.toBuffer()).toEqual(proposal2.toBuffer());
|
|
321
|
+
expect(retrievedProposal!.getSender()?.toString()).toBe(signers[1].address.toString());
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('should handle block proposals with different slots and same archive', async () => {
|
|
325
|
+
const archive = Fr.random();
|
|
326
|
+
const proposal1 = mockBlockProposal(signers[0], 100, archive);
|
|
327
|
+
const proposal2 = mockBlockProposal(signers[1], 200, archive);
|
|
328
|
+
const proposalId = archive.toString();
|
|
329
|
+
|
|
330
|
+
await ap.addBlockProposal(proposal1);
|
|
331
|
+
await ap.addBlockProposal(proposal2);
|
|
332
|
+
|
|
333
|
+
// Should get the latest one added
|
|
334
|
+
const retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
335
|
+
expect(retrievedProposal).toBeDefined();
|
|
336
|
+
expect(retrievedProposal!.toBuffer()).toEqual(proposal2.toBuffer());
|
|
337
|
+
expect(retrievedProposal!.slotNumber.toBigInt()).toBe(BigInt(200));
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('should delete block proposal when deleting attestations for slot and proposal', async () => {
|
|
341
|
+
const slotNumber = 420;
|
|
342
|
+
const archive = Fr.random();
|
|
343
|
+
const proposal = mockBlockProposal(signers[0], slotNumber, archive);
|
|
344
|
+
const proposalId = proposal.archive.toString();
|
|
345
|
+
|
|
346
|
+
// Add proposal and some attestations
|
|
347
|
+
await ap.addBlockProposal(proposal);
|
|
348
|
+
const attestations = signers.map(signer => mockAttestation(signer, slotNumber, archive));
|
|
349
|
+
await ap.addAttestations(attestations);
|
|
350
|
+
|
|
351
|
+
// Verify proposal exists
|
|
352
|
+
let retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
353
|
+
expect(retrievedProposal).toBeDefined();
|
|
354
|
+
expect(await ap.hasBlockProposal(proposalId)).toBe(true);
|
|
355
|
+
|
|
356
|
+
// Delete attestations for slot and proposal
|
|
357
|
+
await ap.deleteAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
358
|
+
|
|
359
|
+
// Proposal should be deleted
|
|
360
|
+
retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
361
|
+
expect(retrievedProposal).toBeUndefined();
|
|
362
|
+
expect(await ap.hasBlockProposal(proposalId)).toBe(false);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('should delete block proposal when deleting attestations for slot', async () => {
|
|
366
|
+
const slotNumber = 420;
|
|
367
|
+
const archive = Fr.random();
|
|
368
|
+
const proposal = mockBlockProposal(signers[0], slotNumber, archive);
|
|
369
|
+
const proposalId = proposal.archive.toString();
|
|
370
|
+
|
|
371
|
+
// Add proposal
|
|
372
|
+
await ap.addBlockProposal(proposal);
|
|
373
|
+
|
|
374
|
+
// Verify proposal exists
|
|
375
|
+
let retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
376
|
+
expect(retrievedProposal).toBeDefined();
|
|
377
|
+
expect(await ap.hasBlockProposal(proposal)).toBe(true);
|
|
378
|
+
|
|
379
|
+
// Delete attestations for slot
|
|
380
|
+
await ap.deleteAttestationsForSlot(BigInt(slotNumber));
|
|
381
|
+
|
|
382
|
+
// Proposal should be deleted
|
|
383
|
+
retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
384
|
+
expect(retrievedProposal).toBeUndefined();
|
|
385
|
+
expect(await ap.hasBlockProposal(proposal)).toBe(false);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('should be able to fetch both block proposal and attestations', async () => {
|
|
389
|
+
const slotNumber = 420;
|
|
390
|
+
const archive = Fr.random();
|
|
391
|
+
const proposal = mockBlockProposal(signers[0], slotNumber, archive);
|
|
392
|
+
const proposalId = proposal.archive.toString();
|
|
393
|
+
|
|
394
|
+
// Add proposal first
|
|
395
|
+
await ap.addBlockProposal(proposal);
|
|
396
|
+
|
|
397
|
+
// Add attestations for the same proposal
|
|
398
|
+
const attestations = signers.slice(1).map(signer => mockAttestation(signer, slotNumber, archive));
|
|
399
|
+
await ap.addAttestations(attestations);
|
|
400
|
+
|
|
401
|
+
// Retrieve both proposal and attestations
|
|
402
|
+
const retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
403
|
+
const retrievedAttestations = await ap.getAttestationsForSlotAndProposal(BigInt(slotNumber), proposalId);
|
|
404
|
+
|
|
405
|
+
expect(retrievedProposal).toBeDefined();
|
|
406
|
+
expect(retrievedProposal).toEqual(proposal);
|
|
407
|
+
expect(await ap.hasBlockProposal(proposalId)).toBe(true);
|
|
408
|
+
|
|
409
|
+
compareAttestations(retrievedAttestations, attestations);
|
|
410
|
+
// Check hasAttestation for all attestations
|
|
411
|
+
for (const attestation of attestations) {
|
|
412
|
+
expect(await ap.hasAttestation(attestation)).toBe(true);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
});
|
|
230
416
|
}
|