Inclusion rewards are based off previous epoch (#3855)

This commit is contained in:
terence tsao 2019-10-28 22:39:16 -07:00 committed by GitHub
parent f8c870aa91
commit 3d1b69e945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View File

@ -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
}

View File

@ -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},

View File

@ -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 {