@@ -117,7 +117,11 @@ func NewClient(
117117func (c * Client ) Start () {
118118 c .onceStart .Do (func () {
119119 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+ )
121125 c .Protocol .Start ()
122126 // Start goroutine to cleanup resources on protocol shutdown
123127 go func () {
@@ -132,7 +136,11 @@ func (c *Client) Stop() error {
132136 var err error
133137 c .onceStop .Do (func () {
134138 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+ )
136144 c .busyMutex .Lock ()
137145 defer c .busyMutex .Unlock ()
138146 msg := NewMsgDone ()
@@ -146,7 +154,12 @@ func (c *Client) Stop() error {
146154// GetCurrentTip returns the current chain tip
147155func (c * Client ) GetCurrentTip () (* Tip , error ) {
148156 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+ )
150163 done := atomic.Bool {}
151164 requestResultChan := make (chan Tip , 1 )
152165 requestErrorChan := make (chan error , 1 )
@@ -186,13 +199,25 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
186199 waitingForCurrentTipChan = nil
187200 case tip := <- waitingResultChan :
188201 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+ )
190209 // The result from the other request is ready.
191210 done .Store (true )
192211 return & tip , nil
193212 case tip := <- requestResultChan :
194213 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+ )
196221 // If waitingForCurrentTipChan is full, the for loop that empties it might finish the
197222 // loop before the select statement that writes to it is triggered. For that reason we
198223 // require requestResultChan here.
@@ -215,16 +240,49 @@ func (c *Client) GetAvailableBlockRange(
215240 if len (intersectPoints ) == 0 {
216241 intersectPoints = []common.Point {common .NewPointOrigin ()}
217242 }
243+
244+ // Debug logging
218245 switch len (intersectPoints ) {
219246 case 1 :
220247 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+ )
222259 case 2 :
223260 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+ )
225274 default :
226275 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+ )
228286 }
229287
230288 // Find our chain intersection
@@ -300,16 +358,49 @@ func (c *Client) Sync(intersectPoints []common.Point) error {
300358 if len (intersectPoints ) == 0 {
301359 intersectPoints = []common.Point {common .NewPointOrigin ()}
302360 }
361+
362+ // Debug logging
303363 switch len (intersectPoints ) {
304364 case 1 :
305365 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+ )
307377 case 2 :
308378 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+ )
310392 default :
311393 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+ )
313404 }
314405
315406 intersectResultChan , cancel := c .wantIntersectFound ()
@@ -478,13 +569,23 @@ func (c *Client) messageHandler(msg protocol.Message) error {
478569
479570func (c * Client ) handleAwaitReply () error {
480571 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+ )
482578 return nil
483579}
484580
485581func (c * Client ) handleRollForward (msgGeneric protocol.Message ) error {
486582 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+ )
488589 firstBlockChan := func () chan <- clientPointResult {
489590 select {
490591 case ch := <- c .wantFirstBlockChan :
@@ -594,7 +695,12 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error {
594695
595696func (c * Client ) handleRollBackward (msg protocol.Message ) error {
596697 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+ )
598704 msgRollBackward := msg .(* MsgRollBackward )
599705 c .sendCurrentTip (msgRollBackward .Tip )
600706 if len (c .wantFirstBlockChan ) == 0 {
@@ -621,7 +727,12 @@ func (c *Client) handleRollBackward(msg protocol.Message) error {
621727
622728func (c * Client ) handleIntersectFound (msg protocol.Message ) error {
623729 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+ )
625736 msgIntersectFound := msg .(* MsgIntersectFound )
626737 c .sendCurrentTip (msgIntersectFound .Tip )
627738
@@ -635,7 +746,12 @@ func (c *Client) handleIntersectFound(msg protocol.Message) error {
635746
636747func (c * Client ) handleIntersectNotFound (msgGeneric protocol.Message ) error {
637748 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+ )
639755 msgIntersectNotFound := msgGeneric .(* MsgIntersectNotFound )
640756 c .sendCurrentTip (msgIntersectNotFound .Tip )
641757
0 commit comments