@aztec/p2p 0.76.4 → 0.77.0-testnet-ignition.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts +2 -2
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +55 -41
- package/dest/client/factory.d.ts +8 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +8 -10
- package/dest/client/index.js +0 -1
- package/dest/client/p2p_client.d.ts +7 -4
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +492 -514
- package/dest/config.d.ts +8 -10
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +54 -47
- package/dest/enr/generate-enr.d.ts +9 -0
- package/dest/enr/generate-enr.d.ts.map +1 -0
- package/dest/enr/generate-enr.js +30 -0
- package/dest/enr/index.d.ts +2 -0
- package/dest/enr/index.d.ts.map +1 -0
- package/dest/enr/index.js +1 -0
- package/dest/errors/reqresp.error.js +6 -10
- package/dest/index.js +0 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +6 -2
- 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 +65 -33
- package/dest/mem_pools/attestation_pool/index.js +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +3 -3
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +23 -20
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +22 -26
- package/dest/mem_pools/attestation_pool/mocks.d.ts +3 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +12 -7
- package/dest/mem_pools/index.d.ts +2 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -2
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +35 -39
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/interface.js +3 -2
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +2 -2
- 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 +129 -136
- package/dest/mem_pools/tx_pool/index.js +0 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +2 -2
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +46 -44
- package/dest/mem_pools/tx_pool/priority.d.ts +1 -1
- package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/priority.js +1 -3
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool.js +3 -2
- 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 +109 -39
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +2 -2
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +4 -4
- package/dest/msg_validators/attestation_validator/index.js +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +2 -2
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +3 -3
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/dest/msg_validators/index.js +0 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +9 -11
- 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 +18 -13
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +102 -33
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +34 -20
- package/dest/msg_validators/tx_validator/index.js +0 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +30 -27
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts +2 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +17 -12
- package/dest/services/data_store.js +57 -57
- package/dest/services/discv5/discV5_service.d.ts +2 -0
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +64 -36
- package/dest/services/dummy_service.d.ts +4 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +41 -59
- package/dest/services/encoding.d.ts +3 -3
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +10 -9
- package/dest/services/gossipsub/scoring.d.ts +7 -0
- package/dest/services/gossipsub/scoring.d.ts.map +1 -0
- package/dest/services/gossipsub/scoring.js +10 -0
- package/dest/services/index.js +0 -1
- package/dest/services/libp2p/libp2p_service.d.ts +10 -33
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +682 -673
- package/dest/services/peer-manager/metrics.js +14 -7
- package/dest/services/peer-manager/peer_manager.d.ts +24 -6
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +390 -340
- package/dest/services/peer-manager/peer_scoring.d.ts +3 -3
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +21 -19
- package/dest/services/reqresp/config.js +4 -5
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts +2 -2
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/batch_connection_sampler.js +35 -28
- 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/connection-sampler/connection_sampler.js +67 -61
- package/dest/services/reqresp/index.js +1 -3
- 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 +27 -31
- 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 +23 -10
- package/dest/services/reqresp/protocols/block.d.ts +2 -2
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +1 -2
- package/dest/services/reqresp/protocols/goodbye.d.ts +5 -5
- package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/goodbye.js +36 -41
- package/dest/services/reqresp/protocols/index.js +1 -3
- package/dest/services/reqresp/protocols/ping.js +1 -3
- package/dest/services/reqresp/protocols/status.js +1 -3
- package/dest/services/reqresp/protocols/tx.d.ts +3 -3
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +6 -9
- package/dest/services/reqresp/rate-limiter/index.js +0 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts +9 -9
- package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limiter.js +53 -46
- package/dest/services/reqresp/rate-limiter/rate_limits.js +16 -17
- package/dest/services/reqresp/reqresp.d.ts +4 -4
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +467 -464
- package/dest/services/reqresp/status.js +16 -17
- package/dest/services/service.d.ts +3 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/service.js +3 -4
- package/dest/test-helpers/generate-peer-id-private-keys.js +2 -4
- package/dest/test-helpers/get-ports.js +3 -3
- package/dest/test-helpers/index.js +0 -1
- package/dest/test-helpers/make-enrs.d.ts +1 -1
- package/dest/test-helpers/make-enrs.d.ts.map +1 -1
- package/dest/test-helpers/make-enrs.js +3 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts +7 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +10 -12
- package/dest/test-helpers/reqresp-nodes.d.ts +18 -7
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +64 -40
- package/dest/testbench/p2p_client_testbench_worker.js +61 -45
- package/dest/testbench/parse_log_file.d.ts +2 -0
- package/dest/testbench/parse_log_file.d.ts.map +1 -0
- package/dest/testbench/parse_log_file.js +131 -0
- package/dest/testbench/testbench.d.ts +2 -0
- package/dest/testbench/testbench.d.ts.map +1 -0
- package/dest/testbench/testbench.js +141 -0
- package/dest/{services/types.d.ts → types/index.d.ts} +1 -1
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +28 -0
- package/dest/util.d.ts +5 -5
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +23 -34
- package/dest/versioning.d.ts +3 -3
- package/dest/versioning.d.ts.map +1 -1
- package/dest/versioning.js +7 -12
- package/package.json +15 -13
- package/src/bootstrap/bootstrap.ts +30 -17
- package/src/client/factory.ts +9 -12
- package/src/client/p2p_client.ts +13 -24
- package/src/config.ts +14 -15
- package/src/enr/generate-enr.ts +39 -0
- package/src/enr/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +1 -1
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +4 -3
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +3 -3
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +2 -2
- package/src/mem_pools/attestation_pool/mocks.ts +5 -5
- package/src/mem_pools/index.ts +2 -2
- package/src/mem_pools/instrumentation.ts +4 -3
- package/src/mem_pools/interface.ts +3 -3
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +4 -4
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +3 -3
- package/src/mem_pools/tx_pool/priority.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool.ts +1 -1
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +4 -3
- package/src/msg_validators/attestation_validator/attestation_validator.ts +2 -2
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +2 -2
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
- package/src/msg_validators/tx_validator/data_validator.ts +57 -4
- package/src/msg_validators/tx_validator/double_spend_validator.ts +17 -12
- package/src/msg_validators/tx_validator/metadata_validator.ts +2 -2
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -6
- package/src/services/discv5/discV5_service.ts +33 -8
- package/src/services/dummy_service.ts +4 -2
- package/src/services/encoding.ts +3 -3
- package/src/services/gossipsub/scoring.ts +13 -0
- package/src/services/libp2p/libp2p_service.ts +124 -146
- package/src/services/peer-manager/peer_manager.ts +71 -13
- package/src/services/peer-manager/peer_scoring.ts +3 -3
- package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +2 -2
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +9 -3
- package/src/services/reqresp/interface.ts +4 -3
- package/src/services/reqresp/metrics.ts +1 -1
- package/src/services/reqresp/protocols/block.ts +3 -3
- package/src/services/reqresp/protocols/goodbye.ts +7 -7
- package/src/services/reqresp/protocols/tx.ts +5 -5
- package/src/services/reqresp/rate-limiter/rate_limiter.ts +22 -18
- package/src/services/reqresp/reqresp.ts +18 -11
- package/src/services/service.ts +3 -2
- package/src/test-helpers/make-enrs.ts +1 -1
- package/src/test-helpers/make-test-p2p-clients.ts +9 -7
- package/src/test-helpers/reqresp-nodes.ts +32 -18
- package/src/testbench/p2p_client_testbench_worker.ts +16 -9
- package/src/testbench/parse_log_file.ts +175 -0
- package/src/testbench/testbench.ts +157 -0
- package/src/util.ts +5 -5
- package/src/versioning.ts +7 -7
- package/dest/services/libp2p/libp2p_logger.d.ts +0 -7
- package/dest/services/libp2p/libp2p_logger.d.ts.map +0 -1
- package/dest/services/libp2p/libp2p_logger.js +0 -67
- package/dest/services/types.d.ts.map +0 -1
- package/dest/services/types.js +0 -35
- package/src/services/libp2p/libp2p_logger.ts +0 -78
- package/src/testbench/scripts/run_testbench.sh +0 -7
- /package/src/{services/types.ts → types/index.ts} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { PeerId } from '@libp2p/interface';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import type { PeerManager } from '../../peer-manager/peer_manager.js';
|
|
6
6
|
import { ReqRespSubProtocol, type ReqRespSubProtocolHandler } from '../interface.js';
|
|
7
|
-
import {
|
|
7
|
+
import type { ReqResp } from '../reqresp.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Enum defining the possible reasons for a goodbye message.
|
|
@@ -12,8 +12,8 @@ import { type ReqResp } from '../reqresp.js';
|
|
|
12
12
|
export enum GoodByeReason {
|
|
13
13
|
/** The peer has shutdown, will be received whenever a peer's node is routinely stopped */
|
|
14
14
|
SHUTDOWN = 0x1,
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/** The max peer count has been reached, will be received whenever a low scoring peer is disconnected to satisfy the max peer count */
|
|
16
|
+
MAX_PEERS = 0x2,
|
|
17
17
|
/** The peer has a low score, will be received whenever a peer's score is low */
|
|
18
18
|
LOW_SCORE = 0x3,
|
|
19
19
|
/** The peer has been banned, will be received whenever a peer is banned */
|
|
@@ -48,8 +48,8 @@ export function prettyGoodbyeReason(reason: GoodByeReason): string {
|
|
|
48
48
|
switch (reason) {
|
|
49
49
|
case GoodByeReason.SHUTDOWN:
|
|
50
50
|
return 'shutdown';
|
|
51
|
-
case GoodByeReason.
|
|
52
|
-
return '
|
|
51
|
+
case GoodByeReason.MAX_PEERS:
|
|
52
|
+
return 'max_peers';
|
|
53
53
|
case GoodByeReason.LOW_SCORE:
|
|
54
54
|
return 'low_score';
|
|
55
55
|
case GoodByeReason.BANNED:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TxHash } from '@aztec/
|
|
1
|
+
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
2
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { PeerId } from '@libp2p/interface';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import type { MemPools } from '../../../mem_pools/interface.js';
|
|
7
|
+
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* We want to keep the logic of the req resp handler in this file, but we do not have a reference to the mempools here
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* Rationale is that if it was good enough for them, then it should be good enough for us.
|
|
4
4
|
* https://github.com/ChainSafe/lodestar
|
|
5
5
|
*/
|
|
6
|
-
import { PeerErrorSeverity } from '@aztec/
|
|
6
|
+
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import type { PeerId } from '@libp2p/interface';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import type { PeerScoring } from '../../peer-manager/peer_scoring.js';
|
|
11
|
+
import type { ReqRespSubProtocol, ReqRespSubProtocolRateLimits } from '../interface.js';
|
|
12
12
|
import { DEFAULT_RATE_LIMITS } from './rate_limits.js';
|
|
13
13
|
|
|
14
14
|
// Check for disconnected peers every 10 minutes
|
|
@@ -72,10 +72,21 @@ interface PeerRateLimiter {
|
|
|
72
72
|
lastAccess: number;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
enum RateLimitStatus {
|
|
76
|
-
Allowed,
|
|
75
|
+
export enum RateLimitStatus {
|
|
77
76
|
DeniedGlobal,
|
|
78
77
|
DeniedPeer,
|
|
78
|
+
Allowed, // Note: allowed last to prevent enum evaluating to 0 for success
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function prettyPrintRateLimitStatus(status: RateLimitStatus) {
|
|
82
|
+
switch (status) {
|
|
83
|
+
case RateLimitStatus.DeniedGlobal:
|
|
84
|
+
return 'DeniedGlobal';
|
|
85
|
+
case RateLimitStatus.DeniedPeer:
|
|
86
|
+
return 'DeniedPeer';
|
|
87
|
+
case RateLimitStatus.Allowed:
|
|
88
|
+
return 'Allowed';
|
|
89
|
+
}
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
/**
|
|
@@ -191,24 +202,17 @@ export class RequestResponseRateLimiter {
|
|
|
191
202
|
}, CHECK_DISCONNECTED_PEERS_INTERVAL_MS);
|
|
192
203
|
}
|
|
193
204
|
|
|
194
|
-
allow(subProtocol: ReqRespSubProtocol, peerId: PeerId):
|
|
205
|
+
allow(subProtocol: ReqRespSubProtocol, peerId: PeerId): RateLimitStatus {
|
|
195
206
|
const limiter = this.subProtocolRateLimiters.get(subProtocol);
|
|
196
207
|
if (!limiter) {
|
|
197
|
-
return
|
|
208
|
+
return RateLimitStatus.Allowed;
|
|
198
209
|
}
|
|
199
210
|
const rateLimitStatus = limiter.allow(peerId);
|
|
200
211
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// Hitting a peer specific limit, we should lightly penalise the peer
|
|
204
|
-
this.peerScoring.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
205
|
-
return false;
|
|
206
|
-
case RateLimitStatus.DeniedGlobal:
|
|
207
|
-
// Hitting a global limit, we should not penalise the peer
|
|
208
|
-
return false;
|
|
209
|
-
default:
|
|
210
|
-
return true;
|
|
212
|
+
if (rateLimitStatus === RateLimitStatus.DeniedPeer) {
|
|
213
|
+
this.peerScoring.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
211
214
|
}
|
|
215
|
+
return rateLimitStatus;
|
|
212
216
|
}
|
|
213
217
|
|
|
214
218
|
cleanupInactivePeers() {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @attribution: lodestar impl for inspiration
|
|
2
|
-
import { PeerErrorSeverity } from '@aztec/circuit-types';
|
|
3
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
3
|
import { executeTimeout } from '@aztec/foundation/timer';
|
|
4
|
+
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
5
5
|
import { Attributes, type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import type { IncomingStreamData, PeerId, Stream } from '@libp2p/interface';
|
|
8
8
|
import { pipe } from 'it-pipe';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import type { Libp2p } from 'libp2p';
|
|
10
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
CollectiveReqRespTimeoutError,
|
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
InvalidResponseError,
|
|
16
16
|
} from '../../errors/reqresp.error.js';
|
|
17
17
|
import { SnappyTransform } from '../encoding.js';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import type { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
19
|
+
import type { P2PReqRespConfig } from './config.js';
|
|
20
20
|
import { BatchConnectionSampler } from './connection-sampler/batch_connection_sampler.js';
|
|
21
21
|
import { ConnectionSampler } from './connection-sampler/connection_sampler.js';
|
|
22
22
|
import {
|
|
@@ -30,7 +30,11 @@ import {
|
|
|
30
30
|
subProtocolMap,
|
|
31
31
|
} from './interface.js';
|
|
32
32
|
import { ReqRespMetrics } from './metrics.js';
|
|
33
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
RateLimitStatus,
|
|
35
|
+
RequestResponseRateLimiter,
|
|
36
|
+
prettyPrintRateLimitStatus,
|
|
37
|
+
} from './rate-limiter/rate_limiter.js';
|
|
34
38
|
import { ReqRespStatus, ReqRespStatusError, parseStatusChunk, prettyPrintReqRespStatus } from './status.js';
|
|
35
39
|
|
|
36
40
|
/**
|
|
@@ -589,8 +593,13 @@ export class ReqResp {
|
|
|
589
593
|
|
|
590
594
|
try {
|
|
591
595
|
// Store a reference to from this for the async generator
|
|
592
|
-
|
|
593
|
-
|
|
596
|
+
const rateLimitStatus = this.rateLimiter.allow(protocol, connection.remotePeer);
|
|
597
|
+
if (rateLimitStatus != RateLimitStatus.Allowed) {
|
|
598
|
+
this.logger.warn(
|
|
599
|
+
`Rate limit exceeded ${prettyPrintRateLimitStatus(rateLimitStatus)} for ${protocol} from ${
|
|
600
|
+
connection.remotePeer
|
|
601
|
+
}`,
|
|
602
|
+
);
|
|
594
603
|
|
|
595
604
|
throw new ReqRespStatusError(ReqRespStatus.RATE_LIMIT_EXCEEDED);
|
|
596
605
|
}
|
|
@@ -598,8 +607,6 @@ export class ReqResp {
|
|
|
598
607
|
const handler = this.subProtocolHandlers[protocol];
|
|
599
608
|
const transform = this.snappyTransform;
|
|
600
609
|
|
|
601
|
-
this.logger.info(`Stream handler for ${protocol}`);
|
|
602
|
-
|
|
603
610
|
await pipe(
|
|
604
611
|
stream,
|
|
605
612
|
async function* (source: any) {
|
package/src/services/service.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
2
|
+
import type { BlockAttestation, BlockProposal, Gossipable } from '@aztec/stdlib/p2p';
|
|
2
3
|
|
|
3
4
|
import type { ENR } from '@chainsafe/enr';
|
|
4
5
|
import type { PeerId } from '@libp2p/interface';
|
|
5
6
|
import type EventEmitter from 'events';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import type { ReqRespSubProtocol, SubProtocolMap } from './reqresp/interface.js';
|
|
8
9
|
|
|
9
10
|
export enum PeerDiscoveryState {
|
|
10
11
|
RUNNING = 'running',
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { MockL2BlockSource } from '@aztec/archiver/test';
|
|
2
|
-
import {
|
|
3
|
-
import { type EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
4
|
+
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
6
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
+
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
|
+
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
7
8
|
|
|
8
9
|
import { createP2PClient } from '../client/index.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import type { P2PClient } from '../client/p2p_client.js';
|
|
11
|
+
import type { P2PConfig } from '../config.js';
|
|
12
|
+
import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
13
|
+
import type { TxPool } from '../mem_pools/tx_pool/index.js';
|
|
13
14
|
import { generatePeerIdPrivateKeys } from '../test-helpers/generate-peer-id-private-keys.js';
|
|
14
15
|
import { getPorts } from './get-ports.js';
|
|
15
16
|
import { makeEnrs } from './make-enrs.js';
|
|
@@ -65,6 +66,7 @@ export async function makeTestP2PClient(
|
|
|
65
66
|
bootstrapNodes: peers,
|
|
66
67
|
peerCheckIntervalMS: 1000,
|
|
67
68
|
maxPeerCount: 10,
|
|
69
|
+
bootstrapNodesAsFullPeers: true,
|
|
68
70
|
...p2pConfigOverrides,
|
|
69
71
|
} as P2PConfig & DataStoreConfig;
|
|
70
72
|
|
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ClientProtocolCircuitVerifier,
|
|
3
|
-
type L2BlockSource,
|
|
4
|
-
type P2PClientType,
|
|
5
|
-
type Tx,
|
|
6
|
-
type WorldStateSynchronizer,
|
|
7
|
-
} from '@aztec/circuit-types';
|
|
8
|
-
import { type ChainConfig, emptyChainConfig } from '@aztec/circuit-types/config';
|
|
9
|
-
import { type EpochCache } from '@aztec/epoch-cache';
|
|
1
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
10
2
|
import { timesParallel } from '@aztec/foundation/collection';
|
|
11
|
-
import {
|
|
3
|
+
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
12
4
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
6
|
+
import { type ChainConfig, emptyChainConfig } from '@aztec/stdlib/config';
|
|
7
|
+
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
8
|
+
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
9
|
+
import type { Tx } from '@aztec/stdlib/tx';
|
|
13
10
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
11
|
|
|
12
|
+
import { SignableENR } from '@chainsafe/enr';
|
|
15
13
|
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
16
14
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
17
15
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
18
16
|
import { bootstrap } from '@libp2p/bootstrap';
|
|
19
17
|
import { identify } from '@libp2p/identify';
|
|
20
|
-
import {
|
|
18
|
+
import type { PeerId } from '@libp2p/interface';
|
|
21
19
|
import { createSecp256k1PeerId } from '@libp2p/peer-id-factory';
|
|
22
20
|
import { tcp } from '@libp2p/tcp';
|
|
21
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
23
22
|
import getPort from 'get-port';
|
|
24
23
|
import { type Libp2p, type Libp2pOptions, createLibp2p } from 'libp2p';
|
|
25
24
|
|
|
26
25
|
import { BootstrapNode } from '../bootstrap/bootstrap.js';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
26
|
+
import type { BootnodeConfig, P2PConfig } from '../config.js';
|
|
27
|
+
import type { MemPools } from '../mem_pools/interface.js';
|
|
29
28
|
import { DiscV5Service } from '../services/discv5/discV5_service.js';
|
|
30
29
|
import { LibP2PService } from '../services/libp2p/libp2p_service.js';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
30
|
+
import type { PeerScoring } from '../services/peer-manager/peer_scoring.js';
|
|
31
|
+
import type { P2PReqRespConfig } from '../services/reqresp/config.js';
|
|
33
32
|
import {
|
|
34
33
|
ReqRespSubProtocol,
|
|
35
34
|
type ReqRespSubProtocolHandlers,
|
|
@@ -38,7 +37,7 @@ import {
|
|
|
38
37
|
} from '../services/reqresp/interface.js';
|
|
39
38
|
import { pingHandler, statusHandler } from '../services/reqresp/protocols/index.js';
|
|
40
39
|
import { ReqResp } from '../services/reqresp/reqresp.js';
|
|
41
|
-
import { type PubSubLibp2p } from '../util.js';
|
|
40
|
+
import { type PubSubLibp2p, convertToMultiaddr, createLibP2PPeerIdFromPrivateKey } from '../util.js';
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
43
|
* Creates a libp2p node, pre configured.
|
|
@@ -235,13 +234,13 @@ export class AlwaysFalseCircuitVerifier implements ClientProtocolCircuitVerifier
|
|
|
235
234
|
// Bootnodes
|
|
236
235
|
export function createBootstrapNodeConfig(privateKey: string, port: number, chainConfig: ChainConfig): BootnodeConfig {
|
|
237
236
|
return {
|
|
237
|
+
l1ChainId: chainConfig.l1ChainId,
|
|
238
238
|
udpListenAddress: `0.0.0.0:${port}`,
|
|
239
239
|
udpAnnounceAddress: `127.0.0.1:${port}`,
|
|
240
240
|
peerIdPrivateKey: privateKey,
|
|
241
|
-
maxPeerCount: 100,
|
|
242
241
|
dataDirectory: undefined,
|
|
243
242
|
dataStoreMapSizeKB: 0,
|
|
244
|
-
|
|
243
|
+
bootstrapNodes: [],
|
|
245
244
|
};
|
|
246
245
|
}
|
|
247
246
|
|
|
@@ -255,6 +254,21 @@ export function createBootstrapNodeFromPrivateKey(
|
|
|
255
254
|
return startBootstrapNode(config, telemetry);
|
|
256
255
|
}
|
|
257
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Create a bootstrap node ENR
|
|
259
|
+
* @param privateKey - the private key of the bootstrap node
|
|
260
|
+
* @param port - the port of the bootstrap node
|
|
261
|
+
* @returns the bootstrap node ENR
|
|
262
|
+
*/
|
|
263
|
+
export async function getBootstrapNodeEnr(privateKey: string, port: number) {
|
|
264
|
+
const peerId = await createLibP2PPeerIdFromPrivateKey(privateKey);
|
|
265
|
+
const enr = SignableENR.createFromPeerId(peerId);
|
|
266
|
+
const listenAddrUdp = multiaddr(convertToMultiaddr(`127.0.0.1:${port}`, 'udp'));
|
|
267
|
+
enr.setLocationMultiaddr(listenAddrUdp);
|
|
268
|
+
|
|
269
|
+
return enr;
|
|
270
|
+
}
|
|
271
|
+
|
|
258
272
|
export async function createBootstrapNode(
|
|
259
273
|
port: number,
|
|
260
274
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
@@ -4,18 +4,22 @@
|
|
|
4
4
|
* Used when running testbench commands
|
|
5
5
|
*/
|
|
6
6
|
import { MockL2BlockSource } from '@aztec/archiver/test';
|
|
7
|
-
import {
|
|
8
|
-
import { type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
9
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
11
10
|
import { sleep } from '@aztec/foundation/sleep';
|
|
12
|
-
import {
|
|
11
|
+
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
13
12
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
13
|
+
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
14
|
+
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
15
|
+
import { Tx, TxStatus } from '@aztec/stdlib/tx';
|
|
14
16
|
|
|
15
|
-
import {
|
|
17
|
+
import type { Message, PeerId } from '@libp2p/interface';
|
|
18
|
+
|
|
19
|
+
import type { P2PConfig } from '../config.js';
|
|
16
20
|
import { createP2PClient } from '../index.js';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
21
|
+
import type { AttestationPool } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
22
|
+
import type { TxPool } from '../mem_pools/tx_pool/index.js';
|
|
19
23
|
import { AlwaysTrueCircuitVerifier } from '../test-helpers/reqresp-nodes.js';
|
|
20
24
|
|
|
21
25
|
// Simple mock implementation
|
|
@@ -101,12 +105,15 @@ process.on('message', async msg => {
|
|
|
101
105
|
|
|
102
106
|
// Create spy for gossip messages
|
|
103
107
|
let gossipMessageCount = 0;
|
|
104
|
-
(client as any).p2pService.handleNewGossipMessage = (
|
|
108
|
+
(client as any).p2pService.handleNewGossipMessage = (msg: Message, msgId: string, source: PeerId) => {
|
|
105
109
|
gossipMessageCount++;
|
|
106
|
-
process.send!({
|
|
110
|
+
process.send!({
|
|
111
|
+
type: 'GOSSIP_RECEIVED',
|
|
112
|
+
count: gossipMessageCount,
|
|
113
|
+
});
|
|
107
114
|
return (client as any).p2pService.constructor.prototype.handleNewGossipMessage.apply(
|
|
108
115
|
(client as any).p2pService,
|
|
109
|
-
|
|
116
|
+
[msg, msgId, source],
|
|
110
117
|
);
|
|
111
118
|
};
|
|
112
119
|
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Parse Log File
|
|
2
|
+
// 1. Determine when a message was sent from the Sent Message log
|
|
3
|
+
// 2. Parse all Received Tx logs, extracting the timestamp and peer ID
|
|
4
|
+
// 3. Compute the delay for each peer relative to the timestamp of the sent message
|
|
5
|
+
// 4. Print the delays
|
|
6
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
|
|
10
|
+
const logger = createLogger('parse_log_file');
|
|
11
|
+
|
|
12
|
+
interface LogEvent {
|
|
13
|
+
timestamp: number; // in milliseconds (from start of log)
|
|
14
|
+
peerId: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface BenchmarkResult {
|
|
18
|
+
delays: {
|
|
19
|
+
peerId: string;
|
|
20
|
+
delay: number;
|
|
21
|
+
}[];
|
|
22
|
+
stats: {
|
|
23
|
+
numberReceived: number;
|
|
24
|
+
minDelay: number;
|
|
25
|
+
maxDelay: number;
|
|
26
|
+
averageDelay: number;
|
|
27
|
+
medianDelay: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getTimestamp(line: string): number | null {
|
|
32
|
+
const timestampMatch = line.match(/"time":(\d+)/);
|
|
33
|
+
if (!timestampMatch) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return parseInt(timestampMatch[1], 10);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Parses a single log line. If the line contains an "rpc.from" event,
|
|
41
|
+
* it extracts the timestamp and the peer ID.
|
|
42
|
+
*/
|
|
43
|
+
function parseReceivedTx(line: string): LogEvent | null {
|
|
44
|
+
if (!line.includes('Received tx')) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Extract timestamp from the line: e.g. {"time":1740142435845}
|
|
49
|
+
const timestamp = getTimestamp(line);
|
|
50
|
+
if (!timestamp) {
|
|
51
|
+
logger.error('No timestamp found in received tx log');
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// TODO: this is not correct - it is just the tx hash for now
|
|
56
|
+
// Extract the peer ID after "Received tx"
|
|
57
|
+
const peerIdMatch = line.match(/p2p:(\d+):/);
|
|
58
|
+
if (!peerIdMatch) {
|
|
59
|
+
logger.error('No peer Number found in received tx log');
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const peerId = peerIdMatch[1];
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
timestamp,
|
|
66
|
+
peerId,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseSentMessage(line: string): number | null {
|
|
71
|
+
if (!line.includes('Sent message')) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const timestamp = getTimestamp(line);
|
|
76
|
+
if (!timestamp) {
|
|
77
|
+
logger.error('No timestamp found in sent message log');
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return timestamp;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Processes the given log file, extracts all rpc.from events, computes the
|
|
86
|
+
* propagation delay for each peer relative to the earliest event, and prints
|
|
87
|
+
* some benchmark statistics.
|
|
88
|
+
*/
|
|
89
|
+
function processLogFile(logFilePath: string, outputJsonPath?: string) {
|
|
90
|
+
const content = fs.readFileSync(logFilePath, 'utf-8');
|
|
91
|
+
const lines = content.split('\n');
|
|
92
|
+
const events: LogEvent[] = [];
|
|
93
|
+
let t0 = 0;
|
|
94
|
+
|
|
95
|
+
// We begin our search as soon as we see the Sent message log
|
|
96
|
+
let messageSent = false;
|
|
97
|
+
for (const line of lines) {
|
|
98
|
+
// Look for Sent message log
|
|
99
|
+
if (line.includes('Sent message')) {
|
|
100
|
+
messageSent = true;
|
|
101
|
+
t0 = parseSentMessage(line)!;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!messageSent) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// Once we see the sent message log, we begin parsing Received tx logs
|
|
108
|
+
const event = parseReceivedTx(line);
|
|
109
|
+
if (event) {
|
|
110
|
+
events.push(event);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (events.length === 0) {
|
|
115
|
+
logger.error('No message received events found in log file.');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Sort events by timestamp (ascending)
|
|
120
|
+
events.sort((a, b) => a.timestamp - b.timestamp);
|
|
121
|
+
|
|
122
|
+
// Compute delay for each event relative to t0
|
|
123
|
+
const numberReceived = events.length;
|
|
124
|
+
const delays = events.map(e => ({
|
|
125
|
+
peerId: e.peerId,
|
|
126
|
+
delay: e.timestamp - t0,
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
logger.info('Propagation delays (in ms) per peer:');
|
|
130
|
+
for (const d of delays) {
|
|
131
|
+
logger.info(`${d.peerId}: ${d.delay} ms`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Compute basic statistics
|
|
135
|
+
const delayValues = delays.map(d => d.delay);
|
|
136
|
+
const minDelay = Math.min(...delayValues);
|
|
137
|
+
const maxDelay = Math.max(...delayValues);
|
|
138
|
+
const sumDelay = delayValues.reduce((sum, val) => sum + val, 0);
|
|
139
|
+
const avgDelay = sumDelay / delayValues.length;
|
|
140
|
+
const sortedDelays = delayValues.slice().sort((a, b) => a - b);
|
|
141
|
+
const medianDelay = sortedDelays[Math.floor(sortedDelays.length / 2)];
|
|
142
|
+
|
|
143
|
+
logger.info('\nBenchmark Statistics:');
|
|
144
|
+
logger.info(`Number of messages received: ${numberReceived}`);
|
|
145
|
+
logger.info(`Min delay: ${minDelay} ms`);
|
|
146
|
+
logger.info(`Max delay: ${maxDelay} ms`);
|
|
147
|
+
logger.info(`Average delay: ${avgDelay.toFixed(2)} ms`);
|
|
148
|
+
logger.info(`Median delay: ${medianDelay} ms`);
|
|
149
|
+
|
|
150
|
+
// If output JSON path is provided, write results to file
|
|
151
|
+
if (outputJsonPath) {
|
|
152
|
+
const result: BenchmarkResult = {
|
|
153
|
+
delays,
|
|
154
|
+
stats: {
|
|
155
|
+
numberReceived,
|
|
156
|
+
minDelay,
|
|
157
|
+
maxDelay,
|
|
158
|
+
averageDelay: Number(avgDelay.toFixed(2)),
|
|
159
|
+
medianDelay,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
fs.writeFileSync(outputJsonPath, JSON.stringify(result, null, 2));
|
|
164
|
+
logger.info(`\nResults written to ${outputJsonPath}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Get the log file path and optional output JSON path from command-line arguments
|
|
169
|
+
const [logFilePath, outputJsonPath] = process.argv.slice(2);
|
|
170
|
+
if (!logFilePath) {
|
|
171
|
+
logger.error('Usage: ts-node parse_log_file.ts <logFilePath> [outputJsonPath]');
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
processLogFile(logFilePath, outputJsonPath);
|