Skip to content

Commit

Permalink
Remove NoImplicitPrelude from cardano-node
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Feb 6, 2023
1 parent df9bce4 commit 6d755f3
Show file tree
Hide file tree
Showing 30 changed files with 137 additions and 115 deletions.
1 change: 0 additions & 1 deletion cardano-node/app/cardano-node.hs
@@ -1,4 +1,3 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}

Expand Down
7 changes: 5 additions & 2 deletions cardano-node/cardano-node.cabal
Expand Up @@ -27,8 +27,7 @@ flag systemd
common project-config
default-language: Haskell2010

default-extensions: NoImplicitPrelude
OverloadedStrings
default-extensions: OverloadedStrings
build-depends: base >= 4.14 && < 4.17

ghc-options: -Wall
Expand Down Expand Up @@ -166,6 +165,7 @@ library
, lobemo-backend-ekg
, lobemo-backend-monitoring
, lobemo-backend-trace-forwarder
, mtl
, network
, network-mux ^>= 0.2
, nothunks
Expand Down Expand Up @@ -233,10 +233,13 @@ test-suite cardano-node-test
, hedgehog
, hedgehog-corpus
, iproute
, mtl
, ouroboros-consensus
, ouroboros-network
, mtl
, text
, time
, transformers
, vector

other-modules: Test.Cardano.Node.FilePermissions
Expand Down
27 changes: 17 additions & 10 deletions cardano-node/src/Cardano/Node/Configuration/Logging.hs
Expand Up @@ -23,17 +23,24 @@ module Cardano.Node.Configuration.Logging
, LOContent (..)
) where

import Cardano.Api (textShow)
import qualified Cardano.Api as Api
import Cardano.Prelude hiding (trace)

