Skip to content

Commit

Permalink
Reformatting with fourmolu 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrange committed May 9, 2023
1 parent d31738a commit 653d6b2
Show file tree
Hide file tree
Showing 28 changed files with 246 additions and 238 deletions.
26 changes: 13 additions & 13 deletions hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import Hydra.Prelude
import Test.Hydra.Prelude

import CardanoNode (RunningNode (..), withCardanoNodeDevnet)
import Control.Lens (to, (^?))
import Control.Monad.Class.MonadAsync (mapConcurrently)
import Control.Concurrent.Class.MonadSTM (
MonadSTM (readTVarIO),
check,
Expand All @@ -20,6 +18,8 @@ import Control.Concurrent.Class.MonadSTM (
tryReadTBQueue,
writeTBQueue,
)
import Control.Lens (to, (^?))
import Control.Monad.Class.MonadAsync (mapConcurrently)
import Data.Aeson (Result (Error, Success), Value, encode, fromJSON, (.=))
import Data.Aeson.Lens (key, _Array, _JSON, _Number, _String)
import qualified Data.List as List
Expand Down Expand Up @@ -363,18 +363,18 @@ waitForAllConfirmations n1 Registry{processedTxs} submissionQ allIds = do
where
go remainingIds
| Set.null remainingIds = do
putStrLn "All transactions confirmed. Sweet!"
putStrLn "All transactions confirmed. Sweet!"
| otherwise = do
waitForSnapshotConfirmation >>= \case
TxValid{transaction} -> do
validTx processedTxs (txId transaction)
go remainingIds
TxInvalid{transaction} -> do
atomically $ writeTBQueue submissionQ transaction
go remainingIds
SnapshotConfirmed{transactions} -> do
confirmedIds <- mapM (confirmTx processedTxs) transactions
go $ remainingIds \\ Set.fromList confirmedIds
waitForSnapshotConfirmation >>= \case
TxValid{transaction} -> do
validTx processedTxs (txId transaction)
go remainingIds
TxInvalid{transaction} -> do
atomically $ writeTBQueue submissionQ transaction
go remainingIds
SnapshotConfirmed{transactions} -> do
confirmedIds <- mapM (confirmTx processedTxs) transactions
go $ remainingIds \\ Set.fromList confirmedIds

waitForSnapshotConfirmation = waitMatch 20 n1 $ \v ->
maybeTxValid v <|> maybeTxInvalid v <|> maybeSnapshotConfirmed v
Expand Down
46 changes: 23 additions & 23 deletions hydra-cluster/bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,29 @@ benchOptionsParser =
\ populated with new transactions and UTxO set."
)
)
<*> option
auto
( long "scaling-factor"
<> value 100
<> metavar "INT"
<> help "The scaling factor to apply to transactions generator (default: 100)"
)
<*> option
auto
( long "timeout"
<> value 600.0
<> metavar "SECONDS"
<> help
"The timeout for the run, in seconds (default: '600s')"
)
<*> option
auto
( long "cluster-size"
<> value 3
<> metavar "INT"
<> help
"The number of Hydra nodes to start and connect (default: 3)"
)
<*> option
auto
( long "scaling-factor"
<> value 100
<> metavar "INT"
<> help "The scaling factor to apply to transactions generator (default: 100)"
)
<*> option
auto
( long "timeout"
<> value 600.0
<> metavar "SECONDS"
<> help
"The timeout for the run, in seconds (default: '600s')"
)
<*> option
auto
( long "cluster-size"
<> value 3
<> metavar "INT"
<> help
"The number of Hydra nodes to start and connect (default: 3)"
)

benchOptions :: ParserInfo Options
benchOptions =
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/exe/hydra-cluster/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Main where

import Hydra.Prelude

import CardanoNode (withCardanoNodeOnKnownNetwork, withCardanoNodeDevnet)
import CardanoNode (withCardanoNodeDevnet, withCardanoNodeOnKnownNetwork)
import Hydra.Cluster.Faucet (publishHydraScriptsAs)
import Hydra.Cluster.Fixture (Actor (Faucet))
import Hydra.Cluster.Options (Options (..), PublishOrReuse (Publish, Reuse), parseOptions)
Expand Down
46 changes: 23 additions & 23 deletions hydra-cluster/src/CardanoNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ data RunningNode = RunningNode

