Skip to content

Commit 19ed816

Browse files
authored
Merge pull request #889 from input-output-hk/fix-failing-fetcher-test-checkpoint-block-fit-into-waiting-headers
[FIX] Block fetcher failing test fix
2 parents 5f38623 + 4696aa8 commit 19ed816

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockFetcherState.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ case class BlockFetcherState(
100100
.withKnownTopAt(block.number)
101101
Right(newState)
102102
} else if (isExistInWaitingHeaders(block.header.parentHash)) {
103+
// ignore already requested bodies
104+
val newFetchingBodiesState =
105+
if (fetchingBodiesState == AwaitingBodies) AwaitingBodiesToBeIgnored else fetchingBodiesState
103106
val newState = copy(
104-
waitingHeaders = waitingHeaders.takeWhile(_.number < block.number).enqueue(block.header)
107+
waitingHeaders = waitingHeaders.takeWhile(_.number < block.number).enqueue(block.header),
108+
fetchingBodiesState = newFetchingBodiesState
105109
)
106110
.withKnownTopAt(block.number)
107111
Right(newState)

src/test/scala/io/iohk/ethereum/blockchain/sync/regular/BlockFetcherSpec.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,25 @@ class BlockFetcherSpec
320320

321321
handleFirstBlockBatchBodies()
322322

323+
// second bodies request
324+
val secondGetBlockBodiesRequest = GetBlockBodies(secondBlocksBatch.map(_.hash))
325+
peersClient.expectMsgPF() { case PeersClient.Request(msg, _, _) if msg == secondGetBlockBodiesRequest => ()}
326+
323327
// send old checkpoint block
324328
blockFetcher ! MessageFromPeer(PV64.NewBlock(checkpointBlock, ChainWeight(checkpointBlock.number, checkpointBlock.header.difficulty)), fakePeer.id)
325329

326-
// Second bodies request
327-
val secondGetBlockBodiesRequest = GetBlockBodies(alternativeSecondBlocksBatch.map(_.hash))
328-
peersClient.expectMsgPF() { case PeersClient.Request(msg, _, _) if msg == secondGetBlockBodiesRequest => () }
329-
330-
// Second bodies response
331-
val secondGetBlockBodiesResponse = BlockBodies(alternativeSecondBlocksBatch.map(_.body))
330+
// second bodies response
331+
val secondGetBlockBodiesResponse = BlockBodies(secondBlocksBatch.map(_.body))
332332
peersClient.reply(PeersClient.Response(fakePeer, secondGetBlockBodiesResponse))
333333

334+
// third bodies request after adding checkpoint into the waiting headers queue
335+
val thirdGetBlockBodiesRequest = GetBlockBodies(alternativeSecondBlocksBatch.map(_.hash))
336+
peersClient.expectMsgPF() { case PeersClient.Request(msg, _, _) if msg == thirdGetBlockBodiesRequest => ()}
337+
338+
// third bodies response
339+
val thirdGetBlockBodiesResponse = BlockBodies(alternativeSecondBlocksBatch.map(_.body))
340+
peersClient.reply(PeersClient.Response(fakePeer, thirdGetBlockBodiesResponse))
341+
334342
// We need to wait a while in order to allow fetcher to process all the blocks
335343
system.scheduler.scheduleOnce(Timeouts.shortTimeout) {
336344
importer.send(blockFetcher, PickBlocks(syncConfig.blocksBatchSize * 2))

0 commit comments

Comments
 (0)