| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.MiniProtocol.ChainSync.Client
Contents
Synopsis
- type Consensus (client :: Type -> Type -> Type -> (Type -> Type) -> Type -> Type) blk m = client (Header blk) (Point blk) (Tip blk) m ChainSyncClientResult
- chainSyncClient :: forall m blk. (IOLike m, LedgerSupportsProtocol blk) => MkPipelineDecision -> Tracer m (TraceChainSyncClientEvent blk) -> TopLevelConfig blk -> ChainDbView m blk -> NodeToNodeVersion -> ControlMessageSTM m -> StrictTVar m (AnchoredFragment (Header blk)) -> Consensus ChainSyncClientPipelined blk m
- bracketChainSyncClient :: (IOLike m, Ord peer, BlockSupportsProtocol blk, LedgerSupportsProtocol blk) => Tracer m (TraceChainSyncClientEvent blk) -> ChainDbView m blk -> StrictTVar m (Map peer (StrictTVar m (AnchoredFragment (Header blk)))) -> peer -> (StrictTVar m (AnchoredFragment (Header blk)) -> m a) -> m a
- data ChainSyncClientResult
- = forall blk.BlockSupportsProtocol blk => ForkTooDeep (Point blk) (Our (Tip blk)) (Their (Tip blk))
- | forall blk.BlockSupportsProtocol blk => NoMoreIntersection (Our (Tip blk)) (Their (Tip blk))
- | forall blk.BlockSupportsProtocol blk => RolledBackPastIntersection (Point blk) (Our (Tip blk)) (Their (Tip blk))
- | AskedToTerminate
- data ChainSyncClientException
- = forall blk.(BlockSupportsProtocol blk, ValidateEnvelope blk) => HeaderError (Point blk) (HeaderError blk) (Our (Tip blk)) (Their (Tip blk))
- | forall blk.BlockSupportsProtocol blk => InvalidIntersection (Point blk) (Our (Tip blk)) (Their (Tip blk))
- | forall blk.BlockSupportsProtocol blk => DoesntFit (ChainHash blk) (ChainHash blk) (Our (Tip blk)) (Their (Tip blk))
- | forall blk.LedgerSupportsProtocol blk => InvalidBlock (Point blk) (InvalidBlockReason blk)
- data ChainDbView m blk = ChainDbView {
- getCurrentChain :: STM m (AnchoredFragment (Header blk))
- getHeaderStateHistory :: STM m (HeaderStateHistory blk)
- getPastLedger :: Point blk -> STM m (Maybe (ExtLedgerState blk))
- getIsInvalidBlock :: STM m (WithFingerprint (HeaderHash blk -> Maybe (InvalidBlockReason blk)))
- defaultChainDbView :: ChainDB m blk -> ChainDbView m blk
- newtype Our a = Our {
- unOur :: a
- newtype Their a = Their {
- unTheir :: a
- data TraceChainSyncClientEvent blk
- = TraceDownloadedHeader (Header blk)
- | TraceRolledBack (Point blk)
- | TraceFoundIntersection (Point blk) (Our (Tip blk)) (Their (Tip blk))
- | TraceException ChainSyncClientException
- data InvalidBlockReason blk
Documentation
type Consensus (client :: Type -> Type -> Type -> (Type -> Type) -> Type -> Type) blk m = client (Header blk) (Point blk) (Tip blk) m ChainSyncClientResult Source #
chainSyncClient :: forall m blk. (IOLike m, LedgerSupportsProtocol blk) => MkPipelineDecision -> Tracer m (TraceChainSyncClientEvent blk) -> TopLevelConfig blk -> ChainDbView m blk -> NodeToNodeVersion -> ControlMessageSTM m -> StrictTVar m (AnchoredFragment (Header blk)) -> Consensus ChainSyncClientPipelined blk m Source #
Chain sync client
This never terminates. In case of a failure, a ChainSyncClientException
is thrown. The network layer classifies exception such that the
corresponding peer will never be chosen again.
bracketChainSyncClient Source #
Arguments
| :: (IOLike m, Ord peer, BlockSupportsProtocol blk, LedgerSupportsProtocol blk) | |
| => Tracer m (TraceChainSyncClientEvent blk) | |
| -> ChainDbView m blk | |
| -> StrictTVar m (Map peer (StrictTVar m (AnchoredFragment (Header blk)))) | The candidate chains, we need the whole map because we
(de)register nodes ( |
| -> peer | |
| -> (StrictTVar m (AnchoredFragment (Header blk)) -> m a) | |
| -> m a |
data ChainSyncClientResult Source #
The Chain sync client only _gracefully_ terminates when the upstream node's chain is not interesting (e.g., forked off too far in the past). By gracefully terminating, the network layer can keep the other mini-protocols connect to the same upstream node running.
For example, a relay node will often receive connections from nodes syncing from scratch or an old chain. Since these nodes have a chain that is shorter than the relay node's chain, it's useless for the relay node to run the client-side of the chain sync protocol. However, the other direction of the protocol, and, e.g., the transaction submission protocol, should keep running.
Constructors
| forall blk.BlockSupportsProtocol blk => ForkTooDeep | The server we're connecting to forked more than |
| forall blk.BlockSupportsProtocol blk => NoMoreIntersection (Our (Tip blk)) (Their (Tip blk)) | Our chain changed such that it no longer intersects with the candidate's fragment, and asking for a new intersection did not yield one. |
| forall blk.BlockSupportsProtocol blk => RolledBackPastIntersection | We were asked to roll back past the anchor point of the candidate's
fragment. This means the candidate chain no longer forks off within
|
| AskedToTerminate | We were asked to terminate via the |
Instances
| Eq ChainSyncClientResult Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.ChainSync.Client Methods (==) :: ChainSyncClientResult -> ChainSyncClientResult -> Bool # (/=) :: ChainSyncClientResult -> ChainSyncClientResult -> Bool # | |
| Show ChainSyncClientResult Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.ChainSync.Client Methods showsPrec :: Int -> ChainSyncClientResult -> ShowS # show :: ChainSyncClientResult -> String # showList :: [ChainSyncClientResult] -> ShowS # | |
data ChainSyncClientException Source #
When the upstream node violates the protocol or exhibits malicious behaviour, e.g., serving an invalid header or a header corresponding to a known invalid block, we throw an exception to disconnect. This will bring down all miniprotocols in both directions with that node.
Constructors
| forall blk.(BlockSupportsProtocol blk, ValidateEnvelope blk) => HeaderError | Header validation threw an error. |
| forall blk.BlockSupportsProtocol blk => InvalidIntersection | We send the upstream node a bunch of points from a chain fragment and the upstream node responded with an intersection point that is not on our chain fragment, and thus not among the points we sent. We store the intersection point the upstream node sent us. |
| forall blk.BlockSupportsProtocol blk => DoesntFit | The received header to roll forward doesn't fit onto the previous one. The first |
| forall blk.LedgerSupportsProtocol blk => InvalidBlock | The upstream node's chain contained a block that we know is invalid. |
Fields
| |
Instances
| Eq ChainSyncClientException Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.ChainSync.Client Methods (==) :: ChainSyncClientException -> ChainSyncClientException -> Bool # (/=) :: ChainSyncClientException -> ChainSyncClientException -> Bool # | |
| Show ChainSyncClientException Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.ChainSync.Client Methods showsPrec :: Int -> ChainSyncClientException -> ShowS # show :: ChainSyncClientException -> String # showList :: [ChainSyncClientException] -> ShowS # | |
| Exception ChainSyncClientException Source # | |
data ChainDbView m blk Source #
Abstract over the ChainDB
Constructors
| ChainDbView | |
Fields
| |
defaultChainDbView :: ChainDB m blk -> ChainDbView m blk Source #
Trace events
data TraceChainSyncClientEvent blk Source #
Events traced by the Chain Sync Client.
Constructors
| TraceDownloadedHeader (Header blk) | While following a candidate chain, we rolled forward by downloading a header. |
| TraceRolledBack (Point blk) | While following a candidate chain, we rolled back to the given point. |
| TraceFoundIntersection (Point blk) (Our (Tip blk)) (Their (Tip blk)) | We found an intersection between our chain fragment and the candidate's chain. |
| TraceException ChainSyncClientException | An exception was thrown by the Chain Sync Client. |
Instances
| (BlockSupportsProtocol blk, Eq (ValidationErr (BlockProtocol blk)), Eq (Header blk)) => Eq (TraceChainSyncClientEvent blk) Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.ChainSync.Client Methods (==) :: TraceChainSyncClientEvent blk -> TraceChainSyncClientEvent blk -> Bool # (/=) :: TraceChainSyncClientEvent blk -> TraceChainSyncClientEvent blk -> Bool # | |
| (BlockSupportsProtocol blk, Show (Header blk)) => Show (TraceChainSyncClientEvent blk) Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.ChainSync.Client Methods showsPrec :: Int -> TraceChainSyncClientEvent blk -> ShowS # show :: TraceChainSyncClientEvent blk -> String # showList :: [TraceChainSyncClientEvent blk] -> ShowS # | |
data InvalidBlockReason blk Source #
The reason why a block is invalid.