Skip to content

Commit

Permalink
Merge pull request #5818 from IntersectMBO/mgalazyn/test/enable-epoch…
Browse files Browse the repository at this point in the history
…-state-logging-by-default

Enable epoch state logging by default
  • Loading branch information
carbolymer committed May 3, 2024
2 parents a8c0da2 + f49f55b commit 285268c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 24 deletions.
5 changes: 5 additions & 0 deletions cardano-testnet/src/Parsers/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ optsTestnet envCli = CardanoTestnetOptions
<> OA.showDefault
<> OA.value 3
)
<*> OA.flag False True
( OA.long "enable-new-epoch-state-logging"
<> OA.help "Enable new epoch state logging to logs/ledger-epoch-state.log"
<> OA.showDefault
)

pNumSpoNodes :: Parser [TestnetNodeOptions]
pNumSpoNodes =
Expand Down
32 changes: 19 additions & 13 deletions cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import qualified GHC.Stack as GHC
import Network.Socket (PortNumber)
import Prettyprinter (unAnnotate)
import qualified System.Directory as IO
import System.Directory (doesDirectoryExist)
import System.FilePath
import qualified System.IO as IO
import qualified System.Process as IO
Expand Down Expand Up @@ -332,8 +331,9 @@ createSubdirectoryIfMissingNew parent subdirectory = GHC.withFrozenCallStack $ d
-- | Start ledger's new epoch state logging for the first node in the background.
-- Logs will be placed in <tmp workspace directory>/logs/ledger-new-epoch-state.log
-- The logging thread will be cancelled when `MonadResource` releases all resources.
-- Idempotent.
startLedgerNewEpochStateLogging
:: forall m. HasCallStack
:: HasCallStack
=> MonadCatch m
=> MonadResource m
=> MonadTest m
Expand All @@ -342,24 +342,30 @@ startLedgerNewEpochStateLogging
-> m ()
startLedgerNewEpochStateLogging testnetRuntime tmpWorkspace = withFrozenCallStack $ do
let logDir = makeLogDir (TmpAbsolutePath tmpWorkspace)
-- used as a lock to start only a single instance of epoch state logging
logFile = logDir </> "ledger-epoch-state.log"

H.evalIO (doesDirectoryExist logDir) >>= \case
H.evalIO (IO.doesDirectoryExist logDir) >>= \case
True -> pure ()
False -> do
H.note_ $ "Log directory does not exist: " <> logDir <> " - cannot start logging epoch states"
H.failure

socketPath <- H.noteM $ H.sprocketSystemName <$> H.headM (poolSprockets testnetRuntime)
_ <- runInBackground . runExceptT $
foldEpochState
(File $ configurationFile testnetRuntime)
(Api.File socketPath)
Api.QuickValidation
(EpochNo maxBound)
()
(\epochState _ _ -> handler logFile epochState)
H.note_ $ "Started logging epoch states to to: " <> logFile
H.evalIO (IO.doesFileExist logFile) >>= \case
True -> do
H.note_ $ "Epoch states logging to " <> logFile <> " is already started."
False -> do
H.evalIO $ appendFile logFile ""
socketPath <- H.noteM $ H.sprocketSystemName <$> H.headM (poolSprockets testnetRuntime)
_ <- runInBackground . runExceptT $
foldEpochState
(File $ configurationFile testnetRuntime)
(Api.File socketPath)
Api.QuickValidation
(EpochNo maxBound)
()
(\epochState _ _ -> handler logFile epochState)
H.note_ $ "Started logging epoch states to: " <> logFile
where
handler :: FilePath -> AnyNewEpochState -> StateT () IO LedgerStateCondition
handler outputFp anyNewEpochState = handleException . liftIO $ do
Expand Down
3 changes: 3 additions & 0 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ cardanoTestnet

H.assertExpectedSposInLedgerState stakePoolsFp testnetOptions execConfig

when (cardanoEnableNewEpochStateLogging testnetOptions) $
TR.startLedgerNewEpochStateLogging runtime tempBaseAbsPath

pure runtime
where
writeGenesisSpecFile :: (MonadTest m, MonadIO m, HasCallStack) => ToJSON a => String -> a -> m ()
Expand Down
2 changes: 2 additions & 0 deletions cardano-testnet/src/Testnet/Start/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ data CardanoTestnetOptions = CardanoTestnetOptions
, cardanoEnableP2P :: Bool
, cardanoNodeLoggingFormat :: NodeLoggingFormat
, cardanoNumDReps :: Int -- ^ The number of DReps to generate at creation
, cardanoEnableNewEpochStateLogging :: Bool -- ^ if epoch state logging is enabled
} deriving (Eq, Show)

