Skip to content

Commit 47b5836

Browse files
committed
ETCM-732: Always reorganize chain in case of error.
1 parent 7743570 commit 47b5836

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import io.iohk.ethereum.ledger.Ledger.BlockResult
1515
import io.iohk.ethereum.mpt.MerklePatriciaTrie
1616
import io.iohk.ethereum.utils.Config
1717
import io.iohk.ethereum.utils.Config.SyncConfig
18-
import io.iohk.ethereum.{Fixtures, Mocks, ObjectGenerators, crypto}
18+
import io.iohk.ethereum.{Fixtures, LongPatience, Mocks, ObjectGenerators, crypto}
1919
import monix.execution.Scheduler
2020
import org.scalamock.scalatest.MockFactory
2121
import org.scalatest.BeforeAndAfterAll
22-
import org.scalatest.concurrent.Eventually.eventually
22+
import org.scalatest.concurrent.Eventually
2323
import org.scalatest.flatspec.AsyncFlatSpecLike
2424
import org.scalatest.matchers.should.Matchers
2525

@@ -30,10 +30,12 @@ class BlockImporterItSpec
3030
with TestSetupWithVmAndValidators
3131
with AsyncFlatSpecLike
3232
with Matchers
33-
with BeforeAndAfterAll {
33+
with BeforeAndAfterAll
34+
with Eventually {
3435

3536
implicit val testScheduler = Scheduler.fixedPool("test", 32)
3637

38+
3739
override def afterAll(): Unit = {
3840
testScheduler.shutdown()
3941
testScheduler.awaitTermination(60.second)
@@ -150,7 +152,7 @@ class BlockImporterItSpec
150152
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(newBranch))
151153

152154
//because the blocks are not valid, we shouldn't reorganise, but at least stay with a current chain, and the best block of the current chain is oldBlock4
153-
eventually { blockchain.getBestBlock().get shouldEqual oldBlock4 }
155+
eventually {Thread.sleep(1000); blockchain.getBestBlock().get shouldEqual oldBlock4 }
154156
}
155157

156158
it should "return a correct new best block after reorganising longer chain to a shorter one if its weight is bigger" in {
@@ -162,7 +164,7 @@ class BlockImporterItSpec
162164

163165
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(newBranch))
164166

165-
eventually { Thread.sleep(200); blockchain.getBestBlock().get shouldEqual newBlock3 }
167+
eventually { Thread.sleep(1000); blockchain.getBestBlock().get shouldEqual newBlock3 }
166168
}
167169

168170
it should "return Unknown branch, in case of PickedBlocks with block that has a parent that's not in the chain" in {
@@ -189,7 +191,7 @@ class BlockImporterItSpec
189191
//not reorganising anymore until oldBlock4(not part of the chain anymore), no block/ommer validation when not part of the chain, resolveBranch is returning UnknownBranch
190192
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(List(newBlock5ParentOldBlock4)))
191193

192-
eventually { blockchain.getBestBlock().get shouldEqual newBlock4ParentOldBlock3 }
194+
eventually {Thread.sleep(1000); blockchain.getBestBlock().get shouldEqual newBlock4ParentOldBlock3 }
193195
}
194196

195197
it should "switch to a branch with a checkpoint" in {
@@ -202,8 +204,8 @@ class BlockImporterItSpec
202204

203205
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(newBranch))
204206

205-
eventually { blockchain.getBestBlock().get shouldEqual oldBlock5WithCheckpoint }
206-
eventually { blockchain.getLatestCheckpointBlockNumber() shouldEqual oldBlock5WithCheckpoint.header.number }
207+
eventually { Thread.sleep(1000); blockchain.getBestBlock().get shouldEqual oldBlock5WithCheckpoint }
208+
eventually { Thread.sleep(1000); blockchain.getLatestCheckpointBlockNumber() shouldEqual oldBlock5WithCheckpoint.header.number }
207209
}
208210

209211
it should "switch to a branch with a newer checkpoint" in {
@@ -216,8 +218,8 @@ class BlockImporterItSpec
216218

217219
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(newBranch))
218220

219-
eventually { blockchain.getBestBlock().get shouldEqual newBlock4WithCheckpoint }
220-
eventually { blockchain.getLatestCheckpointBlockNumber() shouldEqual newBlock4WithCheckpoint.header.number }
221+
eventually {Thread.sleep(1000); blockchain.getBestBlock().get shouldEqual newBlock4WithCheckpoint }
222+
eventually {Thread.sleep(1000); blockchain.getLatestCheckpointBlockNumber() shouldEqual newBlock4WithCheckpoint.header.number }
221223
}
222224

223225
it should "return a correct checkpointed block after receiving a request for generating a new checkpoint" in {
@@ -264,9 +266,8 @@ class BlockImporterItSpec
264266
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(List(invalidBlock)))
265267

266268
eventually {
267-
Thread.sleep(1000)
268-
269-
val msg = fetcherProbe.fishForMessage() {
269+
Thread.sleep(1000);
270+
val msg = fetcherProbe.fishForMessage(5.seconds) {
270271
case BlockFetcher.FetchStateNode(_) => true
271272
case _ => false
272273
}.asInstanceOf[BlockFetcher.FetchStateNode]

src/main/scala/io/iohk/ethereum/ledger/BlockImport.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ class BlockImport(
188188
case None =>
189189
Right(oldBlocksData.map(_.block), executedBlocks.map(_.block), executedBlocks.map(_.weight))
190190

191-
case Some(MPTError(reason)) if reason.isInstanceOf[MissingNodeException] =>
192-
Left(MPTError(reason))
193-
194191
case Some(error) =>
195192
revertChainReorganisation(newBranch, oldBlocksData, executedBlocks)
196193
Left(error)

0 commit comments

Comments
 (0)