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.
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
VC: Hardening and optimizing time handling. #4743
VC: Hardening and optimizing time handling. #4743
Changes from 6 commits
e17a785
6beb537
b21adc9
17336cd
5740df5
5be531a
447332f
aa4a00d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Ideally we would remove
durationToNextSlot
andfromNow
- both of these are compound operations that mix "current time" from the global clock with "time arithmetic" which leads to problems and confusion in code that uses them, since getting the "current time" generally should only be done in a controlled way:await
boundariestherefore:
fromNow
,durationToNext*
etcnow
consistently when the current time is needed as the only function that accesses the global clockdurationFrom(a, b: BeaconTime): tuple[future: bool, dur: Duration]
as is done infromNow
bn
andvc
to use the above functionsfromNow
becomesslot.start_beacon_time().durationFrom(clock.now())
durationToNextSlot
becomeslet now = clock.now(); saturate((now.slotOrZero() + 1).start_beacon_time().durationFrom(now))
more or less (slotOrZero
is incorrect for pre-genesis - it needs to return duration to genesis for any time before genesis)BeaconTime
and do the saturation if need be, but these helpers should never access the clock itselfdurationFrom
can be added for slot vs time etc to make it less verbosedurationFrom
can also bedurationTo
or some other name or shape - doesn't matter which direction it goes in, but sinceDuration
is undefined for negative values, we need to return a tuple - we also sometimes need to know that genesis hasn't happened yet, so we don't always want to saturate.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.
Proposed solution do not support negative Slot values which is happened when you are running before genesis. So it become impossible to provide such UX experience like it was done now. Because its impossible to supply negative Slot values it is very hard to find proper argument value for
durationFrom/durationTo
. Its whydurationToNextSlot
looks the most appropriate name for the procedure which is able to calculate duration to next slot which is either before or after genesis.