@aztec/p2p 0.0.0-test.1 → 0.0.1-commit.5476d83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +22 -9
- package/dest/client/factory.d.ts +14 -4
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +60 -24
- package/dest/client/index.d.ts +2 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -0
- package/dest/client/interface.d.ts +157 -0
- package/dest/client/interface.d.ts.map +1 -0
- package/dest/client/interface.js +9 -0
- package/dest/client/p2p_client.d.ts +72 -187
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +373 -177
- package/dest/config.d.ts +151 -125
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +183 -34
- package/dest/enr/generate-enr.d.ts +11 -3
- package/dest/enr/generate-enr.d.ts.map +1 -1
- package/dest/enr/generate-enr.js +27 -5
- package/dest/enr/index.d.ts +1 -1
- package/dest/errors/attestation-pool.error.d.ts +7 -0
- package/dest/errors/attestation-pool.error.d.ts.map +1 -0
- package/dest/errors/attestation-pool.error.js +12 -0
- package/dest/errors/reqresp.error.d.ts +1 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/index.d.ts +4 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +68 -8
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +214 -63
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -6
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +126 -25
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +19 -6
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +111 -21
- package/dest/mem_pools/attestation_pool/mocks.d.ts +225 -5
- 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/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +10 -12
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +35 -38
- package/dest/mem_pools/interface.d.ts +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +62 -13
- 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/index.d.ts +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +34 -10
- 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.d.ts +1 -1
- package/dest/mem_pools/tx_pool/priority.js +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +65 -9
- 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 +264 -39
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +45 -9
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +20 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +67 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -1
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/index.js +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +6 -2
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +73 -12
- package/dest/msg_validators/block_proposal_validator/index.d.ts +1 -1
- package/dest/msg_validators/index.d.ts +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts +10 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -0
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.js +36 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +3 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +27 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/archive_cache.js +22 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +4 -4
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +56 -86
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +21 -27
- package/dest/msg_validators/tx_validator/factory.d.ts +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 +8 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +7 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +8 -4
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +39 -20
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +14 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/phases_validator.js +93 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +17 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/test_utils.js +22 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +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 +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +6 -5
- package/dest/services/data_store.d.ts +1 -1
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.d.ts +10 -9
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +63 -36
- package/dest/services/dummy_service.d.ts +50 -11
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +88 -5
- package/dest/services/encoding.d.ts +26 -7
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +73 -5
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +5 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +4 -0
- package/dest/services/libp2p/instrumentation.d.ts +20 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +164 -0
- package/dest/services/libp2p/libp2p_service.d.ts +78 -89
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +698 -246
- package/dest/services/peer-manager/interface.d.ts +23 -0
- package/dest/services/peer-manager/interface.d.ts.map +1 -0
- package/dest/services/peer-manager/interface.js +1 -0
- package/dest/services/peer-manager/metrics.d.ts +6 -2
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +22 -2
- package/dest/services/peer-manager/peer_manager.d.ts +102 -22
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +549 -72
- package/dest/services/peer-manager/peer_scoring.d.ts +7 -2
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +40 -2
- package/dest/services/reqresp/config.d.ts +11 -9
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +18 -4
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +10 -6
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +31 -17
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +142 -84
- package/dest/services/reqresp/index.d.ts +3 -2
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +73 -24
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +45 -26
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +6 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +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 +47 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.d.ts +3 -5
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +7 -7
- package/dest/services/reqresp/protocols/index.d.ts +3 -1
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/ping.d.ts +1 -3
- package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +39 -7
- 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 +13 -2
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +6 -4
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +10 -2
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +21 -1
- package/dest/services/reqresp/reqresp.d.ts +24 -66
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +298 -207
- package/dest/services/reqresp/status.d.ts +10 -4
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +9 -2
- package/dest/services/service.d.ts +23 -19
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +58 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +50 -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 +52 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +177 -0
- package/dest/services/tx_collection/tx_collection.d.ts +109 -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/generate-peer-id-private-keys.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts +1 -1
- package/dest/test-helpers/get-ports.d.ts.map +1 -1
- package/dest/test-helpers/index.d.ts +2 -1
- package/dest/test-helpers/index.d.ts.map +1 -1
- package/dest/test-helpers/index.js +1 -0
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +4 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts +33 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +86 -16
- package/dest/test-helpers/mock-pubsub.d.ts +59 -0
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -0
- package/dest/test-helpers/mock-pubsub.js +130 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts +12 -0
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -0
- package/dest/test-helpers/mock-tx-helpers.js +19 -0
- package/dest/test-helpers/reqresp-nodes.d.ts +15 -11
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +62 -28
- package/dest/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +103 -29
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/parse_log_file.js +4 -4
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/testbench.js +4 -4
- package/dest/testbench/worker_client_manager.d.ts +1 -6
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +11 -19
- package/dest/types/index.d.ts +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -0
- package/dest/util.d.ts +24 -16
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +75 -69
- package/dest/versioning.d.ts +4 -4
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +8 -3
- package/package.json +32 -27
- package/src/bootstrap/bootstrap.ts +27 -11
- package/src/client/factory.ts +136 -45
- package/src/client/index.ts +1 -0
- package/src/client/interface.ts +198 -0
- package/src/client/p2p_client.ts +469 -330
- package/src/config.ts +305 -134
- package/src/enr/generate-enr.ts +39 -6
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/index.ts +4 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +75 -7
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +264 -65
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +173 -34
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +156 -30
- package/src/mem_pools/attestation_pool/mocks.ts +11 -10
- package/src/mem_pools/instrumentation.ts +43 -44
- 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 +54 -11
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +91 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +82 -14
- package/src/msg_validators/msg_seen_validator/msg_seen_validator.ts +36 -0
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +35 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +28 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +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 +116 -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 +167 -0
- package/src/services/libp2p/libp2p_service.ts +866 -294
- package/src/services/peer-manager/interface.ts +29 -0
- package/src/services/peer-manager/metrics.ts +26 -1
- package/src/services/peer-manager/peer_manager.ts +654 -78
- package/src/services/peer-manager/peer_scoring.ts +46 -3
- package/src/services/reqresp/config.ts +26 -9
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +12 -6
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +148 -95
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +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 +233 -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 +151 -25
- package/src/testbench/parse_log_file.ts +4 -4
- package/src/testbench/testbench.ts +4 -4
- package/src/testbench/worker_client_manager.ts +17 -23
- package/src/types/index.ts +2 -0
- package/src/util.ts +105 -91
- package/src/versioning.ts +11 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
|
|
2
|
+
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
3
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
|
+
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
|
|
7
|
+
let defaultAllowedSetupFunctions: AllowedElement[] | undefined = undefined;
|
|
8
|
+
export async function getDefaultAllowedSetupFunctions(): Promise<AllowedElement[]> {
|
|
9
|
+
if (defaultAllowedSetupFunctions === undefined) {
|
|
10
|
+
defaultAllowedSetupFunctions = [
|
|
11
|
+
// needed for authwit support
|
|
12
|
+
{
|
|
13
|
+
address: ProtocolContractAddress.AuthRegistry,
|
|
14
|
+
},
|
|
15
|
+
// needed for claiming on the same tx as a spend
|
|
16
|
+
{
|
|
17
|
+
address: ProtocolContractAddress.FeeJuice,
|
|
18
|
+
// We can't restrict the selector because public functions get routed via dispatch.
|
|
19
|
+
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),u128)'),
|
|
20
|
+
},
|
|
21
|
+
// needed for private transfers via FPC
|
|
22
|
+
{
|
|
23
|
+
classId: (await getContractClassFromArtifact(TokenContractArtifact)).id,
|
|
24
|
+
// We can't restrict the selector because public functions get routed via dispatch.
|
|
25
|
+
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),u128)'),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
classId: (await getContractClassFromArtifact(FPCContract.artifact)).id,
|
|
29
|
+
// We can't restrict the selector because public functions get routed via dispatch.
|
|
30
|
+
// selector: FunctionSelector.fromSignature('prepare_fee((Field),Field,(Field),Field)'),
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
return defaultAllowedSetupFunctions;
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { ArchiveSource } from '@aztec/p2p';
|
|
3
|
+
import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
4
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Implements an archive source by checking a DB and an in-memory collection.
|
|
8
|
+
* Intended for validating transactions as they are added to a block.
|
|
9
|
+
*/
|
|
10
|
+
export class ArchiveCache implements ArchiveSource {
|
|
11
|
+
archives: Map<string, bigint>;
|
|
12
|
+
|
|
13
|
+
constructor(private db: MerkleTreeReadOperations) {
|
|
14
|
+
this.archives = new Map<string, bigint>();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async getArchiveIndices(archives: Fr[]): Promise<(bigint | undefined)[]> {
|
|
18
|
+
const toCheckDb = archives.filter(n => !this.archives.has(n.toString()));
|
|
19
|
+
const dbHits = await this.db.findLeafIndices(MerkleTreeId.ARCHIVE, toCheckDb);
|
|
20
|
+
dbHits.forEach((x, index) => {
|
|
21
|
+
if (x !== undefined) {
|
|
22
|
+
this.archives.set(toCheckDb[index].toString(), x);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return archives.map(n => this.archives.get(n.toString()));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { type AnyTx,
|
|
3
|
+
import { type AnyTx, TX_ERROR_BLOCK_HEADER, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
export interface ArchiveSource {
|
|
6
6
|
getArchiveIndices: (archives: Fr[]) => Promise<(bigint | undefined)[]>;
|
|
@@ -15,10 +15,10 @@ export class BlockHeaderTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async validateTx(tx: T): Promise<TxValidationResult> {
|
|
18
|
-
const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.
|
|
18
|
+
const [index] = await this.#archiveSource.getArchiveIndices([await tx.data.constants.anchorBlockHeader.hash()]);
|
|
19
19
|
if (index === undefined) {
|
|
20
|
-
this.#log.
|
|
21
|
-
return { result: 'invalid', reason: [
|
|
20
|
+
this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for referencing an unknown block header`);
|
|
21
|
+
return { result: 'invalid', reason: [TX_ERROR_BLOCK_HEADER] };
|
|
22
22
|
}
|
|
23
23
|
return { result: 'valid' };
|
|
24
24
|
}
|
|
@@ -1,106 +1,118 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import {
|
|
3
|
+
import { computeCalldataHash } from '@aztec/stdlib/hash';
|
|
4
|
+
import {
|
|
5
|
+
TX_ERROR_CALLDATA_COUNT_MISMATCH,
|
|
6
|
+
TX_ERROR_CALLDATA_COUNT_TOO_LARGE,
|
|
7
|
+
TX_ERROR_CONTRACT_CLASS_LOGS,
|
|
8
|
+
TX_ERROR_CONTRACT_CLASS_LOG_COUNT,
|
|
9
|
+
TX_ERROR_CONTRACT_CLASS_LOG_LENGTH,
|
|
10
|
+
TX_ERROR_CONTRACT_CLASS_LOG_SORTING,
|
|
11
|
+
TX_ERROR_INCORRECT_CALLDATA,
|
|
12
|
+
TX_ERROR_INCORRECT_HASH,
|
|
13
|
+
Tx,
|
|
14
|
+
type TxValidationResult,
|
|
15
|
+
type TxValidator,
|
|
16
|
+
} from '@aztec/stdlib/tx';
|
|
4
17
|
|
|
5
18
|
export class DataTxValidator implements TxValidator<Tx> {
|
|
6
19
|
#log = createLogger('p2p:tx_validator:tx_data');
|
|
7
20
|
|
|
8
21
|
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
22
|
+
const reason =
|
|
23
|
+
(await this.#hasCorrectHash(tx)) ??
|
|
24
|
+
(await this.#hasCorrectCalldata(tx)) ??
|
|
25
|
+
(await this.#hasCorrectContractClassLogs(tx));
|
|
26
|
+
return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
|
|
12
27
|
}
|
|
13
28
|
|
|
14
|
-
async #
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.#log.warn(
|
|
21
|
-
`Rejecting tx ${Tx.getHash(tx)} because of mismatch number of execution requests for public calls. Expected ${
|
|
22
|
-
callRequests.length
|
|
23
|
-
}. Got ${tx.enqueuedPublicFunctionCalls.length}.`,
|
|
29
|
+
async #hasCorrectHash(tx: Tx): Promise<string | undefined> {
|
|
30
|
+
const expected = await Tx.computeTxHash(tx);
|
|
31
|
+
if (!tx.getTxHash().equals(expected)) {
|
|
32
|
+
const reason = TX_ERROR_INCORRECT_HASH;
|
|
33
|
+
this.#log.verbose(
|
|
34
|
+
`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected hash ${expected.toString()}. Got ${tx.getTxHash().toString()}.`,
|
|
24
35
|
);
|
|
25
|
-
return
|
|
36
|
+
return reason;
|
|
26
37
|
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
27
40
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)}
|
|
41
|
+
async #hasCorrectCalldata(tx: Tx): Promise<string | undefined> {
|
|
42
|
+
if (tx.publicFunctionCalldata.length !== tx.numberOfPublicCalls()) {
|
|
43
|
+
const reason = TX_ERROR_CALLDATA_COUNT_MISMATCH;
|
|
44
|
+
this.#log.verbose(
|
|
45
|
+
`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected ${tx.numberOfPublicCalls()}. Got ${
|
|
46
|
+
tx.publicFunctionCalldata.length
|
|
47
|
+
}.`,
|
|
33
48
|
);
|
|
34
|
-
return
|
|
49
|
+
return reason;
|
|
35
50
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
)
|
|
42
|
-
).findIndex(Boolean);
|
|
43
|
-
if (invalidExecutionRequestIndex !== -1) {
|
|
44
|
-
this.#log.warn(
|
|
45
|
-
`Rejecting tx ${await Tx.getHash(
|
|
46
|
-
tx,
|
|
47
|
-
)} because of incorrect execution requests for public call at index ${invalidExecutionRequestIndex}.`,
|
|
51
|
+
|
|
52
|
+
if (tx.getTotalPublicCalldataCount() > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) {
|
|
53
|
+
const reason = TX_ERROR_CALLDATA_COUNT_TOO_LARGE;
|
|
54
|
+
this.#log.verbose(
|
|
55
|
+
`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected no greater than ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS} fields. Got ${tx.getTotalPublicCalldataCount()}.`,
|
|
48
56
|
);
|
|
49
|
-
return
|
|
57
|
+
return reason;
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
const callRequests = tx.getPublicCallRequestsWithCalldata();
|
|
61
|
+
for (let i = 0; i < callRequests.length; i++) {
|
|
62
|
+
const { request, calldata } = callRequests[i];
|
|
63
|
+
const hash = await computeCalldataHash(calldata);
|
|
64
|
+
if (!hash.equals(request.calldataHash)) {
|
|
65
|
+
const reason = TX_ERROR_INCORRECT_CALLDATA;
|
|
66
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Call request index: ${i}.`);
|
|
67
|
+
return reason;
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
|
|
61
|
-
return
|
|
71
|
+
return undefined;
|
|
62
72
|
}
|
|
63
73
|
|
|
64
|
-
async #hasCorrectContractClassLogs(tx: Tx): Promise<
|
|
74
|
+
async #hasCorrectContractClassLogs(tx: Tx): Promise<string | undefined> {
|
|
65
75
|
const contractClassLogsHashes = tx.data.getNonEmptyContractClassLogsHashes();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
`Rejecting tx ${Tx.getHash(tx)} because of mismatched number of contract class logs. Expected ${
|
|
76
|
+
if (contractClassLogsHashes.length !== tx.contractClassLogFields.length) {
|
|
77
|
+
this.#log.verbose(
|
|
78
|
+
`Rejecting tx ${tx.getTxHash().toString()} because of mismatched number of contract class logs. Expected ${
|
|
70
79
|
contractClassLogsHashes.length
|
|
71
|
-
}. Got ${
|
|
80
|
+
}. Got ${tx.contractClassLogFields.length}.`,
|
|
72
81
|
);
|
|
73
|
-
return
|
|
82
|
+
return TX_ERROR_CONTRACT_CLASS_LOG_COUNT;
|
|
74
83
|
}
|
|
84
|
+
|
|
85
|
+
const expectedHashes = await Promise.all(tx.contractClassLogFields.map(l => l.hash()));
|
|
75
86
|
for (const [i, logHash] of contractClassLogsHashes.entries()) {
|
|
76
|
-
const
|
|
77
|
-
if (!logHash.value.equals(
|
|
78
|
-
if (
|
|
79
|
-
const matchingLogIndex =
|
|
80
|
-
this.#log.
|
|
81
|
-
`Rejecting tx ${
|
|
82
|
-
tx,
|
|
83
|
-
)} because of mismatched contract class logs indices. Expected ${i} from the kernel's log hashes. Got ${matchingLogIndex} in the tx.`,
|
|
87
|
+
const hash = expectedHashes[i];
|
|
88
|
+
if (!logHash.value.equals(hash)) {
|
|
89
|
+
if (expectedHashes.some(h => logHash.value.equals(h))) {
|
|
90
|
+
const matchingLogIndex = expectedHashes.findIndex(l => logHash.value.equals(l));
|
|
91
|
+
this.#log.verbose(
|
|
92
|
+
`Rejecting tx ${tx.getTxHash().toString()} because of mismatched contract class logs indices. Expected ${i} from the kernel's log hashes. Got ${matchingLogIndex} in the tx.`,
|
|
84
93
|
);
|
|
85
|
-
return
|
|
94
|
+
return TX_ERROR_CONTRACT_CLASS_LOG_SORTING;
|
|
86
95
|
} else {
|
|
87
|
-
this.#log.
|
|
88
|
-
`Rejecting tx ${
|
|
96
|
+
this.#log.verbose(
|
|
97
|
+
`Rejecting tx ${tx.getTxHash().toString()} because of mismatched contract class logs. Expected hash ${
|
|
89
98
|
logHash.value
|
|
90
|
-
} from the kernels. Got ${
|
|
99
|
+
} from the kernels. Got ${hash} in the tx.`,
|
|
91
100
|
);
|
|
92
|
-
return
|
|
101
|
+
return TX_ERROR_CONTRACT_CLASS_LOGS;
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
|
|
105
|
+
const expectedMinLength = 1 + tx.contractClassLogFields[i].fields.findLastIndex(f => !f.isZero());
|
|
106
|
+
if (logHash.logHash.length < expectedMinLength) {
|
|
107
|
+
this.#log.verbose(
|
|
108
|
+
`Rejecting tx ${tx.getTxHash().toString()} because of incorrect contract class log length. Expected the length to be at least ${expectedMinLength}. Got ${
|
|
98
109
|
logHash.logHash.length
|
|
99
|
-
}
|
|
110
|
+
}.`,
|
|
100
111
|
);
|
|
101
|
-
return
|
|
112
|
+
return TX_ERROR_CONTRACT_CLASS_LOG_LENGTH;
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
|
-
|
|
115
|
+
|
|
116
|
+
return undefined;
|
|
105
117
|
}
|
|
106
118
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type AnyTx,
|
|
4
|
+
TX_ERROR_DUPLICATE_NULLIFIER_IN_TX,
|
|
5
|
+
TX_ERROR_EXISTING_NULLIFIER,
|
|
6
|
+
Tx,
|
|
7
|
+
type TxValidationResult,
|
|
8
|
+
type TxValidator,
|
|
9
|
+
} from '@aztec/stdlib/tx';
|
|
3
10
|
|
|
4
11
|
export interface NullifierSource {
|
|
5
12
|
nullifiersExist: (nullifiers: Buffer[]) => Promise<boolean[]>;
|
|
@@ -14,25 +21,20 @@ export class DoubleSpendTxValidator<T extends AnyTx> implements TxValidator<T> {
|
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
async validateTx(tx: T): Promise<TxValidationResult> {
|
|
17
|
-
|
|
18
|
-
// because the AVM will perform merkle insertions as it goes and will fail on
|
|
19
|
-
// duplicate nullifier. In fact we CANNOT check here because the nullifiers
|
|
20
|
-
// have already been inserted, and so they will exist in nullifierSource.
|
|
21
|
-
if (!hasPublicCalls(tx)) {
|
|
22
|
-
const nullifiers = tx instanceof Tx ? tx.data.getNonEmptyNullifiers() : tx.txEffect.nullifiers;
|
|
24
|
+
const nullifiers = tx instanceof Tx ? tx.data.getNonEmptyNullifiers() : tx.txEffect.nullifiers;
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
// Ditch this tx if it has repeated nullifiers
|
|
27
|
+
const uniqueNullifiers = new Set(nullifiers.map(n => n.toBigInt()));
|
|
28
|
+
if (uniqueNullifiers.size !== nullifiers.length) {
|
|
29
|
+
this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for emitting duplicate nullifiers`);
|
|
30
|
+
return { result: 'invalid', reason: [TX_ERROR_DUPLICATE_NULLIFIER_IN_TX] };
|
|
31
|
+
}
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
33
|
+
if ((await this.#nullifierSource.nullifiersExist(nullifiers.map(n => n.toBuffer()))).some(Boolean)) {
|
|
34
|
+
this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for repeating a nullifier`);
|
|
35
|
+
return { result: 'invalid', reason: [TX_ERROR_EXISTING_NULLIFIER] };
|
|
35
36
|
}
|
|
37
|
+
|
|
36
38
|
return { result: 'valid' };
|
|
37
39
|
}
|
|
38
40
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
3
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { GasFees } from '@aztec/stdlib/gas';
|
|
6
|
+
import type {
|
|
7
|
+
AllowedElement,
|
|
8
|
+
ClientProtocolCircuitVerifier,
|
|
9
|
+
WorldStateSynchronizer,
|
|
10
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
11
|
+
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
12
|
+
import { DatabasePublicStateSource, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
|
+
import type { Tx, TxValidationResult } from '@aztec/stdlib/tx';
|
|
14
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
15
|
+
|
|
16
|
+
import { ArchiveCache } from './archive_cache.js';
|
|
17
|
+
import { BlockHeaderTxValidator } from './block_header_validator.js';
|
|
18
|
+
import { DataTxValidator } from './data_validator.js';
|
|
19
|
+
import { DoubleSpendTxValidator } from './double_spend_validator.js';
|
|
20
|
+
import { GasTxValidator } from './gas_validator.js';
|
|
21
|
+
import { MetadataTxValidator } from './metadata_validator.js';
|
|
22
|
+
import { PhasesTxValidator } from './phases_validator.js';
|
|
23
|
+
import { TimestampTxValidator } from './timestamp_validator.js';
|
|
24
|
+
import { TxPermittedValidator } from './tx_permitted_validator.js';
|
|
25
|
+
import { TxProofValidator } from './tx_proof_validator.js';
|
|
26
|
+
|
|
27
|
+
export interface MessageValidator {
|
|
28
|
+
validator: {
|
|
29
|
+
validateTx(tx: Tx): Promise<TxValidationResult>;
|
|
30
|
+
};
|
|
31
|
+
severity: PeerErrorSeverity;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createTxMessageValidators(
|
|
35
|
+
timestamp: UInt64,
|
|
36
|
+
blockNumber: number,
|
|
37
|
+
worldStateSynchronizer: WorldStateSynchronizer,
|
|
38
|
+
gasFees: GasFees,
|
|
39
|
+
l1ChainId: number,
|
|
40
|
+
rollupVersion: number,
|
|
41
|
+
protocolContractsHash: Fr,
|
|
42
|
+
contractDataSource: ContractDataSource,
|
|
43
|
+
proofVerifier: ClientProtocolCircuitVerifier,
|
|
44
|
+
txsPermitted: boolean,
|
|
45
|
+
allowedInSetup: AllowedElement[] = [],
|
|
46
|
+
): Record<string, MessageValidator>[] {
|
|
47
|
+
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
48
|
+
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
txsPermittedValidator: {
|
|
52
|
+
validator: new TxPermittedValidator(txsPermitted),
|
|
53
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
54
|
+
},
|
|
55
|
+
dataValidator: {
|
|
56
|
+
validator: new DataTxValidator(),
|
|
57
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
58
|
+
},
|
|
59
|
+
metadataValidator: {
|
|
60
|
+
validator: new MetadataTxValidator({
|
|
61
|
+
l1ChainId: new Fr(l1ChainId),
|
|
62
|
+
rollupVersion: new Fr(rollupVersion),
|
|
63
|
+
protocolContractsHash,
|
|
64
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
65
|
+
}),
|
|
66
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
67
|
+
},
|
|
68
|
+
timestampValidator: {
|
|
69
|
+
validator: new TimestampTxValidator<Tx>({
|
|
70
|
+
timestamp,
|
|
71
|
+
blockNumber,
|
|
72
|
+
}),
|
|
73
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
74
|
+
},
|
|
75
|
+
doubleSpendValidator: {
|
|
76
|
+
validator: new DoubleSpendTxValidator({
|
|
77
|
+
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
78
|
+
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
79
|
+
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
80
|
+
return indices.map(index => index !== undefined);
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
84
|
+
},
|
|
85
|
+
gasValidator: {
|
|
86
|
+
validator: new GasTxValidator(
|
|
87
|
+
new DatabasePublicStateSource(merkleTree),
|
|
88
|
+
ProtocolContractAddress.FeeJuice,
|
|
89
|
+
gasFees,
|
|
90
|
+
),
|
|
91
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
92
|
+
},
|
|
93
|
+
phasesValidator: {
|
|
94
|
+
validator: new PhasesTxValidator(contractDataSource, allowedInSetup, timestamp),
|
|
95
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
96
|
+
},
|
|
97
|
+
blockHeaderValidator: {
|
|
98
|
+
validator: new BlockHeaderTxValidator(new ArchiveCache(merkleTree)),
|
|
99
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
proofValidator: {
|
|
104
|
+
validator: new TxProofValidator(proofVerifier),
|
|
105
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { AVM_MAX_PROCESSABLE_L2_GAS, FIXED_DA_GAS, FIXED_L2_GAS } from '@aztec/constants';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
|
+
import { getCallRequestsWithCalldataByPhase } from '@aztec/simulator/server';
|
|
5
|
+
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
+
import { Gas, GasFees } from '@aztec/stdlib/gas';
|
|
8
|
+
import type { PublicStateSource } from '@aztec/stdlib/trees';
|
|
9
|
+
import {
|
|
10
|
+
TX_ERROR_GAS_LIMIT_TOO_HIGH,
|
|
11
|
+
TX_ERROR_INSUFFICIENT_FEE_PAYER_BALANCE,
|
|
12
|
+
TX_ERROR_INSUFFICIENT_FEE_PER_GAS,
|
|
13
|
+
TX_ERROR_INSUFFICIENT_GAS_LIMIT,
|
|
14
|
+
type Tx,
|
|
15
|
+
TxExecutionPhase,
|
|
16
|
+
type TxValidationResult,
|
|
17
|
+
type TxValidator,
|
|
18
|
+
} from '@aztec/stdlib/tx';
|
|
19
|
+
|
|
20
|
+
export class GasTxValidator implements TxValidator<Tx> {
|
|
21
|
+
#log = createLogger('sequencer:tx_validator:tx_gas');
|
|
22
|
+
#publicDataSource: PublicStateSource;
|
|
23
|
+
#feeJuiceAddress: AztecAddress;
|
|
24
|
+
#gasFees: GasFees;
|
|
25
|
+
|
|
26
|
+
constructor(publicDataSource: PublicStateSource, feeJuiceAddress: AztecAddress, gasFees: GasFees) {
|
|
27
|
+
this.#publicDataSource = publicDataSource;
|
|
28
|
+
this.#feeJuiceAddress = feeJuiceAddress;
|
|
29
|
+
this.#gasFees = gasFees;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async validateTx(tx: Tx): Promise<TxValidationResult> {
|
|
33
|
+
const gasLimitValidation = this.#validateGasLimit(tx);
|
|
34
|
+
if (gasLimitValidation.result === 'invalid') {
|
|
35
|
+
return Promise.resolve(gasLimitValidation);
|
|
36
|
+
}
|
|
37
|
+
if (this.#shouldSkip(tx)) {
|
|
38
|
+
return Promise.resolve({ result: 'skipped', reason: [TX_ERROR_INSUFFICIENT_FEE_PER_GAS] });
|
|
39
|
+
}
|
|
40
|
+
return await this.validateTxFee(tx);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check whether the tx's max fees are valid for the current block, and skip if not.
|
|
45
|
+
* We skip instead of invalidating since the tx may become eligible later.
|
|
46
|
+
* Note that circuits check max fees even if fee payer is unset, so we
|
|
47
|
+
* keep this validation even if the tx does not pay fees.
|
|
48
|
+
*/
|
|
49
|
+
#shouldSkip(tx: Tx): boolean {
|
|
50
|
+
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
51
|
+
|
|
52
|
+
// Skip the tx if its max fees are not enough for the current block's gas fees.
|
|
53
|
+
const maxFeesPerGas = gasSettings.maxFeesPerGas;
|
|
54
|
+
const notEnoughMaxFees =
|
|
55
|
+
maxFeesPerGas.feePerDaGas < this.#gasFees.feePerDaGas || maxFeesPerGas.feePerL2Gas < this.#gasFees.feePerL2Gas;
|
|
56
|
+
|
|
57
|
+
if (notEnoughMaxFees) {
|
|
58
|
+
this.#log.verbose(`Skipping transaction ${tx.getTxHash().toString()} due to insufficient fee per gas`, {
|
|
59
|
+
txMaxFeesPerGas: maxFeesPerGas.toInspect(),
|
|
60
|
+
currentGasFees: this.#gasFees.toInspect(),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return notEnoughMaxFees;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Check whether the tx's gas limit is above the minimum amount.
|
|
68
|
+
*/
|
|
69
|
+
#validateGasLimit(tx: Tx): TxValidationResult {
|
|
70
|
+
const gasLimits = tx.data.constants.txContext.gasSettings.gasLimits;
|
|
71
|
+
const minGasLimits = new Gas(FIXED_DA_GAS, FIXED_L2_GAS);
|
|
72
|
+
|
|
73
|
+
if (minGasLimits.gtAny(gasLimits)) {
|
|
74
|
+
this.#log.verbose(`Rejecting transaction due to the gas limit(s) not being above the minimum gas limit`, {
|
|
75
|
+
gasLimits,
|
|
76
|
+
minGasLimits,
|
|
77
|
+
});
|
|
78
|
+
return { result: 'invalid', reason: [TX_ERROR_INSUFFICIENT_GAS_LIMIT] };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (gasLimits.l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
|
|
82
|
+
this.#log.verbose(`Rejecting transaction due to the gas limit(s) being higher than the maximum processable gas`, {
|
|
83
|
+
gasLimits,
|
|
84
|
+
minGasLimits,
|
|
85
|
+
});
|
|
86
|
+
return { result: 'invalid', reason: [TX_ERROR_GAS_LIMIT_TOO_HIGH] };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { result: 'valid' };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public async validateTxFee(tx: Tx): Promise<TxValidationResult> {
|
|
93
|
+
const feePayer = tx.data.feePayer;
|
|
94
|
+
|
|
95
|
+
// Compute the maximum fee that this tx may pay, based on its gasLimits and maxFeePerGas
|
|
96
|
+
const feeLimit = tx.data.constants.txContext.gasSettings.getFeeLimit();
|
|
97
|
+
|
|
98
|
+
// Read current balance of the feePayer
|
|
99
|
+
const initialBalance = await this.#publicDataSource.storageRead(
|
|
100
|
+
this.#feeJuiceAddress,
|
|
101
|
+
await computeFeePayerBalanceStorageSlot(feePayer),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// If there is a claim in this tx that increases the fee payer balance in Fee Juice, add it to balance
|
|
105
|
+
const setupFns = getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP);
|
|
106
|
+
const increasePublicBalanceSelector = await FunctionSelector.fromSignature(
|
|
107
|
+
'_increase_public_balance((Field),u128)',
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// Arguments of the claim function call:
|
|
111
|
+
// - args[0]: Amount recipient.
|
|
112
|
+
// - args[1]: Amount being claimed.
|
|
113
|
+
const claimFunctionCall = setupFns.find(
|
|
114
|
+
fn =>
|
|
115
|
+
fn.request.contractAddress.equals(this.#feeJuiceAddress) &&
|
|
116
|
+
fn.request.msgSender.equals(this.#feeJuiceAddress) &&
|
|
117
|
+
fn.calldata.length > 2 &&
|
|
118
|
+
fn.functionSelector.equals(increasePublicBalanceSelector) &&
|
|
119
|
+
fn.args[0].equals(feePayer.toField()) &&
|
|
120
|
+
!fn.request.isStaticCall,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const balance = claimFunctionCall ? initialBalance.add(claimFunctionCall.args[1]) : initialBalance;
|
|
124
|
+
if (balance.lt(feeLimit)) {
|
|
125
|
+
this.#log.verbose(`Rejecting transaction due to not enough fee payer balance`, {
|
|
126
|
+
feePayer,
|
|
127
|
+
balance: balance.toBigInt(),
|
|
128
|
+
feeLimit: feeLimit.toBigInt(),
|
|
129
|
+
});
|
|
130
|
+
return { result: 'invalid', reason: [TX_ERROR_INSUFFICIENT_FEE_PAYER_BALANCE] };
|
|
131
|
+
}
|
|
132
|
+
return { result: 'valid' };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -4,3 +4,10 @@ export * from './double_spend_validator.js';
|
|
|
4
4
|
export * from './metadata_validator.js';
|
|
5
5
|
export * from './tx_proof_validator.js';
|
|
6
6
|
export * from './block_header_validator.js';
|
|
7
|
+
export * from './gas_validator.js';
|
|
8
|
+
export * from './phases_validator.js';
|
|
9
|
+
export * from './test_utils.js';
|
|
10
|
+
export * from './allowed_public_setup.js';
|
|
11
|
+
export * from './archive_cache.js';
|
|
12
|
+
export * from './tx_permitted_validator.js';
|
|
13
|
+
export * from './timestamp_validator.js';
|