-
Notifications
You must be signed in to change notification settings - Fork 146
Implement update_validator_registry
and seek for a quick review
#314
Conversation
@@ -812,8 +822,206 @@ def _check_if_update_validator_registry(state: BeaconState, | |||
return True, num_shards_in_committees | |||
|
|||
|
|||
def update_validator_registry(state: BeaconState) -> BeaconState: | |||
# TODO | |||
def is_ready_to_active(state: BeaconState, |
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.
nitpick (spelling): s/active/activate/
may want to hold off if you think this function will not end up in the final PR
@hwwhww i prefer the primary benefits come via ease of understanding/comprehension and ease of testing (the more names you have for a thing, the more control you have over it; here we go from no names for the subroutines to having at least one name.) the main argument against this implementation is some perceived difficulty in understanding. i would contend that there is a bit more upfront grokking required ("ok, what are these functions, how are they being used in the callee") but once that cost is incurred, all downstream maintenance is much easier. since you seem concerned about the something like: # in `update_validator_registry`
churn_fn = lambda state, index: activate_validator(state, index, False, config.GENESIS_EPOCH, config.SLOTS_PER_EPOCH, config.ACTIVATION_EXIT_DELAY)
state = churn_validators(
state=state,
config=config,
check_should_churn_fn=is_ready_to_active,
churn_fn=churn_fn,
current_epoch=current_epoch,
max_balance_churn=max_balance_churn,
) you could do something similar w/ we could also make this into a "factory function" but i don't think it's necessary here given how simple this closure is.... ( but for completeness, by factory function i just mean something like: def mk_f(f, args):
@functools.wraps(f)
def g(state, index):
f(state, index, *args)
return g ) btw i think what is already here is fine, altho i was asking myself at first why duplicate some of the config constants edit: another point to consider is that the overarching structure of this function is less likely to change given the status of the phase 0 spec, while the parts that are more likely to change are the exact details (which we have already started to abstract behind a barrier w/ the use of higher-order funcs in |
1aa2fe3
to
78ed252
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.
I generally agree with @ralexstokes. update_validator_registry
might be considered overkill by some, but I found it very easy to read/review.
exiting_index = 0 | ||
|
||
activating_validator = ValidatorRecord.create_pending_validator( | ||
b'\x10' * 48, |
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.
Use positional args here
a2a4f77
to
d85cd69
Compare
@ralexstokes @djrtwo thanks for the feedback! I like |
d85cd69
to
5f40426
Compare
What was wrong?
Part of #223
update_validator_registry
How was it fixed?
I found that I need to finish #306 to upgrade it to the latest version.
But meanwhile, I implemented two versions of
update_validator_registry
and hope to get some suggestions/advices:update_validator_registry_2
:update_validator_registry_2
is similar to the spec: https://github.com/ethereum/eth2.0-specs/blob/dev/specs/core/0_beacon-chain.md#validator-registry-and-shuffling-seed-data:update_validator_registry
: there are some logic that could be refactored inupdate_validator_registry_2
, so I madeupdate_validator_registry
… but after I finished it, it’s still not ideal since the arguments are not exactly the same.What do you think about
update_validator_registry
v.s.update_validator_registry_2
?Any feedback would be appreciated. 🙏
Cute Animal Picture