Skip to content

Commit 7dd239f

Browse files
author
Michal Mrozek
committed
[ECTM-104] Refactoring names
1 parent 797b12b commit 7dd239f

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

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

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ class FastSync(
6464
}
6565

6666
def startWithState(syncState: SyncState): Unit = {
67-
if (syncState.updatingTargetBlock) {
68-
log.info(s"FastSync interrupted during targetBlock update, choosing new target block")
67+
if (syncState.updatingPivotBlock) {
68+
log.info(s"FastSync interrupted during pivot block update, choosing new pivot block")
6969
val syncingHandler = new SyncingHandler(syncState)
70-
val targetBlockSelector = context.actorOf(
70+
val pivotBlockSelector = context.actorOf(
7171
FastSyncPivotBlockSelector.props(etcPeerManager, peerEventBus, syncConfig, scheduler),
7272
"pivot-block-selector"
7373
)
74-
targetBlockSelector ! FastSyncPivotBlockSelector.ChoosePivotBlock
75-
context become syncingHandler.waitingForTargetBlockUpdate(ImportedLastBlock)
74+
pivotBlockSelector ! FastSyncPivotBlockSelector.ChoosePivotBlock
75+
context become syncingHandler.waitingForPivotBlockUpdate(ImportedLastBlock)
7676
} else {
7777
log.info(
78-
s"Starting block synchronization (fast mode), target block ${syncState.pivotBlock.number}, " +
78+
s"Starting block synchronization (fast mode), pivot block ${syncState.pivotBlock.number}, " +
7979
s"block to download to ${syncState.safeDownloadTarget}"
8080
)
8181
val syncingHandler = new SyncingHandler(syncState)
@@ -85,18 +85,18 @@ class FastSync(
8585
}
8686

8787
def startFromScratch(): Unit = {
88-
val targetBlockSelector = context.actorOf(
88+
val pivotBlockSelector = context.actorOf(
8989
FastSyncPivotBlockSelector.props(etcPeerManager, peerEventBus, syncConfig, scheduler),
9090
"pivot-block-selector"
9191
)
92-
targetBlockSelector ! FastSyncPivotBlockSelector.ChoosePivotBlock
93-
context become waitingForTargetBlock
92+
pivotBlockSelector ! FastSyncPivotBlockSelector.ChoosePivotBlock
93+
context become waitingForPivotBlock
9494
}
9595

96-
def waitingForTargetBlock: Receive = handleCommonMessages orElse {
96+
def waitingForPivotBlock: Receive = handleCommonMessages orElse {
9797
case FastSyncPivotBlockSelector.Result(pivotBlockHeader) =>
9898
if (pivotBlockHeader.number < 1) {
99-
log.info("Unable to start block synchronization in fast mode: target block is less than 1")
99+
log.info("Unable to start block synchronization in fast mode: pivot block is less than 1")
100100
appStateStorage.fastSyncDone().commit()
101101
context become idle
102102
syncController ! Done
@@ -188,16 +188,16 @@ class FastSync(
188188
handleRequestFailure(assignedHandlers(ref), ref, "Unexpected error")
189189
}
190190

191-
def waitingForTargetBlockUpdate(processState: FinalBlockProcessingResult): Receive = handleCommonMessages orElse {
191+
def waitingForPivotBlockUpdate(processState: FinalBlockProcessingResult): Receive = handleCommonMessages orElse {
192192
case FastSyncPivotBlockSelector.Result(pivotBlockHeader) =>
193193
log.info(s"New pivot block with number ${pivotBlockHeader.number} received")
194194
if (pivotBlockHeader.number >= syncState.pivotBlock.number) {
195195
updatePivotSyncState(processState, pivotBlockHeader)
196-
syncState = syncState.copy(updatingTargetBlock = false)
196+
syncState = syncState.copy(updatingPivotBlock = false)
197197
context become this.receive
198198
processSyncing()
199199
} else {
200-
syncState = syncState.copy(targetBlockUpdateFailures = syncState.targetBlockUpdateFailures + 1)
200+
syncState = syncState.copy(pivotBlockUpdateFailures = syncState.pivotBlockUpdateFailures + 1)
201201
scheduler.scheduleOnce(syncRetryInterval, self, UpdatePivotBlock(processState))
202202
}
203203

@@ -207,51 +207,51 @@ class FastSync(
207207
}
208208

209209
private def updatePivotBlock(state: FinalBlockProcessingResult): Unit = {
210-
syncState = syncState.copy(updatingTargetBlock = true)
211-
if (syncState.targetBlockUpdateFailures <= syncConfig.maximumTargetUpdateFailures) {
210+
syncState = syncState.copy(updatingPivotBlock = true)
211+
if (syncState.pivotBlockUpdateFailures <= syncConfig.maximumTargetUpdateFailures) {
212212
if (assignedHandlers.nonEmpty) {
213-
log.info(s"Still waiting for some responses, rescheduling target block update")
213+
log.info(s"Still waiting for some responses, rescheduling pivot block update")
214214
scheduler.scheduleOnce(syncRetryInterval, self, UpdatePivotBlock(state))
215215
} else {
216216
log.info("Asking for new pivot block")
217217
val pivotBlockSelector =
218218
context.actorOf(FastSyncPivotBlockSelector.props(etcPeerManager, peerEventBus, syncConfig, scheduler))
219219
pivotBlockSelector ! FastSyncPivotBlockSelector.ChoosePivotBlock
220-
context become waitingForTargetBlockUpdate(state)
220+
context become waitingForPivotBlockUpdate(state)
221221
}
222222
} else {
223-
log.warning(s"Sync failure! Number of targetBlock Failures reached maximum.")
223+
log.warning(s"Sync failure! Number of pivot block update failures reached maximum.")
224224
sys.exit(1)
225225
}
226226
}
227227

228-
private def updatePivotSyncState(state: FinalBlockProcessingResult, targetBlockHeader: BlockHeader): Unit =
228+
private def updatePivotSyncState(state: FinalBlockProcessingResult, pivotBlockHeader: BlockHeader): Unit =
229229
state match {
230-
case ImportedLastBlock =>
231-
if (targetBlockHeader.number - syncState.pivotBlock.number <= syncConfig.maxTargetDifference) {
232-
log.info(s"Current target block is fresh enough, starting state download")
233-
if (syncState.pivotBlock.stateRoot == ByteString(MerklePatriciaTrie.EmptyRootHash)) {
234-
syncState = syncState.copy(pendingMptNodes = Seq())
235-
} else {
236-
syncState = syncState.copy(pendingMptNodes = Seq(StateMptNodeHash(syncState.pivotBlock.stateRoot)))
237-
}
230+
case ImportedLastBlock
231+
if pivotBlockHeader.number - syncState.pivotBlock.number <= syncConfig.maxTargetDifference =>
232+
log.info(s"Current pivot block is fresh enough, starting state download")
233+
if (syncState.pivotBlock.stateRoot == ByteString(MerklePatriciaTrie.EmptyRootHash)) {
234+
syncState = syncState.copy(pendingMptNodes = Seq())
238235
} else {
239-
syncState = syncState.updateTargetBlock(
240-
targetBlockHeader,
241-
syncConfig.fastSyncBlockValidationX,
242-
updateFailures = false
243-
)
244-
log.info(
245-
s"Changing target block to ${targetBlockHeader.number}, new safe target is ${syncState.safeDownloadTarget}"
246-
)
236+
syncState = syncState.copy(pendingMptNodes = Seq(StateMptNodeHash(syncState.pivotBlock.stateRoot)))
247237
}
248238

249239
case LastBlockValidationFailed =>
250240
log.info(
251-
s"Changing target block after failure, to ${targetBlockHeader.number}, new safe target is ${syncState.safeDownloadTarget}"
241+
s"Changing pivot block after failure, to ${pivotBlockHeader.number}, new safe target is ${syncState.safeDownloadTarget}"
252242
)
253243
syncState =
254-
syncState.updateTargetBlock(targetBlockHeader, syncConfig.fastSyncBlockValidationX, updateFailures = true)
244+
syncState.updatePivotBlock(pivotBlockHeader, syncConfig.fastSyncBlockValidationX, updateFailures = true)
245+
246+
case _ =>
247+
log.info(
248+
s"Changing pivot block to ${pivotBlockHeader.number}, new safe target is ${syncState.safeDownloadTarget}"
249+
)
250+
syncState = syncState.updatePivotBlock(
251+
pivotBlockHeader,
252+
syncConfig.fastSyncBlockValidationX,
253+
updateFailures = false
254+
)
255255
}
256256

257257
private def removeRequestHandler(handler: ActorRef): Unit = {
@@ -277,7 +277,7 @@ class FastSync(
277277
case Right(headerAndDif) =>
278278
updateSyncState(headerAndDif._1, headerAndDif._2)
279279
if (header.number == syncState.safeDownloadTarget) {
280-
ImportedTargetBlock
280+
ImportedPivotBlock
281281
} else {
282282
processHeaders(peer, headers.tail)
283283
}
@@ -360,7 +360,7 @@ class FastSync(
360360
handleRewind(header, peer, syncConfig.fastSyncBlockValidationN)
361361
case HeadersProcessingFinished =>
362362
processSyncing()
363-
case ImportedTargetBlock =>
363+
case ImportedPivotBlock =>
364364
updatePivotBlock(ImportedLastBlock)
365365
case ValidationFailed(header, peerToBlackList) =>
366366
log.warning(s"validation fo header ${header.idTag} failed")
@@ -622,7 +622,7 @@ class FastSync(
622622
if (fullySynced) {
623623
finish()
624624
} else {
625-
if (anythingToDownload && !syncState.updatingTargetBlock) processDownloads()
625+
if (anythingToDownload && !syncState.updatingPivotBlock) processDownloads()
626626
else log.info("No more items to request, waiting for {} responses", assignedHandlers.size)
627627
}
628628
}
@@ -855,8 +855,8 @@ object FastSync {
855855
totalNodesCount: Int = 0,
856856
bestBlockHeaderNumber: BigInt = 0,
857857
nextBlockToFullyValidate: BigInt = 1,
858-
targetBlockUpdateFailures: Int = 0,
859-
updatingTargetBlock: Boolean = false
858+
pivotBlockUpdateFailures: Int = 0,
859+
updatingPivotBlock: Boolean = false
860860
) {
861861

862862
def enqueueBlockBodies(blockBodies: Seq[ByteString]): SyncState =
@@ -897,11 +897,11 @@ object FastSync {
897897
nextBlockToFullyValidate = (header.number - N) max 1
898898
)
899899

900-
def updateTargetBlock(newTarget: BlockHeader, numberOfSafeBlocks: BigInt, updateFailures: Boolean): SyncState =
900+
def updatePivotBlock(newPivot: BlockHeader, numberOfSafeBlocks: BigInt, updateFailures: Boolean): SyncState =
901901
copy(
902-
pivotBlock = newTarget,
903-
safeDownloadTarget = newTarget.number + numberOfSafeBlocks,
904-
targetBlockUpdateFailures = if (updateFailures) targetBlockUpdateFailures + 1 else targetBlockUpdateFailures
902+
pivotBlock = newPivot,
903+
safeDownloadTarget = newPivot.number + numberOfSafeBlocks,
904+
pivotBlockUpdateFailures = if (updateFailures) pivotBlockUpdateFailures + 1 else pivotBlockUpdateFailures
905905
)
906906
}
907907

@@ -921,7 +921,7 @@ object FastSync {
921921
case object HeadersProcessingFinished extends HeaderProcessingResult
922922
case class ParentDifficultyNotFound(header: BlockHeader) extends HeaderProcessingResult
923923
case class ValidationFailed(header: BlockHeader, peer: Peer) extends HeaderProcessingResult
924-
case object ImportedTargetBlock extends HeaderProcessingResult
924+
case object ImportedPivotBlock extends HeaderProcessingResult
925925

926926
sealed abstract class FinalBlockProcessingResult
927927
case object ImportedLastBlock extends FinalBlockProcessingResult

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class SyncControllerSpec extends AnyFlatSpec with Matchers with BeforeAndAfter w
375375
syncState.blockBodiesQueue.isEmpty shouldBe true
376376
syncState.receiptsQueue.isEmpty shouldBe true
377377
syncState.nextBlockToFullyValidate shouldBe (newBestBlock - syncConfig.fastSyncBlockValidationN + 1)
378-
syncState.targetBlockUpdateFailures shouldEqual 1
378+
syncState.pivotBlockUpdateFailures shouldEqual 1
379379
}
380380

381381
it should "not process, out of date new target block" in new TestSetup() {
@@ -422,7 +422,7 @@ class SyncControllerSpec extends AnyFlatSpec with Matchers with BeforeAndAfter w
422422

423423
val syncState = storagesInstance.storages.fastSyncStateStorage.getSyncState().get
424424

425-
syncState.targetBlockUpdateFailures shouldEqual 1
425+
syncState.pivotBlockUpdateFailures shouldEqual 1
426426

427427
Thread.sleep(syncConfig.syncRetryInterval.toMillis)
428428

@@ -442,7 +442,7 @@ class SyncControllerSpec extends AnyFlatSpec with Matchers with BeforeAndAfter w
442442
newSyncState.safeDownloadTarget shouldEqual goodTarget.number + syncConfig.fastSyncBlockValidationX
443443
newSyncState.pivotBlock shouldEqual goodTarget
444444
newSyncState.bestBlockHeaderNumber shouldEqual bestBlockNumber + syncConfig.blockHeadersPerRequest
445-
newSyncState.targetBlockUpdateFailures shouldEqual 1
445+
newSyncState.pivotBlockUpdateFailures shouldEqual 1
446446
}
447447

448448
it should "should start state download only when target block is fresh enough" in new TestSetup() {

0 commit comments

Comments
 (0)