Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[CDEC-356] Force ntp check #3323

Merged
merged 3 commits into from
Aug 6, 2018
Merged

[CDEC-356] Force ntp check #3323

merged 3 commits into from
Aug 6, 2018

Conversation

coot
Copy link
Contributor

@coot coot commented Jul 30, 2018

Description

Force ntp check by overwriting NtpStatus mutable cell.

Linked issue

https://iohk.myjetbrains.com/youtrack/issue/CDEC-356

Type of change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🛠 New feature (non-breaking change which adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
  • 🔨 New or improved tests for existing code
  • ⛑ git-flow chore (backport, hotfix, etc)

Developer checklist

  • I have read the style guide document, and my code follows the code style of this project.
  • If my code deals with exceptions, it follows the guidelines.
  • I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on cardanodocs.com, amending the inline Haddock comments, any relevant README file or one of the document listed in the docs directory.

Testing checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.

QA Steps

Screenshots (if available)

@coot coot requested a review from avieth July 30, 2018 08:45
@coot coot requested a review from dcoutts as a code owner July 30, 2018 08:45
Copy link
Contributor

@avieth avieth left a comment

Choose a reason for hiding this comment

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

@coot could you give me a brief description of why this change is needed?

@@ -192,6 +204,13 @@ sendLoop cli addrs = do
retry
logDebug "collected all responses"

forceRequest =
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused about the name. It looks like this doesn't really force anything, rather it waits for something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll rename it.

@coot
Copy link
Contributor Author

coot commented Jul 31, 2018

@avieth this is required by the wallet. There are occasions where a wallet user might be asked to rerun the ntp check. A user will click a button and the wallet backend will receive a request to force ntp check. This is a minimal change to support this functionality. The wallet can re-use the already exposed NtpState TVar to force an ntp check.

case cmd of
Nothing -> cancel a
Just SendRequest
-> sendLoop cli addrs
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it right to recurse here? It's not tail recursive. Is it possible that we get a stack overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's a real danger, it can only be triggered by the end user action. But maybe there is a simple solution to get tail recursion here, I'll look into that.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we recurse here, is it still necessary to do lines 194-196? If not, put them in the Nothing case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right, we don't need to recurs here at all. It's fine if we just return () and recurs only in the tail position. The timeout poll (wait a) will wait until either the poll timeout or somebody (re)set the ncStatus :: TVar NtpStatus.

-- after @'updateStatus'@ @'ntpStatus'@ is guaranteed to be
-- different from @'NtpSyncPending'@, now we can wait until it was
-- changed back to @'NtpSyncPending'@ to force a request.
waitForRequest
Copy link
Contributor

@avieth avieth Aug 1, 2018

Choose a reason for hiding this comment

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

One more question, this time about the withAsync concurrency here. Why is it needed? Could this not be done sequentially by sendPacketing, then timeout respTimeout waitForResponses, then waitForRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, unless the ntp servers answer faster than haskell executes waitForResponses ;)

@coot
Copy link
Contributor Author

coot commented Aug 2, 2018

@avieth I was looking in the Network.Socket documentation and I found that:

If AF_INET6 is used and the socket type is Stream or Datagram, the IPv6Only socket option is set to 0 so that both IPv4 and IPv6 can be handled with one socket.

This means we can further simplify the ntp client, there's no need to distinguish ipv4 and ipv6 sockets.

@avieth
Copy link
Contributor

avieth commented Aug 2, 2018

This means we can further simplify the ntp client, there's no need to distinguish ipv4 and ipv6 sockets.

Nice. No mention of cross-platform support though. Would be good to verify that.

@coot coot merged commit 3a6e31a into develop Aug 6, 2018
@coot coot deleted the coot/cdec-356 branch January 22, 2019 15:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants