Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit ffa1266

Browse files
authored
Merge pull request #28 from kadena-io/edmund/configure-getwork-timeout
Add configurable default HTTP request timeout
2 parents 4e216d8 + 97e031b commit ffa1266

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

chainweb-mining-client.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ test-suite tests
138138
, exceptions >=0.10
139139
, hashable >=1.3
140140
, hostaddress >=0.2
141+
, optparse-applicative < 0.18
141142
, memory >=0.15
142143
, quickcheck-instances >=0.3
143144
, stm >=2.5

main/Main.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ data Config = Config
262262
, _configOnDemandPort :: !Port
263263
, _configOnDemandInterface :: !HostPreference
264264
, _configConstantDelayBlockTime :: !Natural
265+
, _configDefaultHTTPTimeout :: !Int
265266
}
266267
deriving (Show, Eq, Ord, Generic)
267268

@@ -287,6 +288,7 @@ defaultConfig = Config
287288
, _configOnDemandPort = 1917
288289
, _configOnDemandInterface = "*"
289290
, _configConstantDelayBlockTime = 30
291+
, _configDefaultHTTPTimeout = 1000000
290292
}
291293

292294
instance ToJSON Config where
@@ -309,6 +311,7 @@ instance ToJSON Config where
309311
, "onDemandPort" .= _configOnDemandPort c
310312
, "onDemandInterface" .= _configOnDemandInterface c
311313
, "constantDelayBlockTime" .= _configConstantDelayBlockTime c
314+
, "defaultHTTPTimeout" .= _configDefaultHTTPTimeout c
312315
]
313316

314317
instance FromJSON (Config -> Config) where
@@ -331,6 +334,7 @@ instance FromJSON (Config -> Config) where
331334
<*< configOnDemandPort ..: "onDemandPort" % o
332335
<*< configOnDemandInterface ..: "onDemandInterface" % o
333336
<*< configConstantDelayBlockTime ..: "constantDelayBlockTime" % o
337+
<*< configDefaultHTTPTimeout ..: "defaultHTTPTimeout" % o
334338
where
335339
parseLogLevel = withText "LogLevel" $ return . logLevelFromText
336340

@@ -403,6 +407,9 @@ parseConfig = id
403407
<*< configOnDemandPort .:: option jsonReader
404408
% long "on-demand-port"
405409
<> help "port on which the on-demand mining server listens"
410+
<*< configDefaultHTTPTimeout .:: option auto
411+
% long "default-http-timeout"
412+
<> help "the default timeout of HTTP requests made by the miner, for example to the node"
406413

407414
-- -------------------------------------------------------------------------- --
408415
-- HTTP Retry Logic
@@ -810,7 +817,7 @@ main = runWithPkgInfoConfiguration mainInfo pkgInfo $ \conf ->
810817
run :: Config -> Logger -> IO ()
811818
run conf logger = do
812819
mgr <- HTTP.newManager (HTTP.mkManagerSettings tlsSettings Nothing)
813-
{ HTTP.managerResponseTimeout = HTTP.responseTimeoutMicro 1000000 }
820+
{ HTTP.managerResponseTimeout = HTTP.responseTimeoutMicro (_configDefaultHTTPTimeout conf) }
814821
-- We don't want to wait too long, because latencies matter in
815822
-- mining. NOTE, however, that for large blocks it can take a while
816823
-- to get new work. This can be an issue with public mining mode.

0 commit comments

Comments
 (0)