import qualified Control.Concurrent as Conc
import qualified Control.Concurrent.Async as Async
import Control.Concurrent.MVar (MVar, newMVar)
import Control.Concurrent.STM (STM)
import Control.Exception (IOException)
import Control.Exception.Safe (MonadCatch)
import Control.Monad (forM_, forever, void, when)
import Control.Monad.Except (ExceptT)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except.Extra (catchIOExceptT)
import "contra-tracer" Control.Tracer
import Data.List (nub)
import qualified Data.Map.Strict as Map
import Data.Text (pack)
import Data.Maybe (isJust)
import Data.Text (Text, pack)
import Data.Time.Clock (UTCTime, getCurrentTime)
import Data.Version (showVersion)
import System.Metrics.Counter (Counter)
Expand Down Expand Up @@ -344,22 +351,22 @@ nodeBasicInfo nc (SomeConsensusProtocol whichP pForInfo) nodeStartTime' = do
[ ("protocol", pack . show $ ncProtocol nc)
, ("version", pack . showVersion $ version)
, ("commit", gitRev)
, ("nodeStartTime", show nodeStartTime')
, ("nodeStartTime", textShow nodeStartTime')
] ++ protocolDependentItems
logObjects =
map (\(nm, msg) -> LogObject ("basicInfo." <> nm) meta (LogMessage msg)) items
return logObjects
where
getGenesisValuesByron cfg config =
let genesis = byronLedgerConfig config
in [ ("systemStartTime", show (WCT.getSystemStart . getSystemStart $ Consensus.configBlock cfg))
, ("slotLengthByron", show (WCT.getSlotLength . fromByronSlotLength $ genesisSlotLength genesis))
, ("epochLengthByron", show (unEpochSize . fromByronEpochSlots $ Gen.configEpochSlots genesis))
in [ ("systemStartTime", textShow (WCT.getSystemStart . getSystemStart $ Consensus.configBlock cfg))
, ("slotLengthByron", textShow (WCT.getSlotLength . fromByronSlotLength $ genesisSlotLength genesis))
, ("epochLengthByron", textShow (unEpochSize . fromByronEpochSlots $ Gen.configEpochSlots genesis))
]
getGenesisValues era config =
let genesis = shelleyLedgerGenesis $ shelleyLedgerConfig config
in [ ("systemStartTime", show (SL.sgSystemStart genesis))
, ("slotLength" <> era, show (WCT.getSlotLength . WCT.mkSlotLength $ SL.sgSlotLength genesis))
, ("epochLength" <> era, show (unEpochSize . SL.sgEpochLength $ genesis))
, ("slotsPerKESPeriod" <> era, show (SL.sgSlotsPerKESPeriod genesis))
in [ ("systemStartTime", textShow (SL.sgSystemStart genesis))
, ("slotLength" <> era, textShow (WCT.getSlotLength . WCT.mkSlotLength $ SL.sgSlotLength genesis))
, ("epochLength" <> era, textShow (unEpochSize . SL.sgEpochLength $ genesis))
, ("slotsPerKESPeriod" <> era, textShow (SL.sgSlotsPerKESPeriod genesis))
]
13 changes: 9 additions & 4 deletions cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
Expand Up @@ -26,13 +26,18 @@ module Cardano.Node.Handlers.Shutdown
)
where

import Cardano.Prelude
import Control.Applicative (Alternative (..))
import Control.Concurrent.Async (race_)
import Control.Exception (try)
import Control.Exception.Base (throwIO)
import Control.Monad (void, when)
import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text, pack)
import Generic.Data.Orphans ()

import Data.Text (pack)
import GHC.Generics (Generic)
import qualified GHC.IO.Handle.FD as IO (fdToHandle)
import qualified Options.Applicative as Opt
import System.Exit (ExitCode (..))
import qualified System.IO as IO
import qualified System.IO.Error as IO
import System.Posix.Types (Fd (Fd))
Expand Down Expand Up @@ -148,7 +153,7 @@ maybeSpawnOnSlotSyncedShutdownHandler sc tr registry chaindb =
spawnLimitTerminator :: ShutdownOn -> IO ()
spawnLimitTerminator limit =
void $ forkLinkedWatcher registry "slotLimitTerminator" Watcher {
wFingerprint = identity
wFingerprint = id
, wInitial = Nothing
, wReader =
case limit of
Expand Down
9 changes: 7 additions & 2 deletions cardano-node/src/Cardano/Node/Protocol/Byron.hs
Expand Up @@ -12,10 +12,12 @@ module Cardano.Node.Protocol.Byron
, readLeaderCredentials
) where

import Cardano.Prelude (ConvertText (..), canonicalDecodePretty)

import Cardano.Prelude
import Control.Monad.Except (throwError)
import Control.Monad.Trans.Except.Extra (bimapExceptT, firstExceptT, hoistEither, left)
import qualified Data.ByteString.Lazy as LB
import Data.Maybe (fromMaybe)
import qualified Data.Text as Text

import Cardano.Api.Byron
Expand All @@ -42,6 +44,9 @@ import Cardano.Tracing.OrphanInstances.Shelley ()
import Cardano.Node.Tracing.Era.Byron ()
import Cardano.Node.Tracing.Era.HardFork ()
import Cardano.Node.Tracing.Tracers.ChainDB ()
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Data.Text (Text)



Expand Down Expand Up @@ -134,7 +139,7 @@ readGenesis (GenesisFile file) mbExpectedGenesisHash ncReqNetworkMagic = do
$ h
where
impossible =
panic "fromByronGenesisHash: old and new crypto libs disagree on hash size"
error "fromByronGenesisHash: old and new crypto libs disagree on hash size"



Expand Down
5 changes: 3 additions & 2 deletions cardano-node/src/Cardano/Node/Queries.hs
Expand Up @@ -36,12 +36,13 @@ module Cardano.Node.Queries
, fromSMaybe
) where

import Cardano.Prelude hiding (All, (:.:))

import Control.Monad.STM (atomically)
import Data.ByteString (ByteString)
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import qualified Data.Map.Strict as Map
import Data.SOP.Strict
import qualified Data.UMap as UM
import Data.Word (Word64)

import qualified Cardano.Chain.Block as Byron
import qualified Cardano.Chain.UTxO as Byron
Expand Down
4 changes: 0 additions & 4 deletions cardano-node/src/Cardano/Node/STM.hs
Expand Up @@ -7,10 +7,6 @@ module Cardano.Node.STM
, modifyReadTVarIO'
) where

import Data.Function
import Control.Monad
import System.IO (IO)

import qualified Control.Concurrent.STM as STM

-- | Mutate the contents of a TVar and return the new value of the TVar (non-strict).
Expand Down
13 changes: 7 additions & 6 deletions cardano-node/src/Cardano/Node/Tracing/Era/Byron.hs
Expand Up @@ -16,9 +16,9 @@ module Cardano.Node.Tracing.Era.Byron () where
import Cardano.Tracing.OrphanInstances.Byron ()

import Cardano.Logging
import Cardano.Prelude
import Data.Aeson (Value (String), (.=))

import Data.Aeson (Value (String), (.=))
import Data.ByteString (ByteString)
import qualified Data.Set as Set
import qualified Data.Text as Text

