@aztec/p2p 0.67.1-devnet → 0.68.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/client/factory.d.ts +19 -0
- package/dest/client/factory.d.ts.map +1 -0
- package/dest/client/factory.js +40 -0
- package/dest/client/index.d.ts +1 -16
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +2 -40
- package/dest/config.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -2
- package/dest/mocks/index.d.ts +2 -1
- package/dest/mocks/index.d.ts.map +1 -1
- package/dest/mocks/index.js +3 -3
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +8 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.js +19 -0
- package/dest/msg_validators/attestation_validator/index.d.ts +2 -0
- package/dest/msg_validators/attestation_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/attestation_validator/index.js +2 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +8 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +21 -0
- package/dest/msg_validators/block_proposal_validator/index.d.ts +2 -0
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/block_proposal_validator/index.js +2 -0
- package/dest/msg_validators/epoch_proof_quote_validator/epoch_proof_quote_validator.d.ts +8 -0
- package/dest/msg_validators/epoch_proof_quote_validator/epoch_proof_quote_validator.d.ts.map +1 -0
- package/dest/msg_validators/epoch_proof_quote_validator/epoch_proof_quote_validator.js +16 -0
- package/dest/msg_validators/epoch_proof_quote_validator/index.d.ts +2 -0
- package/dest/msg_validators/epoch_proof_quote_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/epoch_proof_quote_validator/index.js +2 -0
- package/dest/msg_validators/index.d.ts +4 -0
- package/dest/msg_validators/index.d.ts.map +1 -0
- package/dest/msg_validators/index.js +4 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -0
- package/dest/{tx_validator → msg_validators/tx_validator}/aggregate_tx_validator.js +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -0
- package/dest/{tx_validator → msg_validators/tx_validator}/data_validator.js +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -0
- package/dest/{tx_validator → msg_validators/tx_validator}/double_spend_validator.js +1 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -0
- package/dest/{tx_validator → msg_validators/tx_validator}/index.js +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -0
- package/dest/{tx_validator → msg_validators/tx_validator}/metadata_validator.js +1 -1
- package/dest/msg_validators/tx_validator/tx_proof_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +29 -0
- package/dest/services/libp2p/libp2p_service.d.ts +54 -7
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +129 -12
- package/dest/services/peer-scoring/peer_scoring.d.ts +1 -17
- package/dest/services/peer-scoring/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-scoring/peer_scoring.js +6 -23
- package/dest/services/peer_manager.d.ts +1 -2
- package/dest/services/peer_manager.d.ts.map +1 -1
- package/dest/services/peer_manager.js +41 -1
- package/dest/services/reqresp/rate_limiter/rate_limiter.d.ts +0 -5
- package/dest/services/reqresp/rate_limiter/rate_limiter.d.ts.map +1 -1
- package/dest/services/reqresp/rate_limiter/rate_limiter.js +7 -2
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +2 -2
- package/package.json +12 -10
- package/src/client/factory.ts +97 -0
- package/src/client/index.ts +1 -95
- package/src/config.ts +1 -1
- package/src/index.ts +1 -1
- package/src/mocks/index.ts +3 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +26 -0
- package/src/msg_validators/attestation_validator/index.ts +1 -0
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +29 -0
- package/src/msg_validators/block_proposal_validator/index.ts +1 -0
- package/src/msg_validators/epoch_proof_quote_validator/epoch_proof_quote_validator.ts +22 -0
- package/src/msg_validators/epoch_proof_quote_validator/index.ts +1 -0
- package/src/msg_validators/index.ts +3 -0
- package/src/services/libp2p/libp2p_service.ts +146 -7
- package/src/services/peer-scoring/peer_scoring.ts +5 -22
- package/src/services/peer_manager.ts +46 -2
- package/src/services/reqresp/rate_limiter/rate_limiter.ts +2 -1
- package/src/services/reqresp/reqresp.ts +1 -1
- package/dest/tx_validator/aggregate_tx_validator.d.ts.map +0 -1
- package/dest/tx_validator/data_validator.d.ts.map +0 -1
- package/dest/tx_validator/double_spend_validator.d.ts.map +0 -1
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/metadata_validator.d.ts.map +0 -1
- package/dest/tx_validator/tx_proof_validator.d.ts.map +0 -1
- package/dest/tx_validator/tx_proof_validator.js +0 -29
- /package/dest/{tx_validator → msg_validators/tx_validator}/aggregate_tx_validator.d.ts +0 -0
- /package/dest/{tx_validator → msg_validators/tx_validator}/data_validator.d.ts +0 -0
- /package/dest/{tx_validator → msg_validators/tx_validator}/double_spend_validator.d.ts +0 -0
- /package/dest/{tx_validator → msg_validators/tx_validator}/index.d.ts +0 -0
- /package/dest/{tx_validator → msg_validators/tx_validator}/metadata_validator.d.ts +0 -0
- /package/dest/{tx_validator → msg_validators/tx_validator}/tx_proof_validator.d.ts +0 -0
- /package/src/{tx_validator → msg_validators/tx_validator}/aggregate_tx_validator.ts +0 -0
- /package/src/{tx_validator → msg_validators/tx_validator}/data_validator.ts +0 -0
- /package/src/{tx_validator → msg_validators/tx_validator}/double_spend_validator.ts +0 -0
- /package/src/{tx_validator → msg_validators/tx_validator}/index.ts +0 -0
- /package/src/{tx_validator → msg_validators/tx_validator}/metadata_validator.ts +0 -0
- /package/src/{tx_validator → msg_validators/tx_validator}/tx_proof_validator.ts +0 -0
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type Gossipable,
|
|
7
7
|
type L2BlockSource,
|
|
8
8
|
MerkleTreeId,
|
|
9
|
+
PeerErrorSeverity,
|
|
9
10
|
type PeerInfo,
|
|
10
11
|
type RawGossipMessage,
|
|
11
12
|
TopicTypeMap,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
} from '@aztec/circuit-types';
|
|
18
19
|
import { P2PClientType } from '@aztec/circuit-types';
|
|
19
20
|
import { Fr } from '@aztec/circuits.js';
|
|
21
|
+
import { type EpochCache } from '@aztec/epoch-cache';
|
|
20
22
|
import { createLogger } from '@aztec/foundation/log';
|
|
21
23
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
22
24
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
@@ -37,16 +39,17 @@ import { createLibp2p } from 'libp2p';
|
|
|
37
39
|
|
|
38
40
|
import { type P2PConfig } from '../../config.js';
|
|
39
41
|
import { type MemPools } from '../../mem_pools/interface.js';
|
|
42
|
+
import { EpochProofQuoteValidator } from '../../msg_validators/epoch_proof_quote_validator/index.js';
|
|
43
|
+
import { AttestationValidator, BlockProposalValidator } from '../../msg_validators/index.js';
|
|
40
44
|
import {
|
|
41
45
|
DataTxValidator,
|
|
42
46
|
DoubleSpendTxValidator,
|
|
43
47
|
MetadataTxValidator,
|
|
44
48
|
TxProofValidator,
|
|
45
|
-
} from '../../tx_validator/index.js';
|
|
49
|
+
} from '../../msg_validators/tx_validator/index.js';
|
|
46
50
|
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
47
51
|
import { AztecDatastore } from '../data_store.js';
|
|
48
52
|
import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
49
|
-
import { PeerErrorSeverity } from '../peer-scoring/peer_scoring.js';
|
|
50
53
|
import { PeerManager } from '../peer_manager.js';
|
|
51
54
|
import { pingHandler, statusHandler } from '../reqresp/handlers.js';
|
|
52
55
|
import {
|
|
@@ -85,6 +88,11 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
85
88
|
private peerManager: PeerManager;
|
|
86
89
|
private discoveryRunningPromise?: RunningPromise;
|
|
87
90
|
|
|
91
|
+
// Message validators
|
|
92
|
+
private attestationValidator: AttestationValidator;
|
|
93
|
+
private blockProposalValidator: BlockProposalValidator;
|
|
94
|
+
private epochProofQuoteValidator: EpochProofQuoteValidator;
|
|
95
|
+
|
|
88
96
|
// Request and response sub service
|
|
89
97
|
public reqresp: ReqResp;
|
|
90
98
|
|
|
@@ -102,6 +110,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
102
110
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
103
111
|
private mempools: MemPools<T>,
|
|
104
112
|
private l2BlockSource: L2BlockSource,
|
|
113
|
+
private epochCache: EpochCache,
|
|
105
114
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
106
115
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
107
116
|
private telemetry: TelemetryClient,
|
|
@@ -117,6 +126,10 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
117
126
|
this.node.services.pubsub.score.params.appSpecificWeight = 10;
|
|
118
127
|
this.reqresp = new ReqResp(config, node, this.peerManager);
|
|
119
128
|
|
|
129
|
+
this.attestationValidator = new AttestationValidator(epochCache);
|
|
130
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache);
|
|
131
|
+
this.epochProofQuoteValidator = new EpochProofQuoteValidator(epochCache);
|
|
132
|
+
|
|
120
133
|
this.blockReceivedCallback = (block: BlockProposal): Promise<BlockAttestation | undefined> => {
|
|
121
134
|
this.logger.verbose(
|
|
122
135
|
`[WARNING] handler not yet registered: Block received callback not set. Received block ${block.p2pMessageIdentifier()} from peer.`,
|
|
@@ -153,7 +166,17 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
153
166
|
}
|
|
154
167
|
|
|
155
168
|
// Add p2p topic validators
|
|
156
|
-
|
|
169
|
+
// As they are stored within a kv pair, there is no need to register them conditionally
|
|
170
|
+
// based on the client type
|
|
171
|
+
const topicValidators = {
|
|
172
|
+
[Tx.p2pTopic]: this.validatePropagatedTxFromMessage.bind(this),
|
|
173
|
+
[BlockAttestation.p2pTopic]: this.validatePropagatedAttestationFromMessage.bind(this),
|
|
174
|
+
[BlockProposal.p2pTopic]: this.validatePropagatedBlockFromMessage.bind(this),
|
|
175
|
+
[EpochProofQuote.p2pTopic]: this.validatePropagatedEpochProofQuoteFromMessage.bind(this),
|
|
176
|
+
};
|
|
177
|
+
for (const [topic, validator] of Object.entries(topicValidators)) {
|
|
178
|
+
this.node.services.pubsub.topicValidators.set(topic, validator);
|
|
179
|
+
}
|
|
157
180
|
|
|
158
181
|
// add GossipSub listener
|
|
159
182
|
this.node.services.pubsub.addEventListener('gossipsub:message', async e => {
|
|
@@ -215,6 +238,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
215
238
|
peerId: PeerId,
|
|
216
239
|
mempools: MemPools<T>,
|
|
217
240
|
l2BlockSource: L2BlockSource,
|
|
241
|
+
epochCache: EpochCache,
|
|
218
242
|
proofVerifier: ClientProtocolCircuitVerifier,
|
|
219
243
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
220
244
|
store: AztecKVStore,
|
|
@@ -329,6 +353,7 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
329
353
|
peerDiscoveryService,
|
|
330
354
|
mempools,
|
|
331
355
|
l2BlockSource,
|
|
356
|
+
epochCache,
|
|
332
357
|
proofVerifier,
|
|
333
358
|
worldStateSynchronizer,
|
|
334
359
|
telemetry,
|
|
@@ -537,6 +562,12 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
537
562
|
return true;
|
|
538
563
|
}
|
|
539
564
|
|
|
565
|
+
/**
|
|
566
|
+
* Validate a tx from a peer.
|
|
567
|
+
* @param propagationSource - The peer ID of the peer that sent the tx.
|
|
568
|
+
* @param msg - The tx message.
|
|
569
|
+
* @returns True if the tx is valid, false otherwise.
|
|
570
|
+
*/
|
|
540
571
|
private async validatePropagatedTxFromMessage(
|
|
541
572
|
propagationSource: PeerId,
|
|
542
573
|
msg: Message,
|
|
@@ -551,11 +582,62 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
551
582
|
}
|
|
552
583
|
|
|
553
584
|
/**
|
|
554
|
-
* Validate
|
|
555
|
-
* @param
|
|
556
|
-
* @param
|
|
557
|
-
* @returns True if the
|
|
585
|
+
* Validate an attestation from a peer.
|
|
586
|
+
* @param propagationSource - The peer ID of the peer that sent the attestation.
|
|
587
|
+
* @param msg - The attestation message.
|
|
588
|
+
* @returns True if the attestation is valid, false otherwise.
|
|
589
|
+
*/
|
|
590
|
+
private async validatePropagatedAttestationFromMessage(
|
|
591
|
+
propagationSource: PeerId,
|
|
592
|
+
msg: Message,
|
|
593
|
+
): Promise<TopicValidatorResult> {
|
|
594
|
+
const attestation = BlockAttestation.fromBuffer(Buffer.from(msg.data));
|
|
595
|
+
const isValid = await this.validateAttestation(propagationSource, attestation);
|
|
596
|
+
this.logger.trace(`validatePropagatedAttestation: ${isValid}`, {
|
|
597
|
+
[Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toString(),
|
|
598
|
+
[Attributes.P2P_ID]: propagationSource.toString(),
|
|
599
|
+
});
|
|
600
|
+
return isValid ? TopicValidatorResult.Accept : TopicValidatorResult.Reject;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Validate a block proposal from a peer.
|
|
605
|
+
* @param propagationSource - The peer ID of the peer that sent the block.
|
|
606
|
+
* @param msg - The block proposal message.
|
|
607
|
+
* @returns True if the block proposal is valid, false otherwise.
|
|
558
608
|
*/
|
|
609
|
+
private async validatePropagatedBlockFromMessage(
|
|
610
|
+
propagationSource: PeerId,
|
|
611
|
+
msg: Message,
|
|
612
|
+
): Promise<TopicValidatorResult> {
|
|
613
|
+
const block = BlockProposal.fromBuffer(Buffer.from(msg.data));
|
|
614
|
+
const isValid = await this.validateBlockProposal(propagationSource, block);
|
|
615
|
+
this.logger.trace(`validatePropagatedBlock: ${isValid}`, {
|
|
616
|
+
[Attributes.SLOT_NUMBER]: block.payload.header.globalVariables.slotNumber.toString(),
|
|
617
|
+
[Attributes.P2P_ID]: propagationSource.toString(),
|
|
618
|
+
});
|
|
619
|
+
return isValid ? TopicValidatorResult.Accept : TopicValidatorResult.Reject;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Validate an epoch proof quote from a peer.
|
|
624
|
+
* @param propagationSource - The peer ID of the peer that sent the epoch proof quote.
|
|
625
|
+
* @param msg - The epoch proof quote message.
|
|
626
|
+
* @returns True if the epoch proof quote is valid, false otherwise.
|
|
627
|
+
*/
|
|
628
|
+
private async validatePropagatedEpochProofQuoteFromMessage(
|
|
629
|
+
propagationSource: PeerId,
|
|
630
|
+
msg: Message,
|
|
631
|
+
): Promise<TopicValidatorResult> {
|
|
632
|
+
const epochProofQuote = EpochProofQuote.fromBuffer(Buffer.from(msg.data));
|
|
633
|
+
const isValid = await this.validateEpochProofQuote(propagationSource, epochProofQuote);
|
|
634
|
+
this.logger.trace(`validatePropagatedEpochProofQuote: ${isValid}`, {
|
|
635
|
+
[Attributes.EPOCH_NUMBER]: epochProofQuote.payload.epochToProve.toString(),
|
|
636
|
+
[Attributes.P2P_ID]: propagationSource.toString(),
|
|
637
|
+
});
|
|
638
|
+
return isValid ? TopicValidatorResult.Accept : TopicValidatorResult.Reject;
|
|
639
|
+
}
|
|
640
|
+
|
|
559
641
|
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
560
642
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
561
643
|
}))
|
|
@@ -687,6 +769,63 @@ export class LibP2PService<T extends P2PClientType> extends WithTracer implement
|
|
|
687
769
|
return true;
|
|
688
770
|
}
|
|
689
771
|
|
|
772
|
+
/**
|
|
773
|
+
* Validate an attestation.
|
|
774
|
+
*
|
|
775
|
+
* @param attestation - The attestation to validate.
|
|
776
|
+
* @returns True if the attestation is valid, false otherwise.
|
|
777
|
+
*/
|
|
778
|
+
@trackSpan('Libp2pService.validateAttestation', (_peerId, attestation) => ({
|
|
779
|
+
[Attributes.SLOT_NUMBER]: attestation.payload.header.globalVariables.slotNumber.toString(),
|
|
780
|
+
}))
|
|
781
|
+
public async validateAttestation(peerId: PeerId, attestation: BlockAttestation): Promise<boolean> {
|
|
782
|
+
const severity = await this.attestationValidator.validate(attestation);
|
|
783
|
+
if (severity) {
|
|
784
|
+
this.peerManager.penalizePeer(peerId, severity);
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Validate a block proposal.
|
|
793
|
+
*
|
|
794
|
+
* @param block - The block proposal to validate.
|
|
795
|
+
* @returns True if the block proposal is valid, false otherwise.
|
|
796
|
+
*/
|
|
797
|
+
@trackSpan('Libp2pService.validateBlockProposal', (_peerId, block) => ({
|
|
798
|
+
[Attributes.SLOT_NUMBER]: block.payload.header.globalVariables.slotNumber.toString(),
|
|
799
|
+
}))
|
|
800
|
+
public async validateBlockProposal(peerId: PeerId, block: BlockProposal): Promise<boolean> {
|
|
801
|
+
const severity = await this.blockProposalValidator.validate(block);
|
|
802
|
+
if (severity) {
|
|
803
|
+
this.peerManager.penalizePeer(peerId, severity);
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Validate an epoch proof quote.
|
|
812
|
+
*
|
|
813
|
+
* @param epochProofQuote - The epoch proof quote to validate.
|
|
814
|
+
* @returns True if the epoch proof quote is valid, false otherwise.
|
|
815
|
+
*/
|
|
816
|
+
@trackSpan('Libp2pService.validateEpochProofQuote', (_peerId, epochProofQuote) => ({
|
|
817
|
+
[Attributes.EPOCH_NUMBER]: epochProofQuote.payload.epochToProve.toString(),
|
|
818
|
+
}))
|
|
819
|
+
public async validateEpochProofQuote(peerId: PeerId, epochProofQuote: EpochProofQuote): Promise<boolean> {
|
|
820
|
+
const severity = await this.epochProofQuoteValidator.validate(epochProofQuote);
|
|
821
|
+
if (severity) {
|
|
822
|
+
this.peerManager.penalizePeer(peerId, severity);
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
828
|
+
|
|
690
829
|
public getPeerScore(peerId: PeerId): number {
|
|
691
830
|
return this.node.services.pubsub.score.score(peerId.toString());
|
|
692
831
|
}
|
|
@@ -1,29 +1,12 @@
|
|
|
1
|
+
import { PeerErrorSeverity } from '@aztec/circuit-types';
|
|
1
2
|
import { median } from '@aztec/foundation/collection';
|
|
2
3
|
|
|
3
4
|
import { type P2PConfig } from '../../config.js';
|
|
4
5
|
|
|
5
|
-
export enum PeerErrorSeverity {
|
|
6
|
-
/**
|
|
7
|
-
* Not malicious action, but it must not be tolerated
|
|
8
|
-
* ~2 occurrences will get the peer banned
|
|
9
|
-
*/
|
|
10
|
-
LowToleranceError = 'LowToleranceError',
|
|
11
|
-
/**
|
|
12
|
-
* Negative action that can be tolerated only sometimes
|
|
13
|
-
* ~10 occurrences will get the peer banned
|
|
14
|
-
*/
|
|
15
|
-
MidToleranceError = 'MidToleranceError',
|
|
16
|
-
/**
|
|
17
|
-
* Some error that can be tolerated multiple times
|
|
18
|
-
* ~50 occurrences will get the peer banned
|
|
19
|
-
*/
|
|
20
|
-
HighToleranceError = 'HighToleranceError',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
6
|
const DefaultPeerPenalties = {
|
|
24
|
-
[PeerErrorSeverity.LowToleranceError]:
|
|
7
|
+
[PeerErrorSeverity.LowToleranceError]: 50,
|
|
25
8
|
[PeerErrorSeverity.MidToleranceError]: 10,
|
|
26
|
-
[PeerErrorSeverity.HighToleranceError]:
|
|
9
|
+
[PeerErrorSeverity.HighToleranceError]: 2,
|
|
27
10
|
};
|
|
28
11
|
|
|
29
12
|
export class PeerScoring {
|
|
@@ -37,11 +20,11 @@ export class PeerScoring {
|
|
|
37
20
|
const orderedValues = config.peerPenaltyValues?.sort((a, b) => a - b);
|
|
38
21
|
this.peerPenalties = {
|
|
39
22
|
[PeerErrorSeverity.HighToleranceError]:
|
|
40
|
-
orderedValues?.[0] ?? DefaultPeerPenalties[PeerErrorSeverity.
|
|
23
|
+
orderedValues?.[0] ?? DefaultPeerPenalties[PeerErrorSeverity.HighToleranceError],
|
|
41
24
|
[PeerErrorSeverity.MidToleranceError]:
|
|
42
25
|
orderedValues?.[1] ?? DefaultPeerPenalties[PeerErrorSeverity.MidToleranceError],
|
|
43
26
|
[PeerErrorSeverity.LowToleranceError]:
|
|
44
|
-
orderedValues?.[2] ?? DefaultPeerPenalties[PeerErrorSeverity.
|
|
27
|
+
orderedValues?.[2] ?? DefaultPeerPenalties[PeerErrorSeverity.LowToleranceError],
|
|
45
28
|
};
|
|
46
29
|
}
|
|
47
30
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PeerInfo } from '@aztec/circuit-types';
|
|
1
|
+
import { type PeerErrorSeverity, type PeerInfo } from '@aztec/circuit-types';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ import { inspect } from 'util';
|
|
|
9
9
|
|
|
10
10
|
import { type P2PConfig } from '../config.js';
|
|
11
11
|
import { type PubSubLibp2p } from '../util.js';
|
|
12
|
-
import {
|
|
12
|
+
import { PeerScoring } from './peer-scoring/peer_scoring.js';
|
|
13
13
|
import { type PeerDiscoveryService } from './service.js';
|
|
14
14
|
|
|
15
15
|
const MAX_DIAL_ATTEMPTS = 3;
|
|
@@ -233,6 +233,7 @@ export class PeerManager implements Traceable {
|
|
|
233
233
|
this.logger.trace(`Failed to dial peer ${id} (attempt ${peer.dialAttempts})`, { error: inspect(error) });
|
|
234
234
|
this.cachedPeers.set(id, peer);
|
|
235
235
|
} else {
|
|
236
|
+
formatLibp2pDialError(error as Error);
|
|
236
237
|
this.logger.debug(`Failed to dial peer ${id} (dropping)`, { error: inspect(error) });
|
|
237
238
|
this.cachedPeers.delete(id);
|
|
238
239
|
}
|
|
@@ -267,3 +268,46 @@ export class PeerManager implements Traceable {
|
|
|
267
268
|
}
|
|
268
269
|
}
|
|
269
270
|
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* copied from github.com/ChainSafe/lodestar
|
|
274
|
+
* libp2p errors with extremely noisy errors here, which are deeply nested taking 30-50 lines.
|
|
275
|
+
* Some known errors:
|
|
276
|
+
* ```
|
|
277
|
+
* Error: The operation was aborted
|
|
278
|
+
* Error: stream ended before 1 bytes became available
|
|
279
|
+
* Error: Error occurred during XX handshake: Error occurred while verifying signed payload: Peer ID doesn't match libp2p public key
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* Also the error's message is not properly formatted, where the error message is indented and includes the full stack
|
|
283
|
+
* ```
|
|
284
|
+
* {
|
|
285
|
+
* emessage: '\n' +
|
|
286
|
+
* ' Error: stream ended before 1 bytes became available\n' +
|
|
287
|
+
* ' at /home/lion/Code/eth2.0/lodestar/node_modules/it-reader/index.js:37:9\n' +
|
|
288
|
+
* ' at runMicrotasks (<anonymous>)\n' +
|
|
289
|
+
* ' at decoder (/home/lion/Code/eth2.0/lodestar/node_modules/it-length-prefixed/src/decode.js:113:22)\n' +
|
|
290
|
+
* ' at first (/home/lion/Code/eth2.0/lodestar/node_modules/it-first/index.js:11:20)\n' +
|
|
291
|
+
* ' at Object.exports.read (/home/lion/Code/eth2.0/lodestar/node_modules/multistream-select/src/multistream.js:31:15)\n' +
|
|
292
|
+
* ' at module.exports (/home/lion/Code/eth2.0/lodestar/node_modules/multistream-select/src/select.js:21:19)\n' +
|
|
293
|
+
* ' at Upgrader._encryptOutbound (/home/lion/Code/eth2.0/lodestar/node_modules/libp2p/src/upgrader.js:397:36)\n' +
|
|
294
|
+
* ' at Upgrader.upgradeOutbound (/home/lion/Code/eth2.0/lodestar/node_modules/libp2p/src/upgrader.js:176:11)\n' +
|
|
295
|
+
* ' at ClassIsWrapper.dial (/home/lion/Code/eth2.0/lodestar/node_modules/libp2p-tcp/src/index.js:49:18)'
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* Tracking issue https://github.com/libp2p/js-libp2p/issues/996
|
|
300
|
+
*/
|
|
301
|
+
function formatLibp2pDialError(e: Error): void {
|
|
302
|
+
const errorMessage = e.message.trim();
|
|
303
|
+
const newlineIndex = errorMessage.indexOf('\n');
|
|
304
|
+
e.message = newlineIndex !== -1 ? errorMessage.slice(0, newlineIndex) : errorMessage;
|
|
305
|
+
|
|
306
|
+
if (
|
|
307
|
+
e.message.includes('The operation was aborted') ||
|
|
308
|
+
e.message.includes('stream ended before 1 bytes became available') ||
|
|
309
|
+
e.message.includes('The operation was aborted')
|
|
310
|
+
) {
|
|
311
|
+
e.stack = undefined;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -3,9 +3,10 @@
|
|
|
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/circuit-types';
|
|
7
|
+
|
|
6
8
|
import { type PeerId } from '@libp2p/interface';
|
|
7
9
|
|
|
8
|
-
import { PeerErrorSeverity } from '../../peer-scoring/peer_scoring.js';
|
|
9
10
|
import { type PeerManager } from '../../peer_manager.js';
|
|
10
11
|
import { type ReqRespSubProtocol, type ReqRespSubProtocolRateLimits } from '../interface.js';
|
|
11
12
|
import { DEFAULT_RATE_LIMITS } from './rate_limits.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// @attribution: lodestar impl for inspiration
|
|
2
|
+
import { PeerErrorSeverity } from '@aztec/circuit-types';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { executeTimeoutWithCustomError } from '@aztec/foundation/timer';
|
|
4
5
|
|
|
@@ -13,7 +14,6 @@ import {
|
|
|
13
14
|
InvalidResponseError,
|
|
14
15
|
} from '../../errors/reqresp.error.js';
|
|
15
16
|
import { SnappyTransform } from '../encoding.js';
|
|
16
|
-
import { PeerErrorSeverity } from '../peer-scoring/peer_scoring.js';
|
|
17
17
|
import { type PeerManager } from '../peer_manager.js';
|
|
18
18
|
import { type P2PReqRespConfig } from './config.js';
|
|
19
19
|
import {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate_tx_validator.d.ts","sourceRoot":"","sources":["../../src/tx_validator/aggregate_tx_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,EAAE,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnF,qBAAa,oBAAoB,CAAC,CAAC,SAAS,EAAE,GAAG,WAAW,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;gBAEzE,GAAG,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE;IAQrC,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;IAcjF,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAS1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data_validator.d.ts","sourceRoot":"","sources":["../../src/tx_validator/data_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAG5D,qBAAa,eAAgB,YAAW,WAAW,CAAC,EAAE,CAAC;;IAGrD,WAAW,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAenE,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CA2CrC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"double_spend_validator.d.ts","sourceRoot":"","sources":["../../src/tx_validator/double_spend_validator.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,KAAK,EAAM,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxE,MAAM,WAAW,eAAe;IAC9B,mBAAmB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;CAChF;AAED,qBAAa,sBAAsB,CAAC,CAAC,SAAS,KAAK,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;IAI9B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;gBAApE,eAAe,EAAE,eAAe,EAAmB,iBAAiB,GAAE,OAAc;IAI1F,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;IAiBtE,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAoCpC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tx_validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metadata_validator.d.ts","sourceRoot":"","sources":["../../src/tx_validator/metadata_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAM,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAG7C,qBAAa,mBAAmB,CAAC,CAAC,SAAS,KAAK,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;IAG7D,OAAO,CAAC,OAAO;IAAM,OAAO,CAAC,WAAW;gBAAhC,OAAO,EAAE,EAAE,EAAU,WAAW,EAAE,EAAE;IAExD,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;IAoBhE,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CA+BpC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tx_proof_validator.d.ts","sourceRoot":"","sources":["../../src/tx_validator/tx_proof_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,6BAA6B,EAAE,EAAE,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGhG,qBAAa,gBAAiB,YAAW,WAAW,CAAC,EAAE,CAAC;;IAG1C,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,6BAA6B;IAErD,WAAW,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAgBzE,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAGrC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var _TxProofValidator_log;
|
|
2
|
-
import { __classPrivateFieldGet } from "tslib";
|
|
3
|
-
import { Tx } from '@aztec/circuit-types';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
export class TxProofValidator {
|
|
6
|
-
constructor(verifier) {
|
|
7
|
-
this.verifier = verifier;
|
|
8
|
-
_TxProofValidator_log.set(this, createLogger('p2p:tx_validator:private_proof'));
|
|
9
|
-
}
|
|
10
|
-
async validateTxs(txs) {
|
|
11
|
-
const validTxs = [];
|
|
12
|
-
const invalidTxs = [];
|
|
13
|
-
for (const tx of txs) {
|
|
14
|
-
if (await this.verifier.verifyProof(tx)) {
|
|
15
|
-
validTxs.push(tx);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
__classPrivateFieldGet(this, _TxProofValidator_log, "f").warn(`Rejecting tx ${Tx.getHash(tx)} for invalid proof`);
|
|
19
|
-
invalidTxs.push(tx);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return [validTxs, invalidTxs];
|
|
23
|
-
}
|
|
24
|
-
validateTx(tx) {
|
|
25
|
-
return this.verifier.verifyProof(tx);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
_TxProofValidator_log = new WeakMap();
|
|
29
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfcHJvb2ZfdmFsaWRhdG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3R4X3ZhbGlkYXRvci90eF9wcm9vZl92YWxpZGF0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxPQUFPLEVBQXNDLEVBQUUsRUFBb0IsTUFBTSxzQkFBc0IsQ0FBQztBQUNoRyxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFckQsTUFBTSxPQUFPLGdCQUFnQjtJQUczQixZQUFvQixRQUF1QztRQUF2QyxhQUFRLEdBQVIsUUFBUSxDQUErQjtRQUYzRCxnQ0FBTyxZQUFZLENBQUMsZ0NBQWdDLENBQUMsRUFBQztJQUVRLENBQUM7SUFFL0QsS0FBSyxDQUFDLFdBQVcsQ0FBQyxHQUFTO1FBQ3pCLE1BQU0sUUFBUSxHQUFTLEVBQUUsQ0FBQztRQUMxQixNQUFNLFVBQVUsR0FBUyxFQUFFLENBQUM7UUFFNUIsS0FBSyxNQUFNLEVBQUUsSUFBSSxHQUFHLEVBQUUsQ0FBQztZQUNyQixJQUFJLE1BQU0sSUFBSSxDQUFDLFFBQVEsQ0FBQyxXQUFXLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQztnQkFDeEMsUUFBUSxDQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQztZQUNwQixDQUFDO2lCQUFNLENBQUM7Z0JBQ04sdUJBQUEsSUFBSSw2QkFBSyxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsRUFBRSxDQUFDLE9BQU8sQ0FBQyxFQUFFLENBQUMsb0JBQW9CLENBQUMsQ0FBQztnQkFDbkUsVUFBVSxDQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQztZQUN0QixDQUFDO1FBQ0gsQ0FBQztRQUVELE9BQU8sQ0FBQyxRQUFRLEVBQUUsVUFBVSxDQUFDLENBQUM7SUFDaEMsQ0FBQztJQUVELFVBQVUsQ0FBQyxFQUFNO1FBQ2YsT0FBTyxJQUFJLENBQUMsUUFBUSxDQUFDLFdBQVcsQ0FBQyxFQUFFLENBQUMsQ0FBQztJQUN2QyxDQUFDO0NBQ0YifQ==
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|