Skip to content

Commit 5b1ec44

Browse files
authored
Merge pull request #2 from notunrandom/fixbuild
Fix build error and warnings
2 parents 67ca032 + 0a69b69 commit 5b1ec44

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ dist/
2525
**/tags
2626
**/TAGS
2727

28+
# Shake
29+
30+
report.html
31+
bin
32+
blst
33+
libsodium
34+
secp256k1
35+
2836
# nix
2937
result
3038
result-[0-9]*

db-server.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ library
6161
aeson,
6262
base >=4.14 && <4.21,
6363
base16-bytestring >=1.0,
64-
base64-bytestring,
6564
bytestring >=0.10 && <0.13,
6665
cardano-crypto-class,
6766
cardano-ledger-api,
@@ -90,7 +89,6 @@ executable db-server
9089
base,
9190
contra-tracer,
9291
cardano-crypto-class,
93-
network,
9492
optparse-applicative,
9593
db-server,
9694
with-utf8,

src/Cardano/Tools/DB.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE DerivingStrategies #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE DeriveAnyClass #-}
24
{-# LANGUAGE FlexibleContexts #-}
35
{-# LANGUAGE FlexibleInstances #-}
46
{-# LANGUAGE LambdaCase #-}
@@ -51,6 +53,7 @@ import Data.Text (Text)
5153
import qualified Data.Text as Text
5254
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
5355
import Data.Word (Word64)
56+
import GHC.Generics (Generic)
5457
import Ouroboros.Consensus.Block (ChainHash (..), ConvertRawHash (fromRawHash), Proxy (..), headerPrevHash, toRawHash)
5558
import Ouroboros.Consensus.Block.Abstract (HeaderHash)
5659
import Ouroboros.Consensus.Block.RealPoint
@@ -160,7 +163,8 @@ data DBError
160163
| MalformedQuery Text
161164
| InitialHeader
162165
| UnknownStateType
163-
deriving stock (Eq, Show)
166+
deriving stock (Eq, Show, Generic)
167+
deriving anyclass (ToJSON, FromJSON)
164168

165169
toBytestring :: (IsString s) => DBError -> s
166170
toBytestring = fromString . show

src/Cardano/Tools/DBQuery.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE DerivingStrategies #-}
33
{-# LANGUAGE LambdaCase #-}
44
{-# LANGUAGE OverloadedStrings #-}
5-
{-# LANGUAGE ViewPatterns #-}
65

76
module Cardano.Tools.DBQuery
87
( DBQueryLog (..),
@@ -40,7 +39,7 @@ import qualified Data.Text as Text
4039
import GHC.Generics (Generic)
4140
import Ouroboros.Consensus.Storage.ChainDB (TraceEvent)
4241

43-
data DBQueryLog = DBLog (TraceEvent StandardBlock)
42+
newtype DBQueryLog = DBLog (TraceEvent StandardBlock)
4443
deriving stock (Eq, Show, Generic)
4544

4645
instance ToJSON DBQueryLog where
@@ -76,7 +75,7 @@ runQuery tracer configurationFile databaseDirectory query =
7675
runDBQuery :: DB -> Text -> IO (Result LBS.ByteString)
7776
runDBQuery db query = do
7877
case parseQuery query of
79-
Left err -> pure $ Err (MalformedQuery query)
78+
Left _ -> pure $ Err (MalformedQuery query)
8079
Right q ->
8180
case q of
8281
GetBlock point -> getBlock db point

src/Cardano/Tools/DBServer.hs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ run tracer (fromIntegral -> port) host configurationFile databaseDirectory = do
6161
& Warp.setServerName "db-server"
6262
& Warp.setTimeout 120
6363
& Warp.setMaximumBodyFlush Nothing
64-
& Warp.setBeforeMainLoop (traceWith tr HttpServerListening {host, port})
64+
& Warp.setBeforeMainLoop (traceWith tr (HttpListenLog (ListenEvent {host, port})))
6565

6666
webApp :: ChainDB IO StandardBlock -> Application
6767
webApp db req send =
@@ -74,8 +74,8 @@ webApp db req send =
7474
_ -> send responseNotFound
7575
where
7676
responseNotFound = responseLBS status404 [] ""
77-
responseBadRequest msg = responseLBS status400 [] msg
78-
responseOk content = responseLBS status200 [("content-type", "application/json")] content
77+
responseBadRequest = responseLBS status400 []
78+
responseOk = responseLBS status200 [("content-type", "application/json")]
7979

8080
handleGetSnapshots =
8181
listSnapshots db >>= \snapshotsPoints ->
@@ -90,7 +90,7 @@ webApp db req send =
9090
Err err -> send $ responseBadRequest ("Bad query: " <> toBytestring err)
9191
Found result -> send $ responseOk (LHex.encode result)
9292

93-
handleGetHeader slot hash = handleWithPoint getHeader slot hash
93+
handleGetHeader = handleWithPoint getHeader
9494

9595
handleGetSnapshot slot =
9696
case makeSlot slot of
@@ -101,9 +101,9 @@ webApp db req send =
101101
Err err -> send $ responseBadRequest ("Bad query: " <> toBytestring err)
102102
Found snapshot -> send $ responseOk (LHex.encode snapshot)
103103

104-
handleGetParent slot hash = handleWithPoint getParent slot hash
104+
handleGetParent = handleWithPoint getParent
105105

106-
handleGetBlock slot hash = handleWithPoint getBlock slot hash
106+
handleGetBlock = handleWithPoint getBlock
107107

108108
-- * Tracing
109109

@@ -131,12 +131,12 @@ withLog hdl k = do
131131
tracerMiddleware :: Tracer IO HttpServerLog -> Middleware
132132
tracerMiddleware tr runApp req send = do
133133
start <- GHC.Clock.getMonotonicTimeNSec
134-
traceWith tr HttpRequest {path, method}
134+
traceWith tr (HttpRequestLog (RequestEvent {path, method}))
135135
runApp req $ \res -> do
136136
result <- send res
137137
end <- GHC.Clock.getMonotonicTimeNSec
138138
let time = mkRequestTime start end
139-
traceWith tr HttpResponse {status = mkStatus (responseStatus res), time}
139+
traceWith tr (HttpResponseLog (ResponseEvent {status = mkStatus (responseStatus res), time}))
140140
pure result
141141
where
142142
method = decodeUtf8 (requestMethod req)
@@ -161,9 +161,20 @@ data HttpStatus = HttpStatus {code :: Int, message :: Text}
161161
deriving stock (Eq, Generic, Show)
162162
deriving anyclass (ToJSON, FromJSON)
163163

164-
data HttpServerLog
165-
= HttpServerListening {host :: String, port :: Int}
166-
| HttpRequest {path :: [Text], method :: Text}
167-
| HttpResponse {status :: HttpStatus, time :: RequestTime}
164+
data HttpServerLog =
165+
HttpListenLog ListenEvent
166+
| HttpRequestLog RequestEvent
167+
| HttpResponseLog ResponseEvent
168168
deriving stock (Eq, Show, Generic)
169169
deriving anyclass (ToJSON, FromJSON)
170+
171+
data ListenEvent = ListenEvent {host :: String, port :: Int}
172+
deriving stock (Eq, Show, Generic)
173+
deriving anyclass (ToJSON, FromJSON)
174+
data RequestEvent = RequestEvent {path :: [Text], method :: Text}
175+
deriving stock (Eq, Show, Generic)
176+
deriving anyclass (ToJSON, FromJSON)
177+
data ResponseEvent = ResponseEvent {status :: HttpStatus, time :: RequestTime}
178+
deriving stock (Eq, Show, Generic)
179+
deriving anyclass (ToJSON, FromJSON)
180+

0 commit comments

Comments
 (0)