@@ -100,6 +100,7 @@ func NewClient(
100
100
Name : ProtocolName ,
101
101
ProtocolId : ProtocolId ,
102
102
Muxer : protoOptions .Muxer ,
103
+ Logger : protoOptions .Logger ,
103
104
ErrorChan : protoOptions .ErrorChan ,
104
105
Mode : protoOptions .Mode ,
105
106
Role : protocol .ProtocolRoleClient ,
@@ -115,6 +116,8 @@ func NewClient(
115
116
116
117
func (c * Client ) Start () {
117
118
c .onceStart .Do (func () {
119
+ c .Protocol .Logger ().
120
+ Debug (fmt .Sprintf ("starting protocol: %s" , ProtocolName ))
118
121
c .Protocol .Start ()
119
122
// Start goroutine to cleanup resources on protocol shutdown
120
123
go func () {
@@ -124,33 +127,12 @@ func (c *Client) Start() {
124
127
})
125
128
}
126
129
127
- func (c * Client ) messageHandler (msg protocol.Message ) error {
128
- var err error
129
- switch msg .Type () {
130
- case MessageTypeAwaitReply :
131
- err = c .handleAwaitReply ()
132
- case MessageTypeRollForward :
133
- err = c .handleRollForward (msg )
134
- case MessageTypeRollBackward :
135
- err = c .handleRollBackward (msg )
136
- case MessageTypeIntersectFound :
137
- err = c .handleIntersectFound (msg )
138
- case MessageTypeIntersectNotFound :
139
- err = c .handleIntersectNotFound (msg )
140
- default :
141
- err = fmt .Errorf (
142
- "%s: received unexpected message type %d" ,
143
- ProtocolName ,
144
- msg .Type (),
145
- )
146
- }
147
- return err
148
- }
149
-
150
130
// Stop transitions the protocol to the Done state. No more protocol operations will be possible afterward
151
131
func (c * Client ) Stop () error {
152
132
var err error
153
133
c .onceStop .Do (func () {
134
+ c .Protocol .Logger ().
135
+ Debug (fmt .Sprintf ("stopping protocol: %s" , ProtocolName ))
154
136
c .busyMutex .Lock ()
155
137
defer c .busyMutex .Unlock ()
156
138
msg := NewMsgDone ()
@@ -163,6 +145,8 @@ func (c *Client) Stop() error {
163
145
164
146
// GetCurrentTip returns the current chain tip
165
147
func (c * Client ) GetCurrentTip () (* Tip , error ) {
148
+ c .Protocol .Logger ().
149
+ Debug (fmt .Sprintf ("client called %s GetCurrentTip()" , ProtocolName ))
166
150
done := atomic.Bool {}
167
151
requestResultChan := make (chan Tip , 1 )
168
152
requestErrorChan := make (chan error , 1 )
@@ -220,6 +204,8 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
220
204
func (c * Client ) GetAvailableBlockRange (
221
205
intersectPoints []common.Point ,
222
206
) (common.Point , common.Point , error ) {
207
+ c .Protocol .Logger ().
208
+ Debug (fmt .Sprintf ("client called %s GetAvailableBlockRange(intersectPoints: %+v)" , ProtocolName , intersectPoints ))
223
209
c .busyMutex .Lock ()
224
210
defer c .busyMutex .Unlock ()
225
211
@@ -293,6 +279,8 @@ func (c *Client) GetAvailableBlockRange(
293
279
// Sync begins a chain-sync operation using the provided intersect point(s). Incoming blocks will be delivered
294
280
// via the RollForward callback function specified in the protocol config
295
281
func (c * Client ) Sync (intersectPoints []common.Point ) error {
282
+ c .Protocol .Logger ().
283
+ Debug (fmt .Sprintf ("client called %s Sync(intersectPoints: %+v)" , ProtocolName , intersectPoints ))
296
284
c .busyMutex .Lock ()
297
285
defer c .busyMutex .Unlock ()
298
286
// Use origin if no intersect points were specified
@@ -441,11 +429,40 @@ func (c *Client) requestFindIntersect(
441
429
}
442
430
}
443
431
432
+ func (c * Client ) messageHandler (msg protocol.Message ) error {
433
+ c .Protocol .Logger ().
434
+ Debug (fmt .Sprintf ("handling client message for %s" , ProtocolName ))
435
+ var err error
436
+ switch msg .Type () {
437
+ case MessageTypeAwaitReply :
438
+ err = c .handleAwaitReply ()
439
+ case MessageTypeRollForward :
440
+ err = c .handleRollForward (msg )
441
+ case MessageTypeRollBackward :
442
+ err = c .handleRollBackward (msg )
443
+ case MessageTypeIntersectFound :
444
+ err = c .handleIntersectFound (msg )
445
+ case MessageTypeIntersectNotFound :
446
+ err = c .handleIntersectNotFound (msg )
447
+ default :
448
+ err = fmt .Errorf (
449
+ "%s: received unexpected message type %d" ,
450
+ ProtocolName ,
451
+ msg .Type (),
452
+ )
453
+ }
454
+ return err
455
+ }
456
+
444
457
func (c * Client ) handleAwaitReply () error {
458
+ c .Protocol .Logger ().
459
+ Debug (fmt .Sprintf ("handling client await reply for %s" , ProtocolName ))
445
460
return nil
446
461
}
447
462
448
463
func (c * Client ) handleRollForward (msgGeneric protocol.Message ) error {
464
+ c .Protocol .Logger ().
465
+ Debug (fmt .Sprintf ("handling client roll forward for %s" , ProtocolName ))
449
466
firstBlockChan := func () chan <- clientPointResult {
450
467
select {
451
468
case ch := <- c .wantFirstBlockChan :
@@ -554,6 +571,8 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error {
554
571
}
555
572
556
573
func (c * Client ) handleRollBackward (msg protocol.Message ) error {
574
+ c .Protocol .Logger ().
575
+ Debug (fmt .Sprintf ("handling client roll backward for %s" , ProtocolName ))
557
576
msgRollBackward := msg .(* MsgRollBackward )
558
577
c .sendCurrentTip (msgRollBackward .Tip )
559
578
if len (c .wantFirstBlockChan ) == 0 {
@@ -579,6 +598,8 @@ func (c *Client) handleRollBackward(msg protocol.Message) error {
579
598
}
580
599
581
600
func (c * Client ) handleIntersectFound (msg protocol.Message ) error {
601
+ c .Protocol .Logger ().
602
+ Debug (fmt .Sprintf ("handling client intersect found for %s" , ProtocolName ))
582
603
msgIntersectFound := msg .(* MsgIntersectFound )
583
604
c .sendCurrentTip (msgIntersectFound .Tip )
584
605
@@ -591,6 +612,8 @@ func (c *Client) handleIntersectFound(msg protocol.Message) error {
591
612
}
592
613
593
614
func (c * Client ) handleIntersectNotFound (msgGeneric protocol.Message ) error {
615
+ c .Protocol .Logger ().
616
+ Debug (fmt .Sprintf ("handling client intersect not found for %s" , ProtocolName ))
594
617
msgIntersectNotFound := msgGeneric .(* MsgIntersectNotFound )
595
618
c .sendCurrentTip (msgIntersectNotFound .Tip )
596
619
0 commit comments