-
Notifications
You must be signed in to change notification settings - Fork 156
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
Abstract threshold calculation #3716
Conversation
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.
LGTM 👍 Thank you!
Just an idea: may be we could make PParams
have VotingThreshold
too.
03f5eed
to
f354009
Compare
f354009
to
c342166
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.
There is something about this pattern that feels a little wrong.
I think I understand where it's coming from: for these is.*Allowed
functions, we don't actually need to know anything other than whether voting.*ThresholdInternal
returns NoVotingAllowed
, while returning NoVotingAllowed
in voting.*ThresholdInternal
functions does not depend on the value of other parameters like pparam
, isElectedCommittee
or committee
.
So in theory,
for isStakePoolVotingAllowed
we could return True,
for isCommitteeVotingAllowed
we could return True if the action is NoConfidence or NewCommittee
and
for isDRepVotingAllowed
we could return True
,if I understand correctly the code.
But then this would mean we duplicate the logic between determining whether the voting is allowed and computing the actual threshold.
Semantically these parameters are optional (pparam
, isElectedCommittee
or committee
), but I can see how making them optional is not gonna help.
On the other hand, passing emptyPparams
makes it seem like we might depend on the value of the default value of the parameters.
Could we somehow extract this information (i.e.: what makes different actions return NoVotingAllowed) and then use it from both places?
I don't have a concrete idea for refactoring, just sharing my thoughts on this. Maybe we can think of a way to refactor it later if it's not the time for it now.
@teodanciu Good thing that coding is about facts, not feelings 😜. I think you getting the same feeling some people get about the
I don't understand this comment. The whole point of this PR is to prevent duplication of logic in two places: figuring the thresholds and figuring out whether voting is allowed or not. Which, I believe, implementation in this PR successfully avoids duplication.
They are optional for figuring out whether voting is allowed or not, but they are required for figuring out the thresholds. In fact I could use
We could pass
Previous implementation did not allow us to reuse this logic at all for the two different use cases. This was my attempt at making it possible. I know of a way to make it possible to completely avoid using default values for arguments, namely use types that return functions that can be later either applied to arguments. This is an approach one would do in a strict language. However that would result in a more complex solution and more boiler plate, since it would require more types. Luckily for us Haskell is a lazy language, so we don't need to worry about creating more elaborate solutions in order to avoid redundant computation.
We can always try to improve the code later. Most importantly this whole logic is localized to one module, so we don't need to worry about affecting any rules in a breaking way. |
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.
Looks good to me
We need to have ability to answer if voting is allowed for a particilar entity by reusing the current threshold calculation logic, thus reducing duplication. This is needed for #3685
c342166
to
565e8ef
Compare
Description
We need to have ability to answer if voting is allowed for a particular entity by reusing the current threshold calculation logic, thus reducing duplication. This is needed for #3685
Checklist
.cabal
andCHANGELOG.md
files according to theversioning process.
.cabal
files for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)CHANGELOG.md
for the affected packages. New section is never added with the code changes. (See RELEASING.md)fourmolu
(usescripts/fourmolize.sh
)scripts/cabal-format.sh
)hie.yaml
has been updated (usescripts/gen-hie.sh
)