mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
1433fab0d4
* Fix attestations * Fix new * Testing state transition * Fix * Runtime works
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package precompute
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// New 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 New(ctx context.Context, state *pb.BeaconState) ([]*Validator, *Balance) {
|
|
ctx, span := trace.StartSpan(ctx, "precomputeEpoch.New")
|
|
defer span.End()
|
|
|
|
vp := make([]*Validator, len(state.Validators))
|
|
bp := &Balance{}
|
|
|
|
currentEpoch := helpers.CurrentEpoch(state)
|
|
prevEpoch := helpers.PrevEpoch(state)
|
|
|
|
for i, v := range state.Validators {
|
|
// Was validator withdrawable or slashed
|
|
withdrawable := currentEpoch >= v.WithdrawableEpoch
|
|
p := &Validator{
|
|
IsSlashed: v.Slashed,
|
|
IsWithdrawableCurrentEpoch: withdrawable,
|
|
CurrentEpochEffectiveBalance: v.EffectiveBalance,
|
|
}
|
|
// Was validator active current epoch
|
|
if helpers.IsActiveValidator(v, currentEpoch) {
|
|
p.IsActiveCurrentEpoch = true
|
|
bp.CurrentEpoch += v.EffectiveBalance
|
|
}
|
|
// Was validator active previous epoch
|
|
if helpers.IsActiveValidator(v, prevEpoch) {
|
|
p.IsActivePrevEpoch = true
|
|
bp.PrevEpoch += v.EffectiveBalance
|
|
}
|
|
// Set inclusion slot and inclusion distance to be max, they will be compared and replaced
|
|
// with the lower values
|
|
p.InclusionSlot = params.BeaconConfig().FarFutureEpoch
|
|
p.InclusionDistance = params.BeaconConfig().FarFutureEpoch
|
|
|
|
vp[i] = p
|
|
}
|
|
return vp, bp
|
|
}
|