@@ -117,7 +117,11 @@ func NewClient(
117
117
func (c * Client ) Start () {
118
118
c .onceStart .Do (func () {
119
119
c .Protocol .Logger ().
120
- Debug (fmt .Sprintf ("%s: starting client protocol for connection %+v" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
120
+ Debug ("starting client protocol" ,
121
+ "component" , "network" ,
122
+ "protocol" , ProtocolName ,
123
+ "connection_id" , c .callbackContext .ConnectionId .String (),
124
+ )
121
125
c .Protocol .Start ()
122
126
// Start goroutine to cleanup resources on protocol shutdown
123
127
go func () {
@@ -132,7 +136,11 @@ func (c *Client) Stop() error {
132
136
var err error
133
137
c .onceStop .Do (func () {
134
138
c .Protocol .Logger ().
135
- Debug (fmt .Sprintf ("%s: stopping client protocol for connection %+v" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
139
+ Debug ("stopping client protocol" ,
140
+ "component" , "network" ,
141
+ "protocol" , ProtocolName ,
142
+ "connection_id" , c .callbackContext .ConnectionId .String (),
143
+ )
136
144
c .busyMutex .Lock ()
137
145
defer c .busyMutex .Unlock ()
138
146
msg := NewMsgDone ()
@@ -146,7 +154,12 @@ func (c *Client) Stop() error {
146
154
// GetCurrentTip returns the current chain tip
147
155
func (c * Client ) GetCurrentTip () (* Tip , error ) {
148
156
c .Protocol .Logger ().
149
- Debug (fmt .Sprintf ("%s: client %+v called GetCurrentTip()" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
157
+ Debug ("calling GetCurrentTip()" ,
158
+ "component" , "network" ,
159
+ "protocol" , ProtocolName ,
160
+ "role" , "client" ,
161
+ "connection_id" , c .callbackContext .ConnectionId .String (),
162
+ )
150
163
done := atomic.Bool {}
151
164
requestResultChan := make (chan Tip , 1 )
152
165
requestErrorChan := make (chan error , 1 )
@@ -186,13 +199,25 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
186
199
waitingForCurrentTipChan = nil
187
200
case tip := <- waitingResultChan :
188
201
c .Protocol .Logger ().
189
- Debug (fmt .Sprintf ("%s: returning tip results {Slot: %d, Hash: %x, BlockNumber: %d} to %+v" , ProtocolName , tip .Point .Slot , tip .Point .Hash , tip .BlockNumber , c .callbackContext .ConnectionId .RemoteAddr ))
202
+ Debug (
203
+ fmt .Sprintf ("received tip results {Slot: %d, Hash: %x, BlockNumber: %d}" , tip .Point .Slot , tip .Point .Hash , tip .BlockNumber ),
204
+ "component" , "network" ,
205
+ "protocol" , ProtocolName ,
206
+ "role" , "client" ,
207
+ "connection_id" , c .callbackContext .ConnectionId .String (),
208
+ )
190
209
// The result from the other request is ready.
191
210
done .Store (true )
192
211
return & tip , nil
193
212
case tip := <- requestResultChan :
194
213
c .Protocol .Logger ().
195
- Debug (fmt .Sprintf ("%s: returning tip results {Slot: %d, Hash: %x, BlockNumber: %d} to %+v" , ProtocolName , tip .Point .Slot , tip .Point .Hash , tip .BlockNumber , c .callbackContext .ConnectionId .RemoteAddr ))
214
+ Debug (
215
+ fmt .Sprintf ("received tip results {Slot: %d, Hash: %x, BlockNumber: %d}" , tip .Point .Slot , tip .Point .Hash , tip .BlockNumber ),
216
+ "component" , "network" ,
217
+ "protocol" , ProtocolName ,
218
+ "role" , "client" ,
219
+ "connection_id" , c .callbackContext .ConnectionId .String (),
220
+ )
196
221
// If waitingForCurrentTipChan is full, the for loop that empties it might finish the
197
222
// loop before the select statement that writes to it is triggered. For that reason we
198
223
// require requestResultChan here.
@@ -215,16 +240,49 @@ func (c *Client) GetAvailableBlockRange(
215
240
if len (intersectPoints ) == 0 {
216
241
intersectPoints = []common.Point {common .NewPointOrigin ()}
217
242
}
243
+
244
+ // Debug logging
218
245
switch len (intersectPoints ) {
219
246
case 1 :
220
247
c .Protocol .Logger ().
221
- Debug (fmt .Sprintf ("%s: client %+v called GetAvailableBlockRange(intersectPoints: []{Slot: %d, Hash: %x})" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints [0 ].Slot , intersectPoints [0 ].Hash ))
248
+ Debug (
249
+ fmt .Sprintf (
250
+ "calling GetAvailableBlockRange(intersectPoints: []{Slot: %d, Hash: %x})" ,
251
+ intersectPoints [0 ].Slot ,
252
+ intersectPoints [0 ].Hash ,
253
+ ),
254
+ "component" , "network" ,
255
+ "protocol" , ProtocolName ,
256
+ "role" , "client" ,
257
+ "connection_id" , c .callbackContext .ConnectionId .String (),
258
+ )
222
259
case 2 :
223
260
c .Protocol .Logger ().
224
- Debug (fmt .Sprintf ("%s: client %+v called GetAvailableBlockRange(intersectPoints: []{Slot: %d, Hash: %x},{Slot: %d, Hash: %x})" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints [0 ].Slot , intersectPoints [0 ].Hash , intersectPoints [1 ].Slot , intersectPoints [1 ].Hash ))
261
+ Debug (
262
+ fmt .Sprintf (
263
+ "calling GetAvailableBlockRange(intersectPoints: []{Slot: %d, Hash: %x},{Slot: %d, Hash: %x})" ,
264
+ intersectPoints [0 ].Slot ,
265
+ intersectPoints [0 ].Hash ,
266
+ intersectPoints [1 ].Slot ,
267
+ intersectPoints [1 ].Hash ,
268
+ ),
269
+ "component" , "network" ,
270
+ "protocol" , ProtocolName ,
271
+ "role" , "client" ,
272
+ "connection_id" , c .callbackContext .ConnectionId .String (),
273
+ )
225
274
default :
226
275
c .Protocol .Logger ().
227
- Debug (fmt .Sprintf ("%s: client %+v called GetAvailableBlockRange(intersectPoints: %+v)" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints ))
276
+ Debug (
277
+ fmt .Sprintf (
278
+ "calling GetAvailableBlockRange(intersectPoints: %+v)" ,
279
+ intersectPoints ,
280
+ ),
281
+ "component" , "network" ,
282
+ "protocol" , ProtocolName ,
283
+ "role" , "client" ,
284
+ "connection_id" , c .callbackContext .ConnectionId .String (),
285
+ )
228
286
}
229
287
230
288
// Find our chain intersection
@@ -300,16 +358,49 @@ func (c *Client) Sync(intersectPoints []common.Point) error {
300
358
if len (intersectPoints ) == 0 {
301
359
intersectPoints = []common.Point {common .NewPointOrigin ()}
302
360
}
361
+
362
+ // Debug logging
303
363
switch len (intersectPoints ) {
304
364
case 1 :
305
365
c .Protocol .Logger ().
306
- Debug (fmt .Sprintf ("%s: client %+v called Sync(intersectPoints: []{Slot: %d, Hash: %x})" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints [0 ].Slot , intersectPoints [0 ].Hash ))
366
+ Debug (
367
+ fmt .Sprintf (
368
+ "calling Sync(intersectPoints: []{Slot: %d, Hash: %x})" ,
369
+ intersectPoints [0 ].Slot ,
370
+ intersectPoints [0 ].Hash ,
371
+ ),
372
+ "component" , "network" ,
373
+ "protocol" , ProtocolName ,
374
+ "role" , "client" ,
375
+ "connection_id" , c .callbackContext .ConnectionId .String (),
376
+ )
307
377
case 2 :
308
378
c .Protocol .Logger ().
309
- Debug (fmt .Sprintf ("%s: client %+v called Sync(intersectPoints: []{Slot: %d, Hash: %x},{Slot: %d, Hash: %x})" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints [0 ].Slot , intersectPoints [0 ].Hash , intersectPoints [1 ].Slot , intersectPoints [1 ].Hash ))
379
+ Debug (
380
+ fmt .Sprintf (
381
+ "calling Sync(intersectPoints: []{Slot: %d, Hash: %x},{Slot: %d, Hash: %x})" ,
382
+ intersectPoints [0 ].Slot ,
383
+ intersectPoints [0 ].Hash ,
384
+ intersectPoints [1 ].Slot ,
385
+ intersectPoints [1 ].Hash ,
386
+ ),
387
+ "component" , "network" ,
388
+ "protocol" , ProtocolName ,
389
+ "role" , "client" ,
390
+ "connection_id" , c .callbackContext .ConnectionId .String (),
391
+ )
310
392
default :
311
393
c .Protocol .Logger ().
312
- Debug (fmt .Sprintf ("%s: client %+v called Sync(intersectPoints: %+v)" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints ))
394
+ Debug (
395
+ fmt .Sprintf (
396
+ "calling Sync(intersectPoints: %+v)" ,
397
+ intersectPoints ,
398
+ ),
399
+ "component" , "network" ,
400
+ "protocol" , ProtocolName ,
401
+ "role" , "client" ,
402
+ "connection_id" , c .callbackContext .ConnectionId .String (),
403
+ )
313
404
}
314
405
315
406
intersectResultChan , cancel := c .wantIntersectFound ()
@@ -478,13 +569,23 @@ func (c *Client) messageHandler(msg protocol.Message) error {
478
569
479
570
func (c * Client ) handleAwaitReply () error {
480
571
c .Protocol .Logger ().
481
- Debug (fmt .Sprintf ("%s: client await reply for %+v" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
572
+ Debug ("waiting for next reply" ,
573
+ "component" , "network" ,
574
+ "protocol" , ProtocolName ,
575
+ "role" , "client" ,
576
+ "connection_id" , c .callbackContext .ConnectionId .String (),
577
+ )
482
578
return nil
483
579
}
484
580
485
581
func (c * Client ) handleRollForward (msgGeneric protocol.Message ) error {
486
582
c .Protocol .Logger ().
487
- Debug (fmt .Sprintf ("%s: client roll forward for %+v" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
583
+ Debug ("roll forward" ,
584
+ "component" , "network" ,
585
+ "protocol" , ProtocolName ,
586
+ "role" , "client" ,
587
+ "connection_id" , c .callbackContext .ConnectionId .String (),
588
+ )
488
589
firstBlockChan := func () chan <- clientPointResult {
489
590
select {
490
591
case ch := <- c .wantFirstBlockChan :
@@ -594,7 +695,12 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error {
594
695
595
696
func (c * Client ) handleRollBackward (msg protocol.Message ) error {
596
697
c .Protocol .Logger ().
597
- Debug (fmt .Sprintf ("%s: client roll backward for %+v" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
698
+ Debug ("roll backward" ,
699
+ "component" , "network" ,
700
+ "protocol" , ProtocolName ,
701
+ "role" , "client" ,
702
+ "connection_id" , c .callbackContext .ConnectionId .String (),
703
+ )
598
704
msgRollBackward := msg .(* MsgRollBackward )
599
705
c .sendCurrentTip (msgRollBackward .Tip )
600
706
if len (c .wantFirstBlockChan ) == 0 {
@@ -621,7 +727,12 @@ func (c *Client) handleRollBackward(msg protocol.Message) error {
621
727
622
728
func (c * Client ) handleIntersectFound (msg protocol.Message ) error {
623
729
c .Protocol .Logger ().
624
- Debug (fmt .Sprintf ("%s: client intersect found for %+v" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
730
+ Debug ("chain intersect found" ,
731
+ "component" , "network" ,
732
+ "protocol" , ProtocolName ,
733
+ "role" , "client" ,
734
+ "connection_id" , c .callbackContext .ConnectionId .String (),
735
+ )
625
736
msgIntersectFound := msg .(* MsgIntersectFound )
626
737
c .sendCurrentTip (msgIntersectFound .Tip )
627
738
@@ -635,7 +746,12 @@ func (c *Client) handleIntersectFound(msg protocol.Message) error {
635
746
636
747
func (c * Client ) handleIntersectNotFound (msgGeneric protocol.Message ) error {
637
748
c .Protocol .Logger ().
638
- Debug (fmt .Sprintf ("%s: client intersect not found for %+v" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr ))
749
+ Debug ("chain intersect not found" ,
750
+ "component" , "network" ,
751
+ "protocol" , ProtocolName ,
752
+ "role" , "client" ,
753
+ "connection_id" , c .callbackContext .ConnectionId .String (),
754
+ )
639
755
msgIntersectNotFound := msgGeneric .(* MsgIntersectNotFound )
640
756
c .sendCurrentTip (msgIntersectNotFound .Tip )
641
757
0 commit comments