Skip to content

Commit

Permalink
Merge branch 'develop' into fast_sync_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquerodbe committed Jan 13, 2021
2 parents 51a2c5e + 19ed816 commit 287dc15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Expand Up @@ -100,8 +100,12 @@ case class BlockFetcherState(
.withKnownTopAt(block.number)
Right(newState)
} else if (isExistInWaitingHeaders(block.header.parentHash)) {
// ignore already requested bodies
val newFetchingBodiesState =
if (fetchingBodiesState == AwaitingBodies) AwaitingBodiesToBeIgnored else fetchingBodiesState
val newState = copy(
waitingHeaders = waitingHeaders.takeWhile(_.number < block.number).enqueue(block.header)
waitingHeaders = waitingHeaders.takeWhile(_.number < block.number).enqueue(block.header),
fetchingBodiesState = newFetchingBodiesState
)
.withKnownTopAt(block.number)
Right(newState)
Expand Down
Expand Up @@ -343,20 +343,28 @@ class BlockFetcherSpec

handleFirstBlockBatchBodies()

// second bodies request
val secondGetBlockBodiesRequest = GetBlockBodies(secondBlocksBatch.map(_.hash))
peersClient.expectMsgPF() { case PeersClient.Request(msg, _, _) if msg == secondGetBlockBodiesRequest => ()}

// send old checkpoint block
blockFetcher ! MessageFromPeer(
PV64.NewBlock(checkpointBlock, ChainWeight(checkpointBlock.number, checkpointBlock.header.difficulty)),
fakePeer.id
)

// Second bodies request
val secondGetBlockBodiesRequest = GetBlockBodies(alternativeSecondBlocksBatch.map(_.hash))
peersClient.expectMsgPF() { case PeersClient.Request(msg, _, _) if msg == secondGetBlockBodiesRequest => () }

// Second bodies response
val secondGetBlockBodiesResponse = BlockBodies(alternativeSecondBlocksBatch.map(_.body))
// second bodies response
val secondGetBlockBodiesResponse = BlockBodies(secondBlocksBatch.map(_.body))
peersClient.reply(PeersClient.Response(fakePeer, secondGetBlockBodiesResponse))

// third bodies request after adding checkpoint into the waiting headers queue
val thirdGetBlockBodiesRequest = GetBlockBodies(alternativeSecondBlocksBatch.map(_.hash))
peersClient.expectMsgPF() { case PeersClient.Request(msg, _, _) if msg == thirdGetBlockBodiesRequest => ()}

// third bodies response
val thirdGetBlockBodiesResponse = BlockBodies(alternativeSecondBlocksBatch.map(_.body))
peersClient.reply(PeersClient.Response(fakePeer, thirdGetBlockBodiesResponse))

// We need to wait a while in order to allow fetcher to process all the blocks
system.scheduler.scheduleOnce(Timeouts.shortTimeout) {
importer.send(blockFetcher, PickBlocks(syncConfig.blocksBatchSize * 2))
Expand Down

0 comments on commit 287dc15

Please sign in to comment.