Skip to content

Commit 184fcff

Browse files
committed
Rebase
Signed-off-by: Sasha Bogicevic <[email protected]>
1 parent 1fccdb0 commit 184fcff

File tree

12 files changed

+75
-149
lines changed

12 files changed

+75
-149
lines changed

hydra-cluster/src/Hydra/Cluster/Fixture.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ cperiod = UnsafeContestationPeriod 10
3232
blockfrostcperiod :: ContestationPeriod
3333
blockfrostcperiod = UnsafeContestationPeriod 200
3434

35-
ddeadline :: DepositDeadline
36-
ddeadline = UnsafeDepositDeadline 100
37-
3835
-- NOTE: This is hard-coded and needs to correspond to the initial funds set in
3936
-- the genesis-shelley.json file.
4037
availableInitialFunds :: Num a => a

hydra-cluster/src/Hydra/Cluster/Scenarios.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ import Hydra.Ledger.Cardano (mkSimpleTx, mkTransferTx, unsafeBuildTransaction)
107107
import Hydra.Ledger.Cardano.Evaluate (maxTxExecutionUnits)
108108
import Hydra.Logging (Tracer, traceWith)
109109
import Hydra.Node.DepositPeriod (DepositPeriod (..))
110-
import Hydra.Options (CardanoChainConfig (..), ChainBackend (..), DirectBackend (..), defaultDirectBackend, startChainFrom)
110+
import Hydra.Options (CardanoChainConfig (..), ChainBackendOptions (..), DirectOptions (..), defaultDirectOptions, startChainFrom)
111111
import Hydra.Tx (HeadId, IsTx (balance), Party, txId)
112112
import Hydra.Tx.ContestationPeriod qualified as CP
113113
import Hydra.Tx.Utils (dummyValidatorScript, verificationKeyToOnChainId)
@@ -313,11 +313,11 @@ nodeReObservesOnChainTxs tracer workDir cardanoNode hydraScriptsTxId = do
313313
tip <- queryTip networkId nodeSocket
314314
let contestationPeriod = 2
315315
aliceChainConfig <-
316-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
316+
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
317317
<&> modifyConfig (\config -> config{startChainFrom = Nothing, chainBackendOptions = Direct defaultDirectOptions{networkId}})
318318

319319
bobChainConfig <-
320-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
320+
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
321321
<&> modifyConfig (\config -> config{startChainFrom = Nothing, chainBackendOptions = Direct defaultDirectOptions{networkId}})
322322

323323
(aliceCardanoVk, aliceCardanoSk) <- keysFor Alice
@@ -390,7 +390,7 @@ nodeReObservesOnChainTxs tracer workDir cardanoNode hydraScriptsTxId = do
390390
pure (headId, decommitUTxO)
391391

392392
bobChainConfigFromTip <-
393-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
393+
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
394394
<&> modifyConfig (\config -> config{startChainFrom = Just tip, chainBackendOptions = Direct defaultDirectOptions{networkId}})
395395

396396
withTempDir "blank-state" $ \tmpDir -> do
@@ -449,7 +449,7 @@ singlePartyHeadFullLifeCycle tracer workDir node hydraScriptsTxId =
449449
tip <- queryTip networkId nodeSocket
450450
contestationPeriod <- CP.fromNominalDiffTime $ 10 * blockTime
451451
aliceChainConfig <-
452-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
452+
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
453453
<&> modifyConfig (\config -> config{startChainFrom = Just tip, chainBackendOptions = Direct defaultDirectOptions{networkId}})
454454
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
455455
-- Initialize & open head
@@ -505,7 +505,7 @@ singlePartyOpenAHead tracer workDir node hydraScriptsTxId callback =
505505
tip <- queryTip networkId nodeSocket
506506
let contestationPeriod = 100
507507
aliceChainConfig <-
508-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
508+
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
509509
<&> modifyConfig (\config -> config{startChainFrom = Just tip, chainBackendOptions = Direct defaultDirectOptions{networkId}})
510510

511511
(walletVk, walletSk) <- generate genKeyPair
@@ -960,7 +960,7 @@ canCloseWithLongContestationPeriod tracer workDir node hydraScriptsTxId = do
960960
tip <- queryTip networkId nodeSocket
961961
let oneWeek = 60 * 60 * 24 * 7
962962
aliceChainConfig <-
963-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] oneWeek depositDeadline
963+
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] oneWeek
964964
<&> modifyConfig (\config -> config{startChainFrom = Just tip, chainBackendOptions = Direct defaultDirectOptions{networkId}})
965965
let hydraTracer = contramap FromHydraNode tracer
966966
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do

hydra-cluster/src/Hydra/Cluster/Util.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import Hydra.Cardano.Api (
1717
textEnvelopeToJSON,
1818
)
1919
import Hydra.Cluster.Fixture (Actor, actorName, fundsOf)
20-
import Hydra.Options (BlockfrostOptions (..), CardanoChainConfig (..), ChainBackendOptions (..), ChainConfig (..), DirectOptions (..), defaultCardanoChainConfig, defaultDirectOptions)
20+
import Hydra.Node.DepositPeriod (DepositPeriod)
21+
import Hydra.Options (BlockfrostOptions (..), CardanoChainConfig (..), ChainBackendOptions (..), ChainConfig (..), DirectOptions (..), defaultCardanoChainConfig, defaultDepositPeriod, defaultDirectOptions)
2122
import Hydra.Tx.ContestationPeriod (ContestationPeriod)
2223
import Paths_hydra_cluster qualified as Pkg
2324
import System.FilePath ((<.>), (</>))
@@ -66,7 +67,7 @@ chainConfigFor ::
6667
[Actor] ->
6768
ContestationPeriod ->
6869
IO ChainConfig
69-
chainConfigFor me targetDir nodeSocket = chainConfigFor' me targetDir (Right nodeSocket)
70+
chainConfigFor me targetDir nodeSocket txids actors cp = chainConfigFor' me targetDir (Right nodeSocket) txids actors cp defaultDepositPeriod
7071

7172
chainConfigFor' ::
7273
HasCallStack =>
@@ -77,9 +78,9 @@ chainConfigFor' ::
7778
[TxId] ->
7879
[Actor] ->
7980
ContestationPeriod ->
80-
DepositDeadline ->
81+
DepositPeriod ->
8182
IO ChainConfig
82-
chainConfigFor' me targetDir socketOrProjectPath hydraScriptsTxId them contestationPeriod depositDeadline = do
83+
chainConfigFor' me targetDir socketOrProjectPath hydraScriptsTxId them contestationPeriod depositPeriod = do
8384
when (me `elem` them) $
8485
failure $
8586
show me <> " must not be in " <> show them
@@ -98,7 +99,7 @@ chainConfigFor' me targetDir socketOrProjectPath hydraScriptsTxId them contestat
9899
, cardanoSigningKey = actorFilePath me "sk"
99100
, cardanoVerificationKeys = [actorFilePath himOrHer "vk" | himOrHer <- them]
100101
, contestationPeriod
101-
, depositDeadline
102+
, depositPeriod
102103
, chainBackendOptions =
103104
case socketOrProjectPath of
104105
Left projectPath -> Blockfrost BlockfrostOptions{projectPath}

hydra-cluster/src/HydraNode.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ withHydraCluster tracer workDir nodeSocket firstNodeId allKeys hydraKeys hydraSc
317317
, cardanoSigningKey
318318
, cardanoVerificationKeys
319319
, contestationPeriod
320-
, depositDeadline
321320
, chainBackendOptions =
322321
Direct
323322
defaultDirectOptions

