@aztec/p2p 0.0.1-commit.b655e406 → 0.0.1-commit.c7c42ec
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/client/factory.d.ts +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +2 -3
- package/dest/client/index.d.ts +1 -1
- package/dest/client/interface.d.ts +4 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +9 -27
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +39 -32
- package/dest/config.d.ts +62 -59
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +19 -12
- package/dest/enr/generate-enr.d.ts +1 -1
- 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 +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +28 -6
- 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 +35 -34
- package/dest/mem_pools/attestation_pool/index.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +13 -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 +41 -18
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +11 -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 +30 -8
- package/dest/mem_pools/attestation_pool/mocks.d.ts +226 -5
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -2
- package/dest/mem_pools/index.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts +9 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +38 -2
- package/dest/mem_pools/interface.d.ts +3 -4
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +30 -60
- 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 +262 -324
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +18 -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 +56 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +83 -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 +5 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +88 -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 +76 -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/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/msg_validators/attestation_validator/attestation_validator.d.ts +4 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +12 -12
- 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 +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +22 -10
- 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 +1 -1
- package/dest/msg_validators/msg_seen_validator/msg_seen_validator.d.ts.map +1 -1
- 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 +1 -1
- package/dest/msg_validators/tx_validator/archive_cache.d.ts +2 -2
- package/dest/msg_validators/tx_validator/archive_cache.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/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/double_spend_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.d.ts +4 -3
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -1
- 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 +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/tx_permitted_validator.d.ts.map +1 -1
- 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/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 +1 -1
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +1 -1
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +1 -1
- package/dest/services/gossipsub/scoring.d.ts +1 -1
- package/dest/services/index.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts +3 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +9 -2
- package/dest/services/libp2p/libp2p_service.d.ts +14 -70
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +231 -66
- package/dest/services/peer-manager/interface.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts +8 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +28 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -32
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +6 -2
- 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 +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/index.d.ts +1 -1
- package/dest/services/reqresp/interface.d.ts +2 -2
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +1 -1
- 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 +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 +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +4 -6
- 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 +1 -1
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts +1 -1
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -1
- package/dest/services/reqresp/protocols/ping.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts +6 -5
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -3
- package/dest/services/reqresp/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/index.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +2 -2
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts +1 -41
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/status.d.ts +2 -2
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/service.d.ts +1 -1
- package/dest/services/tx_collection/config.d.ts +1 -1
- package/dest/services/tx_collection/config.js +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -9
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/index.d.ts +1 -1
- 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/slow_tx_collection.d.ts +6 -7
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +2 -1
- package/dest/services/tx_collection/tx_collection.d.ts +11 -11
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.d.ts +3 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_source.d.ts +1 -1
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -1
- 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 +11 -2
- 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 -1
- 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 +1 -1
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-test-p2p-clients.d.ts +2 -2
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +4 -4
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-tx-helpers.d.ts +2 -2
- package/dest/test-helpers/mock-tx-helpers.d.ts.map +1 -1
- 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/testbench/p2p_client_testbench_worker.d.ts +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +12 -8
- package/dest/testbench/parse_log_file.d.ts +1 -1
- package/dest/testbench/testbench.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/types/index.d.ts +1 -1
- package/dest/util.d.ts +2 -1
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +11 -2
- package/dest/versioning.d.ts +1 -1
- package/package.json +19 -18
- package/src/client/factory.ts +5 -10
- package/src/client/interface.ts +4 -1
- package/src/client/p2p_client.ts +63 -60
- package/src/config.ts +28 -17
- package/src/errors/attestation-pool.error.ts +13 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +29 -5
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +47 -34
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +66 -24
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +50 -16
- package/src/mem_pools/attestation_pool/mocks.ts +3 -3
- package/src/mem_pools/instrumentation.ts +46 -0
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +255 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +314 -373
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +71 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +108 -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 +91 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -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/msg_validators/attestation_validator/attestation_validator.ts +14 -16
- 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 +26 -10
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +1 -1
- package/src/msg_validators/tx_validator/factory.ts +3 -2
- package/src/msg_validators/tx_validator/metadata_validator.ts +1 -1
- package/src/msg_validators/tx_validator/phases_validator.ts +3 -1
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +2 -1
- package/src/services/encoding.ts +1 -1
- package/src/services/libp2p/instrumentation.ts +10 -1
- package/src/services/libp2p/libp2p_service.ts +263 -79
- package/src/services/peer-manager/metrics.ts +32 -0
- package/src/services/peer-manager/peer_manager.ts +6 -2
- package/src/services/peer-manager/peer_scoring.ts +46 -3
- package/src/services/reqresp/interface.ts +1 -1
- 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/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +9 -8
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/tx_collection/config.ts +1 -1
- package/src/services/tx_collection/fast_tx_collection.ts +3 -2
- package/src/services/tx_collection/slow_tx_collection.ts +7 -6
- package/src/services/tx_collection/tx_collection.ts +10 -9
- package/src/services/tx_provider.ts +21 -5
- package/src/services/tx_provider_instrumentation.ts +19 -2
- package/src/test-helpers/mock-pubsub.ts +1 -1
- package/src/test-helpers/mock-tx-helpers.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +10 -6
- package/src/util.ts +12 -2
- 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/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Attributes,
|
|
3
3
|
type Gauge,
|
|
4
|
+
type Histogram,
|
|
4
5
|
Metrics,
|
|
5
6
|
type TelemetryClient,
|
|
6
7
|
type Tracer,
|
|
@@ -9,12 +10,18 @@ import {
|
|
|
9
10
|
getTelemetryClient,
|
|
10
11
|
} from '@aztec/telemetry-client';
|
|
11
12
|
|
|
13
|
+
import type { PeerId } from '@libp2p/interface';
|
|
14
|
+
|
|
12
15
|
import { type GoodByeReason, prettyGoodbyeReason } from '../reqresp/protocols/index.js';
|
|
13
16
|
|
|
14
17
|
export class PeerManagerMetrics {
|
|
15
18
|
private sentGoodbyes: UpDownCounter;
|
|
16
19
|
private receivedGoodbyes: UpDownCounter;
|
|
17
20
|
private peerCount: Gauge;
|
|
21
|
+
private lowScoreDisconnects: UpDownCounter;
|
|
22
|
+
private peerConnectionDuration: Histogram;
|
|
23
|
+
|
|
24
|
+
private peerConnectedAt: Map<string, number> = new Map<string, number>();
|
|
18
25
|
|
|
19
26
|
public readonly tracer: Tracer;
|
|
20
27
|
|
|
@@ -40,6 +47,16 @@ export class PeerManagerMetrics {
|
|
|
40
47
|
unit: 'peers',
|
|
41
48
|
valueType: ValueType.INT,
|
|
42
49
|
});
|
|
50
|
+
this.lowScoreDisconnects = meter.createUpDownCounter(Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS, {
|
|
51
|
+
description: 'Number of peers disconnected due to low score',
|
|
52
|
+
unit: 'peers',
|
|
53
|
+
valueType: ValueType.INT,
|
|
54
|
+
});
|
|
55
|
+
this.peerConnectionDuration = meter.createHistogram(Metrics.PEER_MANAGER_PEER_CONNECTION_DURATION, {
|
|
56
|
+
description: 'Time duration between peer connection and disconnection',
|
|
57
|
+
unit: 'ms',
|
|
58
|
+
valueType: ValueType.INT,
|
|
59
|
+
});
|
|
43
60
|
}
|
|
44
61
|
|
|
45
62
|
public recordGoodbyeSent(reason: GoodByeReason) {
|
|
@@ -53,4 +70,19 @@ export class PeerManagerMetrics {
|
|
|
53
70
|
public recordPeerCount(count: number) {
|
|
54
71
|
this.peerCount.record(count);
|
|
55
72
|
}
|
|
73
|
+
|
|
74
|
+
public recordLowScoreDisconnect(scoreState: 'Banned' | 'Disconnect') {
|
|
75
|
+
this.lowScoreDisconnects.add(1, { [Attributes.P2P_PEER_SCORE_STATE]: scoreState });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public peerConnected(id: PeerId) {
|
|
79
|
+
this.peerConnectedAt.set(id.toString(), Date.now());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public peerDisconnected(id: PeerId) {
|
|
83
|
+
const connectedAt = this.peerConnectedAt.get(id.toString());
|
|
84
|
+
if (connectedAt) {
|
|
85
|
+
this.peerConnectionDuration.record(Date.now() - connectedAt);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
56
88
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
-
import { makeEthSignDigest, tryRecoverAddress } from '@aztec/foundation/crypto';
|
|
2
|
+
import { makeEthSignDigest, tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
7
7
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -278,6 +278,7 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
278
278
|
private handleConnectedPeerEvent(e: CustomEvent<PeerId>) {
|
|
279
279
|
const peerId = e.detail;
|
|
280
280
|
this.logger.verbose(`Connected to peer ${peerId.toString()}`);
|
|
281
|
+
this.metrics.peerConnected(peerId);
|
|
281
282
|
if (this.config.p2pDisableStatusHandshake) {
|
|
282
283
|
return;
|
|
283
284
|
}
|
|
@@ -303,6 +304,7 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
303
304
|
*/
|
|
304
305
|
private handleDisconnectedPeerEvent(e: CustomEvent<PeerId>) {
|
|
305
306
|
const peerId = e.detail;
|
|
307
|
+
this.metrics.peerDisconnected(peerId);
|
|
306
308
|
this.logger.verbose(`Disconnected from peer ${peerId.toString()}`);
|
|
307
309
|
const validatorAddress = this.authenticatedPeerIdToValidatorAddress.get(peerId.toString());
|
|
308
310
|
if (validatorAddress !== undefined) {
|
|
@@ -577,9 +579,11 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
577
579
|
const score = this.peerScoring.getScoreState(peer.remotePeer.toString());
|
|
578
580
|
switch (score) {
|
|
579
581
|
case PeerScoreState.Banned:
|
|
582
|
+
this.metrics.recordLowScoreDisconnect('Banned');
|
|
580
583
|
void this.goodbyeAndDisconnectPeer(peer.remotePeer, GoodByeReason.BANNED);
|
|
581
584
|
break;
|
|
582
585
|
case PeerScoreState.Disconnect:
|
|
586
|
+
this.metrics.recordLowScoreDisconnect('Disconnect');
|
|
583
587
|
void this.goodbyeAndDisconnectPeer(peer.remotePeer, GoodByeReason.LOW_SCORE);
|
|
584
588
|
break;
|
|
585
589
|
case PeerScoreState.Healthy:
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { median } from '@aztec/foundation/collection';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
4
|
+
import {
|
|
5
|
+
Attributes,
|
|
6
|
+
Metrics,
|
|
7
|
+
type TelemetryClient,
|
|
8
|
+
type UpDownCounter,
|
|
9
|
+
ValueType,
|
|
10
|
+
getTelemetryClient,
|
|
11
|
+
} from '@aztec/telemetry-client';
|
|
4
12
|
|
|
5
13
|
import type { PeerId } from '@libp2p/interface';
|
|
6
14
|
|
|
@@ -30,7 +38,9 @@ export class PeerScoring {
|
|
|
30
38
|
private decayFactor = 0.9;
|
|
31
39
|
peerPenalties: { [key in PeerErrorSeverity]: number };
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
private peerStateCounter: UpDownCounter;
|
|
42
|
+
|
|
43
|
+
constructor(config: P2PConfig, telemetry: TelemetryClient = getTelemetryClient()) {
|
|
34
44
|
const orderedValues = config.peerPenaltyValues?.sort((a, b) => a - b);
|
|
35
45
|
this.peerPenalties = {
|
|
36
46
|
[PeerErrorSeverity.HighToleranceError]:
|
|
@@ -40,6 +50,13 @@ export class PeerScoring {
|
|
|
40
50
|
[PeerErrorSeverity.LowToleranceError]:
|
|
41
51
|
orderedValues?.[2] ?? DefaultPeerPenalties[PeerErrorSeverity.LowToleranceError],
|
|
42
52
|
};
|
|
53
|
+
|
|
54
|
+
const meter = telemetry.getMeter('PeerScoring');
|
|
55
|
+
|
|
56
|
+
this.peerStateCounter = meter.createUpDownCounter(Metrics.P2P_PEER_STATE_COUNT, {
|
|
57
|
+
description: 'Count of peers by state (Healthy, Disconnect, Banned)',
|
|
58
|
+
valueType: ValueType.INT,
|
|
59
|
+
});
|
|
43
60
|
}
|
|
44
61
|
|
|
45
62
|
public penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity) {
|
|
@@ -99,7 +116,33 @@ export class PeerScoring {
|
|
|
99
116
|
return PeerScoreState.Healthy;
|
|
100
117
|
}
|
|
101
118
|
|
|
102
|
-
getStats(): { medianScore: number } {
|
|
103
|
-
|
|
119
|
+
getStats(): { medianScore: number; healthyCount: number; disconnectCount: number; bannedCount: number } {
|
|
120
|
+
const stateCounts = { healthy: 0, disconnect: 0, banned: 0 };
|
|
121
|
+
|
|
122
|
+
for (const peerId of this.scores.keys()) {
|
|
123
|
+
const state = this.getScoreState(peerId);
|
|
124
|
+
switch (state) {
|
|
125
|
+
case PeerScoreState.Healthy:
|
|
126
|
+
stateCounts.healthy++;
|
|
127
|
+
break;
|
|
128
|
+
case PeerScoreState.Disconnect:
|
|
129
|
+
stateCounts.disconnect++;
|
|
130
|
+
break;
|
|
131
|
+
case PeerScoreState.Banned:
|
|
132
|
+
stateCounts.banned++;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this.peerStateCounter.add(stateCounts.healthy, { [Attributes.P2P_PEER_SCORE_STATE]: 'Healthy' });
|
|
138
|
+
this.peerStateCounter.add(stateCounts.disconnect, { [Attributes.P2P_PEER_SCORE_STATE]: 'Disconnect' });
|
|
139
|
+
this.peerStateCounter.add(stateCounts.banned, { [Attributes.P2P_PEER_SCORE_STATE]: 'Banned' });
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
medianScore: median(Array.from(this.scores.values())) ?? 0,
|
|
143
|
+
healthyCount: stateCounts.healthy,
|
|
144
|
+
disconnectCount: stateCounts.disconnect,
|
|
145
|
+
bannedCount: stateCounts.banned,
|
|
146
|
+
};
|
|
104
147
|
}
|
|
105
148
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
-
import { keccak256 } from '@aztec/foundation/crypto';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
6
6
|
|
|
7
7
|
import { StatusMessage } from './status.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
3
4
|
|
|
4
5
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -27,7 +28,7 @@ export function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubPro
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
try {
|
|
30
|
-
const foundBlock = await l2BlockSource.getBlock(Number(blockNumber));
|
|
31
|
+
const foundBlock = await l2BlockSource.getBlock(BlockNumber(Number(blockNumber)));
|
|
31
32
|
return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
|
|
32
33
|
} catch (err: any) {
|
|
33
34
|
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
@@ -15,9 +16,9 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
15
16
|
export class StatusMessage {
|
|
16
17
|
constructor(
|
|
17
18
|
readonly compressedComponentsVersion: string,
|
|
18
|
-
readonly latestBlockNumber:
|
|
19
|
+
readonly latestBlockNumber: BlockNumber,
|
|
19
20
|
readonly latestBlockHash: string,
|
|
20
|
-
readonly finalizedBlockNumber:
|
|
21
|
+
readonly finalizedBlockNumber: BlockNumber,
|
|
21
22
|
//TODO: add finalizedBlockHash
|
|
22
23
|
//readonly finalizedBlockHash: string,
|
|
23
24
|
) {}
|
|
@@ -31,9 +32,9 @@ export class StatusMessage {
|
|
|
31
32
|
const reader = BufferReader.asReader(buffer);
|
|
32
33
|
return new StatusMessage(
|
|
33
34
|
reader.readString(), // compressedComponentsVersion
|
|
34
|
-
reader.readNumber(), // latestBlockNumber
|
|
35
|
+
BlockNumber(reader.readNumber()), // latestBlockNumber
|
|
35
36
|
reader.readString(), // latestBlockHash
|
|
36
|
-
reader.readNumber(), // finalizedBlockNumber
|
|
37
|
+
BlockNumber(reader.readNumber()), // finalizedBlockNumber
|
|
37
38
|
//TODO: add finalizedBlockHash
|
|
38
39
|
//reader.readString(), // finalizedBlockHash
|
|
39
40
|
);
|
|
@@ -63,9 +64,9 @@ export class StatusMessage {
|
|
|
63
64
|
static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage {
|
|
64
65
|
return new StatusMessage(
|
|
65
66
|
version,
|
|
66
|
-
syncStatus.latestBlockNumber,
|
|
67
|
+
BlockNumber(syncStatus.latestBlockNumber),
|
|
67
68
|
syncStatus.latestBlockHash,
|
|
68
|
-
syncStatus.finalizedBlockNumber,
|
|
69
|
+
BlockNumber(syncStatus.finalizedBlockNumber),
|
|
69
70
|
//TODO: add finalizedBlockHash
|
|
70
71
|
);
|
|
71
72
|
}
|
|
@@ -73,9 +74,9 @@ export class StatusMessage {
|
|
|
73
74
|
static random(): StatusMessage {
|
|
74
75
|
return new StatusMessage(
|
|
75
76
|
'1.0.0',
|
|
76
|
-
Math.floor(Math.random() * 100),
|
|
77
|
+
BlockNumber(Math.floor(Math.random() * 100)),
|
|
77
78
|
Buffer32.random().toString(),
|
|
78
|
-
Math.floor(Math.random() * 100),
|
|
79
|
+
BlockNumber(Math.floor(Math.random() * 100)),
|
|
79
80
|
//TODO: add finalizedBlockHash
|
|
80
81
|
);
|
|
81
82
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { chunk } from '@aztec/foundation/collection';
|
|
2
|
-
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
3
2
|
import { TxArray, TxHash, TxHashArray } from '@aztec/stdlib/tx';
|
|
4
3
|
|
|
5
4
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -16,7 +15,7 @@ import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
|
16
15
|
* @param mempools - the mempools
|
|
17
16
|
* @returns the Tx request handler
|
|
18
17
|
*/
|
|
19
|
-
export function reqRespTxHandler
|
|
18
|
+
export function reqRespTxHandler(mempools: MemPools): ReqRespSubProtocolHandler {
|
|
20
19
|
/**
|
|
21
20
|
* Handler for tx requests
|
|
22
21
|
* @param msg - the tx request message
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ConfigMappingsType, booleanConfigHelper, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
-
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/
|
|
2
|
+
import { MAX_RPC_TXS_LEN } from '@aztec/stdlib/interfaces/api-limit';
|
|
3
3
|
|
|
4
4
|
export type TxCollectionConfig = {
|
|
5
5
|
/** How long to wait before starting reqresp for fast collection */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { times } from '@aztec/foundation/collection';
|
|
2
3
|
import { AbortError, TimeoutError } from '@aztec/foundation/error';
|
|
3
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
@@ -316,7 +317,7 @@ export class FastTxCollection {
|
|
|
316
317
|
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
317
318
|
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
318
319
|
*/
|
|
319
|
-
public stopCollectingForBlocksUpTo(blockNumber:
|
|
320
|
+
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
320
321
|
for (const request of this.requests) {
|
|
321
322
|
if (request.blockInfo.blockNumber <= blockNumber) {
|
|
322
323
|
request.promise.reject(new AbortError(`Stopped collecting txs up to block ${blockNumber}`));
|
|
@@ -329,7 +330,7 @@ export class FastTxCollection {
|
|
|
329
330
|
* Stop collecting all txs for blocks greater than the block number specified.
|
|
330
331
|
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
331
332
|
*/
|
|
332
|
-
public stopCollectingForBlocksAfter(blockNumber:
|
|
333
|
+
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
333
334
|
for (const request of this.requests) {
|
|
334
335
|
if (request.blockInfo.blockNumber > blockNumber) {
|
|
335
336
|
request.promise.reject(new AbortError(`Stopped collecting txs after block ${blockNumber}`));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { chunk } from '@aztec/foundation/collection';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { boundInclusive } from '@aztec/foundation/number';
|
|
4
5
|
import { RunningPromise } from '@aztec/foundation/promise';
|
|
5
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import type {
|
|
7
|
+
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
7
8
|
import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
8
9
|
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
9
10
|
|
|
@@ -75,7 +76,7 @@ export class SlowTxCollection {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
78
|
-
public startCollecting(block:
|
|
79
|
+
public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
|
|
79
80
|
const slot = block.header.getSlot();
|
|
80
81
|
const deadline = this.getDeadlineForSlot(slot);
|
|
81
82
|
if (+deadline < this.dateProvider.now()) {
|
|
@@ -202,7 +203,7 @@ export class SlowTxCollection {
|
|
|
202
203
|
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
203
204
|
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
204
205
|
*/
|
|
205
|
-
public stopCollectingForBlocksUpTo(blockNumber:
|
|
206
|
+
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
206
207
|
for (const [txHash, info] of this.missingTxs.entries()) {
|
|
207
208
|
if (info.blockNumber <= blockNumber) {
|
|
208
209
|
this.missingTxs.delete(txHash);
|
|
@@ -214,7 +215,7 @@ export class SlowTxCollection {
|
|
|
214
215
|
* Stop collecting all txs for blocks greater than the block number specified.
|
|
215
216
|
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
216
217
|
*/
|
|
217
|
-
public stopCollectingForBlocksAfter(blockNumber:
|
|
218
|
+
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
218
219
|
for (const [txHash, info] of this.missingTxs.entries()) {
|
|
219
220
|
if (info.blockNumber > blockNumber) {
|
|
220
221
|
this.missingTxs.delete(txHash);
|
|
@@ -223,9 +224,9 @@ export class SlowTxCollection {
|
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
/** Computes the proof submission deadline for a given slot, a tx mined in this slot is no longer interesting after this deadline */
|
|
226
|
-
private getDeadlineForSlot(slotNumber:
|
|
227
|
+
private getDeadlineForSlot(slotNumber: SlotNumber): Date {
|
|
227
228
|
const epoch = getEpochAtSlot(slotNumber, this.constants);
|
|
228
|
-
const submissionEndEpoch = epoch +
|
|
229
|
+
const submissionEndEpoch = EpochNumber(epoch + this.constants.proofSubmissionEpochs);
|
|
229
230
|
const submissionEndTimestamp = getTimestampRangeForEpoch(submissionEndEpoch, this.constants)[1];
|
|
230
231
|
return new Date(Number(submissionEndTimestamp) * 1000);
|
|
231
232
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { compactArray } from '@aztec/foundation/collection';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { type PromiseWithResolvers, RunningPromise } from '@aztec/foundation/promise';
|
|
4
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import type {
|
|
6
|
+
import type { L2BlockInfo, L2BlockNew } from '@aztec/stdlib/block';
|
|
6
7
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
7
8
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
8
9
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -21,11 +22,11 @@ import type { TxSource } from './tx_source.js';
|
|
|
21
22
|
|
|
22
23
|
export type CollectionMethod = 'fast-req-resp' | 'fast-node-rpc' | 'slow-req-resp' | 'slow-node-rpc';
|
|
23
24
|
|
|
24
|
-
export type MissingTxInfo = { blockNumber:
|
|
25
|
+
export type MissingTxInfo = { blockNumber: BlockNumber; deadline: Date; readyForReqResp: boolean };
|
|
25
26
|
|
|
26
27
|
export type FastCollectionRequestInput =
|
|
27
|
-
| { type: 'block'; block:
|
|
28
|
-
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber:
|
|
28
|
+
| { type: 'block'; block: L2BlockNew }
|
|
29
|
+
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
|
|
29
30
|
|
|
30
31
|
export type FastCollectionRequest = FastCollectionRequestInput & {
|
|
31
32
|
missingTxHashes: Set<string>;
|
|
@@ -145,14 +146,14 @@ export class TxCollection {
|
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
148
|
-
public startCollecting(block:
|
|
149
|
+
public startCollecting(block: L2BlockNew, txHashes: TxHash[]) {
|
|
149
150
|
return this.slowCollection.startCollecting(block, txHashes);
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
/** Collects the set of txs for the given block proposal as fast as possible */
|
|
153
154
|
public collectFastForProposal(
|
|
154
155
|
blockProposal: BlockProposal,
|
|
155
|
-
blockNumber:
|
|
156
|
+
blockNumber: BlockNumber,
|
|
156
157
|
txHashes: TxHash[] | string[],
|
|
157
158
|
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
158
159
|
) {
|
|
@@ -161,7 +162,7 @@ export class TxCollection {
|
|
|
161
162
|
|
|
162
163
|
/** Collects the set of txs for the given mined block as fast as possible */
|
|
163
164
|
public collectFastForBlock(
|
|
164
|
-
block:
|
|
165
|
+
block: L2BlockNew,
|
|
165
166
|
txHashes: TxHash[] | string[],
|
|
166
167
|
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
167
168
|
) {
|
|
@@ -187,7 +188,7 @@ export class TxCollection {
|
|
|
187
188
|
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
188
189
|
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
189
190
|
*/
|
|
190
|
-
public stopCollectingForBlocksUpTo(blockNumber:
|
|
191
|
+
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
191
192
|
this.slowCollection.stopCollectingForBlocksUpTo(blockNumber);
|
|
192
193
|
this.fastCollection.stopCollectingForBlocksUpTo(blockNumber);
|
|
193
194
|
}
|
|
@@ -196,7 +197,7 @@ export class TxCollection {
|
|
|
196
197
|
* Stop collecting all txs for blocks greater than the block number specified.
|
|
197
198
|
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
198
199
|
*/
|
|
199
|
-
public stopCollectingForBlocksAfter(blockNumber:
|
|
200
|
+
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
200
201
|
this.slowCollection.stopCollectingForBlocksAfter(blockNumber);
|
|
201
202
|
this.fastCollection.stopCollectingForBlocksAfter(blockNumber);
|
|
202
203
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { compactArray } from '@aztec/foundation/collection';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { elapsed } from '@aztec/foundation/timer';
|
|
4
|
-
import type {
|
|
5
|
+
import type { L2BlockInfo, L2BlockNew } from '@aztec/stdlib/block';
|
|
5
6
|
import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
|
|
6
7
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
7
8
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -55,7 +56,7 @@ export class TxProvider implements ITxProvider {
|
|
|
55
56
|
/** Gathers txs from the tx pool, proposal body, remote rpc nodes, and reqresp. */
|
|
56
57
|
public getTxsForBlockProposal(
|
|
57
58
|
blockProposal: BlockProposal,
|
|
58
|
-
blockNumber:
|
|
59
|
+
blockNumber: BlockNumber,
|
|
59
60
|
opts: { pinnedPeer: PeerId | undefined; deadline: Date },
|
|
60
61
|
): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
|
|
61
62
|
return this.getOrderedTxsFromAllSources(
|
|
@@ -67,7 +68,7 @@ export class TxProvider implements ITxProvider {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/** Gathers txs from the tx pool, remote rpc nodes, and reqresp. */
|
|
70
|
-
public getTxsForBlock(block:
|
|
71
|
+
public getTxsForBlock(block: L2BlockNew, opts: { deadline: Date }): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
|
|
71
72
|
return this.getOrderedTxsFromAllSources(
|
|
72
73
|
{ type: 'block', block },
|
|
73
74
|
block.toBlockInfo(),
|
|
@@ -136,6 +137,7 @@ export class TxProvider implements ITxProvider {
|
|
|
136
137
|
);
|
|
137
138
|
|
|
138
139
|
if (missingTxHashes.size === 0) {
|
|
140
|
+
this.instrumentation.incTxsFromP2P(0, txHashes.length);
|
|
139
141
|
return { txsFromMempool };
|
|
140
142
|
}
|
|
141
143
|
|
|
@@ -154,24 +156,26 @@ export class TxProvider implements ITxProvider {
|
|
|
154
156
|
|
|
155
157
|
if (missingTxHashes.size === 0) {
|
|
156
158
|
await this.processProposalTxs(txsFromProposal);
|
|
159
|
+
this.instrumentation.incTxsFromP2P(0, txHashes.length);
|
|
157
160
|
return { txsFromMempool, txsFromProposal };
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
// Start tx collection from the network if needed, while we validate the txs taken from the proposal in parallel
|
|
161
164
|
const [txsFromNetwork] = await Promise.all([
|
|
162
|
-
this.
|
|
165
|
+
this.collectFromP2P(request, [...missingTxHashes], opts),
|
|
163
166
|
this.processProposalTxs(txsFromProposal),
|
|
164
167
|
] as const);
|
|
165
168
|
|
|
166
169
|
if (txsFromNetwork.length > 0) {
|
|
167
170
|
txsFromNetwork.forEach(tx => missingTxHashes.delete(tx.txHash.toString()));
|
|
168
|
-
this.instrumentation.incTxsFromP2P(txsFromNetwork.length);
|
|
169
171
|
this.log.debug(
|
|
170
172
|
`Retrieved ${txsFromNetwork.length} txs from network for block proposal (${missingTxHashes.size} pending)`,
|
|
171
173
|
{ ...blockInfo, missingTxHashes: [...missingTxHashes] },
|
|
172
174
|
);
|
|
173
175
|
}
|
|
174
176
|
|
|
177
|
+
this.instrumentation.incTxsFromP2P(txsFromNetwork.length, txHashes.length);
|
|
178
|
+
|
|
175
179
|
if (missingTxHashes.size === 0) {
|
|
176
180
|
return { txsFromNetwork, txsFromMempool, txsFromProposal };
|
|
177
181
|
}
|
|
@@ -199,6 +203,18 @@ export class TxProvider implements ITxProvider {
|
|
|
199
203
|
};
|
|
200
204
|
}
|
|
201
205
|
|
|
206
|
+
private async collectFromP2P(
|
|
207
|
+
input: FastCollectionRequestInput,
|
|
208
|
+
txHashes: TxHash[] | string[],
|
|
209
|
+
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
210
|
+
): Promise<Tx[]> {
|
|
211
|
+
const requestedAt = Date.now();
|
|
212
|
+
const result = await this.txCollection.collectFastFor(input, txHashes, opts);
|
|
213
|
+
const requestProcessedAt = Date.now();
|
|
214
|
+
this.instrumentation.recordTxsRequestDelay(requestProcessedAt - requestedAt);
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
|
|
202
218
|
private extractFromProposal(proposal: BlockProposal | undefined, missingTxHashes: string[]): Tx[] {
|
|
203
219
|
if (!proposal) {
|
|
204
220
|
return [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
|
|
1
|
+
import { type Histogram, Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
|
|
2
2
|
|
|
3
3
|
export class TxProviderInstrumentation {
|
|
4
4
|
private txFromProposalCount: UpDownCounter;
|
|
@@ -6,6 +6,9 @@ export class TxProviderInstrumentation {
|
|
|
6
6
|
private txFromP2PCount: UpDownCounter;
|
|
7
7
|
private missingTxsCount: UpDownCounter;
|
|
8
8
|
|
|
9
|
+
private fractionOfTxsRequestedFromP2P: Histogram;
|
|
10
|
+
private txsRequestDelay: Histogram;
|
|
11
|
+
|
|
9
12
|
constructor(client: TelemetryClient, name: string) {
|
|
10
13
|
const meter = client.getMeter(name);
|
|
11
14
|
|
|
@@ -24,6 +27,15 @@ export class TxProviderInstrumentation {
|
|
|
24
27
|
this.missingTxsCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_MISSING_TXS_COUNT, {
|
|
25
28
|
description: 'The number of txs not found anywhere',
|
|
26
29
|
});
|
|
30
|
+
|
|
31
|
+
this.fractionOfTxsRequestedFromP2P = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUESTED_FRACTION, {
|
|
32
|
+
description: 'The fraction of transaction requested from peers',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.txsRequestDelay = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUEST_DELAY, {
|
|
36
|
+
unit: 'ms',
|
|
37
|
+
description: 'The time it took to request missing transactions from p2p',
|
|
38
|
+
});
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
incTxsFromProposals(count: number) {
|
|
@@ -34,8 +46,13 @@ export class TxProviderInstrumentation {
|
|
|
34
46
|
this.txFromMempoolCount.add(count);
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
incTxsFromP2P(count: number) {
|
|
49
|
+
incTxsFromP2P(count: number, total: number) {
|
|
38
50
|
this.txFromP2PCount.add(count);
|
|
51
|
+
this.fractionOfTxsRequestedFromP2P.record(count / total);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
recordTxsRequestDelay(delay: number) {
|
|
55
|
+
this.txsRequestDelay.record(delay);
|
|
39
56
|
}
|
|
40
57
|
|
|
41
58
|
incMissingTxs(count: number) {
|
|
@@ -39,7 +39,7 @@ export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
|
|
|
39
39
|
peerId: PeerId,
|
|
40
40
|
deps: {
|
|
41
41
|
packageVersion: string;
|
|
42
|
-
mempools: MemPools
|
|
42
|
+
mempools: MemPools;
|
|
43
43
|
l2BlockSource: L2BlockSource & ContractDataSource;
|
|
44
44
|
epochCache: EpochCacheInterface;
|
|
45
45
|
proofVerifier: ClientProtocolCircuitVerifier;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
3
3
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
4
4
|
import { mockTx } from '@aztec/stdlib/testing';
|
|
@@ -112,7 +112,7 @@ export async function createTestLibP2PService<T extends P2PClientType>(
|
|
|
112
112
|
archiver: L2BlockSource & ContractDataSource,
|
|
113
113
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
114
114
|
epochCache: EpochCache,
|
|
115
|
-
mempools: MemPools
|
|
115
|
+
mempools: MemPools,
|
|
116
116
|
telemetry: TelemetryClient,
|
|
117
117
|
port: number = 0,
|
|
118
118
|
peerId?: PeerId,
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { MockL2BlockSource } from '@aztec/archiver/test';
|
|
7
7
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
8
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
8
9
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
10
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
@@ -55,6 +56,7 @@ function mockTxPool(): TxPool {
|
|
|
55
56
|
hasTx: () => Promise.resolve(false),
|
|
56
57
|
updateConfig: () => {},
|
|
57
58
|
markTxsAsNonEvictable: () => Promise.resolve(),
|
|
59
|
+
clearNonEvictableTxs: () => Promise.resolve(),
|
|
58
60
|
cleanupDeletedMinedTxs: () => Promise.resolve(0),
|
|
59
61
|
};
|
|
60
62
|
return Object.assign(new EventEmitter(), pool);
|
|
@@ -74,23 +76,25 @@ function mockAttestationPool(): AttestationPool {
|
|
|
74
76
|
getBlockProposal: () => Promise.resolve(undefined),
|
|
75
77
|
hasBlockProposal: () => Promise.resolve(false),
|
|
76
78
|
hasAttestation: () => Promise.resolve(false),
|
|
79
|
+
canAddProposal: () => Promise.resolve(true),
|
|
80
|
+
canAddAttestation: () => Promise.resolve(true),
|
|
77
81
|
};
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
function mockEpochCache(): EpochCacheInterface {
|
|
81
85
|
return {
|
|
82
|
-
getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch:
|
|
86
|
+
getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: EpochNumber.ZERO }),
|
|
83
87
|
getProposerIndexEncoding: () => '0x' as `0x${string}`,
|
|
84
|
-
getEpochAndSlotNow: () => ({ epoch:
|
|
88
|
+
getEpochAndSlotNow: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n }),
|
|
85
89
|
computeProposerIndex: () => 0n,
|
|
86
90
|
getProposerAttesterAddressInCurrentOrNextSlot: () =>
|
|
87
91
|
Promise.resolve({
|
|
88
92
|
currentProposer: EthAddress.ZERO,
|
|
89
93
|
nextProposer: EthAddress.ZERO,
|
|
90
|
-
currentSlot:
|
|
91
|
-
nextSlot:
|
|
94
|
+
currentSlot: SlotNumber.ZERO,
|
|
95
|
+
nextSlot: SlotNumber.ZERO,
|
|
92
96
|
}),
|
|
93
|
-
getEpochAndSlotInNextL1Slot: () => ({ epoch:
|
|
97
|
+
getEpochAndSlotInNextL1Slot: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n, now: 0n }),
|
|
94
98
|
isInCommittee: () => Promise.resolve(false),
|
|
95
99
|
getRegisteredValidators: () => Promise.resolve([]),
|
|
96
100
|
filterInCommittee: () => Promise.resolve([]),
|
|
@@ -123,7 +127,7 @@ class TestLibP2PService<T extends P2PClientType = P2PClientType.Full> extends Li
|
|
|
123
127
|
peerDiscoveryService: PeerDiscoveryService,
|
|
124
128
|
reqresp: ReqResp,
|
|
125
129
|
peerManager: PeerManager,
|
|
126
|
-
mempools: MemPools
|
|
130
|
+
mempools: MemPools,
|
|
127
131
|
archiver: L2BlockSource & ContractDataSource,
|
|
128
132
|
epochCache: EpochCacheInterface,
|
|
129
133
|
proofVerifier: ClientProtocolCircuitVerifier,
|