@aztec/p2p 0.0.1-commit.96dac018d → 0.0.1-commit.993d52e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/factory.d.ts +4 -5
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +6 -6
- package/dest/client/interface.d.ts +4 -4
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +4 -4
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +1 -1
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -2
- package/dest/config.d.ts +10 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +11 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +2 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +3 -3
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +30 -7
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +62 -16
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +9 -10
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +38 -30
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +3 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +10 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +2 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +166 -0
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -7
- package/dest/services/libp2p/libp2p_service.d.ts +6 -7
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +11 -12
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +37 -14
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +11 -17
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +15 -49
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +2 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/testbench/p2p_client_testbench_worker.js +5 -5
- package/package.json +14 -14
- package/src/client/factory.ts +9 -14
- package/src/client/interface.ts +3 -9
- package/src/client/p2p_client.ts +2 -12
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -2
- package/src/config.ts +20 -2
- package/src/mem_pools/tx_pool_v2/README.md +9 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +3 -3
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +89 -17
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +11 -11
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +43 -27
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +1 -1
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +1 -1
- package/src/msg_validators/proposal_validator/proposal_validator.ts +15 -1
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +144 -1
- package/src/services/encoding.ts +5 -6
- package/src/services/libp2p/libp2p_service.ts +10 -12
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +42 -14
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +24 -63
- package/src/test-helpers/make-test-p2p-clients.ts +0 -2
- package/src/test-helpers/mock-pubsub.ts +3 -6
- package/src/test-helpers/reqresp-nodes.ts +2 -5
- package/src/testbench/p2p_client_testbench_worker.ts +2 -6
|
@@ -16,13 +16,12 @@ import {
|
|
|
16
16
|
CheckpointProposal,
|
|
17
17
|
type CheckpointProposalCore,
|
|
18
18
|
type Gossipable,
|
|
19
|
-
P2PClientType,
|
|
20
19
|
P2PMessage,
|
|
21
20
|
type ValidationResult as P2PValidationResult,
|
|
22
21
|
PeerErrorSeverity,
|
|
23
22
|
TopicType,
|
|
24
23
|
createTopicString,
|
|
25
|
-
|
|
24
|
+
getTopicsForConfig,
|
|
26
25
|
metricsTopicStrToLabels,
|
|
27
26
|
} from '@aztec/stdlib/p2p';
|
|
28
27
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
@@ -135,7 +134,7 @@ type ReceivedMessageValidationResult<T, M = undefined> =
|
|
|
135
134
|
/**
|
|
136
135
|
* Lib P2P implementation of the P2PService interface.
|
|
137
136
|
*/
|
|
138
|
-
export class LibP2PService
|
|
137
|
+
export class LibP2PService extends WithTracer implements P2PService {
|
|
139
138
|
private discoveryRunningPromise?: RunningPromise;
|
|
140
139
|
private msgIdSeenValidators: Record<TopicType, MessageSeenValidator> = {} as Record<TopicType, MessageSeenValidator>;
|
|
141
140
|
|
|
@@ -182,7 +181,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
182
181
|
protected logger: Logger;
|
|
183
182
|
|
|
184
183
|
constructor(
|
|
185
|
-
private clientType: T,
|
|
186
184
|
private config: P2PConfig,
|
|
187
185
|
protected node: PubSubLibp2p,
|
|
188
186
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
@@ -224,9 +222,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
224
222
|
this.protocolVersion,
|
|
225
223
|
);
|
|
226
224
|
|
|
227
|
-
this.blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
225
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
226
|
+
txsPermitted: !config.disableTransactions,
|
|
227
|
+
maxTxsPerBlock: config.maxTxsPerBlock,
|
|
228
|
+
});
|
|
228
229
|
this.checkpointProposalValidator = new CheckpointProposalValidator(epochCache, {
|
|
229
230
|
txsPermitted: !config.disableTransactions,
|
|
231
|
+
maxTxsPerBlock: config.maxTxsPerBlock,
|
|
230
232
|
});
|
|
231
233
|
this.checkpointAttestationValidator = config.fishermanMode
|
|
232
234
|
? new FishermanAttestationValidator(epochCache, mempools.attestationPool, telemetry)
|
|
@@ -262,8 +264,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
262
264
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
263
265
|
* @returns The new service.
|
|
264
266
|
*/
|
|
265
|
-
public static async new
|
|
266
|
-
clientType: T,
|
|
267
|
+
public static async new(
|
|
267
268
|
config: P2PConfig,
|
|
268
269
|
peerId: PeerId,
|
|
269
270
|
deps: {
|
|
@@ -475,7 +476,6 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
475
476
|
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
476
477
|
|
|
477
478
|
return new LibP2PService(
|
|
478
|
-
clientType,
|
|
479
479
|
config,
|
|
480
480
|
node,
|
|
481
481
|
peerDiscoveryService,
|
|
@@ -549,7 +549,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
549
549
|
await this.node.start();
|
|
550
550
|
|
|
551
551
|
// Subscribe to standard GossipSub topics by default
|
|
552
|
-
for (const topic of
|
|
552
|
+
for (const topic of getTopicsForConfig(this.config.disableTransactions)) {
|
|
553
553
|
this.subscribeToTopic(this.topicStrings[topic]);
|
|
554
554
|
}
|
|
555
555
|
|
|
@@ -818,9 +818,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
|
|
|
818
818
|
if (msg.topic === this.topicStrings[TopicType.tx]) {
|
|
819
819
|
await this.handleGossipedTx(p2pMessage.payload, msgId, source);
|
|
820
820
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_attestation]) {
|
|
821
|
-
|
|
822
|
-
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
823
|
-
}
|
|
821
|
+
await this.processCheckpointAttestationFromPeer(p2pMessage.payload, msgId, source);
|
|
824
822
|
} else if (msg.topic === this.topicStrings[TopicType.block_proposal]) {
|
|
825
823
|
await this.processBlockFromPeer(p2pMessage.payload, msgId, source);
|
|
826
824
|
} else if (msg.topic === this.topicStrings[TopicType.checkpoint_proposal]) {
|
|
@@ -8,6 +8,7 @@ import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
|
8
8
|
import { Tx, TxArray, TxHash } from '@aztec/stdlib/tx';
|
|
9
9
|
|
|
10
10
|
import type { PeerId } from '@libp2p/interface';
|
|
11
|
+
import { peerIdFromString } from '@libp2p/peer-id';
|
|
11
12
|
|
|
12
13
|
import type { IMissingTxsTracker } from '../../tx_collection/missing_txs_tracker.js';
|
|
13
14
|
import { ReqRespSubProtocol } from '.././interface.js';
|
|
@@ -89,9 +90,10 @@ export class BatchTxRequester {
|
|
|
89
90
|
if (this.opts.peerCollection) {
|
|
90
91
|
this.peers = this.opts.peerCollection;
|
|
91
92
|
} else {
|
|
93
|
+
const initialPeers = this.p2pService.connectionSampler.getPeerListSortedByConnectionCountAsc();
|
|
92
94
|
const badPeerThreshold = this.opts.badPeerThreshold ?? DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD;
|
|
93
95
|
this.peers = new PeerCollection(
|
|
94
|
-
|
|
96
|
+
initialPeers,
|
|
95
97
|
this.pinnedPeer,
|
|
96
98
|
this.dateProvider,
|
|
97
99
|
badPeerThreshold,
|
|
@@ -225,6 +227,7 @@ export class BatchTxRequester {
|
|
|
225
227
|
* Starts dumb worker loops
|
|
226
228
|
* */
|
|
227
229
|
private async dumbRequester() {
|
|
230
|
+
const nextPeerIndex = this.makeRoundRobinIndexer();
|
|
228
231
|
const nextBatchIndex = this.makeRoundRobinIndexer();
|
|
229
232
|
|
|
230
233
|
// Chunk missing tx hashes into batches of txBatchSize, wrapping around to ensure no peer gets less than txBatchSize
|
|
@@ -260,9 +263,15 @@ export class BatchTxRequester {
|
|
|
260
263
|
return { blockRequest, txs };
|
|
261
264
|
};
|
|
262
265
|
|
|
263
|
-
const
|
|
266
|
+
const nextPeer = () => {
|
|
267
|
+
const peers = this.peers.getDumbPeersToQuery();
|
|
268
|
+
const idx = nextPeerIndex(() => peers.length);
|
|
269
|
+
return idx === undefined ? undefined : peerIdFromString(peers[idx]);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const workerCount = Math.min(this.dumbParallelWorkerCount, this.peers.getAllPeers().size);
|
|
264
273
|
const workers = Array.from({ length: workerCount }, (_, index) =>
|
|
265
|
-
this.dumbWorkerLoop(
|
|
274
|
+
this.dumbWorkerLoop(nextPeer, makeRequest, index + 1),
|
|
266
275
|
);
|
|
267
276
|
|
|
268
277
|
await Promise.allSettled(workers);
|
|
@@ -323,6 +332,14 @@ export class BatchTxRequester {
|
|
|
323
332
|
* Starts smart worker loops
|
|
324
333
|
* */
|
|
325
334
|
private async smartRequester() {
|
|
335
|
+
const nextPeerIndex = this.makeRoundRobinIndexer();
|
|
336
|
+
|
|
337
|
+
const nextPeer = () => {
|
|
338
|
+
const peers = this.peers.getSmartPeersToQuery();
|
|
339
|
+
const idx = nextPeerIndex(() => peers.length);
|
|
340
|
+
return idx === undefined ? undefined : peerIdFromString(peers[idx]);
|
|
341
|
+
};
|
|
342
|
+
|
|
326
343
|
const makeRequest = (pid: PeerId) => {
|
|
327
344
|
const txs = this.txsMetadata.getTxsToRequestFromThePeer(pid);
|
|
328
345
|
const blockRequest = BlockTxsRequest.fromTxsSourceAndMissingTxs(this.blockTxsSource, txs);
|
|
@@ -333,8 +350,9 @@ export class BatchTxRequester {
|
|
|
333
350
|
return { blockRequest, txs };
|
|
334
351
|
};
|
|
335
352
|
|
|
336
|
-
const workers = Array.from(
|
|
337
|
-
|
|
353
|
+
const workers = Array.from(
|
|
354
|
+
{ length: Math.min(this.smartParallelWorkerCount, this.peers.getAllPeers().size) },
|
|
355
|
+
(_, index) => this.smartWorkerLoop(nextPeer, makeRequest, index + 1),
|
|
338
356
|
);
|
|
339
357
|
|
|
340
358
|
await Promise.allSettled(workers);
|
|
@@ -369,18 +387,26 @@ export class BatchTxRequester {
|
|
|
369
387
|
if (weRanOutOfPeersToQuery) {
|
|
370
388
|
this.logger.debug(`Worker loop smart: No more peers to query`);
|
|
371
389
|
|
|
372
|
-
// If
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
390
|
+
// If there are no more dumb peers to query then none of our peers can become smart,
|
|
391
|
+
// thus we can simply exit this worker
|
|
392
|
+
const noMoreDumbPeersToQuery = this.peers.getDumbPeersToQuery().length === 0;
|
|
393
|
+
if (noMoreDumbPeersToQuery) {
|
|
394
|
+
// These might be either smart peers that will get unblocked after _some time_
|
|
395
|
+
const nextSmartPeerDelay = this.peers.getNextSmartPeerAvailabilityDelayMs();
|
|
396
|
+
const thereAreSomeRateLimitedSmartPeers = nextSmartPeerDelay !== undefined;
|
|
397
|
+
if (thereAreSomeRateLimitedSmartPeers) {
|
|
398
|
+
await this.sleepClampedToDeadline(nextSmartPeerDelay);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
this.logger.debug(`Worker loop smart: No more smart peers to query killing ${workerIndex}`);
|
|
403
|
+
break;
|
|
378
404
|
}
|
|
379
405
|
|
|
406
|
+
// Otherwise there are still some dumb peers that could become smart.
|
|
380
407
|
// We end up here when all known smart peers became temporarily unavailable via combination of
|
|
381
408
|
// (bad, in-flight, or rate-limited) or in some weird scenario all current smart peers turn bad which is permanent
|
|
382
|
-
// but
|
|
383
|
-
// or new peer can join as dumb and be promoted later
|
|
409
|
+
// but dumb peers still exist that could become smart.
|
|
384
410
|
//
|
|
385
411
|
// When a dumb peer responds with valid txIndices, it gets
|
|
386
412
|
// promoted to smart and releases the semaphore, waking this worker.
|
|
@@ -573,7 +599,9 @@ export class BatchTxRequester {
|
|
|
573
599
|
this.markTxsPeerHas(peerId, response);
|
|
574
600
|
|
|
575
601
|
// Unblock smart workers
|
|
576
|
-
this.
|
|
602
|
+
if (this.peers.getSmartPeersToQuery().length <= this.smartParallelWorkerCount) {
|
|
603
|
+
this.smartRequesterSemaphore.release();
|
|
604
|
+
}
|
|
577
605
|
}
|
|
578
606
|
|
|
579
607
|
private isBlockResponseValid(response: BlockTxsResponse): boolean {
|
|
@@ -2,22 +2,18 @@ import type { DateProvider } from '@aztec/foundation/timer';
|
|
|
2
2
|
import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
3
3
|
|
|
4
4
|
import type { PeerId } from '@libp2p/interface';
|
|
5
|
-
import { peerIdFromString } from '@libp2p/peer-id';
|
|
6
5
|
|
|
7
|
-
import type { ConnectionSampler } from '../connection-sampler/connection_sampler.js';
|
|
8
6
|
import { DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD } from './config.js';
|
|
9
7
|
import type { IPeerPenalizer } from './interface.js';
|
|
10
8
|
|
|
11
9
|
export const RATE_LIMIT_EXCEEDED_PEER_CACHE_TTL = 1000; // 1s
|
|
12
10
|
|
|
13
11
|
export interface IPeerCollection {
|
|
12
|
+
getAllPeers(): Set<string>;
|
|
13
|
+
getSmartPeers(): Set<string>;
|
|
14
14
|
markPeerSmart(peerId: PeerId): void;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
nextSmartPeerToQuery(): PeerId | undefined;
|
|
18
|
-
/** Sample next peer in round-robin fashion. No dumb peers if returns undefined */
|
|
19
|
-
nextDumbPeerToQuery(): PeerId | undefined;
|
|
20
|
-
|
|
15
|
+
getSmartPeersToQuery(): Array<string>;
|
|
16
|
+
getDumbPeersToQuery(): Array<string>;
|
|
21
17
|
thereAreSomeDumbRatelimitExceededPeers(): boolean;
|
|
22
18
|
penalisePeer(peerId: PeerId, severity: PeerErrorSeverity): void;
|
|
23
19
|
unMarkPeerAsBad(peerId: PeerId): void;
|
|
@@ -32,6 +28,8 @@ export interface IPeerCollection {
|
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
export class PeerCollection implements IPeerCollection {
|
|
31
|
+
private readonly peers;
|
|
32
|
+
|
|
35
33
|
private readonly smartPeers = new Set<string>();
|
|
36
34
|
private readonly inFlightPeers = new Set<string>();
|
|
37
35
|
private readonly rateLimitExceededPeers = new Map<string, number>();
|
|
@@ -39,60 +37,46 @@ export class PeerCollection implements IPeerCollection {
|
|
|
39
37
|
private readonly badPeers = new Set<string>();
|
|
40
38
|
|
|
41
39
|
constructor(
|
|
42
|
-
|
|
40
|
+
initialPeers: PeerId[],
|
|
43
41
|
private readonly pinnedPeerId: PeerId | undefined,
|
|
44
42
|
private readonly dateProvider: DateProvider,
|
|
45
43
|
private readonly badPeerThreshold: number = DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD,
|
|
46
44
|
private readonly peerPenalizer?: IPeerPenalizer,
|
|
47
45
|
) {
|
|
48
|
-
|
|
46
|
+
this.peers = new Set(initialPeers.map(peer => peer.toString()));
|
|
47
|
+
|
|
48
|
+
// Pinned peer is treaded specially, always mark it as in-flight
|
|
49
49
|
// and never return it as part of smart/dumb peers
|
|
50
50
|
if (this.pinnedPeerId) {
|
|
51
51
|
const peerIdStr = this.pinnedPeerId.toString();
|
|
52
52
|
this.inFlightPeers.add(peerIdStr);
|
|
53
|
+
this.peers.delete(peerIdStr);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
public
|
|
57
|
-
this.
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// We keep track of all peers that are queried for peer sampling algorithm
|
|
61
|
-
private queriedSmartPeers: Set<string> = new Set<string>();
|
|
62
|
-
private queriedDumbPeers: Set<string> = new Set<string>();
|
|
63
|
-
|
|
64
|
-
private static nextPeer(allPeers: Set<string>, queried: Set<string>): PeerId | undefined {
|
|
65
|
-
if (allPeers.size === 0) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
const availablePeers = allPeers.difference(queried);
|
|
69
|
-
let [first] = availablePeers;
|
|
70
|
-
if (first === undefined) {
|
|
71
|
-
// We queried all peers. Start over
|
|
72
|
-
[first] = allPeers;
|
|
73
|
-
queried.clear();
|
|
74
|
-
}
|
|
75
|
-
queried.add(first);
|
|
76
|
-
return peerIdFromString(first);
|
|
57
|
+
public getAllPeers(): Set<string> {
|
|
58
|
+
return this.peers;
|
|
77
59
|
}
|
|
78
60
|
|
|
79
|
-
public
|
|
80
|
-
return
|
|
61
|
+
public getSmartPeers(): Set<string> {
|
|
62
|
+
return this.smartPeers;
|
|
81
63
|
}
|
|
82
64
|
|
|
83
|
-
public
|
|
84
|
-
|
|
65
|
+
public markPeerSmart(peerId: PeerId): void {
|
|
66
|
+
this.smartPeers.add(peerId.toString());
|
|
85
67
|
}
|
|
86
68
|
|
|
87
|
-
|
|
88
|
-
return
|
|
69
|
+
public getSmartPeersToQuery(): Array<string> {
|
|
70
|
+
return Array.from(
|
|
89
71
|
this.smartPeers.difference(this.getBadPeers().union(this.inFlightPeers).union(this.getRateLimitExceededPeers())),
|
|
90
72
|
);
|
|
91
73
|
}
|
|
92
74
|
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
this.
|
|
75
|
+
public getDumbPeersToQuery(): Array<string> {
|
|
76
|
+
return Array.from(
|
|
77
|
+
this.peers.difference(
|
|
78
|
+
this.smartPeers.union(this.getBadPeers()).union(this.inFlightPeers).union(this.getRateLimitExceededPeers()),
|
|
79
|
+
),
|
|
96
80
|
);
|
|
97
81
|
}
|
|
98
82
|
|
|
@@ -218,27 +202,4 @@ export class PeerCollection implements IPeerCollection {
|
|
|
218
202
|
|
|
219
203
|
return minExpiry! - now;
|
|
220
204
|
}
|
|
221
|
-
|
|
222
|
-
private orderedPeers: Set<string> = new Set();
|
|
223
|
-
|
|
224
|
-
private get peers(): Set<string> {
|
|
225
|
-
const pinnedStr = this.pinnedPeerId?.toString();
|
|
226
|
-
const currentlyConnected = new Set(
|
|
227
|
-
this.connectionSampler
|
|
228
|
-
.getPeerListSortedByConnectionCountAsc()
|
|
229
|
-
.map(p => p.toString())
|
|
230
|
-
.filter(p => p !== pinnedStr),
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
// Remove disconnected peers, preserving order of the rest.
|
|
234
|
-
this.orderedPeers = this.orderedPeers.intersection(currentlyConnected);
|
|
235
|
-
|
|
236
|
-
// Append newly connected peers at the end (lowest priority).
|
|
237
|
-
for (const peer of currentlyConnected) {
|
|
238
|
-
if (!this.orderedPeers.has(peer)) {
|
|
239
|
-
this.orderedPeers.add(peer);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return this.orderedPeers;
|
|
243
|
-
}
|
|
244
205
|
}
|
|
@@ -7,7 +7,6 @@ import { sleep } from '@aztec/foundation/sleep';
|
|
|
7
7
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
8
8
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
9
9
|
import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
11
10
|
|
|
12
11
|
import { createP2PClient } from '../client/index.js';
|
|
13
12
|
import type { P2PClient } from '../client/p2p_client.js';
|
|
@@ -98,7 +97,6 @@ export async function makeTestP2PClient(
|
|
|
98
97
|
const kvStore = await openTmpStore('test');
|
|
99
98
|
|
|
100
99
|
const client = await createP2PClient(
|
|
101
|
-
P2PClientType.Full,
|
|
102
100
|
config,
|
|
103
101
|
l2BlockSource,
|
|
104
102
|
proofVerifier,
|
|
@@ -4,7 +4,6 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
|
4
4
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
5
5
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
6
6
|
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
8
7
|
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
9
8
|
|
|
10
9
|
import type { GossipsubEvents, GossipsubMessage } from '@chainsafe/libp2p-gossipsub';
|
|
@@ -42,11 +41,10 @@ type GossipSubService = PubSubLibp2p['services']['pubsub'];
|
|
|
42
41
|
* Given a mock gossip sub network, returns a factory function that creates an instance LibP2PService connected to it.
|
|
43
42
|
* Designed to be used in tests in P2PClientDeps.p2pServiceFactory.
|
|
44
43
|
*/
|
|
45
|
-
export function getMockPubSubP2PServiceFactory
|
|
44
|
+
export function getMockPubSubP2PServiceFactory(
|
|
46
45
|
network: MockGossipSubNetwork,
|
|
47
|
-
): (...args: Parameters<(typeof LibP2PService
|
|
46
|
+
): (...args: Parameters<(typeof LibP2PService)['new']>) => Promise<LibP2PService> {
|
|
48
47
|
return (
|
|
49
|
-
clientType: P2PClientType,
|
|
50
48
|
config: P2PConfig,
|
|
51
49
|
peerId: PeerId,
|
|
52
50
|
deps: {
|
|
@@ -66,8 +64,7 @@ export function getMockPubSubP2PServiceFactory<T extends P2PClientType>(
|
|
|
66
64
|
const peerManager = new DummyPeerManager(peerId, network);
|
|
67
65
|
const reqresp: ReqRespInterface = new MockReqResp(peerId, network);
|
|
68
66
|
const peerDiscoveryService = new DummyPeerDiscoveryService();
|
|
69
|
-
const service = new LibP2PService
|
|
70
|
-
clientType as T,
|
|
67
|
+
const service = new LibP2PService(
|
|
71
68
|
config,
|
|
72
69
|
libp2p,
|
|
73
70
|
peerDiscoveryService,
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
IVCProofVerificationResult,
|
|
13
13
|
WorldStateSynchronizer,
|
|
14
14
|
} from '@aztec/stdlib/interfaces/server';
|
|
15
|
-
import type { P2PClientType } from '@aztec/stdlib/p2p';
|
|
16
15
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
17
16
|
import { compressComponentVersions } from '@aztec/stdlib/versioning';
|
|
18
17
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -107,8 +106,7 @@ export async function createLibp2pNode(
|
|
|
107
106
|
*
|
|
108
107
|
*
|
|
109
108
|
*/
|
|
110
|
-
export async function createTestLibP2PService
|
|
111
|
-
clientType: T,
|
|
109
|
+
export async function createTestLibP2PService(
|
|
112
110
|
boostrapAddrs: string[] = [],
|
|
113
111
|
archiver: L2BlockSource & ContractDataSource,
|
|
114
112
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
@@ -159,8 +157,7 @@ export async function createTestLibP2PService<T extends P2PClientType>(
|
|
|
159
157
|
p2pNode.services.pubsub.score.params.appSpecificScore = (peerId: string) =>
|
|
160
158
|
peerManager.shouldDisableP2PGossip(peerId) ? -Infinity : peerManager.getPeerScore(peerId);
|
|
161
159
|
|
|
162
|
-
return new LibP2PService
|
|
163
|
-
clientType,
|
|
160
|
+
return new LibP2PService(
|
|
164
161
|
config,
|
|
165
162
|
p2pNode as PubSubLibp2p,
|
|
166
163
|
discoveryService,
|
|
@@ -19,7 +19,7 @@ import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
|
19
19
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
20
20
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
21
21
|
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
22
|
-
import { type BlockProposal,
|
|
22
|
+
import { type BlockProposal, P2PMessage } from '@aztec/stdlib/p2p';
|
|
23
23
|
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
24
24
|
import { makeAztecAddress, makeBlockHeader, makeBlockProposal, mockTx } from '@aztec/stdlib/testing';
|
|
25
25
|
import { Tx, TxHash, type TxValidationResult } from '@aztec/stdlib/tx';
|
|
@@ -86,12 +86,11 @@ export interface BenchReadyMessage {
|
|
|
86
86
|
}
|
|
87
87
|
const txCache = new Map<number, Tx[]>();
|
|
88
88
|
|
|
89
|
-
class TestLibP2PService
|
|
89
|
+
class TestLibP2PService extends LibP2PService {
|
|
90
90
|
private disableTxValidation: boolean;
|
|
91
91
|
private gossipMessageCount = 0;
|
|
92
92
|
|
|
93
93
|
constructor(
|
|
94
|
-
clientType: T,
|
|
95
94
|
config: P2PConfig,
|
|
96
95
|
node: PubSubLibp2p,
|
|
97
96
|
peerDiscoveryService: PeerDiscoveryService,
|
|
@@ -107,7 +106,6 @@ class TestLibP2PService<T extends P2PClientType = P2PClientType.Full> extends Li
|
|
|
107
106
|
disableTxValidation = true,
|
|
108
107
|
) {
|
|
109
108
|
super(
|
|
110
|
-
clientType,
|
|
111
109
|
config,
|
|
112
110
|
node,
|
|
113
111
|
peerDiscoveryService,
|
|
@@ -365,7 +363,6 @@ process.on('message', async msg => {
|
|
|
365
363
|
};
|
|
366
364
|
|
|
367
365
|
const client = await createP2PClient(
|
|
368
|
-
P2PClientType.Full,
|
|
369
366
|
config as P2PConfig & DataStoreConfig,
|
|
370
367
|
l2BlockSource,
|
|
371
368
|
proofVerifier as ClientProtocolCircuitVerifier,
|
|
@@ -378,7 +375,6 @@ process.on('message', async msg => {
|
|
|
378
375
|
);
|
|
379
376
|
|
|
380
377
|
const testService = new TestLibP2PService(
|
|
381
|
-
P2PClientType.Full,
|
|
382
378
|
config,
|
|
383
379
|
(client as any).p2pService.node,
|
|
384
380
|
(client as any).p2pService.peerDiscoveryService,
|