Skip to content

Commit ff865d2

Browse files
author
Petra Bierleutgeb
committed
Small cleanup
1 parent f74b073 commit ff865d2

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ object Blacklist {
2525
}
2626
}
2727

28-
final case class CacheBasedBlacklist(cache: Cache[BlacklistId, String])
29-
extends Blacklist with Logger {
28+
final case class CacheBasedBlacklist(cache: Cache[BlacklistId, String]) extends Blacklist with Logger {
3029

3130
override def isBlacklisted(id: BlacklistId): Boolean = cache.getIfPresent(id).isDefined
3231

3332
override def add(id: BlacklistId, duration: FiniteDuration, reason: String): Unit =
34-
cache.policy().expireVariably().toScala.fold {
35-
log.warn(s"Unexpected error while adding peer [${id.value}] to blacklist using custom expiration time. Falling back to default expiration.")
36-
cache.put(id, reason)
37-
} { varExpirationPolicy =>
38-
varExpirationPolicy.put(id, reason, duration.toJava)
39-
}
33+
cache
34+
.policy()
35+
.expireVariably()
36+
.toScala
37+
.fold {
38+
log.warn(
39+
s"Unexpected error while adding peer [${id.value}] to blacklist using custom expiration time. Falling back to default expiration."
40+
)
41+
cache.put(id, reason)
42+
} { varExpirationPolicy =>
43+
varExpirationPolicy.put(id, reason, duration.toJava)
44+
}
4045
override def remove(id: BlacklistId): Unit = cache.invalidate(id)
4146

4247
override def keys: Set[BlacklistId] = cache.underlying.asMap().keySet().asScala.toSet
@@ -47,10 +52,14 @@ object CacheBasedBlacklist {
4752
def empty(maxSize: Int): CacheBasedBlacklist = {
4853
val cache =
4954
Scaffeine()
50-
.expireAfter[BlacklistId, String](create = (_, _) => 60.minutes,
55+
.expireAfter[BlacklistId, String](
56+
create = (_, _) => 60.minutes,
5157
update = (_, _, _) => 60.minutes,
52-
read = (_, _, _) => 60.minutes) // required to enable VarExpiration policy (i.e. set custom expiration time per element)
53-
.maximumSize(maxSize) // uses Window TinyLfu eviction policy, see https://github.com/ben-manes/caffeine/wiki/Efficiency
58+
read = (_, _, _) => 60.minutes
59+
) // required to enable VarExpiration policy (i.e. set custom expiration time per element)
60+
.maximumSize(
61+
maxSize
62+
) // uses Window TinyLfu eviction policy, see https://github.com/ben-manes/caffeine/wiki/Efficiency
5463
.build[BlacklistId, String]()
5564
CacheBasedBlacklist(cache)
5665
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ class FastSync(
5959

6060
override def receive: Receive = idle
6161

62-
def handleCommonMessages: Receive = handlePeerListMessages
63-
64-
def idle: Receive = handleCommonMessages orElse {
62+
def idle: Receive = handlePeerListMessages orElse {
6563
case SyncProtocol.Start => start()
6664
case SyncProtocol.GetStatus => sender() ! SyncProtocol.Status.NotSyncing
6765
}
@@ -90,7 +88,7 @@ class FastSync(
9088
context become waitingForPivotBlock
9189
}
9290

93-
def waitingForPivotBlock: Receive = handleCommonMessages orElse {
91+
def waitingForPivotBlock: Receive = handlePeerListMessages orElse {
9492
case SyncProtocol.GetStatus => sender() ! SyncProtocol.Status.NotSyncing
9593
case PivotBlockSelector.Result(pivotBlockHeader) =>
9694
if (pivotBlockHeader.number < 1) {
@@ -161,7 +159,7 @@ class FastSync(
161159
syncState = syncState.copy(downloadedNodesCount = saved, totalNodesCount = saved + missing)
162160
}
163161

164-
def receive: Receive = handleCommonMessages orElse handleStatus orElse {
162+
def receive: Receive = handlePeerListMessages orElse handleStatus orElse {
165163
case UpdatePivotBlock(reason) => updatePivotBlock(reason)
166164
case WaitingForNewTargetBlock =>
167165
log.info("State sync stopped until receiving new pivot block")
@@ -248,7 +246,7 @@ class FastSync(
248246
}
249247

250248
def waitingForPivotBlockUpdate(updateReason: PivotBlockUpdateReason): Receive =
251-
handleCommonMessages orElse handleStatus orElse {
249+
handlePeerListMessages orElse handleStatus orElse {
252250
case PivotBlockSelector.Result(pivotBlockHeader)
253251
if newPivotIsGoodEnough(pivotBlockHeader, syncState, updateReason) =>
254252
log.info("New pivot block with number {} received", pivotBlockHeader.number)

0 commit comments

Comments
 (0)