Skip to content

Instantly share code, notes, and snippets.

@guybrush
Created February 13, 2020 13:00
Show Gist options
  • Save guybrush/635195e8fc8e453874a1782c4e3548ac to your computer and use it in GitHub Desktop.
Save guybrush/635195e8fc8e453874a1782c4e3548ac to your computer and use it in GitHub Desktop.
func test9(addr string) {
dialOpt := grpc.WithInsecure()
conn, err := grpc.Dial(addr, dialOpt)
if err != nil {
panic(err)
}
chainClient := ethpb.NewBeaconChainClient(conn)
for _, epoch := range []uint64{50, 100, 1000, 7000} {
fmt.Printf("checking epoch %v\n", epoch)
var totalEffectiveBalance uint64
validatorsResponse := &ethpb.Validators{}
for {
validatorsResponse, err = chainClient.ListValidators(
context.Background(),
&ethpb.ListValidatorsRequest{
PageToken: validatorsResponse.NextPageToken,
PageSize: 500,
QueryFilter: &ethpb.ListValidatorsRequest_Epoch{Epoch: epoch},
},
)
if err != nil {
panic(err)
}
if validatorsResponse.TotalSize == 0 {
break
}
for _, validator := range validatorsResponse.ValidatorList {
if validator.Validator.ActivationEpoch > epoch ||
validator.Validator.ActivationEligibilityEpoch > epoch ||
validator.Validator.ExitEpoch <= epoch {
fmt.Printf("%v %v %v\n", validator.Index, validator.Validator.ActivationEpoch, validator.Validator.ActivationEligibilityEpoch)
}
totalEffectiveBalance += validator.Validator.EffectiveBalance
}
if validatorsResponse.NextPageToken == "" {
break
}
}
validatorParticipation, err := chainClient.GetValidatorParticipation(
context.Background(),
&ethpb.GetValidatorParticipationRequest{
QueryFilter: &ethpb.GetValidatorParticipationRequest_Epoch{Epoch: epoch},
},
)
if err != nil {
panic(err)
}
fmt.Printf("totalEffectiveBalance: %v\n", totalEffectiveBalance)
fmt.Printf("eligibleEther : %v\n", validatorParticipation.Participation.EligibleEther)
fmt.Printf("votedEther : %v\n", validatorParticipation.Participation.VotedEther)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment