Skip to content

Commit

Permalink
Change Era from BabbageEra to ConwayEra
Browse files Browse the repository at this point in the history
Do filter protocol updates in Arbitrary Tx anymore

Those are now represented differently in Conway and we'll see how the
fully random transactions (including governance actions that supersede
protocol updates) behave in situations where we use this generator.
  • Loading branch information
locallycompact committed Aug 12, 2024
1 parent 1ae6839 commit bfd684d
Show file tree
Hide file tree
Showing 40 changed files with 34,456 additions and 37,145 deletions.
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"build": "yarn prepare && docusaurus build",
"build-dev": "yarn prepare && docusaurus build --no-minify -l en",
"start": "yarn dummy-spec && docusaurus start",
"validate:inputs": "./validate-api.js publish '/' '../hydra-node/golden/ReasonablySized (ClientInput (Tx BabbageEra)).json'",
"validate:outputs": "./validate-api.js subscribe '/' '../hydra-node/golden/ReasonablySized (TimedServerOutput (Tx BabbageEra)).json'",
"validate:inputs": "./validate-api.js publish '/' '../hydra-node/golden/ReasonablySized (ClientInput (Tx ConwayEra)).json'",
"validate:outputs": "./validate-api.js subscribe '/' '../hydra-node/golden/ReasonablySized (TimedServerOutput (Tx ConwayEra)).json'",
"validate": "yarn validate:inputs && yarn validate:outputs",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Data.Text (Text)
import Data.Text qualified as T
import Prelude

type Era = BabbageEra
type Era = ConwayEra

type UTxO = UTxO' (TxOut CtxUTxO Era)

Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import Data.Typeable (Typeable)
import GHC.Stack (HasCallStack)
import Test.QuickCheck (Arbitrary (..), Gen)

type Era = BabbageEra
type Era = ConwayEra

-- | Currently supported ledger era.
type LedgerEra = ShelleyLedgerEra Era
Expand Down
11 changes: 8 additions & 3 deletions hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ module Hydra.Cardano.Api.TxBody where
import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Api (AlonzoPlutusPurpose (..), AsItem (..), AsIx, PlutusPurpose)
import Cardano.Ledger.Api (
AsItem (..),
AsIx,
ConwayPlutusPurpose (..),
PlutusPurpose,
)
import Cardano.Ledger.Babbage.Core (redeemerPointer)
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
import Cardano.Ledger.Core qualified as Ledger
Expand All @@ -23,7 +28,7 @@ findRedeemerSpending ::
TxIn ->
Maybe a
findRedeemerSpending (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) txIn = do
ptr <- strictMaybeToMaybe $ redeemerPointer body (AlonzoSpending . AsItem $ toLedgerTxIn txIn)
ptr <- strictMaybeToMaybe $ redeemerPointer body (ConwaySpending . AsItem $ toLedgerTxIn txIn)
lookupRedeemer ptr scriptData

findRedeemerMinting ::
Expand All @@ -32,7 +37,7 @@ findRedeemerMinting ::
PolicyId ->
Maybe a
findRedeemerMinting (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) pid = do
ptr <- strictMaybeToMaybe $ redeemerPointer body (AlonzoMinting . AsItem $ toLedgerPolicyID pid)
ptr <- strictMaybeToMaybe $ redeemerPointer body (ConwayMinting . AsItem $ toLedgerPolicyID pid)
lookupRedeemer ptr scriptData

