Skip to content

Commit 0554a62

Browse files
KonradStanieckapke
authored andcommitted
[ETCM-275] Improve synccontroller tests
1 parent 91dc4a6 commit 0554a62

File tree

2 files changed

+176
-130
lines changed

2 files changed

+176
-130
lines changed

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

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,36 +90,37 @@ class SyncStateSchedulerActor(
9090
self ! BloomFilterResult(value)
9191
}
9292

93-
def waitingForBloomFilterToLoad(lastReceivedCommand: Option[(SyncStateSchedulerActorCommand, ActorRef)]): Receive = {
94-
case BloomFilterResult(result) =>
95-
log.debug(
96-
s"Loaded ${result.writtenElements} already known elements from storage to bloom filter the error while loading " +
97-
s"was ${result.error}"
98-
)
99-
lastReceivedCommand match {
100-
case Some((startSignal: StartSyncingTo, sender)) =>
101-
val initStats = ProcessingStatistics().addSaved(result.writtenElements)
102-
val initState = startSyncing(startSignal.stateRoot, startSignal.blockNumber)
103-
context become (syncing(
104-
initState,
105-
DownloaderState(),
106-
initStats,
107-
startSignal.blockNumber,
108-
sender,
109-
Queue(),
110-
processing = false,
111-
None
112-
))
113-
case Some((restartSignal: RestartRequested.type, sender)) =>
114-
sender ! WaitingForNewTargetBlock
115-
context.become(idle(ProcessingStatistics().addSaved(result.writtenElements)))
116-
case _ =>
117-
context.become(idle(ProcessingStatistics().addSaved(result.writtenElements)))
118-
}
93+
def waitingForBloomFilterToLoad(lastReceivedCommand: Option[(SyncStateSchedulerActorCommand, ActorRef)]): Receive =
94+
handleCommonMessages orElse {
95+
case BloomFilterResult(result) =>
96+
log.debug(
97+
s"Loaded ${result.writtenElements} already known elements from storage to bloom filter the error while loading " +
98+
s"was ${result.error}"
99+
)
100+
lastReceivedCommand match {
101+
case Some((startSignal: StartSyncingTo, sender)) =>
102+
val initStats = ProcessingStatistics().addSaved(result.writtenElements)
103+
val initState = startSyncing(startSignal.stateRoot, startSignal.blockNumber)
104+
context become (syncing(
105+
initState,
106+
DownloaderState(),
107+
initStats,
108+
startSignal.blockNumber,
109+
sender,
110+
Queue(),
111+
processing = false,
112+
None
113+
))
114+
case Some((restartSignal: RestartRequested.type, sender)) =>
115+
sender ! WaitingForNewTargetBlock
116+
context.become(idle(ProcessingStatistics().addSaved(result.writtenElements)))
117+
case _ =>
118+
context.become(idle(ProcessingStatistics().addSaved(result.writtenElements)))
119+
}
119120

120-
case command: SyncStateSchedulerActorCommand =>
121-
context.become(waitingForBloomFilterToLoad(Some((command, sender()))))
122-
}
121+
case command: SyncStateSchedulerActorCommand =>
122+
context.become(waitingForBloomFilterToLoad(Some((command, sender()))))
123+
}
123124

124125
private def startSyncing(root: ByteString, bn: BigInt): SchedulerState = {
125126
timers.startTimerAtFixedRate(PrintInfoKey, PrintInfo, 30.seconds)
@@ -130,7 +131,7 @@ class SyncStateSchedulerActor(
130131
initState
131132
}
132133

133-
def idle(processingStatistics: ProcessingStatistics): Receive = {
134+
def idle(processingStatistics: ProcessingStatistics): Receive = handleCommonMessages orElse {
134135
case StartSyncingTo(root, bn) =>
135136
val state1 = startSyncing(root, bn)
136137
context become (syncing(

0 commit comments

Comments
 (0)