Skip to content

Commit

Permalink
More debug info for validator withdrawal calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Mar 11, 2024
1 parent 564228f commit dd68af4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/validator/withdrawal/process.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Weald Technology Trading.
// Copyright © 2023, 2024 Weald Technology Trading.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -61,7 +61,7 @@ func (c *command) process(ctx context.Context) error {
return errors.Wrap(err, "failed to obtain block slot")
}
if c.debug {
fmt.Fprintf(os.Stderr, "Slot is %d\n", slot)
fmt.Fprintf(os.Stderr, "Current slot is %d\n", slot)
}

response, err := c.consensusClient.(consensusclient.ValidatorsProvider).Validators(ctx, &api.ValidatorsOpts{
Expand All @@ -88,6 +88,8 @@ func (c *command) process(ctx context.Context) error {
fmt.Fprintf(os.Stderr, "Next withdrawal validator index is %d\n", nextWithdrawalValidatorIndex)
}

withdrawalSlot := slot + 1
withdrawalsInSlot := 0
index := int(nextWithdrawalValidatorIndex)
for {
if index == len(validators) {
Expand All @@ -97,11 +99,20 @@ func (c *command) process(ctx context.Context) error {
break
}
if validators[index].Validator.WithdrawalCredentials[0] == ethWithdrawalPrefix &&
validators[index].Validator.EffectiveBalance == c.maxEffectiveBalance {
validators[index].Validator.EffectiveBalance == c.maxEffectiveBalance &&
validators[index].Validator.ActivationEpoch <= c.chainTime.SlotToEpoch(withdrawalSlot) {
c.res.WithdrawalsToGo++
withdrawalsInSlot++
if withdrawalsInSlot == int(c.maxWithdrawalsPerPayload) {
withdrawalSlot++
withdrawalsInSlot = 0
}
}
index++
}
if c.debug {
fmt.Fprintf(os.Stderr, "There are %d withdrawals to go until this validator\n", c.res.WithdrawalsToGo)
}

c.res.BlocksToGo = c.res.WithdrawalsToGo / c.maxWithdrawalsPerPayload
if c.res.WithdrawalsToGo%c.maxWithdrawalsPerPayload != 0 {
Expand Down

0 comments on commit dd68af4

Please sign in to comment.