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

Provide an applicative network heartbeat #15

Merged
18 commits merged into from
Jun 10, 2021
Merged

Conversation

ghost
Copy link

@ghost ghost commented Jun 9, 2021

Remove connectivity check from concrete HydraNetwork implementations and implement a generic Heartbeat wrapper that independently sends heartbeats/pings across the network for some time.
This also illustrates the "decorator" pattern as exposed in https://github.com/input-output-hk/hydra-poc/blob/master/docs/adr/0007-with-pattern-component-interfaces.md

Next steps:

  • Provide similar component for self-sending messages.

abailly added 11 commits June 4, 2021 14:25
This probably makes the whole HeartbeatMessage / HydraMessage
dichotomy redundant but I keep it for now for the sake of illustrating
map/contramap transformation of messages.
As Heartbeat logic has moved out of Network layer, ensuring messages
are properly broadcasted requires actively retrying until they are
seen on all nodes, as startup time might lead to messages being
dropped.
@ghost ghost requested review from ch1bo and KtorZ June 9, 2021 16:08
hydra-node/src/Hydra/Network.hs Outdated Show resolved Hide resolved
hydra-node/src/Hydra/Network.hs Show resolved Hide resolved
hydra-node/src/Hydra/Network/Heartbeat.hs Outdated Show resolved Hide resolved
@@ -71,6 +80,7 @@ instance ToCBOR tx => ToCBOR (HydraMessage tx) where
ReqSn -> toCBOR ("ReqSn" :: Text)
AckSn -> toCBOR ("AckSn" :: Text)
ConfSn -> toCBOR ("ConfSn" :: Text)
Ping pty -> toCBOR ("ConfSn" :: Text) <> toCBOR pty
Copy link
Member

Choose a reason for hiding this comment

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

Wrong identifier!

Suggested change
Ping pty -> toCBOR ("ConfSn" :: Text) <> toCBOR pty
Ping pty -> toCBOR ("Ping" :: Text) <> toCBOR pty

hydra-node/src/Hydra/Network/Heartbeat.hs Outdated Show resolved Hide resolved
hydra-node/src/Hydra/Network/Ouroboros.hs Outdated Show resolved Hide resolved
hydra-node/test/Hydra/Network/HeartbeatSpec.hs Outdated Show resolved Hide resolved
hydra-node/test/Hydra/Network/HeartbeatSpec.hs Outdated Show resolved Hide resolved

broadcast hn3 requestTx
failAfter 1 $ takeMVar node1received `shouldReturn` MessageReceived requestTx
failAfter 1 $ takeMVar node2received `shouldReturn` MessageReceived requestTx
Copy link
Member

Choose a reason for hiding this comment

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

Would this not pass anymore? The new assertions do simultaneously broadcast the same message from different senders, right?

Copy link
Author

Choose a reason for hiding this comment

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

Not sure I understand.

Copy link
Author

Choose a reason for hiding this comment

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

Make each requestTx different for each node so that we have a narrower shotgun...


waitForOtherNodesConnected :: [Int] -> HydraNode -> IO ()
waitForOtherNodesConnected allNodeIds n@HydraNode{hydraNodeId} =
mapM_ (\otherNode -> waitForResponse 10 [n] $ "NodeConnectedToNetwork " <> show otherNode) $ filter (/= hydraNodeId) allNodeIds
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename the output to NodeConnectedToPeer?

forever $ do
threadDelay 0.5
st <- atomically $ readTVar heartbeatState
when (st == SendHeartbeat) $ broadcast (Ping me)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't this exit instead when the heartbeat is stopped? Or do we expect the heartbeat to be restarted?

sendRequest n1 "Init [1, 2, 3]"
waitForResponse 3 [n1] "ReadyToCommit"

metrics <- getMetrics n1
metrics `shouldSatisfy` ("hydra_head_events 3" `BS.isInfixOf`)
metrics `shouldSatisfy` ("hydra_head_events 5" `BS.isInfixOf`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 ? Pings are now included?

@ghost ghost merged commit b647bba into master Jun 10, 2021
@ghost ghost deleted the abailly-iohk/network-heartbeat branch June 10, 2021 11:02
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