Skip to content

Event log rotation #1997

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

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ prepareHydraNode chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNodeIds
, hydraSigningKey
, hydraVerificationKeys
, persistenceDir = stateDir
, persistenceRotateAfter = Nothing
, chainConfig
, ledgerConfig =
CardanoLedgerConfig
Expand Down Expand Up @@ -517,6 +518,7 @@ withHydraNode tracer chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNod
, hydraSigningKey
, hydraVerificationKeys
, persistenceDir = stateDir
, persistenceRotateAfter = Nothing
, chainConfig
, ledgerConfig =
CardanoLedgerConfig
Expand Down
55 changes: 55 additions & 0 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import CardanoNode (
withCardanoNodeDevnet,
)
import Control.Lens ((^..), (^?))
import Control.Monad (foldM_)
import Data.Aeson (Result (..), Value (Null, Object, String), fromJSON, object, (.=))
import Data.Aeson qualified as Aeson
import Data.Aeson.Lens (AsJSON (_JSON), key, values, _JSON)
import Data.Aeson.Types (parseMaybe)
import Data.ByteString qualified as BS
import Data.List qualified as List
import Data.Map qualified as Map
Expand Down Expand Up @@ -88,6 +90,7 @@ import HydraNode (
getSnapshotUTxO,
input,
output,
prepareHydraNode,
requestCommitTx,
send,
waitFor,
Expand All @@ -96,6 +99,7 @@ import HydraNode (
waitMatch,
withHydraCluster,
withHydraNode,
withPreparedHydraNode,
)
import System.Directory (removeDirectoryRecursive, removeFile)
import System.FilePath ((</>))
Expand Down Expand Up @@ -159,6 +163,57 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
waitMatch 10 node $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"

it "rotates persistence on start up" $ \tracer -> do
withClusterTempDir $ \tmpDir -> do
(aliceCardanoVk, aliceCardanoSk) <- keysFor Alice
initialUTxO <- generate $ genUTxOFor aliceCardanoVk
Aeson.encodeFile (tmpDir </> "utxo.json") initialUTxO
let offlineConfig =
Offline
OfflineChainConfig
{ offlineHeadSeed = "test"
, initialUTxOFile = tmpDir </> "utxo.json"
, ledgerGenesisFile = Nothing
}
-- Start a hydra-node in offline mode and submit several self-txs
withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 1 aliceSk [] [] $ \node -> do
foldM_
( \utxo i -> do
let Just (aliceTxIn, aliceTxOut) = UTxO.find (isVkTxOut aliceCardanoVk) utxo
let Right selfTx =
mkSimpleTx
(aliceTxIn, aliceTxOut)
(mkVkAddress testNetworkId aliceCardanoVk, txOutValue aliceTxOut)
aliceCardanoSk
send node $ input "NewTx" ["transaction" .= selfTx]
waitMatch 10 node $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
guard $ v ^? key "snapshot" . key "number" == Just (toJSON (i :: Integer))
v ^? key "snapshot" . key "utxo" >>= parseMaybe parseJSON
)
initialUTxO
[1 .. (200 :: Integer)]

-- Measure restart time
t0 <- getCurrentTime
diff1 <- withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 1 aliceSk [] [] $ \_ -> do
t1 <- getCurrentTime
let diff = diffUTCTime t1 t0
pure diff

-- Measure restart after rotation
options <- prepareHydraNode offlineConfig tmpDir 1 aliceSk [] [] id
let options' = options{persistenceRotateAfter = Just 10}
t1 <- getCurrentTime
diff2 <- withPreparedHydraNode (contramap FromHydraNode tracer) tmpDir 1 options' $ \_ -> do
t2 <- getCurrentTime
let diff = diffUTCTime t2 t1
pure diff

unless (diff2 < diff1 * 0.9) $
failure $
"Expected to start up 10% quicker than original " <> show diff1 <> ", but it took " <> show diff2

it "supports multi-party networked heads" $ \tracer -> do
withClusterTempDir $ \tmpDir -> do
(aliceCardanoVk, aliceCardanoSk) <- keysFor Alice
Expand Down
Loading