Skip to content

Commit 565b4d1

Browse files
committed
ouroboros-network-protocols: improved haddocks of node-to-node protocols
1 parent 3e6298f commit 565b4d1

File tree

6 files changed

+123
-50
lines changed

6 files changed

+123
-50
lines changed

ouroboros-network-framework/src/Ouroboros/Network/Protocol/Handshake/Codec.hs

+12-4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ byteLimitsHandshake = ProtocolSizeLimits stateToLimit (fromIntegral . BL.length)
9999

100100
-- | Time limits.
101101
--
102+
-- +--------------------+-------------+
103+
-- | 'Handshake' state | timeout (s) |
104+
-- +====================+=============+
105+
-- | `StPropose` | `shortWait` |
106+
-- +--------------------+-------------+
107+
-- | `StConfirm` | `shortWait` |
108+
-- +--------------------+-------------+
109+
--
102110
timeLimitsHandshake :: forall vNumber. ProtocolTimeLimits (Handshake vNumber CBOR.Term)
103111
timeLimitsHandshake = ProtocolTimeLimits stateToLimit
104112
where
@@ -123,10 +131,9 @@ noTimeLimitsHandshake = ProtocolTimeLimits stateToLimit
123131

124132
-- |
125133
-- @'Handshake'@ codec. The @'MsgProposeVersions'@ encodes proposed map in
126-
-- ascending order and it expects to receive them in this order. This allows
127-
-- to construct the map in linear time. There is also another limiting factor
128-
-- to the number of versions on can present: the whole message must fit into
129-
-- a single TCP segment.
134+
-- ascending order and it expects to receive them in this order. The whole
135+
-- `MsgProposeVersions` message must fit into a single TCP segment which limits
136+
-- number of versions that can be proposed.
130137
--
131138
codecHandshake
132139
:: forall vNumber m failure.
@@ -135,6 +142,7 @@ codecHandshake
135142
, Show failure
136143
)
137144
=> CodecCBORTerm (failure, Maybe Int) vNumber
145+
-- ^ `CBOR.Term` codec for `vNumber`
138146
-> Codec (Handshake vNumber CBOR.Term) CBOR.DeserialiseFailure m ByteString
139147
codecHandshake versionNumberCodec = mkCodecCborLazyBS encodeMsg decodeMsg
140148
where

ouroboros-network-protocols/src/Ouroboros/Network/Protocol/BlockFetch/Codec.hs

+17-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Ouroboros.Network.Protocol.Limits
3131

3232
-- | Byte Limit.
3333
byteLimitsBlockFetch :: forall bytes block point.
34-
(bytes -> Word)
34+
(bytes -> Word) -- ^ compute size of bytes
3535
-> ProtocolSizeLimits (BlockFetch block point) bytes
3636
byteLimitsBlockFetch = ProtocolSizeLimits stateToLimit
3737
where
@@ -44,10 +44,16 @@ byteLimitsBlockFetch = ProtocolSizeLimits stateToLimit
4444

4545
-- | Time Limits
4646
--
47-
-- `TokIdle' No timeout
48-
-- `TokBusy` `longWait` timeout
49-
-- `TokStreaming` `longWait` timeout
50-
timeLimitsBlockFetch :: forall block point.
47+
-- +------------------+---------------+
48+
-- | BlockFetch state | timeout (s) |
49+
-- +==================+===============+
50+
-- | `BFIdle` | `waitForever` |
51+
-- +------------------+---------------+
52+
-- | `BFBusy` | `longWait` |
53+
-- +------------------+---------------+
54+
-- | `BFStreaming` | `longWait` |
55+
-- +------------------+---------------+
56+
--
5157
ProtocolTimeLimits (BlockFetch block point)
5258
timeLimitsBlockFetch = ProtocolTimeLimits stateToLimit
5359
where
@@ -58,17 +64,21 @@ timeLimitsBlockFetch = ProtocolTimeLimits stateToLimit
5864
stateToLimit SingBFStreaming = longWait
5965
stateToLimit a@SingBFDone = notActiveState a
6066

61-
-- | Codec for chain sync that encodes/decodes blocks
67+
-- | Codec for chain sync that encodes/decodes blocks and points.
6268
--
63-
-- NOTE: See 'wrapCBORinCBOR' and 'unwrapCBORinCBOR' if you want to use this
69+
-- /NOTE:/ See 'wrapCBORinCBOR' and 'unwrapCBORinCBOR' if you want to use this
6470
-- with a block type that has annotations.
6571
codecBlockFetch
6672
:: forall block point m.
6773
MonadST m
6874
=> (block -> CBOR.Encoding)
75+
-- ^ encode block
6976
-> (forall s. CBOR.Decoder s block)
77+
-- ^ decode block
7078
-> (point -> CBOR.Encoding)
79+
-- ^ encode point
7180
-> (forall s. CBOR.Decoder s point)
81+
-- ^ decode point
7282
-> Codec (BlockFetch block point) CBOR.DeserialiseFailure m LBS.ByteString
7383
codecBlockFetch encodeBlock decodeBlock
7484
encodePoint decodePoint =

ouroboros-network-protocols/src/Ouroboros/Network/Protocol/ChainSync/Codec.hs

+28-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Ouroboros.Network.Protocol.ChainSync.Codec
1717
import Control.Monad.Class.MonadST
1818
import Control.Monad.Class.MonadTime.SI
1919

20-
import Network.TypedProtocol.Codec.CBOR hiding (encode, decode)
20+
import Network.TypedProtocol.Codec.CBOR hiding (decode, encode)
2121

2222
import Ouroboros.Network.Protocol.ChainSync.Type
2323
import Ouroboros.Network.Protocol.Limits
@@ -35,8 +35,8 @@ import Text.Printf
3535

3636

3737
-- | 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`
4040
-> ProtocolSizeLimits (ChainSync header point tip) bytes
4141
byteLimitsChainSync = ProtocolSizeLimits stateToLimit
4242
where
@@ -63,10 +63,21 @@ maxChainSyncTimeout = 269
6363

6464
-- | Time Limits
6565
--
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+
--
7081
timeLimitsChainSync :: forall header point tip.
7182
StdGen
7283
-> ProtocolTimeLimits (ChainSync header point tip)
@@ -97,18 +108,26 @@ timeLimitsChainSync rnd = ProtocolTimeLimits stateToLimit
97108
$ rnd
98109
in Just timeout
99110
stateToLimit a@SingDone = notActiveState a
111+
112+
-- | Codec for chain sync that encodes/decodes headers, points & tips.
100113
--
101-
-- NOTE: See 'wrapCBORinCBOR' and 'unwrapCBORinCBOR' if you want to use this
114+
-- /NOTE:/ See 'wrapCBORinCBOR' and 'unwrapCBORinCBOR' if you want to use this
102115
-- with a header type that has annotations.
103116
codecChainSync
104117
:: forall header point tip m.
105118
(MonadST m)
106119
=> (header -> CBOR.Encoding)
120+
-- ^ encode header
107121
-> (forall s . CBOR.Decoder s header)
122+
-- ^ decode header
108123
-> (point -> CBOR.Encoding)
124+
-- ^ encode point
109125
-> (forall s . CBOR.Decoder s point)
126+
-- ^ decode point
110127
-> (tip -> CBOR.Encoding)
128+
-- ^ encode tip
111129
-> (forall s. CBOR.Decoder s tip)
130+
-- ^ decode tip
112131
-> Codec (ChainSync header point tip)
113132
CBOR.DeserialiseFailure m LBS.ByteString
114133
codecChainSync encodeHeader decodeHeader
@@ -230,7 +249,7 @@ decodeList dec = do
230249
-- | An identity 'Codec' for the 'ChainSync' protocol. It does not do any
231250
-- serialisation. It keeps the typed messages, wrapped in 'AnyMessage'.
232251
--
233-
codecChainSyncId :: forall header point tip m. Monad m
252+
codecChainSyncId :: forall (header :: Type) (point :: Type) (tip :: Type) m. Monad m
234253
=> Codec (ChainSync header point tip)
235254
CodecFailure m (AnyMessage (ChainSync header point tip))
236255
codecChainSyncId = Codec encode decode

ouroboros-network-protocols/src/Ouroboros/Network/Protocol/KeepAlive/Codec.hs

