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

tx-generator: Core.hs: simplifications + better non-Byron support #6085

Merged
merged 2 commits into from
Jan 24, 2025
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
21 changes: 9 additions & 12 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Core.hs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new helper function caseByronOrShelleyBasedEra is wonderful, thanks for propagating its use onward!

Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,23 @@ cancelBenchmark = do
getLocalConnectInfo :: ActionM LocalNodeConnectInfo
getLocalConnectInfo = makeLocalConnectInfo <$> getEnvNetworkId <*> getEnvSocketPath

queryEra :: ActionM AnyCardanoEra
queryEra :: ActionM AnyShelleyBasedEra
queryEra = do
localNodeConnectInfo <- getLocalConnectInfo
chainTip <- getLocalChainTip localNodeConnectInfo
mapExceptT liftIO .
AnyCardanoEra era <- mapExceptT liftIO .
modifyError (Env.TxGenError . TxGenError . show) $
queryNodeLocalState localNodeConnectInfo (SpecificPoint $ chainTipToChainPoint chainTip) QueryCurrentEra
caseByronOrShelleyBasedEra
(liftTxGenError $ TxGenError "queryEra Byron not supported")
(return . AnyShelleyBasedEra)
era

queryRemoteProtocolParameters :: ActionM ProtocolParameters
queryRemoteProtocolParameters = do
localNodeConnectInfo <- getLocalConnectInfo
chainTip <- liftIO $ getLocalChainTip localNodeConnectInfo
era <- queryEra
AnyShelleyBasedEra sbe <- queryEra
let
callQuery :: forall era.
QueryInEra era (Ledger.PParams (ShelleyLedgerEra era))
Expand All @@ -187,22 +191,15 @@ queryRemoteProtocolParameters = do
liftIO $ BSL.writeFile pparamsFile $ prettyPrintOrdered pp'
traceDebug $ "queryRemoteProtocolParameters : query result saved in: " ++ pparamsFile
return pp'
case era of
AnyCardanoEra ByronEra -> liftTxGenError $ TxGenError "queryRemoteProtocolParameters Byron not supported"
AnyCardanoEra ShelleyEra -> callQuery $ QueryInShelleyBasedEra ShelleyBasedEraShelley QueryProtocolParameters
AnyCardanoEra AllegraEra -> callQuery $ QueryInShelleyBasedEra ShelleyBasedEraAllegra QueryProtocolParameters
AnyCardanoEra MaryEra -> callQuery $ QueryInShelleyBasedEra ShelleyBasedEraMary QueryProtocolParameters
AnyCardanoEra AlonzoEra -> callQuery $ QueryInShelleyBasedEra ShelleyBasedEraAlonzo QueryProtocolParameters
AnyCardanoEra BabbageEra -> callQuery $ QueryInShelleyBasedEra ShelleyBasedEraBabbage QueryProtocolParameters
AnyCardanoEra ConwayEra -> callQuery $ QueryInShelleyBasedEra ShelleyBasedEraConway QueryProtocolParameters
callQuery $ QueryInShelleyBasedEra sbe QueryProtocolParameters

getProtocolParameters :: ActionM ProtocolParameters
getProtocolParameters = do
getProtoParamMode >>= \case
ProtocolParameterQuery -> queryRemoteProtocolParameters
ProtocolParameterLocal parameters -> return parameters

waitForEra :: AnyCardanoEra -> ActionM ()
waitForEra :: AnyShelleyBasedEra -> ActionM ()
waitForEra era = do
currentEra <- queryEra
if currentEra == era
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ data Action where
-- with testing and quick fixes.
Reserved :: [String] -> Action
-- 'WaitForEra' loops doing delays/sleeps until the current era matches.
WaitForEra :: !AnyCardanoEra -> Action
WaitForEra :: !AnyShelleyBasedEra -> Action
-- | 'SetProtocolParameters' has one option to read from a file and
-- another to pass directly and just sets a state variable for
-- the @protoParams@ field of 'Cardano.Benchmarking.Script.Env.Env'.
Expand Down
Loading