From 4d1a58fa2e2fcd4bec0d06d72deffa4ca3060c7b Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Wed, 11 Sep 2024 19:39:01 +0300 Subject: [PATCH] wip --- node/src/main/resources/application.conf | 2 +- .../wavesplatform/network/PeerDatabaseImpl.scala | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/node/src/main/resources/application.conf b/node/src/main/resources/application.conf index 6f29a812e3..5846c2e61c 100644 --- a/node/src/main/resources/application.conf +++ b/node/src/main/resources/application.conf @@ -96,7 +96,7 @@ waves { # How long the information about peer stays in database after the last communication with it. # This value should be big eno - peers-data-residence-time = 15m + peers-data-residence-time = 1h # How long peer stays in blacklist after getting in it black-list-residence-time = 15m diff --git a/node/src/main/scala/com/wavesplatform/network/PeerDatabaseImpl.scala b/node/src/main/scala/com/wavesplatform/network/PeerDatabaseImpl.scala index 6b9e4709b1..07454c7a9c 100644 --- a/node/src/main/scala/com/wavesplatform/network/PeerDatabaseImpl.scala +++ b/node/src/main/scala/com/wavesplatform/network/PeerDatabaseImpl.scala @@ -11,7 +11,7 @@ import java.net.{InetAddress, InetSocketAddress} import java.util.concurrent.TimeUnit import scala.annotation.tailrec import scala.collection.* -import scala.concurrent.duration.FiniteDuration +import scala.concurrent.duration.{DurationInt, FiniteDuration} import scala.jdk.CollectionConverters.* import scala.util.Random import scala.util.control.NonFatal @@ -123,7 +123,7 @@ class PeerDatabaseImpl(settings: NetworkSettings) extends PeerDatabase with Scor } } - val knownPeersFromConfig = settings.knownPeers.flatMap(p => inetSocketAddress(p, 6868)) + val knownPeersFromConfig = settings.knownPeers.flatMap(p => inetSocketAddress(p, 6868)) val nextCandidateFromConfig = knownPeersFromConfig.filterNot(knownPeers.keySet).headOption nextCandidateFromConfig @@ -138,12 +138,15 @@ class PeerDatabaseImpl(settings: NetworkSettings) extends PeerDatabase with Scor } override def close(): Unit = settings.file.foreach { f => - log.info(s"Saving ${knownPeers.size} known peer(s) to ${f.getName}") + val tsThreshold = System.currentTimeMillis() - 3.minutes.toMillis val rawPeers = for { - inetAddress <- knownPeers.keySet - address <- Option(inetAddress.getAddress) + (inetAddress, timestamp) <- knownPeers + if timestamp >= tsThreshold + address <- Option(inetAddress.getAddress) } yield s"${address.getHostAddress}:${inetAddress.getPort}" + log.info(s"Saving ${rawPeers.size} known peer(s) to ${f.getName}") + JsonFileStorage.save[PeersPersistenceType](rawPeers, f.getCanonicalPath) }