Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 627a2de

Browse files
committed
[CSL-1822] Print header of received block less often
Before this commit online and up-to-date node was printing header of a newly created block received from the network 5 times. It's quite a lot, especially considering that each header takes about 9 lines. Few observations: 1. Printing header in 'handleUnsolicitedHeader' makes more sense than in 'addHeaderToBlockRequestQueue', because it's called earlier and allows us to inspect header before we do something with it. 2. Printing header after we processed it is not useful, because we must have printed it already. Printing hash is enough. 3. 'handleContinues' and 'handleAlternative' are called after we receive an unsolicited header. It implies that we have printed it already, so we can print its hash.
1 parent bea79ed commit 627a2de

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

block/src/Pos/Block/Network/Announce.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ announceBlock
4343
:: BlockWorkMode ctx m
4444
=> EnqueueMsg m -> MainBlockHeader -> m (Map NodeId (m ()))
4545
announceBlock enqueue header = do
46-
logDebug $ sformat ("Announcing header to others:\n"%build) header
46+
logDebug $ sformat ("Announcing header to others: "%shortHashF)
47+
(headerHash header)
4748
enqueue (MsgAnnounceBlockHeader OriginSender) (\addr _ -> announceBlockDo addr)
4849
where
4950
announceBlockDo

block/src/Pos/Block/Network/Logic.hs

+7-6
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,8 @@ handleUnsolicitedHeader
184184
-> m ()
185185
handleUnsolicitedHeader header nodeId = do
186186
logDebug $ sformat
187-
("handleUnsolicitedHeader: single header "%shortHashF%
188-
" was propagated, processing")
189-
hHash
187+
("handleUnsolicitedHeader: single header was propagated, processing:\n"
188+
%build) header
190189
classificationRes <- classifyNewHeader header
191190
-- TODO: should we set 'To' hash to hash of header or leave it unlimited?
192191
case classificationRes of
@@ -399,7 +398,8 @@ addHeaderToBlockRequestQueue
399398
-> Bool -- ^ Was classified as chain continuation
400399
-> m ()
401400
addHeaderToBlockRequestQueue nodeId header continues = do
402-
logDebug $ sformat ("addToBlockRequestQueue, : "%build) header
401+
let hHash = headerHash header
402+
logDebug $ sformat ("addToBlockRequestQueue, : "%shortHashF) hHash
403403
queue <- view (lensOf @BlockRetrievalQueueTag)
404404
lastKnownH <- view (lensOf @LastKnownHeaderTag)
405405
added <- atomically $ do
@@ -409,7 +409,7 @@ addHeaderToBlockRequestQueue nodeId header continues = do
409409
if added
410410
then logDebug $ sformat ("Added headers to block request queue: nodeId="%build%
411411
", header="%build)
412-
nodeId (headerHash header)
412+
nodeId hHash
413413
else logWarning $ sformat ("Failed to add headers from "%build%
414414
" to block retrieval queue: queue is full")
415415
nodeId
@@ -581,7 +581,8 @@ relayBlock enqueue (Right mainBlk) = do
581581
recoveryInProgress >>= \case
582582
True -> logDebug "Not relaying block in recovery mode"
583583
False -> do
584-
logDebug $ sformat ("Calling announceBlock for "%build%".") (mainBlk ^. gbHeader)
584+
logDebug $ sformat ("Calling announceBlock for "%shortHashF%".")
585+
(mainBlk ^. gbHeader . headerHashG)
585586
void $ announceBlock enqueue $ mainBlk ^. gbHeader
586587

587588
----------------------------------------------------------------------------

block/src/Pos/Block/Network/Retrieval.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ retrievalWorkerImpl keepAliveTimer SendActions {..} =
126126

127127
-- When we have continuation, we just try to get and apply it.
128128
handleContinues nodeId header = do
129-
logDebug $ "handleContinues: " <> pretty header
129+
let hHash = headerHash header
130+
logDebug $ "handleContinues: " <> pretty hHash
130131
classifyNewHeader header >>= \case
131132
CHContinues ->
132-
void $ getProcessBlocks enqueueMsg nodeId header (headerHash header)
133+
void $ getProcessBlocks enqueueMsg nodeId header hHash
133134
res -> logDebug $
134135
"processContHeader: expected header to " <>
135136
"be continuation, but it's " <> show res
@@ -138,7 +139,7 @@ retrievalWorkerImpl keepAliveTimer SendActions {..} =
138139
-- really recovery mode (server side should send us headers as a
139140
-- proof) and then enter recovery mode.
140141
handleAlternative nodeId header = do
141-
logDebug $ "handleAlternative: " <> pretty header
142+
logDebug $ "handleAlternative: " <> pretty (headerHash header)
142143
classifyNewHeader header >>= \case
143144
CHInvalid _ ->
144145
logError "handleAlternative: invalid header got into retrievalWorker queue"

0 commit comments

Comments
 (0)