Skip to content

Commit

Permalink
Use the new GetRewardInfoPools
Browse files Browse the repository at this point in the history
… and drop the other local state queries related to rewards.

This depends on `cardano-node` version 1.33 or later.
  • Loading branch information
HeinrichApfelmus committed Mar 23, 2022
1 parent 83bd65c commit 1283ffc
Show file tree
Hide file tree
Showing 10 changed files with 624 additions and 612 deletions.
10 changes: 10 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module Cardano.Wallet.Api.Types
, ApiBase64
, ApiMintBurnData (..)
, ApiStakePool (..)
, invariantApiStakePool
, ApiStakePoolMetrics (..)
, ApiStakePoolFlag (..)
, ApiWallet (..)
Expand Down Expand Up @@ -811,14 +812,23 @@ data ApiStakePool = ApiStakePool
, flags :: ![ApiStakePoolFlag]
} deriving (Eq, Generic, Show)

-- | The 'ApiStakePool' response contains redundant information
-- and needs to satisfy this invariant.
invariantApiStakePool :: ApiStakePool -> Bool
invariantApiStakePool r =
(OwnerStakeLowerThanPledge `elem` flags r)
== (pledge r < ownerStake (metrics r))

data ApiStakePoolFlag
= Delisted
| OwnerStakeLowerThanPledge
deriving stock (Eq, Generic, Show)
deriving anyclass NFData

data ApiStakePoolMetrics = ApiStakePoolMetrics
{ nonMyopicMemberRewards :: !(Quantity "lovelace" Natural)
, relativeStake :: !(Quantity "percent" Percentage)
, ownerStake :: !(Quantity "lovelace" Natural)
, saturation :: !Double
, producedBlocks :: !(Quantity "block" Natural)
} deriving (Eq, Generic, Show)
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import Cardano.BM.Data.Severity
( Severity (..) )
import Cardano.BM.Data.Tracer
( HasPrivacyAnnotation (..), HasSeverityAnnotation (..) )
import Cardano.Pool.Rank
( StakePoolsSummary )
import Cardano.Wallet.Primitive.BlockSummary
( LightSummary )
import Cardano.Wallet.Primitive.Slotting
Expand All @@ -55,7 +57,6 @@ import Cardano.Wallet.Primitive.Types
, ProtocolParameters
, SlotNo (..)
, SlottingParameters (..)
, StakePoolsSummary
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin )
Expand Down Expand Up @@ -160,8 +161,7 @@ data NetworkLayer m block = NetworkLayer
-- ^ Broadcast a transaction to the chain producer

, stakeDistribution
:: Coin -- Stake to consider for rewards
-> m StakePoolsSummary
:: m (Maybe StakePoolsSummary)

, getCachedRewardAccountBalance
:: RewardAccount
Expand Down
18 changes: 0 additions & 18 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ module Cardano.Wallet.Primitive.Types
, IsDelegatingTo (..)

-- * Stake Pools
, StakePoolsSummary (..)
, PoolId(..)
, PoolOwner(..)
, poolIdBytesLength
Expand Down Expand Up @@ -215,8 +214,6 @@ import Data.Kind
( Type )
import Data.List
( intercalate )
import Data.Map.Strict
( Map )
import Data.Maybe
( isJust, isNothing )
import Data.Proxy
Expand Down Expand Up @@ -253,7 +250,6 @@ import Fmt
, blockListF'
, indentF
, listF'
, mapF
, prefixF
, pretty
, suffixF
Expand All @@ -276,7 +272,6 @@ import Test.QuickCheck
import qualified Codec.Binary.Bech32 as Bech32
import qualified Codec.Binary.Bech32.TH as Bech32
import qualified Data.ByteString as BS
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import qualified Data.Text.Encoding as T

Expand Down Expand Up @@ -759,19 +754,6 @@ instance FromJSON PoolOwner where
instance ToJSON PoolOwner where
toJSON = toJSON . toText

data StakePoolsSummary = StakePoolsSummary
{ nOpt :: Int
, rewards :: Map PoolId Coin
, stake :: Map PoolId Percentage
} deriving (Show, Eq)

instance Buildable StakePoolsSummary where
build StakePoolsSummary{nOpt,rewards,stake} = listF' id
[ "Stake: " <> mapF (Map.toList stake)
, "Non-myopic member rewards: " <> mapF (Map.toList rewards)
, "Optimum number of pools: " <> pretty nOpt
]

{-------------------------------------------------------------------------------
Block
-------------------------------------------------------------------------------}
Expand Down
Loading

0 comments on commit 1283ffc

Please sign in to comment.