+10
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ byteLimitsKeepAlive = ProtocolSizeLimits sizeLimitForState
8686
sizeLimitForState a@SingDone = notActiveState a
8787

8888

89+
-- | 'KeepAlive' time limits.
90+
--
91+
-- +--------------------+---------------+
92+
-- | 'KeepAlive' state | timeout (s) |
93+
-- +====================+===============+
94+
-- | `StClient` | @Just 97@ |
95+
-- +--------------------+---------------+
96+
-- | `StServer` | @Just 60@ |
97+
-- +--------------------+---------------+
98+
--
8999
timeLimitsKeepAlive :: ProtocolTimeLimits KeepAlive
90100
timeLimitsKeepAlive = ProtocolTimeLimits { timeLimitForState }
91101
where

ouroboros-network-protocols/src/Ouroboros/Network/Protocol/PeerSharing/Codec.hs

+16-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import Ouroboros.Network.Protocol.PeerSharing.Type
2626
codecPeerSharing :: forall m peerAddress.
2727
MonadST m
2828
=> (peerAddress -> CBOR.Encoding)
29+
-- ^ encode 'peerAddress'
2930
-> (forall s . CBOR.Decoder s peerAddress)
31+
-- ^ decode 'peerAddress'
3032
-> Codec (PeerSharing peerAddress)
31-
CBOR.DeserialiseFailure
32-
m
33-
ByteString
33+
CBOR.DeserialiseFailure
34+
m
35+
ByteString
3436
codecPeerSharing encodeAddress decodeAddress = mkCodecCborLazyBS encodeMsg decodeMsg
3537
where
3638
encodeMsg :: Message (PeerSharing peerAddress) st st'
@@ -120,7 +122,7 @@ maxTransmissionUnit :: Word
120122
maxTransmissionUnit = 4 * 1440
121123

122124
byteLimitsPeerSharing :: forall peerAddress bytes.
123-
(bytes -> Word)
125+
(bytes -> Word) -- ^ compute size of bytes
124126
-> ProtocolSizeLimits (PeerSharing peerAddress) bytes
125127
byteLimitsPeerSharing = ProtocolSizeLimits sizeLimitForState
126128
where
@@ -132,7 +134,16 @@ byteLimitsPeerSharing = ProtocolSizeLimits sizeLimitForState
132134
sizeLimitForState a@SingDone = notActiveState a
133135

134136

135-
timeLimitsPeerSharing :: forall peerAddress. ProtocolTimeLimits (PeerSharing peerAddress)
137+
-- | 'PeerSharing' timeouts.
138+
--
139+
-- +----------------------+---------------+
140+
-- | 'PeerSharing' state | timeout (s) |
141+
-- +======================+===============+
142+
-- | `StIdle` | `waitForever` |
143+
-- +----------------------+---------------+
144+
-- | `StBusy` | `longWait` |
145+
-- +----------------------+---------------+
146+
--
136147
timeLimitsPeerSharing = ProtocolTimeLimits { timeLimitForState }
137148
where
138149
timeLimitForState :: forall (st :: PeerSharing peerAddress).

ouroboros-network-protocols/src/Ouroboros/Network/Protocol/TxSubmission2/Codec.hs

+40-25
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,22 @@ byteLimitsTxSubmission2 = ProtocolSizeLimits stateToLimit
4747
stateToLimit a@SingDone = notActiveState a
4848

4949

