-
Notifications
You must be signed in to change notification settings - Fork 217
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
Rework slotting functions #2352
Conversation
beffe61
to
965e543
Compare
e76a218
to
efde25f
Compare
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.
Ok, separating the RelativeTime
Maybe
problem seems fair.
Currently the TimeInterpreter is fetched from the network layer through an IORef (or similar). Then the query is run in IO, when most of the time it's a pure computation (due to the changes above). This just muddles things up.
Maybe. I think there's value in allowing the TimeInterpreter
including the IORef
to escape from the NetworkLayer and to be modified by combinators.
currentEpoch ti = ti . epochAt =<< liftIO getCurrentTime | ||
-- | This is 'Ouroboros.Consensus.HardFork.History.Qry.Qry' wrapped in a reader | ||
-- to provide the blockchain system start time as context. | ||
type Qry = ReaderT StartTime HF.Qry |
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.
Ok, neat!
-- If the current time is before the system start (this would only happen when | ||
-- launching testnets), the relative time is reported as 0. | ||
currentRelativeTime :: MonadIO m => TimeInterpreter m -> m RelativeTime | ||
currentRelativeTime ti = ti getStartTime >>= getCurrentTimeRelativeFromStart |
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.
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.
OK thanks.
Maybe we should change MonadIO
to just IO
, or MonadTime
(from io-sim-classes package).
7e52749
to
85ebd67
Compare
@rvl I rebased off master and added a hint fix commit. I'll leave it to you to squash and merge. Although the tests are suddenly failing 🤔 That seems weird.
|
85ebd67
to
24c2c7b
Compare
Thanks. I have never seen that test failure locally. It looks like a new one. bors r+ |
Build succeeded: |
Overview
I am looking at the changes in #2245 related to slotting.
The way the error handling is, it seems like we are walking around with our shoelaces tied together.
Times relative to system start
Part of the problem is that converting a UTC time into a time relative to the system start can fail. (
UTCTimeToRel :: UTCTime -> Qry (Maybe Cardano.RelativeTime)
). But, really in most cases it won't. The best way to deal with that is to push relative time conversions outside of the queries. Then the caller of the slotting can make decisions about how to get a RelativeTime.Things like converting a slot range to a time range become much simpler.
Shorten Slotting module.
We already chopped out a lot of old code in #2351.
But if we use unembellished types from ouroboros-consensus, this module can be even shorter.
Qry
is now just aReaderT
wrapper aroundHF.Qry
.Running a query is to just apply the start time parameter to
runReaderT
and then callOuroboros.Consensus.HardFork.History.Qry.interpretQuery
.Mixing with
IO
Sometimes we want to know the chain-relative time for "now". A simplification is to assume that "now" is always after the start time. In the corner case, it suffices to use the relative time of 0. Now callers of this function don't need to worry about whether it can fail somehow.
Relative times are usually better - e.g. Sync progress
The calculation of sync progress with UTC is something like
(b - a - s) / (b - s)
. But with relative times it's justa / b
.Todo
Separate running a query from obtaining the time interpreter
Currently the TimeInterpreter is fetched from the network layer through an IORef (or similar). Then the query is run in IO, when most of the time it's a pure computation (due to the changes above). This just muddles things up.
Stake pool retirement time
Because stake pool retirement epochs are almost certainly past time safe zone, we need to use the unsafeExtend function to assume that the current epoch is the final epoch.
Transaction expiry (TTL)
Expiry times need to be converted fo/from slots. But these are rarely going to be outside of the safe zone. If they are, it is fine to refuse to convert, and show "Nothing" (for incoming tx) or reject the payment request (for outgoing tx).