-
Notifications
You must be signed in to change notification settings - Fork 157
Stop using UMap
in favor of Accounts
type family
#5128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
0fa485d
to
ca95503
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first pass, will have another look later! Looks great, I finally feel I can be friends with DState 😆
-- or not. | ||
addAccountState :: Credential 'Staking -> AccountState era -> Accounts era -> Accounts era | ||
|
||
accountsMapL :: Lens' (Accounts era) (Map (Credential 'Staking) (AccountState era)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to follow the naming convention of the other lenses, how about:
accountStateAccountsL
? too verbose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think this will work, because it is important that it returns a Map
.
Every operation that happens after usage of this lens expects a Map
.
Also, technically it would have to be plural: either accountStatesAccountsL
or accountsStatesAccountsL
. In any case, it would be much harder to read it, since there are too many "accounts" in the name 😄 Also, I believe it would be harder to understand what the hell this lens does.
rewardAccounts_ :: Map.Map (KeyHash 'StakePool) (RewardAccount, Coin) | ||
rewardAccounts_ = Map.intersectionWith (,) rewardAccounts retiringDeposits | ||
rewardAccounts' :: Map.Map RewardAccount Coin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These names are terrible, why not something like:
rewardAccounts_ :: Map.Map (KeyHash 'StakePool) (RewardAccount, Coin) | |
rewardAccounts_ = Map.intersectionWith (,) rewardAccounts retiringDeposits | |
rewardAccounts' :: Map.Map RewardAccount Coin | |
rewardAccountsWithCoin :: Map.Map (KeyHash 'StakePool) (RewardAccount, Coin) | |
rewardAccountsWithCoin = Map.intersectionWith (,) rewardAccounts retiringDeposits | |
coinsByRewardAccount :: Map.Map RewardAccount Coin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor corrections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few more minor suggestions
rewardAccount | ||
(packageLeaderReward poolRI) | ||
acc | ||
|| account `Map.member` accountsMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here we could use
|| account `Map.member` accountsMap | |
| isAccountRegistered account ( ls ^. lsCertStateL . certDStateL . accountsL) |
but it's more verbose, so not necessarily worth it, just if we wanted to reinforce the Accounts terminology
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice suggestion, I'll adjust it a tiny bit:
|| account `Map.member` accountsMap | |
|| isAccountRegistered account accounts |
toShelleyAccountsPairs :: Aeson.KeyValue e a => ShelleyAccounts era -> [a] | ||
toShelleyAccountsPairs sas@(ShelleyAccounts _ _) = | ||
let ShelleyAccounts {..} = sas | ||
in [ "credentials" .= saStates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "credentials" accurate here? Maybe more like "states" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am worried a bit about breakage downstream, but I 100% agree with you that it is a terrible name, so I am very much leaning towards your suggestion of changing it.
eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/Deposits.hs
Outdated
Show resolved
Hide resolved
@@ -158,75 +159,33 @@ newLab b cs = | |||
-- 1) do not give this function duplicates in the 'stakes' or 'pools' inputs. | |||
-- 2) do not use this function when crossing the epoch boundary, | |||
-- instead use 'newEpoch'. | |||
feesAndDeposits :: | |||
addPoolDeposits :: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand well what this function was doing before, but it looks like the haddock for it no longer matches the implementation. So maybe we can remove it or change it to something like:
addPoolDeposits :: | |
Add deposits for new pools and adjust the deposit tables in the UTxOState and CertState accordingly. | |
addPoolDeposits :: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed the haddock, which hopefully makes it clearer what this function now does:
-- | Add new pools while updating the deposit pot
(scSPools stakeCredentials, scRewards stakeCredentials) | ||
where | ||
stakeCredentials = domRestrictedStakeCredentials creds umap | ||
|
||
-- | Uses `filterStakePoolDelegsAndRewards` to get the same information from the `NewEpochState` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment no longer holds
-- | Uses `filterStakePoolDelegsAndRewards` to get the same information from the `NewEpochState` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That a huge piece of work!! I think it's a great improvement in terms of understanding not only what we store/map but also how to work with it, thanks to the clear interface.
I admit I got lost with the Transition
modules, I don't understand at all what they're about, but that's on me, I shall study them.
Looks good to me, great work!
6c37635
to
afaa57f
Compare
f802c1e
to
5eeb3a8
Compare
… AccountStates Simplify Transition and reuse it in shelley-test Add mkTestAccountState and addAccountState
Reworked some messages when things fail. Removed some unused imports that were not necessary. Changed Test.Cardano.Ledger.Constrained.Conway.LedgerTypes.Specs, by changing conwayCertStateSpec to pass one component of PState through reify to DState and then pass one component of DState though reify to VState. This replaces the use of two exists. Made some small chages to MiniTrace. Added Witnessing the rng of a map that was ConwayAccountState. Added some Winessed instances that deal with AccountState type family and its instances.
Fix mkConwayTestAccountState which was calling era if the DRep was delegated.
0587e7f
to
c45599a
Compare
Description
Resolves #4694
Checklist
CHANGELOG.md
files updated for packages with externally visible changes.NOTE: New section is never added with the code changes. (See RELEASING.md).
.cabal
andCHANGELOG.md
files when necessary, according to theversioning process.
.cabal
files updated when necessary.NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
scripts/fourmolize.sh
).scripts/cabal-format.sh
).scripts/gen-cddl.sh
)hie.yaml
updated (usescripts/gen-hie.sh
).