@@ -98,6 +98,7 @@ class BlockFetcher(
9898
9999 private def handleCommands (state : BlockFetcherState ): Receive = {
100100 case PickBlocks (amount) => state.pickBlocks(amount) |> handlePickedBlocks(state) |> fetchBlocks
101+
101102 case StrictPickBlocks (from, atLeastWith) =>
102103 // FIXME: Consider having StrictPickBlocks calls guaranteeing this
103104 // from parameter could be negative or 0 so we should cap it to 1 if that's the case
@@ -113,9 +114,10 @@ class BlockFetcher(
113114 }
114115
115116 fetchBlocks(newState)
117+
116118 case InvalidateBlocksFrom (blockNr, reason, withBlacklist) =>
117119 val (blockProvider, newState) = state.invalidateBlocksFrom(blockNr, withBlacklist)
118- log.debug (" Invalidate blocks from {}" , blockNr)
120+ log.info (" Invalidate blocks from {}" , blockNr)
119121 blockProvider.foreach(peersClient ! BlacklistPeer (_, reason))
120122 fetchBlocks(newState)
121123 }
@@ -124,7 +126,7 @@ class BlockFetcher(
124126 case Response (_, BlockHeaders (headers)) if state.isFetchingHeaders =>
125127 val newState =
126128 if (state.fetchingHeadersState == AwaitingHeadersToBeIgnored ) {
127- log.debug (
129+ log.info (
128130 " Received {} headers starting from block {} that will be ignored" ,
129131 headers.size,
130132 headers.headOption.map(_.number)
@@ -149,17 +151,17 @@ class BlockFetcher(
149151
150152 fetchBlocks(newState)
151153 case RetryHeadersRequest if state.isFetchingHeaders =>
152- log.debug (" Something failed on a headers request, cancelling the request and re-fetching" )
154+ log.info (" Something failed on a headers request, cancelling the request and re-fetching" )
153155
154156 val newState = state.withHeaderFetchReceived
155157 fetchBlocks(newState)
156158 }
157159
158160 private def handleBodiesMessages (state : BlockFetcherState ): Receive = {
159161 case Response (peer, BlockBodies (bodies)) if state.isFetchingBodies =>
160- log.debug(s " Received ${bodies.size } block bodies " )
162+ log.debug(" Received { } block bodies" , bodies.size )
161163 if (state.fetchingBodiesState == AwaitingBodiesToBeIgnored ) {
162- log.debug (" Block bodies will be ignored due to an invalidation was requested for them" )
164+ log.info (" Block bodies will be ignored due to an invalidation was requested for them" )
163165 fetchBlocks(state.withBodiesFetchReceived)
164166 } else {
165167 val newState =
@@ -171,19 +173,22 @@ class BlockFetcher(
171173 state.withBodiesFetchReceived.handleRequestedBlocks(newBlocks, peer.id)
172174 }
173175 val waitingHeadersDequeued = state.waitingHeaders.size - newState.waitingHeaders.size
174- log.debug(s " Processed $waitingHeadersDequeued new blocks from received block bodies " )
176+ log.debug(" Processed {} new blocks from received block bodies" , waitingHeadersDequeued )
175177 fetchBlocks(newState)
176178 }
179+
177180 case RetryBodiesRequest if state.isFetchingBodies =>
178- log.debug (" Something failed on a bodies request, cancelling the request and re-fetching" )
181+ log.info (" Something failed on a bodies request, cancelling the request and re-fetching" )
179182 val newState = state.withBodiesFetchReceived
180183 fetchBlocks(newState)
181184 }
182185
183186 private def handleStateNodeMessages (state : BlockFetcherState ): Receive = {
184187 case FetchStateNode (hash) => fetchStateNode(hash, sender(), state)
188+
185189 case RetryFetchStateNode if state.isFetchingStateNode =>
186190 state.stateNodeFetcher.foreach(fetcher => fetchStateNode(fetcher.hash, fetcher.replyTo, state))
191+
187192 case Response (peer, NodeData (values)) if state.isFetchingStateNode =>
188193 log.debug(" Received state node response from peer {}" , peer)
189194 state.stateNodeFetcher.foreach(fetcher => {
@@ -196,7 +201,7 @@ class BlockFetcher(
196201
197202 validatedNode match {
198203 case Left (err) =>
199- log.debug (err)
204+ log.info (err)
200205 peersClient ! BlacklistPeer (peer.id, err)
201206 fetchStateNode(fetcher.hash, fetcher.replyTo, state)
202207 case Right (node) =>
@@ -215,10 +220,13 @@ class BlockFetcher(
215220 }
216221 supervisor ! ProgressProtocol .GotNewBlock (newState.knownTop)
217222 fetchBlocks(newState)
223+
218224 case MessageFromPeer (CommonMessages .NewBlock (block, _), peerId) =>
219225 handleNewBlock(block, peerId, state)
226+
220227 case MessageFromPeer (PV64 .NewBlock (block, _), peerId) =>
221228 handleNewBlock(block, peerId, state)
229+
222230 case BlockImportFailed (blockNr, reason) =>
223231 val (peerId, newState) = state.invalidateBlocksFrom(blockNr)
224232 peerId.foreach(id => peersClient ! BlacklistPeer (id, reason))
@@ -247,7 +255,7 @@ class BlockFetcher(
247255 }
248256
249257 private def handleFutureBlock (block : Block , state : BlockFetcherState ): Unit = {
250- log.debug (" Ignoring received block as it doesn't match local state or fetch side is not on top" )
258+ log.info (" Ignoring received block as it doesn't match local state or fetch side is not on top" )
251259 val newState = state.withPossibleNewTopAt(block.number)
252260 supervisor ! ProgressProtocol .GotNewBlock (newState.knownTop)
253261 fetchBlocks(newState)
@@ -259,16 +267,18 @@ class BlockFetcher(
259267 state.tryInsertBlock(block, peerId) match {
260268 case Left (_) if block.number <= state.lastBlock =>
261269 log.debug(
262- s " Checkpoint block ${ByteStringUtils .hash2string(blockHash)} is older than current last block ${state.lastBlock}" +
263- s " - clearing the queues and putting checkpoint to ready blocks queue "
270+ " Checkpoint block {} is older than current last block {} - clearing the queues and putting checkpoint to ready blocks queue" ,
271+ ByteStringUtils .hash2string(blockHash),
272+ state.lastBlock
264273 )
265274 val newState = state
266275 .clearQueues()
267276 .enqueueReadyBlock(block, peerId)
268277 fetchBlocks(newState)
269278 case Left (_) if block.number <= state.knownTop =>
270279 log.debug(
271- s " Checkpoint block ${ByteStringUtils .hash2string(blockHash)} not fit into queues - clearing the queues and setting possible new top "
280+ " Checkpoint block {} not fit into queues - clearing the queues and setting possible new top" ,
281+ ByteStringUtils .hash2string(blockHash)
272282 )
273283 val newState = state
274284 .clearQueues()
@@ -279,7 +289,7 @@ class BlockFetcher(
279289 log.debug(error)
280290 handleFutureBlock(block, state)
281291 case Right (state) =>
282- log.debug(s " Checkpoint block [ ${ ByteStringUtils .hash2string(blockHash) }] fit into queues " )
292+ log.debug(" Checkpoint block [{ }] fit into queues" , ByteStringUtils .hash2string(blockHash) )
283293 fetchBlocks(state)
284294 }
285295 }
@@ -289,20 +299,20 @@ class BlockFetcher(
289299 // ex. After a successful handshake, fetcher will receive the info about the header of the peer best block
290300 case MessageFromPeer (BlockHeaders (headers), _) =>
291301 headers.lastOption.map { bh =>
292- log.debug( s " Candidate for new top at block ${bh.number }, current known top ${ state.knownTop} " )
302+ log.info( " Candidate for new top at block { }, current known top {} " , bh.number, state.knownTop)
293303 val newState = state.withPossibleNewTopAt(bh.number)
294304 fetchBlocks(newState)
295305 }
296306 // keep fetcher state updated in case new mined block was imported
297307 case InternalLastBlockImport (blockNr) =>
298- log.debug( s " New mined block $blockNr imported from the inside " )
308+ log.info( " New mined block {} imported from the inside" , blockNr )
299309 val newState = state.withLastBlock(blockNr).withPossibleNewTopAt(blockNr)
300310
301311 fetchBlocks(newState)
302312
303313 // keep fetcher state updated in case new checkpoint block was imported
304314 case InternalCheckpointImport (blockNr) =>
305- log.debug( s " New checkpoint block $blockNr imported from the inside " )
315+ log.info( " New checkpoint block {} imported from the inside" , blockNr )
306316
307317 val newState = state
308318 .clearQueues()
@@ -414,13 +424,16 @@ class BlockFetcher(
414424
415425 private def handleRequestResult (fallback : FetchMsg )(msg : Any ): Task [Any ] = msg match {
416426 case failed : RequestFailed =>
417- log.debug (" Request failed due to {}" , failed)
427+ log.error (" Request failed due to {}" , failed)
418428 Task .now(fallback)
429+
419430 case NoSuitablePeer =>
420431 Task .now(fallback).delayExecution(syncConfig.syncRetryInterval)
432+
421433 case Failure (cause) =>
422434 log.error(cause, " Unexpected error on the request result" )
423435 Task .now(fallback)
436+
424437 case m =>
425438 Task .now(m)
426439 }
0 commit comments