-
Notifications
You must be signed in to change notification settings - Fork 971
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
64 epoch cleanup by @justindrake #2212
Conversation
port @JustinDrake's general cleanups from #2212
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.
My first scan. 👀
- remove
and is_matching_target
inprocess_attestation
whenappend(TIMELY_HEAD_FLAG_MASK)
I can't find it in this PR. Was it left during the previous cleanups?
# 2**26 (= 67,108,864) | ||
INACTIVITY_PENALTY_QUOTIENT: 67108864 | ||
# 2**28 (= 268,435,456) | ||
LEAK_PENALTY_QUOTIENT: 268435456 |
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.
INACTIVITY_PENALTY_QUOTIENT
was renamed here but it was not modified inphase0/beacon-chain.md
.- The phase 0 value should be
2**26 (= 67,108,864)
. - Double check: is it necessary to rename the variable of phase0?
get_inactivity_penalty_deltas
will be rewritten anyway. So we only have to rename it in HF1.- Besides that the client implementations have to change their phase 0 code, the additional documents may also need to sync the differences.
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 don't think we should rename any variables from phase 0. It's way to easy to bork test vectors and cause issues in clients, imo
|
||
### Time parameters | ||
|
||
| Name | Value | Unit | Duration | | ||
| - | - | :-: | :-: | | ||
| `EPOCHS_PER_SYNC_COMMITTEE_PERIOD` | `Epoch(2**8)` (= 256) | epochs | ~27 hours | | ||
| `EPOCHS_PER_ACTIVATION_EXIT_PERIOD` | `Epoch(2**6)` (= 64) | epochs | ~6.8 hours | | ||
| `EPOCHS_TO_LEAK_PENALTIES` | `uint64(2**2)` (= 4) | epochs | 25.6 minutes | |
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.
It was defined/renamed in phase0 spec in this PR and the value was unchanged. This line could be removed:
| `EPOCHS_TO_LEAK_PENALTIES` | `uint64(2**2)` (= 4) | epochs | 25.6 minutes | |
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.
leaving in here for now until we decide about renaming in general
@@ -99,7 +99,7 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256 | |||
# 2**8 (= 256) epochs ~27 hours | |||
SHARD_COMMITTEE_PERIOD: 256 | |||
# 2**2 (= 4) epochs 25.6 minutes | |||
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4 | |||
EPOCHS_TO_LEAK_PENALTIES: 4 |
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.
Again, want to make sure if it's a necessary change in phase 0.
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.
ditto
#### `is_leak_active` | ||
|
||
```python | ||
def is_leak_active(state: BeaconState) -> bool: | ||
return get_finality_delay(state) > EPOCHS_TO_LEAK_PENALTIES | ||
``` |
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.
It's a 100% duplicate of the phase 0 version.
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.
leaving in until we decide on cross-cutting changes on phases
process_rewards(state) | ||
process_penalties(state) |
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 can see why this change makes sense, but IMHO it's good to have multiple purpose-focused functions. It would be more flexible when we have to modify it in the future forks.
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 would tend to agree given the surgery we've had to do across forks thus far
@@ -602,21 +555,19 @@ def process_sync_committee(state: BeaconState, body: BeaconBlockBody) -> None: | |||
|
|||
### Modified helpers | |||
|
|||
#### New `compute_activation_exit_epoch` | |||
#### Modified `compute_activation_exit_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.
TODO: need to add some unit tests for it.
I'm against changing constants names from phase 0 (and especially values e.g. The general policy has been "never change constants at forks, only add new ones and update calling code". This helps keep configuration clean and avoid hard to track down changes and issues in testing (that might also surface in clients) |
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.
minor
specs/lightclient/beacon-chain.md
Outdated
def add_validator_flags(flags: ValidatorFlag, add: ValidatorFlag) -> ValidatorFlag: | ||
return flags | add | ||
def add_flag(flags: ParticipationFlags, flag_index: int) -> ParticipationFlags: | ||
flag = ParticipationFlags(2**flag_index) |
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.
flag = ParticipationFlags(2**flag_index) | |
flag = ParticipationFlags(2 ** flag_index) |
# 2**26 (= 67,108,864) | ||
INACTIVITY_PENALTY_QUOTIENT: 67108864 | ||
# 2**28 (= 268,435,456) | ||
LEAK_PENALTY_QUOTIENT: 268435456 |
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 don't think we should rename any variables from phase 0. It's way to easy to bork test vectors and cause issues in clients, imo
@@ -99,7 +99,7 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256 | |||
# 2**8 (= 256) epochs ~27 hours | |||
SHARD_COMMITTEE_PERIOD: 256 | |||
# 2**2 (= 4) epochs 25.6 minutes | |||
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4 | |||
EPOCHS_TO_LEAK_PENALTIES: 4 |
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.
ditto
|
||
### Time parameters | ||
|
||
| Name | Value | Unit | Duration | | ||
| - | - | :-: | :-: | | ||
| `EPOCHS_PER_SYNC_COMMITTEE_PERIOD` | `Epoch(2**8)` (= 256) | epochs | ~27 hours | | ||
| `EPOCHS_PER_ACTIVATION_EXIT_PERIOD` | `Epoch(2**6)` (= 64) | epochs | ~6.8 hours | | ||
| `EPOCHS_TO_LEAK_PENALTIES` | `uint64(2**2)` (= 4) | epochs | 25.6 minutes | |
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.
leaving in here for now until we decide about renaming in general
penalties = [Gwei(0)] * len(state.validators) | ||
|
||
# Only give penalties on period boundaries |
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.
The problem with removing this blocking condition is that test vectors can very strangely be generated. That is, the vectors for get_leak_penalties
specifically if run not on an epoch boundary will return non-zero values. I'd prefer keeping the blocking condition in to avoid misuse in alternative contexts even though the calling function in the spec had the conditional
this is purposeful
|
This optimization will not go into Altair. More R&D is desired before making such spec optimizations. See call notes here ethereum/eth2.0-pm#208 |
From @JustinDrake :
Pushed my review/cleanup. Largely just polishing :)
Cosmetic fixes
leak_score
toleak_scores
(for consistency withvalidators
,balances
, etc.)ValidatorFlag
toParticipationFlags
(more precise; also pluralised because as there are 8 flags)ParticipationFlags
with0b0000_0000
(instead of 0)TIMELY_HEAD_FLAG
toTIMELY_HEAD_FLAG_MASK
)is_activation_exit_period_boundary
tois_activation_exit_epoch
(for consistency withcompute_activation_exit_epoch
)process_leak_updates
(extracting logic fromprocess_rewards_and_penalties
) and call directly fromprocess_epoch
leak_epoch_counter
toEpoch
leak_epoch_counter
toleak_epochs_counter
SYNC_COMMITTEE_PUBKEY_AGGREGATES_SIZE
toSYNC_SUBCOMMITTEE_SIZE
is_leak_active
(replacing and deprecatingis_in_inactivity_leak
)LEAK_PENALTY_QUOTIENT
(merging withLEAK_SCORE_BIAS
; replacing and deprecatingINACTIVITY_PENALTY_QUOTIENT
)EPOCHS_TO_LEAK_PENALTIES
(replacing and deprecatingMIN_EPOCHS_TO_INACTIVITY_PENALTY
)for index in get_eligible_validator_indices(state)
inprocess_leak_updates
andget_flag_rewards
Substantive fixes
process_effective_balance_updates
only at activation-exit epochscompute_activation_exit_epoch
(notice special case whenepoch % EPOCHS_PER_ACTIVATION_EXIT_PERIOD == 0
)and is_matching_target
inprocess_attestation
whenappend(TIMELY_HEAD_FLAG_MASK)