Expand All @@ -32,6 +32,7 @@ import Ouroboros.Consensus.Byron.Ledger.Inspect (ByronLedgerUpdate (..
import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx, txId)
import Ouroboros.Consensus.Util.Condense (condense)

import Cardano.Api (textShow)
import Cardano.Chain.Block (ABlockOrBoundaryHdr (..), AHeader (..),
ChainValidationError (..), delegationCertificate)
import Cardano.Chain.Byron.API (ApplyMempoolPayloadErr (..))
Expand All @@ -49,22 +50,22 @@ instance LogFormatting ApplyMempoolPayloadErr where
forMachine _dtal (MempoolTxErr utxoValidationErr) =
mconcat
[ "kind" .= String "MempoolTxErr"
, "error" .= String (show utxoValidationErr)
, "error" .= String (textShow utxoValidationErr)
]
forMachine _dtal (MempoolDlgErr delegScheduleError) =
mconcat
[ "kind" .= String "MempoolDlgErr"
, "error" .= String (show delegScheduleError)
, "error" .= String (textShow delegScheduleError)
]
forMachine _dtal (MempoolUpdateProposalErr iFaceErr) =
mconcat
[ "kind" .= String "MempoolUpdateProposalErr"
, "error" .= String (show iFaceErr)
, "error" .= String (textShow iFaceErr)
]
forMachine _dtal (MempoolUpdateVoteErr iFaceErrr) =
mconcat
[ "kind" .= String "MempoolUpdateVoteErr"
, "error" .= String (show iFaceErrr)
, "error" .= String (textShow iFaceErrr)
]

instance LogFormatting ByronLedgerUpdate where
Expand Down
2 changes: 0 additions & 2 deletions cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs
Expand Up @@ -15,8 +15,6 @@
module Cardano.Node.Tracing.Era.HardFork ()
where

import Cardano.Prelude hiding (All)

import Cardano.Tracing.OrphanInstances.HardFork ()

import Data.Aeson
Expand Down
14 changes: 7 additions & 7 deletions cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs
Expand Up @@ -19,7 +19,9 @@ import Data.Aeson (ToJSON (..), Value (..), (.=))
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Key as Aeson
import qualified Data.Aeson.Types as Aeson
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)

import Cardano.Api (textShow)
import qualified Cardano.Api as Api
Expand All @@ -28,7 +30,6 @@ import qualified Cardano.Api.Shelley as Api
import qualified Cardano.Crypto.Hash.Class as Crypto
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Logging
import Cardano.Prelude
import Cardano.Slotting.Block (BlockNo (..))

import Ouroboros.Network.Block (SlotNo (..), blockHash, blockNo, blockSlot)
Expand Down Expand Up @@ -146,7 +147,6 @@ instance Core.Crypto era => LogFormatting (TPraosCannotForge era) where
]



instance ( ShelleyBasedEra era
, LogFormatting (PredicateFailure (ShelleyUTXO era))
, LogFormatting (PredicateFailure (ShelleyUTXOW era))
Expand Down Expand Up @@ -514,7 +514,7 @@ renderBadInputsUTxOErr txIns

renderValueNotConservedErr :: Show val => val -> val -> Value
renderValueNotConservedErr consumed produced = String $
"This transaction consumed " <> show consumed <> " but produced " <> show produced
"This transaction consumed " <> textShow consumed <> " but produced " <> textShow produced

instance Core.Crypto (Ledger.Crypto era) => LogFormatting (ShelleyPpupPredFailure era) where
forMachine _dtal (NonGenesisUpdatePPUP proposalKeys genesisKeys) =
Expand All @@ -524,7 +524,7 @@ instance Core.Crypto (Ledger.Crypto era) => LogFormatting (ShelleyPpupPredFailur
mconcat [ "kind" .= String "PPUpdateWrongEpoch"
, "currentEpoch" .= currEpoch
, "intendedEpoch" .= intendedEpoch
, "votingPeriod" .= String (show votingPeriod)
, "votingPeriod" .= String (textShow votingPeriod)
]
forMachine _dtal (PVCannotFollowPPUP badPv) =
mconcat [ "kind" .= String "PVCannotFollowPPUP"
Expand Down Expand Up @@ -700,7 +700,7 @@ instance ( LogFormatting (PredicateFailure (Core.EraRule "EPOCH" era))
forMachine dtal (MirFailure f) = forMachine dtal f
forMachine _dtal (CorruptRewardUpdate update) =
mconcat [ "kind" .= String "CorruptRewardUpdate"
, "update" .= String (show update) ]
, "update" .= String (textShow update) ]


instance ( LogFormatting (PredicateFailure (Core.EraRule "POOLREAP" era))
Expand Down Expand Up @@ -965,7 +965,7 @@ instance ( Ledger.Era era
, Show (PredicateFailure (Ledger.EraRule "LEDGERS" era))
) => LogFormatting (AlonzoBbodyPredFailure era) where
forMachine _ err = mconcat [ "kind" .= String "AlonzoBbodyPredFail"
, "error" .= String (show err)
, "error" .= String (textShow err)
]
--------------------------------------------------------------------------------
-- Babbage related
Expand Down Expand Up @@ -1034,7 +1034,7 @@ instance Core.Crypto crypto => LogFormatting (Praos.PraosValidationErr crypto) w
mconcat [ "kind" .= String "VRFKeyBadProof"
, "slotNumberUsedInVrfCalculation" .= slotNo
, "nonceUsedInVrfCalculation" .= nonce
, "calculatedVrfValue" .= String (show vrfCalculatedVal)
, "calculatedVrfValue" .= String (textShow vrfCalculatedVal)
]
Praos.VRFLeaderValueTooBig leaderValue sigma f->
mconcat [ "kind" .= String "VRFLeaderValueTooBig"
Expand Down
3 changes: 2 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Peers.hs
Expand Up @@ -7,6 +7,7 @@ module Cardano.Node.Tracing.Peers
) where

import Cardano.Prelude

import Data.Aeson (FromJSON, ToJSON)

import Cardano.Logging
Expand Down Expand Up @@ -41,4 +42,4 @@ traceNodePeers
:: Trace IO NodePeers
-> [PeerT blk]
-> IO ()
traceNodePeers tr ev = traceWith tr $ NodePeers (map ppPeer ev)
traceNodePeers tr ev = traceWith tr $ NodePeers (fmap ppPeer ev)
8 changes: 6 additions & 2 deletions cardano-node/src/Cardano/Node/Tracing/StateRep.hs
Expand Up @@ -19,11 +19,15 @@ module Cardano.Node.Tracing.StateRep
, traceNodeStateShutdown
) where

import Cardano.Api (textShow)

import Cardano.Logging
import Cardano.Prelude

import Data.Aeson
import Data.Text (Text)
import Data.Time.Clock
import Data.Time.Clock.POSIX
import GHC.Generics (Generic)

import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..))
import qualified Ouroboros.Consensus.Block.RealPoint as RP
Expand Down Expand Up @@ -244,7 +248,7 @@ traceNodeStateStartup
traceNodeStateStartup tr ev =
case ev of
Startup.StartupSocketConfigError e ->
traceWith tr $ NodeStartup $ StartupSocketConfigError (show e)
traceWith tr $ NodeStartup $ StartupSocketConfigError (textShow e)
Startup.StartupDBValidation ->
traceWith tr $ NodeStartup StartupDBValidation
Startup.NetworkConfigUpdate ->
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers.hs
Expand Up @@ -13,9 +13,9 @@ module Cardano.Node.Tracing.Tracers
) where

import Codec.CBOR.Read (DeserialiseFailure)
import Data.Proxy (Proxy (..))

import Cardano.Logging
import Cardano.Prelude hiding (trace)

import Cardano.Node.Tracing.Formatting ()
import Cardano.Node.Tracing.Tracers.BlockReplayProgress
Expand Down
Expand Up @@ -5,11 +5,13 @@ module Cardano.Node.Tracing.Tracers.BlockReplayProgress
, ReplayBlockStats(..)
) where

import Control.Monad.IO.Class (MonadIO)
import Data.Aeson (Value (String), (.=))
import Data.Text (pack)

import Cardano.Api (textShow)

import Cardano.Logging
import Cardano.Prelude

import Ouroboros.Consensus.Block (realPointSlot)
import Ouroboros.Network.Block (pointSlot, unSlotNo)
Expand Down Expand Up @@ -37,7 +39,7 @@ instance LogFormatting ReplayBlockStats where
[ "kind" .= String "ReplayBlockStats"
, "progress" .= String (pack $ show rpsProgress)
]
forHuman ReplayBlockStats {..} = "Block replay progress " <> show rpsProgress <> "%"
forHuman ReplayBlockStats {..} = "Block replay progress " <> textShow rpsProgress <> "%"
asMetrics ReplayBlockStats {..} =
[DoubleM "ChainDB.BlockReplayProgress" rpsProgress]

Expand Down

0 comments on commit 6d755f3

Please sign in to comment.