@aztec/p2p 0.72.1 → 0.74.0
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 +1 -1
- package/dest/client/factory.d.ts +2 -2
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +4 -4
- package/dest/client/p2p_client.d.ts +13 -16
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +50 -62
- 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 +11 -19
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +6 -13
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +74 -80
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +5 -5
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +3 -3
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +9 -9
- 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 +59 -53
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +7 -7
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +17 -18
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +7 -7
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +48 -47
- package/dest/mocks/index.js +3 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.js +2 -2
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +2 -2
- package/dest/msg_validators/tx_validator/block_header_validator.js +3 -3
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +7 -7
- package/dest/msg_validators/tx_validator/double_spend_validator.js +3 -3
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +9 -9
- package/dest/services/data_store.d.ts +4 -4
- package/dest/services/data_store.d.ts.map +1 -1
- package/dest/services/data_store.js +7 -7
- package/dest/services/libp2p/libp2p_service.d.ts +3 -3
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +56 -35
- package/dest/services/peer-manager/peer_manager.d.ts +1 -0
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +6 -3
- package/dest/services/reqresp/protocols/tx.js +4 -4
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +2 -2
- package/dest/util.d.ts +2 -2
- package/dest/util.d.ts.map +1 -1
- package/dest/util.js +2 -2
- package/package.json +7 -7
- package/src/bootstrap/bootstrap.ts +2 -2
- package/src/client/factory.ts +5 -5
- package/src/client/p2p_client.ts +63 -75
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +14 -22
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +100 -94
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +4 -4
- package/src/mem_pools/attestation_pool/mocks.ts +3 -3
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +84 -72
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +26 -23
- package/src/mem_pools/tx_pool/tx_pool.ts +7 -7
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +50 -47
- package/src/mocks/index.ts +2 -2
- package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
- package/src/msg_validators/block_proposal_validator/block_proposal_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 +12 -9
- package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
- package/src/msg_validators/tx_validator/metadata_validator.ts +8 -8
- package/src/services/data_store.ts +9 -9
- package/src/services/libp2p/libp2p_service.ts +70 -36
- package/src/services/peer-manager/peer_manager.ts +7 -2
- package/src/services/reqresp/protocols/tx.ts +3 -3
- package/src/services/reqresp/reqresp.ts +7 -1
- package/src/util.ts +7 -4
|
@@ -23,7 +23,7 @@ import { type EpochCache } from '@aztec/epoch-cache';
|
|
|
23
23
|
import { createLogger } from '@aztec/foundation/log';
|
|
24
24
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
25
25
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
26
|
-
import type {
|
|
26
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
27
27
|
import { Attributes, OtelMetricsAdapter, type TelemetryClient, WithTracer, trackSpan } from '@aztec/telemetry-client';
|
|
28
28
|
|
|
29
29
|
import { type ENR } from '@chainsafe/enr';
|
|
@@ -142,11 +142,12 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
142
142
|
this.blockProposalValidator = new BlockProposalValidator(epochCache);
|
|
143
143
|
this.epochProofQuoteValidator = new EpochProofQuoteValidator(epochCache);
|
|
144
144
|
|
|
145
|
-
this.blockReceivedCallback = (block: BlockProposal): Promise<BlockAttestation | undefined> => {
|
|
146
|
-
this.logger.
|
|
147
|
-
`
|
|
145
|
+
this.blockReceivedCallback = async (block: BlockProposal): Promise<BlockAttestation | undefined> => {
|
|
146
|
+
this.logger.warn(
|
|
147
|
+
`Handler not yet registered: Block received callback not set. Received block for slot ${block.slotNumber.toNumber()} from peer.`,
|
|
148
|
+
{ p2pMessageIdentifier: await block.p2pMessageIdentifier() },
|
|
148
149
|
);
|
|
149
|
-
return
|
|
150
|
+
return undefined;
|
|
150
151
|
};
|
|
151
152
|
}
|
|
152
153
|
|
|
@@ -166,7 +167,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
166
167
|
epochCache: EpochCache,
|
|
167
168
|
proofVerifier: ClientProtocolCircuitVerifier,
|
|
168
169
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
169
|
-
store:
|
|
170
|
+
store: AztecAsyncKVStore,
|
|
170
171
|
telemetry: TelemetryClient,
|
|
171
172
|
) {
|
|
172
173
|
const { tcpListenAddress, tcpAnnounceAddress, minPeerCount, maxPeerCount } = config;
|
|
@@ -376,11 +377,13 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
376
377
|
return this.peerManager.getPeers(includePending);
|
|
377
378
|
}
|
|
378
379
|
|
|
379
|
-
private
|
|
380
|
+
private handleGossipSubEvent(e: CustomEvent<GossipsubMessage>) {
|
|
380
381
|
const { msg } = e.detail;
|
|
381
382
|
this.logger.trace(`Received PUBSUB message.`);
|
|
382
383
|
|
|
383
|
-
|
|
384
|
+
void this.jobQueue
|
|
385
|
+
.put(() => this.handleNewGossipMessage(msg))
|
|
386
|
+
.catch(err => this.logger.error(`Error processing gossip message`, err));
|
|
384
387
|
}
|
|
385
388
|
|
|
386
389
|
/**
|
|
@@ -472,7 +475,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
472
475
|
}
|
|
473
476
|
if (message.topic == EpochProofQuote.p2pTopic) {
|
|
474
477
|
const epochProofQuote = EpochProofQuote.fromBuffer(Buffer.from(message.data));
|
|
475
|
-
this.processEpochProofQuoteFromPeer(epochProofQuote);
|
|
478
|
+
await this.processEpochProofQuoteFromPeer(epochProofQuote);
|
|
476
479
|
}
|
|
477
480
|
|
|
478
481
|
return;
|
|
@@ -483,14 +486,22 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
483
486
|
*
|
|
484
487
|
* @param attestation - The attestation to process.
|
|
485
488
|
*/
|
|
486
|
-
@trackSpan('Libp2pService.processAttestationFromPeer', attestation => ({
|
|
489
|
+
@trackSpan('Libp2pService.processAttestationFromPeer', async attestation => ({
|
|
487
490
|
[Attributes.BLOCK_NUMBER]: attestation.payload.header.globalVariables.blockNumber.toNumber(),
|
|
488
491
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toNumber(),
|
|
489
492
|
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
490
|
-
[Attributes.P2P_ID]: attestation.p2pMessageIdentifier().toString(),
|
|
493
|
+
[Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then(i => i.toString()),
|
|
491
494
|
}))
|
|
492
495
|
private async processAttestationFromPeer(attestation: BlockAttestation): Promise<void> {
|
|
493
|
-
this.logger.debug(
|
|
496
|
+
this.logger.debug(
|
|
497
|
+
`Received attestation for block ${attestation.blockNumber.toNumber()} slot ${attestation.slotNumber.toNumber()} from external peer.`,
|
|
498
|
+
{
|
|
499
|
+
p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
|
|
500
|
+
slot: attestation.slotNumber.toNumber(),
|
|
501
|
+
archive: attestation.archive.toString(),
|
|
502
|
+
block: attestation.blockNumber.toNumber(),
|
|
503
|
+
},
|
|
504
|
+
);
|
|
494
505
|
await this.mempools.attestationPool!.addAttestations([attestation]);
|
|
495
506
|
}
|
|
496
507
|
|
|
@@ -501,21 +512,37 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
501
512
|
* @param block - The block to process.
|
|
502
513
|
*/
|
|
503
514
|
// REVIEW: callback pattern https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
504
|
-
@trackSpan('Libp2pService.processBlockFromPeer', block => ({
|
|
505
|
-
[Attributes.BLOCK_NUMBER]: block.
|
|
506
|
-
[Attributes.SLOT_NUMBER]: block.
|
|
515
|
+
@trackSpan('Libp2pService.processBlockFromPeer', async block => ({
|
|
516
|
+
[Attributes.BLOCK_NUMBER]: block.blockNumber.toNumber(),
|
|
517
|
+
[Attributes.SLOT_NUMBER]: block.slotNumber.toNumber(),
|
|
507
518
|
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
508
|
-
[Attributes.P2P_ID]: block.p2pMessageIdentifier().toString(),
|
|
519
|
+
[Attributes.P2P_ID]: await block.p2pMessageIdentifier().then(i => i.toString()),
|
|
509
520
|
}))
|
|
510
521
|
private async processBlockFromPeer(block: BlockProposal): Promise<void> {
|
|
511
|
-
this.logger.verbose(
|
|
522
|
+
this.logger.verbose(
|
|
523
|
+
`Received block ${block.blockNumber.toNumber()} for slot ${block.slotNumber.toNumber()} from external peer.`,
|
|
524
|
+
{
|
|
525
|
+
p2pMessageIdentifier: await block.p2pMessageIdentifier(),
|
|
526
|
+
slot: block.slotNumber.toNumber(),
|
|
527
|
+
archive: block.archive.toString(),
|
|
528
|
+
block: block.blockNumber.toNumber(),
|
|
529
|
+
},
|
|
530
|
+
);
|
|
512
531
|
const attestation = await this.blockReceivedCallback(block);
|
|
513
532
|
|
|
514
533
|
// TODO: fix up this pattern - the abstraction is not nice
|
|
515
534
|
// The attestation can be undefined if no handler is registered / the validator deems the block invalid
|
|
516
535
|
if (attestation != undefined) {
|
|
517
|
-
this.logger.verbose(
|
|
518
|
-
|
|
536
|
+
this.logger.verbose(
|
|
537
|
+
`Broadcasting attestation for block ${attestation.blockNumber.toNumber()} slot ${attestation.slotNumber.toNumber()}`,
|
|
538
|
+
{
|
|
539
|
+
p2pMessageIdentifier: await attestation.p2pMessageIdentifier(),
|
|
540
|
+
slot: attestation.slotNumber.toNumber(),
|
|
541
|
+
archive: attestation.archive.toString(),
|
|
542
|
+
block: attestation.blockNumber.toNumber(),
|
|
543
|
+
},
|
|
544
|
+
);
|
|
545
|
+
await this.broadcastAttestation(attestation);
|
|
519
546
|
}
|
|
520
547
|
}
|
|
521
548
|
|
|
@@ -523,18 +550,24 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
523
550
|
* Broadcast an attestation to all peers.
|
|
524
551
|
* @param attestation - The attestation to broadcast.
|
|
525
552
|
*/
|
|
526
|
-
@trackSpan('Libp2pService.broadcastAttestation', attestation => ({
|
|
553
|
+
@trackSpan('Libp2pService.broadcastAttestation', async attestation => ({
|
|
527
554
|
[Attributes.BLOCK_NUMBER]: attestation.payload.header.globalVariables.blockNumber.toNumber(),
|
|
528
555
|
[Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toNumber(),
|
|
529
556
|
[Attributes.BLOCK_ARCHIVE]: attestation.archive.toString(),
|
|
530
|
-
[Attributes.P2P_ID]: attestation.p2pMessageIdentifier().toString(),
|
|
557
|
+
[Attributes.P2P_ID]: await attestation.p2pMessageIdentifier().then(i => i.toString()),
|
|
531
558
|
}))
|
|
532
|
-
private broadcastAttestation(attestation: BlockAttestation)
|
|
533
|
-
this.propagate(attestation);
|
|
559
|
+
private async broadcastAttestation(attestation: BlockAttestation) {
|
|
560
|
+
await this.propagate(attestation);
|
|
534
561
|
}
|
|
535
562
|
|
|
536
|
-
private processEpochProofQuoteFromPeer(epochProofQuote: EpochProofQuote)
|
|
537
|
-
|
|
563
|
+
private async processEpochProofQuoteFromPeer(epochProofQuote: EpochProofQuote) {
|
|
564
|
+
const epoch = epochProofQuote.payload.epochToProve;
|
|
565
|
+
const prover = epochProofQuote.payload.prover.toString();
|
|
566
|
+
const p2pMessageIdentifier = await epochProofQuote.p2pMessageIdentifier();
|
|
567
|
+
this.logger.verbose(
|
|
568
|
+
`Received epoch proof quote ${p2pMessageIdentifier} by prover ${prover} for epoch ${epoch} from external peer.`,
|
|
569
|
+
{ quote: epochProofQuote.toInspect(), p2pMessageIdentifier },
|
|
570
|
+
);
|
|
538
571
|
this.mempools.epochProofQuotePool.addQuote(epochProofQuote);
|
|
539
572
|
}
|
|
540
573
|
|
|
@@ -542,15 +575,16 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
542
575
|
* Propagates provided message to peers.
|
|
543
576
|
* @param message - The message to propagate.
|
|
544
577
|
*/
|
|
545
|
-
public propagate<T extends Gossipable>(message: T)
|
|
546
|
-
|
|
578
|
+
public async propagate<T extends Gossipable>(message: T) {
|
|
579
|
+
const p2pMessageIdentifier = await message.p2pMessageIdentifier();
|
|
580
|
+
this.logger.trace(`Message ${p2pMessageIdentifier} queued`, { p2pMessageIdentifier });
|
|
547
581
|
void this.jobQueue.put(async () => {
|
|
548
582
|
await this.sendToPeers(message);
|
|
549
583
|
});
|
|
550
584
|
}
|
|
551
585
|
|
|
552
586
|
private async processTxFromPeer(tx: Tx): Promise<void> {
|
|
553
|
-
const txHash = tx.getTxHash();
|
|
587
|
+
const txHash = await tx.getTxHash();
|
|
554
588
|
const txHashString = txHash.toString();
|
|
555
589
|
this.logger.verbose(`Received tx ${txHashString} from external peer.`);
|
|
556
590
|
await this.mempools.txPool.addTxs([tx]);
|
|
@@ -578,7 +612,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
578
612
|
const validProof = await proofValidator.validateTx(responseTx);
|
|
579
613
|
|
|
580
614
|
// If the node returns the wrong data, we penalize it
|
|
581
|
-
if (!requestedTxHash.equals(responseTx.getTxHash())) {
|
|
615
|
+
if (!requestedTxHash.equals(await responseTx.getTxHash())) {
|
|
582
616
|
// Returning the wrong data is a low tolerance error
|
|
583
617
|
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.MidToleranceError);
|
|
584
618
|
return false;
|
|
@@ -606,7 +640,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
606
640
|
const tx = Tx.fromBuffer(Buffer.from(msg.data));
|
|
607
641
|
const isValid = await this.validatePropagatedTx(tx, propagationSource);
|
|
608
642
|
this.logger.trace(`validatePropagatedTx: ${isValid}`, {
|
|
609
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
643
|
+
[Attributes.TX_HASH]: (await tx.getTxHash()).toString(),
|
|
610
644
|
[Attributes.P2P_ID]: propagationSource.toString(),
|
|
611
645
|
});
|
|
612
646
|
return isValid ? TopicValidatorResult.Accept : TopicValidatorResult.Reject;
|
|
@@ -669,8 +703,8 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
669
703
|
return isValid ? TopicValidatorResult.Accept : TopicValidatorResult.Reject;
|
|
670
704
|
}
|
|
671
705
|
|
|
672
|
-
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
673
|
-
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
706
|
+
@trackSpan('Libp2pService.validatePropagatedTx', async tx => ({
|
|
707
|
+
[Attributes.TX_HASH]: (await tx.getTxHash()).toString(),
|
|
674
708
|
}))
|
|
675
709
|
private async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
|
|
676
710
|
const blockNumber = (await this.l2BlockSource.getBlockNumber()) + 1;
|
|
@@ -866,17 +900,17 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
866
900
|
private async sendToPeers<T extends Gossipable>(message: T) {
|
|
867
901
|
const parent = message.constructor as typeof Gossipable;
|
|
868
902
|
|
|
869
|
-
const identifier = message.p2pMessageIdentifier().toString();
|
|
870
|
-
this.logger.trace(`Sending message ${identifier}
|
|
903
|
+
const identifier = await message.p2pMessageIdentifier().then(i => i.toString());
|
|
904
|
+
this.logger.trace(`Sending message ${identifier}`, { p2pMessageIdentifier: identifier });
|
|
871
905
|
|
|
872
906
|
const recipientsNum = await this.publishToTopic(parent.p2pTopic, message.toBuffer());
|
|
873
|
-
this.logger.debug(`Sent message ${identifier} to ${recipientsNum} peers
|
|
907
|
+
this.logger.debug(`Sent message ${identifier} to ${recipientsNum} peers`, { p2pMessageIdentifier: identifier });
|
|
874
908
|
}
|
|
875
909
|
|
|
876
910
|
// Libp2p seems to hang sometimes if new peers are initiating connections.
|
|
877
911
|
private async stopLibP2P() {
|
|
878
912
|
const TIMEOUT_MS = 5000; // 5 seconds timeout
|
|
879
|
-
const timeout = new Promise((
|
|
913
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
880
914
|
setTimeout(() => reject(new Error('Timeout during libp2p.stop()')), TIMEOUT_MS);
|
|
881
915
|
});
|
|
882
916
|
try {
|
|
@@ -42,6 +42,7 @@ export class PeerManager {
|
|
|
42
42
|
private timedOutPeers: Map<string, TimedOutPeer> = new Map();
|
|
43
43
|
|
|
44
44
|
private metrics: PeerManagerMetrics;
|
|
45
|
+
private discoveredPeerHandler;
|
|
45
46
|
|
|
46
47
|
constructor(
|
|
47
48
|
private libP2PNode: PubSubLibp2p,
|
|
@@ -60,7 +61,10 @@ export class PeerManager {
|
|
|
60
61
|
this.libP2PNode.addEventListener(PeerEvent.DISCONNECTED, this.handleDisconnectedPeerEvent.bind(this));
|
|
61
62
|
|
|
62
63
|
// Handle Discovered peers
|
|
63
|
-
this.
|
|
64
|
+
this.discoveredPeerHandler = (enr: ENR) =>
|
|
65
|
+
this.handleDiscoveredPeer(enr).catch(e => this.logger.error('Error handling discovered peer', e));
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
67
|
+
this.peerDiscoveryService.on(PeerEvent.DISCOVERED, this.discoveredPeerHandler);
|
|
64
68
|
|
|
65
69
|
// Display peer counts every 60 seconds
|
|
66
70
|
this.displayPeerCountsPeerHeartbeat = Math.floor(60_000 / this.config.peerCheckIntervalMS);
|
|
@@ -411,7 +415,8 @@ export class PeerManager {
|
|
|
411
415
|
* Removing all event listeners.
|
|
412
416
|
*/
|
|
413
417
|
public async stop() {
|
|
414
|
-
|
|
418
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
419
|
+
this.peerDiscoveryService.off(PeerEvent.DISCOVERED, this.discoveredPeerHandler);
|
|
415
420
|
|
|
416
421
|
// Send goodbyes to all peers
|
|
417
422
|
await Promise.all(
|
|
@@ -20,10 +20,10 @@ export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>)
|
|
|
20
20
|
* @param msg - the tx request message
|
|
21
21
|
* @returns the tx response message
|
|
22
22
|
*/
|
|
23
|
-
return (_peerId: PeerId, msg: Buffer) => {
|
|
23
|
+
return async (_peerId: PeerId, msg: Buffer) => {
|
|
24
24
|
const txHash = TxHash.fromBuffer(msg);
|
|
25
|
-
const foundTx = mempools.txPool.getTxByHash(txHash);
|
|
25
|
+
const foundTx = await mempools.txPool.getTxByHash(txHash);
|
|
26
26
|
const buf = foundTx ? foundTx.toBuffer() : Buffer.alloc(0);
|
|
27
|
-
return
|
|
27
|
+
return buf;
|
|
28
28
|
};
|
|
29
29
|
}
|
|
@@ -95,7 +95,13 @@ export class ReqResp {
|
|
|
95
95
|
|
|
96
96
|
// Register all protocol handlers
|
|
97
97
|
for (const subProtocol of Object.keys(this.subProtocolHandlers)) {
|
|
98
|
-
await this.libp2p.handle(
|
|
98
|
+
await this.libp2p.handle(
|
|
99
|
+
subProtocol,
|
|
100
|
+
(data: IncomingStreamData) =>
|
|
101
|
+
void this.streamHandler(subProtocol as ReqRespSubProtocol, data).catch(err =>
|
|
102
|
+
this.logger.error(`Error on libp2p subprotocol ${subProtocol} handler`, err),
|
|
103
|
+
),
|
|
104
|
+
);
|
|
99
105
|
}
|
|
100
106
|
this.rateLimiter.start();
|
|
101
107
|
}
|
package/src/util.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
2
|
import { type DataStoreConfig } from '@aztec/kv-store/config';
|
|
3
3
|
|
|
4
4
|
import type { GossipSub } from '@chainsafe/libp2p-gossipsub';
|
|
@@ -157,14 +157,17 @@ export async function configureP2PClientAddresses(
|
|
|
157
157
|
* 3. If not, create a new one, then persist it in the node
|
|
158
158
|
*
|
|
159
159
|
*/
|
|
160
|
-
export async function getPeerIdPrivateKey(
|
|
161
|
-
|
|
160
|
+
export async function getPeerIdPrivateKey(
|
|
161
|
+
config: { peerIdPrivateKey?: string },
|
|
162
|
+
store: AztecAsyncKVStore,
|
|
163
|
+
): Promise<string> {
|
|
164
|
+
const peerIdPrivateKeySingleton = store.openSingleton<string>('peerIdPrivateKey');
|
|
162
165
|
if (config.peerIdPrivateKey) {
|
|
163
166
|
await peerIdPrivateKeySingleton.set(config.peerIdPrivateKey);
|
|
164
167
|
return config.peerIdPrivateKey;
|
|
165
168
|
}
|
|
166
169
|
|
|
167
|
-
const storedPeerIdPrivateKey = peerIdPrivateKeySingleton.
|
|
170
|
+
const storedPeerIdPrivateKey = await peerIdPrivateKeySingleton.getAsync();
|
|
168
171
|
if (storedPeerIdPrivateKey) {
|
|
169
172
|
return storedPeerIdPrivateKey;
|
|
170
173
|
}
|