Skip to content

Commit

Permalink
Merge pull request #28 from kadena-io/edmund/configure-getwork-timeout
Browse files Browse the repository at this point in the history
Add configurable default HTTP request timeout
  • Loading branch information
edmundnoble authored Jun 20, 2023
2 parents 4e216d8 + 97e031b commit ffa1266
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions chainweb-mining-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ test-suite tests
, exceptions >=0.10
, hashable >=1.3
, hostaddress >=0.2
, optparse-applicative < 0.18
, memory >=0.15
, quickcheck-instances >=0.3
, stm >=2.5
Expand Down
9 changes: 8 additions & 1 deletion main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ data Config = Config
, _configOnDemandPort :: !Port
, _configOnDemandInterface :: !HostPreference
, _configConstantDelayBlockTime :: !Natural
, _configDefaultHTTPTimeout :: !Int
}
deriving (Show, Eq, Ord, Generic)

Expand All @@ -287,6 +288,7 @@ defaultConfig = Config
, _configOnDemandPort = 1917
, _configOnDemandInterface = "*"
, _configConstantDelayBlockTime = 30
, _configDefaultHTTPTimeout = 1000000
}

instance ToJSON Config where
Expand All @@ -309,6 +311,7 @@ instance ToJSON Config where
, "onDemandPort" .= _configOnDemandPort c
, "onDemandInterface" .= _configOnDemandInterface c
, "constantDelayBlockTime" .= _configConstantDelayBlockTime c
, "defaultHTTPTimeout" .= _configDefaultHTTPTimeout c
]

instance FromJSON (Config -> Config) where
Expand All @@ -331,6 +334,7 @@ instance FromJSON (Config -> Config) where
<*< configOnDemandPort ..: "onDemandPort" % o
<*< configOnDemandInterface ..: "onDemandInterface" % o
<*< configConstantDelayBlockTime ..: "constantDelayBlockTime" % o
<*< configDefaultHTTPTimeout ..: "defaultHTTPTimeout" % o
where
parseLogLevel = withText "LogLevel" $ return . logLevelFromText

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

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

0 comments on commit ffa1266

Please sign in to comment.