findScriptMinting ::
Expand Down
7 changes: 1 addition & 6 deletions hydra-chain-observer/src/Hydra/ChainObserver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ import Hydra.Cardano.Api (
Tx,
UTxO,
connectToLocalNode,
convertConwayTx,
fromLedgerTx,
getChainPoint,
getTxBody,
getTxId,
toLedgerTx,
pattern Block,
)
import Hydra.Cardano.Api.Prelude (TxId)
Expand Down Expand Up @@ -175,16 +172,14 @@ chainSyncClient tracer networkId startingPoint observerHandler =
{ recvMsgRollForward = \blockInMode _tip -> ChainSyncClient $ do
let receivedTxIds = case blockInMode of
BlockInMode ConwayEra (Block _ conwayTxs) -> getTxId . getTxBody <$> conwayTxs
BlockInMode BabbageEra (Block _ babbageTxs) -> getTxId . getTxBody <$> babbageTxs
_ -> []

(BlockInMode _ (Block bh@(BlockHeader _ _ blockNo) _)) = blockInMode
point = getChainPoint bh
traceWith tracer RollForward{point, receivedTxIds}

let txs = case blockInMode of
BlockInMode ConwayEra (Block _ conwayTxs) -> map (fromLedgerTx . convertConwayTx . toLedgerTx) conwayTxs
BlockInMode BabbageEra (Block _ babbageTxs) -> babbageTxs
BlockInMode ConwayEra (Block _ conwayTxs) -> conwayTxs
_ -> []

(utxo', observations) = observeAll networkId utxo txs
Expand Down
1 change: 1 addition & 0 deletions hydra-cluster/config/devnet/cardano-node.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"TestMaryHardForkAtEpoch": 0,
"TestAlonzoHardForkAtEpoch": 0,
"TestBabbageHardForkAtEpoch": 0,
"TestConwayHardForkAtEpoch": 0,

"RequiresNetworkMagic": "RequiresNoMagic",

Expand Down
5 changes: 4 additions & 1 deletion hydra-cluster/config/devnet/genesis-conway.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,8 @@
"numerator": 2,
"denominator": 3
}
}
},
"minFeeRefScriptCostPerByte": 0,
"plutusV3CostModel":[],
"extraPraosEntropy": null
}
34 changes: 33 additions & 1 deletion hydra-cluster/config/protocol-parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,5 +379,37 @@
"stakePoolDeposit": 500000000,
"stakePoolTargetNum": 500,
"treasuryCut": 0.2,
"utxoCostPerByte": 4310
"utxoCostPerByte": 4310,
"poolVotingThresholds": {
"committeeNormal": 0.51,
"committeeNoConfidence": 0.51,
"hardForkInitiation": 0.51,
"motionNoConfidence": 0.51,
"ppSecurityGroup": 0.51
},
"dRepVotingThresholds": {
"motionNoConfidence": 0.51,
"committeeNormal": 0.51,
"committeeNoConfidence": 0.51,
"updateToConstitution": 0.51,
"hardForkInitiation": 0.51,
"ppNetworkGroup": 0.51,
"ppEconomicGroup": 0.51,
"ppTechnicalGroup": 0.51,
"ppGovGroup": 0.51,
"treasuryWithdrawal": 0.51
},
"committeeMinSize": 0,
"committeeMaxTermLength": 200,
"govActionLifetime": 10,
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"constitution": {
"anchor": {
"url": "",
"dataHash": "0000000000000000000000000000000000000000000000000000000000000000"
}
},
"minFeeRefScriptCostPerByte": 0
}
2 changes: 1 addition & 1 deletion hydra-cluster/datasets/1-node.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hydra-cluster/datasets/3-nodes.json

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions hydra-cluster/src/CardanoNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,6 @@ setupCardanoDevnet stateDirectory = do
Aeson.encodeFile (stateDirectory </> nodeTopologyFile args) $
mkTopology peers

-- | Modify the cardano-node configuration to fork into conway at given era
-- number.
forkIntoConwayInEpoch :: FilePath -> CardanoNodeArgs -> Natural -> IO ()
forkIntoConwayInEpoch stateDirectory args n = do
config <-
unsafeDecodeJsonFile @Aeson.Value (stateDirectory </> nodeConfigFile args)
<&> atKey "TestConwayHardForkAtEpoch" ?~ toJSON n
Aeson.encodeFile
(stateDirectory </> nodeConfigFile args)
config

withCardanoNode ::
Tracer IO NodeLog ->
FilePath ->
Expand Down Expand Up @@ -491,7 +480,8 @@ cliQueryProtocolParameters nodeSocket networkId = do
cmd = "cardano-cli"

