Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX some code format with fourmolu #539

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ unsafePaymentKeyHashFromBytes ::
Hash PaymentKey
unsafePaymentKeyHashFromBytes bytes
| BS.length bytes /= 28 =
error $ "unsafePaymentKeyHashFromBytes: pre-condition failed: " <> show (BS.length bytes) <> " bytes."
error $ "unsafePaymentKeyHashFromBytes: pre-condition failed: " <> show (BS.length bytes) <> " bytes."
| otherwise =
PaymentKeyHash $ Ledger.KeyHash $ unsafeHashFromBytes bytes
PaymentKeyHash $ Ledger.KeyHash $ unsafeHashFromBytes bytes

-- | Unsafe wrap some bytes as a 'ScriptHash', relying on the fact that Plutus
-- is using Blake2b_224 for hashing data (according to 'cardano-ledger').
Expand All @@ -42,11 +42,11 @@ unsafeScriptHashFromBytes ::
ScriptHash
unsafeScriptHashFromBytes bytes
| BS.length bytes /= 28 =
error $ "unsafeScriptHashFromBytes: pre-condition failed: " <> show (BS.length bytes) <> " bytes."
error $ "unsafeScriptHashFromBytes: pre-condition failed: " <> show (BS.length bytes) <> " bytes."
| otherwise =
fromShelleyScriptHash
. Ledger.ScriptHash
$ unsafeHashFromBytes bytes
fromShelleyScriptHash
. Ledger.ScriptHash
$ unsafeHashFromBytes bytes

-- | Unsafe wrap some bytes as a 'Hash ScriptData', relying on the fact that
-- Plutus is using Blake2b_256 for hashing data (according to 'cardano-ledger').
Expand All @@ -58,11 +58,11 @@ unsafeScriptDataHashFromBytes ::
Hash ScriptData
unsafeScriptDataHashFromBytes bytes
| BS.length bytes /= 32 =
error $ "unsafeScriptDataHashFromBytes: pre-condition failed: " <> show (BS.length bytes) <> " bytes."
error $ "unsafeScriptDataHashFromBytes: pre-condition failed: " <> show (BS.length bytes) <> " bytes."
| otherwise =
ScriptDataHash
. unsafeMakeSafeHash
$ unsafeHashFromBytes bytes
ScriptDataHash
. unsafeMakeSafeHash
$ unsafeHashFromBytes bytes

-- NOTE: The constructor for Hash isn't exposed in the cardano-api. Although
-- there's a 'CastHash' type-class, there are not instances for everything, so
Expand Down
22 changes: 11 additions & 11 deletions hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,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
20 changes: 10 additions & 10 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
4 changes: 2 additions & 2 deletions hydra-node/exe/hydra-node/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import Hydra.Node (
createEventQueue,
createHydraNode,
initEnvironment,
runHydraNode
runHydraNode,
)
import Hydra.Options (
ChainConfig (..),
Command (Publish, Run),
LedgerConfig (..),
RunOptions (..),
PublishOptions (..),
RunOptions (..),
parseHydraCommand,
)
import Hydra.Party (Party)
Expand Down
6 changes: 3 additions & 3 deletions hydra-node/src/Hydra/API/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import Control.Concurrent.STM.TVar (TVar, modifyTVar', newTVarIO, readTVar)
import Control.Exception (IOException)
import qualified Data.Aeson as Aeson
import Hydra.API.ClientInput (ClientInput)
import Hydra.API.ServerOutput (ServerOutput (Greetings, InvalidInput))
import Hydra.Ledger (IsTx (..))
import Hydra.Logging (Tracer, traceWith)
import Hydra.Network (IP, PortNumber)
import Hydra.Party (Party)
import Hydra.API.ServerOutput (ServerOutput (Greetings, InvalidInput))
import Network.WebSockets (
acceptRequest,
receiveData,
Expand Down Expand Up @@ -54,8 +54,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 @@ -19,12 +19,12 @@ data ServerOutput tx
| HeadIsOpen {utxo :: UTxOType tx}
| HeadIsClosed
{ 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 {snapshotNumber :: SnapshotNumber}
| ReadyToFanout
Expand Down
16 changes: 8 additions & 8 deletions hydra-node/src/Hydra/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ instance IsTx tx => Arbitrary (PostTxError tx) where

-- | Handle to interface with the main chain network
newtype Chain tx m = Chain
{ -- | Construct and send a transaction to the main chain corresponding to the
-- given 'OnChainTx' event. This function is not expected to block, so it is
-- only responsible for submitting, but it should validate the created
-- transaction against a reasonable local view of the chain and throw an
-- exception when invalid.
--
-- Does at least throw 'PostTxError'.
postTx :: MonadThrow m => PostChainTx tx -> m ()
{ postTx :: MonadThrow m => PostChainTx tx -> m ()
-- ^ Construct and send a transaction to the main chain corresponding to the
-- given 'OnChainTx' event. This function is not expected to block, so it is
-- only responsible for submitting, but it should validate the created
-- transaction against a reasonable local view of the chain and throw an
-- exception when invalid.
--
-- Does at least throw 'PostTxError'.
}

data ChainEvent tx
Expand Down
26 changes: 13 additions & 13 deletions hydra-node/src/Hydra/Chain/Direct/TimeHandle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ import Hydra.Chain.CardanoClient (
querySystemStart,
queryTip,
)
import Hydra.Ledger.Cardano.Evaluate (eraHistoryWithHorizonAt)
import Ouroboros.Consensus.HardFork.History.Qry (interpretQuery, slotToWallclock, wallclockToSlot)
import Test.QuickCheck (getPositive)
import Hydra.Ledger.Cardano.Evaluate (eraHistoryWithHorizonAt)

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
, -- | Adjust a 'PointInTime' by some number of slots, positively or
-- negatively.
adjustPointInTime :: SlotNo -> PointInTime -> Either Text PointInTime
{ 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".
, adjustPointInTime :: SlotNo -> PointInTime -> Either Text PointInTime
-- ^ Adjust a 'PointInTime' by some number of slots, positively or
-- negatively.
}

-- | Generate consistent values for 'SystemStart' and 'EraHistory' which has
Expand All @@ -48,7 +48,7 @@ genTimeParams = do
uptimeSeconds <- getPositive <$> arbitrary
let uptime = secondsToNominalDiffTime uptimeSeconds
currentTime = addUTCTime uptime startTime
-- formula: 3 * k / f where k = securityParam and f = slotLength from the genesis config
-- formula: 3 * k / f where k = securityParam and f = slotLength from the genesis config
safeZone = 3 * 2160 / 0.05
horizonSlot = SlotNo $ truncate $ uptimeSeconds + safeZone
pure (SystemStart startTime, eraHistoryWithHorizonAt horizonSlot, horizonSlot, currentTime)
Expand Down
32 changes: 16 additions & 16 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ abortTx ::
Either AbortTxError Tx
abortTx scriptRegistry vk (headInput, initialHeadOutput, ScriptDatumForTxIn -> headDatumBefore) headTokenScript initialsToAbort commitsToAbort
| isJust (lookup headInput initialsToAbort) =
Left OverlappingInputs
Left OverlappingInputs
| otherwise =
Right $
unsafeBuildTransaction $
emptyTxBody
& addInputs ((headInput, headWitness) : initialInputs <> commitInputs)
& addReferenceInputs [initialScriptRef, commitScriptRef]
& addOutputs reimbursedOutputs
& burnTokens headTokenScript Burn headTokens
& addExtraRequiredSigners [verificationKeyHash vk]
Right $
unsafeBuildTransaction $
emptyTxBody
& addInputs ((headInput, headWitness) : initialInputs <> commitInputs)
& addReferenceInputs [initialScriptRef, commitScriptRef]
& addOutputs reimbursedOutputs
& burnTokens headTokenScript Burn headTokens
& addExtraRequiredSigners [verificationKeyHash vk]
where
headWitness =
BuildTxWith $ ScriptWitness scriptWitnessCtx $ mkScriptWitness headScript headDatumBefore headRedeemer
Expand Down Expand Up @@ -523,12 +523,12 @@ abortTx scriptRegistry vk (headInput, initialHeadOutput, ScriptDatumForTxIn -> h
-- * Observe Hydra Head transactions

data InitObservation = InitObservation
{ -- | The state machine UTxO produced by the Init transaction
-- This output should always be present and 'threaded' across all
-- transactions.
-- NOTE(SN): The Head's identifier is somewhat encoded in the TxOut's address
-- XXX(SN): Data and [OnChain.Party] are overlapping
threadOutput :: InitialThreadOutput
{ threadOutput :: InitialThreadOutput
-- ^ The state machine UTxO produced by the Init transaction
-- This output should always be present and 'threaded' across all
-- transactions.
-- NOTE(SN): The Head's identifier is somewhat encoded in the TxOut's address
-- XXX(SN): Data and [OnChain.Party] are overlapping
, initials :: [UTxOWithScript]
, commits :: [UTxOWithScript]
, headId :: HeadId
Expand Down Expand Up @@ -874,7 +874,7 @@ findHeadAssetId txOut =
flip findFirst (valueToList $ txOutValue txOut) $ \case
(AssetId pid aname, q)
| aname == hydraHeadV1AssetName && q == 1 ->
Just (pid, aname)
Just (pid, aname)
_ ->
Nothing

Expand Down
26 changes: 13 additions & 13 deletions hydra-node/src/Hydra/Chain/Direct/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ type TxOut = Ledger.TxOut LedgerEra
-- 'reset'. Otherwise it can be fed blocks via 'update' as the chain rolls
-- forward.
data TinyWallet m = TinyWallet
{ -- | Return all known UTxO addressed to this wallet.
getUTxO :: STM m (Map TxIn TxOut)
{ getUTxO :: STM m (Map TxIn TxOut)
-- ^ Return all known UTxO addressed to this wallet.
, sign :: ValidatedTx LedgerEra -> ValidatedTx LedgerEra
, coverFee :: Map TxIn TxOut -> ValidatedTx LedgerEra -> STM m (Either ErrCoverFee (ValidatedTx LedgerEra))
, -- | Reset the wallet state to some point.
reset :: QueryPoint -> m ()
, -- | Update the wallet state given some 'Block'.
update :: Block -> m ()
, reset :: QueryPoint -> m ()
-- ^ Reset the wallet state to some point.
, update :: Block -> m ()
-- ^ Update the wallet state given some 'Block'.
}

type ChainQuery m =
Expand Down Expand Up @@ -292,13 +292,13 @@ coverFee_ pparams systemStart epochInfo lookupUTxO walletUTxO partialTx@Validate
mkChange (Ledger.Babbage.TxOut addr _ datum _) resolvedInputs otherOutputs fee
-- FIXME: The delta between in and out must be greater than the min utxo value!
| totalIn <= totalOut =
Left $
ChangeError
{ inputBalance = totalIn
, outputBalance = totalOut
}
Left $
ChangeError
{ inputBalance = totalIn
, outputBalance = totalOut
}
| otherwise =
Right $ Ledger.Babbage.TxOut addr (inject changeOut) datum refScript
Right $ Ledger.Babbage.TxOut addr (inject changeOut) datum refScript
where
totalOut = foldMap getAdaValue otherOutputs <> fee
totalIn = foldMap getAdaValue resolvedInputs
Expand All @@ -317,7 +317,7 @@ coverFee_ pparams systemStart epochInfo lookupUTxO walletUTxO partialTx@Validate
case ptr of
RdmrPtr Spend idx
| fromIntegral idx `elem` differences ->
(RdmrPtr Spend (idx + 1), (d, executionUnitsFor ptr))
(RdmrPtr Spend (idx + 1), (d, executionUnitsFor ptr))
_ ->
(ptr, (d, executionUnitsFor ptr))

Expand Down
Loading