@aztec/p2p 0.0.1-commit.f5d02921e → 0.0.1-commit.f650c0a5c
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/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 +11 -9
- package/dest/services/libp2p/libp2p_service.d.ts +2 -15
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +4 -53
- package/dest/services/peer-manager/peer_scoring.d.ts +3 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +4 -0
- package/dest/services/reqresp/interface.d.ts +1 -9
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +0 -11
- 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 +0 -1
- package/dest/services/reqresp/protocols/index.d.ts +1 -2
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +0 -1
- package/dest/services/reqresp/protocols/tx.d.ts +1 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +1 -3
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +0 -10
- package/dest/services/reqresp/reqresp.js +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts +1 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +0 -2
- package/dest/test-helpers/testbench-utils.d.ts +1 -1
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +1 -0
- package/dest/testbench/p2p_client_testbench_worker.js +22 -0
- package/dest/testbench/worker_client_manager.d.ts +8 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +49 -0
- package/package.json +14 -14
- package/src/msg_validators/tx_validator/gas_validator.ts +25 -9
- package/src/services/libp2p/libp2p_service.ts +1 -53
- package/src/services/peer-manager/peer_scoring.ts +6 -0
- package/src/services/reqresp/interface.ts +0 -11
- package/src/services/reqresp/metrics.ts +0 -1
- package/src/services/reqresp/protocols/index.ts +0 -1
- package/src/services/reqresp/protocols/tx.ts +1 -3
- package/src/services/reqresp/rate-limiter/rate_limits.ts +0 -10
- package/src/services/reqresp/reqresp.ts +1 -1
- package/src/test-helpers/reqresp-nodes.ts +0 -2
- package/src/test-helpers/testbench-utils.ts +1 -0
- package/src/testbench/p2p_client_testbench_worker.ts +27 -0
- package/src/testbench/worker_client_manager.ts +55 -0
- package/dest/services/reqresp/protocols/block.d.ts +0 -9
- package/dest/services/reqresp/protocols/block.d.ts.map +0 -1
- package/dest/services/reqresp/protocols/block.js +0 -32
- package/src/services/reqresp/protocols/block.ts +0 -37
|
@@ -187,7 +187,6 @@ export const MOCK_SUB_PROTOCOL_HANDLERS: ReqRespSubProtocolHandlers = {
|
|
|
187
187
|
[ReqRespSubProtocol.STATUS]: (_msg: any) => Promise.resolve(Buffer.from('status')),
|
|
188
188
|
[ReqRespSubProtocol.TX]: (_msg: any) => Promise.resolve(Buffer.from('tx')),
|
|
189
189
|
[ReqRespSubProtocol.GOODBYE]: (_msg: any) => Promise.resolve(Buffer.from('goodbye')),
|
|
190
|
-
[ReqRespSubProtocol.BLOCK]: (_msg: any) => Promise.resolve(Buffer.from('block')),
|
|
191
190
|
[ReqRespSubProtocol.AUTH]: (_msg: any) => Promise.resolve(Buffer.from('auth')),
|
|
192
191
|
[ReqRespSubProtocol.BLOCK_TXS]: (_msg: any) => Promise.resolve(Buffer.from('block_txs')),
|
|
193
192
|
};
|
|
@@ -199,7 +198,6 @@ export const MOCK_SUB_PROTOCOL_VALIDATORS: ReqRespSubProtocolValidators = {
|
|
|
199
198
|
[ReqRespSubProtocol.STATUS]: noopValidator,
|
|
200
199
|
[ReqRespSubProtocol.TX]: noopValidator,
|
|
201
200
|
[ReqRespSubProtocol.GOODBYE]: noopValidator,
|
|
202
|
-
[ReqRespSubProtocol.BLOCK]: noopValidator,
|
|
203
201
|
[ReqRespSubProtocol.AUTH]: noopValidator,
|
|
204
202
|
[ReqRespSubProtocol.BLOCK_TXS]: noopValidator,
|
|
205
203
|
};
|
|
@@ -287,6 +287,7 @@ export function createMockEpochCache(): EpochCacheInterface {
|
|
|
287
287
|
nowMs: 0n,
|
|
288
288
|
}),
|
|
289
289
|
isProposerPipeliningEnabled: () => false,
|
|
290
|
+
pipeliningOffset: () => 0,
|
|
290
291
|
computeProposerIndex: () => 0n,
|
|
291
292
|
getCurrentAndNextSlot: () => ({ currentSlot: SlotNumber.ZERO, nextSlot: SlotNumber.ZERO }),
|
|
292
293
|
getTargetAndNextSlot: () => ({ targetSlot: SlotNumber.ZERO, nextSlot: SlotNumber.ZERO }),
|
|
@@ -204,6 +204,25 @@ function installUnlimitedRateLimits(client: P2PClient): void {
|
|
|
204
204
|
rateLimiter.allow = () => RateLimitStatus.Allowed;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
/** Resets peer scores to prevent cross-case contamination in benchmarks. */
|
|
208
|
+
function resetPeerScores(client: P2PClient): void {
|
|
209
|
+
const peerManager = (client as any).p2pService.peerManager;
|
|
210
|
+
const peerScoring = peerManager?.peerScoring;
|
|
211
|
+
if (peerScoring?.resetAllScores) {
|
|
212
|
+
peerScoring.resetAllScores();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Returns the number of connected peers for connectivity checks. */
|
|
217
|
+
function getConnectedPeerCount(client: P2PClient): number {
|
|
218
|
+
const p2pService = (client as any).p2pService;
|
|
219
|
+
const connectionSampler = p2pService?.reqresp?.getConnectionSampler?.();
|
|
220
|
+
if (connectionSampler?.getPeerListSortedByConnectionCountAsc) {
|
|
221
|
+
return connectionSampler.getPeerListSortedByConnectionCountAsc().length;
|
|
222
|
+
}
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
207
226
|
async function runAggregatorBenchmark(
|
|
208
227
|
client: P2PClient,
|
|
209
228
|
blockProposal: BlockProposal,
|
|
@@ -452,6 +471,13 @@ process.on('message', async msg => {
|
|
|
452
471
|
}
|
|
453
472
|
break;
|
|
454
473
|
|
|
474
|
+
case 'GET_PEER_COUNT':
|
|
475
|
+
process.send!({
|
|
476
|
+
type: 'PEER_COUNT',
|
|
477
|
+
count: workerClient ? getConnectedPeerCount(workerClient) : 0,
|
|
478
|
+
});
|
|
479
|
+
break;
|
|
480
|
+
|
|
455
481
|
case 'BENCH_REQRESP': {
|
|
456
482
|
const benchCmd = cmd as BenchReqRespCommand;
|
|
457
483
|
if (!workerClient || !workerTxPool || !workerAttestationPool || !workerConfig || !workerLogger) {
|
|
@@ -468,6 +494,7 @@ process.on('message', async msg => {
|
|
|
468
494
|
// Reset state before each benchmark run to avoid cross-run contamination
|
|
469
495
|
workerTxPool.resetState();
|
|
470
496
|
workerAttestationPool.resetState();
|
|
497
|
+
resetPeerScores(workerClient);
|
|
471
498
|
|
|
472
499
|
installUnlimitedRateLimits(workerClient);
|
|
473
500
|
|
|
@@ -424,6 +424,61 @@ class WorkerClientManager {
|
|
|
424
424
|
this.logger.info('All worker processes cleaned up');
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
/**
|
|
428
|
+
* Checks that the aggregator (client 0) has sufficient peer connections before running a benchmark.
|
|
429
|
+
* This prevents benchmark cases from starting with degraded connectivity after a previous case
|
|
430
|
+
* caused connection failures.
|
|
431
|
+
*/
|
|
432
|
+
async waitForConnectivity(minPeers: number, timeoutMs: number = 15_000): Promise<number> {
|
|
433
|
+
const waitInterval = 1000;
|
|
434
|
+
let waited = 0;
|
|
435
|
+
|
|
436
|
+
while (waited < timeoutMs) {
|
|
437
|
+
const count = await this.getPeerCount(0, 5000);
|
|
438
|
+
if (count >= minPeers) {
|
|
439
|
+
this.logger.info(`Connectivity check passed: ${count}/${minPeers} peers connected`);
|
|
440
|
+
return count;
|
|
441
|
+
}
|
|
442
|
+
this.logger.debug(`Waiting for connectivity: ${count}/${minPeers} (waited ${waited}ms)`);
|
|
443
|
+
await sleep(waitInterval);
|
|
444
|
+
waited += waitInterval;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const finalCount = await this.getPeerCount(0, 5000);
|
|
448
|
+
this.logger.warn(`Connectivity check: only ${finalCount}/${minPeers} peers after ${timeoutMs}ms`);
|
|
449
|
+
return finalCount;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private getPeerCount(clientIndex: number, timeoutMs: number): Promise<number> {
|
|
453
|
+
return new Promise<number>(resolve => {
|
|
454
|
+
let resolved = false;
|
|
455
|
+
|
|
456
|
+
const handler = (msg: any) => {
|
|
457
|
+
if (resolved) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (msg.type === 'PEER_COUNT') {
|
|
461
|
+
resolved = true;
|
|
462
|
+
clearTimeout(timeout);
|
|
463
|
+
this.processes[clientIndex].off('message', handler);
|
|
464
|
+
resolve(msg.count as number);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const timeout = setTimeout(() => {
|
|
469
|
+
if (resolved) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
resolved = true;
|
|
473
|
+
this.processes[clientIndex].off('message', handler);
|
|
474
|
+
resolve(0);
|
|
475
|
+
}, timeoutMs);
|
|
476
|
+
|
|
477
|
+
this.processes[clientIndex].on('message', handler);
|
|
478
|
+
this.processes[clientIndex].send({ type: 'GET_PEER_COUNT' });
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
427
482
|
/**
|
|
428
483
|
* Run a req/resp benchmark across all worker clients.
|
|
429
484
|
*
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
2
|
-
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
3
|
-
/**
|
|
4
|
-
* Handler for L2 Block requests
|
|
5
|
-
* @param l2BlockSource - source for L2 blocks
|
|
6
|
-
* @returns the Block request handler
|
|
7
|
-
* */
|
|
8
|
-
export declare function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubProtocolHandler;
|
|
9
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2suZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9zZXJ2aWNlcy9yZXFyZXNwL3Byb3RvY29scy9ibG9jay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUl6RCxPQUFPLEtBQUssRUFBRSx5QkFBeUIsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBR2pFOzs7O0tBSUs7QUFDTCx3QkFBZ0IsbUJBQW1CLENBQUMsYUFBYSxFQUFFLGFBQWEsR0FBRyx5QkFBeUIsQ0FzQjNGIn0=
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/services/reqresp/protocols/block.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGjE;;;;KAIK;AACL,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,yBAAyB,CAsB3F"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
4
|
-
/**
|
|
5
|
-
* Handler for L2 Block requests
|
|
6
|
-
* @param l2BlockSource - source for L2 blocks
|
|
7
|
-
* @returns the Block request handler
|
|
8
|
-
* */ export function reqRespBlockHandler(l2BlockSource) {
|
|
9
|
-
/**
|
|
10
|
-
* @param peerId - the peer ID of the requester
|
|
11
|
-
* @param msg - the block request message, which is expected to contain valid block number as a Buffer
|
|
12
|
-
* @returns a Buffer containing the requested block data, or an empty Buffer if the block is not found
|
|
13
|
-
* @throws ReqRespStatusError if the input msg is not a valid block number
|
|
14
|
-
* */ return async (_peerId, msg)=>{
|
|
15
|
-
let blockNumber;
|
|
16
|
-
try {
|
|
17
|
-
blockNumber = Fr.fromBuffer(msg);
|
|
18
|
-
} catch (err) {
|
|
19
|
-
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, {
|
|
20
|
-
cause: err
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
const foundBlock = await l2BlockSource.getBlock(BlockNumber(Number(blockNumber)));
|
|
25
|
-
return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
|
|
26
|
-
} catch (err) {
|
|
27
|
-
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, {
|
|
28
|
-
cause: err
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
4
|
-
|
|
5
|
-
import type { PeerId } from '@libp2p/interface';
|
|
6
|
-
|
|
7
|
-
import type { ReqRespSubProtocolHandler } from '../interface.js';
|
|
8
|
-
import { ReqRespStatus, ReqRespStatusError } from '../status.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Handler for L2 Block requests
|
|
12
|
-
* @param l2BlockSource - source for L2 blocks
|
|
13
|
-
* @returns the Block request handler
|
|
14
|
-
* */
|
|
15
|
-
export function reqRespBlockHandler(l2BlockSource: L2BlockSource): ReqRespSubProtocolHandler {
|
|
16
|
-
/**
|
|
17
|
-
* @param peerId - the peer ID of the requester
|
|
18
|
-
* @param msg - the block request message, which is expected to contain valid block number as a Buffer
|
|
19
|
-
* @returns a Buffer containing the requested block data, or an empty Buffer if the block is not found
|
|
20
|
-
* @throws ReqRespStatusError if the input msg is not a valid block number
|
|
21
|
-
* */
|
|
22
|
-
return async (_peerId: PeerId, msg: Buffer) => {
|
|
23
|
-
let blockNumber: Fr;
|
|
24
|
-
try {
|
|
25
|
-
blockNumber = Fr.fromBuffer(msg);
|
|
26
|
-
} catch (err: any) {
|
|
27
|
-
throw new ReqRespStatusError(ReqRespStatus.BADLY_FORMED_REQUEST, { cause: err });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const foundBlock = await l2BlockSource.getBlock(BlockNumber(Number(blockNumber)));
|
|
32
|
-
return foundBlock ? foundBlock.toBuffer() : Buffer.alloc(0);
|
|
33
|
-
} catch (err: any) {
|
|
34
|
-
throw new ReqRespStatusError(ReqRespStatus.INTERNAL_ERROR, { cause: err });
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|