Skip to content
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

Make clearer that the distribution iterates over all active validators #8866

Merged

Conversation

hjorthjort
Copy link
Contributor

@hjorthjort hjorthjort commented Mar 12, 2021

Description

We found that the current distribution code for distributing to all bonded validators wasn't perfectly clear, and it confused both me and @sunnya97. Here's a suggestion on how to fix that.

This fact is already reflected in the docs, but the wording in the code made us suspect there was a mismatch. I think @sunnya97 can look into and double check that req.LastCommitInfo.GetVotes() actually returns all bonded validators.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@hjorthjort hjorthjort force-pushed the hjorthjort/distribution-clarification branch from 7dee93d to fb772ae Compare March 12, 2021 17:06
@alexanderbez alexanderbez added the Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. label Mar 12, 2021
@ValarDragon
Copy link
Contributor

ValarDragon commented Mar 12, 2021

I don't think there is a bug at least, since req.LastCommitInfo.GetVotes() is all validators, see:
https://github.com/tendermint/tendermint/blob/0d0181856b3ec54946cb1fa7ce56651606de8910/state/execution.go#L366-L372

I think this could be improved by changing the naming of this, and making it not be called GetVotes to instead perhaps GetVoteStatuses? (I completely agree that the current naming makes it unclear if you're iterating over just the validators who voted, or all validators)

@hjorthjort hjorthjort changed the title Make clearer that the distribution iterates over all active validator… Make clearer that the distribution iterates over all active validators Mar 15, 2021
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
@hjorthjort
Copy link
Contributor Author

Thanks @ValarDragon for checking this. We suspected that there wasn't a bug, but it's nice to get that verified.

Do you know if this is tested with a unit test somewhere? That GetVotes supplies a list of all bonded validators, regardless of if they voted or not? That would be good to have since the distribution crucially relies on it, but the description and name doesn't really make that clear.

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the argument doc comment to the function doc comment. Also left a suggestion to use more concise name.

x/distribution/keeper/allocation.go Outdated Show resolved Hide resolved
@@ -13,7 +13,7 @@ import (
// AllocateTokens handles distribution of the collected fees
func (k Keeper) AllocateTokens(
ctx sdk.Context, sumPreviousPrecommitPower, totalPreviousPower int64,
previousProposer sdk.ConsAddress, previousVotes []abci.VoteInfo,
previousProposer sdk.ConsAddress, bondedValidatorsVoteInfo []abci.VoteInfo,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
previousProposer sdk.ConsAddress, bondedValidatorsVoteInfo []abci.VoteInfo,
previousProposer sdk.ConsAddress, bondedVotes []abci.VoteInfo,

Copy link
Collaborator

@robert-zaremba robert-zaremba Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't prefer concise names and we don't need to repeat a type name in the variable name.

@robert-zaremba
Copy link
Collaborator

Do you know if this is tested with a unit test somewhere?

Maybe it would be good to add a test?

@lgtm-com
Copy link

lgtm-com bot commented Mar 18, 2021

This pull request introduces 4 alerts when merging 41f7693 into deaee53 - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable
  • 2 for Unreachable statement

@hjorthjort
Copy link
Contributor Author

Do you know if this is tested with a unit test somewhere?

Maybe it would be good to add a test?

Looks lite the function GetVotes is auto-generated by the protobufs. So this may better be a test on the Tendermint end?

@robert-zaremba
Copy link
Collaborator

Do you know if this is tested with a unit test somewhere?

Maybe it would be good to add a test?

Looks lite the function GetVotes is auto-generated by the protobufs. So this may better be a test on the Tendermint end?

OK, could you check on Tendermint sit and create issue there if needed?

@tac0turtle tac0turtle added the A:automerge Automatically merge PR once all prerequisites pass. label Mar 29, 2021
@tac0turtle tac0turtle merged commit 7fc7b3f into cosmos:master Mar 29, 2021
@orijbot
Copy link

orijbot commented Mar 29, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants