Skip to content

Commit

Permalink
Ability to disable time synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov committed Nov 28, 2024
1 parent 4e408d5 commit c1816dc
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions node/src/main/scala/com/wavesplatform/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import scala.concurrent.duration.*
import scala.concurrent.{Await, Future}
import scala.util.{Failure, Success, Try}

class Application(val actorSystem: ActorSystem, val settings: WavesSettings, configRoot: ConfigObject, time: NTP) extends ScorexLogging {
class Application(val actorSystem: ActorSystem, val settings: WavesSettings, configRoot: ConfigObject, time: Time) extends ScorexLogging {
app =>

import Application.*
Expand Down Expand Up @@ -660,7 +660,7 @@ object Application extends ScorexLogging {
SystemInformationReporter.report(settings.config)
}

val time = new NTP(settings.ntpServer)
val time = settings.ntpServer.fold[Time](SystemTime)(new NTP(_))
Metrics.start(settings.metrics, time)

def dumpMinerConfig(): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion node/src/main/scala/com/wavesplatform/Exporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object Exporter extends ScorexLogging {
val settings = Application.loadApplicationConfig(configFile)

Using.resources(
new NTP(settings.ntpServer),
settings.ntpServer.fold[Time](SystemTime)(new NTP(_)),
RDB.open(settings.dbSettings)
) { (time, rdb) =>
val (blockchain, rdbWriter) = StorageFactory(settings, rdb, time, BlockchainUpdateTriggers.noop)
Expand Down
8 changes: 4 additions & 4 deletions node/src/main/scala/com/wavesplatform/Importer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object Importer extends ScorexLogging {
appenderScheduler: Scheduler,
extensionTime: Time,
utxPool: UtxPool,
rdb: RDB,
rdb: RDB
): Seq[Extension] =
if (wavesSettings.extensions.isEmpty) Seq.empty
else {
Expand Down Expand Up @@ -308,7 +308,7 @@ object Importer extends ScorexLogging {
case _ =>
counter = counter + 1
}
} else if (!quit){
} else if (!quit) {
log.warn(s"Block $block is not a child of the last block ${blockchain.lastBlockId.get}")
}
}
Expand Down Expand Up @@ -343,9 +343,9 @@ object Importer extends ScorexLogging {
}

val scheduler = Schedulers.singleThread("appender")
val time = new NTP(settings.ntpServer)
val time = settings.ntpServer.fold[Time](SystemTime)(new NTP(_))

val rdb = RDB.open(settings.dbSettings)
val rdb = RDB.open(settings.dbSettings)
val (blockchainUpdater, rdbWriter) =
StorageFactory(settings, rdb, time, BlockchainUpdateTriggers.combined(triggers))
val utxPool = new UtxPoolImpl(time, blockchainUpdater, settings.utxSettings, settings.maxTxErrorLogSize, settings.minerSettings.enable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import pureconfig.generic.auto.*

case class WavesSettings(
directory: String,
ntpServer: String,
ntpServer: Option[String],
maxTxErrorLogSize: Int,
dbSettings: DBSettings,
extensions: Seq[String],
Expand All @@ -33,7 +33,7 @@ object WavesSettings {
val wavesConfigSource = ConfigSource.fromConfig(waves)

val directory = wavesConfigSource.at("directory").loadOrThrow[String]
val ntpServer = wavesConfigSource.at("ntp-server").loadOrThrow[String]
val ntpServer = wavesConfigSource.at("ntp-server").loadOrThrow[Option[String]]
val maxTxErrorLogSize = wavesConfigSource.at("max-tx-error-log-size").loadOrThrow[Int]
val dbSettings = wavesConfigSource.at("db").loadOrThrow[DBSettings]
val extensions = wavesConfigSource.at("extensions").loadOrThrow[Seq[String]]
Expand Down
8 changes: 7 additions & 1 deletion node/src/main/scala/com/wavesplatform/utils/Time.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import org.apache.commons.net.ntp.NTPUDPClient
import java.time.Duration
import scala.concurrent.duration.DurationInt

trait Time {
trait Time extends AutoCloseable {
def correctedTime(): Long
def getTimestamp(): Long
override def close(): Unit = {}
}

object SystemTime extends Time {
def correctedTime(): Long = System.currentTimeMillis()
def getTimestamp(): Long = System.currentTimeMillis()
}

class NTP(ntpServer: String) extends Time with ScorexLogging with AutoCloseable {
Expand Down
2 changes: 1 addition & 1 deletion node/src/main/scala/com/wavesplatform/utils/UtilApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ object UtilApp {
private[this] final class NodeState(c: Command) {
lazy val settings = Application.loadApplicationConfig(c.configFile.map(new File(_)))
lazy val wallet = Wallet(settings.walletSettings)
lazy val time = new NTP(settings.ntpServer)
lazy val time = settings.ntpServer.fold[Time](SystemTime)(new NTP(_))
}

private[this] object Actions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.wavesplatform.test.NumericExt
import com.wavesplatform.transaction.Asset.IssuedAsset
import com.wavesplatform.transaction.TxHelpers.*
import com.wavesplatform.transaction.{Asset, AssetIdLength, TxHelpers}
import com.wavesplatform.utils.{Schedulers, Time}
import com.wavesplatform.utils.{Schedulers, SystemTime}
import io.netty.util.HashedWheelTimer
import monix.execution.schedulers.SchedulerService
import org.scalamock.scalatest.PathMockFactory
Expand All @@ -44,10 +44,7 @@ class UtilsRouteEvaluateSpec
"rest-time-limited"
)
private val utilsApi: UtilsApiRoute = UtilsApiRoute(
new Time {
def correctedTime(): Long = System.currentTimeMillis()
def getTimestamp(): Long = System.currentTimeMillis()
},
SystemTime,
restAPISettings,
Int.MaxValue,
() => ScriptEstimatorV3.latest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.wavesplatform.settings.TestSettings
import com.wavesplatform.state.Blockchain
import com.wavesplatform.state.diffs.FeeValidation
import com.wavesplatform.transaction.smart.script.ScriptCompiler
import com.wavesplatform.utils.{Schedulers, Time}
import com.wavesplatform.utils.{Schedulers, SystemTime}
import io.netty.util.HashedWheelTimer
import monix.execution.schedulers.SchedulerService
import org.scalacheck.Gen
Expand All @@ -38,7 +38,7 @@ import play.api.libs.json.*
import scala.concurrent.duration.*

class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with PropertyChecks with PathMockFactory with Inside with WithDomain {
private val estimator = ScriptEstimatorV2
private val estimator = ScriptEstimatorV2
protected override implicit val routeTestTimeout: RouteTestTimeout = RouteTestTimeout(20.seconds)

private val timeBounded: SchedulerService = Schedulers.timeBoundedFixedPool(
Expand All @@ -48,11 +48,7 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with
"rest-time-limited"
)
private val utilsApi: UtilsApiRoute = UtilsApiRoute(
new Time {
def correctedTime(): Long = System.currentTimeMillis()

def getTimestamp(): Long = System.currentTimeMillis()
},
SystemTime,
restAPISettings,
Int.MaxValue,
() => estimator,
Expand Down

0 comments on commit c1816dc

Please sign in to comment.