Skip to content
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

Simplify and clarify code for local-cluster #25

Merged
12 commits merged into from
Jun 25, 2021

Conversation

ghost
Copy link

@ghost ghost commented Jun 21, 2021

The local-cluster project was the first code we wrote and some stuff in it are redundant with stuff we wrote later, or ill-named.

  • Replace local-cluster Logging with Hydra.Logging
  • Move Ports utility module to Hydra.Network and use its feature there, namely in the NetworkSpec tests
  • Rename Lib -> CardanoCluster and Node -> CardanoNode

The changes introduced made it even more apparent how flaky our NetworkSpec tests were so this PR also fixes that by:

  • Having a simpler way to check we broadcast to all nodes in the tests
  • Increasing timeout of Ouroboros network tests to 30s to give time to the framework to retry failed connection attempts

@ghost ghost requested review from KtorZ and ch1bo June 21, 2021 08:29
@ghost
Copy link
Author

ghost commented Jun 21, 2021

This PR was triggered by this ticket in our board's Red Bin: https://miro.com/app/board/o9J_lRyWcSY=/?moveToWidget=3074457360130079706&cot=14

hydra-node/test/Hydra/NetworkSpec.hs Show resolved Hide resolved
@ghost ghost force-pushed the abailly-iohk/unify-local-cluster-code branch from c81b5a6 to 3b6f315 Compare June 21, 2021 11:35
@ghost ghost force-pushed the abailly-iohk/unify-local-cluster-code branch 3 times, most recently from d9afdd4 to 9a19190 Compare June 24, 2021 12:31
@ghost ghost requested a review from KtorZ June 24, 2021 12:46
hydra-node/hydra-node.cabal Outdated Show resolved Hide resolved
hydra-node/src/Hydra/Network/Ouroboros.hs Outdated Show resolved Hide resolved
hydra-node/test/Hydra/NetworkSpec.hs Show resolved Hide resolved
hydra-node/test/Hydra/NetworkSpec.hs Outdated Show resolved Hide resolved
abailly added 11 commits June 24, 2021 15:40
The local-cluster project was the first code we wrote and some stuff
in it are redundant with stuff we wrote later, or ill-named.

* Replace local-cluster Logging with Hydra.Logging
* Move Ports utility module to Hydra.Network and use its feature there
* Rename Lib -> CardanoCluster and Node -> CardanoNode
This does not seem to improve the stability of the tests but it's
still better to not have hard coded ports like that lying around.
There is a fixed retry window of 10s in Ouroboros networking code that
cannot be configured hence having a 10s timeout runs a high risk of
failing because a node which fails to connect won't have the time to
reconnect.
@ghost ghost force-pushed the abailly-iohk/unify-local-cluster-code branch from c26d3a2 to af56a16 Compare June 24, 2021 15:50
Copy link
Member

@ch1bo ch1bo left a comment

Choose a reason for hiding this comment

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

Only minor things remain, but can also be merged like this

data WithHost trace = WithHost Host trace
deriving (Show)

data TraceOuroborosNetwork msg
= TraceSubscriptions (WithIPList (SubscriptionTrace SockAddr))
| TraceErrorPolicy (WithAddr SockAddr ErrorPolicyTrace)
| TraceAcceptPolicy AcceptConnectionsPolicyTrace
Copy link
Member

Choose a reason for hiding this comment

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

Seeing the naming convention of ouroboros-network of likely being XXXTrace for trace types. Shall we adopt that as well? We have at least TraceXXX and XXXLog in use.

Copy link
Member

Choose a reason for hiding this comment

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

No change required here, just starting the conversation :)

@@ -254,9 +256,14 @@ withOuroborosNetwork tracer localHost remoteHosts networkCallback between = do
, recvMsgDone = pure ()
}

data TraceOuroborosNetwork
data WithHost trace = WithHost Host trace
Copy link
Member

Choose a reason for hiding this comment

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

Isn't hlint warning that this could be a newtype? if yes, I'd follow that suggestion

| SubscribedTo [String]
| MessageSent Host LByteString
| LogMessageReceived Host Text
| SubscribedTo Host [String]
deriving (Show)
Copy link
Member

Choose a reason for hiding this comment

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

Could: use the WithHost type you introduced

Comment on lines +93 to +96
parallelBroadcast :: IO () -> [(PortNumber, Network IO Integer, TQueue IO Integer)] -> IO ()
parallelBroadcast check [] = check
parallelBroadcast check ((port, network, _) : rest) =
withAsync (fromIntegral port `broadcastFrom` network) $ \_ -> parallelBroadcast check rest
Copy link
Member

Choose a reason for hiding this comment

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

Could: This function is passing check around to just have it as "core" to the withAsync chain.. an alternative (which reads a bit clearer to me, would be to race_ (parallelBroadcast networks) checkQueues above and consequently:

Suggested change
parallelBroadcast :: IO () -> [(PortNumber, Network IO Integer, TQueue IO Integer)] -> IO ()
parallelBroadcast check [] = check
parallelBroadcast check ((port, network, _) : rest) =
withAsync (fromIntegral port `broadcastFrom` network) $ \_ -> parallelBroadcast check rest
parallelBroadcast :: [(PortNumber, Network IO Integer, TQueue IO Integer)] -> IO ()
parallelBroadcast [] = pure ()
parallelBroadcast [(port, network, _)] = fromIntegral port `broadcastFrom` network
parallelBroadcast ((port, network, _) : rest) =
withAsync (fromIntegral port `broadcastFrom` network) $ \_ -> parallelBroadcast rest

@@ -84,6 +82,7 @@ library
, hspec-expectations
, http-conduit
, hydra-prelude
, hydra-node
Copy link
Member

Choose a reason for hiding this comment

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

As we have this here anyway, I guess I'd prefer the Hydra.Network.Ports to be in hydra-node instead of the hydra-prelude. May I move it or WDYT?

@ghost
Copy link
Author

ghost commented Jun 25, 2021

@ch1bo All valid points, I will address them after the merge.

@ghost ghost merged commit a2ebd35 into master Jun 25, 2021
@ghost ghost deleted the abailly-iohk/unify-local-cluster-code branch June 25, 2021 06:51
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants