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

Augment of query spo-stake-distribution to include the DRep delegation choices of the Pool's rewards accounts #990

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2024-10-11T15:49:11Z
, cardano-haskell-packages 2024-12-05T13:51:16Z
, cardano-haskell-packages 2024-12-19T20:16:27Z

packages:
cardano-cli
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ library
binary,
bytestring,
canonical-json,
cardano-api ^>=10.4,
cardano-api ^>=10.5,
cardano-binary,
cardano-crypto,
cardano-crypto-class ^>=2.1.2,
Expand Down
131 changes: 108 additions & 23 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
Dismissed Show dismissed Hide dismissed
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

Expand Down Expand Up @@ -57,6 +58,7 @@ import Cardano.CLI.Types.Output (QueryDRepStateOutput (..))
import qualified Cardano.CLI.Types.Output as O
import Cardano.Crypto.Hash (hashToBytesAsHex)
import qualified Cardano.Crypto.Hash.Blake2b as Blake2b
import Cardano.Prelude (catMaybes)
import Cardano.Slotting.EpochInfo (EpochInfo (..), epochInfoSlotToUTCTime, hoistEpochInfo)
import Cardano.Slotting.Time (RelativeTime (..), toRelativeTime)

Expand Down Expand Up @@ -565,7 +567,7 @@ runQueryKesPeriodInfoCmd
case Map.lookup (coerce blockIssuerHash) opCertCounterMap of
-- Operational certificate exists in the protocol state
-- so our ondisk op cert counter must be greater than or
-- equal to what is in the node state
-- equal to what is in the node state.
Just ptclStateCounter -> return (OpCertOnDiskCounter onDiskOpCertCount, Just $ OpCertNodeStateCounter ptclStateCounter)
Nothing -> return (OpCertOnDiskCounter onDiskOpCertCount, Nothing)

Expand Down Expand Up @@ -874,6 +876,40 @@ runQueryStakeAddressInfoCmd
=> Cmd.QueryStakeAddressInfoCmdArgs
-> ExceptT QueryCmdError IO ()
runQueryStakeAddressInfoCmd
[email protected]
{ Cmd.commons =
Cmd.QueryCommons
{ Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
, Cmd.target
}
, Cmd.mOutFile
} = do
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath
AnyCardanoEra era <-
firstExceptT
QueryCmdAcquireFailure
(newExceptT $ executeLocalStateQueryExpr localNodeConnInfo target queryCurrentEra)
& onLeft (left . QueryCmdUnsupportedNtcVersion)
sbe <- requireShelleyBasedEra era & onNothing (left QueryCmdByronEra)

said <- callQueryStakeAddressInfoCmd cmd

writeStakeAddressInfo sbe said mOutFile

-- | Container for data returned by 'callQueryStakeAddressInfoCmd'
data StakeAddressInfoData = StakeAddressInfoData
{ rewards :: DelegationsAndRewards
, deposits :: Map StakeAddress Lovelace
, delegatees :: Map StakeAddress (L.DRep L.StandardCrypto)
}

callQueryStakeAddressInfoCmd
:: ()
=> Cmd.QueryStakeAddressInfoCmdArgs
-> ExceptT QueryCmdError IO StakeAddressInfoData
callQueryStakeAddressInfoCmd
Cmd.QueryStakeAddressInfoCmdArgs
{ Cmd.commons =
Cmd.QueryCommons
Expand All @@ -883,7 +919,6 @@ runQueryStakeAddressInfoCmd
, Cmd.target
}
, Cmd.addr = StakeAddress _ addr
, Cmd.mOutFile
} = do
CarlosLopezDeLara marked this conversation as resolved.
Show resolved Hide resolved
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath

Expand All @@ -908,13 +943,12 @@ runQueryStakeAddressInfoCmd
stakeVoteDelegatees <- monoidForEraInEonA era $ \ceo ->
easyRunQuery (queryStakeVoteDelegatees ceo stakeAddr)

return $ do
writeStakeAddressInfo
sbe
mOutFile
(DelegationsAndRewards (stakeRewardAccountBalances, stakePools))
(Map.mapKeys (makeStakeAddress networkId) stakeDelegDeposits)
(Map.mapKeys (makeStakeAddress networkId) stakeVoteDelegatees)
return $
return $
StakeAddressInfoData
(DelegationsAndRewards (stakeRewardAccountBalances, stakePools))
(Map.mapKeys (makeStakeAddress networkId) stakeDelegDeposits)
(Map.mapKeys (makeStakeAddress networkId) stakeVoteDelegatees)
CarlosLopezDeLara marked this conversation as resolved.
Show resolved Hide resolved
)
& onLeft (left . QueryCmdAcquireFailure)
& onLeft left
Expand All @@ -923,19 +957,18 @@ runQueryStakeAddressInfoCmd

