Skip to content

Commit 4e361c5

Browse files
authored
fix: standardize mini-protocol debug logging (#741)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 59c7df4 commit 4e361c5

File tree

18 files changed

+110
-101
lines changed

18 files changed

+110
-101
lines changed

protocol/blockfetch/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
8282
func (c *Client) Start() {
8383
c.onceStart.Do(func() {
8484
c.Protocol.Logger().
85-
Debug(fmt.Sprintf("%s: starting protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
85+
Debug(fmt.Sprintf("%s: starting client protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
8686
c.Protocol.Start()
8787
// Start goroutine to cleanup resources on protocol shutdown
8888
go func() {
@@ -97,7 +97,7 @@ func (c *Client) Stop() error {
9797
var err error
9898
c.onceStop.Do(func() {
9999
c.Protocol.Logger().
100-
Debug(fmt.Sprintf("%s: stopping protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
100+
Debug(fmt.Sprintf("%s: stopping client protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
101101
msg := NewMsgClientDone()
102102
err = c.SendMessage(msg)
103103
})

protocol/blockfetch/server.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ func (s *Server) initProtocol() {
6161

6262
func (s *Server) NoBlocks() error {
6363
s.Protocol.Logger().
64-
Debug(fmt.Sprintf("server called %s NoBlocks()", ProtocolName))
64+
Debug(fmt.Sprintf("%s: server %+v called NoBlocks()", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
6565
msg := NewMsgNoBlocks()
6666
return s.SendMessage(msg)
6767
}
6868

6969
func (s *Server) StartBatch() error {
7070
s.Protocol.Logger().
71-
Debug(fmt.Sprintf("server called %s StartBatch()", ProtocolName))
71+
Debug(fmt.Sprintf("%s: server %+v called StartBatch()", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
7272
msg := NewMsgStartBatch()
7373
return s.SendMessage(msg)
7474
}
7575

7676
func (s *Server) Block(blockType uint, blockData []byte) error {
7777
s.Protocol.Logger().
78-
Debug(fmt.Sprintf("server called %s Block(blockType: %+v, blockData: %x)", ProtocolName, blockType, blockData))
78+
Debug(fmt.Sprintf("%s: server %+v called Block(blockType: %+v, blockData: %x)", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr, blockType, blockData))
7979
wrappedBlock := WrappedBlock{
8080
Type: blockType,
8181
RawBlock: blockData,
@@ -90,14 +90,12 @@ func (s *Server) Block(blockType uint, blockData []byte) error {
9090

9191
func (s *Server) BatchDone() error {
9292
s.Protocol.Logger().
93-
Debug(fmt.Sprintf("server called %s BatchDone()", ProtocolName))
93+
Debug(fmt.Sprintf("%s: server %+v called BatchDone()", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
9494
msg := NewMsgBatchDone()
9595
return s.SendMessage(msg)
9696
}
9797

9898
func (s *Server) messageHandler(msg protocol.Message) error {
99-
s.Protocol.Logger().
100-
Debug(fmt.Sprintf("handling server message for %s", ProtocolName))
10199
var err error
102100
switch msg.Type() {
103101
case MessageTypeRequestRange:
@@ -116,7 +114,7 @@ func (s *Server) messageHandler(msg protocol.Message) error {
116114

117115
func (s *Server) handleRequestRange(msg protocol.Message) error {
118116
s.Protocol.Logger().
119-
Debug(fmt.Sprintf("handling server request range for %s", ProtocolName))
117+
Debug(fmt.Sprintf("%s: server request range for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
120118
if s.config == nil || s.config.RequestRangeFunc == nil {
121119
return fmt.Errorf(
122120
"received block-fetch RequestRange message but no callback function is defined",
@@ -132,7 +130,7 @@ func (s *Server) handleRequestRange(msg protocol.Message) error {
132130

133131
func (s *Server) handleClientDone() error {
134132
s.Protocol.Logger().
135-
Debug(fmt.Sprintf("handling server client done for %s", ProtocolName))
133+
Debug(fmt.Sprintf("%s: server client done for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
136134
// Restart protocol
137135
s.Protocol.Stop()
138136
s.initProtocol()

protocol/chainsync/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func NewClient(
117117
func (c *Client) Start() {
118118
c.onceStart.Do(func() {
119119
c.Protocol.Logger().
120-
Debug(fmt.Sprintf("%s: starting protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
120+
Debug(fmt.Sprintf("%s: starting client 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("%s: stopping protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
135+
Debug(fmt.Sprintf("%s: stopping client protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
136136
c.busyMutex.Lock()
137137
defer c.busyMutex.Unlock()
138138
msg := NewMsgDone()

protocol/chainsync/server.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ func (s *Server) initProtocol() {
7979

8080
func (s *Server) RollBackward(point common.Point, tip Tip) error {
8181
s.Protocol.Logger().
82-
Debug(fmt.Sprintf("server called %s RollBackward(point: %+v, tip: %+v)", ProtocolName, point, tip))
82+
Debug(fmt.Sprintf("%s: server %+v called RollBackward(point: {Slot: %d, Hash: %x}, tip: {Point: %+v, BlockNumber: %d})", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr, point.Slot, point.Hash, tip.Point, tip.BlockNumber))
8383
msg := NewMsgRollBackward(point, tip)
8484
return s.SendMessage(msg)
8585
}
8686

8787
func (s *Server) AwaitReply() error {
8888
s.Protocol.Logger().
89-
Debug(fmt.Sprintf("server called %s AwaitReply()", ProtocolName))
89+
Debug(fmt.Sprintf("%s: server %+v called AwaitReply()", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
9090
msg := NewMsgAwaitReply()
9191
return s.SendMessage(msg)
9292
}
9393

9494
func (s *Server) RollForward(blockType uint, blockData []byte, tip Tip) error {
9595
s.Protocol.Logger().
96-
Debug(fmt.Sprintf("server called %s Rollforward(blockType: %+v, blockData: %x, tip: %+v)", ProtocolName, blockType, blockData, tip))
96+
Debug(fmt.Sprintf("%s: server %+v called RollForward(blockType: %+v, blockData: %x, tip: {Point: {Slot: %d, Hash: %x}, BlockNumber: %d})", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr, blockType, blockData, tip.Point.Slot, tip.Point.Hash, tip.BlockNumber))
9797
if s.Mode() == protocol.ProtocolModeNodeToNode {
9898
eraId := ledger.BlockToBlockHeaderTypeMap[blockType]
9999
msg := NewMsgRollForwardNtN(
@@ -114,8 +114,6 @@ func (s *Server) RollForward(blockType uint, blockData []byte, tip Tip) error {
114114
}
115115

116116
func (s *Server) messageHandler(msg protocol.Message) error {
117-
s.Protocol.Logger().
118-
Debug(fmt.Sprintf("handling server message for %s", ProtocolName))
119117
var err error
120118
switch msg.Type() {
121119
case MessageTypeRequestNext:
@@ -137,8 +135,8 @@ func (s *Server) messageHandler(msg protocol.Message) error {
137135
func (s *Server) handleRequestNext() error {
138136
// TODO: figure out why this one log message causes a panic (and only this one)
139137
// during tests
140-
// s.Protocol.Logger().
141-
// Debug(fmt.Sprintf("handling server request next for %s", ProtocolName))
138+
//s.Protocol.Logger().
139+
// Debug(fmt.Sprintf("%s: server request next for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
142140
if s.config == nil || s.config.RequestNextFunc == nil {
143141
return fmt.Errorf(
144142
"received chain-sync RequestNext message but no callback function is defined",
@@ -149,7 +147,7 @@ func (s *Server) handleRequestNext() error {
149147

150148
func (s *Server) handleFindIntersect(msg protocol.Message) error {
151149
s.Protocol.Logger().
152-
Debug(fmt.Sprintf("handling server find intersect for %s", ProtocolName))
150+
Debug(fmt.Sprintf("%s: server find intersect for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
153151
if s.config == nil || s.config.FindIntersectFunc == nil {
154152
return fmt.Errorf(
155153
"received chain-sync FindIntersect message but no callback function is defined",
@@ -179,7 +177,7 @@ func (s *Server) handleFindIntersect(msg protocol.Message) error {
179177

180178
func (s *Server) handleDone() error {
181179
s.Protocol.Logger().
182-
Debug(fmt.Sprintf("handling server done for %s", ProtocolName))
180+
Debug(fmt.Sprintf("%s: server done for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
183181
// Restart protocol
184182
s.Protocol.Stop()
185183
s.initProtocol()

protocol/handshake/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
7070
func (c *Client) Start() {
7171
c.onceStart.Do(func() {
7272
c.Protocol.Logger().
73-
Debug(fmt.Sprintf("%s: starting protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
73+
Debug(fmt.Sprintf("%s: starting client protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
7474
c.Protocol.Start()
7575
// Send our ProposeVersions message
7676
msg := NewMsgProposeVersions(c.config.ProtocolVersionMap)

protocol/handshake/server.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ func NewServer(protoOptions protocol.ProtocolOptions, cfg *Config) *Server {
6161
}
6262

6363
func (s *Server) handleMessage(msg protocol.Message) error {
64-
s.Protocol.Logger().
65-
Debug(fmt.Sprintf("handling server message for %s", ProtocolName))
6664
var err error
6765
switch msg.Type() {
6866
case MessageTypeProposeVersions:
@@ -79,7 +77,7 @@ func (s *Server) handleMessage(msg protocol.Message) error {
7977

8078
func (s *Server) handleProposeVersions(msg protocol.Message) error {
8179
s.Protocol.Logger().
82-
Debug(fmt.Sprintf("handling server propose versions for %s", ProtocolName))
80+
Debug(fmt.Sprintf("%s: server propose versions for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
8381
if s.config.FinishedFunc == nil {
8482
return fmt.Errorf(
8583
"received handshake ProposeVersions message but no callback function is defined",

protocol/keepalive/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
7070
func (c *Client) Start() {
7171
c.onceStart.Do(func() {
7272
c.Protocol.Logger().
73-
Debug(fmt.Sprintf("%s: starting protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
73+
Debug(fmt.Sprintf("%s: starting client protocol for connection %+v", ProtocolName, c.callbackContext.ConnectionId.RemoteAddr))
7474
c.Protocol.Start()
7575
// Start goroutine to cleanup resources on protocol shutdown
7676
go func() {

protocol/keepalive/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func NewServer(protoOptions protocol.ProtocolOptions, cfg *Config) *Server {
3838
Name: ProtocolName,
3939
ProtocolId: ProtocolId,
4040
Muxer: protoOptions.Muxer,
41+
Logger: protoOptions.Logger,
4142
ErrorChan: protoOptions.ErrorChan,
4243
Mode: protoOptions.Mode,
4344
Role: protocol.ProtocolRoleServer,
@@ -68,6 +69,8 @@ func (s *Server) messageHandler(msg protocol.Message) error {
6869
}
6970

7071
func (s *Server) handleKeepAlive(msgGeneric protocol.Message) error {
72+
s.Protocol.Logger().
73+
Debug(fmt.Sprintf("%s: server keep alive for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
7174
msg := msgGeneric.(*MsgKeepAlive)
7275
if s.config != nil && s.config.KeepAliveFunc != nil {
7376
// Call the user callback function
@@ -80,6 +83,8 @@ func (s *Server) handleKeepAlive(msgGeneric protocol.Message) error {
8083
}
8184

8285
func (s *Server) handleDone() error {
86+
s.Protocol.Logger().
87+
Debug(fmt.Sprintf("%s: server done for %+v", ProtocolName, s.callbackContext.ConnectionId.RemoteAddr))
8388
if s.config != nil && s.config.DoneFunc != nil {
8489
// Call the user callback function
8590
return s.config.DoneFunc(s.callbackContext)

0 commit comments

Comments
 (0)