Skip to content

Commit

Permalink
Make query pool-params behave the same as query pool-state, but make …
Browse files Browse the repository at this point in the history
…it hidden
  • Loading branch information
newhoggy committed Jul 19, 2022
1 parent 8c1d6c9 commit 0df5d04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 69 deletions.
2 changes: 0 additions & 2 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ data QueryCmd =
| QueryDebugLedgerState' AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryProtocolState' AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryStakeSnapshot' AnyConsensusModeParams NetworkId (Hash StakePoolKey)
| QueryPoolParams' AnyConsensusModeParams NetworkId (Hash StakePoolKey)
| QueryKesPeriodInfo
AnyConsensusModeParams
NetworkId
Expand All @@ -391,7 +390,6 @@ renderQueryCmd cmd =
QueryDebugLedgerState' {} -> "query ledger-state"
QueryProtocolState' {} -> "query protocol-state"
QueryStakeSnapshot' {} -> "query stake-snapshot"
QueryPoolParams' {} -> "query pool-params"
QueryKesPeriodInfo {} -> "query kes-period-info"
QueryPoolState' {} -> "query pool-state"

Expand Down
14 changes: 6 additions & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,8 @@ pQueryCmd =
(Opt.info pQueryProtocolState $ Opt.progDesc "Dump the current protocol state of the node (Ledger.ChainDepState -- advanced command)")
, subParser "stake-snapshot"
(Opt.info pQueryStakeSnapshot $ Opt.progDesc "Obtain the three stake snapshots for a pool, plus the total active stake (advanced command)")
, subParser "pool-params"
(Opt.info pQueryPoolParams $ Opt.progDesc "DEPRECATE. Use query pool-state instead. Dump the pool parameters (Ledger.NewEpochState.esLState._delegationState._pState._pParams -- advanced command)")
, hiddenSubParser "pool-params"
(Opt.info pQueryPoolState $ Opt.progDesc "DEPRECATED. Use query pool-state instead. Dump the pool parameters (Ledger.NewEpochState.esLState._delegationState._pState._pParams -- advanced command)")
, subParser "leadership-schedule"
(Opt.info pLeadershipSchedule $ Opt.progDesc "Get the slots the node is expected to mint a block in (advanced command)")
, subParser "kes-period-info"
Expand Down Expand Up @@ -1005,12 +1005,6 @@ pQueryCmd =
<*> pNetworkId
<*> pStakePoolVerificationKeyHash

pQueryPoolParams :: Parser QueryCmd
pQueryPoolParams = QueryPoolParams'
<$> pConsensusModeParams
<*> pNetworkId
<*> pStakePoolVerificationKeyHash

pQueryPoolState :: Parser QueryCmd
pQueryPoolState = QueryPoolState'
<$> pConsensusModeParams
Expand Down Expand Up @@ -3319,3 +3313,7 @@ readerFromParsecParser p =
subParser :: String -> ParserInfo a -> Parser a
subParser availableCommand pInfo =
Opt.hsubparser $ Opt.command availableCommand pInfo <> Opt.metavar availableCommand

hiddenSubParser :: String -> ParserInfo a -> Parser a
hiddenSubParser availableCommand pInfo =
Opt.hsubparser $ Opt.command availableCommand pInfo <> Opt.metavar availableCommand <> Opt.hidden
61 changes: 2 additions & 59 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ import qualified Cardano.Ledger.Era as Ledger
import Cardano.Ledger.Keys (KeyHash (..), KeyRole (..))
import Cardano.Ledger.Shelley.Constraints
import Cardano.Ledger.Shelley.EpochBoundary
import Cardano.Ledger.Shelley.LedgerState (DPState (..),
EpochState (esLState, esSnapshots), LedgerState (..), NewEpochState (nesEs),
PState (_fPParams, _pParams, _retiring))
import Cardano.Ledger.Shelley.LedgerState (EpochState (esSnapshots),
NewEpochState (nesEs), PState (_fPParams, _pParams, _retiring))
import qualified Cardano.Ledger.Shelley.LedgerState as SL
import qualified Cardano.Ledger.Shelley.PParams as Shelley
import Cardano.Ledger.Shelley.Scripts ()
Expand Down Expand Up @@ -190,8 +189,6 @@ runQueryCmd cmd =
runQueryLedgerState consensusModeParams network mOutFile
QueryStakeSnapshot' consensusModeParams network poolid ->
runQueryStakeSnapshot consensusModeParams network poolid
QueryPoolParams' consensusModeParams network poolid ->
runQueryPoolParams consensusModeParams network poolid
QueryProtocolState' consensusModeParams network mOutFile ->
runQueryProtocolState consensusModeParams network mOutFile
QueryUTxO' consensusModeParams qFilter networkId mOutFile ->
Expand Down Expand Up @@ -598,32 +595,6 @@ renderOpCertIntervalInformation opCertFile
" Operational certificate's starting KES period: " <> show start <> "\n" <>
" Operational certificate's expiry KES period: " <> show end