cardanoDefaultTestnetOptions :: CardanoTestnetOptions
Expand All @@ -61,6 +62,7 @@ cardanoDefaultTestnetOptions = CardanoTestnetOptions
, cardanoEnableP2P = False
, cardanoNodeLoggingFormat = NodeLoggingFormatAsJson
, cardanoNumDReps = 3
, cardanoEnableNewEpochStateLogging = True
}

-- | Specify a BFT node (Pre-Babbage era only) or an SPO (Shelley era onwards only)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Usage: cardano-testnet cardano [--num-pool-nodes COUNT]
[--enable-p2p BOOL]
[--nodeLoggingFormat LOGGING_FORMAT]
[--num-dreps NUMBER]
[--enable-new-epoch-state-logging]

Start a testnet in any era

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Usage: cardano-testnet cardano [--num-pool-nodes COUNT]
[--enable-p2p BOOL]
[--nodeLoggingFormat LOGGING_FORMAT]
[--num-dreps NUMBER]
[--enable-new-epoch-state-logging]

Start a testnet in any era

Expand Down Expand Up @@ -41,4 +42,7 @@ Available options:
(default: NodeLoggingFormatAsJson)
--num-dreps NUMBER Number of delegate representatives (DReps) to
generate (default: 3)
--enable-new-epoch-state-logging
Enable new epoch state logging to
logs/ledger-epoch-state.log
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Testnet.Components.DReps (createVotingTxBody, delegateToDRep, g
import Testnet.Components.Query (EpochStateView, checkDRepState,
findLargestUtxoForPaymentKey, getCurrentEpochNo, getEpochStateView,
getMinDRepDeposit)
import Testnet.Components.TestWatchdog
import Testnet.Defaults
import qualified Testnet.Process.Cli as P
import qualified Testnet.Process.Run as H
Expand All @@ -51,7 +52,7 @@ import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
-- | Execute me with:
-- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/DRep Activity/"'@
hprop_check_drep_activity :: Property
hprop_check_drep_activity = H.integrationWorkspace "test-activity" $ \tempAbsBasePath' -> do
hprop_check_drep_activity = H.integrationWorkspace "test-activity" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do
-- Start a local test net
conf@Conf { tempAbsPath } <- mkConf tempAbsBasePath'
let tempAbsPath' = unTmpAbsPath tempAbsPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t
, cardanoNodeEra = AnyCardanoEra era
}

testnetRuntime@TestnetRuntime
TestnetRuntime
{ testnetMagic
, poolNodes
, wallets=wallet0:wallet1:_
Expand All @@ -80,8 +80,6 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t

epochStateView <- getEpochStateView (File configurationFile) (File socketPath)

startLedgerNewEpochStateLogging testnetRuntime tempAbsPath'

H.note_ $ "Sprocket: " <> show poolSprocket1
H.note_ $ "Abs path: " <> tempAbsBasePath'
H.note_ $ "Socketpath: " <> socketPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu
, cardanoActiveSlotsCoeff = 0.3
}

testnetRuntime@TestnetRuntime
TestnetRuntime
{ testnetMagic
, poolNodes
, wallets=wallet0:wallet1:_
Expand All @@ -92,8 +92,6 @@ hprop_ledger_events_treasury_withdrawal = H.integrationRetryWorkspace 1 "treasu
H.note_ $ "Socketpath: " <> socketPath
H.note_ $ "Foldblocks config file: " <> configurationFile

startLedgerNewEpochStateLogging testnetRuntime tempAbsPath'

gov <- H.createDirectoryIfMissing $ work </> "governance"
proposalAnchorFile <- H.note $ work </> gov </> "sample-proposal-anchor"
treasuryWithdrawalActionFp <- H.note $ work </> gov </> "treasury-withdrawal.action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ prop_check_if_treasury_is_growing = H.integrationRetryWorkspace 0 "growing-treas

runtime@TestnetRuntime{configurationFile} <- cardanoTestnetDefault options conf

-- uncomment for epoch state live access
-- startLedgerNewEpochStateLogging runtime tempAbsBasePath'

-- Get socketPath
socketPathAbs <- do
socketPath' <- H.noteShowM $ H.sprocketArgumentName <$> H.headM (poolSprockets runtime)
socketPath' <- H.sprocketArgumentName <$> H.headM (poolSprockets runtime)
H.noteIO (IO.canonicalizePath $ tempAbsPath' </> socketPath')

(_condition, treasuryValues) <- H.leftFailM . H.evalIO . runExceptT $
Expand Down

0 comments on commit 285268c

Please sign in to comment.