From f4d2ec9f203e8c44f8179d87f20e0d67d6dc8f6a Mon Sep 17 00:00:00 2001 From: Thomas Droxler Date: Wed, 1 May 2024 16:46:54 +0200 Subject: [PATCH] Refactor config with `services` that can be enabled --- app/src/main/resources/application.conf | 62 +++++++++++++------ .../org/alephium/explorer/SyncServices.scala | 10 +-- .../explorer/config/ExplorerConfig.scala | 57 ++++++++++++----- 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/app/src/main/resources/application.conf b/app/src/main/resources/application.conf index 26fc934b..d16f1820 100644 --- a/app/src/main/resources/application.conf +++ b/app/src/main/resources/application.conf @@ -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 diff --git a/app/src/main/scala/org/alephium/explorer/SyncServices.scala b/app/src/main/scala/org/alephium/explorer/SyncServices.scala index 0203cba9..62ecd671 100644 --- a/app/src/main/scala/org/alephium/explorer/SyncServices.scala +++ b/app/src/main/scala/org/alephium/explorer/SyncServices.scala @@ -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 ) } } diff --git a/app/src/main/scala/org/alephium/explorer/config/ExplorerConfig.scala b/app/src/main/scala/org/alephium/explorer/config/ExplorerConfig.scala index 153b4080..64d1623d 100644 --- a/app/src/main/scala/org/alephium/explorer/config/ExplorerConfig.scala +++ b/app/src/main/scala/org/alephium/explorer/config/ExplorerConfig.scala @@ -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, @@ -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, @@ -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,