Skip to content

Commit

Permalink
do not use a Map for pool owners! We need to preserve the list order …
Browse files Browse the repository at this point in the history
…for zipping correctly!
  • Loading branch information
KtorZ committed Dec 11, 2019
1 parent 62b4db6 commit 8bc319b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Pool/Metrics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ newStakePoolLayer db@DBLayer{..} nl tr = StakePoolLayer
pure $ replicate (length poolIds) Nothing
Right metas -> do
let res = associateMetadata
(Map.fromList $ zip poolIds owners)
(zip poolIds owners)
(zip owners' metas)
mapM_ (logTrace tr . fst) res
pure $ map snd res
Expand Down Expand Up @@ -546,13 +546,13 @@ count = Map.map (Quantity . fromIntegral . length)
--
-- It also provides a log message for each association.
associateMetadata
:: Map PoolId [PoolOwner]
:: [(PoolId, [PoolOwner])]
-- ^ Ordered mapping from pool to owner(s).
-> [(PoolOwner, Maybe StakePoolMetadata)]
-- ^ Association between owner and metadata
-> [(StakePoolLayerMsg, Maybe StakePoolMetadata)]
associateMetadata poolOwners ownerMeta =
map (uncurry getResult . fmap associate) $ Map.toList poolOwners
map (uncurry getResult . fmap associate) poolOwners
where
-- Filter the metadata to just the entries which were submitted by the given
-- owners.
Expand Down
10 changes: 5 additions & 5 deletions lib/core/test/unit/Cardano/Pool/MetricsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ arbitraryChunks xs = do

associateMetadataSpec :: Spec
associateMetadataSpec = describe "associateMetadata" $ do
let mkMetadata owner@(PoolOwner bs) tckr = StakePoolMetadata
let mkMetadata owner tckr = StakePoolMetadata
{ owner = owner
, ticker = unsafeFromText tckr
, name = tckr
Expand All @@ -519,14 +519,14 @@ associateMetadataSpec = describe "associateMetadata" $ do
let pid = PoolId "1"

let res = associateMetadata
(Map.fromList [(pid, [owner])])
[(pid, [owner])]
[(owner, Just md)]

res `shouldBe` [(MsgMetadataUsing pid owner md, Just md)]

it "missing metadata" $ do
let res = associateMetadata
(Map.fromList [(PoolId "1", [PoolOwner "a"])])
[(PoolId "1", [PoolOwner "a"])]
[(PoolOwner "a", Nothing)]

res `shouldBe` [(MsgMetadataMissing (PoolId "1"), Nothing)]
Expand All @@ -535,7 +535,7 @@ associateMetadataSpec = describe "associateMetadata" $ do
let mda = mkMetadata (PoolOwner "a") "AAAA"
let mdb = mkMetadata (PoolOwner "b") "AAAA"
let [(msg, res)] = associateMetadata
(Map.fromList [(PoolId "1", [PoolOwner "a", PoolOwner "b"])])
[(PoolId "1", [PoolOwner "a", PoolOwner "b"])]
[ (PoolOwner "a", Just mda)
, (PoolOwner "b", Just mdb)
]
Expand All @@ -555,7 +555,7 @@ associateMetadataSpec = describe "associateMetadata" $ do
let mdb = mkMetadata (PoolOwner "b") "BBBB"

let res = associateMetadata
(Map.fromList [(PoolId "1", [PoolOwner "a", PoolOwner "b"])])
[(PoolId "1", [PoolOwner "a", PoolOwner "b"])]
[ (PoolOwner "a", Just mda)
, (PoolOwner "b", Just mdb)
]
Expand Down

0 comments on commit 8bc319b

Please sign in to comment.