mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Inclusion rewards are based off previous epoch (#3855)
This commit is contained in:
parent
f8c870aa91
commit
3d1b69e945
@ -139,6 +139,12 @@ func UpdateValidator(vp []*Validator, record *Validator, indices []uint64, a *pb
|
||||
}
|
||||
if record.IsPrevEpochAttester {
|
||||
vp[i].IsPrevEpochAttester = true
|
||||
// Update attestation inclusion info if inclusion slot is lower than before
|
||||
if inclusionSlot < vp[i].InclusionSlot {
|
||||
vp[i].InclusionSlot = aSlot + a.InclusionDelay
|
||||
vp[i].InclusionDistance = a.InclusionDelay
|
||||
vp[i].ProposerIndex = a.ProposerIndex
|
||||
}
|
||||
}
|
||||
if record.IsPrevEpochTargetAttester {
|
||||
vp[i].IsPrevEpochTargetAttester = true
|
||||
@ -146,13 +152,6 @@ func UpdateValidator(vp []*Validator, record *Validator, indices []uint64, a *pb
|
||||
if record.IsPrevEpochHeadAttester {
|
||||
vp[i].IsPrevEpochHeadAttester = true
|
||||
}
|
||||
|
||||
// Update attestation inclusion info if inclusion slot is lower than before
|
||||
if inclusionSlot < vp[i].InclusionSlot {
|
||||
vp[i].InclusionSlot = aSlot + a.InclusionDelay
|
||||
vp[i].InclusionDistance = a.InclusionDelay
|
||||
vp[i].ProposerIndex = a.ProposerIndex
|
||||
}
|
||||
}
|
||||
return vp
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
)
|
||||
|
||||
func TestUpdateValidator(t *testing.T) {
|
||||
func TestUpdateValidator_Works(t *testing.T) {
|
||||
e := params.BeaconConfig().FarFutureEpoch
|
||||
vp := []*precompute.Validator{{}, {InclusionSlot: e}, {}, {InclusionSlot: e}, {}, {InclusionSlot: e}}
|
||||
record := &precompute.Validator{IsCurrentEpochAttester: true, IsCurrentEpochTargetAttester: true,
|
||||
@ -33,6 +33,21 @@ func TestUpdateValidator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateValidator_InclusionOnlyCountsPrevEpoch(t *testing.T) {
|
||||
e := params.BeaconConfig().FarFutureEpoch
|
||||
vp := []*precompute.Validator{{InclusionSlot: e}}
|
||||
record := &precompute.Validator{IsCurrentEpochAttester: true, IsCurrentEpochTargetAttester: true}
|
||||
a := &pb.PendingAttestation{InclusionDelay: 1, ProposerIndex: 2}
|
||||
|
||||
// Verify inclusion info doesnt get updated.
|
||||
vp = precompute.UpdateValidator(vp, record, []uint64{0}, a, 100)
|
||||
wanted := &precompute.Validator{IsCurrentEpochAttester: true, IsCurrentEpochTargetAttester: true, InclusionSlot: e}
|
||||
wantedVp := []*precompute.Validator{wanted}
|
||||
if !reflect.DeepEqual(vp, wantedVp) {
|
||||
t.Error("Incorrect attesting validator calculations")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateBalance(t *testing.T) {
|
||||
vp := []*precompute.Validator{
|
||||
{IsCurrentEpochAttester: true, CurrentEpochEffectiveBalance: 100},
|
||||
|
@ -153,7 +153,7 @@ func crosslinkDeltaPreCompute(state *pb.BeaconState, bp *Balance, vp []*Validato
|
||||
attestingBalance := helpers.TotalBalance(state, attestingIndices)
|
||||
|
||||
for _, index := range committee {
|
||||
base := vp[i].CurrentEpochEffectiveBalance * params.BeaconConfig().BaseRewardFactor / mathutil.IntegerSquareRoot(bp.CurrentEpoch) / params.BeaconConfig().BaseRewardsPerEpoch
|
||||
base := vp[index].CurrentEpochEffectiveBalance * params.BeaconConfig().BaseRewardFactor / mathutil.IntegerSquareRoot(bp.CurrentEpoch) / params.BeaconConfig().BaseRewardsPerEpoch
|
||||
if _, ok := attested[index]; ok {
|
||||
rewards[index] += base * attestingBalance / committeeBalance
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user