mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
Review Altair core epoch files with changes (#9556)
* Clean up core epoch for Altair * Update BUILD.bazel * Remove check for spec test * Update validators_test.go * Update validators_test.go * Update beacon-chain/core/altair/epoch_precompute.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/core/altair/epoch_precompute_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/core/altair/epoch_spec.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
@@ -246,7 +246,7 @@ func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconSt
|
||||
return err
|
||||
}
|
||||
case version.Altair:
|
||||
v, b, err = altair.InitializeEpochValidators(ctx, headState)
|
||||
v, b, err = altair.InitializePrecomputeValidators(ctx, headState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ go_library(
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,52 +13,48 @@ import (
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// InitializeEpochValidators gets called at the beginning of process epoch cycle to return
|
||||
// pre computed instances of validators attesting records and total
|
||||
// balances attested in an epoch.
|
||||
func InitializeEpochValidators(ctx context.Context, st state.BeaconStateAltair) ([]*precompute.Validator, *precompute.Balance, error) {
|
||||
_, span := trace.StartSpan(ctx, "altair.InitializeEpochValidators")
|
||||
// InitializePrecomputeValidators precomputes individual validator for its attested balances and the total sum of validators attested balances of the epoch.
|
||||
func InitializePrecomputeValidators(ctx context.Context, beaconState state.BeaconStateAltair) ([]*precompute.Validator, *precompute.Balance, error) {
|
||||
_, span := trace.StartSpan(ctx, "altair.InitializePrecomputeValidators")
|
||||
defer span.End()
|
||||
pValidators := make([]*precompute.Validator, st.NumValidators())
|
||||
vals := make([]*precompute.Validator, beaconState.NumValidators())
|
||||
bal := &precompute.Balance{}
|
||||
prevEpoch := core.PrevEpoch(st)
|
||||
currentEpoch := core.CurrentEpoch(st)
|
||||
inactivityScores, err := st.InactivityScores()
|
||||
prevEpoch := core.PrevEpoch(beaconState)
|
||||
currentEpoch := core.CurrentEpoch(beaconState)
|
||||
inactivityScores, err := beaconState.InactivityScores()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// This shouldn't happen with a correct beacon state,
|
||||
// but rather be safe to defend against index out of bound panics.
|
||||
if st.NumValidators() > len(inactivityScores) {
|
||||
return nil, nil, errors.New("num of validators can't be greater than length of inactivity scores")
|
||||
if beaconState.NumValidators() != len(inactivityScores) {
|
||||
return nil, nil, errors.New("num of validators is different than num of inactivity scores")
|
||||
}
|
||||
if err := st.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
|
||||
// Was validator withdrawable or slashed
|
||||
withdrawable := currentEpoch >= val.WithdrawableEpoch()
|
||||
pVal := &precompute.Validator{
|
||||
IsSlashed: val.Slashed(),
|
||||
IsWithdrawableCurrentEpoch: withdrawable,
|
||||
if err := beaconState.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
|
||||
// Set validator's balance, inactivity score and slashed/withdrawable status.
|
||||
v := &precompute.Validator{
|
||||
CurrentEpochEffectiveBalance: val.EffectiveBalance(),
|
||||
InactivityScore: inactivityScores[idx],
|
||||
IsSlashed: val.Slashed(),
|
||||
IsWithdrawableCurrentEpoch: currentEpoch >= val.WithdrawableEpoch(),
|
||||
}
|
||||
// Validator active current epoch
|
||||
// Set validator's active status for current epoch.
|
||||
if helpers.IsActiveValidatorUsingTrie(val, currentEpoch) {
|
||||
pVal.IsActiveCurrentEpoch = true
|
||||
v.IsActiveCurrentEpoch = true
|
||||
bal.ActiveCurrentEpoch += val.EffectiveBalance()
|
||||
}
|
||||
// Validator active previous epoch
|
||||
// Set validator's active status for preivous epoch.
|
||||
if helpers.IsActiveValidatorUsingTrie(val, prevEpoch) {
|
||||
pVal.IsActivePrevEpoch = true
|
||||
v.IsActivePrevEpoch = true
|
||||
bal.ActivePrevEpoch += val.EffectiveBalance()
|
||||
}
|
||||
|
||||
pValidators[idx] = pVal
|
||||
vals[idx] = v
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not initialize epoch validator")
|
||||
return nil, nil, errors.Wrap(err, "could not read every validator")
|
||||
}
|
||||
return pValidators, bal, nil
|
||||
return vals, bal, nil
|
||||
}
|
||||
|
||||
// ProcessInactivityScores of beacon chain. This updates inactivity scores of beacon chain and
|
||||
@@ -71,26 +67,26 @@ func InitializeEpochValidators(ctx context.Context, st state.BeaconStateAltair)
|
||||
// If the chain has recently finalized, each validator's score drops by 16.
|
||||
func ProcessInactivityScores(
|
||||
ctx context.Context,
|
||||
state state.BeaconState,
|
||||
beaconState state.BeaconState,
|
||||
vals []*precompute.Validator,
|
||||
) (state.BeaconState, []*precompute.Validator, error) {
|
||||
_, span := trace.StartSpan(ctx, "altair.ProcessInactivityScores")
|
||||
defer span.End()
|
||||
|
||||
cfg := params.BeaconConfig()
|
||||
if core.CurrentEpoch(state) == cfg.GenesisEpoch {
|
||||
return state, vals, nil
|
||||
if core.CurrentEpoch(beaconState) == cfg.GenesisEpoch {
|
||||
return beaconState, vals, nil
|
||||
}
|
||||
|
||||
inactivityScores, err := state.InactivityScores()
|
||||
inactivityScores, err := beaconState.InactivityScores()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
bias := cfg.InactivityScoreBias
|
||||
recoveryRate := cfg.InactivityScoreRecoveryRate
|
||||
prevEpoch := core.PrevEpoch(state)
|
||||
finalizedEpoch := state.FinalizedCheckpointEpoch()
|
||||
prevEpoch := core.PrevEpoch(beaconState)
|
||||
finalizedEpoch := beaconState.FinalizedCheckpointEpoch()
|
||||
for i, v := range vals {
|
||||
if !precompute.EligibleForRewards(v) {
|
||||
continue
|
||||
@@ -116,11 +112,11 @@ func ProcessInactivityScores(
|
||||
inactivityScores[i] = v.InactivityScore
|
||||
}
|
||||
|
||||
if err := state.SetInactivityScores(inactivityScores); err != nil {
|
||||
if err := beaconState.SetInactivityScores(inactivityScores); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return state, vals, nil
|
||||
return beaconState, vals, nil
|
||||
}
|
||||
|
||||
// ProcessEpochParticipation processes the epoch participation in state and updates individual validator's pre computes,
|
||||
@@ -135,14 +131,14 @@ func ProcessInactivityScores(
|
||||
// return set(filter(lambda index: not state.validators[index].slashed, participating_indices))
|
||||
func ProcessEpochParticipation(
|
||||
ctx context.Context,
|
||||
state state.BeaconState,
|
||||
beaconState state.BeaconState,
|
||||
bal *precompute.Balance,
|
||||
vals []*precompute.Validator,
|
||||
) ([]*precompute.Validator, *precompute.Balance, error) {
|
||||
_, span := trace.StartSpan(ctx, "altair.ProcessEpochParticipation")
|
||||
defer span.End()
|
||||
|
||||
cp, err := state.CurrentEpochParticipation()
|
||||
cp, err := beaconState.CurrentEpochParticipation()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -155,7 +151,7 @@ func ProcessEpochParticipation(
|
||||
vals[i].IsCurrentEpochTargetAttester = true
|
||||
}
|
||||
}
|
||||
pp, err := state.PreviousEpochParticipation()
|
||||
pp, err := beaconState.PreviousEpochParticipation()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -177,27 +173,28 @@ func ProcessEpochParticipation(
|
||||
// ProcessRewardsAndPenaltiesPrecompute processes the rewards and penalties of individual validator.
|
||||
// This is an optimized version by passing in precomputed validator attesting records and and total epoch balances.
|
||||
func ProcessRewardsAndPenaltiesPrecompute(
|
||||
state state.BeaconStateAltair,
|
||||
beaconState state.BeaconStateAltair,
|
||||
bal *precompute.Balance,
|
||||
vals []*precompute.Validator,
|
||||
) (state.BeaconStateAltair, error) {
|
||||
// Don't process rewards and penalties in genesis epoch.
|
||||
if core.CurrentEpoch(state) == 0 {
|
||||
return state, nil
|
||||
cfg := params.BeaconConfig()
|
||||
if core.CurrentEpoch(beaconState) == cfg.GenesisEpoch {
|
||||
return beaconState, nil
|
||||
}
|
||||
|
||||
numOfVals := state.NumValidators()
|
||||
numOfVals := beaconState.NumValidators()
|
||||
// Guard against an out-of-bounds using validator balance precompute.
|
||||
if len(vals) != numOfVals || len(vals) != state.BalancesLength() {
|
||||
return state, errors.New("validator registries not the same length as state's validator registries")
|
||||
if len(vals) != numOfVals || len(vals) != beaconState.BalancesLength() {
|
||||
return beaconState, errors.New("validator registries not the same length as state's validator registries")
|
||||
}
|
||||
|
||||
attsRewards, attsPenalties, err := AttestationsDelta(state, bal, vals)
|
||||
attsRewards, attsPenalties, err := AttestationsDelta(beaconState, bal, vals)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get attestation delta")
|
||||
}
|
||||
|
||||
balances := state.Balances()
|
||||
balances := beaconState.Balances()
|
||||
for i := 0; i < numOfVals; i++ {
|
||||
vals[i].BeforeEpochTransitionBalance = balances[i]
|
||||
|
||||
@@ -209,23 +206,23 @@ func ProcessRewardsAndPenaltiesPrecompute(
|
||||
vals[i].AfterEpochTransitionBalance = balances[i]
|
||||
}
|
||||
|
||||
if err := state.SetBalances(balances); err != nil {
|
||||
if err := beaconState.SetBalances(balances); err != nil {
|
||||
return nil, errors.Wrap(err, "could not set validator balances")
|
||||
}
|
||||
|
||||
return state, nil
|
||||
return beaconState, nil
|
||||
}
|
||||
|
||||
// AttestationsDelta computes and returns the rewards and penalties differences for individual validators based on the
|
||||
// voting records.
|
||||
func AttestationsDelta(state state.BeaconStateAltair, bal *precompute.Balance, vals []*precompute.Validator) (rewards, penalties []uint64, err error) {
|
||||
numOfVals := state.NumValidators()
|
||||
func AttestationsDelta(beaconState state.BeaconStateAltair, bal *precompute.Balance, vals []*precompute.Validator) (rewards, penalties []uint64, err error) {
|
||||
numOfVals := beaconState.NumValidators()
|
||||
rewards = make([]uint64, numOfVals)
|
||||
penalties = make([]uint64, numOfVals)
|
||||
prevEpoch := core.PrevEpoch(state)
|
||||
finalizedEpoch := state.FinalizedCheckpointEpoch()
|
||||
|
||||
cfg := params.BeaconConfig()
|
||||
prevEpoch := core.PrevEpoch(beaconState)
|
||||
finalizedEpoch := beaconState.FinalizedCheckpointEpoch()
|
||||
increment := cfg.EffectiveBalanceIncrement
|
||||
factor := cfg.BaseRewardFactor
|
||||
baseRewardMultiplier := increment * factor / math.IntegerSquareRoot(bal.ActiveCurrentEpoch)
|
||||
@@ -241,10 +238,10 @@ func AttestationsDelta(state state.BeaconStateAltair, bal *precompute.Balance, v
|
||||
|
||||
func attestationDelta(
|
||||
bal *precompute.Balance,
|
||||
v *precompute.Validator,
|
||||
val *precompute.Validator,
|
||||
baseRewardMultiplier, inactivityDenominator uint64,
|
||||
inactivityLeak bool) (reward, penalty uint64) {
|
||||
eligible := v.IsActivePrevEpoch || (v.IsSlashed && !v.IsWithdrawableCurrentEpoch)
|
||||
eligible := val.IsActivePrevEpoch || (val.IsSlashed && !val.IsWithdrawableCurrentEpoch)
|
||||
// Per spec `ActiveCurrentEpoch` can't be 0 to process attestation delta.
|
||||
if !eligible || bal.ActiveCurrentEpoch == 0 {
|
||||
return 0, 0
|
||||
@@ -252,7 +249,7 @@ func attestationDelta(
|
||||
|
||||
cfg := params.BeaconConfig()
|
||||
increment := cfg.EffectiveBalanceIncrement
|
||||
effectiveBalance := v.CurrentEpochEffectiveBalance
|
||||
effectiveBalance := val.CurrentEpochEffectiveBalance
|
||||
baseReward := (effectiveBalance / increment) * baseRewardMultiplier
|
||||
activeIncrement := bal.ActiveCurrentEpoch / increment
|
||||
|
||||
@@ -262,7 +259,7 @@ func attestationDelta(
|
||||
headWeight := cfg.TimelyHeadWeight
|
||||
reward, penalty = uint64(0), uint64(0)
|
||||
// Process source reward / penalty
|
||||
if v.IsPrevEpochAttester && !v.IsSlashed {
|
||||
if val.IsPrevEpochAttester && !val.IsSlashed {
|
||||
if !inactivityLeak {
|
||||
n := baseReward * srcWeight * (bal.PrevEpochAttested / increment)
|
||||
reward += n / (activeIncrement * weightDenominator)
|
||||
@@ -272,7 +269,7 @@ func attestationDelta(
|
||||
}
|
||||
|
||||
// Process target reward / penalty
|
||||
if v.IsPrevEpochTargetAttester && !v.IsSlashed {
|
||||
if val.IsPrevEpochTargetAttester && !val.IsSlashed {
|
||||
if !inactivityLeak {
|
||||
n := baseReward * tgtWeight * (bal.PrevEpochTargetAttested / increment)
|
||||
reward += n / (activeIncrement * weightDenominator)
|
||||
@@ -282,7 +279,7 @@ func attestationDelta(
|
||||
}
|
||||
|
||||
// Process head reward / penalty
|
||||
if v.IsPrevEpochHeadAttester && !v.IsSlashed {
|
||||
if val.IsPrevEpochHeadAttester && !val.IsSlashed {
|
||||
if !inactivityLeak {
|
||||
n := baseReward * headWeight * (bal.PrevEpochHeadAttested / increment)
|
||||
reward += n / (activeIncrement * weightDenominator)
|
||||
@@ -291,8 +288,8 @@ func attestationDelta(
|
||||
|
||||
// Process finality delay penalty
|
||||
// Apply an additional penalty to validators that did not vote on the correct target or slashed
|
||||
if !v.IsPrevEpochTargetAttester || v.IsSlashed {
|
||||
n := effectiveBalance * v.InactivityScore
|
||||
if !val.IsPrevEpochTargetAttester || val.IsSlashed {
|
||||
n := effectiveBalance * val.InactivityScore
|
||||
penalty += n / inactivityDenominator
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestInitializeEpochValidators_Ok(t *testing.T) {
|
||||
InactivityScores: []uint64{0, 1, 2, 3},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
v, b, err := InitializeEpochValidators(context.Background(), s)
|
||||
v, b, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, &precompute.Validator{
|
||||
IsSlashed: true,
|
||||
@@ -68,14 +68,14 @@ func TestInitializeEpochValidators_BadState(t *testing.T) {
|
||||
InactivityScores: []uint64{},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, _, err = InitializeEpochValidators(context.Background(), s)
|
||||
require.ErrorContains(t, "num of validators can't be greater than length of inactivity scores", err)
|
||||
_, _, err = InitializePrecomputeValidators(context.Background(), s)
|
||||
require.ErrorContains(t, "num of validators is different than num of inactivity scores", err)
|
||||
}
|
||||
|
||||
func TestProcessEpochParticipation(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, balance, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -145,7 +145,7 @@ func TestProcessEpochParticipation_InactiveValidator(t *testing.T) {
|
||||
InactivityScores: []uint64{0, 0, 0},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), st)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), st)
|
||||
require.NoError(t, err)
|
||||
validators, balance, err = ProcessEpochParticipation(context.Background(), st, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -182,7 +182,7 @@ func TestProcessEpochParticipation_InactiveValidator(t *testing.T) {
|
||||
func TestAttestationsDelta(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, balance, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -208,7 +208,7 @@ func TestAttestationsDelta(t *testing.T) {
|
||||
func TestProcessRewardsAndPenaltiesPrecompute_Ok(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, balance, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -240,7 +240,7 @@ func TestProcessRewardsAndPenaltiesPrecompute_Ok(t *testing.T) {
|
||||
func TestProcessRewardsAndPenaltiesPrecompute_InactivityLeak(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, balance, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -268,7 +268,7 @@ func TestProcessInactivityScores_CanProcessInactivityLeak(t *testing.T) {
|
||||
defaultScore := uint64(5)
|
||||
require.NoError(t, s.SetInactivityScores([]uint64{defaultScore, defaultScore, defaultScore, defaultScore}))
|
||||
require.NoError(t, s.SetSlot(params.BeaconConfig().SlotsPerEpoch*types.Slot(params.BeaconConfig().MinEpochsToInactivityPenalty+2)))
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, _, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -283,12 +283,32 @@ func TestProcessInactivityScores_CanProcessInactivityLeak(t *testing.T) {
|
||||
require.Equal(t, defaultScore-1, inactivityScores[3])
|
||||
}
|
||||
|
||||
func TestProcessInactivityScores_GenesisEpoch(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
defaultScore := uint64(10)
|
||||
require.NoError(t, s.SetInactivityScores([]uint64{defaultScore, defaultScore, defaultScore, defaultScore}))
|
||||
require.NoError(t, s.SetSlot(params.BeaconConfig().GenesisSlot))
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, _, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
s, _, err = ProcessInactivityScores(context.Background(), s, validators)
|
||||
require.NoError(t, err)
|
||||
inactivityScores, err := s.InactivityScores()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, defaultScore, inactivityScores[0])
|
||||
require.Equal(t, defaultScore, inactivityScores[1])
|
||||
require.Equal(t, defaultScore, inactivityScores[2])
|
||||
require.Equal(t, defaultScore, inactivityScores[3])
|
||||
}
|
||||
|
||||
func TestProcessInactivityScores_CanProcessNonInactivityLeak(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
defaultScore := uint64(5)
|
||||
require.NoError(t, s.SetInactivityScores([]uint64{defaultScore, defaultScore, defaultScore, defaultScore}))
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, _, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -306,7 +326,7 @@ func TestProcessInactivityScores_CanProcessNonInactivityLeak(t *testing.T) {
|
||||
func TestProcessRewardsAndPenaltiesPrecompute_GenesisEpoch(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
validators, balance, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -325,7 +345,7 @@ func TestProcessRewardsAndPenaltiesPrecompute_GenesisEpoch(t *testing.T) {
|
||||
func TestProcessRewardsAndPenaltiesPrecompute_BadState(t *testing.T) {
|
||||
s, err := testState()
|
||||
require.NoError(t, err)
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
_, balance, err = ProcessEpochParticipation(context.Background(), s, balance, validators)
|
||||
require.NoError(t, err)
|
||||
@@ -338,7 +358,7 @@ func TestProcessInactivityScores_NonEligibleValidator(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defaultScore := uint64(5)
|
||||
require.NoError(t, s.SetInactivityScores([]uint64{defaultScore, defaultScore, defaultScore, defaultScore}))
|
||||
validators, balance, err := InitializeEpochValidators(context.Background(), s)
|
||||
validators, balance, err := InitializePrecomputeValidators(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
|
||||
// v0 is eligible (not active previous epoch, slashed and not withdrawable)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// ProcessSyncCommitteeUpdates processes sync client committee updates for the beacon state.
|
||||
@@ -35,7 +36,7 @@ func ProcessSyncCommitteeUpdates(ctx context.Context, beaconState state.BeaconSt
|
||||
return nil, err
|
||||
}
|
||||
if err := helpers.UpdateSyncCommitteeCache(beaconState); err != nil {
|
||||
return nil, err
|
||||
log.WithError(err).Error("Could not update sync committee cache")
|
||||
}
|
||||
}
|
||||
return beaconState, nil
|
||||
|
||||
@@ -35,7 +35,7 @@ func ProcessEpoch(ctx context.Context, state state.BeaconStateAltair) (state.Bea
|
||||
if state == nil || state.IsNil() {
|
||||
return nil, errors.New("nil state")
|
||||
}
|
||||
vp, bp, err := InitializeEpochValidators(ctx, state)
|
||||
vp, bp, err := InitializePrecomputeValidators(ctx, state)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -537,7 +537,7 @@ func (bs *Server) GetValidatorParticipation(
|
||||
return nil, status.Errorf(codes.Internal, "Could not pre compute attestations: %v", err)
|
||||
}
|
||||
case version.Altair:
|
||||
v, b, err = altair.InitializeEpochValidators(ctx, beaconState)
|
||||
v, b, err = altair.InitializePrecomputeValidators(ctx, beaconState)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not set up altair pre compute instance: %v", err)
|
||||
}
|
||||
@@ -697,7 +697,7 @@ func (bs *Server) GetValidatorPerformance(
|
||||
}
|
||||
validatorSummary = vp
|
||||
case version.Altair:
|
||||
vp, bp, err := altair.InitializeEpochValidators(ctx, headState)
|
||||
vp, bp, err := altair.InitializePrecomputeValidators(ctx, headState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2019,6 +2019,7 @@ func TestGetValidatorPerformanceAltair_OK(t *testing.T) {
|
||||
},
|
||||
}
|
||||
require.NoError(t, headState.SetValidators(validators))
|
||||
require.NoError(t, headState.SetInactivityScores([]uint64{0, 0, 0}))
|
||||
require.NoError(t, headState.SetBalances([]uint64{100, 101, 102}))
|
||||
offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
bs := &Server{
|
||||
|
||||
@@ -29,7 +29,7 @@ func RunInactivityUpdatesTest(t *testing.T, config string) {
|
||||
|
||||
func processInactivityUpdates(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
ctx := context.Background()
|
||||
vp, bp, err := altair.InitializeEpochValidators(ctx, st)
|
||||
vp, bp, err := altair.InitializePrecomputeValidators(ctx, st)
|
||||
require.NoError(t, err)
|
||||
vp, _, err = altair.ProcessEpochParticipation(ctx, st, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -28,7 +28,7 @@ func RunJustificationAndFinalizationTests(t *testing.T, config string) {
|
||||
|
||||
func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
ctx := context.Background()
|
||||
vp, bp, err := altair.InitializeEpochValidators(ctx, st)
|
||||
vp, bp, err := altair.InitializePrecomputeValidators(ctx, st)
|
||||
require.NoError(t, err)
|
||||
_, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -29,7 +29,7 @@ func RunRewardsAndPenaltiesTests(t *testing.T, config string) {
|
||||
|
||||
func processRewardsAndPenaltiesPrecomputeWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
ctx := context.Background()
|
||||
vp, bp, err := altair.InitializeEpochValidators(ctx, st)
|
||||
vp, bp, err := altair.InitializePrecomputeValidators(ctx, st)
|
||||
require.NoError(t, err)
|
||||
vp, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -68,7 +68,7 @@ func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) {
|
||||
preBeaconState, err := stateAltair.InitializeFromProto(preBeaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
vp, bp, err := altair.InitializeEpochValidators(ctx, preBeaconState)
|
||||
vp, bp, err := altair.InitializePrecomputeValidators(ctx, preBeaconState)
|
||||
require.NoError(t, err)
|
||||
vp, bp, err = altair.ProcessEpochParticipation(ctx, preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user