hydra-cluster/test/Test/BlockfrostChainSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import Hydra.Cluster.Fixture (
3333
alice,
3434
aliceSk,
3535
blockfrostcperiod,
36-
ddeadline,
3736
)
3837
import Hydra.Cluster.Util (chainConfigFor', keysFor)
3938
import Hydra.Ledger.Cardano (Tx)
4039
import Hydra.Logging (Tracer, showLogsOnFailure)
40+
import Hydra.Node.DepositPeriod (DepositPeriod (..))
4141
import Hydra.Options (
4242
BlockfrostOptions (..),
4343
CardanoChainConfig (..),
@@ -87,7 +87,7 @@ spec = around (showLogsOnFailure "BlockfrostChainSpec") $ do
8787
void $ Blockfrost.runBlockfrostM prj $ Blockfrost.awaitUTxO networkId [faucetAddress] (List.last hydraScriptsTxId) 100
8888

8989
-- Alice setup
90-
aliceChainConfig <- chainConfigFor' Alice tmp (Left projectPath) hydraScriptsTxId [] blockfrostcperiod ddeadline
90+
aliceChainConfig <- chainConfigFor' Alice tmp (Left projectPath) hydraScriptsTxId [] blockfrostcperiod (DepositPeriod 100)
9191

9292
withBlockfrostChainTest (contramap (FromBlockfrostChain "alice") tracer) aliceChainConfig alice $
9393
\aliceChain@CardanoChainTest{postTx} -> do

hydra-node/golden/RunOptions.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
},
1717
"tag": "Blockfrost"
1818
},
19-
"contestationPeriod": 43200,
20-
"depositDeadline": 74,
19+
"contestationPeriod": 36181,
20+
"depositPeriod": 20565,
2121
"hydraScriptsTxId": [
2222
"0e7aa6a6b04903b07ee1c14b892dd41d79fcdb8d5150b379ee395e6fccd7ac94",
2323
"678a8fe9a4d9bae4beb9f04f3514a0ac4934a30213ad0e78adc386c8a3b40b6a",
@@ -104,8 +104,8 @@
104104
},
105105
"tag": "Blockfrost"
106106
},
107-
"contestationPeriod": 14376,
108-
"depositDeadline": 50,
107+
"contestationPeriod": 604800,
108+
"depositPeriod": 77091,
109109
"hydraScriptsTxId": [
110110
"1e09c30835b4d9070d62bb8505e2106719ffbf105c23e75e4e379f6625612756",
111111
"2641215eaa36ece3f69185f5f644e1385ac059aa38be5a76a66c694e5bb7bba4",
@@ -197,8 +197,8 @@
197197
},
198198
"tag": "Direct"
199199
},
200-
"contestationPeriod": 31536000,
201-
"depositDeadline": 214,
200+
"contestationPeriod": 53328,
201+
"depositPeriod": 13685,
202202
"hydraScriptsTxId": [
203203
"9ed39761f06f5004ead6a765de1962dfa0efd70df42c6bc1e168735368af2f80",
204204
"4823f8d21a11fbd5a357b6cdb37c33699fc3bbbab64d30cc2bb9297574db21c4",
@@ -275,8 +275,8 @@
275275
},
276276
"tag": "Blockfrost"
277277
},
278-
"contestationPeriod": 604800,
279-
"depositDeadline": 116,
278+
"contestationPeriod": 86400,
279+
"depositPeriod": 73355,
280280
"hydraScriptsTxId": [
281281
"2faf8248f026c26067bc554e9b0ceb7502339b6f9eded057df4789b531362850",
282282
"e7b3193074581b48b62417594b5486c92177f85894c65c362b4f8ad56b5ab5d5",

hydra-node/hydra-node.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ library
6060
Hydra.Chain.Blockfrost.Client
6161
Hydra.Chain.CardanoClient
6262
Hydra.Chain.Direct
63-
Hydra.Chain.Blockfrost
6463
Hydra.Chain.Direct.Handlers
6564
Hydra.Chain.Direct.State
6665
Hydra.Chain.Direct.TimeHandle

hydra-node/src/Hydra/Chain/Blockfrost/Client.hs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,22 @@ import Money qualified
6868
import Ouroboros.Consensus.Block (GenesisWindow (..))
6969
import Ouroboros.Consensus.HardFork.History (Bound (..), EraEnd (..), EraParams (..), EraSummary (..), SafeZone (..), Summary (..), mkInterpreter)
7070

71-
data APIBlockfrostError
72-
= BlockfrostError Text
71+
data BlockfrostException
72+
= TimeoutOnUTxO TxId
73+
| FailedToDecodeAddress Text
74+
| ByronAddressNotSupported
75+
| FailedUTxOForHash Text
76+
| FailedEraHistory
77+
| AssetNameMissing
78+
| DeserialiseError Text
7379
| DecodeError Text
80+
| BlockfrostAPIError Text
7481
deriving (Show, Exception)
7582

83+
newtype APIBlockfrostError
84+
= BlockfrostError BlockfrostException
85+
deriving newtype (Show, Exception)
86+
7687
runBlockfrostM ::
7788
(MonadIO m, MonadThrow m) =>
7889
Blockfrost.Project ->
@@ -81,7 +92,7 @@ runBlockfrostM ::
8192
runBlockfrostM prj action = do
8293
result <- liftIO $ runBlockfrost prj action
8394
case result of
84-
Left err -> throwIO (BlockfrostError $ show err)
95+
Left err -> throwIO $ BlockfrostError $ BlockfrostAPIError (show err)
8596
Right val -> pure val
8697

8798
-- | Query for 'TxIn's in the search for outputs containing all the reference
@@ -242,7 +253,7 @@ toCardanoTxOut networkId addrTxt val mDatumHash mInlineDatum plutusScript = do
242253
case plutusScript of
243254
Nothing -> do
244255
case toCardanoAddress addrTxt of
245-
Nothing -> liftIO $ throwIO $ BlockfrostError $ "Failed to decode address: " <> addrTxt
256+
Nothing -> liftIO $ throwIO $ BlockfrostError $ FailedToDecodeAddress addrTxt
246257
Just addr -> pure $ TxOut addr val datum ReferenceScriptNone
247258
Just script -> pure $ TxOut (scriptAddr script) val datum (mkScriptRef script)
248259
where
@@ -257,13 +268,13 @@ toCardanoPolicyIdAndAssetName :: Text -> BlockfrostClientT IO (PolicyId, AssetNa
257268
toCardanoPolicyIdAndAssetName pid = do
258269
Blockfrost.AssetDetails{_assetDetailsPolicyId, _assetDetailsAssetName} <- Blockfrost.getAssetDetails (Blockfrost.mkAssetId pid)
259270
case deserialiseFromRawBytesHex (encodeUtf8 $ Blockfrost.unPolicyId _assetDetailsPolicyId) of
260-
Left err -> liftIO $ throwIO $ BlockfrostError $ show err
271+
Left err -> liftIO $ throwIO $ BlockfrostError $ DeserialiseError (show err)
261272
Right p ->
262273
case _assetDetailsAssetName of
263-
Nothing -> liftIO $ throwIO $ BlockfrostError "Asset name is missing."
274+
Nothing -> liftIO $ throwIO $ BlockfrostError AssetNameMissing
264275
Just assetName ->
265276
case deserialiseFromRawBytesHex (encodeUtf8 assetName) of
266-
Left err -> liftIO $ throwIO $ BlockfrostError $ show err
277+
Left err -> liftIO $ throwIO $ BlockfrostError $ DeserialiseError (show err)
267278
Right asset -> pure (p, asset)
268279

269280
toCardanoValue :: [Blockfrost.Amount] -> BlockfrostClientT IO Value
@@ -370,11 +381,11 @@ submitTransaction tx = Blockfrost.submitTx $ Blockfrost.CBORString $ fromStrict
370381
queryEraHistory :: BlockfrostClientT IO EraHistory
371382
queryEraHistory = do
372383
eras' <- Blockfrost.getNetworkEras
373-
let eras = filter withoutEmptyEra eras'
384+
let eras = filter isEmptyEra eras'
374385
let summary = mkEra <$> eras
375386
case nonEmptyFromList summary of
376387
Nothing ->
377-
liftIO $ throwIO $ BlockfrostError "Failed to create EraHistory."
388+
liftIO $ throwIO $ BlockfrostError FailedEraHistory
378389
Just s -> pure $ EraHistory (mkInterpreter $ Summary s)
379390
where
380391
mkBound Blockfrost.NetworkEraBound{_boundEpoch, _boundSlot, _boundTime} =
@@ -396,7 +407,7 @@ queryEraHistory = do
396407
, eraEnd = EraEnd $ mkBound _networkEraEnd
397408
, eraParams = mkEraParams _networkEraParameters
398409
}
399-
withoutEmptyEra
410+
isEmptyEra
400411
Blockfrost.NetworkEraSummary
401412
{ _networkEraStart = Blockfrost.NetworkEraBound{_boundTime = boundStart}
402413
, _networkEraEnd = Blockfrost.NetworkEraBound{_boundTime = boundEnd}
@@ -407,7 +418,7 @@ queryEraHistory = do
407418
queryUTxOByTxIn :: NetworkId -> Text -> BlockfrostClientT IO UTxO
408419
queryUTxOByTxIn networkId txHash = go (100 :: Int) -- TODO: make this configurable
409420
where
410-
go 0 = liftIO $ throwIO $ BlockfrostError $ "Failed to get UTxO for tx hash: " <> txHash
421+
go 0 = liftIO $ throwIO $ BlockfrostError $ FailedUTxOForHash txHash
411422
go n = do
412423
res <- Blockfrost.tryError $ Blockfrost.getTxUtxos (Blockfrost.TxHash txHash)
413424
case res of
@@ -468,7 +479,7 @@ queryUTxOFor vk = do
468479
ShelleyAddressInEra addr ->
469480
queryUTxO networkId [addr]
470481
ByronAddressInEra{} ->
471-
liftIO $ throwIO $ BlockfrostError "impossible: mkVkAddress returned Byron address."
482+
liftIO $ throwIO $ BlockfrostError ByronAddressNotSupported
472483

473484
-- | Query the Blockfrost API for 'Genesis'
474485
queryGenesisParameters :: BlockfrostClientT IO Blockfrost.Genesis
@@ -530,7 +541,7 @@ awaitUTxO ::
530541
awaitUTxO networkId addresses txid i = do
531542
go i
532543
where
533-
go 0 = liftIO $ throwIO $ BlockfrostError $ "Timeout waiting for UTxO from Blockfrost. Relevant txid: " <> T.pack (show txid)
544+
go 0 = liftIO $ throwIO $ BlockfrostError (TimeoutOnUTxO txid)
534545
go n = do
535546
utxo <- Blockfrost.tryError $ queryUTxO networkId addresses
536547
case utxo of

hydra-node/src/Hydra/Chain/Blockfrost/Wallet.hs

Lines changed: 0 additions & 63 deletions
This file was deleted.

hydra-node/src/Hydra/Node.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ import Hydra.Node.Environment (Environment (..))
5656
import Hydra.Node.InputQueue (InputQueue (..), Queued (..), createInputQueue)
5757
import Hydra.Node.ParameterMismatch (ParamMismatch (..), ParameterMismatch (..))
5858
import Hydra.Node.Util (readFileTextEnvelopeThrow)
59-
import Hydra.Options (CardanoChainConfig (..), ChainConfig (..), RunOptions (..), defaultContestationPeriod, defaultDepositDeadline)
59+
import Hydra.Options (CardanoChainConfig (..), ChainConfig (..), RunOptions (..), defaultContestationPeriod, defaultDepositPeriod)
6060
import Hydra.Tx (HasParty (..), HeadParameters (..), Party (..), deriveParty)
61-
import Hydra.Tx.Environment (Environment (..))
6261
import Hydra.Tx.Utils (verificationKeyToOnChainId)
6362

6463
-- * Environment Handling
@@ -96,9 +95,9 @@ initEnvironment options = do
9695
contestationPeriod = case chainConfig of
9796
Offline{} -> defaultContestationPeriod
9897
Cardano CardanoChainConfig{contestationPeriod = cp} -> cp
99-
depositDeadline = case chainConfig of
100-
Offline{} -> defaultDepositDeadline
101-
Cardano CardanoChainConfig{depositDeadline = ddeadline} -> ddeadline
98+
depositPeriod = case chainConfig of
99+
Offline{} -> defaultDepositPeriod
100+
Cardano CardanoChainConfig{depositPeriod = dp} -> dp
102101

103102
loadParty p =
104103
Party <$> readFileTextEnvelopeThrow p

0 commit comments

Comments
 (0)