Skip to content

Commit c6c439c

Browse files
committed
[FIX] Update last block when appending full new block to queue
1 parent 101a363 commit c6c439c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ case class BlockFetcherState(
9292
def appendNewBlock(block: Block, fromPeer: PeerId): BlockFetcherState =
9393
withPeerForBlocks(fromPeer, Seq(block.header.number))
9494
.withPossibleNewTopAt(block.number)
95+
.withLastBlock(block.number)
9596
.copy(
9697
readyBlocks = readyBlocks.enqueue(block),
9798
waitingHeaders = waitingHeaders.filter(block.number != _.number)

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package io.iohk.ethereum.blockchain.sync.regular
22

33
import akka.actor.ActorSystem
44
import akka.testkit.{TestKit, TestProbe}
5+
import io.iohk.ethereum.domain.Block
56
import org.scalatest.{Matchers, WordSpecLike}
6-
7+
import io.iohk.ethereum.Fixtures.Blocks.ValidBlock
8+
import io.iohk.ethereum.network.PeerId
79

810
class BlockFetcherStateSpec extends TestKit(ActorSystem()) with WordSpecLike with Matchers {
911
"BlockFetcherState" when {
@@ -15,5 +17,21 @@ class BlockFetcherStateSpec extends TestKit(ActorSystem()) with WordSpecLike wit
1517
actual.lastBlock shouldBe 0
1618
}
1719
}
20+
21+
"appending last full block" should {
22+
"update last block" in {
23+
val importer = TestProbe().ref
24+
val currentBestBlock = Block(ValidBlock.header, ValidBlock.body)
25+
val newBestBlock = Block(ValidBlock.header.copy(number = ValidBlock.header.number + 1), ValidBlock.body)
26+
val fakePeerId = PeerId("fake")
27+
28+
val currentState = BlockFetcherState.initial(importer, currentBestBlock.number)
29+
val newState = currentState.appendNewBlock(newBestBlock, fakePeerId)
30+
newState.lastBlock shouldEqual newBestBlock.number
31+
newState.blockProviders(newBestBlock.number) shouldEqual fakePeerId
32+
newState.knownTop shouldEqual newBestBlock.number
33+
}
34+
}
35+
1836
}
1937
}

0 commit comments

Comments
 (0)