@aztec/p2p 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +4 -3
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +4 -4
- package/dest/client/factory.d.ts +7 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +53 -15
- package/dest/client/interface.d.ts +58 -25
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +51 -56
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +608 -264
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts +2 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +305 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts +73 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.d.ts.map +1 -0
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.js +8 -0
- package/dest/config.d.ts +38 -13
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +31 -20
- package/dest/errors/tx-pool.error.d.ts +8 -0
- package/dest/errors/tx-pool.error.d.ts.map +1 -0
- package/dest/errors/tx-pool.error.js +9 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +111 -76
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +441 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- 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 +529 -289
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts +11 -8
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +17 -13
- package/dest/mem_pools/index.d.ts +3 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/instrumentation.d.ts +7 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +31 -13
- package/dest/mem_pools/interface.d.ts +6 -7
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +37 -27
- 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 +314 -335
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -6
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +30 -24
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +104 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +251 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +128 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +93 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +95 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +174 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +25 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +65 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +93 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +78 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +73 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +6 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +5 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/instrumentation.js +43 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +211 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +9 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +97 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +152 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +108 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +355 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +60 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +161 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +77 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +896 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +52 -19
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +7 -7
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +22 -13
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +3 -3
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.js +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +20 -6
- 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 -3
- package/dest/msg_validators/tx_validator/data_validator.d.ts +3 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +4 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +15 -4
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +7 -6
- package/dest/msg_validators/tx_validator/factory.d.ts +10 -4
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +22 -12
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +11 -16
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +4 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/size_validator.d.ts +8 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +23 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +23 -5
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +8 -8
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.js +2 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +2 -2
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +10 -6
- package/dest/services/discv5/discV5_service.js +1 -1
- package/dest/services/dummy_service.d.ts +28 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +51 -0
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +10 -8
- package/dest/services/gossipsub/index.d.ts +3 -0
- package/dest/services/gossipsub/index.d.ts.map +1 -0
- package/dest/services/gossipsub/index.js +2 -0
- package/dest/services/gossipsub/scoring.d.ts +21 -3
- package/dest/services/gossipsub/scoring.d.ts.map +1 -1
- package/dest/services/gossipsub/scoring.js +24 -7
- package/dest/services/gossipsub/topic_score_params.d.ts +173 -0
- package/dest/services/gossipsub/topic_score_params.d.ts.map +1 -0
- package/dest/services/gossipsub/topic_score_params.js +346 -0
- package/dest/services/index.d.ts +2 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +1 -0
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +30 -72
- package/dest/services/libp2p/libp2p_service.d.ts +109 -36
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +988 -326
- package/dest/services/peer-manager/metrics.d.ts +7 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +33 -21
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +4 -12
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +32 -6
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +48 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +562 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts +17 -0
- package/dest/services/reqresp/batch-tx-requester/config.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/config.js +27 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts +46 -0
- package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/interface.js +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +34 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/missing_txs.js +130 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +54 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +139 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts +20 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.d.ts.map +1 -0
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +21 -0
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +22 -3
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +63 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +12 -0
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/interface.d.ts +13 -2
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +16 -2
- package/dest/services/reqresp/metrics.d.ts +6 -5
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +17 -21
- package/dest/services/reqresp/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +5 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +12 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +7 -5
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +27 -9
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +30 -7
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +60 -14
- package/dest/services/reqresp/protocols/status.d.ts +5 -4
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -3
- package/dest/services/reqresp/protocols/tx.d.ts +8 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +6 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +471 -50
- package/dest/services/service.d.ts +55 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +22 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +56 -2
- package/dest/services/tx_collection/fast_tx_collection.d.ts +10 -6
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +71 -44
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +167 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +37 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +90 -0
- package/dest/services/tx_collection/index.d.ts +3 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +2 -0
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +11 -13
- package/dest/services/tx_collection/missing_txs_tracker.d.ts +32 -0
- package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +1 -0
- package/dest/services/tx_collection/missing_txs_tracker.js +27 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +49 -0
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -0
- package/dest/services/tx_collection/proposal_tx_collector.js +50 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +9 -4
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +60 -26
- package/dest/services/tx_collection/tx_collection.d.ts +31 -17
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +79 -7
- package/dest/services/tx_collection/tx_collection_sink.d.ts +18 -8
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +26 -29
- package/dest/services/tx_collection/tx_source.d.ts +8 -3
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.js +19 -2
- package/dest/services/tx_file_store/config.d.ts +16 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +22 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +48 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +152 -0
- package/dest/services/tx_provider.d.ts +6 -4
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +16 -6
- package/dest/services/tx_provider_instrumentation.d.ts +5 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +14 -14
- package/dest/test-helpers/index.d.ts +3 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +2 -0
- package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +29 -2
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +103 -2
- package/dest/test-helpers/mock-tx-helpers.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -1
- package/dest/test-helpers/test_tx_provider.d.ts +40 -0
- package/dest/test-helpers/test_tx_provider.d.ts.map +1 -0
- package/dest/test-helpers/test_tx_provider.js +41 -0
- package/dest/test-helpers/testbench-utils.d.ts +163 -0
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -0
- package/dest/test-helpers/testbench-utils.js +366 -0
- package/dest/testbench/p2p_client_testbench_worker.d.ts +28 -2
- package/dest/testbench/p2p_client_testbench_worker.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +221 -126
- package/dest/testbench/worker_client_manager.d.ts +51 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +226 -39
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/bootstrap/bootstrap.ts +7 -4
- package/src/client/factory.ts +98 -31
- package/src/client/interface.ts +76 -25
- package/src/client/p2p_client.ts +283 -307
- package/src/client/test/tx_proposal_collector/README.md +227 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +346 -0
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker_protocol.ts +43 -0
- package/src/config.ts +59 -29
- package/src/errors/tx-pool.error.ts +12 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +510 -78
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +614 -322
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/attestation_pool/mocks.ts +22 -15
- package/src/mem_pools/index.ts +4 -1
- package/src/mem_pools/instrumentation.ts +39 -14
- package/src/mem_pools/interface.ts +5 -7
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +367 -371
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
- package/src/mem_pools/tx_pool_v2/README.md +275 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +321 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +160 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +121 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +122 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +27 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +209 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +91 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +90 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
- package/src/mem_pools/tx_pool_v2/index.ts +12 -0
- package/src/mem_pools/tx_pool_v2/instrumentation.ts +69 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +242 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +242 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +444 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +223 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +1069 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +21 -18
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
- package/src/msg_validators/tx_validator/archive_cache.ts +3 -3
- package/src/msg_validators/tx_validator/block_header_validator.ts +21 -8
- package/src/msg_validators/tx_validator/data_validator.ts +18 -6
- package/src/msg_validators/tx_validator/double_spend_validator.ts +15 -9
- package/src/msg_validators/tx_validator/factory.ts +67 -25
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +17 -28
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +19 -8
- package/src/msg_validators/tx_validator/phases_validator.ts +5 -3
- package/src/msg_validators/tx_validator/size_validator.ts +22 -0
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +30 -19
- package/src/msg_validators/tx_validator/tx_permitted_validator.ts +8 -3
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +8 -3
- package/src/services/data_store.ts +10 -7
- package/src/services/discv5/discV5_service.ts +1 -1
- package/src/services/dummy_service.ts +68 -1
- package/src/services/encoding.ts +9 -7
- package/src/services/gossipsub/README.md +641 -0
- package/src/services/gossipsub/index.ts +2 -0
- package/src/services/gossipsub/scoring.ts +29 -5
- package/src/services/gossipsub/topic_score_params.ts +487 -0
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/instrumentation.ts +32 -73
- package/src/services/libp2p/libp2p_service.ts +661 -316
- package/src/services/peer-manager/metrics.ts +39 -21
- package/src/services/peer-manager/peer_manager.ts +5 -4
- package/src/services/peer-manager/peer_scoring.ts +28 -4
- package/src/services/reqresp/batch-tx-requester/README.md +305 -0
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +706 -0
- package/src/services/reqresp/batch-tx-requester/config.ts +40 -0
- package/src/services/reqresp/batch-tx-requester/interface.ts +53 -0
- package/src/services/reqresp/batch-tx-requester/missing_txs.ts +161 -0
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +205 -0
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +37 -0
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +65 -4
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +19 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +30 -2
- package/src/services/reqresp/metrics.ts +36 -27
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +16 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +35 -12
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +75 -10
- package/src/services/reqresp/protocols/status.ts +16 -12
- package/src/services/reqresp/protocols/tx.ts +23 -2
- package/src/services/reqresp/reqresp.ts +79 -22
- package/src/services/service.ts +72 -4
- package/src/services/tx_collection/config.ts +84 -2
- package/src/services/tx_collection/fast_tx_collection.ts +96 -49
- package/src/services/tx_collection/file_store_tx_collection.ts +202 -0
- package/src/services/tx_collection/file_store_tx_source.ts +117 -0
- package/src/services/tx_collection/index.ts +6 -0
- package/src/services/tx_collection/instrumentation.ts +11 -13
- package/src/services/tx_collection/missing_txs_tracker.ts +52 -0
- package/src/services/tx_collection/proposal_tx_collector.ts +113 -0
- package/src/services/tx_collection/slow_tx_collection.ts +69 -36
- package/src/services/tx_collection/tx_collection.ts +122 -24
- package/src/services/tx_collection/tx_collection_sink.ts +30 -34
- package/src/services/tx_collection/tx_source.ts +22 -3
- package/src/services/tx_file_store/config.ts +37 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +175 -0
- package/src/services/tx_provider.ts +27 -10
- package/src/services/tx_provider_instrumentation.ts +24 -14
- package/src/test-helpers/index.ts +2 -0
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +144 -4
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +3 -2
- package/src/test-helpers/test_tx_provider.ts +64 -0
- package/src/test-helpers/testbench-utils.ts +430 -0
- package/src/testbench/p2p_client_testbench_worker.ts +349 -123
- package/src/testbench/worker_client_manager.ts +304 -42
- package/src/util.ts +7 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -37
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -213
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -30
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -219
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -298
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -287
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -1,130 +1,562 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
6
|
+
import {
|
|
7
|
+
BlockProposal,
|
|
8
|
+
CheckpointAttestation,
|
|
9
|
+
CheckpointProposal,
|
|
10
|
+
type CheckpointProposalCore,
|
|
11
|
+
} from '@aztec/stdlib/p2p';
|
|
12
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
|
+
|
|
14
|
+
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
15
|
+
|
|
16
|
+
/** Result of trying to add an item (proposal or attestation) to the pool */
|
|
17
|
+
export type TryAddResult = {
|
|
18
|
+
/** Whether the item was added */
|
|
19
|
+
added: boolean;
|
|
20
|
+
/** Whether the exact item already existed */
|
|
21
|
+
alreadyExists: boolean;
|
|
22
|
+
/** Count of items for the position. Meaning varies by method:
|
|
23
|
+
* - tryAddBlockProposal: proposals at (slot, indexWithinCheckpoint)
|
|
24
|
+
* - tryAddCheckpointProposal: proposals at slot
|
|
25
|
+
* - tryAddCheckpointAttestation: attestations by this signer for this slot */
|
|
26
|
+
count: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const MAX_CHECKPOINT_PROPOSALS_PER_SLOT = 5;
|
|
30
|
+
export const MAX_BLOCK_PROPOSALS_PER_POSITION = 3;
|
|
31
|
+
/** Maximum attestations a single signer can make per slot before being rejected. */
|
|
32
|
+
export const MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER = 3;
|
|
33
|
+
|
|
34
|
+
/** Public API interface for attestation pools. Used for typing mocks and test implementations. */
|
|
35
|
+
export type AttestationPoolApi = Pick<
|
|
36
|
+
AttestationPool,
|
|
37
|
+
| 'tryAddBlockProposal'
|
|
38
|
+
| 'getBlockProposal'
|
|
39
|
+
| 'tryAddCheckpointProposal'
|
|
40
|
+
| 'getCheckpointProposal'
|
|
41
|
+
| 'addOwnCheckpointAttestations'
|
|
42
|
+
| 'tryAddCheckpointAttestation'
|
|
43
|
+
| 'deleteOlderThan'
|
|
44
|
+
| 'getCheckpointAttestationsForSlot'
|
|
45
|
+
| 'getCheckpointAttestationsForSlotAndProposal'
|
|
46
|
+
| 'hasBlockProposalsForSlot'
|
|
47
|
+
| 'isEmpty'
|
|
48
|
+
>;
|
|
3
49
|
|
|
4
50
|
/**
|
|
5
|
-
*
|
|
51
|
+
* Pool for storing attestations and proposals collected by a validator.
|
|
6
52
|
*
|
|
7
|
-
* Attestations
|
|
53
|
+
* Attestations and proposals observed via the p2p network are stored for requests
|
|
8
54
|
* from the validator to produce a block, or to serve to other peers.
|
|
9
55
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
56
|
+
export class AttestationPool {
|
|
57
|
+
private metrics: PoolInstrumentation<CheckpointAttestation>;
|
|
58
|
+
|
|
59
|
+
// Checkpoint attestations from attestation key (slot-proposalId-signer) to serialized CheckpointAttestation
|
|
60
|
+
// Keys are lexicographically sortable allowing range queries by slot or by (slot, proposalId)
|
|
61
|
+
private checkpointAttestations: AztecAsyncMap<string, Buffer>;
|
|
62
|
+
|
|
63
|
+
// Checkpoint proposals from proposal archive to serialized CheckpointProposal
|
|
64
|
+
private checkpointProposals: AztecAsyncMap<string, Buffer>;
|
|
65
|
+
|
|
66
|
+
// Checkpoint proposals indexed by slot for querying all proposals in a slot
|
|
67
|
+
// Key: slot number, Value: proposal archive strings
|
|
68
|
+
private checkpointProposalsForSlot: AztecAsyncMultiMap<number, string>;
|
|
69
|
+
|
|
70
|
+
// Block proposals from proposal archive to serialized BlockProposal
|
|
71
|
+
private blockProposals: AztecAsyncMap<string, Buffer>;
|
|
72
|
+
|
|
73
|
+
// Block proposals indexed by slot and index-within-checkpoint for duplicate detection
|
|
74
|
+
// Key: (slot << 10) | indexWithinCheckpoint, Value: archive string
|
|
75
|
+
private blockProposalsForSlotAndIndex: AztecAsyncMultiMap<number, string>;
|
|
76
|
+
|
|
77
|
+
// Checkpoint attestations indexed by (slot, signer) for tracking attestations per (slot, signer) for duplicate detection
|
|
78
|
+
// Key: `${Fr(slot).toString()}-${signerAddress}` string (padded for lexicographic ordering), Value: `proposalId` strings
|
|
79
|
+
private checkpointAttestationsPerSlotAndSigner: AztecAsyncMultiMap<string, string>;
|
|
80
|
+
|
|
81
|
+
constructor(
|
|
82
|
+
private store: AztecAsyncKVStore,
|
|
83
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
84
|
+
private log = createLogger('aztec:attestation_pool'),
|
|
85
|
+
) {
|
|
86
|
+
// Initialize block proposal storage
|
|
87
|
+
this.blockProposals = store.openMap('proposals');
|
|
88
|
+
this.blockProposalsForSlotAndIndex = store.openMultiMap('block_proposals_for_slot_and_index');
|
|
89
|
+
|
|
90
|
+
// Initialize checkpoint attestations storage
|
|
91
|
+
this.checkpointAttestations = store.openMap('checkpoint_attestations');
|
|
92
|
+
this.checkpointAttestationsPerSlotAndSigner = store.openMultiMap('checkpoint_attestations_per_slot_and_signer');
|
|
93
|
+
|
|
94
|
+
// Initialize checkpoint proposal storage
|
|
95
|
+
this.checkpointProposals = store.openMap('checkpoint_proposals');
|
|
96
|
+
this.checkpointProposalsForSlot = store.openMultiMap('checkpoint_proposals_for_slot');
|
|
97
|
+
|
|
98
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL, this.poolStats);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private poolStats: PoolStatsCallback = async () => {
|
|
102
|
+
return {
|
|
103
|
+
itemCount: await this.checkpointAttestations.sizeAsync(),
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** Returns whether the pool is empty. */
|
|
108
|
+
public async isEmpty(): Promise<boolean> {
|
|
109
|
+
for await (const _ of this.checkpointAttestations.entriesAsync()) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
for await (const _ of this.blockProposals.entriesAsync()) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private getProposalKey(slot: number | bigint | Fr | string, proposalId: Fr | string | Buffer): string {
|
|
119
|
+
const slotStr = typeof slot === 'string' ? slot : new Fr(slot).toString();
|
|
120
|
+
const proposalIdStr =
|
|
121
|
+
typeof proposalId === 'string'
|
|
122
|
+
? proposalId
|
|
123
|
+
: Buffer.isBuffer(proposalId)
|
|
124
|
+
? Fr.fromBuffer(proposalId).toString()
|
|
125
|
+
: proposalId.toString();
|
|
126
|
+
|
|
127
|
+
return `${slotStr}-${proposalIdStr}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private getAttestationKey(slot: number | bigint | Fr | string, proposalId: Fr | string, address: string): string {
|
|
131
|
+
return `${this.getProposalKey(slot, proposalId)}-${address}`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Returns range bounds for querying all attestations for a given slot. */
|
|
135
|
+
private getAttestationKeyRangeForSlot(slot: SlotNumber): { start: string; end: string } {
|
|
136
|
+
const slotStr = new Fr(slot).toString();
|
|
137
|
+
return { start: `${slotStr}-`, end: `${slotStr}-Z` }; // 'Z' sorts after any hex character
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Returns range bounds for querying all attestations for a given (slot, proposalId). */
|
|
141
|
+
private getAttestationKeyRangeForProposal(slot: SlotNumber, proposalId: string): { start: string; end: string } {
|
|
142
|
+
const proposalKey = this.getProposalKey(slot, proposalId);
|
|
143
|
+
return { start: `${proposalKey}-`, end: `${proposalKey}-Z` };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Creates a key for the per-signer-per-slot attestation index. Uses padded slot for lexicographic ordering. */
|
|
147
|
+
private getSlotSignerKey(slot: SlotNumber, signerAddress: string): string {
|
|
148
|
+
const slotStr = new Fr(slot).toString();
|
|
149
|
+
return `${slotStr}-${signerAddress}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Number of bits reserved for indexWithinCheckpoint in position keys. */
|
|
153
|
+
private static readonly INDEX_BITS = 10;
|
|
154
|
+
/** Maximum indexWithinCheckpoint value (2^10 - 1 = 1023). */
|
|
155
|
+
private static readonly MAX_INDEX = (1 << AttestationPool.INDEX_BITS) - 1;
|
|
156
|
+
|
|
157
|
+
/** Creates a position key for block proposals: (slot << 10) | indexWithinCheckpoint. */
|
|
158
|
+
private getBlockPositionKey(slot: number, indexWithinCheckpoint: number): number {
|
|
159
|
+
if (indexWithinCheckpoint > AttestationPool.MAX_INDEX) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
`Value for indexWithinCheckpoint ${indexWithinCheckpoint} exceeds maximum ${AttestationPool.MAX_INDEX}`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return (slot << AttestationPool.INDEX_BITS) | indexWithinCheckpoint;
|
|
165
|
+
}
|
|
15
166
|
|
|
16
167
|
/**
|
|
17
|
-
*
|
|
168
|
+
* Attempts to add a block proposal to the pool.
|
|
18
169
|
*
|
|
19
|
-
*
|
|
170
|
+
* This method performs validation and addition in a single call:
|
|
171
|
+
* - Checks if the proposal already exists (returns alreadyExists: true if so)
|
|
172
|
+
* - Checks if the position has reached the proposal cap (returns added: false if so)
|
|
173
|
+
* - Adds the proposal if validation passes
|
|
20
174
|
*
|
|
21
|
-
* @
|
|
175
|
+
* @param blockProposal - The block proposal to add
|
|
176
|
+
* @returns Result indicating whether the proposal was added and duplicate detection info
|
|
22
177
|
*/
|
|
23
|
-
|
|
178
|
+
public async tryAddBlockProposal(blockProposal: BlockProposal): Promise<TryAddResult> {
|
|
179
|
+
return await this.store.transactionAsync(async () => {
|
|
180
|
+
const proposalId = blockProposal.archive.toString();
|
|
181
|
+
|
|
182
|
+
// Check if already exists
|
|
183
|
+
const alreadyExists = await this.blockProposals.hasAsync(proposalId);
|
|
184
|
+
if (alreadyExists) {
|
|
185
|
+
const count = await this.getBlockProposalCountForPosition(
|
|
186
|
+
blockProposal.slotNumber,
|
|
187
|
+
blockProposal.indexWithinCheckpoint,
|
|
188
|
+
);
|
|
189
|
+
return { added: false, alreadyExists: true, count };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Get current count for position and check cap, do not add if exceeded
|
|
193
|
+
const count = await this.getBlockProposalCountForPosition(
|
|
194
|
+
blockProposal.slotNumber,
|
|
195
|
+
blockProposal.indexWithinCheckpoint,
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
if (count >= MAX_BLOCK_PROPOSALS_PER_POSITION) {
|
|
199
|
+
return { added: false, alreadyExists: false, count };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Add the proposal
|
|
203
|
+
await this.addBlockProposal(blockProposal);
|
|
204
|
+
|
|
205
|
+
this.log.debug(
|
|
206
|
+
`Added block proposal for slot ${blockProposal.slotNumber} and index ${blockProposal.indexWithinCheckpoint}`,
|
|
207
|
+
{
|
|
208
|
+
proposalId,
|
|
209
|
+
slotNumber: blockProposal.slotNumber,
|
|
210
|
+
indexWithinCheckpoint: blockProposal.indexWithinCheckpoint,
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return { added: true, alreadyExists: false, count: count + 1 };
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Gets the count of block proposals for a given position (slot, indexWithinCheckpoint). */
|
|
219
|
+
private getBlockProposalCountForPosition(
|
|
220
|
+
slot: SlotNumber,
|
|
221
|
+
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
222
|
+
): Promise<number> {
|
|
223
|
+
const positionKey = this.getBlockPositionKey(slot, indexWithinCheckpoint);
|
|
224
|
+
return this.blockProposalsForSlotAndIndex.getValueCountAsync(positionKey);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Internal method - must be called within a transaction. */
|
|
228
|
+
private async addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
229
|
+
const proposalId = blockProposal.archive.toString();
|
|
230
|
+
// Strip signedTxs before storing to avoid persisting full tx data
|
|
231
|
+
await this.blockProposals.set(proposalId, blockProposal.withoutSignedTxs().toBuffer());
|
|
232
|
+
|
|
233
|
+
// Index by slot and position for duplicate detection
|
|
234
|
+
const positionKey = this.getBlockPositionKey(blockProposal.slotNumber, blockProposal.indexWithinCheckpoint);
|
|
235
|
+
await this.blockProposalsForSlotAndIndex.set(positionKey, proposalId);
|
|
236
|
+
}
|
|
24
237
|
|
|
25
238
|
/**
|
|
26
|
-
*
|
|
239
|
+
* Get block proposal by its ID.
|
|
27
240
|
*
|
|
28
|
-
* @param
|
|
241
|
+
* @param id - The ID of the block proposal to retrieve. The ID is proposal.payload.archive
|
|
29
242
|
*
|
|
30
|
-
* @return
|
|
243
|
+
* @return The block proposal if it exists, otherwise undefined.
|
|
31
244
|
*/
|
|
32
|
-
|
|
245
|
+
public async getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
246
|
+
const buffer = await this.blockProposals.getAsync(id);
|
|
247
|
+
try {
|
|
248
|
+
if (buffer && buffer.length > 0) {
|
|
249
|
+
return BlockProposal.fromBuffer(buffer);
|
|
250
|
+
}
|
|
251
|
+
} catch {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
33
254
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* @param attestations - Attestations to add into the pool
|
|
38
|
-
*/
|
|
39
|
-
addAttestations(attestations: BlockAttestation[]): Promise<void>;
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
40
257
|
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
258
|
+
/** Checks if any block proposals exist for a given slot (at index 0). */
|
|
259
|
+
public async hasBlockProposalsForSlot(slot: SlotNumber): Promise<boolean> {
|
|
260
|
+
const positionKey = this.getBlockPositionKey(slot, 0);
|
|
261
|
+
const count = await this.blockProposalsForSlotAndIndex.getValueCountAsync(positionKey);
|
|
262
|
+
return count > 0;
|
|
263
|
+
}
|
|
47
264
|
|
|
48
265
|
/**
|
|
49
|
-
*
|
|
266
|
+
* Attempts to add a checkpoint proposal to the pool.
|
|
267
|
+
*
|
|
268
|
+
* This method performs validation and addition in a single call:
|
|
269
|
+
* - Checks if the proposal already exists (returns alreadyExists: true if so)
|
|
270
|
+
* - Checks if the slot has reached the proposal cap (returns added: false if so)
|
|
271
|
+
* - Adds the proposal if validation passes
|
|
50
272
|
*
|
|
51
|
-
*
|
|
273
|
+
* Note: This method only handles the CheckpointProposalCore. If the original
|
|
274
|
+
* CheckpointProposal contains a lastBlock, the caller should extract it via
|
|
275
|
+
* getBlockProposal() and add it separately via tryAddBlockProposal().
|
|
52
276
|
*
|
|
53
|
-
* @param
|
|
277
|
+
* @param proposal - The checkpoint proposal core to add
|
|
278
|
+
* @returns Result indicating whether the proposal was added and duplicate detection info
|
|
54
279
|
*/
|
|
55
|
-
|
|
280
|
+
public async tryAddCheckpointProposal(proposal: CheckpointProposalCore): Promise<TryAddResult> {
|
|
281
|
+
return await this.store.transactionAsync(async () => {
|
|
282
|
+
const proposalId = proposal.archive.toString();
|
|
283
|
+
|
|
284
|
+
// Check if already exists
|
|
285
|
+
const alreadyExists = await this.checkpointProposals.hasAsync(proposalId);
|
|
286
|
+
if (alreadyExists) {
|
|
287
|
+
const count = await this.checkpointProposalsForSlot.getValueCountAsync(proposal.slotNumber);
|
|
288
|
+
return { added: false, alreadyExists: true, count };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Get current count for slot and check cap
|
|
292
|
+
const count = await this.checkpointProposalsForSlot.getValueCountAsync(proposal.slotNumber);
|
|
293
|
+
if (count >= MAX_CHECKPOINT_PROPOSALS_PER_SLOT) {
|
|
294
|
+
return { added: false, alreadyExists: false, count };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Add the proposal if cap not exceeded
|
|
298
|
+
await this.addCheckpointProposal(proposal);
|
|
299
|
+
|
|
300
|
+
this.log.debug(`Added checkpoint proposal for slot ${proposal.slotNumber}`, {
|
|
301
|
+
proposalId,
|
|
302
|
+
slotNumber: proposal.slotNumber,
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
return { added: true, alreadyExists: false, count: count + 1 };
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Internal method - must be called within a transaction. */
|
|
310
|
+
private async addCheckpointProposal(proposal: CheckpointProposalCore): Promise<void> {
|
|
311
|
+
const slotKey = proposal.slotNumber;
|
|
312
|
+
const proposalId = proposal.archive.toString();
|
|
313
|
+
|
|
314
|
+
await this.checkpointProposalsForSlot.set(slotKey, proposalId);
|
|
315
|
+
await this.checkpointProposals.set(proposalId, proposal.toBuffer());
|
|
316
|
+
}
|
|
56
317
|
|
|
57
318
|
/**
|
|
58
|
-
*
|
|
319
|
+
* Get checkpoint proposal by its ID.
|
|
59
320
|
*
|
|
60
|
-
*
|
|
321
|
+
* Returns a CheckpointProposalCore (without lastBlock info) since the lastBlock
|
|
322
|
+
* is extracted and stored separately as a BlockProposal when added.
|
|
61
323
|
*
|
|
62
|
-
* @param
|
|
324
|
+
* @param id - The ID of the checkpoint proposal to retrieve (proposal.archive)
|
|
325
|
+
* @return The checkpoint proposal core if it exists, otherwise undefined.
|
|
63
326
|
*/
|
|
64
|
-
|
|
327
|
+
public async getCheckpointProposal(id: string): Promise<CheckpointProposalCore | undefined> {
|
|
328
|
+
const buffer = await this.checkpointProposals.getAsync(id);
|
|
329
|
+
try {
|
|
330
|
+
if (buffer && buffer.length > 0) {
|
|
331
|
+
return CheckpointProposal.fromBuffer(buffer);
|
|
332
|
+
}
|
|
333
|
+
} catch {
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
65
339
|
|
|
66
340
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* Removes all attestations associated with a slot and proposal
|
|
70
|
-
*
|
|
71
|
-
* @param slot - The slot to delete.
|
|
72
|
-
* @param proposalId - The proposal to delete.
|
|
341
|
+
* Adds own checkpoint attestations to the pool.
|
|
342
|
+
* Skips validations on number of checkpoint attestations stored for the given slot.
|
|
73
343
|
*/
|
|
74
|
-
|
|
344
|
+
public async addOwnCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
345
|
+
await this.store.transactionAsync(async () => {
|
|
346
|
+
for (const attestation of attestations) {
|
|
347
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
348
|
+
const proposalId = attestation.archive;
|
|
349
|
+
const sender = attestation.getSender();
|
|
350
|
+
|
|
351
|
+
// Skip attestations with invalid signatures
|
|
352
|
+
if (!sender) {
|
|
353
|
+
this.log.warn(`Skipping own checkpoint attestation with invalid signature for slot ${slotNumber}`, {
|
|
354
|
+
signature: attestation.signature.toString(),
|
|
355
|
+
slotNumber,
|
|
356
|
+
proposalId,
|
|
357
|
+
});
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const address = sender.toString();
|
|
362
|
+
|
|
363
|
+
await this.checkpointAttestations.set(
|
|
364
|
+
this.getAttestationKey(slotNumber, proposalId, address),
|
|
365
|
+
attestation.toBuffer(),
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
this.log.debug(`Added own checkpoint attestation for slot ${slotNumber} from ${address}`, {
|
|
369
|
+
signature: attestation.signature.toString(),
|
|
370
|
+
slotNumber,
|
|
371
|
+
address,
|
|
372
|
+
proposalId,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
75
377
|
|
|
76
378
|
/**
|
|
77
|
-
* Get all
|
|
78
|
-
*
|
|
79
|
-
* Retrieve all of the attestations observed pertaining to a given slot
|
|
379
|
+
* Get all checkpoint attestations for a given slot.
|
|
80
380
|
*
|
|
81
381
|
* @param slot - The slot to query
|
|
82
|
-
* @return
|
|
382
|
+
* @return CheckpointAttestations
|
|
83
383
|
*/
|
|
84
|
-
|
|
384
|
+
public async getCheckpointAttestationsForSlot(slot: SlotNumber): Promise<CheckpointAttestation[]> {
|
|
385
|
+
const range = this.getAttestationKeyRangeForSlot(slot);
|
|
386
|
+
const attestations: CheckpointAttestation[] = [];
|
|
387
|
+
|
|
388
|
+
for await (const [_, buf] of this.checkpointAttestations.entriesAsync(range)) {
|
|
389
|
+
attestations.push(CheckpointAttestation.fromBuffer(buf));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return attestations;
|
|
393
|
+
}
|
|
85
394
|
|
|
86
395
|
/**
|
|
87
|
-
* Get
|
|
88
|
-
*
|
|
89
|
-
* Retrieve all of the attestations observed pertaining to a given slot
|
|
396
|
+
* Get checkpoint attestations for slot and given proposal.
|
|
90
397
|
*
|
|
91
398
|
* @param slot - The slot to query
|
|
92
399
|
* @param proposalId - The proposal to query
|
|
93
|
-
* @return
|
|
400
|
+
* @return CheckpointAttestations
|
|
94
401
|
*/
|
|
95
|
-
|
|
402
|
+
public async getCheckpointAttestationsForSlotAndProposal(
|
|
403
|
+
slot: SlotNumber,
|
|
404
|
+
proposalId: string,
|
|
405
|
+
): Promise<CheckpointAttestation[]> {
|
|
406
|
+
const range = this.getAttestationKeyRangeForProposal(slot, proposalId);
|
|
407
|
+
const attestations: CheckpointAttestation[] = [];
|
|
96
408
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
hasAttestation(attestation: BlockAttestation): Promise<boolean>;
|
|
409
|
+
for await (const [_, buf] of this.checkpointAttestations.entriesAsync(range)) {
|
|
410
|
+
attestations.push(CheckpointAttestation.fromBuffer(buf));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return attestations;
|
|
414
|
+
}
|
|
104
415
|
|
|
105
416
|
/**
|
|
106
|
-
*
|
|
107
|
-
* - True if the proposal already exists, allow overwrite to keep parity with tests.
|
|
108
|
-
* - True if the slot is below the proposal cap.
|
|
109
|
-
* - False if the slot is at/above cap and this would be a new unique proposal.
|
|
417
|
+
* Delete all pool data (attestations, proposals) older than the given slot.
|
|
110
418
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @returns True if the proposal can be added (or already exists), false otherwise.
|
|
419
|
+
* @param oldestSlot - The oldest slot to keep.
|
|
113
420
|
*/
|
|
114
|
-
|
|
421
|
+
public async deleteOlderThan(oldestSlot: SlotNumber): Promise<void> {
|
|
422
|
+
let numberOfAttestations = 0;
|
|
423
|
+
let numberOfCheckpointProposals = 0;
|
|
424
|
+
let numberOfBlockProposals = 0;
|
|
425
|
+
|
|
426
|
+
await this.store.transactionAsync(async () => {
|
|
427
|
+
// Delete checkpoint attestations with slot < oldestSlot
|
|
428
|
+
// Attestation keys start with Fr(slot).toString(), so we use end bound of Fr(oldestSlot).toString()
|
|
429
|
+
const attestationEndKey = new Fr(oldestSlot).toString();
|
|
430
|
+
for await (const key of this.checkpointAttestations.keysAsync({ end: attestationEndKey })) {
|
|
431
|
+
await this.checkpointAttestations.delete(key);
|
|
432
|
+
numberOfAttestations++;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Clean up per-signer-per-slot index. Keys are formatted as `${Fr(slot).toString()}-${signerAddress}`.
|
|
436
|
+
// Since Fr pads to fixed-width hex, Fr(oldestSlot) is lexicographically greater than any key with
|
|
437
|
+
// a smaller slot (even with the signer suffix), so using it as the exclusive end bound is correct.
|
|
438
|
+
const slotSignerEndKey = new Fr(oldestSlot).toString();
|
|
439
|
+
for await (const key of this.checkpointAttestationsPerSlotAndSigner.keysAsync({ end: slotSignerEndKey })) {
|
|
440
|
+
await this.checkpointAttestationsPerSlotAndSigner.delete(key);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Delete checkpoint proposals for slots < oldestSlot, using checkpointProposalsForSlot as index
|
|
444
|
+
for await (const slot of this.checkpointProposalsForSlot.keysAsync({ end: oldestSlot })) {
|
|
445
|
+
const proposalIds = await toArray(this.checkpointProposalsForSlot.getValuesAsync(slot));
|
|
446
|
+
for (const proposalId of proposalIds) {
|
|
447
|
+
await this.checkpointProposals.delete(proposalId);
|
|
448
|
+
numberOfCheckpointProposals++;
|
|
449
|
+
}
|
|
450
|
+
await this.checkpointProposalsForSlot.delete(slot);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Delete block proposals for slots < oldestSlot, using blockProposalsForSlotAndIndex as index
|
|
454
|
+
// Key format: (slot << INDEX_BITS) | indexWithinCheckpoint
|
|
455
|
+
const blockPositionEndKey = oldestSlot << AttestationPool.INDEX_BITS;
|
|
456
|
+
for await (const positionKey of this.blockProposalsForSlotAndIndex.keysAsync({ end: blockPositionEndKey })) {
|
|
457
|
+
const proposalIds = await toArray(this.blockProposalsForSlotAndIndex.getValuesAsync(positionKey));
|
|
458
|
+
for (const proposalId of proposalIds) {
|
|
459
|
+
await this.blockProposals.delete(proposalId);
|
|
460
|
+
numberOfBlockProposals++;
|
|
461
|
+
}
|
|
462
|
+
await this.blockProposalsForSlotAndIndex.delete(positionKey);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
this.log.verbose(`Deleted old pool data`, {
|
|
467
|
+
oldestSlot,
|
|
468
|
+
numberOfAttestations,
|
|
469
|
+
numberOfCheckpointProposals,
|
|
470
|
+
numberOfBlockProposals,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
115
473
|
|
|
116
474
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* -
|
|
475
|
+
* Attempts to add a checkpoint attestation to the pool.
|
|
476
|
+
*
|
|
477
|
+
* This method performs validation and addition in a single call:
|
|
478
|
+
* - Checks if the attestation already exists (returns alreadyExists: true if so)
|
|
479
|
+
* - Checks if this signer has reached the per-signer attestation cap for this slot
|
|
480
|
+
* - Adds the attestation if validation passes
|
|
121
481
|
*
|
|
122
|
-
* @param attestation - The attestation to
|
|
123
|
-
* @
|
|
124
|
-
*
|
|
482
|
+
* @param attestation - The checkpoint attestation to add
|
|
483
|
+
* @returns Result indicating whether the attestation was added, existence info, and count of
|
|
484
|
+
* attestations by this signer for this slot (for equivocation detection)
|
|
125
485
|
*/
|
|
126
|
-
|
|
486
|
+
public async tryAddCheckpointAttestation(attestation: CheckpointAttestation): Promise<TryAddResult> {
|
|
487
|
+
const slotNumber = attestation.payload.header.slotNumber;
|
|
488
|
+
const proposalId = attestation.archive.toString();
|
|
489
|
+
const sender = attestation.getSender();
|
|
127
490
|
|
|
128
|
-
|
|
129
|
-
|
|
491
|
+
if (!sender) {
|
|
492
|
+
return { added: false, alreadyExists: false, count: 0 };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const signerAddress = sender.toString();
|
|
496
|
+
|
|
497
|
+
return await this.store.transactionAsync(async () => {
|
|
498
|
+
const key = this.getAttestationKey(slotNumber, proposalId, signerAddress);
|
|
499
|
+
const alreadyExists = await this.checkpointAttestations.hasAsync(key);
|
|
500
|
+
|
|
501
|
+
// Get count of attestations by this signer for this slot (for duplicate detection)
|
|
502
|
+
const signerAttestationCount = await this.getSignerAttestationCountForSlot(slotNumber, signerAddress);
|
|
503
|
+
|
|
504
|
+
if (alreadyExists) {
|
|
505
|
+
return {
|
|
506
|
+
added: false,
|
|
507
|
+
alreadyExists: true,
|
|
508
|
+
count: signerAttestationCount,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Check if this signer has exceeded the per-signer cap for this slot
|
|
513
|
+
if (signerAttestationCount >= MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER) {
|
|
514
|
+
this.log.debug(`Rejecting attestation: signer ${signerAddress} exceeded per-slot cap for slot ${slotNumber}`, {
|
|
515
|
+
slotNumber,
|
|
516
|
+
signerAddress,
|
|
517
|
+
proposalId,
|
|
518
|
+
signerAttestationCount,
|
|
519
|
+
});
|
|
520
|
+
return {
|
|
521
|
+
added: false,
|
|
522
|
+
alreadyExists: false,
|
|
523
|
+
count: signerAttestationCount,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Add the attestation
|
|
528
|
+
await this.checkpointAttestations.set(key, attestation.toBuffer());
|
|
529
|
+
|
|
530
|
+
// Track this attestation in the per-signer-per-slot index for duplicate detection
|
|
531
|
+
const slotSignerKey = this.getSlotSignerKey(slotNumber, signerAddress);
|
|
532
|
+
await this.checkpointAttestationsPerSlotAndSigner.set(slotSignerKey, proposalId);
|
|
533
|
+
|
|
534
|
+
this.log.debug(`Added checkpoint attestation for slot ${slotNumber} from ${signerAddress}`, {
|
|
535
|
+
signature: attestation.signature.toString(),
|
|
536
|
+
slotNumber,
|
|
537
|
+
address: signerAddress,
|
|
538
|
+
proposalId,
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
// Return the new count
|
|
542
|
+
return {
|
|
543
|
+
added: true,
|
|
544
|
+
alreadyExists: false,
|
|
545
|
+
count: signerAttestationCount + 1,
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** Gets the count of attestations by a specific signer for a given slot. */
|
|
551
|
+
private async getSignerAttestationCountForSlot(slot: SlotNumber, signerAddress: string): Promise<number> {
|
|
552
|
+
const slotSignerKey = this.getSlotSignerKey(slot, signerAddress);
|
|
553
|
+
return await this.checkpointAttestationsPerSlotAndSigner.getValueCountAsync(slotSignerKey);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** Creates an AttestationPool backed by a temporary store for testing. */
|
|
558
|
+
export async function createTestAttestationPool(telemetry?: TelemetryClient): Promise<AttestationPool> {
|
|
559
|
+
const { openTmpStore } = await import('@aztec/kv-store/lmdb-v2');
|
|
560
|
+
const store = await openTmpStore('test-attestation-pool');
|
|
561
|
+
return new AttestationPool(store, telemetry);
|
|
130
562
|
}
|