Skip to content

Commit

Permalink
Remove redundant helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirlogachev committed Nov 18, 2024
1 parent dd38d84 commit 0ae2d8b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
20 changes: 0 additions & 20 deletions node/src/main/scala/com/wavesplatform/settings/DBSettings.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.wavesplatform.settings

import com.typesafe.config.Config

case class DBSettings(
directory: String,
storeTransactionsByAddress: Boolean,
Expand All @@ -13,21 +11,3 @@ case class DBSettings(
cleanupInterval: Option[Int] = None,
rocksdb: RocksDBSettings
)

object DBSettings {
def fromConfig(config: Config): DBSettings = DBSettings(
directory = config.getString("directory"),
storeTransactionsByAddress = config.getBoolean("store-transactions-by-address"),
storeLeaseStatesByAddress = config.getBoolean("store-lease-states-by-address"),
storeInvokeScriptResults = config.getBoolean("store-invoke-script-results"),
storeStateHashes = config.getBoolean("store-state-hashes"),
maxCacheSize = config.getInt("max-cache-size"),
maxRollbackDepth = config.getInt("max-rollback-depth"),
cleanupInterval = if (config.hasPath("cleanup-interval")) {
Option(config.getInt("cleanup-interval"))
} else {
None
},
rocksdb = RocksDBSettings.fromConfig(config.getConfig("rocksdb"))
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.wavesplatform.settings

import com.typesafe.config.Config

case class RocksDBSettings(
mainCacheSize: SizeInBytes,
txCacheSize: SizeInBytes,
Expand All @@ -14,19 +12,3 @@ case class RocksDBSettings(
parallelism: Int,
maxOpenFiles: Int
)

object RocksDBSettings {
def fromConfig(config: Config): RocksDBSettings =
RocksDBSettings(
mainCacheSize = SizeInBytes(config.getBytes("main-cache-size").toLong),
txCacheSize = SizeInBytes(config.getBytes("tx-cache-size").toLong),
txMetaCacheSize = SizeInBytes(config.getBytes("tx-meta-cache-size").toLong),
txSnapshotCacheSize = SizeInBytes(config.getBytes("tx-snapshot-cache-size").toLong),
apiCacheSize = SizeInBytes(config.getBytes("api-cache-size").toLong),
writeBufferSize = SizeInBytes(config.getBytes("write-buffer-size").toLong),
enableStatistics = config.getBoolean("enable-statistics"),
allowMmapReads = config.getBoolean("allow-mmap-reads"),
parallelism = config.getInt("parallelism"),
maxOpenFiles = config.getInt("max-open-files")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object WavesSettings {
val enableLightMode = wavesConfigSource.at("enable-light-mode").loadOrThrow[Boolean]
val ntpServer = wavesConfigSource.at("ntp-server").loadOrThrow[String]
val maxTxErrorLogSize = wavesConfigSource.at("max-tx-error-log-size").loadOrThrow[Int]
val dbSettings = DBSettings.fromConfig(waves.getConfig("db"))
val dbSettings = wavesConfigSource.at("db").loadOrThrow[DBSettings]
val extensions = wavesConfigSource.at("extensions").loadOrThrow[Seq[String]]
val extensionsShutdownTimeout = wavesConfigSource.at("extensions-shutdown-timeout").loadOrThrow[FiniteDuration]
val networkSettings = wavesConfigSource.at("network").loadOrThrow[NetworkSettings]
Expand Down
10 changes: 10 additions & 0 deletions node/src/main/scala/com/wavesplatform/settings/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ package object settings {
object SizeInBytes extends TaggedType[Long]
type SizeInBytes = SizeInBytes.Type

implicit val sizeInBytesConfigReader: ConfigReader[SizeInBytes] = ConfigReader.fromCursor(cur =>
for {
configValue <- cur.asConfigValue
} yield {
val config = ConfigFactory.empty().withValue("stubKey", configValue)
val bytes: Long = config.getBytes("stubKey")
SizeInBytes(bytes)
}
)

def loadConfig(userConfig: Config): Config = {
loadConfig(Some(userConfig))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.wavesplatform.settings

import com.typesafe.config.ConfigFactory
import com.wavesplatform.test.FlatSpec
import pureconfig.ConfigSource
import pureconfig.generic.auto.*

class DbSettingsSpecification extends FlatSpec {
"DbSettingsSpecification" should "read values from config" in {
Expand All @@ -27,7 +29,8 @@ class DbSettingsSpecification extends FlatSpec {
| max-open-files = 100
| }
|}""".stripMargin))
val actualDbSettings = DBSettings.fromConfig(config.getConfig("waves.db"))

val actualDbSettings = ConfigSource.fromConfig(config).at("waves.db").loadOrThrow[DBSettings]

val expectedDbSettings: DBSettings = DBSettings(
directory = "/data",
Expand Down

0 comments on commit 0ae2d8b

Please sign in to comment.