@aztec/p2p 0.67.1 → 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/bootstrap/bootstrap.js +2 -2
- 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 -15
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +2 -37
- package/dest/client/p2p_client.d.ts +6 -6
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +12 -11
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -3
- package/dest/errors/reqresp.error.d.ts +12 -1
- package/dest/errors/reqresp.error.d.ts.map +1 -1
- package/dest/errors/reqresp.error.js +15 -2
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -3
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +9 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +3 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +171 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +29 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +114 -0
- package/dest/mem_pools/interface.d.ts +4 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mocks/index.d.ts +7 -6
- package/dest/mocks/index.d.ts.map +1 -1
- package/dest/mocks/index.js +8 -8
- 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/{tx_validator → msg_validators/tx_validator}/aggregate_tx_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +34 -0
- 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/{tx_validator → msg_validators/tx_validator}/double_spend_validator.d.ts +3 -2
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/double_spend_validator.js +56 -0
- 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/data_store.d.ts.map +1 -0
- package/dest/services/data_store.js +188 -0
- package/dest/{service → services/discv5}/discV5_service.d.ts +2 -2
- package/dest/services/discv5/discV5_service.d.ts.map +1 -0
- package/dest/services/discv5/discV5_service.js +144 -0
- package/dest/services/dummy_service.d.ts.map +1 -0
- package/dest/{service → services}/dummy_service.js +1 -1
- package/dest/{service → services}/encoding.d.ts +5 -0
- package/dest/services/encoding.d.ts.map +1 -0
- package/dest/services/encoding.js +65 -0
- package/dest/services/index.d.ts +3 -0
- package/dest/services/index.d.ts.map +1 -0
- package/dest/services/index.js +3 -0
- package/dest/services/libp2p/libp2p_service.d.ts +221 -0
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -0
- package/dest/services/libp2p/libp2p_service.js +690 -0
- package/dest/services/peer-scoring/peer_scoring.d.ts +19 -0
- package/dest/services/peer-scoring/peer_scoring.d.ts.map +1 -0
- package/dest/services/peer-scoring/peer_scoring.js +55 -0
- package/dest/{service → services}/peer_manager.d.ts +5 -4
- package/dest/services/peer_manager.d.ts.map +1 -0
- package/dest/services/peer_manager.js +270 -0
- package/dest/services/reqresp/config.d.ts.map +1 -0
- package/dest/{service → services}/reqresp/config.js +1 -1
- package/dest/services/reqresp/handlers.d.ts.map +1 -0
- package/dest/{service → services}/reqresp/handlers.js +1 -1
- package/dest/services/reqresp/index.d.ts.map +1 -0
- package/dest/{service → services}/reqresp/index.js +1 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -0
- package/dest/{service → services}/reqresp/interface.js +1 -1
- package/dest/services/reqresp/rate_limiter/index.d.ts.map +1 -0
- package/dest/{service → services}/reqresp/rate_limiter/index.js +1 -1
- package/dest/{service → services}/reqresp/rate_limiter/rate_limiter.d.ts +0 -5
- package/dest/services/reqresp/rate_limiter/rate_limiter.d.ts.map +1 -0
- package/dest/{service → services}/reqresp/rate_limiter/rate_limiter.js +7 -2
- package/dest/services/reqresp/rate_limiter/rate_limits.d.ts.map +1 -0
- package/dest/{service → services}/reqresp/rate_limiter/rate_limits.js +1 -1
- package/dest/{service → services}/reqresp/reqresp.d.ts +16 -0
- package/dest/services/reqresp/reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/reqresp.js +279 -0
- package/dest/services/service.d.ts.map +1 -0
- package/dest/{service → services}/service.js +1 -1
- package/package.json +13 -10
- package/src/bootstrap/bootstrap.ts +1 -1
- package/src/client/factory.ts +97 -0
- package/src/client/index.ts +1 -73
- package/src/client/p2p_client.ts +28 -15
- package/src/config.ts +2 -2
- package/src/errors/reqresp.error.ts +15 -1
- package/src/index.ts +2 -2
- package/src/mem_pools/attestation_pool/attestation_pool.ts +10 -0
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +237 -0
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +153 -0
- package/src/mem_pools/interface.ts +5 -3
- package/src/mocks/index.ts +16 -10
- 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/{tx_validator → msg_validators/tx_validator}/aggregate_tx_validator.ts +5 -3
- package/src/{tx_validator → msg_validators/tx_validator}/double_spend_validator.ts +6 -8
- package/src/{service → services/discv5}/discV5_service.ts +3 -3
- package/src/{service → services}/encoding.ts +21 -3
- package/src/services/index.ts +2 -0
- package/src/{service → services/libp2p}/libp2p_service.ts +330 -85
- package/src/{service → services/peer-scoring}/peer_scoring.ts +6 -23
- package/src/{service → services}/peer_manager.ts +50 -3
- package/src/{service → services}/reqresp/rate_limiter/rate_limiter.ts +2 -1
- package/src/{service → services}/reqresp/reqresp.ts +83 -17
- package/dest/service/data_store.d.ts.map +0 -1
- package/dest/service/data_store.js +0 -188
- package/dest/service/discV5_service.d.ts.map +0 -1
- package/dest/service/discV5_service.js +0 -144
- package/dest/service/dummy_service.d.ts.map +0 -1
- package/dest/service/encoding.d.ts.map +0 -1
- package/dest/service/encoding.js +0 -49
- package/dest/service/index.d.ts +0 -3
- package/dest/service/index.d.ts.map +0 -1
- package/dest/service/index.js +0 -3
- package/dest/service/libp2p_service.d.ts +0 -136
- package/dest/service/libp2p_service.d.ts.map +0 -1
- package/dest/service/libp2p_service.js +0 -500
- package/dest/service/peer_manager.d.ts.map +0 -1
- package/dest/service/peer_manager.js +0 -214
- package/dest/service/peer_scoring.d.ts +0 -35
- package/dest/service/peer_scoring.d.ts.map +0 -1
- package/dest/service/peer_scoring.js +0 -72
- package/dest/service/reqresp/config.d.ts.map +0 -1
- package/dest/service/reqresp/handlers.d.ts.map +0 -1
- package/dest/service/reqresp/index.d.ts.map +0 -1
- package/dest/service/reqresp/interface.d.ts.map +0 -1
- package/dest/service/reqresp/rate_limiter/index.d.ts.map +0 -1
- package/dest/service/reqresp/rate_limiter/rate_limiter.d.ts.map +0 -1
- package/dest/service/reqresp/rate_limiter/rate_limits.d.ts.map +0 -1
- package/dest/service/reqresp/reqresp.d.ts.map +0 -1
- package/dest/service/reqresp/reqresp.js +0 -230
- package/dest/service/service.d.ts.map +0 -1
- package/dest/tx_validator/aggregate_tx_validator.d.ts.map +0 -1
- package/dest/tx_validator/aggregate_tx_validator.js +0 -32
- 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/double_spend_validator.js +0 -56
- 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/src/service/index.ts +0 -2
- /package/dest/{tx_validator → msg_validators/tx_validator}/data_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/dest/{service → services}/data_store.d.ts +0 -0
- /package/dest/{service → services}/dummy_service.d.ts +0 -0
- /package/dest/{service → services}/reqresp/config.d.ts +0 -0
- /package/dest/{service → services}/reqresp/handlers.d.ts +0 -0
- /package/dest/{service → services}/reqresp/index.d.ts +0 -0
- /package/dest/{service → services}/reqresp/interface.d.ts +0 -0
- /package/dest/{service → services}/reqresp/rate_limiter/index.d.ts +0 -0
- /package/dest/{service → services}/reqresp/rate_limiter/rate_limits.d.ts +0 -0
- /package/dest/{service → services}/service.d.ts +0 -0
- /package/src/{tx_validator → msg_validators/tx_validator}/data_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
- /package/src/{service → services}/data_store.ts +0 -0
- /package/src/{service → services}/dummy_service.ts +0 -0
- /package/src/{service → services}/reqresp/config.ts +0 -0
- /package/src/{service → services}/reqresp/handlers.ts +0 -0
- /package/src/{service → services}/reqresp/index.ts +0 -0
- /package/src/{service → services}/reqresp/interface.ts +0 -0
- /package/src/{service → services}/reqresp/rate_limiter/index.ts +0 -0
- /package/src/{service → services}/reqresp/rate_limiter/rate_limits.ts +0 -0
- /package/src/{service → services}/service.ts +0 -0
|
@@ -6,16 +6,19 @@ import {
|
|
|
6
6
|
type Gossipable,
|
|
7
7
|
type L2BlockSource,
|
|
8
8
|
MerkleTreeId,
|
|
9
|
+
PeerErrorSeverity,
|
|
9
10
|
type PeerInfo,
|
|
10
11
|
type RawGossipMessage,
|
|
11
|
-
TopicType,
|
|
12
12
|
TopicTypeMap,
|
|
13
13
|
Tx,
|
|
14
14
|
TxHash,
|
|
15
15
|
type WorldStateSynchronizer,
|
|
16
|
+
getTopicTypeForClientType,
|
|
16
17
|
metricsTopicStrToLabels,
|
|
17
18
|
} from '@aztec/circuit-types';
|
|
19
|
+
import { P2PClientType } from '@aztec/circuit-types';
|
|
18
20
|
import { Fr } from '@aztec/circuits.js';
|
|
21
|
+
import { type EpochCache } from '@aztec/epoch-cache';
|
|
19
22
|
import { createLogger } from '@aztec/foundation/log';
|
|
20
23
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
21
24
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
@@ -28,26 +31,27 @@ import { createPeerScoreParams, createTopicScoreParams } from '@chainsafe/libp2p
|
|
|
28
31
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
29
32
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
30
33
|
import { identify } from '@libp2p/identify';
|
|
31
|
-
import type
|
|
34
|
+
import { type Message, type PeerId, TopicValidatorResult } from '@libp2p/interface';
|
|
32
35
|
import '@libp2p/kad-dht';
|
|
33
36
|
import { mplex } from '@libp2p/mplex';
|
|
34
37
|
import { tcp } from '@libp2p/tcp';
|
|
35
38
|
import { createLibp2p } from 'libp2p';
|
|
36
39
|
|
|
37
|
-
import { type P2PConfig } from '
|
|
38
|
-
import { type MemPools } from '
|
|
40
|
+
import { type P2PConfig } from '../../config.js';
|
|
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';
|
|
39
44
|
import {
|
|
40
45
|
DataTxValidator,
|
|
41
46
|
DoubleSpendTxValidator,
|
|
42
47
|
MetadataTxValidator,
|
|
43
48
|
TxProofValidator,
|
|
44
|
-
} from '
|
|
45
|
-
import { type PubSubLibp2p, convertToMultiaddr } from '
|
|
46
|
-
import { AztecDatastore } from '
|
|
47
|
-
import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '
|
|
48
|
-
import { PeerManager } from '
|
|
49
|
-
import {
|
|
50
|
-
import { pingHandler, statusHandler } from './reqresp/handlers.js';
|
|
49
|
+
} from '../../msg_validators/tx_validator/index.js';
|
|
50
|
+
import { type PubSubLibp2p, convertToMultiaddr } from '../../util.js';
|
|
51
|
+
import { AztecDatastore } from '../data_store.js';
|
|
52
|
+
import { SnappyTransform, fastMsgIdFn, getMsgIdFn, msgIdToStrFn } from '../encoding.js';
|
|
53
|
+
import { PeerManager } from '../peer_manager.js';
|
|
54
|
+
import { pingHandler, statusHandler } from '../reqresp/handlers.js';
|
|
51
55
|
import {
|
|
52
56
|
DEFAULT_SUB_PROTOCOL_HANDLERS,
|
|
53
57
|
DEFAULT_SUB_PROTOCOL_VALIDATORS,
|
|
@@ -57,18 +61,38 @@ import {
|
|
|
57
61
|
STATUS_PROTOCOL,
|
|
58
62
|
type SubProtocolMap,
|
|
59
63
|
TX_REQ_PROTOCOL,
|
|
60
|
-
} from '
|
|
61
|
-
import { ReqResp } from '
|
|
62
|
-
import type { P2PService, PeerDiscoveryService } from '
|
|
64
|
+
} from '../reqresp/interface.js';
|
|
65
|
+
import { ReqResp } from '../reqresp/reqresp.js';
|
|
66
|
+
import type { P2PService, PeerDiscoveryService } from '../service.js';
|
|
67
|
+
|
|
68
|
+
interface MessageValidator {
|
|
69
|
+
validator: {
|
|
70
|
+
validateTx(tx: Tx): Promise<boolean>;
|
|
71
|
+
};
|
|
72
|
+
severity: PeerErrorSeverity;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface ValidationResult {
|
|
76
|
+
name: string;
|
|
77
|
+
isValid: boolean;
|
|
78
|
+
severity: PeerErrorSeverity;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type ValidationOutcome = { allPassed: true } | { allPassed: false; failure: ValidationResult };
|
|
63
82
|
|
|
64
83
|
/**
|
|
65
84
|
* Lib P2P implementation of the P2PService interface.
|
|
66
85
|
*/
|
|
67
|
-
export class LibP2PService extends WithTracer implements P2PService {
|
|
86
|
+
export class LibP2PService<T extends P2PClientType> extends WithTracer implements P2PService {
|
|
68
87
|
private jobQueue: SerialQueue = new SerialQueue();
|
|
69
88
|
private peerManager: PeerManager;
|
|
70
89
|
private discoveryRunningPromise?: RunningPromise;
|
|
71
90
|
|
|
91
|
+
// Message validators
|
|
92
|
+
private attestationValidator: AttestationValidator;
|
|
93
|
+
private blockProposalValidator: BlockProposalValidator;
|
|
94
|
+
private epochProofQuoteValidator: EpochProofQuoteValidator;
|
|
95
|
+
|
|
72
96
|
// Request and response sub service
|
|
73
97
|
public reqresp: ReqResp;
|
|
74
98
|
|
|
@@ -80,11 +104,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
80
104
|
private blockReceivedCallback: (block: BlockProposal) => Promise<BlockAttestation | undefined>;
|
|
81
105
|
|
|
82
106
|
constructor(
|
|
107
|
+
private clientType: T,
|
|
83
108
|
private config: P2PConfig,
|
|
84
109
|
private node: PubSubLibp2p,
|
|
85
110
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
86
|
-
private mempools: MemPools
|
|
111
|
+
private mempools: MemPools<T>,
|
|
87
112
|
private l2BlockSource: L2BlockSource,
|
|
113
|
+
private epochCache: EpochCache,
|
|
88
114
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
89
115
|
private worldStateSynchronizer: WorldStateSynchronizer,
|
|
90
116
|
private telemetry: TelemetryClient,
|
|
@@ -93,13 +119,17 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
93
119
|
) {
|
|
94
120
|
super(telemetry, 'LibP2PService');
|
|
95
121
|
|
|
96
|
-
this.peerManager = new PeerManager(node, peerDiscoveryService, config, logger);
|
|
122
|
+
this.peerManager = new PeerManager(node, peerDiscoveryService, config, this.tracer, logger);
|
|
97
123
|
this.node.services.pubsub.score.params.appSpecificScore = (peerId: string) => {
|
|
98
124
|
return this.peerManager.getPeerScore(peerId);
|
|
99
125
|
};
|
|
100
126
|
this.node.services.pubsub.score.params.appSpecificWeight = 10;
|
|
101
127
|
this.reqresp = new ReqResp(config, node, this.peerManager);
|
|
102
128
|
|
|
129
|
+
this.attestationValidator = new AttestationValidator(epochCache);
|
|
130
|
+
this.blockProposalValidator = new BlockProposalValidator(epochCache);
|
|
131
|
+
this.epochProofQuoteValidator = new EpochProofQuoteValidator(epochCache);
|
|
132
|
+
|
|
103
133
|
this.blockReceivedCallback = (block: BlockProposal): Promise<BlockAttestation | undefined> => {
|
|
104
134
|
this.logger.verbose(
|
|
105
135
|
`[WARNING] handler not yet registered: Block received callback not set. Received block ${block.p2pMessageIdentifier()} from peer.`,
|
|
@@ -131,22 +161,37 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
131
161
|
await this.node.start();
|
|
132
162
|
|
|
133
163
|
// Subscribe to standard GossipSub topics by default
|
|
134
|
-
for (const topic
|
|
164
|
+
for (const topic of getTopicTypeForClientType(this.clientType)) {
|
|
135
165
|
this.subscribeToTopic(TopicTypeMap[topic].p2pTopic);
|
|
136
166
|
}
|
|
137
167
|
|
|
168
|
+
// Add p2p topic validators
|
|
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
|
+
}
|
|
180
|
+
|
|
138
181
|
// add GossipSub listener
|
|
139
182
|
this.node.services.pubsub.addEventListener('gossipsub:message', async e => {
|
|
140
|
-
const { msg
|
|
183
|
+
const { msg } = e.detail;
|
|
141
184
|
this.logger.trace(`Received PUBSUB message.`);
|
|
142
185
|
|
|
143
|
-
await this.jobQueue.put(() => this.handleNewGossipMessage(msg
|
|
186
|
+
await this.jobQueue.put(() => this.handleNewGossipMessage(msg));
|
|
144
187
|
});
|
|
145
188
|
|
|
146
189
|
// Start running promise for peer discovery
|
|
147
|
-
this.discoveryRunningPromise = new RunningPromise(
|
|
148
|
-
this.peerManager.heartbeat()
|
|
149
|
-
|
|
190
|
+
this.discoveryRunningPromise = new RunningPromise(
|
|
191
|
+
() => this.peerManager.heartbeat(),
|
|
192
|
+
this.logger,
|
|
193
|
+
this.config.peerCheckIntervalMS,
|
|
194
|
+
);
|
|
150
195
|
this.discoveryRunningPromise.start();
|
|
151
196
|
|
|
152
197
|
// Define the sub protocol validators - This is done within this start() method to gain a callback to the existing validateTx function
|
|
@@ -186,12 +231,14 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
186
231
|
* @param txPool - The transaction pool to be accessed by the service.
|
|
187
232
|
* @returns The new service.
|
|
188
233
|
*/
|
|
189
|
-
public static async new(
|
|
234
|
+
public static async new<T extends P2PClientType>(
|
|
235
|
+
clientType: T,
|
|
190
236
|
config: P2PConfig,
|
|
191
237
|
peerDiscoveryService: PeerDiscoveryService,
|
|
192
238
|
peerId: PeerId,
|
|
193
|
-
mempools: MemPools
|
|
239
|
+
mempools: MemPools<T>,
|
|
194
240
|
l2BlockSource: L2BlockSource,
|
|
241
|
+
epochCache: EpochCache,
|
|
195
242
|
proofVerifier: ClientProtocolCircuitVerifier,
|
|
196
243
|
worldStateSynchronizer: WorldStateSynchronizer,
|
|
197
244
|
store: AztecKVStore,
|
|
@@ -251,6 +298,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
251
298
|
dataTransform: new SnappyTransform(),
|
|
252
299
|
metricsRegister: otelMetricsAdapter,
|
|
253
300
|
metricsTopicStrToLabel: metricsTopicStrToLabels(),
|
|
301
|
+
asyncValidation: true,
|
|
254
302
|
scoreParams: createPeerScoreParams({
|
|
255
303
|
topics: {
|
|
256
304
|
[Tx.p2pTopic]: createTopicScoreParams({
|
|
@@ -299,11 +347,13 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
299
347
|
};
|
|
300
348
|
|
|
301
349
|
return new LibP2PService(
|
|
350
|
+
clientType,
|
|
302
351
|
config,
|
|
303
352
|
node,
|
|
304
353
|
peerDiscoveryService,
|
|
305
354
|
mempools,
|
|
306
355
|
l2BlockSource,
|
|
356
|
+
epochCache,
|
|
307
357
|
proofVerifier,
|
|
308
358
|
worldStateSynchronizer,
|
|
309
359
|
telemetry,
|
|
@@ -376,12 +426,12 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
376
426
|
* @param topic - The message's topic.
|
|
377
427
|
* @param data - The message data
|
|
378
428
|
*/
|
|
379
|
-
private async handleNewGossipMessage(message: RawGossipMessage
|
|
429
|
+
private async handleNewGossipMessage(message: RawGossipMessage) {
|
|
380
430
|
if (message.topic === Tx.p2pTopic) {
|
|
381
431
|
const tx = Tx.fromBuffer(Buffer.from(message.data));
|
|
382
|
-
await this.processTxFromPeer(tx
|
|
432
|
+
await this.processTxFromPeer(tx);
|
|
383
433
|
}
|
|
384
|
-
if (message.topic === BlockAttestation.p2pTopic) {
|
|
434
|
+
if (message.topic === BlockAttestation.p2pTopic && this.clientType === P2PClientType.Full) {
|
|
385
435
|
const attestation = BlockAttestation.fromBuffer(Buffer.from(message.data));
|
|
386
436
|
await this.processAttestationFromPeer(attestation);
|
|
387
437
|
}
|
|
@@ -410,7 +460,7 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
410
460
|
}))
|
|
411
461
|
private async processAttestationFromPeer(attestation: BlockAttestation): Promise<void> {
|
|
412
462
|
this.logger.debug(`Received attestation ${attestation.p2pMessageIdentifier()} from external peer.`);
|
|
413
|
-
await this.mempools.attestationPool
|
|
463
|
+
await this.mempools.attestationPool!.addAttestations([attestation]);
|
|
414
464
|
}
|
|
415
465
|
|
|
416
466
|
/**Process block from peer
|
|
@@ -468,16 +518,11 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
468
518
|
});
|
|
469
519
|
}
|
|
470
520
|
|
|
471
|
-
private async processTxFromPeer(tx: Tx
|
|
521
|
+
private async processTxFromPeer(tx: Tx): Promise<void> {
|
|
472
522
|
const txHash = tx.getTxHash();
|
|
473
523
|
const txHashString = txHash.toString();
|
|
474
524
|
this.logger.verbose(`Received tx ${txHashString} from external peer.`);
|
|
475
|
-
|
|
476
|
-
const isValidTx = await this.validatePropagatedTx(tx, peerId);
|
|
477
|
-
|
|
478
|
-
if (isValidTx) {
|
|
479
|
-
await this.mempools.txPool.addTxs([tx]);
|
|
480
|
-
}
|
|
525
|
+
await this.mempools.txPool.addTxs([tx]);
|
|
481
526
|
}
|
|
482
527
|
|
|
483
528
|
/**
|
|
@@ -494,6 +539,9 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
494
539
|
* @param peerId - The peer ID of the peer that sent the tx.
|
|
495
540
|
* @returns True if the tx is valid, false otherwise.
|
|
496
541
|
*/
|
|
542
|
+
@trackSpan('Libp2pService.validateRequestedTx', (requestedTxHash, _responseTx) => ({
|
|
543
|
+
[Attributes.TX_HASH]: requestedTxHash.toString(),
|
|
544
|
+
}))
|
|
497
545
|
private async validateRequestedTx(requestedTxHash: TxHash, responseTx: Tx, peerId: PeerId): Promise<boolean> {
|
|
498
546
|
const proofValidator = new TxProofValidator(this.proofVerifier);
|
|
499
547
|
const validProof = await proofValidator.validateTx(responseTx);
|
|
@@ -514,67 +562,264 @@ export class LibP2PService extends WithTracer implements P2PService {
|
|
|
514
562
|
return true;
|
|
515
563
|
}
|
|
516
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
|
+
*/
|
|
571
|
+
private async validatePropagatedTxFromMessage(
|
|
572
|
+
propagationSource: PeerId,
|
|
573
|
+
msg: Message,
|
|
574
|
+
): Promise<TopicValidatorResult> {
|
|
575
|
+
const tx = Tx.fromBuffer(Buffer.from(msg.data));
|
|
576
|
+
const isValid = await this.validatePropagatedTx(tx, propagationSource);
|
|
577
|
+
this.logger.trace(`validatePropagatedTx: ${isValid}`, {
|
|
578
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
579
|
+
[Attributes.P2P_ID]: propagationSource.toString(),
|
|
580
|
+
});
|
|
581
|
+
return isValid ? TopicValidatorResult.Accept : TopicValidatorResult.Reject;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
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.
|
|
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
|
+
|
|
641
|
+
@trackSpan('Libp2pService.validatePropagatedTx', tx => ({
|
|
642
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
643
|
+
}))
|
|
517
644
|
private async validatePropagatedTx(tx: Tx, peerId: PeerId): Promise<boolean> {
|
|
518
645
|
const blockNumber = (await this.l2BlockSource.getBlockNumber()) + 1;
|
|
519
|
-
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
this.node.services.pubsub.score.markInvalidMessageDelivery(peerId.toString(), Tx.p2pTopic);
|
|
525
|
-
return false;
|
|
646
|
+
const messageValidators = this.createMessageValidators(blockNumber);
|
|
647
|
+
const outcome = await this.runValidations(tx, messageValidators);
|
|
648
|
+
|
|
649
|
+
if (outcome.allPassed) {
|
|
650
|
+
return true;
|
|
526
651
|
}
|
|
527
652
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (
|
|
532
|
-
|
|
533
|
-
|
|
653
|
+
const { name, severity } = outcome.failure;
|
|
654
|
+
|
|
655
|
+
// Double spend validator has a special case handler
|
|
656
|
+
if (name === 'doubleSpendValidator') {
|
|
657
|
+
const isValid = await this.handleDoubleSpendFailure(tx, blockNumber, peerId);
|
|
658
|
+
if (isValid) {
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
this.peerManager.penalizePeer(peerId, severity);
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Create message validators for the given block number.
|
|
669
|
+
*
|
|
670
|
+
* Each validator is a pair of a validator and a severity.
|
|
671
|
+
* If a validator fails, the peer is penalized with the severity of the validator.
|
|
672
|
+
*
|
|
673
|
+
* @param blockNumber - The block number to create validators for.
|
|
674
|
+
* @returns The message validators.
|
|
675
|
+
*/
|
|
676
|
+
private createMessageValidators(blockNumber: number): Record<string, MessageValidator> {
|
|
677
|
+
return {
|
|
678
|
+
dataValidator: {
|
|
679
|
+
validator: new DataTxValidator(),
|
|
680
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
681
|
+
},
|
|
682
|
+
metadataValidator: {
|
|
683
|
+
validator: new MetadataTxValidator(new Fr(this.config.l1ChainId), new Fr(blockNumber)),
|
|
684
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
685
|
+
},
|
|
686
|
+
proofValidator: {
|
|
687
|
+
validator: new TxProofValidator(this.proofVerifier),
|
|
688
|
+
severity: PeerErrorSeverity.MidToleranceError,
|
|
689
|
+
},
|
|
690
|
+
doubleSpendValidator: {
|
|
691
|
+
validator: new DoubleSpendTxValidator({
|
|
692
|
+
getNullifierIndices: (nullifiers: Buffer[]) => {
|
|
693
|
+
const merkleTree = this.worldStateSynchronizer.getCommitted();
|
|
694
|
+
return merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
695
|
+
},
|
|
696
|
+
}),
|
|
697
|
+
severity: PeerErrorSeverity.HighToleranceError,
|
|
698
|
+
},
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Run validations on a tx.
|
|
704
|
+
* @param tx - The tx to validate.
|
|
705
|
+
* @param messageValidators - The message validators to run.
|
|
706
|
+
* @returns The validation outcome.
|
|
707
|
+
*/
|
|
708
|
+
private async runValidations(
|
|
709
|
+
tx: Tx,
|
|
710
|
+
messageValidators: Record<string, MessageValidator>,
|
|
711
|
+
): Promise<ValidationOutcome> {
|
|
712
|
+
const validationPromises = Object.entries(messageValidators).map(async ([name, { validator, severity }]) => {
|
|
713
|
+
const isValid = await validator.validateTx(tx);
|
|
714
|
+
return { name, isValid, severity };
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
// A promise that resolves when all validations have been run
|
|
718
|
+
const allValidations = Promise.all(validationPromises);
|
|
719
|
+
|
|
720
|
+
// A promise that resolves when the first validation fails
|
|
721
|
+
const firstFailure = Promise.race(
|
|
722
|
+
validationPromises.map(async promise => {
|
|
723
|
+
const result = await promise;
|
|
724
|
+
return result.isValid ? new Promise(() => {}) : result;
|
|
725
|
+
}),
|
|
726
|
+
);
|
|
727
|
+
|
|
728
|
+
// Wait for the first validation to fail or all validations to pass
|
|
729
|
+
const result = await Promise.race([
|
|
730
|
+
allValidations.then(() => ({ allPassed: true as const })),
|
|
731
|
+
firstFailure.then(failure => ({ allPassed: false as const, failure: failure as ValidationResult })),
|
|
732
|
+
]);
|
|
733
|
+
|
|
734
|
+
// If all validations pass, allPassed will be true, if failed, then the failure will be the first validation to fail
|
|
735
|
+
return result;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Handle a double spend failure.
|
|
740
|
+
*
|
|
741
|
+
* Double spend failures are managed on their own because they are a special case.
|
|
742
|
+
* We must check if the double spend is recent or old, if it is past a threshold, then we heavily penalize the peer.
|
|
743
|
+
*
|
|
744
|
+
* @param tx - The tx that failed the double spend validator.
|
|
745
|
+
* @param blockNumber - The block number of the tx.
|
|
746
|
+
* @param peerId - The peer ID of the peer that sent the tx.
|
|
747
|
+
* @returns True if the tx is valid, false otherwise.
|
|
748
|
+
*/
|
|
749
|
+
private async handleDoubleSpendFailure(tx: Tx, blockNumber: number, peerId: PeerId): Promise<boolean> {
|
|
750
|
+
if (blockNumber <= this.config.severePeerPenaltyBlockLength) {
|
|
534
751
|
return false;
|
|
535
752
|
}
|
|
536
753
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
return
|
|
754
|
+
const snapshotValidator = new DoubleSpendTxValidator({
|
|
755
|
+
getNullifierIndices: (nullifiers: Buffer[]) => {
|
|
756
|
+
const merkleTree = this.worldStateSynchronizer.getSnapshot(
|
|
757
|
+
blockNumber - this.config.severePeerPenaltyBlockLength,
|
|
758
|
+
);
|
|
759
|
+
return merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
543
760
|
},
|
|
544
761
|
});
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const snapshotValidator = new DoubleSpendTxValidator({
|
|
550
|
-
getNullifierIndex: async (nullifier: Fr) => {
|
|
551
|
-
const merkleTree = this.worldStateSynchronizer.getSnapshot(
|
|
552
|
-
blockNumber - this.config.severePeerPenaltyBlockLength,
|
|
553
|
-
);
|
|
554
|
-
const index = await merkleTree.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
|
|
555
|
-
return index;
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
const validSnapshot = await snapshotValidator.validateTx(tx);
|
|
560
|
-
// High penalty if nullifier is older than 20 blocks
|
|
561
|
-
if (!validSnapshot) {
|
|
562
|
-
// penalize
|
|
563
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
564
|
-
return false;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
// penalize
|
|
568
|
-
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.HighToleranceError);
|
|
762
|
+
|
|
763
|
+
const validSnapshot = await snapshotValidator.validateTx(tx);
|
|
764
|
+
if (!validSnapshot) {
|
|
765
|
+
this.peerManager.penalizePeer(peerId, PeerErrorSeverity.LowToleranceError);
|
|
569
766
|
return false;
|
|
570
767
|
}
|
|
571
768
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
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);
|
|
578
823
|
return false;
|
|
579
824
|
}
|
|
580
825
|
|
|
@@ -1,29 +1,12 @@
|
|
|
1
|
+
import { PeerErrorSeverity } from '@aztec/circuit-types';
|
|
1
2
|
import { median } from '@aztec/foundation/collection';
|
|
2
3
|
|
|
3
|
-
import { type P2PConfig } from '
|
|
4
|
-
|
|
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
|
-
}
|
|
4
|
+
import { type P2PConfig } from '../../config.js';
|
|
22
5
|
|
|
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
|
|