@@ -15,12 +15,14 @@ import {
15
15
type Gossipable ,
16
16
P2PClientType ,
17
17
PeerErrorSeverity ,
18
- TopicTypeMap ,
18
+ TopicType ,
19
+ createTopicString ,
19
20
getTopicTypeForClientType ,
20
21
metricsTopicStrToLabels ,
21
22
} from '@aztec/stdlib/p2p' ;
22
23
import { DatabasePublicStateSource , MerkleTreeId } from '@aztec/stdlib/trees' ;
23
24
import { Tx , type TxHash , type TxValidationResult } from '@aztec/stdlib/tx' ;
25
+ import { compressComponentVersions } from '@aztec/stdlib/versioning' ;
24
26
import { Attributes , OtelMetricsAdapter , type TelemetryClient , WithTracer , trackSpan } from '@aztec/telemetry-client' ;
25
27
26
28
import type { ENR } from '@chainsafe/enr' ;
@@ -57,6 +59,7 @@ import {
57
59
} from '../../msg_validators/tx_validator/index.js' ;
58
60
import { GossipSubEvent } from '../../types/index.js' ;
59
61
import { type PubSubLibp2p , convertToMultiaddr } from '../../util.js' ;
62
+ import { getVersions } from '../../versioning.js' ;
60
63
import { AztecDatastore } from '../data_store.js' ;
61
64
import { SnappyTransform , fastMsgIdFn , getMsgIdFn , msgIdToStrFn } from '../encoding.js' ;
62
65
import { gossipScoreThresholds } from '../gossipsub/scoring.js' ;
@@ -95,6 +98,9 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
95
98
private attestationValidator : AttestationValidator ;
96
99
private blockProposalValidator : BlockProposalValidator ;
97
100
101
+ private protocolVersion = '' ;
102
+ private topicStrings : Record < TopicType , string > = { } as Record < TopicType , string > ;
103
+
98
104
// Request and response sub service
99
105
public reqresp : ReqResp ;
100
106
@@ -127,6 +133,17 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
127
133
) {
128
134
super ( telemetry , 'LibP2PService' ) ;
129
135
136
+ const versions = getVersions ( config ) ;
137
+ this . protocolVersion = compressComponentVersions ( versions ) ;
138
+ logger . info ( `Started libp2p service with protocol version ${ this . protocolVersion } ` ) ;
139
+
140
+ this . topicStrings [ TopicType . tx ] = createTopicString ( TopicType . tx , this . protocolVersion ) ;
141
+ this . topicStrings [ TopicType . block_proposal ] = createTopicString ( TopicType . block_proposal , this . protocolVersion ) ;
142
+ this . topicStrings [ TopicType . block_attestation ] = createTopicString (
143
+ TopicType . block_attestation ,
144
+ this . protocolVersion ,
145
+ ) ;
146
+
130
147
const peerScoring = new PeerScoring ( config ) ;
131
148
this . reqresp = new ReqResp ( config , node , peerScoring ) ;
132
149
@@ -198,6 +215,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
198
215
peerDiscovery . push ( bootstrap ( { list : bootstrapNodes } ) ) ;
199
216
}
200
217
218
+ const versions = getVersions ( config ) ;
219
+ const protocolVersion = compressComponentVersions ( versions ) ;
220
+
221
+ const txTopic = createTopicString ( TopicType . tx , protocolVersion ) ;
222
+ const blockProposalTopic = createTopicString ( TopicType . block_proposal , protocolVersion ) ;
223
+ const blockAttestationTopic = createTopicString ( TopicType . block_attestation , protocolVersion ) ;
224
+
201
225
const node = await createLibp2p ( {
202
226
start : false ,
203
227
peerId,
@@ -251,24 +275,24 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
251
275
fastMsgIdFn : fastMsgIdFn ,
252
276
dataTransform : new SnappyTransform ( ) ,
253
277
metricsRegister : otelMetricsAdapter ,
254
- metricsTopicStrToLabel : metricsTopicStrToLabels ( ) ,
278
+ metricsTopicStrToLabel : metricsTopicStrToLabels ( protocolVersion ) ,
255
279
asyncValidation : true ,
256
280
scoreThresholds : gossipScoreThresholds ,
257
281
scoreParams : createPeerScoreParams ( {
258
282
// IPColocation factor can be disabled for local testing - default to -5
259
283
IPColocationFactorWeight : config . debugDisableColocationPenalty ? 0 : - 5.0 ,
260
284
topics : {
261
- [ Tx . p2pTopic ] : createTopicScoreParams ( {
285
+ [ txTopic ] : createTopicScoreParams ( {
262
286
topicWeight : 1 ,
263
287
invalidMessageDeliveriesWeight : - 20 ,
264
288
invalidMessageDeliveriesDecay : 0.5 ,
265
289
} ) ,
266
- [ BlockAttestation . p2pTopic ] : createTopicScoreParams ( {
290
+ [ blockAttestationTopic ] : createTopicScoreParams ( {
267
291
topicWeight : 1 ,
268
292
invalidMessageDeliveriesWeight : - 20 ,
269
293
invalidMessageDeliveriesDecay : 0.5 ,
270
294
} ) ,
271
- [ BlockProposal . p2pTopic ] : createTopicScoreParams ( {
295
+ [ blockProposalTopic ] : createTopicScoreParams ( {
272
296
topicWeight : 1 ,
273
297
invalidMessageDeliveriesWeight : - 20 ,
274
298
invalidMessageDeliveriesDecay : 0.5 ,
@@ -324,7 +348,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
324
348
325
349
// Subscribe to standard GossipSub topics by default
326
350
for ( const topic of getTopicTypeForClientType ( this . clientType ) ) {
327
- this . subscribeToTopic ( TopicTypeMap [ topic ] . p2pTopic ) ;
351
+ this . subscribeToTopic ( this . topicStrings [ topic ] ) ;
328
352
}
329
353
330
354
// Create request response protocol handlers
@@ -483,13 +507,13 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
483
507
* @param data - The message data
484
508
*/
485
509
protected async handleNewGossipMessage ( msg : Message , msgId : string , source : PeerId ) {
486
- if ( msg . topic === Tx . p2pTopic ) {
510
+ if ( msg . topic === this . topicStrings [ TopicType . tx ] ) {
487
511
await this . handleGossipedTx ( msg , msgId , source ) ;
488
512
}
489
- if ( msg . topic === BlockAttestation . p2pTopic && this . clientType === P2PClientType . Full ) {
513
+ if ( msg . topic === this . topicStrings [ TopicType . block_attestation ] && this . clientType === P2PClientType . Full ) {
490
514
await this . processAttestationFromPeer ( msg , msgId , source ) ;
491
515
}
492
- if ( msg . topic == BlockProposal . p2pTopic ) {
516
+ if ( msg . topic === this . topicStrings [ TopicType . block_proposal ] ) {
493
517
await this . processBlockFromPeer ( msg , msgId , source ) ;
494
518
}
495
519
@@ -901,7 +925,7 @@ export class LibP2PService<T extends P2PClientType = P2PClientType.Full> extends
901
925
const identifier = await message . p2pMessageIdentifier ( ) . then ( i => i . toString ( ) ) ;
902
926
this . logger . trace ( `Sending message ${ identifier } ` , { p2pMessageIdentifier : identifier } ) ;
903
927
904
- const recipientsNum = await this . publishToTopic ( parent . p2pTopic , message . toBuffer ( ) ) ;
928
+ const recipientsNum = await this . publishToTopic ( this . topicStrings [ parent . p2pTopic ] , message . toBuffer ( ) ) ;
905
929
this . logger . debug ( `Sent message ${ identifier } to ${ recipientsNum } peers` , {
906
930
p2pMessageIdentifier : identifier ,
907
931
sourcePeer : this . node . peerId . toString ( ) ,
0 commit comments