-
Notifications
You must be signed in to change notification settings - Fork 145
Constants arguments clean-up and shuffling lookahead #271
Conversation
6d81274
to
7c1f552
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.
CommitteeConfig
seems like a reasonable compromise. That said I'm not fully satisfied :/
|
||
epoch = slot_to_epoch(slot, epoch_length) | ||
current_epoch = state.current_epoch(epoch_length) | ||
previous_epoch = state.previous_epoch(epoch_length, genesis_epoch) |
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.
BeaconState
knows the genesis_time
and thus the genesis_slot
/epoch
. I would argue that because this is an method on the state
, that we can forgo the genesis_epoch
param here for cleanliness.
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.
Isn't genesis_time
the unix timestamp when chain starts, while genesis_slot
and (genesis_epoch
) is the offset pivot to slot
? Or do you mean, we can find a way to set genesis_slot
as a configuration inside BeaconState
, not as SSZ field?
On the other hand, it seems it can be solved by ethereum/consensus-specs#504.
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.
ahh. I see. Leave as is for now. This might change when we finish the great integer debate ethereum/consensus-specs#626
eth2/beacon/committee_helpers.py
Outdated
|
||
epoch = slot_to_epoch(slot, epoch_length) | ||
current_epoch = state.current_epoch(epoch_length) | ||
previous_epoch = state.previous_epoch(epoch_length, genesis_epoch) | ||
next_epoch = EpochNumber(current_epoch + 1) |
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.
suggest adding BeaconState.next_epoch
for symmetry
@@ -258,3 +265,46 @@ def create_mock_signed_attestations_at_slot( | |||
keymap, | |||
config.EPOCH_LENGTH, | |||
) | |||
|
|||
|
|||
def get_next_epoch_committee_assignment( |
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 simplified the logic of get_next_epoch_committee_assignment
in the latest spec release by passing in registry_change
rather than returning both values. Looks like this function is still using the outer [False, True]
loop but just returning one assignment.
@@ -111,9 +111,11 @@ def _settle_penality_to_validator_and_whistleblower( | |||
state.validator_balances[index] -= whistleblower_reward | |||
validator.penalized_epoch = slot_to_epoch(state.slot) | |||
""" | |||
EPOCH_LENGTH = committee_config.EPOCH_LENGTH |
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.
capital letters here is not consistent with config assignments in other functions (example: get_crosslink_committees_at_slot
)
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.
Yeah, I prefer to use the lower letter for consistency too.
I remember that @ChihChengLiang introduced capital letters in some other functions, and now there are two different style in the codebase. Can we unify it?
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.
Will fix them to lower cases in my existing PRs
""" | ||
Penalize the validator with the given ``index``. | ||
|
||
Exit the validator, penalize the validator, and reward the whistleblower. | ||
""" | ||
state = exit_validator(state, index, epoch_length, entry_exit_delay) | ||
EPOCH_LENGTH = committee_config.EPOCH_LENGTH |
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.
Same as above. Either way is fine imo, but we should be consistent
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.
Mostly just browsed code. Will leave it to others to verify correctness.
eth2/beacon/on_startup.py
Outdated
state.latest_index_roots, | ||
genesis_epoch % latest_index_roots_length, | ||
index_root, | ||
latest_index_roots = tuple( |
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.
equivalent to either of the following if you like them more
# using itertools.repeat
tuple(itertools.repeat(genesis_active_index_root, latest_index_roots_length))
# using tuple multiplication
(genesis_active_index_root,) * latest_index_roots_length
Co-Authored-By: hwwhww <hwwang156@gmail.com>
…och_committee_assignment`
e5421c5
to
e9561b1
Compare
What was wrong?
CommitteeConfig
How was it fixed?
1. Refactor: clean up constants arguments by adding
CommitteeConfig
Sorry for that this PR became more about refactoring than just add a new feature.
When I tried to implement #258, I have to revamp
get_crosslink_committees_at_slot
helper; and with this new feature, I have to pass four more constants intoget_crosslink_committees_at_slot
and all the function that calls it.That's a stronger signal of that some 💩 code here that we need to fix...
Per #146 (comment), I mentioned passing the shuffling-required constants into
ShufflingConfig
, but after some recent changes, it looks better to have a subset ofBeaconConfig
-CommitteeConfig
to mitigate it.BeaconConfig
inStateMachine
layer.BeaconConfig
has been moved frometh2/beacon/state_machines/configs.py
→eth2/beacon/configs.py
.While this PR is WIP, @pipermerriam @jannikluhn @ralexstokes @djrtwo , any thoughts on this refactoring?
2. Shuffling lookahead
get_crosslink_committees_at_slot
for shuffling lookahead functionget_next_epoch_committee_assignment
for the validator to check if they are assigned in the incoming epoch and the context they need.get_next_epoch_committee_assignment
returnsNoCommitteeAssignment
when no assignment for the givenvalidator_index
.Cute Animal Picture