50-
-- | Time Limits.
50+
-- | 'TxSubmission2' time limits.
51+
--
52+
-- +-----------------------------+---------------+
53+
-- | 'TxSubmission2' state | timeout (s) |
54+
-- +=============================+===============+
55+
-- | `StInit` | `waitForever` |
56+
-- +-----------------------------+---------------+
57+
-- | `StIdle` | `waitForever` |
58+
-- +-----------------------------+---------------+
59+
-- | @'StTxIds' 'StBlocking'@ | `waitForever` |
60+
-- +-----------------------------+---------------+
61+
-- | @'StTxIds' 'StNonBlocking'@ | `shortWait` |
62+
-- +-----------------------------+---------------+
63+
-- | `StTxs` | `shortWait` |
64+
-- +-----------------------------+---------------+
5165
--
52-
-- `SingTxIds SingBlocking` No timeout
53-
-- `SingTxIds SingNonBlocking` `shortWait` timeout
54-
-- `SingTxs` `shortWait` timeout
55-
-- `SingIdle` `shortWait` timeout
56-
timeLimitsTxSubmission2 :: forall txid tx. ProtocolTimeLimits (TxSubmission2 txid tx)
5766
timeLimitsTxSubmission2 = ProtocolTimeLimits stateToLimit
5867
where
5968
stateToLimit :: forall (st :: TxSubmission2 txid tx).
@@ -70,9 +79,13 @@ codecTxSubmission2
7079
:: forall txid tx m.
7180
MonadST m
7281
=> (txid -> CBOR.Encoding)
82+
-- ^ encode 'txid'
7383
-> (forall s . CBOR.Decoder s txid)
84+
-- ^ decode 'txid'
7485
-> (tx -> CBOR.Encoding)
86+
-- ^ encode transaction
7587
-> (forall s . CBOR.Decoder s tx)
88+
-- ^ decode transaction
7689
-> Codec (TxSubmission2 txid tx) CBOR.DeserialiseFailure m ByteString
7790
codecTxSubmission2 encodeTxId decodeTxId
7891
encodeTx decodeTx =
@@ -90,16 +103,17 @@ codecTxSubmission2 encodeTxId decodeTxId
90103
decodeTxSubmission2 decodeTxId decodeTx stok len key
91104

92105
encodeTxSubmission2
93-
:: forall txid tx.
106+
:: forall txid tx (st :: TxSubmission2 txid tx) (st' :: TxSubmission2 txid tx).
94107
(txid -> CBOR.Encoding)
108+
-- ^ encode 'txid'
95109
-> (tx -> CBOR.Encoding)
96-
-> (forall (st :: TxSubmission2 txid tx) (st' :: TxSubmission2 txid tx).
97-
Message (TxSubmission2 txid tx) st st'
98-
-> CBOR.Encoding)
110+
-- ^ encode 'tx'
111+
-> Message (TxSubmission2 txid tx) st st'
112+
-> CBOR.Encoding
99113
encodeTxSubmission2 encodeTxId encodeTx = encode
100114
where
101-
encode :: forall st st'.
102-
Message (TxSubmission2 txid tx) st st'
115+
encode :: forall st0 st1.
116+
Message (TxSubmission2 txid tx) st0 st1
103117
-> CBOR.Encoding
104118
encode MsgInit =
105119
CBOR.encodeListLen 1
@@ -148,23 +162,24 @@ encodeTxSubmission2 encodeTxId encodeTx = encode
148162

149163

150164
decodeTxSubmission2
151-
:: forall txid tx.
152-
(forall s . CBOR.Decoder s txid)
153-
-> (forall s . CBOR.Decoder s tx)
154-
-> (forall (st :: TxSubmission2 txid tx) s.
155-
ActiveState st
156-
=> StateToken st
157-
-> Int
158-
-> Word
159-
-> CBOR.Decoder s (SomeMessage st))
165+
:: forall (txid :: Type) (tx :: Type) (st :: TxSubmission2 txid tx) s.
166+
ActiveState st
167+
=> (forall s'. CBOR.Decoder s' txid)
168+
-- ^ decode 'txid'
169+
-> (forall s'. CBOR.Decoder s' tx)
170+
-- ^ decode transaction
171+
-> StateToken st
172+
-> Int
173+
-> Word
174+
-> CBOR.Decoder s (SomeMessage st)
160175
decodeTxSubmission2 decodeTxId decodeTx = decode
161176
where
162-
decode :: forall s (st :: TxSubmission2 txid tx).
163-
ActiveState st
164-
=> StateToken st
177+
decode :: forall (st' :: TxSubmission2 txid tx).
178+
ActiveState st'
179+
=> StateToken st'
165180
-> Int
166181
-> Word
167-
-> CBOR.Decoder s (SomeMessage st)
182+
-> CBOR.Decoder s (SomeMessage st')
168183
decode stok len key = do
169184
case (stok, len, key) of
170185
(SingInit, 1, 6) ->

0 commit comments

Comments
 (0)