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

Use cardano-api Key interface for Hydra keys #398

Merged
merged 10 commits into from
Aug 2, 2022
24 changes: 13 additions & 11 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ package plutus-merkle-tree
-- Always show detailed output for tests
test-show-details: direct

-- NOTE: master somewhere ahead of 1.35.x, but holding enough of our upstream
-- contributions to use for us
source-repository-package
type: git
location: https://github.com/abailly-iohk/cardano-node
tag: b96c6b075718b2c9e9d17761d16b7ca601937c10
--sha256: 1i3bxc12lsdr9l88l1w75844gwf43y8k6ysz5kx15pybkz1r1i5m
location: https://github.com/input-output-hk/cardano-node.git
tag: aed8e71339cf6c92847fff83fbd92be61e468174
--sha256: 1j8lkrg8xz6gjaq8grx7vc4cynlz5x6n3cd9q4y5w3kzsd89072a
subdir:
cardano-api

Expand Down Expand Up @@ -78,8 +80,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 0f3a867493059e650cda69e20a5cbf1ace289a57
--sha256: 0p0az3sbkhb7njji8xxdrfb0yx2gc8fmrh872ffm8sfip1w29gg1
tag: a3c13fb11bc41fedff7885ca70a3b33f61fef4b5
--sha256: 0h492cz9mvzbsl5yzvp3iq40c0z0j5hmrifdrnnqzzk02g9j9c4b
subdir:
base-deriving-via
binary
Expand All @@ -103,8 +105,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: ce3057e0863304ccb3f79d78c77136219dc786c6
--sha256: 19ijcy1sl1iqa7diy5nsydnjsn3281kp75i2i42qv0fpn58238s9
tag: f49879a79098d9372d63baa13b94a941a56eda34
--sha256: 0i9x66yqkrvx2w79dy6lzlya82yxc8567rgjj828vc2d46d6nvx6
subdir:
eras/alonzo/impl
eras/alonzo/test-suite
Expand Down Expand Up @@ -135,8 +137,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: bb4ed71ba8e587f672d06edf9d2e376f4b055555
--sha256: 00h10l5mmiza9819p9v5q5749nb9pzgi20vpzpy1d34zmh6gf1cj
tag: 6ea36cf2247ac0bc33e08c327abec34dfd05bd99
--sha256: 0z2y3wzppc12bpn9bl48776ms3nszw8j58xfsdxf97nzjgrmd62g
subdir:
cardano-prelude
cardano-prelude-test
Expand Down Expand Up @@ -170,8 +172,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: a65c29b6a85e90d430c7f58d362b7eb097fd4949
--sha256: 1fmab5hmi1y8lss97xh6hhikmyhsx9x31yhvg6zpr2kcq7kc6qkf
tag: c764553561bed8978d2c6753d1608dc65449617a
--sha256: 0hdh7xdrvxw943r6qr0xr4kwszindh5mnsn1lww6qdnxnmn7wcsc
subdir:
monoidal-synchronisation
network-mux
Expand Down
3 changes: 3 additions & 0 deletions hydra-cardano-api/src/Hydra/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Cardano.Api as X hiding (
AddressInEra (..),
AddressTypeInEra (..),
BalancedTxBody (..),
Key (..),
KeyWitness,
PlutusScript,
Script (..),
Expand Down Expand Up @@ -71,11 +72,13 @@ import Cardano.Api.Byron as X (
)
import Cardano.Api.Shelley as X (
Address (..),
Key (..),
PlutusScriptOrReferenceInput (PScript),
PoolId,
ProtocolParameters (..),
ShelleyGenesis (..),
ShelleyLedgerEra,
SigningKey (..),
VerificationKey (..),
fromPlutusData,
toPlutusData,
Expand Down
4 changes: 2 additions & 2 deletions hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Data.Time (UTCTime (UTCTime), nominalDiffTimeToSeconds, utctDayTime)
import Hydra.Cardano.Api (Tx, TxId, UTxO, getVerificationKey)
import Hydra.Cluster.Faucet (Marked (Fuel), seedFromFaucet)
import Hydra.Cluster.Fixture (defaultNetworkId)
import qualified Hydra.Crypto as Hydra
import Hydra.Crypto (generateSigningKey)
import Hydra.Generator (ClientDataset (..), Dataset (..))
import Hydra.Ledger (txId)
import Hydra.Logging (withTracerOutputTo)
Expand Down Expand Up @@ -78,7 +78,7 @@ bench timeoutSeconds workDir dataset@Dataset{clientDatasets} clusterSize =
failAfter timeoutSeconds $ do
putTextLn "Starting benchmark"
let cardanoKeys = map (\ClientDataset{signingKey} -> (getVerificationKey signingKey, signingKey)) clientDatasets
let hydraKeys = Hydra.generateSigningKey . show <$> [1 .. toInteger (length cardanoKeys)]
let hydraKeys = generateSigningKey . show <$> [1 .. toInteger (length cardanoKeys)]
let parties = Set.fromList (deriveParty <$> hydraKeys)
withOSStats workDir $
withCardanoNodeDevnet (contramap FromCardanoNode tracer) workDir $ \node@RunningNode{nodeSocket} -> do
Expand Down
3 changes: 2 additions & 1 deletion hydra-cluster/config/protocol-parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,6 @@
"treasuryCut": 0.1,
"txFeeFixed": 0,
"txFeePerByte": 0,
"utxoCostPerWord": 34488
"utxoCostPerWord": 34488,
"utxoCostPerByte": 4310
}
2 changes: 1 addition & 1 deletion hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: hydra-cluster
version: 0.6.0
version: 0.7.0
synopsis:
Integration test suite using a local cluster of cardano and hydra nodes

Expand Down
13 changes: 6 additions & 7 deletions hydra-cluster/src/Hydra/Cluster/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ import Hydra.Prelude
import Hydra.Cardano.Api (NetworkId)
import qualified Hydra.Cardano.Api as Api
import Hydra.ContestationPeriod (ContestationPeriod (..))
import Hydra.Crypto (deriveVerificationKey, generateSigningKey)
import qualified Hydra.Crypto as Hydra
import Hydra.Crypto (HydraKey, SigningKey, VerificationKey, generateSigningKey, getVerificationKey)
import Hydra.Party (Party, deriveParty)

alice, bob, carol :: Party
alice = deriveParty aliceSk
bob = deriveParty bobSk
carol = deriveParty carolSk

aliceSk, bobSk, carolSk :: Hydra.SigningKey
aliceSk, bobSk, carolSk :: SigningKey HydraKey
aliceSk = generateSigningKey "alice"
bobSk = generateSigningKey "bob"
carolSk = generateSigningKey "carol"

aliceVk, bobVk, carolVk :: Hydra.VerificationKey
aliceVk = deriveVerificationKey aliceSk
bobVk = deriveVerificationKey bobSk
carolVk = deriveVerificationKey carolSk
aliceVk, bobVk, carolVk :: VerificationKey HydraKey
aliceVk = getVerificationKey aliceSk
bobVk = getVerificationKey bobSk
carolVk = getVerificationKey carolSk

cperiod :: ContestationPeriod
cperiod = UnsafeContestationPeriod 10
Expand Down
15 changes: 7 additions & 8 deletions hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import qualified Data.ByteString as BS
import qualified Data.List as List
import qualified Data.Text as T
import Hydra.Cluster.Util (readConfigFile)
import Hydra.Crypto (deriveVerificationKey, serialiseSigningKeyToRawBytes, serialiseVerificationKeyToRawBytes)
import qualified Hydra.Crypto as Hydra
import Hydra.Crypto (HydraKey)
import Hydra.Ledger.Cardano ()
import Hydra.Logging (Tracer, traceWith)
import Hydra.Network (Host (Host))
Expand Down Expand Up @@ -203,7 +202,7 @@ withHydraCluster ::
Int ->
-- | NOTE: This decides on the size of the cluster!
[(VerificationKey PaymentKey, SigningKey PaymentKey)] ->
[Hydra.SigningKey] ->
[SigningKey HydraKey] ->
(NonEmpty HydraClient -> IO ()) ->
IO ()
withHydraCluster tracer workDir nodeSocket firstNodeId allKeys hydraKeys action = do
Expand All @@ -225,7 +224,7 @@ withHydraCluster tracer workDir nodeSocket firstNodeId allKeys hydraKeys action
[] -> action (fromList $ reverse clients)
(nodeId : rest) -> do
let hydraSKey = hydraKeys Prelude.!! (nodeId - firstNodeId)
hydraVKeys = map deriveVerificationKey $ filter (/= hydraSKey) hydraKeys
hydraVKeys = map getVerificationKey $ filter (/= hydraSKey) hydraKeys
cardanoVerificationKeys = [workDir </> show i <.> "vk" | i <- allNodeIds, i /= nodeId]
cardanoSigningKey = workDir </> show nodeId <.> "sk"
chainConfig =
Expand All @@ -252,8 +251,8 @@ withHydraNode ::
ChainConfig ->
FilePath ->
Int ->
Hydra.SigningKey ->
[Hydra.VerificationKey] ->
SigningKey HydraKey ->
[VerificationKey HydraKey] ->
[Int] ->
(HydraClient -> IO a) ->
IO a
Expand All @@ -265,10 +264,10 @@ withHydraNode tracer chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNod
let cardanoLedgerProtocolParametersFile = dir </> "protocol-parameters.json"
readConfigFile "protocol-parameters.json" >>= writeFileBS cardanoLedgerProtocolParametersFile
let hydraSigningKey = dir </> (show hydraNodeId <> ".sk")
BS.writeFile hydraSigningKey (serialiseSigningKeyToRawBytes hydraSKey)
BS.writeFile hydraSigningKey (serialiseToRawBytes hydraSKey)
hydraVerificationKeys <- forM (zip [1 ..] hydraVKeys) $ \(i :: Int, vKey) -> do
let filepath = dir </> (show i <> ".vk")
filepath <$ BS.writeFile filepath (serialiseVerificationKeyToRawBytes vKey)
filepath <$ BS.writeFile filepath (serialiseToRawBytes vKey)
let ledgerConfig =
CardanoLedgerConfig
{ cardanoLedgerGenesisFile
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/test/Test/CardanoNodeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec = do
-- false positives test errors in case someone uses an "untested" /
-- different than in shell.nix version of cardano-node and cardano-cli.
it "has expected cardano-node version available" $
getCardanoNodeVersion >>= (`shouldContain` "1.35.0")
getCardanoNodeVersion >>= (`shouldContain` "1.35.3")

-- NOTE: We hard-code the expected networkId here to detect any change to the
-- genesis-shelley.json
Expand Down
10 changes: 10 additions & 0 deletions hydra-node/golden/VerificationKey HydraKey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"samples": [
"8b8d8971de75cb147c66bf22a109c7d64d667e1e866c91182d8c987cdc462b1c",
"0a808c17865dbb543c704d11d6c9ee282f3f873b16857c478b629914d74a845b",
"e0fa61ce94fc5cd993c6329eb9a79171d5366024e1706a9c6de31ea804c3186a",
"1f244fd970279441beccbf8597df02e69ee0c4d1a7ca27b430603f334a5057ba",
"e06298a9d25522cf1c7a69655ffec31a872ab7d819b8a9639ff7c109efeef24e"
],
"seed": 914957528
}
7 changes: 4 additions & 3 deletions hydra-node/src/Hydra/Chain/Direct/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Hydra.Cardano.Api (
NetworkId (..),
NetworkMagic (..),
PaymentKey,
SigningKey,
Tx,
UTxO,
VerificationKey,
Expand All @@ -28,7 +29,7 @@ import Hydra.Chain.Direct.State (
observeTx,
)
import Hydra.ContestationPeriod (ContestationPeriod)
import qualified Hydra.Crypto as Hydra
import Hydra.Crypto (HydraKey, generateSigningKey)
import Hydra.Ledger.Cardano (genOneUTxOFor, genTxIn, genUTxOAdaOnlyOfSize, genVerificationKey, renderTx)
import Hydra.Ledger.Cardano.Evaluate (genPointInTime, genPointInTimeAfter)
import Hydra.Party (Party, deriveParty)
Expand All @@ -44,7 +45,7 @@ import Test.QuickCheck (choose, elements, frequency, vector)
-- be coherent.
data HydraContext = HydraContext
{ ctxVerificationKeys :: [VerificationKey PaymentKey]
, ctxHydraSigningKeys :: [Hydra.SigningKey]
, ctxHydraSigningKeys :: [SigningKey HydraKey]
, ctxNetworkId :: NetworkId
, ctxContestationPeriod :: ContestationPeriod
}
Expand Down Expand Up @@ -73,7 +74,7 @@ genHydraContext maxParties = choose (1, maxParties) >>= genHydraContextFor
genHydraContextFor :: Int -> Gen HydraContext
genHydraContextFor n = do
ctxVerificationKeys <- replicateM n genVerificationKey
ctxHydraSigningKeys <- fmap Hydra.generateSigningKey <$> vector n
ctxHydraSigningKeys <- fmap generateSigningKey <$> vector n
ctxNetworkId <- Testnet . NetworkMagic <$> arbitrary
ctxContestationPeriod <- arbitrary
pure $
Expand Down
Loading