Add in progress handler to committee cache (#9664)

* Add in progress handler for committee cache

* Remove debug print

* Update validators.go

* Fix all the tests

* More tests

* Update committee_disabled.go

* Update committee_disabled.go

* Update testing util

* Update main.go

Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
terence tsao
2021-09-26 08:27:57 -07:00
committed by GitHub
parent 6e4c2b4b20
commit 376d248c22
95 changed files with 474 additions and 323 deletions

View File

@@ -5,6 +5,7 @@
package epoch
import (
"context"
"fmt"
"sort"
@@ -55,8 +56,8 @@ func (s sortableIndices) Less(i, j int) bool {
// Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei minimum to avoid divisions by zero.
// """
// return get_total_balance(state, get_unslashed_attesting_indices(state, attestations))
func AttestingBalance(state state.ReadOnlyBeaconState, atts []*ethpb.PendingAttestation) (uint64, error) {
indices, err := UnslashedAttestingIndices(state, atts)
func AttestingBalance(ctx context.Context, state state.ReadOnlyBeaconState, atts []*ethpb.PendingAttestation) (uint64, error) {
indices, err := UnslashedAttestingIndices(ctx, state, atts)
if err != nil {
return 0, errors.Wrap(err, "could not get attesting indices")
}
@@ -86,7 +87,7 @@ func AttestingBalance(state state.ReadOnlyBeaconState, atts []*ethpb.PendingAtte
// for index in activation_queue[:get_validator_churn_limit(state)]:
// validator = state.validators[index]
// validator.activation_epoch = compute_activation_exit_epoch(get_current_epoch(state))
func ProcessRegistryUpdates(state state.BeaconState) (state.BeaconState, error) {
func ProcessRegistryUpdates(ctx context.Context, state state.BeaconState) (state.BeaconState, error) {
currentEpoch := core.CurrentEpoch(state)
vals := state.Validators()
var err error
@@ -105,7 +106,7 @@ func ProcessRegistryUpdates(state state.BeaconState) (state.BeaconState, error)
isActive := helpers.IsActiveValidator(validator, currentEpoch)
belowEjectionBalance := validator.EffectiveBalance <= ejectionBal
if isActive && belowEjectionBalance {
state, err = validators.InitiateValidatorExit(state, types.ValidatorIndex(idx))
state, err = validators.InitiateValidatorExit(ctx, state, types.ValidatorIndex(idx))
if err != nil {
return nil, errors.Wrapf(err, "could not initiate exit for validator %d", idx)
}
@@ -124,7 +125,7 @@ func ProcessRegistryUpdates(state state.BeaconState) (state.BeaconState, error)
// Only activate just enough validators according to the activation churn limit.
limit := uint64(len(activationQ))
activeValidatorCount, err := helpers.ActiveValidatorCount(state, currentEpoch)
activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, state, currentEpoch)
if err != nil {
return nil, errors.Wrap(err, "could not get active validator count")
}
@@ -460,12 +461,12 @@ func ProcessFinalUpdates(state state.BeaconState) (state.BeaconState, error) {
// for a in attestations:
// output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits))
// return set(filter(lambda index: not state.validators[index].slashed, output))
func UnslashedAttestingIndices(state state.ReadOnlyBeaconState, atts []*ethpb.PendingAttestation) ([]types.ValidatorIndex, error) {
func UnslashedAttestingIndices(ctx context.Context, state state.ReadOnlyBeaconState, atts []*ethpb.PendingAttestation) ([]types.ValidatorIndex, error) {
var setIndices []types.ValidatorIndex
seen := make(map[uint64]bool)
for _, att := range atts {
committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
committee, err := helpers.BeaconCommitteeFromState(ctx, state, att.Data.Slot, att.Data.CommitteeIndex)
if err != nil {
return nil, err
}