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

Persistence works with committing empty UTxO #1741

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
40 changes: 39 additions & 1 deletion hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Control.Concurrent.Async (mapConcurrently_)
import Control.Lens ((^..), (^?))
import Data.Aeson (Value, object, (.=))
import Data.Aeson qualified as Aeson
import Data.Aeson.Lens (key, values, _JSON)
import Data.Aeson.Lens (key, values, _JSON, _String)
import Data.Aeson.Types (parseMaybe)
import Data.ByteString (isInfixOf)
import Data.ByteString qualified as B
Expand Down Expand Up @@ -469,6 +469,44 @@ singlePartyCommitsScriptBlueprint tracer workDir node hydraScriptsTxId =

RunningNode{networkId, nodeSocket, blockTime} = node

persistenceCanLoadWithEmptyCommit ::
Tracer IO EndToEndLog ->
FilePath ->
RunningNode ->
TxId ->
IO ()
persistenceCanLoadWithEmptyCommit tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
headId <- withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
send n1 $ input "Init" []
headId <- waitMatch (10 * blockTime) n1 $ headIsInitializingWith (Set.fromList [alice])

requestCommitTx n1 mempty >>= submitTx node
waitFor hydraTracer (10 * blockTime) [n1] $
output "HeadIsOpen" ["utxo" .= object mempty, "headId" .= headId]
pure headId
let persistenceState = workDir </> "state-" <> show hydraNodeId </> "state"
stateContents <- readFileBS persistenceState
let headOpened = BSC.pack $ List.last (List.lines $ BSC.unpack stateContents)
case headOpened ^? key "stateChanged" . key "tag" . _String of
Nothing -> error "Failed to find HeadIsOpened in the state file"
Just headIsOpen -> do
headIsOpen `shouldBe` "HeadOpened"
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
waitFor hydraTracer (10 * blockTime) [n1] $
output "HeadIsOpen" ["utxo" .= object mempty, "headId" .= headId]

send n1 $ input "GetUTxO" []

waitFor hydraTracer 10 [n1] $
output "GetUTxOResponse" ["headId" .= headId, "utxo" .= (mempty :: UTxO)]
where
RunningNode{nodeSocket, blockTime} = node

-- | Single hydra-node where the commit is done from a raw transaction
-- blueprint.
singlePartyCommitsFromExternalTxBlueprint ::
Expand Down
6 changes: 6 additions & 0 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import Hydra.Cluster.Scenarios (
canSubmitTransactionThroughAPI,
headIsInitializingWith,
initWithWrongKeys,
persistenceCanLoadWithEmptyCommit,
refuelIfNeeded,
restartedNodeCanAbort,
restartedNodeCanObserveCommitTx,
Expand Down Expand Up @@ -217,6 +218,11 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node ->
publishHydraScriptsAs node Faucet
>>= singlePartyCommitsScriptBlueprint tracer tmpDir node
it "persistence can load with empty commit" $ \tracer -> do
withClusterTempDir $ \tmpDir -> do
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node ->
publishHydraScriptsAs node Faucet
>>= persistenceCanLoadWithEmptyCommit tracer tmpDir node

describe "three hydra nodes scenario" $ do
it "does not error when all nodes open the head concurrently" $ \tracer ->
Expand Down