-- | Configuration parameters for a single node devnet
data DevnetConfig = DevnetConfig
{ -- | Parent state directory
stateDirectory :: FilePath
, -- | Blockchain start time
systemStart :: UTCTime
, -- | A list of port
ports :: PortsConfig
{ stateDirectory :: FilePath
-- ^ Parent state directory
, systemStart :: UTCTime
-- ^ Blockchain start time
, ports :: PortsConfig
-- ^ A list of port
}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
Expand Down Expand Up @@ -98,10 +98,10 @@ defaultCardanoNodeArgs =
-- | Configuration of ports from the perspective of a peer in the context of a
-- fully sockected topology.
data PortsConfig = PortsConfig
{ -- | Our node TCP port.
ours :: Port
, -- | Other peers TCP ports.
peers :: [Port]
{ ours :: Port
-- ^ Our node TCP port.
, peers :: [Port]
-- ^ Other peers TCP ports.
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)
Expand Down Expand Up @@ -315,19 +315,19 @@ cardanoNodeProcess cwd args =
} = args

strArgs =
"run" :
mconcat
[ ["--config", nodeConfigFile]
, ["--topology", nodeTopologyFile]
, ["--database-path", nodeDatabaseDir]
, ["--socket-path", nodeSocket]
, opt "--port" (show <$> nodePort)
, opt "--byron-signing-key" nodeSignKeyFile
, opt "--byron-delegation-certificate" nodeDlgCertFile
, opt "--shelley-operational-certificate" nodeOpCertFile
, opt "--shelley-kes-key" nodeKesKeyFile
, opt "--shelley-vrf-key" nodeVrfKeyFile
]
"run"
: mconcat
[ ["--config", nodeConfigFile]
, ["--topology", nodeTopologyFile]
, ["--database-path", nodeDatabaseDir]
, ["--socket-path", nodeSocket]
, opt "--port" (show <$> nodePort)
, opt "--byron-signing-key" nodeSignKeyFile
, opt "--byron-delegation-certificate" nodeDlgCertFile
, opt "--shelley-operational-certificate" nodeOpCertFile
, opt "--shelley-kes-key" nodeKesKeyFile
, opt "--shelley-vrf-key" nodeVrfKeyFile
]

opt :: a -> Maybe a -> [a]
opt arg = \case
Expand Down
17 changes: 9 additions & 8 deletions hydra-cluster/src/Hydra/Cluster/Faucet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ seedFromFaucet RunningNode{networkId, nodeSocket} receivingVerificationKey lovel
faucetUTxO <- queryUTxO networkId nodeSocket QueryTip [buildAddress faucetVk networkId]
let foundUTxO = UTxO.filter (\o -> txOutLovelace o >= lovelace) faucetUTxO
when (null foundUTxO) $
throwIO $ FaucetHasNotEnoughFunds{faucetUTxO}
throwIO $
FaucetHasNotEnoughFunds{faucetUTxO}
pure foundUTxO

receivingAddress = buildAddress receivingVerificationKey networkId
Expand Down Expand Up @@ -142,13 +143,13 @@ returnFundsToFaucet tracer node@RunningNode{networkId, nodeSocket} sender = do
-- | Build and sign tx and return the calculated fee.
-- - Signing key should be the key of a sender
-- - Address is used as a change address.
calculateTxFee
:: RunningNode
-> SigningKey PaymentKey
-> UTxO
-> AddressInEra
-> Lovelace
-> IO Lovelace
calculateTxFee ::
RunningNode ->
SigningKey PaymentKey ->
UTxO ->
AddressInEra ->
Lovelace ->
IO Lovelace
calculateTxFee RunningNode{networkId, nodeSocket} secretKey utxo addr lovelace =
let theOutput = TxOut addr (lovelaceToValue lovelace) TxOutDatumNone ReferenceScriptNone
in buildTransaction networkId nodeSocket addr utxo [] [theOutput] >>= \case
Expand Down
8 changes: 5 additions & 3 deletions hydra-cluster/src/Hydra/Cluster/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import Test.Hydra.Prelude (failure)
-- package's data path.
readConfigFile :: FilePath -> IO ByteString
readConfigFile source = do
filename <- lookupEnv "HYDRA_CONFIG_DIR" >>=
maybe (Pkg.getDataFileName ("config" </> source)) (pure . (</> source))
filename <-
lookupEnv "HYDRA_CONFIG_DIR"
>>= maybe (Pkg.getDataFileName ("config" </> source)) (pure . (</> source))
BS.readFile filename

-- | Get the "well-known" keys for given actor.
Expand All @@ -49,7 +50,8 @@ keysFor actor = do
chainConfigFor :: HasCallStack => Actor -> FilePath -> FilePath -> [Actor] -> ContestationPeriod -> IO ChainConfig
chainConfigFor me targetDir nodeSocket them cp = do
when (me `elem` them) $
failure $ show me <> " must not be in " <> show them
failure $
show me <> " must not be in " <> show them
readConfigFile ("credentials" </> skName me) >>= writeFileBS (skTarget me)
readConfigFile ("credentials" </> vkName me) >>= writeFileBS (vkTarget me)
forM_ them $ \actor ->
Expand Down
15 changes: 8 additions & 7 deletions hydra-cluster/test/Test/DirectChainSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ spec = around showLogsOnFailure $ do
_ -> Nothing
now <- getCurrentTime
unless (deadline > now) $
failure $ "contestationDeadline in the past: " <> show deadline <> ", now: " <> show now
failure $
"contestationDeadline in the past: " <> show deadline <> ", now: " <> show now
delayUntil deadline

waitMatch aliceChain $ \case
Expand Down Expand Up @@ -329,12 +330,12 @@ spec = around showLogsOnFailure $ do
readCreateProcess
( proc
"hydra-node"
( "publish-scripts" :
mconcat
[ ["--node-socket", nodeSocket]
, toArgNetworkId networkId
, ["--cardano-signing-key", cardanoSigningKey]
]
( "publish-scripts"
: mconcat
[ ["--node-socket", nodeSocket]
, toArgNetworkId networkId
, ["--cardano-signing-key", cardanoSigningKey]
]
)
)
""
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/API/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ instance Arbitrary APIServerLog where

-- | Handle to provide a means for sending server outputs to clients.
newtype Server tx m = Server
{ -- | Send some output to all connected clients.
sendOutput :: ServerOutput tx -> m ()
{ sendOutput :: ServerOutput tx -> m ()
-- ^ Send some output to all connected clients.
}

-- | Callback for receiving client inputs.
Expand Down
12 changes: 6 additions & 6 deletions hydra-node/src/Hydra/API/ServerOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ data ServerOutput tx
| HeadIsClosed
{ headId :: HeadId
, snapshotNumber :: SnapshotNumber
, -- | Nominal deadline until which contest can be submitted and after
-- which fanout is possible. NOTE: Use this only for informational
-- purpose and wait for 'ReadyToFanout' instead before sending 'Fanout'
-- as the ledger of our cardano-node might not have progressed
-- sufficiently in time yet and we do not re-submit transactions (yet).
contestationDeadline :: UTCTime
, contestationDeadline :: UTCTime
-- ^ Nominal deadline until which contest can be submitted and after
-- which fanout is possible. NOTE: Use this only for informational
-- purpose and wait for 'ReadyToFanout' instead before sending 'Fanout'
-- as the ledger of our cardano-node might not have progressed
-- sufficiently in time yet and we do not re-submit transactions (yet).
}
| HeadIsContested {headId :: HeadId, snapshotNumber :: SnapshotNumber}
| ReadyToFanout {headId :: HeadId}
Expand Down
16 changes: 8 additions & 8 deletions hydra-node/src/Hydra/Chain/Direct/TimeHandle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import Test.QuickCheck (getPositive)
type PointInTime = (SlotNo, UTCTime)

data TimeHandle = TimeHandle
{ -- | Get the current 'PointInTime'
currentPointInTime :: Either Text PointInTime
, -- | Lookup slot number given a 'UTCTime'. This will fail if the time is
-- outside the "safe zone".
slotFromUTCTime :: UTCTime -> Either Text SlotNo
, -- | Convert a slot number to a 'UTCTime' using the stored epoch info. This
-- will fail if the slot is outside the "safe zone".
slotToUTCTime :: SlotNo -> Either Text UTCTime
{ currentPointInTime :: Either Text PointInTime
-- ^ Get the current 'PointInTime'
, slotFromUTCTime :: UTCTime -> Either Text SlotNo
-- ^ Lookup slot number given a 'UTCTime'. This will fail if the time is
-- outside the "safe zone".
, slotToUTCTime :: SlotNo -> Either Text UTCTime
-- ^ Convert a slot number to a 'UTCTime' using the stored epoch info. This
-- will fail if the slot is outside the "safe zone".
}

data TimeHandleParams = TimeHandleParams
Expand Down
Loading

0 comments on commit 653d6b2

Please sign in to comment.