@@ -3,6 +3,7 @@ import { ConnectionManager, LightPushCore } from "@waku/core";
33import {
44 type IEncoder ,
55 ILightPush ,
6+ inferProtocolVersion ,
67 type IMessage ,
78 type ISendOptions ,
89 type Libp2p ,
@@ -62,6 +63,26 @@ export class LightPush implements ILightPush {
6263 return this . protocol . multicodec ;
6364 }
6465
66+ /**
67+ * Get all supported protocol codecs
68+ * @returns Array of supported protocol codec strings
69+ */
70+ public get multicodecs ( ) : string [ ] {
71+ return this . protocol . multicodecs ;
72+ }
73+
74+ /**
75+ * Get supported protocol versions
76+ * @returns Array of supported version strings (e.g., ['v2', 'v3'])
77+ */
78+ public get supportedVersions ( ) : string [ ] {
79+ return this . protocol . multicodecs . map ( codec => {
80+ if ( codec . includes ( '3.0.0' ) ) return 'v3' ;
81+ if ( codec . includes ( '2.0.0' ) ) return 'v2' ;
82+ return 'unknown' ;
83+ } ) ;
84+ }
85+
6586 public start ( ) : void {
6687 this . retryManager . start ( ) ;
6788 }
@@ -100,17 +121,63 @@ export class LightPush implements ILightPush {
100121 pubsubTopic : encoder . pubsubTopic
101122 } ) ;
102123
124+ // Track protocol versions used per peer
125+ const protocolVersions : Record < string , string > = { } ;
126+
103127 const coreResults : LightPushCoreResult [ ] =
104128 peerIds ?. length > 0
105129 ? await Promise . all (
106- peerIds . map ( ( peerId ) =>
107- this . protocol . send ( encoder , message , peerId ) . catch ( ( _e ) => ( {
108- success : null ,
109- failure : {
110- error : LightPushError . GENERIC_FAIL
130+ peerIds . map ( async ( peerId ) => {
131+ try {
132+ const result = await this . protocol . send ( encoder , message , peerId ) ;
133+
134+ // Enhanced error logging with protocol version information
135+ if ( result . failure ) {
136+ const peerIdStr = peerId . toString ( ) ;
137+ const protocolVersion = result . failure . protocolVersion || inferProtocolVersion ( result . failure . statusCode !== undefined ) ;
138+ protocolVersions [ peerIdStr ] = protocolVersion ;
139+
140+ log . warn (
141+ `Failed to send to peer ${ peerIdStr } (${ protocolVersion } ): ${ result . failure . error } ` ,
142+ {
143+ peerId : peerIdStr ,
144+ protocolVersion,
145+ error : result . failure . error ,
146+ statusCode : result . failure . statusCode ,
147+ statusDesc : result . failure . statusDesc
148+ }
149+ ) ;
150+
151+ // Ensure protocolVersion is set in failure
152+ if ( ! result . failure . protocolVersion ) {
153+ result . failure . protocolVersion = protocolVersion ;
154+ }
155+ } else if ( result . success ) {
156+ // For successful sends, we need to infer protocol version from peer capabilities
157+ // This is a best-effort approach since success responses don't always contain version info
158+ const peerIdStr = peerId . toString ( ) ;
159+ protocolVersions [ peerIdStr ] = 'v3' ; // Assume v3 for successful sends (will be corrected if needed)
160+
161+ log . info ( `Successfully sent to peer ${ peerIdStr } ` ) ;
111162 }
112- } ) )
113- )
163+
164+ return result ;
165+ } catch ( error ) {
166+ const peerIdStr = peerId . toString ( ) ;
167+ protocolVersions [ peerIdStr ] = 'unknown' ;
168+
169+ log . error ( `Exception sending to peer ${ peerIdStr } :` , error ) ;
170+
171+ return {
172+ success : null ,
173+ failure : {
174+ error : LightPushError . GENERIC_FAIL ,
175+ peerId,
176+ protocolVersion : 'unknown'
177+ }
178+ } ;
179+ }
180+ } )
114181 )
115182 : [ ] ;
116183
@@ -121,15 +188,17 @@ export class LightPush implements ILightPush {
121188 . map ( ( v ) => v . success ) as PeerId [ ] ,
122189 failures : coreResults
123190 . filter ( ( v ) => v . failure )
124- . map ( ( v ) => v . failure ) as LightPushFailure [ ]
191+ . map ( ( v ) => v . failure ) as LightPushFailure [ ] ,
192+ protocolVersions
125193 }
126194 : {
127195 successes : [ ] ,
128196 failures : [
129197 {
130198 error : LightPushError . NO_PEER_AVAILABLE
131199 }
132- ]
200+ ] ,
201+ protocolVersions : { }
133202 } ;
134203
135204 if ( options . autoRetry && results . successes . length === 0 ) {
0 commit comments