mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Check Unrealized Justification Balances In Spectests (#13710)
* add them * Ensure activation epoch does not overflow * add them all in * better check for overflow * fix tests * fix tests --------- Co-authored-by: Potuz <potuz@prysmaticlabs.com>
This commit is contained in:
parent
b2e3c29ab3
commit
2616de1eb1
@ -35,8 +35,8 @@ func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err := state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive, active)
|
||||
require.Equal(t, uint64(0), current)
|
||||
require.Equal(t, uint64(0), previous)
|
||||
require.Equal(t, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(t, params.BeaconConfig().EffectiveBalanceIncrement, previous)
|
||||
|
||||
// Add some votes in the last two epochs:
|
||||
base.CurrentEpochParticipation[0] = 0xFF
|
||||
@ -58,7 +58,7 @@ func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, allActive, active)
|
||||
require.Equal(t, uint64(0), current)
|
||||
require.Equal(t, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, previous)
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func UnrealizedCheckpointBalances(cp, pp []byte, validators ValReader, currentEp
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
}
|
||||
activePrevious := v.ActivationEpoch+1 <= currentEpoch && currentEpoch <= v.ExitEpoch
|
||||
activePrevious := v.ActivationEpoch < currentEpoch && currentEpoch <= v.ExitEpoch
|
||||
if activePrevious && ((pp[i]>>targetIdx)&1) == 1 {
|
||||
prevTarget, err = math.Add64(prevTarget, v.EffectiveBalance)
|
||||
if err != nil {
|
||||
@ -51,5 +51,20 @@ func UnrealizedCheckpointBalances(cp, pp []byte, validators ValReader, currentEp
|
||||
}
|
||||
}
|
||||
}
|
||||
activeBalance, prevTarget, currentTarget = ensureLowerBound(activeBalance, prevTarget, currentTarget)
|
||||
return activeBalance, prevTarget, currentTarget, nil
|
||||
}
|
||||
|
||||
func ensureLowerBound(activeCurrEpoch, prevTargetAttested, currTargetAttested uint64) (uint64, uint64, uint64) {
|
||||
ebi := params.BeaconConfig().EffectiveBalanceIncrement
|
||||
if ebi > activeCurrEpoch {
|
||||
activeCurrEpoch = ebi
|
||||
}
|
||||
if ebi > prevTargetAttested {
|
||||
prevTargetAttested = ebi
|
||||
}
|
||||
if ebi > currTargetAttested {
|
||||
currTargetAttested = ebi
|
||||
}
|
||||
return activeCurrEpoch, prevTargetAttested, currTargetAttested
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err := UnrealizedCheckpointBalances(cp, pp, NewValSliceReader(validators), 0)
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, uint64(0), current)
|
||||
require.Equal(tt, uint64(0), previous)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, previous)
|
||||
})
|
||||
|
||||
t.Run("bad votes in last two epochs", func(tt *testing.T) {
|
||||
@ -39,8 +39,8 @@ func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err := UnrealizedCheckpointBalances(cp, pp, NewValSliceReader(validators), 1)
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, uint64(0), current)
|
||||
require.Equal(tt, uint64(0), previous)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, previous)
|
||||
})
|
||||
|
||||
t.Run("two votes in last epoch", func(tt *testing.T) {
|
||||
@ -50,7 +50,7 @@ func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, 2*params.BeaconConfig().MaxEffectiveBalance, current)
|
||||
require.Equal(tt, uint64(0), previous)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, previous)
|
||||
})
|
||||
|
||||
t.Run("two votes in previous epoch", func(tt *testing.T) {
|
||||
@ -59,7 +59,7 @@ func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err := UnrealizedCheckpointBalances(cp, pp, NewValSliceReader(validators), 1)
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, uint64(0), current)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(tt, 2*params.BeaconConfig().MaxEffectiveBalance, previous)
|
||||
})
|
||||
|
||||
@ -118,8 +118,8 @@ func TestState_MVSlice_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err := UnrealizedCheckpointBalances(cp, pp, NewValMultiValueSliceReader(mv, &testObject{id: 0}), 0)
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, uint64(0), current)
|
||||
require.Equal(tt, uint64(0), previous)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, previous)
|
||||
})
|
||||
|
||||
t.Run("bad votes in last two epochs", func(tt *testing.T) {
|
||||
@ -128,8 +128,8 @@ func TestState_MVSlice_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err := UnrealizedCheckpointBalances(cp, pp, NewValMultiValueSliceReader(mv, &testObject{id: 0}), 1)
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, uint64(0), current)
|
||||
require.Equal(tt, uint64(0), previous)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, previous)
|
||||
})
|
||||
|
||||
t.Run("two votes in last epoch", func(tt *testing.T) {
|
||||
@ -139,7 +139,7 @@ func TestState_MVSlice_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, 2*params.BeaconConfig().MaxEffectiveBalance, current)
|
||||
require.Equal(tt, uint64(0), previous)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, previous)
|
||||
})
|
||||
|
||||
t.Run("two votes in previous epoch", func(tt *testing.T) {
|
||||
@ -148,7 +148,7 @@ func TestState_MVSlice_UnrealizedCheckpointBalances(t *testing.T) {
|
||||
active, previous, current, err := UnrealizedCheckpointBalances(cp, pp, NewValMultiValueSliceReader(mv, &testObject{id: 0}), 1)
|
||||
require.NoError(tt, err)
|
||||
require.Equal(tt, expectedActive, active)
|
||||
require.Equal(tt, uint64(0), current)
|
||||
require.Equal(tt, params.BeaconConfig().EffectiveBalanceIncrement, current)
|
||||
require.Equal(tt, 2*params.BeaconConfig().MaxEffectiveBalance, previous)
|
||||
})
|
||||
|
||||
|
@ -35,6 +35,11 @@ func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, st state
|
||||
require.NoError(t, err)
|
||||
_, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp)
|
||||
require.NoError(t, err)
|
||||
activeBal, targetPrevious, targetCurrent, err := st.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
|
||||
st, err = precompute.ProcessJustificationAndFinalizationPreCompute(st, bp)
|
||||
require.NoError(t, err, "Could not process justification")
|
||||
|
@ -76,6 +76,13 @@ func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) {
|
||||
require.NoError(t, err)
|
||||
vp, bp, err = altair.ProcessEpochParticipation(ctx, preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
activeBal, targetPrevious, targetCurrent, err := preBeaconState.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
|
||||
deltas, err := altair.AttestationsDelta(preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -35,6 +35,11 @@ func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, st state
|
||||
require.NoError(t, err)
|
||||
_, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp)
|
||||
require.NoError(t, err)
|
||||
activeBal, targetPrevious, targetCurrent, err := st.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
|
||||
st, err = precompute.ProcessJustificationAndFinalizationPreCompute(st, bp)
|
||||
require.NoError(t, err, "Could not process justification")
|
||||
|
@ -80,6 +80,13 @@ func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) {
|
||||
require.NoError(t, err)
|
||||
vp, bp, err = altair.ProcessEpochParticipation(ctx, preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
activeBal, targetPrevious, targetCurrent, err := preBeaconState.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
|
||||
deltas, err := altair.AttestationsDelta(preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -35,6 +35,11 @@ func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, st state
|
||||
require.NoError(t, err)
|
||||
_, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp)
|
||||
require.NoError(t, err)
|
||||
activeBal, targetPrevious, targetCurrent, err := st.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
|
||||
st, err = precompute.ProcessJustificationAndFinalizationPreCompute(st, bp)
|
||||
require.NoError(t, err, "Could not process justification")
|
||||
|
@ -80,6 +80,13 @@ func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) {
|
||||
require.NoError(t, err)
|
||||
vp, bp, err = altair.ProcessEpochParticipation(ctx, preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
activeBal, targetPrevious, targetCurrent, err := preBeaconState.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
|
||||
deltas, err := altair.AttestationsDelta(preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -32,7 +32,11 @@ func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, st state
|
||||
require.NoError(t, err)
|
||||
_, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
activeBal, targetPrevious, targetCurrent, err := st.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
st, err = precompute.ProcessJustificationAndFinalizationPreCompute(st, bp)
|
||||
require.NoError(t, err, "Could not process justification")
|
||||
|
||||
|
@ -70,8 +70,16 @@ func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) {
|
||||
|
||||
vp, bp, err := altair.InitializePrecomputeValidators(ctx, preBeaconState)
|
||||
require.NoError(t, err)
|
||||
|
||||
vp, bp, err = altair.ProcessEpochParticipation(ctx, preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
activeBal, targetPrevious, targetCurrent, err := preBeaconState.UnrealizedCheckpointBalances()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bp.ActiveCurrentEpoch, activeBal)
|
||||
require.Equal(t, bp.CurrentEpochTargetAttested, targetCurrent)
|
||||
require.Equal(t, bp.PrevEpochTargetAttested, targetPrevious)
|
||||
|
||||
deltas, err := altair.AttestationsDelta(preBeaconState, bp, vp)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user