Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data FetchClientContext header block (m :: Type -> Type) = FetchClientContext {
- fetchClientCtxTracer :: Tracer m (TraceFetchClientState header)
- fetchClientCtxPolicy :: FetchClientPolicy header block m
- fetchClientCtxStateVars :: FetchClientStateVars m header
- data FetchClientPolicy header block (m :: Type -> Type) = FetchClientPolicy {
- blockFetchSize :: header -> SizeInBytes
- blockMatchesHeader :: header -> block -> Bool
- addFetchedBlock :: Point block -> block -> m ()
- blockForgeUTCTime :: FromConsensus block -> STM m UTCTime
- data FetchClientStateVars (m :: Type -> Type) header = FetchClientStateVars {
- fetchClientStatusVar :: StrictTVar m (PeerFetchStatus header)
- fetchClientInFlightVar :: StrictTVar m (PeerFetchInFlight header)
- fetchClientRequestVar :: TFetchRequestVar m header
- newFetchClientStateVars :: forall (m :: Type -> Type) header. MonadSTM m => STM m (FetchClientStateVars m header)
- readFetchClientState :: forall (m :: Type -> Type) header. MonadSTM m => FetchClientStateVars m header -> STM m (PeerFetchStatus header, PeerFetchInFlight header, FetchClientStateVars m header)
- data PeerFetchStatus header
- data IsIdle
- data PeerFetchInFlight header = PeerFetchInFlight {
- peerFetchReqsInFlight :: !Word
- peerFetchBytesInFlight :: !SizeInBytes
- peerFetchBlocksInFlight :: Set (Point header)
- peerFetchMaxSlotNo :: !MaxSlotNo
- initialPeerFetchInFlight :: PeerFetchInFlight header
- newtype FetchRequest header = FetchRequest {
- fetchRequestFragments :: [AnchoredFragment header]
- addNewFetchRequest :: (MonadSTM m, HasHeader header) => Tracer m (TraceFetchClientState header) -> (header -> SizeInBytes) -> FetchRequest header -> PeerGSV -> FetchClientStateVars m header -> m (PeerFetchStatus header)
- acknowledgeFetchRequest :: MonadSTM m => Tracer m (TraceFetchClientState header) -> ControlMessageSTM m -> FetchClientStateVars m header -> m (Maybe (FetchRequest header, PeerGSV, PeerFetchInFlightLimits))
- startedFetchBatch :: MonadSTM m => Tracer m (TraceFetchClientState header) -> PeerFetchInFlightLimits -> ChainRange (Point header) -> FetchClientStateVars m header -> m ()
- completeBlockDownload :: (MonadSTM m, HasHeader header) => Tracer m (TraceFetchClientState header) -> (header -> SizeInBytes) -> PeerFetchInFlightLimits -> header -> NominalDiffTime -> FetchClientStateVars m header -> m ()
- completeFetchBatch :: MonadSTM m => Tracer m (TraceFetchClientState header) -> PeerFetchInFlightLimits -> ChainRange (Point header) -> FetchClientStateVars m header -> m ()
- rejectedFetchBatch :: (MonadSTM m, HasHeader header) => Tracer m (TraceFetchClientState header) -> (header -> SizeInBytes) -> PeerFetchInFlightLimits -> ChainRange (Point header) -> [header] -> FetchClientStateVars m header -> m ()
- data TraceFetchClientState header
- = AddedFetchRequest (FetchRequest header) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header)
- | AcknowledgedFetchRequest (FetchRequest header)
- | SendFetchRequest (AnchoredFragment header) PeerGSV
- | StartedFetchBatch (ChainRange (Point header)) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header)
- | CompletedBlockFetch (Point header) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header) NominalDiffTime SizeInBytes
- | CompletedFetchBatch (ChainRange (Point header)) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header)
- | RejectedFetchBatch (ChainRange (Point header)) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header)
- | ClientTerminating Int
- data TraceLabelPeer peerid a = TraceLabelPeer peerid a
- data ChainRange point = ChainRange !point !point
- newtype FromConsensus a = FromConsensus {
- unFromConsensus :: a
- data WhetherReceivingTentativeBlocks
Documentation
data FetchClientContext header block (m :: Type -> Type) Source #
The context that is passed into the block fetch protocol client when it is started.
FetchClientContext | |
|
data FetchClientPolicy header block (m :: Type -> Type) Source #
The policy used by the fetch clients. It is set by the central block fetch
logic, and passed to them via the FetchClientRegistry
.
FetchClientPolicy | |
|
data FetchClientStateVars (m :: Type -> Type) header Source #
A set of variables shared between the block fetch logic thread and each
thread executing the client side of the block fetch protocol. That is, these
are the shared variables per peer. The FetchClientRegistry
contains the
mapping of these for all peers.
The variables are used for communicating from the protocol thread to the decision making thread the status of things with that peer. And in the other direction one shared variable is for providing new fetch requests.
FetchClientStateVars | |
|
newFetchClientStateVars :: forall (m :: Type -> Type) header. MonadSTM m => STM m (FetchClientStateVars m header) Source #
readFetchClientState :: forall (m :: Type -> Type) header. MonadSTM m => FetchClientStateVars m header -> STM m (PeerFetchStatus header, PeerFetchInFlight header, FetchClientStateVars m header) Source #
data PeerFetchStatus header Source #
The status of the block fetch communication with a peer. This is maintained by fetch protocol threads and used in the block fetch decision making logic. Changes in this status trigger re-evaluation of fetch decisions.
PeerFetchStatusShutdown | Communication with the peer has failed. This is a temporary status that may occur during the process of shutting down the thread that runs the block fetch protocol. The peer will promptly be removed from the peer registry and so will not be considered at all. |
PeerFetchStatusStarting | Blockfetch is starting up and waiting on corresponding Chainsync |
PeerFetchStatusAberrant | The peer is in a potentially-temporary state in which it has not responded to us within a certain expected time limit. This is not a hard protocol timeout where the whole connection will be abandoned, it is simply a reply that has taken longer than expected. This status is used to trigger re-evaluating which peer to ask for blocks from, so that we can swiftly ask other peers for blocks if one unexpectedly responds too slowly Peers in this state may later return to normal states if communication resumes, or they may eventually hit a hard timeout and fail. |
PeerFetchStatusBusy | Communication with the peer is in a normal state, and the peer is considered too busy to accept new requests. Changing from this state to the ready state is used to trigger re-evaluating fetch decisions and may eventually result in new fetch requests. This state is used as part of a policy to batch new requests: instead of switching to the ready state the moment there is tiny bit of capacity available, the state is changed once the capacity reaches a certain threshold. |
PeerFetchStatusReady (Set (Point header)) IsIdle | Communication with the peer is in a normal state, and the peer is considered ready to accept new requests. The |
Instances
StandardHash header => Show (PeerFetchStatus header) Source # | |
Defined in Ouroboros.Network.BlockFetch.ClientState showsPrec :: Int -> PeerFetchStatus header -> ShowS # show :: PeerFetchStatus header -> String # showList :: [PeerFetchStatus header] -> ShowS # | |
StandardHash header => Eq (PeerFetchStatus header) Source # | |
Defined in Ouroboros.Network.BlockFetch.ClientState (==) :: PeerFetchStatus header -> PeerFetchStatus header -> Bool # (/=) :: PeerFetchStatus header -> PeerFetchStatus header -> Bool # |
Whether this mini protocol instance is in the Idle
State
data PeerFetchInFlight header Source #
The number of requests in-flight and the amount of data in-flight with a peer. This is maintained by fetch protocol threads and used in the block fetch decision making logic.
PeerFetchInFlight | |
|
Instances
StandardHash header => Show (PeerFetchInFlight header) Source # | |
Defined in Ouroboros.Network.BlockFetch.ClientState showsPrec :: Int -> PeerFetchInFlight header -> ShowS # show :: PeerFetchInFlight header -> String # showList :: [PeerFetchInFlight header] -> ShowS # | |
StandardHash header => Eq (PeerFetchInFlight header) Source # | |
Defined in Ouroboros.Network.BlockFetch.ClientState (==) :: PeerFetchInFlight header -> PeerFetchInFlight header -> Bool # (/=) :: PeerFetchInFlight header -> PeerFetchInFlight header -> Bool # |
initialPeerFetchInFlight :: PeerFetchInFlight header Source #
newtype FetchRequest header Source #
FetchRequest | |
|
Instances
HasHeader header => Semigroup (FetchRequest header) Source # | We sometimes have the opportunity to merge fetch request fragments to reduce the number of separate range request messages that we send. We send one message per fragment. It is better to send fewer requests for bigger ranges, rather than lots of requests for small ranges. We never expect fetch requests to overlap (ie have blocks in common) but we do expect a common case that requests will "touch" so that two ranges could be merged into a single contiguous range. This semigroup instance implements this merging when possible, otherwise the two lists of fragments are just appended. A consequence of merging and sending fewer request messages is that tracking the number of requests in-flight a bit more subtle. To track this accurately we have to look at the old request as well a the updated request after any merging. We meed to account for the difference in the number of fragments in the existing request (if any) and in new request. |
Defined in Ouroboros.Network.BlockFetch.ClientState (<>) :: FetchRequest header -> FetchRequest header -> FetchRequest header # sconcat :: NonEmpty (FetchRequest header) -> FetchRequest header # stimes :: Integral b => b -> FetchRequest header -> FetchRequest header # | |
(StandardHash header, Show header) => Show (FetchRequest header) Source # | |
Defined in Ouroboros.Network.BlockFetch.ClientState showsPrec :: Int -> FetchRequest header -> ShowS # show :: FetchRequest header -> String # showList :: [FetchRequest header] -> ShowS # |
addNewFetchRequest :: (MonadSTM m, HasHeader header) => Tracer m (TraceFetchClientState header) -> (header -> SizeInBytes) -> FetchRequest header -> PeerGSV -> FetchClientStateVars m header -> m (PeerFetchStatus header) Source #
Add a new fetch request for a single peer. This is used by the fetch decision logic thread to add new fetch requests.
We have as a pre-condition that all requested blocks are new, i.e. none
should appear in the existing peerFetchBlocksInFlight
. This is a
relatively easy precondition to satisfy since the decision logic can filter
its requests based on this in-flight blocks state, and this operation is the
only operation that grows the in-flight blocks, and is only used by the
fetch decision logic thread.
acknowledgeFetchRequest :: MonadSTM m => Tracer m (TraceFetchClientState header) -> ControlMessageSTM m -> FetchClientStateVars m header -> m (Maybe (FetchRequest header, PeerGSV, PeerFetchInFlightLimits)) Source #
This is used by the fetch client threads.
startedFetchBatch :: MonadSTM m => Tracer m (TraceFetchClientState header) -> PeerFetchInFlightLimits -> ChainRange (Point header) -> FetchClientStateVars m header -> m () Source #
completeBlockDownload :: (MonadSTM m, HasHeader header) => Tracer m (TraceFetchClientState header) -> (header -> SizeInBytes) -> PeerFetchInFlightLimits -> header -> NominalDiffTime -> FetchClientStateVars m header -> m () Source #
completeFetchBatch :: MonadSTM m => Tracer m (TraceFetchClientState header) -> PeerFetchInFlightLimits -> ChainRange (Point header) -> FetchClientStateVars m header -> m () Source #
rejectedFetchBatch :: (MonadSTM m, HasHeader header) => Tracer m (TraceFetchClientState header) -> (header -> SizeInBytes) -> PeerFetchInFlightLimits -> ChainRange (Point header) -> [header] -> FetchClientStateVars m header -> m () Source #
data TraceFetchClientState header Source #
Tracing types for the various events that change the state
(i.e. FetchClientStateVars
) for a block fetch client.
Note that while these are all state changes, the AddedFetchRequest
occurs
in the decision thread while the other state changes occur in the block
fetch client threads.
AddedFetchRequest (FetchRequest header) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header) | The block fetch decision thread has added a new fetch instruction consisting of one or more individual request ranges. |
AcknowledgedFetchRequest (FetchRequest header) | Mark the point when the fetch client picks up the request added
by the block fetch decision thread. Note that this event can happen
fewer times than the |
SendFetchRequest (AnchoredFragment header) PeerGSV | Mark the point when fetch request for a fragment is actually sent over the wire. |
StartedFetchBatch (ChainRange (Point header)) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header) | Mark the start of receiving a streaming batch of blocks. This will
be followed by one or more |
CompletedBlockFetch (Point header) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header) NominalDiffTime SizeInBytes | Mark the completion of of receiving a single block within a streaming batch of blocks. |
CompletedFetchBatch (ChainRange (Point header)) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header) | Mark the successful end of receiving a streaming batch of blocks |
RejectedFetchBatch (ChainRange (Point header)) (PeerFetchInFlight header) PeerFetchInFlightLimits (PeerFetchStatus header) | If the other peer rejects our request then we have this event
instead of |
ClientTerminating Int | The client is terminating. Log the number of outstanding requests. |
Instances
(StandardHash header, Show header) => Show (TraceFetchClientState header) Source # | |
Defined in Ouroboros.Network.BlockFetch.ClientState showsPrec :: Int -> TraceFetchClientState header -> ShowS # show :: TraceFetchClientState header -> String # showList :: [TraceFetchClientState header] -> ShowS # |
data TraceLabelPeer peerid a #
A peer label for use in Tracer
s. This annotates tracer output as being
associated with a given peer identifier.
TraceLabelPeer peerid a |
Instances
Bifunctor TraceLabelPeer | |
Defined in Network.Mux.Trace bimap :: (a -> b) -> (c -> d) -> TraceLabelPeer a c -> TraceLabelPeer b d # first :: (a -> b) -> TraceLabelPeer a c -> TraceLabelPeer b c # second :: (b -> c) -> TraceLabelPeer a b -> TraceLabelPeer a c # | |
Functor (TraceLabelPeer peerid) | |
Defined in Network.Mux.Trace fmap :: (a -> b) -> TraceLabelPeer peerid a -> TraceLabelPeer peerid b # (<$) :: a -> TraceLabelPeer peerid b -> TraceLabelPeer peerid a # | |
(Show peerid, Show a) => Show (TraceLabelPeer peerid a) | |
Defined in Network.Mux.Trace showsPrec :: Int -> TraceLabelPeer peerid a -> ShowS # show :: TraceLabelPeer peerid a -> String # showList :: [TraceLabelPeer peerid a] -> ShowS # | |
(Eq peerid, Eq a) => Eq (TraceLabelPeer peerid a) | |
Defined in Network.Mux.Trace (==) :: TraceLabelPeer peerid a -> TraceLabelPeer peerid a -> Bool # (/=) :: TraceLabelPeer peerid a -> TraceLabelPeer peerid a -> Bool # |
data ChainRange point #
Range of blocks, defined by a lower and upper point, inclusive.
ChainRange !point !point |
Instances
Ancillary
newtype FromConsensus a #
A new type used to emphasize the precondition of
headerForgeUTCTime
and
blockForgeUTCTime
at each
call site.
At time of writing, the a
is either a header or a block. The headers are
literally from Consensus (ie provided by ChainSync). Blocks, on the other
hand, are indirectly from Consensus: they were fetched only because we
favored the corresponding header that Consensus provided.
Instances
Applicative FromConsensus | |
Defined in Ouroboros.Network.BlockFetch.ConsensusInterface pure :: a -> FromConsensus a # (<*>) :: FromConsensus (a -> b) -> FromConsensus a -> FromConsensus b # liftA2 :: (a -> b -> c) -> FromConsensus a -> FromConsensus b -> FromConsensus c # (*>) :: FromConsensus a -> FromConsensus b -> FromConsensus b # (<*) :: FromConsensus a -> FromConsensus b -> FromConsensus a # | |
Functor FromConsensus | |
Defined in Ouroboros.Network.BlockFetch.ConsensusInterface fmap :: (a -> b) -> FromConsensus a -> FromConsensus b # (<$) :: a -> FromConsensus b -> FromConsensus a # |
data WhetherReceivingTentativeBlocks #
Whether the block fetch peer is sending tentative blocks, which are understood to possibly be invalid