Skip to content

Commit a3047c8

Browse files
Use a directory name that is the hash of the clusterPeers for etcd state (#1965)
This should function as an "auto-clear" when connecting to a new cluster configuration.
1 parent 2fe866e commit a3047c8

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,48 @@ threeNodesNoErrorsOnOpen tracer tmpDir node@RunningNode{nodeSocket} hydraScripts
10961096
Right _headIsOpen ->
10971097
pure ()
10981098

1099+
-- | Hydra nodes ABC run on ABC cluster and connect to each other.
1100+
-- Hydra nodes BC shut down.
1101+
-- Hydra nodes BC run on BC cluster and connect to each other.
1102+
-- Hydra nodes BC shut down.
1103+
-- Hydra nodes BC run and connect ABC cluster again.
1104+
nodeCanSupportMultipleEtcdClusters :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [TxId] -> IO ()
1105+
nodeCanSupportMultipleEtcdClusters tracer workDir RunningNode{networkId, nodeSocket} hydraScriptsTxId = do
1106+
let contestationPeriod = UnsafeContestationPeriod 2
1107+
let depositDeadline = UnsafeDepositDeadline 50
1108+
1109+
aliceChainConfig <-
1110+
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob, Carol] contestationPeriod depositDeadline
1111+
<&> setNetworkId networkId
1112+
bobChainConfig <-
1113+
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice, Carol] contestationPeriod depositDeadline
1114+
<&> setNetworkId networkId
1115+
carolChainConfig <-
1116+
chainConfigFor Carol workDir nodeSocket hydraScriptsTxId [Alice, Bob] contestationPeriod depositDeadline
1117+
<&> setNetworkId networkId
1118+
1119+
let hydraTracer = contramap FromHydraNode tracer
1120+
1121+
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk, carolVk] [1, 2, 3] $ \n1 -> do
1122+
withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk, carolVk] [1, 2, 3] $ \n2 -> do
1123+
withHydraNode hydraTracer carolChainConfig workDir 3 carolSk [aliceVk, bobVk] [1, 2, 3] $ \n3 -> do
1124+
waitForNodesConnected hydraTracer 30 $ n1 :| [n2, n3]
1125+
1126+
bobChainConfig' <-
1127+
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Carol] contestationPeriod depositDeadline
1128+
<&> setNetworkId networkId
1129+
carolChainConfig' <-
1130+
chainConfigFor Carol workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
1131+
<&> setNetworkId networkId
1132+
1133+
withHydraNode hydraTracer bobChainConfig' workDir 2 bobSk [carolVk] [2, 3] $ \n2 -> do
1134+
withHydraNode hydraTracer carolChainConfig' workDir 3 carolSk [bobVk] [2, 3] $ \n3 -> do
1135+
waitForNodesConnected hydraTracer 30 $ n2 :| [n3]
1136+
1137+
withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk, carolVk] [1, 2, 3] $ \n2 -> do
1138+
withHydraNode hydraTracer carolChainConfig workDir 3 carolSk [aliceVk, bobVk] [1, 2, 3] $ \n3 -> do
1139+
waitForNodesConnected hydraTracer 30 $ n1 :| [n2, n3]
1140+
10991141
-- | Two hydra node setup where Alice is wrongly configured to use Carol's
11001142
-- cardano keys instead of Bob's which will prevent him to be notified the
11011143
-- `HeadIsInitializing` but he should still receive some notification.

hydra-cluster/test/Test/EndToEndSpec.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import Hydra.Cluster.Scenarios (
6060
checkFanout,
6161
headIsInitializingWith,
6262
initWithWrongKeys,
63+
nodeCanSupportMultipleEtcdClusters,
6364
nodeReObservesOnChainTxs,
6465
oneOfThreeNodesStopsForAWhile,
6566
persistenceCanLoadWithEmptyCommit,
@@ -282,6 +283,13 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
282283
publishHydraScriptsAs node Faucet
283284
>>= threeNodesNoErrorsOnOpen tracer tmpDir node
284285

286+
it "node can support multiple etcd clusters" $ \tracer ->
287+
failAfter 60 $
288+
withClusterTempDir $ \tmpDir -> do
289+
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \node -> do
290+
publishHydraScriptsAs node Faucet
291+
>>= nodeCanSupportMultipleEtcdClusters tracer tmpDir node
292+
285293
it "inits a Head, processes a single Cardano transaction and closes it again" $ \tracer ->
286294
failAfter 60 $
287295
withClusterTempDir $ \tmpDir -> do

hydra-node/src/Hydra/Network/Etcd.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Hydra.Network.Etcd where
4444
import Hydra.Prelude
4545

4646
import Cardano.Binary (decodeFull', serialize')
47+
import Cardano.Crypto.Hash (SHA256, hashToStringAsHex, hashWithSerialiser)
4748
import Control.Concurrent.Class.MonadSTM (
4849
modifyTVar',
4950
newTBQueueIO,
@@ -61,6 +62,7 @@ import Data.Aeson qualified as Aeson
6162
import Data.Aeson.Types (Value)
6263
import Data.Bits ((.|.))
6364
import Data.ByteString qualified as BS
65+
import Data.ByteString.Char8 qualified as BS8
6466
import Data.List ((\\))
6567
import Data.List qualified as List
6668
import Data.Map qualified as Map
@@ -205,7 +207,7 @@ withEtcdNetwork tracer protocolVersion config callback action = do
205207
$ concat
206208
[ -- NOTE: Must be used in clusterPeers
207209
["--name", show advertise]
208-
, ["--data-dir", persistenceDir </> "etcd"]
210+
, ["--data-dir", persistenceDir </> "etcd" </> hashToStringAsHex (hashWithSerialiser @SHA256 toCBOR $ BS8.pack clusterPeers)]
209211
, ["--listen-peer-urls", httpUrl listen]
210212
, ["--initial-advertise-peer-urls", httpUrl advertise]
211213
, ["--listen-client-urls", httpUrl clientHost]

hydra-node/test/Hydra/NetworkSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ spec = do
113113

114114
it "emits connectivity events" $ \tracer -> do
115115
withTempDir "test-etcd" $ \tmp -> do
116-
failAfter 20 $ do
116+
failAfter 30 $ do
117117
PeerConfig3{aliceConfig, bobConfig, carolConfig} <- setup3Peers tmp
118118
-- Record and assert connectivity events from alice's perspective
119119
(recordReceived, _, waitConnectivity) <- newRecordingCallback

0 commit comments

Comments
 (0)