@aztec/p2p 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
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/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/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +16 -19
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +460 -127
- package/dest/config.d.ts +4 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -13
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
- 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 +239 -265
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +114 -109
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
- package/dest/mem_pools/attestation_pool/mocks.d.ts +11 -8
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +17 -13
- package/dest/mem_pools/instrumentation.d.ts +7 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +30 -12
- 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 +37 -27
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +314 -335
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +32 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +112 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +157 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +52 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +78 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +26 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.js +84 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/mem_pools/tx_pool/index.d.ts +1 -2
- package/dest/mem_pools/tx_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/priority.d.ts +5 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +6 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -6
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +30 -24
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +52 -19
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -14
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- package/dest/msg_validators/tx_validator/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/block_header_validator.js +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/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/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +8 -14
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +20 -0
- package/dest/msg_validators/tx_validator/test_utils.d.ts +2 -2
- package/dest/msg_validators/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -6
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +20 -73
- package/dest/services/libp2p/libp2p_service.d.ts +31 -14
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +722 -168
- package/dest/services/peer-manager/metrics.d.ts +6 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +18 -21
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +4 -12
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +2 -5
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/interface.d.ts +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/metrics.js +5 -21
- package/dest/services/reqresp/protocols/auth.d.ts +2 -2
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/auth.js +2 -2
- package/dest/services/reqresp/protocols/block.d.ts +1 -1
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +3 -2
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +2 -2
- 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/status.d.ts +5 -4
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -3
- package/dest/services/reqresp/protocols/tx.d.ts +2 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +402 -24
- package/dest/services/service.d.ts +16 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +1 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +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/instrumentation.js +4 -14
- package/dest/services/tx_collection/slow_tx_collection.d.ts +4 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +7 -6
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +4 -2
- 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 +13 -13
- 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.js +31 -17
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -1
- package/package.json +18 -18
- package/src/client/factory.ts +5 -10
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +101 -154
- package/src/config.ts +12 -18
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +241 -289
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +163 -141
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +21 -15
- package/src/mem_pools/instrumentation.ts +38 -14
- package/src/mem_pools/interface.ts +2 -4
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +367 -371
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +132 -0
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +208 -0
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.ts +104 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +93 -0
- package/src/mem_pools/tx_pool/eviction/low_priority_eviction_rule.ts +106 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/mem_pools/tx_pool/index.ts +0 -1
- package/src/mem_pools/tx_pool/priority.ts +8 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +11 -5
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +23 -17
- package/src/msg_validators/attestation_validator/attestation_validator.ts +37 -22
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +13 -16
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/archive_cache.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +4 -2
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- package/src/msg_validators/tx_validator/factory.ts +3 -2
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +13 -5
- package/src/msg_validators/tx_validator/size_validator.ts +18 -0
- package/src/msg_validators/tx_validator/test_utils.ts +1 -1
- package/src/msg_validators/tx_validator/timestamp_validator.ts +5 -2
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +6 -5
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +369 -138
- package/src/services/peer-manager/metrics.ts +22 -21
- package/src/services/peer-manager/peer_manager.ts +5 -4
- package/src/services/peer-manager/peer_scoring.ts +1 -5
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +1 -1
- package/src/services/reqresp/metrics.ts +7 -23
- package/src/services/reqresp/protocols/auth.ts +2 -2
- package/src/services/reqresp/protocols/block.ts +3 -2
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +1 -1
- package/src/services/reqresp/protocols/status.ts +16 -12
- package/src/services/reqresp/protocols/tx.ts +1 -2
- package/src/services/service.ts +19 -4
- 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/instrumentation.ts +4 -21
- package/src/services/tx_collection/slow_tx_collection.ts +3 -3
- package/src/services/tx_collection/tx_collection.ts +6 -5
- package/src/services/tx_provider.ts +19 -3
- package/src/services/tx_provider_instrumentation.ts +18 -14
- 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 +42 -22
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -80
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +0 -238
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +0 -283
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Attributes,
|
|
3
3
|
type Gauge,
|
|
4
|
+
type Histogram,
|
|
4
5
|
Metrics,
|
|
5
6
|
type TelemetryClient,
|
|
6
7
|
type Tracer,
|
|
7
8
|
type UpDownCounter,
|
|
8
|
-
ValueType,
|
|
9
9
|
getTelemetryClient,
|
|
10
10
|
} from '@aztec/telemetry-client';
|
|
11
11
|
|
|
12
|
+
import type { PeerId } from '@libp2p/interface';
|
|
13
|
+
|
|
12
14
|
import { type GoodByeReason, prettyGoodbyeReason } from '../reqresp/protocols/index.js';
|
|
13
15
|
|
|
14
16
|
export class PeerManagerMetrics {
|
|
@@ -16,6 +18,9 @@ export class PeerManagerMetrics {
|
|
|
16
18
|
private receivedGoodbyes: UpDownCounter;
|
|
17
19
|
private peerCount: Gauge;
|
|
18
20
|
private lowScoreDisconnects: UpDownCounter;
|
|
21
|
+
private peerConnectionDuration: Histogram;
|
|
22
|
+
|
|
23
|
+
private peerConnectedAt: Map<string, number> = new Map<string, number>();
|
|
19
24
|
|
|
20
25
|
public readonly tracer: Tracer;
|
|
21
26
|
|
|
@@ -26,26 +31,11 @@ export class PeerManagerMetrics {
|
|
|
26
31
|
this.tracer = telemetryClient.getTracer(name);
|
|
27
32
|
|
|
28
33
|
const meter = telemetryClient.getMeter(name);
|
|
29
|
-
this.sentGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_SENT
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.receivedGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_RECEIVED, {
|
|
35
|
-
description: 'Number of goodbyes received from peers',
|
|
36
|
-
unit: 'peers',
|
|
37
|
-
valueType: ValueType.INT,
|
|
38
|
-
});
|
|
39
|
-
this.peerCount = meter.createGauge(Metrics.PEER_MANAGER_PEER_COUNT, {
|
|
40
|
-
description: 'Number of peers',
|
|
41
|
-
unit: 'peers',
|
|
42
|
-
valueType: ValueType.INT,
|
|
43
|
-
});
|
|
44
|
-
this.lowScoreDisconnects = meter.createUpDownCounter(Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS, {
|
|
45
|
-
description: 'Number of peers disconnected due to low score',
|
|
46
|
-
unit: 'peers',
|
|
47
|
-
valueType: ValueType.INT,
|
|
48
|
-
});
|
|
34
|
+
this.sentGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_SENT);
|
|
35
|
+
this.receivedGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_RECEIVED);
|
|
36
|
+
this.peerCount = meter.createGauge(Metrics.PEER_MANAGER_PEER_COUNT);
|
|
37
|
+
this.lowScoreDisconnects = meter.createUpDownCounter(Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS);
|
|
38
|
+
this.peerConnectionDuration = meter.createHistogram(Metrics.PEER_MANAGER_PEER_CONNECTION_DURATION);
|
|
49
39
|
}
|
|
50
40
|
|
|
51
41
|
public recordGoodbyeSent(reason: GoodByeReason) {
|
|
@@ -63,4 +53,15 @@ export class PeerManagerMetrics {
|
|
|
63
53
|
public recordLowScoreDisconnect(scoreState: 'Banned' | 'Disconnect') {
|
|
64
54
|
this.lowScoreDisconnects.add(1, { [Attributes.P2P_PEER_SCORE_STATE]: scoreState });
|
|
65
55
|
}
|
|
56
|
+
|
|
57
|
+
public peerConnected(id: PeerId) {
|
|
58
|
+
this.peerConnectedAt.set(id.toString(), Date.now());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public peerDisconnected(id: PeerId) {
|
|
62
|
+
const connectedAt = this.peerConnectedAt.get(id.toString());
|
|
63
|
+
if (connectedAt) {
|
|
64
|
+
this.peerConnectionDuration.record(Date.now() - connectedAt);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
66
67
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
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';
|
|
8
8
|
import type { PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
9
|
import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
10
|
-
import {
|
|
10
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
11
11
|
|
|
12
12
|
import type { Connection, PeerId } from '@libp2p/interface';
|
|
13
13
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
@@ -161,7 +161,6 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
161
161
|
return this.metrics.tracer;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
@trackSpan('PeerManager.heartbeat')
|
|
165
164
|
public async heartbeat() {
|
|
166
165
|
this.heartbeatCounter++;
|
|
167
166
|
this.peerScoring.decayAllScores();
|
|
@@ -278,6 +277,7 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
278
277
|
private handleConnectedPeerEvent(e: CustomEvent<PeerId>) {
|
|
279
278
|
const peerId = e.detail;
|
|
280
279
|
this.logger.verbose(`Connected to peer ${peerId.toString()}`);
|
|
280
|
+
this.metrics.peerConnected(peerId);
|
|
281
281
|
if (this.config.p2pDisableStatusHandshake) {
|
|
282
282
|
return;
|
|
283
283
|
}
|
|
@@ -303,6 +303,7 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
303
303
|
*/
|
|
304
304
|
private handleDisconnectedPeerEvent(e: CustomEvent<PeerId>) {
|
|
305
305
|
const peerId = e.detail;
|
|
306
|
+
this.metrics.peerDisconnected(peerId);
|
|
306
307
|
this.logger.verbose(`Disconnected from peer ${peerId.toString()}`);
|
|
307
308
|
const validatorAddress = this.authenticatedPeerIdToValidatorAddress.get(peerId.toString());
|
|
308
309
|
if (validatorAddress !== undefined) {
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
Metrics,
|
|
7
7
|
type TelemetryClient,
|
|
8
8
|
type UpDownCounter,
|
|
9
|
-
ValueType,
|
|
10
9
|
getTelemetryClient,
|
|
11
10
|
} from '@aztec/telemetry-client';
|
|
12
11
|
|
|
@@ -53,10 +52,7 @@ export class PeerScoring {
|
|
|
53
52
|
|
|
54
53
|
const meter = telemetry.getMeter('PeerScoring');
|
|
55
54
|
|
|
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
|
-
});
|
|
55
|
+
this.peerStateCounter = meter.createUpDownCounter(Metrics.P2P_PEER_STATE_COUNT);
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
public penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity) {
|
|
@@ -261,7 +261,9 @@ export class ConnectionSampler {
|
|
|
261
261
|
}
|
|
262
262
|
} catch (error) {
|
|
263
263
|
this.logger.error(
|
|
264
|
-
`Error cleaning up stale connection to peer ${stream.metadata.peerId?.toString() ?? 'unknown'} stream ${
|
|
264
|
+
`Error cleaning up stale connection to peer ${stream.metadata.peerId?.toString() ?? 'unknown'} stream ${
|
|
265
|
+
stream.id
|
|
266
|
+
}`,
|
|
265
267
|
{ error },
|
|
266
268
|
);
|
|
267
269
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for P2P message deserialization bounds checking.
|
|
3
|
+
* These constants define maximum allowed sizes during deserialization
|
|
4
|
+
* to prevent DoS attacks via maliciously crafted messages.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Max transactions per block for deserialization validation (~300x default of 32) */
|
|
8
|
+
export { MAX_TXS_PER_BLOCK } from '@aztec/stdlib/deserialization';
|
|
9
|
+
|
|
10
|
+
/** Max version string length (e.g., "1.0.0-alpha.123") */
|
|
11
|
+
export const MAX_VERSION_STRING_LENGTH = 64;
|
|
12
|
+
|
|
13
|
+
/** Max block hash string length (hex: 0x + 64 chars, with generous headroom) */
|
|
14
|
+
export const MAX_BLOCK_HASH_STRING_LENGTH = 128;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Request response metrics
|
|
2
|
-
import { Attributes, Metrics
|
|
2
|
+
import { Attributes, Metrics } from '@aztec/telemetry-client';
|
|
3
3
|
import type { TelemetryClient, Tracer, UpDownCounter } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
5
|
export class ReqRespMetrics {
|
|
@@ -18,28 +18,12 @@ export class ReqRespMetrics {
|
|
|
18
18
|
this.tracer = telemetryClient.getTracer(name);
|
|
19
19
|
|
|
20
20
|
const meter = telemetryClient.getMeter(name);
|
|
21
|
-
this.sentRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_SENT_REQUESTS
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
description: 'Number of requests received from peers',
|
|
28
|
-
unit: 'requests',
|
|
29
|
-
valueType: ValueType.INT,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
this.failedOutboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS, {
|
|
33
|
-
description: 'Number of failed outbound requests - nodes not getting valid responses',
|
|
34
|
-
unit: 'requests',
|
|
35
|
-
valueType: ValueType.INT,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
this.failedInboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS, {
|
|
39
|
-
description: 'Number of failed inbound requests - node failing to respond to requests',
|
|
40
|
-
unit: 'requests',
|
|
41
|
-
valueType: ValueType.INT,
|
|
42
|
-
});
|
|
21
|
+
this.sentRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_SENT_REQUESTS);
|
|
22
|
+
this.receivedRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS);
|
|
23
|
+
|
|
24
|
+
this.failedOutboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS);
|
|
25
|
+
|
|
26
|
+
this.failedInboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS);
|
|
43
27
|
}
|
|
44
28
|
|
|
45
29
|
public recordRequestSent(protocol: string) {
|
|
@@ -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,5 +1,7 @@
|
|
|
1
1
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
2
|
|
|
3
|
+
import { MAX_TXS_PER_BLOCK } from '../../constants.js';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* BitVector helper class for representing and serializing bit vectors
|
|
5
7
|
*/
|
|
@@ -80,6 +82,13 @@ export class BitVector {
|
|
|
80
82
|
const reader = BufferReader.asReader(buffer);
|
|
81
83
|
const length = reader.readNumber();
|
|
82
84
|
|
|
85
|
+
if (length < 0) {
|
|
86
|
+
throw new Error(`BitVector length ${length} cannot be negative`);
|
|
87
|
+
}
|
|
88
|
+
if (length > MAX_TXS_PER_BLOCK) {
|
|
89
|
+
throw new Error(`BitVector length ${length} exceeds maximum ${MAX_TXS_PER_BLOCK}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
83
92
|
const bitBuffer = reader.readBytes(BitVector.byteLength(length));
|
|
84
93
|
return new BitVector(bitBuffer, length);
|
|
85
94
|
}
|
|
@@ -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';
|
|
@@ -6,6 +7,8 @@ import type { WorldStateSyncStatus, WorldStateSynchronizer } from '@aztec/stdlib
|
|
|
6
7
|
|
|
7
8
|
import type { PeerId } from '@libp2p/interface';
|
|
8
9
|
|
|
10
|
+
import { MAX_BLOCK_HASH_STRING_LENGTH, MAX_VERSION_STRING_LENGTH } from '../constants.js';
|
|
11
|
+
|
|
9
12
|
/*
|
|
10
13
|
* P2P Status Message
|
|
11
14
|
* It is used to establish Status handshake between to peers
|
|
@@ -15,12 +18,13 @@ import type { PeerId } from '@libp2p/interface';
|
|
|
15
18
|
export class StatusMessage {
|
|
16
19
|
constructor(
|
|
17
20
|
readonly compressedComponentsVersion: string,
|
|
18
|
-
readonly latestBlockNumber:
|
|
21
|
+
readonly latestBlockNumber: BlockNumber,
|
|
19
22
|
readonly latestBlockHash: string,
|
|
20
|
-
readonly finalizedBlockNumber:
|
|
23
|
+
readonly finalizedBlockNumber: BlockNumber,
|
|
24
|
+
) {
|
|
21
25
|
//TODO: add finalizedBlockHash
|
|
22
26
|
//readonly finalizedBlockHash: string,
|
|
23
|
-
|
|
27
|
+
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* Deserializes the StatusMessage object from a Buffer.
|
|
@@ -30,12 +34,12 @@ export class StatusMessage {
|
|
|
30
34
|
static fromBuffer(buffer: Buffer | BufferReader): StatusMessage {
|
|
31
35
|
const reader = BufferReader.asReader(buffer);
|
|
32
36
|
return new StatusMessage(
|
|
33
|
-
reader.readString(), // compressedComponentsVersion
|
|
34
|
-
reader.readNumber(), // latestBlockNumber
|
|
35
|
-
reader.readString(), // latestBlockHash
|
|
36
|
-
reader.readNumber(), // finalizedBlockNumber
|
|
37
|
+
reader.readString(MAX_VERSION_STRING_LENGTH), // compressedComponentsVersion
|
|
38
|
+
BlockNumber(reader.readNumber()), // latestBlockNumber
|
|
39
|
+
reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // latestBlockHash
|
|
40
|
+
BlockNumber(reader.readNumber()), // finalizedBlockNumber
|
|
37
41
|
//TODO: add finalizedBlockHash
|
|
38
|
-
//reader.readString(), // finalizedBlockHash
|
|
42
|
+
//reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // finalizedBlockHash
|
|
39
43
|
);
|
|
40
44
|
}
|
|
41
45
|
|
|
@@ -63,9 +67,9 @@ export class StatusMessage {
|
|
|
63
67
|
static fromWorldStateSyncStatus(version: string, syncStatus: WorldStateSyncStatus): StatusMessage {
|
|
64
68
|
return new StatusMessage(
|
|
65
69
|
version,
|
|
66
|
-
syncStatus.latestBlockNumber,
|
|
70
|
+
BlockNumber(syncStatus.latestBlockNumber),
|
|
67
71
|
syncStatus.latestBlockHash,
|
|
68
|
-
syncStatus.finalizedBlockNumber,
|
|
72
|
+
BlockNumber(syncStatus.finalizedBlockNumber),
|
|
69
73
|
//TODO: add finalizedBlockHash
|
|
70
74
|
);
|
|
71
75
|
}
|
|
@@ -73,9 +77,9 @@ export class StatusMessage {
|
|
|
73
77
|
static random(): StatusMessage {
|
|
74
78
|
return new StatusMessage(
|
|
75
79
|
'1.0.0',
|
|
76
|
-
Math.floor(Math.random() * 100),
|
|
80
|
+
BlockNumber(Math.floor(Math.random() * 100)),
|
|
77
81
|
Buffer32.random().toString(),
|
|
78
|
-
Math.floor(Math.random() * 100),
|
|
82
|
+
BlockNumber(Math.floor(Math.random() * 100)),
|
|
79
83
|
//TODO: add finalizedBlockHash
|
|
80
84
|
);
|
|
81
85
|
}
|
|
@@ -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
|
package/src/services/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore, Gossipable } from '@aztec/stdlib/p2p';
|
|
4
4
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -22,10 +22,23 @@ export enum PeerDiscoveryState {
|
|
|
22
22
|
STOPPED = 'stopped',
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Callback for when a block proposal is received.
|
|
27
|
+
* Validators validate but DO NOT attest to individual blocks - attestations are only for checkpoints.
|
|
28
|
+
* @returns true if the proposal is valid, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export type P2PBlockReceivedCallback = (block: BlockProposal, sender: PeerId) => Promise<boolean>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Callback for when a checkpoint proposal is received.
|
|
34
|
+
* The checkpoint proposal is passed as CheckpointProposalCore (without lastBlock) since
|
|
35
|
+
* the lastBlock is extracted and stored separately as a BlockProposal, and the block
|
|
36
|
+
* callback is invoked and awaited before this checkpoint callback.
|
|
37
|
+
*/
|
|
38
|
+
export type P2PCheckpointReceivedCallback = (
|
|
39
|
+
checkpoint: CheckpointProposalCore,
|
|
27
40
|
sender: PeerId,
|
|
28
|
-
) => Promise<
|
|
41
|
+
) => Promise<CheckpointAttestation[] | undefined>;
|
|
29
42
|
|
|
30
43
|
export type AuthReceivedCallback = (peerId: PeerId, authRequest: AuthRequest) => Promise<AuthResponse | undefined>;
|
|
31
44
|
|
|
@@ -70,6 +83,8 @@ export interface P2PService {
|
|
|
70
83
|
// Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
71
84
|
registerBlockReceivedCallback(callback: P2PBlockReceivedCallback): void;
|
|
72
85
|
|
|
86
|
+
registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback): void;
|
|
87
|
+
|
|
73
88
|
getEnr(): ENR | undefined;
|
|
74
89
|
|
|
75
90
|
getPeers(includePending?: boolean): PeerInfo[];
|
|
@@ -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,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Attributes,
|
|
3
|
-
type Histogram,
|
|
4
|
-
Metrics,
|
|
5
|
-
type TelemetryClient,
|
|
6
|
-
type UpDownCounter,
|
|
7
|
-
ValueType,
|
|
8
|
-
} from '@aztec/telemetry-client';
|
|
1
|
+
import { Attributes, type Histogram, Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
|
|
9
2
|
|
|
10
3
|
import type { CollectionMethod } from './tx_collection.js';
|
|
11
4
|
|
|
@@ -17,21 +10,11 @@ export class TxCollectionInstrumentation {
|
|
|
17
10
|
constructor(client: TelemetryClient, name: string) {
|
|
18
11
|
const meter = client.getMeter(name);
|
|
19
12
|
|
|
20
|
-
this.txsCollected = meter.createUpDownCounter(Metrics.TX_COLLECTOR_COUNT
|
|
21
|
-
description: 'The number of txs collected',
|
|
22
|
-
});
|
|
13
|
+
this.txsCollected = meter.createUpDownCounter(Metrics.TX_COLLECTOR_COUNT);
|
|
23
14
|
|
|
24
|
-
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX
|
|
25
|
-
unit: 'ms',
|
|
26
|
-
description: 'Average duration per tx of an individual tx collection request',
|
|
27
|
-
valueType: ValueType.INT,
|
|
28
|
-
});
|
|
15
|
+
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
|
|
29
16
|
|
|
30
|
-
this.collectionDurationPerRequest = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_REQUEST
|
|
31
|
-
unit: 'ms',
|
|
32
|
-
description: 'Total duration of an individual tx collection request',
|
|
33
|
-
valueType: ValueType.INT,
|
|
34
|
-
});
|
|
17
|
+
this.collectionDurationPerRequest = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_REQUEST);
|
|
35
18
|
}
|
|
36
19
|
|
|
37
20
|
increaseTxsFor(what: CollectionMethod, count: number, duration: number) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { chunk } from '@aztec/foundation/collection';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { boundInclusive } from '@aztec/foundation/number';
|
|
@@ -203,7 +203,7 @@ export class SlowTxCollection {
|
|
|
203
203
|
* Stop collecting all txs for blocks less than or requal to the block number specified.
|
|
204
204
|
* To be called when we no longer care about gathering txs up to a certain block, eg when they become proven or finalized.
|
|
205
205
|
*/
|
|
206
|
-
public stopCollectingForBlocksUpTo(blockNumber:
|
|
206
|
+
public stopCollectingForBlocksUpTo(blockNumber: BlockNumber): void {
|
|
207
207
|
for (const [txHash, info] of this.missingTxs.entries()) {
|
|
208
208
|
if (info.blockNumber <= blockNumber) {
|
|
209
209
|
this.missingTxs.delete(txHash);
|
|
@@ -215,7 +215,7 @@ export class SlowTxCollection {
|
|
|
215
215
|
* Stop collecting all txs for blocks greater than the block number specified.
|
|
216
216
|
* To be called when there is a chain prune and previously mined txs are no longer relevant.
|
|
217
217
|
*/
|
|
218
|
-
public stopCollectingForBlocksAfter(blockNumber:
|
|
218
|
+
public stopCollectingForBlocksAfter(blockNumber: BlockNumber): void {
|
|
219
219
|
for (const [txHash, info] of this.missingTxs.entries()) {
|
|
220
220
|
if (info.blockNumber > blockNumber) {
|
|
221
221
|
this.missingTxs.delete(txHash);
|
|
@@ -1,3 +1,4 @@
|
|
|
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';
|
|
@@ -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
28
|
| { type: 'block'; block: L2Block }
|
|
28
|
-
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber:
|
|
29
|
+
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
|
|
29
30
|
|
|
30
31
|
export type FastCollectionRequest = FastCollectionRequestInput & {
|
|
31
32
|
missingTxHashes: Set<string>;
|
|
@@ -152,7 +153,7 @@ export class TxCollection {
|
|
|
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
|
) {
|
|
@@ -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,3 +1,4 @@
|
|
|
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';
|
|
@@ -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(
|
|
@@ -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 [];
|