Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use go ticker instead of timer #14134

Merged
merged 5 commits into from
Jun 25, 2024

Conversation

hoanguyenkh
Copy link
Contributor

What type of PR is this?

Refactor code, using ticker instead of timer

What does this PR do? Why is it needed?

Which issues(s) does this PR fix?

Fixes #

Other notes for review

@hoanguyenkh hoanguyenkh requested a review from a team as a code owner June 24, 2024 12:48
@rauljordan
Copy link
Contributor

hi @james-prysm wondering if you can take a look at this one

@@ -100,14 +100,13 @@ func (vs *Server) WaitForActivation(req *ethpb.ValidatorActivationRequest, strea
}

waitTime := time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second
timer := time.NewTimer(waitTime)
defer timer.Stop()
ticker := time.NewTicker(waitTime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to use a ticker here , instead using the New Timer because we only have a 1 time action. Wait for Activation only triggers if there are 0 active keys while accounts are updated. the action no longer needs to run afterwards

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop finishes when activeValidatorExists is true, and using NewTicker will remove the need for the manual timer.Reset(waitTime) call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that's fair, I think you're right on this and I was mistaken

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this I'll go ahead and approve

@james-prysm james-prysm added this pull request to the merge queue Jun 25, 2024
Merged via the queue into prysmaticlabs:develop with commit aad29ff Jun 25, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants