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
cardano-testnet: Waiting for blocks using
EpochStateView
. #5836cardano-testnet: Waiting for blocks using
EpochStateView
. #5836Changes from all commits
9c80e65
7e0c341
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.
What was wrong with the
IORef
? If we are going to useTChan
s andTMVar
s there needs to be good justification for doing so. I don't immediately see the benefit of this increased complexity in an already tedious testing environment.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 goal here is to listen to changes of
EpochStateView
. You can't do this just usingIORef
. You could do this usingMVar
, and having watching threads block on emptyMVar
and continue whenMVar
gets filled. But then you still need additionalIORef
for functions checking for currentEpochStateView
without blocking. The problem with usingMVar
andIORef
at the same time, is that you don't have any guarantees about the order of operations in the listening thread. In other words, If you updateIORef
andMVar
in order in one thread, the other threads may see it in a different order. This means that listeners waiting onMVar ()
may see staleIORef
value.I've chosen
STM
which gives you a single view on both of variables, but you don't haveMVar
analogue for waiting in multiple threads for an update of a singleMVar
. (TMVar
is only single-wakeup).If we want to avoid STM here, we can define view and lock:
assuming we won't use one value to check the other, because they can be out-of-sync.
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.
Why do we need to notify the listeners about changes? I could understand wanting to notify listeners of changes if the changes are short lived but they are not (or at least I can't think of any that are). What problem is this solving? Why specifically do we need this level of granularity?
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.
It's an alternative to
watchEpochStateView
which is polling every 100msEpochStateView
. Sometimes new epoch state is updated much slower, like once every few seconds. So it saves some CPU on needlessly computing the check again and again on the same input.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.
I think the additional complexity is not worth it. We should be using the
atomic*
versions of theIORef
functions to avoid race conditions/partial writes etc.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 you can't implement blocking and waiting or multi-wakeup using just
IORef
.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.
If you feel that
MVar
s are too much, I can rewrite this PR using polling inwatchEpochStateView
.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.
Why do we need this? If the goal is to "listen to changes of EpochStateView" and your reason is:
I say the complexity is not worth it. The changes we are interested in don't require this level of granularity. Saving a little bit of CPU does not justify the additional complexity.
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.
Waiting on
MVar
is not that much more complex than polling. I'll rewrite the PR using polling then.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 one I wrote already uses polling, you can use that one, or tune it