File tree Expand file tree Collapse file tree 6 files changed +39
-8
lines changed
conway/impl/src/Cardano/Ledger/Conway/Rules
shelley/impl/src/Cardano/Ledger/Shelley/Rules Expand file tree Collapse file tree 6 files changed +39
-8
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,6 @@ import Control.State.Transition (
7575 )
7676import Data.Map (Map )
7777import qualified Data.Map.Strict as Map
78- import Data.Maybe (isJust )
7978import Data.Set as Set
8079import Data.Void (Void )
8180import GHC.Generics (Generic )
@@ -261,11 +260,19 @@ conwayDelegTransition = do
261260 & certVStateL %~ unDelegReDelegDRep stakeCred accountState Nothing
262261 & certPStateL %~ unDelegReDelegStakePool stakeCred accountState Nothing
263262 ConwayDelegCert stakeCred delegatee -> do
264- let mAccountState = lookupAccountState stakeCred accounts
265- isJust mAccountState ?! StakeKeyNotRegisteredDELEG stakeCred
266263 checkStakeDelegateeRegistered delegatee
267- pure $
268- processDelegationInternal (pvMajor pv < natVersion @ 10 ) stakeCred mAccountState delegatee certState
264+ case lookupAccountStateIntern stakeCred accounts of
265+ Nothing -> do
266+ failBecause $ StakeKeyNotRegisteredDELEG stakeCred
267+ pure certState
268+ Just (internedCred, accountState) -> do
269+ pure $
270+ processDelegationInternal
271+ (pvMajor pv < natVersion @ 10 )
272+ internedCred
273+ (Just accountState)
274+ delegatee
275+ certState
269276 ConwayRegDelegCert stakeCred delegatee deposit -> do
270277 checkDepositAgainstPParams deposit
271278 checkStakeKeyNotRegistered stakeCred
Original file line number Diff line number Diff line change @@ -286,15 +286,15 @@ delegationTransition = do
286286 DelegStakeTxCert cred stakePool -> do
287287 -- note that pattern match is used instead of cwitness and dpool, as in the spec
288288 -- (hk ∈ dom (rewards ds))
289- case lookupAccountState cred (ds ^. accountsL) of
289+ case lookupAccountStateIntern cred (ds ^. accountsL) of
290290 Nothing -> do
291291 failBecause $ StakeDelegationImpossibleDELEG cred
292292 pure certState
293- Just accountState ->
293+ Just (internedCred, accountState) ->
294294 pure $
295295 certState
296296 & certDStateL . accountsL %~ adjustAccountState (stakePoolDelegationAccountStateL ?~ stakePool) cred
297- & certPStateL %~ unDelegReDelegStakePool cred accountState (Just stakePool)
297+ & certPStateL %~ unDelegReDelegStakePool internedCred accountState (Just stakePool)
298298 GenesisDelegTxCert gkh vkh vrf -> do
299299 sp <- liftSTS $ asks stabilityWindow
300300 -- note that pattern match is used instead of genesisDeleg, as in the spec
Original file line number Diff line number Diff line change 22
33## 1.3.0.0
44
5+ * Add ` lookupInternMap `
56* Replace ` okeyL ` with ` toOKey `
67
78## 1.2.4.1
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ module Data.MapExtras (
2828 extractKeysSmallSet ,
2929 fromKeys ,
3030 fromElems ,
31+ lookupInternMap ,
3132) where
3233
3334import Data.Foldable (toList )
@@ -270,3 +271,16 @@ fromElems f vs =
270271 -- a nice optimization for already sorted keys and with list fusion there should be no overhead
271272 Map. fromList [(f v, v) | v <- toList vs]
272273{-# INLINE fromElems #-}
274+
275+ -- | Look up a key in a map and return the interned key together with its value, if present.
276+ -- The returned key is exactly the one stored in the map.
277+ -- Useful for maximizing sharing by avoiding duplicate-but-equal keys.
278+ lookupInternMap :: Ord k => k -> Map k v -> Maybe (k , v )
279+ lookupInternMap k = go
280+ where
281+ go Tip = Nothing
282+ go (Bin _ kx v l r) =
283+ case compare k kx of
284+ LT -> go l
285+ GT -> go r
286+ EQ -> Just (kx, v)
Original file line number Diff line number Diff line change 22
33## 1.19.0.0
44
5+ * Add ` lookupAccountStateIntern ` to ` State.Account ` module
56* Add ` HasOKey ` instance for ` TxId (Tx l era) `
67* Remove ` Generic ` instance from ` BoundedRatio ` type
78* Remove deprecated function ` addrPtrNormalize `
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ module Cardano.Ledger.State.Account (
1515 CanSetAccounts (.. ),
1616 EraAccounts (.. ),
1717 lookupAccountState ,
18+ lookupAccountStateIntern ,
1819 updateLookupAccountState ,
1920 isAccountRegistered ,
2021 adjustAccountState ,
@@ -44,6 +45,7 @@ import Data.Kind (Type)
4445import qualified Data.Map.Merge.Strict as Map
4546import Data.Map.Strict (Map )
4647import qualified Data.Map.Strict as Map
48+ import Data.MapExtras (lookupInternMap )
4749import Data.Set (Set )
4850import Lens.Micro
4951import NoThunks.Class (NoThunks )
@@ -145,6 +147,12 @@ lookupAccountState ::
145147 EraAccounts era => Credential 'Staking -> Accounts era -> Maybe (AccountState era )
146148lookupAccountState cred accounts = Map. lookup cred (accounts ^. accountsMapL)
147149
150+ lookupAccountStateIntern ::
151+ EraAccounts era =>
152+ Credential 'Staking -> Accounts era -> Maybe (Credential 'Staking, AccountState era )
153+ lookupAccountStateIntern cred accounts =
154+ lookupInternMap cred (accounts ^. accountsMapL)
155+
148156-- | Update account state. Returns Nothing if the value is not present and modified value otherwise
149157updateLookupAccountState ::
150158 EraAccounts era =>
You can’t perform that action at this time.
0 commit comments