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

Put validator balances into a separate list in the state #1677

Merged
merged 1 commit into from
Dec 27, 2018

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Dec 26, 2018

What was wrong?

Fixes #1647

How was it fixed?

Put ValidatorRecord.balance: int to BeaconState.validator_balances: Sequence[int].

Cute Animal Picture

iguana_wish_you_a_merry_christmas_card-r47b27aa002bc4616a76125640f7648d1_xvuak_8byvr_540

Copy link
Contributor

@ChihChengLiang ChihChengLiang left a 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. Only a minor comment.

tests/beacon/types/test_states.py Show resolved Hide resolved
@hwwhww hwwhww merged commit 1f7172a into ethereum:master Dec 27, 2018
Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

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

Some post-merge cleanup that could be done.

@@ -350,11 +350,12 @@ def get_attestation_participants(state: 'BeaconState',
#
# Misc
#
def get_effective_balance(validator: 'ValidatorRecord', max_deposit: int) -> int:
def get_effective_balance(validator_balances: Sequence[int], index: int, max_deposit: int) -> int:
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to change the variable name here to max_deposit_gwei or max_deposit_in_gwei so that it is explicit what the units are.

This fits into an architecture category that we've run into multiple times with addresses, hex/byte strings, integer/bytes representations of stack items. In each of these cases we constantly had trouble until we established a canonical representation and ensured that there were very explicit and clear boundaries where things were converted.

In this case, we have a value which is expressed in gwei but which it appears we need to run computations on it in wei (or maybe the ther way around). I think the current approach is going to prove problematic as it is very likely that at some point someone will chain together a few helper APIs and units are going to be mixed. I'd suggest converting all of these APIs to either operate on wei or gwei and establish a firm boundary where the conversions happen. Anything else is very likely to result in accidental bugs.

balance=5566,
],
validator_balances=[
100
Copy link
Member

Choose a reason for hiding this comment

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

FYI, slightly more concise way to do this:

  • tuple(itertools.repeat(100, validator_registry_len))
  • (100,) * validator_registry_len

]
],
validator_balances=(
max_deposit
Copy link
Member

Choose a reason for hiding this comment

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

Same: (max_deposit,) * 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Put validator balances into a separate list in the state
3 participants