@@ -117,7 +117,7 @@ func NewClient(
117
117
func (c * Client ) Start () {
118
118
c .onceStart .Do (func () {
119
119
c .Protocol .Logger ().
120
- Debug (fmt .Sprintf ("starting protocol: %s " , ProtocolName ))
120
+ Debug (fmt .Sprintf ("%s: starting protocol for connection %+v " , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
121
121
c .Protocol .Start ()
122
122
// Start goroutine to cleanup resources on protocol shutdown
123
123
go func () {
@@ -132,7 +132,7 @@ func (c *Client) Stop() error {
132
132
var err error
133
133
c .onceStop .Do (func () {
134
134
c .Protocol .Logger ().
135
- Debug (fmt .Sprintf ("stopping protocol: %s " , ProtocolName ))
135
+ Debug (fmt .Sprintf ("%s: stopping protocol for connection %+v " , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
136
136
c .busyMutex .Lock ()
137
137
defer c .busyMutex .Unlock ()
138
138
msg := NewMsgDone ()
@@ -146,7 +146,7 @@ func (c *Client) Stop() error {
146
146
// GetCurrentTip returns the current chain tip
147
147
func (c * Client ) GetCurrentTip () (* Tip , error ) {
148
148
c .Protocol .Logger ().
149
- Debug (fmt .Sprintf ("client called %s GetCurrentTip()" , ProtocolName ))
149
+ Debug (fmt .Sprintf ("%s: client %+v called GetCurrentTip()" , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
150
150
done := atomic.Bool {}
151
151
requestResultChan := make (chan Tip , 1 )
152
152
requestErrorChan := make (chan error , 1 )
@@ -185,10 +185,14 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
185
185
// The request is being handled by another request, wait for the result.
186
186
waitingForCurrentTipChan = nil
187
187
case tip := <- waitingResultChan :
188
+ 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 ))
188
190
// The result from the other request is ready.
189
191
done .Store (true )
190
192
return & tip , nil
191
193
case tip := <- requestResultChan :
194
+ 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 ))
192
196
// If waitingForCurrentTipChan is full, the for loop that empties it might finish the
193
197
// loop before the select statement that writes to it is triggered. For that reason we
194
198
// require requestResultChan here.
@@ -204,15 +208,25 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
204
208
func (c * Client ) GetAvailableBlockRange (
205
209
intersectPoints []common.Point ,
206
210
) (common.Point , common.Point , error ) {
207
- c .Protocol .Logger ().
208
- Debug (fmt .Sprintf ("client called %s GetAvailableBlockRange(intersectPoints: %+v)" , ProtocolName , intersectPoints ))
209
211
c .busyMutex .Lock ()
210
212
defer c .busyMutex .Unlock ()
211
213
212
214
// Use origin if no intersect points were specified
213
215
if len (intersectPoints ) == 0 {
214
216
intersectPoints = []common.Point {common .NewPointOrigin ()}
215
217
}
218
+ switch len (intersectPoints ) {
219
+ case 1 :
220
+ 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 ))
222
+ case 2 :
223
+ 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 ))
225
+ default :
226
+ c .Protocol .Logger ().
227
+ Debug (fmt .Sprintf ("%s: client %+v called GetAvailableBlockRange(intersectPoints: %+v)" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints ))
228
+ }
229
+
216
230
// Find our chain intersection
217
231
result := c .requestFindIntersect (intersectPoints )
218
232
if result .error != nil {
@@ -279,14 +293,24 @@ func (c *Client) GetAvailableBlockRange(
279
293
// Sync begins a chain-sync operation using the provided intersect point(s). Incoming blocks will be delivered
280
294
// via the RollForward callback function specified in the protocol config
281
295
func (c * Client ) Sync (intersectPoints []common.Point ) error {
282
- c .Protocol .Logger ().
283
- Debug (fmt .Sprintf ("client called %s Sync(intersectPoints: %+v)" , ProtocolName , intersectPoints ))
284
296
c .busyMutex .Lock ()
285
297
defer c .busyMutex .Unlock ()
298
+
286
299
// Use origin if no intersect points were specified
287
300
if len (intersectPoints ) == 0 {
288
301
intersectPoints = []common.Point {common .NewPointOrigin ()}
289
302
}
303
+ switch len (intersectPoints ) {
304
+ case 1 :
305
+ 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 ))
307
+ case 2 :
308
+ 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 ))
310
+ default :
311
+ c .Protocol .Logger ().
312
+ Debug (fmt .Sprintf ("%s: client %+v called Sync(intersectPoints: %+v)" , ProtocolName , c .callbackContext .ConnectionId .RemoteAddr , intersectPoints ))
313
+ }
290
314
291
315
intersectResultChan , cancel := c .wantIntersectFound ()
292
316
msg := NewMsgFindIntersect (intersectPoints )
@@ -430,8 +454,6 @@ func (c *Client) requestFindIntersect(
430
454
}
431
455
432
456
func (c * Client ) messageHandler (msg protocol.Message ) error {
433
- c .Protocol .Logger ().
434
- Debug (fmt .Sprintf ("handling client message for %s" , ProtocolName ))
435
457
var err error
436
458
switch msg .Type () {
437
459
case MessageTypeAwaitReply :
@@ -456,13 +478,13 @@ func (c *Client) messageHandler(msg protocol.Message) error {
456
478
457
479
func (c * Client ) handleAwaitReply () error {
458
480
c .Protocol .Logger ().
459
- Debug (fmt .Sprintf ("handling client await reply for %s " , ProtocolName ))
481
+ Debug (fmt .Sprintf ("%s: client await reply for %+v " , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
460
482
return nil
461
483
}
462
484
463
485
func (c * Client ) handleRollForward (msgGeneric protocol.Message ) error {
464
486
c .Protocol .Logger ().
465
- Debug (fmt .Sprintf ("handling client roll forward for %s " , ProtocolName ))
487
+ Debug (fmt .Sprintf ("%s: client roll forward for %+v " , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
466
488
firstBlockChan := func () chan <- clientPointResult {
467
489
select {
468
490
case ch := <- c .wantFirstBlockChan :
@@ -572,7 +594,7 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error {
572
594
573
595
func (c * Client ) handleRollBackward (msg protocol.Message ) error {
574
596
c .Protocol .Logger ().
575
- Debug (fmt .Sprintf ("handling client roll backward for %s " , ProtocolName ))
597
+ Debug (fmt .Sprintf ("%s: client roll backward for %+v " , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
576
598
msgRollBackward := msg .(* MsgRollBackward )
577
599
c .sendCurrentTip (msgRollBackward .Tip )
578
600
if len (c .wantFirstBlockChan ) == 0 {
@@ -599,7 +621,7 @@ func (c *Client) handleRollBackward(msg protocol.Message) error {
599
621
600
622
func (c * Client ) handleIntersectFound (msg protocol.Message ) error {
601
623
c .Protocol .Logger ().
602
- Debug (fmt .Sprintf ("handling client intersect found for %s " , ProtocolName ))
624
+ Debug (fmt .Sprintf ("%s: client intersect found for %+v " , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
603
625
msgIntersectFound := msg .(* MsgIntersectFound )
604
626
c .sendCurrentTip (msgIntersectFound .Tip )
605
627
@@ -613,7 +635,7 @@ func (c *Client) handleIntersectFound(msg protocol.Message) error {
613
635
614
636
func (c * Client ) handleIntersectNotFound (msgGeneric protocol.Message ) error {
615
637
c .Protocol .Logger ().
616
- Debug (fmt .Sprintf ("handling client intersect not found for %s " , ProtocolName ))
638
+ Debug (fmt .Sprintf ("%s: client intersect not found for %+v " , ProtocolName , c . callbackContext . ConnectionId . RemoteAddr ))
617
639
msgIntersectNotFound := msgGeneric .(* MsgIntersectNotFound )
618
640
c .sendCurrentTip (msgIntersectNotFound .Tip )
619
641
0 commit comments