@@ -86,6 +86,7 @@ import Text.Read (Read(..), readListPrecDefault)
8686import Utils
8787import Logger
8888import Worker
89+ import Worker.ConstantDelay
8990import Worker.CPU
9091import Worker.External
9192import Worker.Simulation
@@ -203,6 +204,7 @@ data WorkerConfig
203204 | ExternalWorker
204205 | SimulationWorker
205206 | StratumWorker
207+ | ConstantDelayWorker
206208 deriving (Show , Eq , Ord , Generic )
207209 deriving anyclass (Hashable )
208210
@@ -220,13 +222,15 @@ workerConfigToText CpuWorker = "cpu"
220222workerConfigToText ExternalWorker = " external"
221223workerConfigToText SimulationWorker = " simulation"
222224workerConfigToText StratumWorker = " stratum"
225+ workerConfigToText ConstantDelayWorker = " constant-delay"
223226
224227workerConfigFromText :: MonadThrow m => T. Text -> m WorkerConfig
225228workerConfigFromText t = case T. toCaseFold t of
226229 " cpu" -> return CpuWorker
227230 " external" -> return ExternalWorker
228231 " simulation" -> return SimulationWorker
229232 " stratum" -> return StratumWorker
233+ " constant-delay" -> return ConstantDelayWorker
230234 _ -> throwM $ FromTextException $ " unknown worker configuraton: " <> t
231235
232236-- -------------------------------------------------------------------------- --
@@ -252,6 +256,7 @@ data Config = Config
252256 , _configStratumInterface :: ! HostPreference
253257 , _configStratumDifficulty :: ! Stratum. StratumDifficulty
254258 , _configStratumRate :: ! Natural
259+ , _configConstantDelayBlockTime :: ! Natural
255260 }
256261 deriving (Show , Eq , Ord , Generic )
257262
@@ -274,6 +279,7 @@ defaultConfig = Config
274279 , _configStratumInterface = " *"
275280 , _configStratumDifficulty = Stratum. WorkDifficulty
276281 , _configStratumRate = 1000
282+ , _configConstantDelayBlockTime = 30
277283 }
278284
279285instance ToJSON Config where
@@ -293,6 +299,7 @@ instance ToJSON Config where
293299 , " stratumInterface" .= _configStratumInterface c
294300 , " stratumDifficulty" .= _configStratumDifficulty c
295301 , " stratumRate" .= _configStratumRate c
302+ , " constantDelayBlockTime" .= _configConstantDelayBlockTime c
296303 ]
297304
298305instance FromJSON (Config -> Config ) where
@@ -312,6 +319,7 @@ instance FromJSON (Config -> Config) where
312319 <*< configStratumInterface ..: " stratumInterface" % o
313320 <*< configStratumDifficulty ..: " stratumDifficulty" % o
314321 <*< configStratumRate ..: " stratumRate" % o
322+ <*< configConstantDelayBlockTime ..: " constantDelayBlockTime" % o
315323 where
316324 parseLogLevel = withText " LogLevel" $ return . logLevelFromText
317325
@@ -358,7 +366,7 @@ parseConfig = id
358366 % short ' w'
359367 <> long " worker"
360368 <> help " The type of mining worker that is used"
361- <> metavar " cpu|external|simulation|stratum"
369+ <> metavar " cpu|external|simulation|stratum|constant-delay "
362370 <*< configExternalWorkerCommand .:: option (textReader $ Right . T. unpack)
363371 % long " external-worker-cmd"
364372 <> help " command that is used to call an external worker. When the command is called the target value is added as last parameter to the command line."
@@ -375,6 +383,9 @@ parseConfig = id
375383 % short ' s'
376384 <> long " stratum-rate"
377385 <> help " Rate (in milliseconds) at which a stratum worker thread emits jobs."
386+ <*< configConstantDelayBlockTime .:: option auto
387+ % long " constant-delay-block-time"
388+ <> help " time at which a constant-delay worker emits blocks"
378389
379390-- -------------------------------------------------------------------------- --
380391-- HTTP Retry Logic
@@ -537,8 +548,8 @@ getJob conf ver mgr = do
537548postSolved :: Config -> ChainwebVersion -> Logger -> HTTP. Manager -> Work -> IO ()
538549postSolved conf ver logger mgr (Work bytes) = retryHttp logger $ do
539550 logg Info " post solved worked"
540- ( void $ HTTP. httpLbs req mgr)
541- `catch` \ ( e@ (HTTP. HttpExceptionRequest _ _) ) -> do
551+ void ( HTTP. httpLbs req mgr)
552+ `catch` \ e@ (HTTP. HttpExceptionRequest _ _) -> do
542553 logg Error $ " failed to submit solved work: " <> sshow e
543554 return ()
544555 where
@@ -817,6 +828,8 @@ run conf logger = do
817828 SimulationWorker -> do
818829 rng <- MWC. createSystemRandom
819830 f $ \ l -> simulationWorker l rng workerRate
831+ ConstantDelayWorker -> do
832+ f $ \ l -> constantDelayWorker l (_configConstantDelayBlockTime conf)
820833 ExternalWorker -> f $ \ l -> externalWorker l (_configExternalWorkerCommand conf)
821834 CpuWorker -> f $ cpuWorker @ Blake2s_256
822835 StratumWorker -> Stratum. withStratumServer
0 commit comments