Skip to content

Commit

Permalink
Merge #1982
Browse files Browse the repository at this point in the history
1982: Don't fetch nOpt another time r=Anviking a=Anviking

# Issue Number

#1981 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] Re-use the existing `nOpt` instead of fetching it again


# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
  • Loading branch information
iohk-bors[bot] and Anviking committed Jul 29, 2020
2 parents 761880a + dcce6c4 commit 3675ef2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ newStakePoolLayer nl db@DBLayer {..} =
-> ExceptT ErrNetworkUnavailable IO [Api.ApiStakePool]
_listPools currentEpoch userStake = do
tip <- withExceptT fromErrCurrentNodeTip $ currentNodeTip nl
lsqData <- combineLsqData <$> stakeDistribution nl tip userStake
rawLsqData <- stakeDistribution nl tip userStake
let lsqData = combineLsqData rawLsqData
dbData <- liftIO $ readPoolDbData db
pp <- liftIO $ getProtocolParameters nl
seed <- liftIO $ atomically readSystemSeed
-- TODO:
-- Use a more efficient way of filtering out retired pools.
Expand All @@ -199,7 +199,11 @@ newStakePoolLayer nl db@DBLayer {..} =
. filter (not . poolIsRetired)
. map snd
. Map.toList
<$> combineDbAndLsqData (timeInterpreter nl) pp lsqData dbData
<$> combineDbAndLsqData
(timeInterpreter nl)
(nOpt rawLsqData)
lsqData
dbData
where
fromErrCurrentNodeTip :: ErrCurrentNodeTip -> ErrNetworkUnavailable
fromErrCurrentNodeTip = \case
Expand Down Expand Up @@ -272,11 +276,11 @@ data PoolDbData = PoolDbData
combineDbAndLsqData
:: forall m. (Monad m)
=> TimeInterpreter m
-> ProtocolParameters
-> Int -- ^ nOpt; desired number of pools
-> Map PoolId PoolLsqData
-> Map PoolId PoolDbData
-> m (Map PoolId Api.ApiStakePool)
combineDbAndLsqData ti pp lsqData =
combineDbAndLsqData ti nOpt lsqData =
Map.mergeA lsqButNoDb dbButNoLsq bothPresent lsqData
where
bothPresent = zipWithAMatched mkApiPool
Expand Down Expand Up @@ -304,7 +308,7 @@ combineDbAndLsqData ti pp lsqData =
freshmanMemberRewards
= Quantity
$ average
$ L.take (fromIntegral $ desiredNumberOfStakePools pp)
$ L.take nOpt
$ L.sort
$ map (Down . getQuantity . nonMyopicMemberRewards)
$ Map.elems lsqData
Expand Down

0 comments on commit 3675ef2

Please sign in to comment.