-
Notifications
You must be signed in to change notification settings - Fork 250
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
Fork choice fixes 2 #1356
Fork choice fixes 2 #1356
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,12 @@ func is_active_validator*(validator: Validator, epoch: Epoch): bool = | |
### Check if ``validator`` is active | ||
validator.activation_epoch <= epoch and epoch < validator.exit_epoch | ||
|
||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_active_validator_indices | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a fine abstraction, but still not something one would want to call that often, for the same reasons that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, as an isolated function, just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, yeah, I suspect there may be tricks to get rid of it - until then, it's a trivial addition that simplifies some code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also avoids memory allocations, which is probably much of what's left outside BLS cryptography. |
||
func count_active_validator_indices*(state: BeaconState, epoch: Epoch): int = | ||
for val in state.validators: | ||
if is_active_validator(val, epoch): | ||
result += 1 | ||
|
||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_active_validator_indices | ||
func get_active_validator_indices*(state: BeaconState, epoch: Epoch): | ||
seq[ValidatorIndex] = | ||
|
@@ -79,8 +85,8 @@ func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 = | |
# CommitteeIndex return type here. | ||
let | ||
epoch = compute_epoch_at_slot(slot) | ||
active_validator_indices = get_active_validator_indices(state, epoch) | ||
result = get_committee_count_at_slot(len(active_validator_indices).uint64) | ||
active_validator_count = count_active_validator_indices(state, epoch) | ||
result = get_committee_count_at_slot(active_validator_count.uint64) | ||
|
||
# Otherwise, get_beacon_committee(...) cannot access some committees. | ||
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT).uint64 >= result | ||
|
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 noticed this when investigating possible causes for the recently found cache invalidation bug. it's conceptually plausible to have that flexibility of an epoch distinct from the state epoch, but in practice was unused.