Skip to content

Commit

Permalink
Refactor config with services that can be enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
tdroxler committed May 1, 2024
1 parent 6fc715d commit f4d2ec9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 39 deletions.
62 changes: 43 additions & 19 deletions app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,49 @@ explorer {
boot-mode = ReadWrite
boot-mode = ${?EXPLORER_BOOT_MODE}

# Sync interval for BlockFlowSyncService & MempoolSyncService
sync-period = 5 seconds
sync-period = ${?EXPLORER_SYNC_PERIOD}

# Schedule time for TokenSupplyService
token-supply-service-schedule-time = "02:00"
token-supply-service-schedule-time = ${?EXPLORER_TOKEN_SUPPLY_SERVICE_SCHEDULE_TIME}

# Sync interval for HashRateService
hash-rate-service-sync-period = 1 hours
hash-rate-service-sync-period = ${?EXPLORER_HASH_RATE_SERVICE_SYNC_PERIOD}

# Sync interval for FinalizerService
finalizer-service-sync-period = 10 minutes
finalizer-service-sync-period = ${?EXPLORER_FINALIZER_SERVICE_SYNC_PERIOD}

# Sync interval for TransactionHistoryService
transaction-history-service-sync-period = 15 minutes
transaction-history-service-sync-period = ${?EXPLORER_TRANSACTION_HISTORY_SERVICE_SYNC_PERIOD}
services {
blockflow-sync = {
# BlockFlowSync Service is always enabled
# Sync interval for BlockFlowSyncService
sync-period = 5 seconds
sync-period = ${?EXPLORER_SYNC_PERIOD}
}

mempool-sync = {
enable = true,
# Sync interval for MempoolSyncService
sync-period = 5 seconds
sync-period = ${?EXPLORER_SYNC_PERIOD}
}

token-supply = {
enable = true,
# Schedule time for TokenSupplyService
schedule-time = "02:00"
schedule-time = ${?EXPLORER_TOKEN_SUPPLY_SERVICE_SCHEDULE_TIME}
}

hashrate = {
enable = true,
# Sync interval for HashRateService
sync-period = 1 hours
sync-period = ${?EXPLORER_HASH_RATE_SERVICE_SYNC_PERIOD}
}

tx-history = {
enable = true,
# Sync interval for TransactionHistoryService
sync-period = 15 minutes
sync-period = ${?EXPLORER_TRANSACTION_HISTORY_SERVICE_SYNC_PERIOD}
}

finalizer = {
# FinalizerService is always enabled
# Sync interval for FinalizerService
sync-period = 10 minutes
sync-period = ${?EXPLORER_FINALIZER_SERVICE_SYNC_PERIOD}
}
}

# Cache reloading intervals for BlockCache
cache-row-count-reload-period = 10 seconds
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/scala/org/alephium/explorer/SyncServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ object SyncServices extends StrictLogging {
) flatMap { peers =>
startSyncServices(
peers = peers,
syncPeriod = config.syncPeriod,
tokenSupplyServiceScheduleTime = config.tokenSupplyServiceScheduleTime,
hashRateServiceSyncPeriod = config.hashRateServiceSyncPeriod,
finalizerServiceSyncPeriod = config.finalizerServiceSyncPeriod,
transactionHistoryServiceSyncPeriod = config.transactionHistoryServiceSyncPeriod
syncPeriod = config.services.blockflowSync.syncPeriod,
tokenSupplyServiceScheduleTime = config.services.tokenSupply.scheduleTime,
hashRateServiceSyncPeriod = config.services.hashrate.syncPeriod,
finalizerServiceSyncPeriod = config.services.finalizer.syncPeriod,
transactionHistoryServiceSyncPeriod = config.services.txHistory.syncPeriod
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ object ExplorerConfig {
host,
port,
explorer.bootMode,
explorer.syncPeriod,
explorer.tokenSupplyServiceScheduleTime,
explorer.hashRateServiceSyncPeriod,
explorer.finalizerServiceSyncPeriod,
explorer.transactionHistoryServiceSyncPeriod,
explorer.services,
explorer.cacheRowCountReloadPeriod,
explorer.cacheBlockTimesReloadPeriod,
explorer.cacheLatestBlocksReloadPeriod,
Expand Down Expand Up @@ -197,15 +193,50 @@ object ExplorerConfig {
marketChartDays: Int
)

final case class Services(
blockflowSync: Services.BlockflowSync,
mempoolSync: Services.MempoolSync,
tokenSupply: Services.TokenSupply,
hashrate: Services.Hashrate,
txHistory: Services.TxHistory,
finalizer: Services.Finalizer
)

object Services {
final case class BlockflowSync(
syncPeriod: FiniteDuration
)

final case class MempoolSync(
enable: Boolean,
syncPeriod: FiniteDuration
)

final case class TokenSupply(
enable: Boolean,
scheduleTime: LocalTime
)

final case class Hashrate(
enable: Boolean,
syncPeriod: FiniteDuration
)

final case class TxHistory(
enable: Boolean,
syncPeriod: FiniteDuration
)

final case class Finalizer(
syncPeriod: FiniteDuration
)
}

final private case class Explorer(
host: String,
port: Int,
bootMode: BootMode,
syncPeriod: FiniteDuration,
tokenSupplyServiceScheduleTime: LocalTime,
hashRateServiceSyncPeriod: FiniteDuration,
finalizerServiceSyncPeriod: FiniteDuration,
transactionHistoryServiceSyncPeriod: FiniteDuration,
services: Services,
cacheRowCountReloadPeriod: FiniteDuration,
cacheBlockTimesReloadPeriod: FiniteDuration,
cacheLatestBlocksReloadPeriod: FiniteDuration,
Expand All @@ -230,11 +261,7 @@ final case class ExplorerConfig private (
host: String,
port: Int,
bootMode: BootMode,
syncPeriod: FiniteDuration,
tokenSupplyServiceScheduleTime: LocalTime,
hashRateServiceSyncPeriod: FiniteDuration,
finalizerServiceSyncPeriod: FiniteDuration,
transactionHistoryServiceSyncPeriod: FiniteDuration,
services: ExplorerConfig.Services,
cacheRowCountReloadPeriod: FiniteDuration,
cacheBlockTimesReloadPeriod: FiniteDuration,
cacheLatestBlocksReloadPeriod: FiniteDuration,
Expand Down

0 comments on commit f4d2ec9

Please sign in to comment.