writeStakeAddressInfo
:: ShelleyBasedEra era
-> StakeAddressInfoData
-> Maybe (File () Out)
-> DelegationsAndRewards
-> Map StakeAddress Lovelace
-- ^ deposits
-> Map StakeAddress (L.DRep L.StandardCrypto)
-- ^ vote delegatees
-> ExceptT QueryCmdError IO ()
writeStakeAddressInfo
sbe
mOutFile
(DelegationsAndRewards (stakeAccountBalances, stakePools))
stakeDelegDeposits
voteDelegatees =
( StakeAddressInfoData
{ rewards = DelegationsAndRewards (stakeAccountBalances, stakePools)
, deposits = stakeDelegDeposits
, delegatees = voteDelegatees
}
)
mOutFile =
firstExceptT QueryCmdWriteFileError . newExceptT $
writeLazyByteStringOutput mOutFile (encodePretty $ jsonInfo sbe)
where
Expand Down Expand Up @@ -1638,7 +1671,7 @@ runQuerySPOStakeDistribution
Cmd.QuerySPOStakeDistributionCmdArgs
{ Cmd.eon
, Cmd.commons =
Cmd.QueryCommons
commons@Cmd.QueryCommons
{ Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
Expand All @@ -1655,9 +1688,60 @@ runQuerySPOStakeDistribution

spos <- fromList <$> mapM spoFromSource spoHashSources

spoStakeDistribution <- runQuery localNodeConnInfo target $ querySPOStakeDistribution eon spos
writeOutput mOutFile $
Map.assocs spoStakeDistribution
let beo = convert eon

spoStakeDistribution :: Map (L.KeyHash L.StakePool StandardCrypto) L.Coin <-
runQuery localNodeConnInfo target $ querySPOStakeDistribution eon spos
let poolIds :: Maybe (Set (Hash StakePoolKey)) = Just $ Set.fromList $ map StakePoolKeyHash $ Map.keys spoStakeDistribution

serialisedPoolState :: SerialisedPoolState era <-
runQuery localNodeConnInfo target $ queryPoolState beo poolIds
CarlosLopezDeLara marked this conversation as resolved.
Show resolved Hide resolved

PoolState (poolState :: (L.PState (ShelleyLedgerEra era))) <-
CarlosLopezDeLara marked this conversation as resolved.
Show resolved Hide resolved
pure (decodePoolState serialisedPoolState)
& onLeft (left . QueryCmdPoolStateDecodeError)

let spoToPoolParams
:: Map
(L.KeyHash L.StakePool StandardCrypto)
(L.PoolParams StandardCrypto) = L.psStakePoolParams poolState
rewardsAccounts
:: Map
(L.KeyHash L.StakePool StandardCrypto)
StakeCredential = Map.map (fromShelleyStakeCredential . L.raCredential . L.ppRewardAccount) spoToPoolParams
rewardsAddresses
:: Map
(L.KeyHash L.StakePool StandardCrypto)
StakeAddress = Map.map (makeStakeAddress networkId) rewardsAccounts
addressesAndRewards
:: Map
StakeAddress
(L.KeyHash L.StakePool StandardCrypto) = Map.fromList [(addr, keyHash) | (keyHash, addr) <- Map.toList rewardsAddresses]
mkQueryStakeAddressInfoCmdArgs addr =
Cmd.QueryStakeAddressInfoCmdArgs
{ Cmd.commons = commons
, addr
, mOutFile -- unused anyway. TODO tighten this by removing the field.
}
infos <-
mapM (callQueryStakeAddressInfoCmd . mkQueryStakeAddressInfoCmdArgs) $ Map.elems rewardsAddresses
let spoToDelegatee :: Map (L.KeyHash L.StakePool StandardCrypto) (L.DRep StandardCrypto) =
Map.fromList $
catMaybes $
[ fmap (,delegatee) mSpo
| info <- infos
, (addr, delegatee) <- Map.toList $ delegatees info
, let mSpo = Map.lookup addr addressesAndRewards
]
CarlosLopezDeLara marked this conversation as resolved.
Show resolved Hide resolved
toWrite =
CarlosLopezDeLara marked this conversation as resolved.
Show resolved Hide resolved
[ ( spo
, coin
, Map.lookup spo spoToDelegatee
)
| (spo, coin) <- Map.assocs spoStakeDistribution
]

writeOutput mOutFile toWrite

runQueryCommitteeMembersState
:: Cmd.QueryCommitteeMembersStateCmdArgs era
Expand Down Expand Up @@ -1870,7 +1954,8 @@ easyRunQuerySystemStart = lift querySystemStart & onLeft (left . QueryCmdUnsuppo
easyRunQuery
:: ()
=> Monad m
=> m (Either UnsupportedNtcVersionError (Either Consensus.EraMismatch a)) -> ExceptT QueryCmdError m a
=> m (Either UnsupportedNtcVersionError (Either Consensus.EraMismatch a))
-> ExceptT QueryCmdError m a
easyRunQuery q =
lift q
& onLeft (left . QueryCmdUnsupportedNtcVersion)
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading