Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests data we have for this function suggests that for 12s slot window clock at 12.5 would still be
zero
slot. To align implementation with the tests data we have to useMath.floor
here. Or else if that's not the case then we should change the tests data else it will be fail.lodestar/packages/validator/test/unit/utils/clock.test.ts
Line 90 in 6a47911
With changing back to
round
it will returnnextSlot + 1
when the clock current time is around the slot boundary.See this output
https://github.com/ChainSafe/lodestar/actions/runs/7652507863/job/20852823580#step:6:714
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we are not applying
Math.round
on the delta, it is applied on the slots since genensis which is based on diff in seconds since genesis.The goal of
getCurrentSlotAround
is clearly that it returns the closest slot, see PR that introduced this #2736.Running those tests locally a few times I can see that those fail sometimes with Math.round and also with Math.floor
When I use
Math.floor
the 12.5s test fails sometimes, and withMath.round
the 11.5s test fails.This is clearly an issue with the tests, and those need to be made more robust. A bit strange is that it only happens with vitest, with mocha those consistenly seem to pass. Weird timing issue I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the answer is to fix the test cases, not force the implementation to change for the buggy tests.
Merging this for now to fix the noticeable validator performance regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes test cases don't enforce implementation, but fixture data particularly guide what kind of behavior we expect form the implementation.