@@ -117,7 +117,7 @@ func NewClient(
117117func (c * Client ) Start () {
118118 c .onceStart .Do (func () {
119119 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 ))
121121 c .Protocol .Start ()
122122 // Start goroutine to cleanup resources on protocol shutdown
123123 go func () {
@@ -132,7 +132,7 @@ func (c *Client) Stop() error {
132132 var err error
133133 c .onceStop .Do (func () {
134134 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 ))
136136 c .busyMutex .Lock ()
137137 defer c .busyMutex .Unlock ()
138138 msg := NewMsgDone ()
@@ -146,7 +146,7 @@ func (c *Client) Stop() error {
146146// GetCurrentTip returns the current chain tip
147147func (c * Client ) GetCurrentTip () (* Tip , error ) {
148148 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 ))
150150 done := atomic.Bool {}
151151 requestResultChan := make (chan Tip , 1 )
152152 requestErrorChan := make (chan error , 1 )
@@ -185,10 +185,14 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
185185 // The request is being handled by another request, wait for the result.
186186 waitingForCurrentTipChan = nil
187187 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 ))
188190 // The result from the other request is ready.
189191 done .Store (true )
190192 return & tip , nil
191193 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 ))
192196 // If waitingForCurrentTipChan is full, the for loop that empties it might finish the
193197 // loop before the select statement that writes to it is triggered. For that reason we
194198 // require requestResultChan here.
@@ -204,15 +208,25 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
204208func (c * Client ) GetAvailableBlockRange (
205209 intersectPoints []common.Point ,
206210) (common.Point , common.Point , error ) {
207- c .Protocol .Logger ().
208- Debug (fmt .Sprintf ("client called %s GetAvailableBlockRange(intersectPoints: %+v)" , ProtocolName , intersectPoints ))
209211 c .busyMutex .Lock ()
210212 defer c .busyMutex .Unlock ()
211213
212214 // Use origin if no intersect points were specified
213215 if len (intersectPoints ) == 0 {
214216 intersectPoints = []common.Point {common .NewPointOrigin ()}
215217 }
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+
216230 // Find our chain intersection
217231 result := c .requestFindIntersect (intersectPoints )
218232 if result .error != nil {
@@ -279,14 +293,24 @@ func (c *Client) GetAvailableBlockRange(
279293// Sync begins a chain-sync operation using the provided intersect point(s). Incoming blocks will be delivered
280294// via the RollForward callback function specified in the protocol config
281295func (c * Client ) Sync (intersectPoints []common.Point ) error {
282- c .Protocol .Logger ().
283- Debug (fmt .Sprintf ("client called %s Sync(intersectPoints: %+v)" , ProtocolName , intersectPoints ))
284296 c .busyMutex .Lock ()
285297 defer c .busyMutex .Unlock ()
298+
286299 // Use origin if no intersect points were specified
287300 if len (intersectPoints ) == 0 {
288301 intersectPoints = []common.Point {common .NewPointOrigin ()}
289302 }
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+ }
290314
291315 intersectResultChan , cancel := c .wantIntersectFound ()
292316 msg := NewMsgFindIntersect (intersectPoints )
@@ -430,8 +454,6 @@ func (c *Client) requestFindIntersect(
430454}
431455
432456func (c * Client ) messageHandler (msg protocol.Message ) error {
433- c .Protocol .Logger ().
434- Debug (fmt .Sprintf ("handling client message for %s" , ProtocolName ))
435457 var err error
436458 switch msg .Type () {
437459 case MessageTypeAwaitReply :
@@ -456,13 +478,13 @@ func (c *Client) messageHandler(msg protocol.Message) error {
456478
457479func (c * Client ) handleAwaitReply () error {
458480 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 ))
460482 return nil
461483}
462484
463485func (c * Client ) handleRollForward (msgGeneric protocol.Message ) error {
464486 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 ))
466488 firstBlockChan := func () chan <- clientPointResult {
467489 select {
468490 case ch := <- c .wantFirstBlockChan :
@@ -572,7 +594,7 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error {
572594
573595func (c * Client ) handleRollBackward (msg protocol.Message ) error {
574596 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 ))
576598 msgRollBackward := msg .(* MsgRollBackward )
577599 c .sendCurrentTip (msgRollBackward .Tip )
578600 if len (c .wantFirstBlockChan ) == 0 {
@@ -599,7 +621,7 @@ func (c *Client) handleRollBackward(msg protocol.Message) error {
599621
600622func (c * Client ) handleIntersectFound (msg protocol.Message ) error {
601623 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 ))
603625 msgIntersectFound := msg .(* MsgIntersectFound )
604626 c .sendCurrentTip (msgIntersectFound .Tip )
605627
@@ -613,7 +635,7 @@ func (c *Client) handleIntersectFound(msg protocol.Message) error {
613635
614636func (c * Client ) handleIntersectNotFound (msgGeneric protocol.Message ) error {
615637 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 ))
617639 msgIntersectNotFound := msgGeneric .(* MsgIntersectNotFound )
618640 c .sendCurrentTip (msgIntersectNotFound .Tip )
619641
0 commit comments