-- | Query the current and future parameters for a stake pool, including the retirement date.
-- Any of these may be empty (in which case a null will be displayed).
--
runQueryPoolParams
:: AnyConsensusModeParams
-> NetworkId
-> Hash StakePoolKey
-> ExceptT ShelleyQueryCmdError IO ()
runQueryPoolParams (AnyConsensusModeParams cModeParams) network poolIds = do
liftIO . IO.hPutStrLn IO.stderr $ "WARNING: The query pool-params command is deprecated. Use query pool-state instead"

SocketPath sockPath <- firstExceptT ShelleyQueryCmdEnvVarSocketErr readEnvSocketPath
let localNodeConnInfo = LocalNodeConnectInfo cModeParams network sockPath

anyE@(AnyCardanoEra era) <- determineEra cModeParams localNodeConnInfo
let cMode = consensusModeOnly cModeParams
sbe <- getSbe $ cardanoEraStyle era

eInMode <- toEraInMode era cMode
& hoistMaybe (ShelleyQueryCmdEraConsensusModeMismatch (AnyConsensusMode cMode) anyE)

let qInMode = QueryInEra eInMode . QueryInShelleyBasedEra sbe $ QueryDebugLedgerState
result <- executeQuery era cModeParams localNodeConnInfo qInMode
obtainLedgerEraClassConstraints sbe (writePoolParams poolIds) result


-- | Query the current and future parameters for a stake pool, including the retirement date.
-- Any of these may be empty (in which case a null will be displayed).
--
Expand Down Expand Up @@ -859,34 +830,6 @@ getAllStake (SnapShot stake _ _) = activeStake
where
Coin activeStake = fold (fmap fromCompact (VMap.toMap (unStake stake)))

-- | This function obtains the pool parameters, equivalent to the following jq query on the output of query ledger-state
-- .nesEs.esLState._delegationState._pstate._pParams.<pool_id>
writePoolParams :: forall era ledgerera. ()
=> ShelleyLedgerEra era ~ ledgerera
=> FromCBOR (DebugLedgerState era)
=> Crypto.Crypto (Era.Crypto ledgerera)
=> Era.Crypto ledgerera ~ StandardCrypto
=> PoolId
-> SerialisedDebugLedgerState era
-> ExceptT ShelleyQueryCmdError IO ()
writePoolParams (StakePoolKeyHash hk) qState =
case decodeDebugLedgerState qState of
-- In the event of decode failure print the CBOR instead
Left bs -> firstExceptT ShelleyQueryCmdHelpersError $ pPrintCBOR bs

Right ledgerState -> do
let DebugLedgerState snapshot = ledgerState

let poolState :: PState StandardCrypto
poolState = dpsPState . lsDPState $ esLState $ nesEs snapshot

-- Pool parameters
let poolParams = Map.lookup hk $ _pParams poolState
let fPoolParams = Map.lookup hk $ _fPParams poolState
let retiring = Map.lookup hk $ _retiring poolState

liftIO . LBS.putStrLn $ encodePretty $ Params poolParams fPoolParams retiring

-- | This function obtains the pool parameters, equivalent to the following jq query on the output of query ledger-state
-- .nesEs.esLState._delegationState._pstate._pParams.<pool_id>
writePoolState :: forall era ledgerera. ()
Expand Down

0 comments on commit 0df5d04

Please sign in to comment.