From 085fd66f33a8d244cb5003a13ecfcee9a924bf83 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 17 Dec 2020 11:55:41 +0400 Subject: [PATCH] p2p: do not format raw msg bytes While debugging the mempool issue (#5796), I've noticed we're spending quite a bit of time encoding blobs of data, which never get printed! The reason is filtering occurs on the level below, so Go runtime rightfully evaluates function arguments. I think it's okay to not format raw bytes. --- p2p/conn/connection.go | 8 ++++---- p2p/switch.go | 2 +- rpc/jsonrpc/client/ws_client.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index e597b4c63..e2c5fe1a7 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -352,7 +352,7 @@ func (c *MConnection) Send(chID byte, msgBytes []byte) bool { return false } - c.Logger.Debug("Send", "channel", chID, "conn", c, "msgBytes", fmt.Sprintf("%X", msgBytes)) + c.Logger.Debug("Send", "channel", chID, "conn", c, "msgBytes", msgBytes) // Send message to channel. channel, ok := c.channelsIdx[chID] @@ -369,7 +369,7 @@ func (c *MConnection) Send(chID byte, msgBytes []byte) bool { default: } } else { - c.Logger.Debug("Send failed", "channel", chID, "conn", c, "msgBytes", fmt.Sprintf("%X", msgBytes)) + c.Logger.Debug("Send failed", "channel", chID, "conn", c, "msgBytes", msgBytes) } return success } @@ -381,7 +381,7 @@ func (c *MConnection) TrySend(chID byte, msgBytes []byte) bool { return false } - c.Logger.Debug("TrySend", "channel", chID, "conn", c, "msgBytes", fmt.Sprintf("%X", msgBytes)) + c.Logger.Debug("TrySend", "channel", chID, "conn", c, "msgBytes", msgBytes) // Send message to channel. channel, ok := c.channelsIdx[chID] @@ -640,7 +640,7 @@ FOR_LOOP: break FOR_LOOP } if msgBytes != nil { - c.Logger.Debug("Received bytes", "chID", pkt.PacketMsg.ChannelID, "msgBytes", fmt.Sprintf("%X", msgBytes)) + c.Logger.Debug("Received bytes", "chID", pkt.PacketMsg.ChannelID, "msgBytes", msgBytes) // NOTE: This means the reactor.Receive runs in the same thread as the p2p recv routine c.onReceive(byte(pkt.PacketMsg.ChannelID), msgBytes) } diff --git a/p2p/switch.go b/p2p/switch.go index 99cc04868..9eff790be 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -272,7 +272,7 @@ func (sw *Switch) OnStop() { // // NOTE: Broadcast uses goroutines, so order of broadcast may not be preserved. func (sw *Switch) Broadcast(chID byte, msgBytes []byte) chan bool { - sw.Logger.Debug("Broadcast", "channel", chID, "msgBytes", fmt.Sprintf("%X", msgBytes)) + sw.Logger.Debug("Broadcast", "channel", chID, "msgBytes", msgBytes) peers := sw.peers.List() var wg sync.WaitGroup diff --git a/rpc/jsonrpc/client/ws_client.go b/rpc/jsonrpc/client/ws_client.go index 1c7ade657..c30e4e1d9 100644 --- a/rpc/jsonrpc/client/ws_client.go +++ b/rpc/jsonrpc/client/ws_client.go @@ -511,7 +511,7 @@ func (c *WSClient) readRoutine() { // c.wg.Wait() in c.Stop(). Note we rely on Quit being closed so that it sends unlimited Quit signals to stop // both readRoutine and writeRoutine - c.Logger.Info("got response", "id", response.ID, "result", fmt.Sprintf("%X", response.Result)) + c.Logger.Info("got response", "id", response.ID, "result", response.Result) select { case <-c.Quit():