mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
64795bd231
* archive participation begin implementation * validator participation compute * comments * compute participation common func * full test for archiving data * gazelle * complete tests * gaz * remove double negative grammar in comment * use archive in rpc * uses the archive! * error if nothing found in archive * comment * use head fetcher and root * tests pass * archive active set changes appropriately * archive committees * archive info * done with committee info archiving * archived set changes stored * fix build * test for archive balances and active indices * further abstractions * only archive epoch end * tests all pass * tests pass now * archive done * test for activated validators * tests for exited * amend message * use different proto * finalization fetcher * gaz * use root * use ctx * use new ethapis * use proper hash * match apis compatibility * match apis * properly use participation * fix tests * use right commit
32 lines
1.2 KiB
Go
32 lines
1.2 KiB
Go
package epoch
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
)
|
|
|
|
// ComputeValidatorParticipation by matching validator attestations during the epoch,
|
|
// computing the attesting balance, and how much attested compared to the total balances.
|
|
func ComputeValidatorParticipation(state *pb.BeaconState) (*ethpb.ValidatorParticipation, error) {
|
|
currentEpoch := helpers.SlotToEpoch(state.Slot)
|
|
atts, err := MatchAttestations(state, currentEpoch)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not retrieve head attestations")
|
|
}
|
|
attestedBalances, err := AttestingBalance(state, atts.Target)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not retrieve attested balances")
|
|
}
|
|
totalBalances, err := helpers.TotalActiveBalance(state)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not retrieve total balances")
|
|
}
|
|
return ðpb.ValidatorParticipation{
|
|
GlobalParticipationRate: float32(attestedBalances) / float32(totalBalances),
|
|
VotedEther: attestedBalances,
|
|
EligibleEther: totalBalances,
|
|
}, nil
|
|
}
|