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

Commit 4e216d8

Browse files
authored
housekeeping (#26)
* housekeeping * add build with ghc-9.4 * add missing COMPLETE pragmas * update outdated actions * remove redundant imports
1 parent 8b876ec commit 4e216d8

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

.github/workflows/build-application.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
ghc: ['8.10.7', '9.0.2', '9.2']
14+
ghc: ['8.10.7', '9.0.2', '9.2', '9.4']
1515
cabal: ['3.8']
1616
os: ['ubuntu-20.04', 'ubuntu-22.04', 'macOS-latest']
1717

@@ -31,7 +31,7 @@ jobs:
3131
- name: Checkout repository
3232
uses: actions/checkout@v3
3333
- name: Install GHC and Cabal
34-
uses: haskell/actions/setup@v2.0.2
34+
uses: haskell/actions/setup@v2
3535
with:
3636
ghc-version: ${{ matrix.ghc }}
3737
cabal-version: ${{ matrix.cabal }}
@@ -145,7 +145,7 @@ jobs:
145145

146146
- name: Docker meta
147147
id: meta
148-
uses: docker/metadata-action@v3
148+
uses: docker/metadata-action@v4
149149
with:
150150
images: ghcr.io/kadena-io/chainweb-mining-client
151151
tags: |
@@ -163,7 +163,7 @@ jobs:
163163

164164
- name: Build and push
165165
id: docker_build
166-
uses: docker/build-push-action@v2
166+
uses: docker/build-push-action@v4
167167
with:
168168
push: true
169169
context: .

main/Main.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Configuration.Utils hiding (Error)
3232
import Control.Concurrent
3333
import Control.Concurrent.Async
3434
import Control.Concurrent.STM
35-
import Control.Exception (IOException, SomeAsyncException)
35+
import Control.Exception (IOException, SomeAsyncException, throwIO)
3636
import Control.Lens hiding ((.=))
3737
import Control.Monad
3838
import Control.Monad.Catch
@@ -551,9 +551,11 @@ postSolved :: Config -> ChainwebVersion -> Logger -> HTTP.Manager -> Work -> IO
551551
postSolved conf ver logger mgr (Work bytes) = retryHttp logger $ do
552552
logg Info "post solved worked"
553553
void (HTTP.httpLbs req mgr)
554-
`catch` \e@(HTTP.HttpExceptionRequest _ _) -> do
555-
logg Error $ "failed to submit solved work: " <> sshow e
556-
return ()
554+
`catch` \case
555+
e@(HTTP.HttpExceptionRequest _ _) -> do
556+
logg Error $ "failed to submit solved work: " <> sshow e
557+
return ()
558+
e -> throwIO e
557559
where
558560
logg = writeLog logger
559561
req = (baseReq conf ver "mining/solved")

src/JsonRpc.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ data Static (a :: k) = Static
5757

5858
pattern StaticNull :: Static 'Nothing
5959
pattern StaticNull = Static
60+
{-# COMPLETE StaticNull #-}
6061

6162
pattern StaticTrue :: Static 'True
6263
pattern StaticTrue = Static
64+
{-# COMPLETE StaticTrue #-}
6365

6466
pattern StaticFalse :: Static 'False
6567
pattern StaticFalse = Static
68+
{-# COMPLETE StaticFalse #-}
6669

6770
instance A.ToJSON (Static 'Nothing) where
6871
toEncoding _ = A.null_

src/Utils.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,11 @@ le64 = f targetByteOrder
311311

312312
-- | Encode to or from little endian. This is @id@ on little endian platforms.
313313
--
314+
#if MIN_VERSION_base(4,17,0)
315+
le64# :: Word64# -> Word64#
316+
#else
314317
le64# :: Word# -> Word#
318+
#endif
315319
le64# = f targetByteOrder
316320
where
317321
f BigEndian x = byteSwap64# x
@@ -333,9 +337,11 @@ secondsNs :: Integer -> Integer
333337
secondsNs i = i * 1_000_000_000
334338
{-# INLINE secondsNs #-}
335339

340+
#if !MIN_VERSION_stm(2,5,1)
336341
writeTMVar :: TMVar a -> a -> STM ()
337342
writeTMVar var a = tryTakeTMVar var >> putTMVar var a
338343
{-# INLINE writeTMVar #-}
344+
#endif
339345

340346
-- -------------------------------------------------------------------------- --
341347
-- BigNum Compatibility

src/Worker/OnDemand.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import Control.Concurrent.STM
2525
import Control.Monad
2626
import Control.Monad.Catch
2727

28-
import Data.Aeson
29-
import qualified Data.ByteString.Lazy.Char8 as LBS8
3028
import Data.Function
3129
import Data.HashMap.Strict(HashMap)
3230
import qualified Data.HashMap.Strict as HashMap

src/Worker/POW/Stratum/Protocol.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
{-# LANGUAGE TypeApplications #-}
1010
{-# LANGUAGE ViewPatterns #-}
1111

12+
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
13+
1214
-- |
1315
-- Module: Worker.POW.Stratum.Protocol
1416
-- Copyright: Copyright © 2021 Kadena LLC.
@@ -506,9 +508,10 @@ parseMiningResponse pendingRequests = A.withObject "MiningResponse" $ \o -> do
506508
r@Submit{} -> (r,) . SubmitResponse mid <$> parseResponse o
507509

508510
where
509-
parseSubscribeParams = A.parseJSON >=> \(StaticNull, v, s) -> case nonceSize @Int s of
510-
Nothing -> fail $ "invalid nonce2 size. Expected a value between 0 and 8 but got " <> show s
511-
Just ns -> (, ns) <$> parseNonce1 (complementNonceSize ns) v
511+
parseSubscribeParams = A.parseJSON >=> \(StaticNull, v, s) ->
512+
case nonceSize @Int s of
513+
Nothing -> fail $ "invalid nonce2 size. Expected a value between 0 and 8 but got " <> show s
514+
Just ns -> (, ns) <$> parseNonce1 (complementNonceSize ns) v
512515

513516
parseAuthorizeParams = A.parseJSON >=> \(T1 StaticTrue) -> return ()
514517
{-# INLINE parseMiningResponse #-}

src/Worker/POW/Stratum/Server.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55
{-# LANGUAGE TypeApplications #-}
66

7+
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
8+
79
-- |
810
-- Module: Worker.POW.Stratum.Server
911
-- Copyright: Copyright © 2021 Kadena LLC.
@@ -277,7 +279,7 @@ targetPeriod :: Period
277279
targetPeriod = Period 10
278280

279281
notify :: Logger -> AppData -> SessionState -> Job -> IO ()
280-
notify logger app sessionCtx job = do
282+
notify logger app _sessionCtx job = do
281283
writeLog logger L.Info "sending notification"
282284
send app $ Notify (_jobId job, _jobWork job, True) -- for now we always replace previous work
283285

@@ -330,7 +332,7 @@ stratumDifficultyFromText t = case readEither @Int $ T.unpack t of
330332
instance A.ToJSON StratumDifficulty where
331333
toJSON WorkDifficulty = "block"
332334
toJSON (DifficultyLevel i) = A.toJSON i
333-
toJSON (DifficultyPeriod i) = error "ToJSON StratumDifficulty: difficulty period is currently not supported"
335+
toJSON (DifficultyPeriod _i) = error "ToJSON StratumDifficulty: difficulty period is currently not supported"
334336

335337
instance A.FromJSON StratumDifficulty where
336338
parseJSON v = case v of
@@ -384,7 +386,7 @@ getNewSessionTarget stratumDifficulty currentHashRate currentTarget jobTarget
384386
DifficultyPeriod p -> newPeriodTarget p
385387

386388
-- The final target must be inbetween maxSessionTarget and jobTarget
387-
newPeriodTarget p = max jobTarget (min maxSessionTarget candidate)
389+
newPeriodTarget _p = max jobTarget (min maxSessionTarget candidate)
388390
where
389391
curD = targetToDifficulty currentTarget
390392
newD = adjustDifficulty periodTolerance currentHashRate targetPeriod curD

0 commit comments

Comments
 (0)