hydra-node-0.13.0: The Hydra node
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hydra.Network.Heartbeat

Description

An implementation of an application-level failure detector. This module exposes a Component withHeartbeat than can be used to wrap another NetworkComponent and piggy-back on it to send and propagate Heartbeat messages and detect other parties' liveness.

It is inspired by the Increasing timeout algorithms from the book Introduction to Reliable and Secure Distributed Programming by Cachin et al. which is an Eventually Perfect Failure Detector suitable for partially synchronous network settings. It has the following behaviour:

  • It broadcasts a Ping to other parties through the underlying Network implementation if the last message has been sent more than 3s ago
  • When receiving messages from other parties, it records reception time and notifies underlying node with a Connected message
  • If new messages are received from alive parties before 3s timeout expires no new Connected message is sent * If main thread detects that a formerly alive party has not been seen for more than 3s, it is marked as suspected and a Disconnected message is sent to the node.
Synopsis

Documentation

data HeartbeatState Source #

Constructors

HeartbeatState 

Fields

  • alive :: Map NodeId Time

    The map of known Connected parties with the last time they've been "seen". This is updated when we see a message from another node

  • suspected :: Set NodeId

    The set of known parties which might be Disconnected This is updated after some time no message has been received from a node.

  • lastSent :: Maybe Time

    The timestamp of the last sent message.

Instances

Instances details
Eq HeartbeatState Source # 
Instance details

Defined in Hydra.Network.Heartbeat

data Heartbeat msg Source #

Constructors

Data NodeId msg 
Ping NodeId 

Instances

Instances details
FromJSON msg => FromJSON (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

Methods

parseJSON :: Value -> Parser (Heartbeat msg)

parseJSONList :: Value -> Parser [Heartbeat msg]

ToJSON msg => ToJSON (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

Methods

toJSON :: Heartbeat msg -> Value

toEncoding :: Heartbeat msg -> Encoding

toJSONList :: [Heartbeat msg] -> Value

toEncodingList :: [Heartbeat msg] -> Encoding

Generic (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

Associated Types

type Rep (Heartbeat msg) :: Type -> Type Source #

Methods

from :: Heartbeat msg -> Rep (Heartbeat msg) x Source #

to :: Rep (Heartbeat msg) x -> Heartbeat msg Source #

Show msg => Show (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

FromCBOR msg => FromCBOR (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

Methods

fromCBOR :: Decoder s (Heartbeat msg)

label :: Proxy (Heartbeat msg) -> Text

ToCBOR msg => ToCBOR (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

Methods

toCBOR :: Heartbeat msg -> Encoding

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Heartbeat msg) -> Size

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Heartbeat msg] -> Size

ToCBOR msg => SignableRepresentation (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

Methods

getSignableRepresentation :: Heartbeat msg -> ByteString

Eq msg => Eq (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

Methods

(==) :: Heartbeat msg -> Heartbeat msg -> Bool Source #

(/=) :: Heartbeat msg -> Heartbeat msg -> Bool Source #

type Rep (Heartbeat msg) Source # 
Instance details

Defined in Hydra.Network.Heartbeat

heartbeatDelay :: DiffTime Source #

Delay between each heartbeat check.

livenessDelay :: DiffTime Source #

Maximal delay between expected and sent heartbeats.

withHeartbeat :: (MonadAsync m, MonadDelay m) => NodeId -> ConnectionMessages m -> NetworkComponent m (Heartbeat msg) a -> NetworkComponent m msg a Source #

Wrap a NetworkComponent and handle sending/receiving of heartbeats.

updateStateFromIncomingMessages :: (MonadSTM m, MonadMonotonicTime m) => TVar m HeartbeatState -> ConnectionMessages m -> NetworkCallback msg m -> NetworkCallback (Heartbeat msg) m Source #

updateStateFromOutgoingMessages :: (MonadSTM m, MonadMonotonicTime m) => NodeId -> TVar m HeartbeatState -> Network m (Heartbeat msg) -> Network m msg Source #

updateLastSent :: MonadSTM m => TVar m HeartbeatState -> Time -> m () Source #

checkHeartbeatState :: (MonadDelay m, MonadSTM m) => NodeId -> TVar m HeartbeatState -> Network m (Heartbeat msg) -> m () Source #

checkRemoteParties :: (MonadDelay m, MonadSTM m) => TVar m HeartbeatState -> ConnectionMessages m -> m () Source #

updateSuspected :: MonadSTM m => TVar m HeartbeatState -> Time -> m (Set NodeId) Source #

checkTimeout :: (DiffTime -> DiffTime) -> Time -> Time -> Bool Source #