@@ -17,7 +17,7 @@ module Ouroboros.Network.Protocol.ChainSync.Codec
17
17
import Control.Monad.Class.MonadST
18
18
import Control.Monad.Class.MonadTime.SI
19
19
20
- import Network.TypedProtocol.Codec.CBOR hiding (encode , decode )
20
+ import Network.TypedProtocol.Codec.CBOR hiding (decode , encode )
21
21
22
22
import Ouroboros.Network.Protocol.ChainSync.Type
23
23
import Ouroboros.Network.Protocol.Limits
@@ -35,8 +35,8 @@ import Text.Printf
35
35
36
36
37
37
-- | Byte Limits
38
- byteLimitsChainSync :: forall bytes header point tip .
39
- (bytes -> Word )
38
+ byteLimitsChainSync :: forall bytes ( header :: Type ) ( point :: Type ) ( tip :: Type ) .
39
+ (bytes -> Word ) -- ^ compute size of `bytes`
40
40
-> ProtocolSizeLimits (ChainSync header point tip ) bytes
41
41
byteLimitsChainSync = ProtocolSizeLimits stateToLimit
42
42
where
@@ -63,10 +63,21 @@ maxChainSyncTimeout = 269
63
63
64
64
-- | Time Limits
65
65
--
66
- -- > 'TokIdle' 'waitForever' (ie never times out)
67
- -- > 'TokNext TokCanAwait' the given 'canAwaitTimeout'
68
- -- > 'TokNext TokMustReply' the given 'mustReplyTimeout'
69
- -- > 'TokIntersect' the given 'intersectTimeout'
66
+ -- +----------------------------+-------------------------------------------------------------+
67
+ -- | ChainSync State | timeout (s) |
68
+ -- +============================+=============================================================+
69
+ -- | @'StIdle'@ | 'waitForever' (i.e. never times out) |
70
+ -- +----------------------------+-------------------------------------------------------------+
71
+ -- | @'StNext' 'StCanAwait'@ | 'shortWait' |
72
+ -- +----------------------------+-------------------------------------------------------------+
73
+ -- | @'StNext' 'StMustReply'@ | randomly picked using uniform distribution from |
74
+ -- | | the range @('minChainSyncTimeout', 'maxChainSyncTimeout')@, |
75
+ -- | | which corresponds to a chance of an empty streak of slots |
76
+ -- | | between `0.0001%` and `1%` probability. |
77
+ -- +----------------------------+-------------------------------------------------------------+
78
+ -- | @'StIntersect'@ | 'shortWait' |
79
+ -- +----------------------------+-------------------------------------------------------------+
80
+ --
70
81
timeLimitsChainSync :: forall header point tip .
71
82
StdGen
72
83
-> ProtocolTimeLimits (ChainSync header point tip )
@@ -97,18 +108,26 @@ timeLimitsChainSync rnd = ProtocolTimeLimits stateToLimit
97
108
$ rnd
98
109
in Just timeout
99
110
stateToLimit a@ SingDone = notActiveState a
111
+
112
+ -- | Codec for chain sync that encodes/decodes headers, points & tips.
100
113
--
101
- -- NOTE: See 'wrapCBORinCBOR' and 'unwrapCBORinCBOR' if you want to use this
114
+ -- / NOTE:/ See 'wrapCBORinCBOR' and 'unwrapCBORinCBOR' if you want to use this
102
115
-- with a header type that has annotations.
103
116
codecChainSync
104
117
:: forall header point tip m .
105
118
(MonadST m )
106
119
=> (header -> CBOR. Encoding )
120
+ -- ^ encode header
107
121
-> (forall s . CBOR. Decoder s header )
122
+ -- ^ decode header
108
123
-> (point -> CBOR. Encoding )
124
+ -- ^ encode point
109
125
-> (forall s . CBOR. Decoder s point )
126
+ -- ^ decode point
110
127
-> (tip -> CBOR. Encoding )
128
+ -- ^ encode tip
111
129
-> (forall s . CBOR. Decoder s tip )
130
+ -- ^ decode tip
112
131
-> Codec (ChainSync header point tip )
113
132
CBOR. DeserialiseFailure m LBS. ByteString
114
133
codecChainSync encodeHeader decodeHeader
@@ -230,7 +249,7 @@ decodeList dec = do
230
249
-- | An identity 'Codec' for the 'ChainSync' protocol. It does not do any
231
250
-- serialisation. It keeps the typed messages, wrapped in 'AnyMessage'.
232
251
--
233
- codecChainSyncId :: forall header point tip m . Monad m
252
+ codecChainSyncId :: forall ( header :: Type ) ( point :: Type ) ( tip :: Type ) m . Monad m
234
253
=> Codec (ChainSync header point tip )
235
254
CodecFailure m (AnyMessage (ChainSync header point tip ))
236
255
codecChainSyncId = Codec encode decode
0 commit comments