args =
[ "query"
[ "conway"
, "query"
, "protocol-parameters"
, "--socket-path"
, unFile nodeSocket
Expand Down
140 changes: 0 additions & 140 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import CardanoClient (
)
import CardanoNode (
CardanoNodeArgs (..),
forkIntoConwayInEpoch,
setupCardanoDevnet,
unsafeDecodeJsonFile,
withCardanoNode,
withCardanoNodeDevnet,
)
import Control.Concurrent.STM (newTVarIO, readTVarIO)
Expand All @@ -37,7 +34,6 @@ import Data.ByteString qualified as BS
import Data.List qualified as List
import Data.Map qualified as Map
import Data.Set qualified as Set
import Data.Text qualified as Text
import Data.Time (secondsToDiffTime)
import Hydra.Cardano.Api hiding (Value, cardanoEra, queryGenesisParameters)
import Hydra.Chain.Direct.Fixture (testNetworkId)
Expand All @@ -58,7 +54,6 @@ import Hydra.Cluster.Fixture (
carol,
carolSk,
carolVk,
cperiod,
)
import Hydra.Cluster.Scenarios (
EndToEndLog (..),
Expand Down Expand Up @@ -99,14 +94,11 @@ import HydraNode (
withHydraNode',
)
import System.Directory (removeDirectoryRecursive)
import System.Exit (ExitCode (ExitFailure))
import System.FilePath ((</>))
import System.IO (
hGetContents,
hGetLine,
)
import System.IO.Error (isEOFError)
import System.Process (waitForProcess)
import Test.QuickCheck (generate)
import Prelude qualified

Expand Down Expand Up @@ -510,138 +502,6 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
logfile <- readFileBS logFilePath
BS.length logfile `shouldSatisfy` (> 0)

describe "forking eras" $ do
it "does report on unsupported era" $ \tracer -> do
pendingWith "Currently supporting Conway era no future upcoming"
withClusterTempDir $ \tmpDir -> do
args <- setupCardanoDevnet tmpDir
forkIntoConwayInEpoch tmpDir args 1
withCardanoNode (contramap FromCardanoNode tracer) tmpDir args $ \node@RunningNode{nodeSocket} -> do
let hydraTracer = contramap FromHydraNode tracer
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod
withHydraNode' hydraTracer chainConfig tmpDir 1 aliceSk [] [1] Nothing $ \out stdErr ph -> do
-- Assert nominal startup
waitForLog 5 out "missing NodeOptions" (Text.isInfixOf "NodeOptions")

waitUntilEpoch tmpDir args node 1

waitForProcess ph `shouldReturn` ExitFailure 1
errorOutputs <- hGetContents stdErr
errorOutputs `shouldContain` "Received blocks in unsupported era"
errorOutputs `shouldContain` "upgrade your hydra-node"

it "does report on unsupported era on startup" $ \tracer -> do
pendingWith "Currently supporting Conway era no future upcoming"
withClusterTempDir $ \tmpDir -> do
args <- setupCardanoDevnet tmpDir
forkIntoConwayInEpoch tmpDir args 1
withCardanoNode (contramap FromCardanoNode tracer) tmpDir args $ \node@RunningNode{nodeSocket} -> do
let hydraTracer = contramap FromHydraNode tracer
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod

waitUntilEpoch tmpDir args node 2

withHydraNode' hydraTracer chainConfig tmpDir 1 aliceSk [] [1] Nothing $ \_out stdErr ph -> do
waitForProcess ph `shouldReturn` ExitFailure 1
errorOutputs <- hGetContents stdErr
errorOutputs `shouldContain` "Connected to cardano-node in unsupported era"
errorOutputs `shouldContain` "upgrade your hydra-node"

it "support new era" $ \tracer -> do
withClusterTempDir $ \tmpDir -> do
args <- setupCardanoDevnet tmpDir

forkIntoConwayInEpoch tmpDir args 10
withCardanoNode (contramap FromCardanoNode tracer) tmpDir args $
\node@RunningNode{nodeSocket, networkId} -> do
let lovelaceBalanceValue = 100_000_000
-- Funds to be used as fuel by Hydra protocol transactions
(aliceCardanoVk, _) <- keysFor Alice
seedFromFaucet_ node aliceCardanoVk lovelaceBalanceValue (contramap FromFaucet tracer)
-- Get some UTXOs to commit to a head
(aliceExternalVk, aliceExternalSk) <- generate genKeyPair
committedUTxOByAlice <- seedFromFaucet node aliceExternalVk aliceCommittedToHead (contramap FromFaucet tracer)

hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod

let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer chainConfig tmpDir 1 aliceSk [] [1] $ \n1 -> do
send n1 $ input "Init" []
headId <- waitForAllMatch 10 [n1] $ headIsInitializingWith (Set.fromList [alice])

requestCommitTx n1 committedUTxOByAlice <&> signTx aliceExternalSk >>= submitTx node

waitFor hydraTracer 3 [n1] $ output "HeadIsOpen" ["utxo" .= committedUTxOByAlice, "headId" .= headId]

guardEra networkId nodeSocket (AnyCardanoEra BabbageEra)
waitUntilEpoch tmpDir args node 10
guardEra networkId nodeSocket (AnyCardanoEra ConwayEra)

send n1 $ input "Close" []
waitMatch 3 n1 $ \v -> do
guard $ v ^? key "tag" == Just "HeadIsClosed"
guard $ v ^? key "headId" == Just (toJSON headId)
snapshotNumber <- v ^? key "snapshotNumber"
guard $ snapshotNumber == Aeson.Number 0

it "can start in conway era" $ \tracer -> do
withClusterTempDir $ \tmpDir -> do
args <- setupCardanoDevnet tmpDir
forkIntoConwayInEpoch tmpDir args 1
withCardanoNode (contramap FromCardanoNode tracer) tmpDir args $
\node@RunningNode{nodeSocket} -> do
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod
waitUntilEpoch tmpDir args node 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer chainConfig tmpDir 1 aliceSk [] [1] $ const $ pure ()

it "support new era on restart" $ \tracer -> do
withClusterTempDir $ \tmpDir -> do
args <- setupCardanoDevnet tmpDir

forkIntoConwayInEpoch tmpDir args 10
withCardanoNode (contramap FromCardanoNode tracer) tmpDir args $
\node@RunningNode{nodeSocket, networkId} -> do
let lovelaceBalanceValue = 100_000_000
-- Funds to be used as fuel by Hydra protocol transactions
(aliceCardanoVk, _) <- keysFor Alice
seedFromFaucet_ node aliceCardanoVk lovelaceBalanceValue (contramap FromFaucet tracer)
-- Get some UTXOs to commit to a head
(aliceExternalVk, aliceExternalSk) <- generate genKeyPair
committedUTxOByAlice <- seedFromFaucet node aliceExternalVk aliceCommittedToHead (contramap FromFaucet tracer)

hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod

guardEra networkId nodeSocket (AnyCardanoEra BabbageEra)

let hydraTracer = contramap FromHydraNode tracer
headId <- withHydraNode hydraTracer chainConfig tmpDir 1 aliceSk [] [1] $ \n1 -> do
send n1 $ input "Init" []
headId <- waitForAllMatch 10 [n1] $ headIsInitializingWith (Set.fromList [alice])

requestCommitTx n1 committedUTxOByAlice <&> signTx aliceExternalSk >>= submitTx node

waitFor hydraTracer 3 [n1] $ output "HeadIsOpen" ["utxo" .= committedUTxOByAlice, "headId" .= headId]

pure headId

waitUntilEpoch tmpDir args node 10

guardEra networkId nodeSocket (AnyCardanoEra ConwayEra)

withHydraNode hydraTracer chainConfig tmpDir 1 aliceSk [] [1] $ \n1 -> do
send n1 $ input "Close" []
waitMatch 3 n1 $ \v -> do
guard $ v ^? key "tag" == Just "HeadIsClosed"
guard $ v ^? key "headId" == Just (toJSON headId)
snapshotNumber <- v ^? key "snapshotNumber"
guard $ snapshotNumber == Aeson.Number 0

-- | Query the current era at the tip, and guard that it is equal to the
-- provided one.
guardEra :: NetworkId -> SocketPath -> AnyCardanoEra -> IO ()
Expand Down
2 changes: 1 addition & 1 deletion hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec =
output
^? key "type" . _String `shouldSatisfy` \case
Nothing -> False
Just something -> something == "Witnessed Tx BabbageEra"
Just something -> something == "Witnessed Tx ConwayEra"

it "has expected cardano-cli version available" $
readProcess "cardano-cli" ["--version"] "" >>= (`shouldContain` "9.2.1.0")
Expand Down
Loading

0 comments on commit bfd684d

Please sign in to comment.