Skip to content

Commit 2e19dc5

Browse files
authored
Merge pull request #5270 from IntersectMBO/td/intern-vrf-counters
Intern VRF Key Hash counters in CBOR deserializer
2 parents ad2b3fd + f2b4fa1 commit 2e19dc5

File tree

4 files changed

+16
-11
lines changed
  • eras
  • libs
    • cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding
    • cardano-ledger-core/src/Cardano/Ledger/State

4 files changed

+16
-11
lines changed

eras/conway/impl/src/Cardano/Ledger/Conway/State/CertState.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import qualified Data.Foldable as F
5151
import Data.Map.Strict (Map)
5252
import qualified Data.Map.Strict as Map
5353
import GHC.Generics (Generic)
54-
import Lens.Micro (Lens', lens, (&), (.~), (^.), _2)
54+
import Lens.Micro (Lens', lens, (&), (.~), (^.))
5555
import NoThunks.Class (NoThunks (..))
5656

5757
data ConwayCertState era = ConwayCertState
@@ -167,7 +167,9 @@ instance EraAccounts era => DecShareCBOR (ConwayCertState era) where
167167
conwayCertVState <-
168168
decSharePlusLensCBOR $
169169
lens (\(cs, _, cd, ch) -> (cs, cd, ch)) (\(_, ks, _, _) (cs, cd, ch) -> (cs, ks, cd, ch))
170-
conwayCertPState <- decSharePlusLensCBOR _2
170+
conwayCertPState <-
171+
decSharePlusLensCBOR $
172+
lens (\(_, ks, _, _) -> (mempty, ks)) (\(cs, _, cd, ch) (_, ks) -> (cs, ks, cd, ch))
171173
conwayCertDState <-
172174
decSharePlusLensCBOR $
173175
lens (\(cs, ks, cd, _) -> (cs, ks, cd)) (\(_, _, _, ch) (cs, ks, cd) -> (cs, ks, cd, ch))

eras/shelley/impl/src/Cardano/Ledger/Shelley/State/CertState.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import Data.Default (Default (..))
4242
import qualified Data.Foldable as F
4343
import qualified Data.Map.Strict as Map
4444
import GHC.Generics (Generic)
45-
import Lens.Micro (Lens', lens, (&), (.~), (^.), _2)
45+
import Lens.Micro (Lens', lens, (&), (.~), (^.))
4646
import NoThunks.Class (NoThunks (..))
4747

4848
data ShelleyCertState era = ShelleyCertState
@@ -133,7 +133,9 @@ instance EraAccounts era => DecShareCBOR (ShelleyCertState era) where
133133
, Interns (Credential 'HotCommitteeRole)
134134
)
135135
decSharePlusCBOR = decodeRecordNamedT "ShelleyCertState" (const 2) $ do
136-
shelleyCertPState <- decSharePlusLensCBOR _2
136+
shelleyCertPState <-
137+
decSharePlusLensCBOR $
138+
lens (\(_, ks, _, _) -> (mempty, ks)) (\(cs, _, cd, ch) (_, ks) -> (cs, ks, cd, ch))
137139
shelleyCertDState <-
138140
decSharePlusLensCBOR $
139141
lens (\(cs, ks, cd, _) -> (cs, ks, cd)) (\(_, _, _, ch) (cs, ks, cd) -> (cs, ks, cd, ch))

libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/Sharing.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ decShareLensCBOR l = do
174174
lift $ decShareCBOR (s ^. l)
175175

176176
-- | Using this function it is possible to compose two lenses. One will extract
177-
-- a value and another will used it for placing it into a empty monoid. Here is
178-
-- an example of how a second element of a tuple can be projected on the third
177+
-- a value and another will place it into an empty monoid.
178+
-- Here is an example of how a second element of a tuple can be projected on the third
179179
-- element of a 3-tuple.
180180
--
181181
-- > toMemptyLens _3 _2 == lens (\(_, b) -> (mempty, mempty, b)) (\(a, _) (_, _, b) -> (a, b))

libs/cardano-ledger-core/src/Cardano/Ledger/State/CertState.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,13 @@ instance Era era => EncCBOR (PState era) where
247247
encodeListLen 4 <> encCBOR a <> encCBOR b <> encCBOR c <> encCBOR d
248248

249249
instance DecShareCBOR (PState era) where
250-
type Share (PState era) = Interns (KeyHash 'StakePool)
250+
type Share (PState era) = (Interns (VRFVerKeyHash 'StakePoolVRF), Interns (KeyHash 'StakePool))
251+
251252
decSharePlusCBOR = decodeRecordNamedT "PState" (const 4) $ do
252-
psVRFKeyHashes <- lift decCBOR
253-
psStakePools <- decSharePlusLensCBOR (toMemptyLens _1 id)
254-
psFutureStakePools <- decSharePlusLensCBOR (toMemptyLens _1 id)
255-
psRetiring <- decSharePlusLensCBOR (toMemptyLens _1 id)
253+
psVRFKeyHashes <- decSharePlusLensCBOR (toMemptyLens _1 _1)
254+
psStakePools <- decSharePlusLensCBOR (toMemptyLens _1 _2)
255+
psFutureStakePools <- decSharePlusLensCBOR (toMemptyLens _1 _2)
256+
psRetiring <- decSharePlusLensCBOR (toMemptyLens _1 _2)
256257
pure PState {psVRFKeyHashes, psStakePools, psFutureStakePools, psRetiring}
257258

258259
instance (Era era, DecShareCBOR (PState era)) => DecCBOR (PState era) where

0 commit comments

Comments
 (0)