Skip to content

Commit

Permalink
Merge pull request #2857 from gobitfly/NOBIDS/[email protected]+
Browse files Browse the repository at this point in the history
Nobids/fix for [email protected]+
  • Loading branch information
guybrush authored Apr 12, 2024
2 parents 3392a09 + 634fdd4 commit b46a311
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
33 changes: 33 additions & 0 deletions cmd/misc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ var opts = struct {
Yes bool
}{}

var lighthouseClient *rpc.LighthouseClient

func main() {
statsPartitionCommand := commands.StatsMigratorCommand{}

Expand Down Expand Up @@ -124,6 +126,7 @@ func main() {
if err != nil {
utils.LogFatal(err, "lighthouse client error", 0)
}
lighthouseClient = rpcClient

erigonClient, err := rpc.NewErigonClient(utils.Config.Eth1ErigonEndpoint)
if err != nil {
Expand Down Expand Up @@ -400,6 +403,8 @@ func main() {
ratelimit.DBUpdater()
case "disable-user-per-email":
err = disableUserPerEmail()
case "fix-epochs":
err = fixEpochs()
default:
utils.LogFatal(nil, fmt.Sprintf("unknown command %s", opts.Command), 0)
}
Expand All @@ -411,6 +416,34 @@ func main() {
}
}

func fixEpochs() error {
for e := opts.StartEpoch; e <= opts.EndEpoch; e++ {
err := fixEpoch(e)
if err != nil {
return fmt.Errorf("error fixingEpoch: %v: %w", e, err)
}
logrus.Infof("fixed epoch %v", e)
}
return nil
}

func fixEpoch(e uint64) error {
tx, err := db.WriterDb.Beginx()
if err != nil {
return fmt.Errorf("error starting tx: %w", err)
}
defer tx.Rollback()
s, err := lighthouseClient.GetValidatorParticipation(e)
if err != nil {
return err
}
err = db.UpdateEpochStatus(s, tx)
if err != nil {
return err
}
return tx.Commit()
}

func disableUserPerEmail() error {
if opts.Email == "" {
return errors.New("no email specified")
Expand Down
18 changes: 17 additions & 1 deletion rpc/lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,25 @@ func (lc *LighthouseClient) GetValidatorParticipation(epoch uint64) (*types.Vali
var res *types.ValidatorParticipation
if epoch < request_epoch {
// we requested the next epoch, so we have to use the previous value for everything here

prevEpochActiveGwei := parsedResponse.Data.PreviousEpochActiveGwei
if prevEpochActiveGwei == 0 {
// [email protected]+ has no previous_epoch_active_gwei field anymore, see https://github.com/sigp/lighthouse/pull/5279
prevResp, err := lc.get(fmt.Sprintf("%s/lighthouse/validator_inclusion/%d/global", lc.endpoint, request_epoch-1))
if err != nil {
return nil, fmt.Errorf("error retrieving validator participation data for prevEpoch %v: %w", request_epoch-1, err)
}
var parsedPrevResponse LighthouseValidatorParticipationResponse
err = json.Unmarshal(prevResp, &parsedPrevResponse)
if err != nil {
return nil, fmt.Errorf("error parsing validator participation data for prevEpoch %v: %w", epoch, err)
}
prevEpochActiveGwei = parsedPrevResponse.Data.CurrentEpochActiveGwei
}

res = &types.ValidatorParticipation{
Epoch: epoch,
GlobalParticipationRate: float32(parsedResponse.Data.PreviousEpochTargetAttestingGwei) / float32(parsedResponse.Data.PreviousEpochActiveGwei),
GlobalParticipationRate: float32(parsedResponse.Data.PreviousEpochTargetAttestingGwei) / float32(prevEpochActiveGwei),
VotedEther: uint64(parsedResponse.Data.PreviousEpochTargetAttestingGwei),
EligibleEther: uint64(parsedResponse.Data.PreviousEpochActiveGwei),
Finalized: epoch <= head.FinalizedEpoch && head.JustifiedEpoch > 0,
Expand Down

0 comments on commit b46a311

Please sign in to comment.