@@ -153,6 +153,29 @@ class BlockImporterItSpec
153
153
blockchain.getBestBlock().get shouldEqual newBlock3
154
154
}
155
155
156
+ it should " return Unknown branch, don't start reorganisation in case of PickedBlocks with block that has a parent who is not present in the chain " in {
157
+ val newcomerBlock4 : Block =
158
+ getBlock(genesisBlock.number + 4 , difficulty = 104 , parent = oldBlock3.header.hash)
159
+ val newcomerWeight4Duplicate = oldWeight3.increase(newcomerBlock4.header)
160
+
161
+ // Block n5 with oldBlock4 as parent
162
+ val newComerBlock5WithOldBlock4Parent : Block =
163
+ getBlock(genesisBlock.number + 5 , difficulty = 108 , parent = oldBlock4.header.hash)
164
+
165
+ blockchain.save(oldBlock2, Nil , oldWeight2, saveAsBestBlock = true )
166
+ blockchain.save(oldBlock3, Nil , oldWeight3, saveAsBestBlock = true )
167
+ blockchain.save(oldBlock4, Nil , oldWeight4, saveAsBestBlock = true )
168
+ // simulation of node restart
169
+ blockchain.saveBestKnownBlocks(blockchain.getBestBlockNumber() - 1 )
170
+ blockchain.save(newcomerBlock4, Nil , newcomerWeight4Duplicate, saveAsBestBlock = true )
171
+
172
+ // this is not reorganising anymore until oldBlock4(not part of the chain anymore) // but resolveBranch is returning UnknownBranch
173
+ blockImporter ! BlockFetcher .PickedBlocks (NonEmptyList .fromListUnsafe(List (newComerBlock5WithOldBlock4Parent)))
174
+
175
+ Thread .sleep(200 )
176
+ blockchain.getBestBlock().get shouldEqual newcomerBlock4
177
+ }
178
+
156
179
it should " switch to a branch with a checkpoint" in {
157
180
158
181
val checkpoint = ObjectGenerators .fakeCheckpointGen(3 , 3 ).sample.get
0 commit comments