@aztec/p2p 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701
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.js +1 -1
- package/dest/client/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +10 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +451 -120
- package/dest/config.d.ts +4 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +8 -11
- 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 +237 -263
- 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 +113 -108
- 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 +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- package/dest/mem_pools/instrumentation.d.ts +3 -3
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +10 -17
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +35 -26
- 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 +312 -336
- 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 +8 -4
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +7 -7
- 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 +51 -18
- 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/block_header_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +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/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 +1 -1
- 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/timestamp_validator.d.ts +1 -1
- 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 +6 -5
- 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 +28 -11
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +711 -152
- 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 +2 -10
- 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/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/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/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -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/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 +3 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +5 -5
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +3 -1
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +6 -19
- 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 +16 -16
- package/src/client/factory.ts +1 -1
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +84 -134
- package/src/config.ts +10 -16
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +19 -13
- package/src/mem_pools/instrumentation.ts +18 -25
- package/src/mem_pools/tx_pool/README.md +270 -0
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +360 -368
- 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 +8 -3
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +7 -7
- package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
- 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/block_header_validator.ts +3 -1
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- 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 +12 -4
- package/src/msg_validators/tx_validator/size_validator.ts +18 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +5 -4
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +351 -115
- package/src/services/peer-manager/metrics.ts +22 -21
- package/src/services/peer-manager/peer_manager.ts +3 -2
- 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/metrics.ts +7 -23
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +4 -4
- package/src/services/tx_provider.ts +6 -3
- package/src/services/tx_provider_instrumentation.ts +11 -24
- package/src/testbench/p2p_client_testbench_worker.ts +41 -21
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +0 -81
- 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 -242
- 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 -288
- 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
|
}
|
|
@@ -7,7 +7,7 @@ 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,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
|
}
|
|
@@ -7,6 +7,8 @@ import type { WorldStateSyncStatus, WorldStateSynchronizer } from '@aztec/stdlib
|
|
|
7
7
|
|
|
8
8
|
import type { PeerId } from '@libp2p/interface';
|
|
9
9
|
|
|
10
|
+
import { MAX_BLOCK_HASH_STRING_LENGTH, MAX_VERSION_STRING_LENGTH } from '../constants.js';
|
|
11
|
+
|
|
10
12
|
/*
|
|
11
13
|
* P2P Status Message
|
|
12
14
|
* It is used to establish Status handshake between to peers
|
|
@@ -19,9 +21,10 @@ export class StatusMessage {
|
|
|
19
21
|
readonly latestBlockNumber: BlockNumber,
|
|
20
22
|
readonly latestBlockHash: string,
|
|
21
23
|
readonly finalizedBlockNumber: BlockNumber,
|
|
24
|
+
) {
|
|
22
25
|
//TODO: add finalizedBlockHash
|
|
23
26
|
//readonly finalizedBlockHash: string,
|
|
24
|
-
|
|
27
|
+
}
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* Deserializes the StatusMessage object from a Buffer.
|
|
@@ -31,12 +34,12 @@ export class StatusMessage {
|
|
|
31
34
|
static fromBuffer(buffer: Buffer | BufferReader): StatusMessage {
|
|
32
35
|
const reader = BufferReader.asReader(buffer);
|
|
33
36
|
return new StatusMessage(
|
|
34
|
-
reader.readString(), // compressedComponentsVersion
|
|
37
|
+
reader.readString(MAX_VERSION_STRING_LENGTH), // compressedComponentsVersion
|
|
35
38
|
BlockNumber(reader.readNumber()), // latestBlockNumber
|
|
36
|
-
reader.readString(), // latestBlockHash
|
|
39
|
+
reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // latestBlockHash
|
|
37
40
|
BlockNumber(reader.readNumber()), // finalizedBlockNumber
|
|
38
41
|
//TODO: add finalizedBlockHash
|
|
39
|
-
//reader.readString(), // finalizedBlockHash
|
|
42
|
+
//reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // finalizedBlockHash
|
|
40
43
|
);
|
|
41
44
|
}
|
|
42
45
|
|
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,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) {
|
|
@@ -4,7 +4,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
4
4
|
import { boundInclusive } from '@aztec/foundation/number';
|
|
5
5
|
import { RunningPromise } from '@aztec/foundation/promise';
|
|
6
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
7
|
-
import type {
|
|
7
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
8
8
|
import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
9
9
|
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
10
10
|
|
|
@@ -76,7 +76,7 @@ export class SlowTxCollection {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
79
|
-
public startCollecting(block:
|
|
79
|
+
public startCollecting(block: L2Block, txHashes: TxHash[]) {
|
|
80
80
|
const slot = block.header.getSlot();
|
|
81
81
|
const deadline = this.getDeadlineForSlot(slot);
|
|
82
82
|
if (+deadline < this.dateProvider.now()) {
|
|
@@ -3,7 +3,7 @@ import { compactArray } from '@aztec/foundation/collection';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { type PromiseWithResolvers, RunningPromise } from '@aztec/foundation/promise';
|
|
5
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import type {
|
|
6
|
+
import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
|
|
7
7
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
8
8
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
9
9
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -25,7 +25,7 @@ export type CollectionMethod = 'fast-req-resp' | 'fast-node-rpc' | 'slow-req-res
|
|
|
25
25
|
export type MissingTxInfo = { blockNumber: BlockNumber; deadline: Date; readyForReqResp: boolean };
|
|
26
26
|
|
|
27
27
|
export type FastCollectionRequestInput =
|
|
28
|
-
| { type: 'block'; block:
|
|
28
|
+
| { type: 'block'; block: L2Block }
|
|
29
29
|
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
|
|
30
30
|
|
|
31
31
|
export type FastCollectionRequest = FastCollectionRequestInput & {
|
|
@@ -146,7 +146,7 @@ export class TxCollection {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
149
|
-
public startCollecting(block:
|
|
149
|
+
public startCollecting(block: L2Block, txHashes: TxHash[]) {
|
|
150
150
|
return this.slowCollection.startCollecting(block, txHashes);
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -162,7 +162,7 @@ export class TxCollection {
|
|
|
162
162
|
|
|
163
163
|
/** Collects the set of txs for the given mined block as fast as possible */
|
|
164
164
|
public collectFastForBlock(
|
|
165
|
-
block:
|
|
165
|
+
block: L2Block,
|
|
166
166
|
txHashes: TxHash[] | string[],
|
|
167
167
|
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
168
168
|
) {
|
|
@@ -2,7 +2,7 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { compactArray } from '@aztec/foundation/collection';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { elapsed } from '@aztec/foundation/timer';
|
|
5
|
-
import type {
|
|
5
|
+
import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
|
|
6
6
|
import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
8
8
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -68,7 +68,7 @@ export class TxProvider implements ITxProvider {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/** Gathers txs from the tx pool, remote rpc nodes, and reqresp. */
|
|
71
|
-
public getTxsForBlock(block:
|
|
71
|
+
public getTxsForBlock(block: L2Block, opts: { deadline: Date }): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
|
|
72
72
|
return this.getOrderedTxsFromAllSources(
|
|
73
73
|
{ type: 'block', block },
|
|
74
74
|
block.toBlockInfo(),
|
|
@@ -137,6 +137,7 @@ export class TxProvider implements ITxProvider {
|
|
|
137
137
|
);
|
|
138
138
|
|
|
139
139
|
if (missingTxHashes.size === 0) {
|
|
140
|
+
this.instrumentation.incTxsFromP2P(0, txHashes.length);
|
|
140
141
|
return { txsFromMempool };
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -155,6 +156,7 @@ export class TxProvider implements ITxProvider {
|
|
|
155
156
|
|
|
156
157
|
if (missingTxHashes.size === 0) {
|
|
157
158
|
await this.processProposalTxs(txsFromProposal);
|
|
159
|
+
this.instrumentation.incTxsFromP2P(0, txHashes.length);
|
|
158
160
|
return { txsFromMempool, txsFromProposal };
|
|
159
161
|
}
|
|
160
162
|
|
|
@@ -166,13 +168,14 @@ export class TxProvider implements ITxProvider {
|
|
|
166
168
|
|
|
167
169
|
if (txsFromNetwork.length > 0) {
|
|
168
170
|
txsFromNetwork.forEach(tx => missingTxHashes.delete(tx.txHash.toString()));
|
|
169
|
-
this.instrumentation.incTxsFromP2P(txsFromNetwork.length, txHashes.length);
|
|
170
171
|
this.log.debug(
|
|
171
172
|
`Retrieved ${txsFromNetwork.length} txs from network for block proposal (${missingTxHashes.size} pending)`,
|
|
172
173
|
{ ...blockInfo, missingTxHashes: [...missingTxHashes] },
|
|
173
174
|
);
|
|
174
175
|
}
|
|
175
176
|
|
|
177
|
+
this.instrumentation.incTxsFromP2P(txsFromNetwork.length, txHashes.length);
|
|
178
|
+
|
|
176
179
|
if (missingTxHashes.size === 0) {
|
|
177
180
|
return { txsFromNetwork, txsFromMempool, txsFromProposal };
|
|
178
181
|
}
|
|
@@ -12,30 +12,17 @@ export class TxProviderInstrumentation {
|
|
|
12
12
|
constructor(client: TelemetryClient, name: string) {
|
|
13
13
|
const meter = client.getMeter(name);
|
|
14
14
|
|
|
15
|
-
this.txFromProposalCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_PROPOSALS_COUNT
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.missingTxsCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_MISSING_TXS_COUNT, {
|
|
28
|
-
description: 'The number of txs not found anywhere',
|
|
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
|
-
});
|
|
15
|
+
this.txFromProposalCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_PROPOSALS_COUNT);
|
|
16
|
+
|
|
17
|
+
this.txFromMempoolCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_MEMPOOL_COUNT);
|
|
18
|
+
|
|
19
|
+
this.txFromP2PCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_P2P_COUNT);
|
|
20
|
+
|
|
21
|
+
this.missingTxsCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_MISSING_TXS_COUNT);
|
|
22
|
+
|
|
23
|
+
this.fractionOfTxsRequestedFromP2P = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUESTED_FRACTION);
|
|
24
|
+
|
|
25
|
+
this.txsRequestDelay = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUEST_DELAY);
|
|
39
26
|
}
|
|
40
27
|
|
|
41
28
|
incTxsFromProposals(count: number) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { MockL2BlockSource } from '@aztec/archiver/test';
|
|
7
7
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
8
8
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
|
-
import {
|
|
9
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
10
10
|
import { createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
12
12
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
@@ -56,6 +56,7 @@ function mockTxPool(): TxPool {
|
|
|
56
56
|
hasTx: () => Promise.resolve(false),
|
|
57
57
|
updateConfig: () => {},
|
|
58
58
|
markTxsAsNonEvictable: () => Promise.resolve(),
|
|
59
|
+
clearNonEvictableTxs: () => Promise.resolve(),
|
|
59
60
|
cleanupDeletedMinedTxs: () => Promise.resolve(0),
|
|
60
61
|
};
|
|
61
62
|
return Object.assign(new EventEmitter(), pool);
|
|
@@ -64,35 +65,37 @@ function mockTxPool(): TxPool {
|
|
|
64
65
|
function mockAttestationPool(): AttestationPool {
|
|
65
66
|
return {
|
|
66
67
|
isEmpty: () => Promise.resolve(false),
|
|
67
|
-
addAttestations: () => Promise.resolve(),
|
|
68
|
-
deleteAttestations: () => Promise.resolve(),
|
|
69
|
-
deleteAttestationsOlderThan: () => Promise.resolve(),
|
|
70
|
-
deleteAttestationsForSlot: () => Promise.resolve(),
|
|
71
|
-
deleteAttestationsForSlotAndProposal: () => Promise.resolve(),
|
|
72
|
-
getAttestationsForSlot: () => Promise.resolve([]),
|
|
73
|
-
getAttestationsForSlotAndProposal: () => Promise.resolve([]),
|
|
74
68
|
addBlockProposal: () => Promise.resolve(),
|
|
75
69
|
getBlockProposal: () => Promise.resolve(undefined),
|
|
76
70
|
hasBlockProposal: () => Promise.resolve(false),
|
|
77
|
-
hasAttestation: () => Promise.resolve(false),
|
|
78
71
|
canAddProposal: () => Promise.resolve(true),
|
|
79
|
-
|
|
72
|
+
// Checkpoint attestation methods
|
|
73
|
+
addCheckpointProposal: () => Promise.resolve(),
|
|
74
|
+
getCheckpointProposal: () => Promise.resolve(undefined),
|
|
75
|
+
hasCheckpointProposal: () => Promise.resolve(false),
|
|
76
|
+
addCheckpointAttestations: () => Promise.resolve(),
|
|
77
|
+
getCheckpointAttestationsForSlot: () => Promise.resolve([]),
|
|
78
|
+
getCheckpointAttestationsForSlotAndProposal: () => Promise.resolve([]),
|
|
79
|
+
deleteCheckpointAttestationsOlderThan: () => Promise.resolve(),
|
|
80
|
+
hasReachedCheckpointProposalCap: () => Promise.resolve(false),
|
|
81
|
+
hasReachedCheckpointAttestationCap: () => Promise.resolve(false),
|
|
82
|
+
canAddCheckpointProposal: () => Promise.resolve(true),
|
|
83
|
+
canAddCheckpointAttestation: () => Promise.resolve(true),
|
|
84
|
+
hasCheckpointAttestation: () => Promise.resolve(false),
|
|
80
85
|
};
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
function mockEpochCache(): EpochCacheInterface {
|
|
84
89
|
return {
|
|
85
|
-
getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: EpochNumber.ZERO }),
|
|
90
|
+
getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: EpochNumber.ZERO, isEscapeHatchOpen: false }),
|
|
86
91
|
getProposerIndexEncoding: () => '0x' as `0x${string}`,
|
|
87
|
-
getEpochAndSlotNow: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n }),
|
|
92
|
+
getEpochAndSlotNow: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n, nowMs: 0n }),
|
|
88
93
|
computeProposerIndex: () => 0n,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
nextSlot: SlotNumber.ZERO,
|
|
95
|
-
}),
|
|
94
|
+
getCurrentAndNextSlot: () => ({
|
|
95
|
+
currentSlot: SlotNumber.ZERO,
|
|
96
|
+
nextSlot: SlotNumber.ZERO,
|
|
97
|
+
}),
|
|
98
|
+
getProposerAttesterAddressInSlot: () => Promise.resolve(undefined),
|
|
96
99
|
getEpochAndSlotInNextL1Slot: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n, now: 0n }),
|
|
97
100
|
isInCommittee: () => Promise.resolve(false),
|
|
98
101
|
getRegisteredValidators: () => Promise.resolve([]),
|
|
@@ -188,9 +191,25 @@ class TestLibP2PService<T extends P2PClientType = P2PClientType.Full> extends Li
|
|
|
188
191
|
|
|
189
192
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
190
193
|
process.on('message', async msg => {
|
|
191
|
-
|
|
194
|
+
// Note: peerIdPrivateKey comes as a raw string (not SecretValue) because
|
|
195
|
+
// SecretValue's private fields can't be serialized via IPC
|
|
196
|
+
const {
|
|
197
|
+
type,
|
|
198
|
+
config: rawConfig,
|
|
199
|
+
clientIndex,
|
|
200
|
+
} = msg as {
|
|
201
|
+
type: string;
|
|
202
|
+
config: Omit<P2PConfig, 'peerIdPrivateKey'> & { peerIdPrivateKey?: string };
|
|
203
|
+
clientIndex: number;
|
|
204
|
+
};
|
|
192
205
|
try {
|
|
193
206
|
if (type === 'START') {
|
|
207
|
+
// Re-wrap the peerIdPrivateKey with SecretValue
|
|
208
|
+
const config: P2PConfig = {
|
|
209
|
+
...rawConfig,
|
|
210
|
+
peerIdPrivateKey: rawConfig.peerIdPrivateKey ? new SecretValue(rawConfig.peerIdPrivateKey) : undefined,
|
|
211
|
+
} as P2PConfig;
|
|
212
|
+
|
|
194
213
|
const txPool = mockTxPool();
|
|
195
214
|
const attestationPool = mockAttestationPool();
|
|
196
215
|
const epochCache = mockEpochCache();
|
|
@@ -223,14 +242,15 @@ process.on('message', async msg => {
|
|
|
223
242
|
);
|
|
224
243
|
|
|
225
244
|
// Create test service with validation disabled
|
|
245
|
+
// Note: Parameter order must match LibP2PService constructor
|
|
226
246
|
const testService = new TestLibP2PService(
|
|
227
247
|
P2PClientType.Full,
|
|
228
248
|
config,
|
|
229
249
|
(client as any).p2pService.node,
|
|
230
250
|
(client as any).p2pService.peerDiscoveryService,
|
|
231
|
-
(client as any).p2pService.mempools,
|
|
232
251
|
(client as any).p2pService.reqresp,
|
|
233
252
|
(client as any).p2pService.peerManager,
|
|
253
|
+
(client as any).p2pService.mempools,
|
|
234
254
|
(client as any).p2pService.archiver,
|
|
235
255
|
epochCache,
|
|
236
256
|
proofVerifier,
|
|
@@ -73,7 +73,12 @@ class WorkerClientManager {
|
|
|
73
73
|
clientIndex: number,
|
|
74
74
|
): [ChildProcess, Promise<void>] {
|
|
75
75
|
const childProcess = fork(workerPath);
|
|
76
|
-
|
|
76
|
+
// Extract the raw peerIdPrivateKey value since SecretValue can't be serialized via IPC
|
|
77
|
+
const serializedConfig = {
|
|
78
|
+
...config,
|
|
79
|
+
peerIdPrivateKey: config.peerIdPrivateKey?.getValue(),
|
|
80
|
+
};
|
|
81
|
+
childProcess.send({ type: 'START', config: serializedConfig, clientIndex });
|
|
77
82
|
|
|
78
83
|
// Handle unexpected child process exit
|
|
79
84
|
childProcess.on('exit', (code, signal) => {
|