Skip to content

Commit 116782f

Browse files
committed
[ETCM-213] Properly handle restart while loading bloom filter
1 parent 1bdc6b9 commit 116782f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/scala/io/iohk/ethereum/blockchain/sync/SyncStateSchedulerActor.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class SyncStateSchedulerActor(downloader: ActorRef, sync: SyncStateScheduler, sy
5353
val initStats = ProcessingStatistics().addSaved(result.writtenElements)
5454
val initState = startSyncing(startSignal.stateRoot, startSignal.blockNumber)
5555
context become (syncing(initState, initStats, startSignal.blockNumber, sender))
56+
case Some((restartSignal: RestartRequested.type, sender)) =>
57+
sender ! WaitingForNewTargetBlock
58+
context.become(idle(ProcessingStatistics().addSaved(result.writtenElements)))
5659
case _ =>
5760
context.become(idle(ProcessingStatistics().addSaved(result.writtenElements)))
5861
}
@@ -104,7 +107,6 @@ class SyncStateSchedulerActor(downloader: ActorRef, sync: SyncStateScheduler, sy
104107
log.debug(s"Received {} new nodes to process", nodes.size)
105108
// Current SyncStateDownloaderActor makes sure that there is no not requested or duplicated values in its response.
106109
// so we can ignore those errors.
107-
// TODO make processing async as sometimes downloader sits idle
108110
sync.processResponses(currentState, nodes) match {
109111
case Left(value) =>
110112
log.error(s"Critical error while state syncing ${value}, stopping state sync")

src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncSpec.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.iohk.ethereum.blockchain.sync
22

33
import java.net.InetSocketAddress
4+
import java.util.concurrent.ThreadLocalRandom
45

56
import akka.actor.{ActorRef, ActorSystem}
67
import akka.testkit.TestActor.AutoPilot
@@ -14,12 +15,12 @@ import io.iohk.ethereum.blockchain.sync.SyncStateSchedulerActor.{
1415
}
1516
import io.iohk.ethereum.domain.BlockchainImpl
1617
import io.iohk.ethereum.network.EtcPeerManagerActor.{GetHandshakedPeers, HandshakedPeers, PeerInfo, SendMessage}
17-
import io.iohk.ethereum.network.{Peer, PeerId}
1818
import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.MessageFromPeer
1919
import io.iohk.ethereum.network.p2p.messages.CommonMessages.Status
2020
import io.iohk.ethereum.network.p2p.messages.PV63.GetNodeData.GetNodeDataEnc
2121
import io.iohk.ethereum.network.p2p.messages.PV63.NodeData
2222
import io.iohk.ethereum.network.p2p.messages.Versions
23+
import io.iohk.ethereum.network.{Peer, PeerId}
2324
import io.iohk.ethereum.utils.Config
2425
import io.iohk.ethereum.{Fixtures, ObjectGenerators, WithActorSystemShutDown}
2526
import org.scalactic.anyvals.PosInt
@@ -29,7 +30,6 @@ import org.scalatest.matchers.should.Matchers
2930
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
3031

3132
import scala.concurrent.duration._
32-
import scala.util.Random
3333

3434
class StateSyncSpec
3535
extends TestKit(ActorSystem("MySpec"))
@@ -131,7 +131,7 @@ class StateSyncSpec
131131
}
132132

133133
val maxMptNodeRequest = 50
134-
134+
val minMptNodeRequest = 20
135135
val partialResponseConfig: PeerConfig = peersMap.map { case (peer, _) =>
136136
peer.id -> PartialResponse
137137
}
@@ -162,7 +162,8 @@ class StateSyncSpec
162162
sender ! MessageFromPeer(responseMsg, peer)
163163
this
164164
case PartialResponse =>
165-
val elementsToServe = Random.nextInt(maxMptNodeRequest)
165+
val random: ThreadLocalRandom = ThreadLocalRandom.current()
166+
val elementsToServe = random.nextInt(minMptNodeRequest, maxMptNodeRequest + 1)
166167
val toGet = msg.underlyingMsg.mptElementsHashes.toList.take(elementsToServe)
167168
val responseMsg = NodeData(trieProvider.getNodes(toGet).map(_.data))
168169
sender ! MessageFromPeer(responseMsg, peer)

0 commit comments

Comments
 (0)