Skip to content

Commit

Permalink
export NodeToClient Codecs as a single record
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcFontaine committed Apr 6, 2020
1 parent 9e2c68f commit 9653e01
Showing 1 changed file with 51 additions and 35 deletions.
86 changes: 51 additions & 35 deletions ouroboros-consensus/src/Ouroboros/Consensus/NodeNetwork.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ module Ouroboros.Consensus.NodeNetwork (
, ProtocolCodecs (..)
, protocolCodecs
, protocolCodecsId
, staticBlockFetchCodecSerialised
, staticTxSubmissionCodec
, staticLocalChainSyncCodec
, staticLocalTxSubmissionCodec
, staticLocalStateQueryCodec
, NodeToClientCodecs (..)
, nodeToClientCodecs
, ProtocolTracers
, ProtocolTracers' (..)
, nullProtocolTracers
Expand Down Expand Up @@ -277,55 +274,74 @@ protocolCodecs cfg version = ProtocolCodecs {
, pcLocalStateQueryCodec = staticLocalStateQueryCodec
}

data NodeToClientCodecs blk failure m bytesLCS bytesLTX bytesLSQ = NodeToClientCodecs {
nodeToClientChainSyncCodec :: Codec (ChainSync (Serialised blk) (Tip blk))
failure m bytesLCS
, nodeToClientTxSubmissionCodec :: Codec (LocalTxSubmission (GenTx blk) (ApplyTxErr blk))
failure m bytesLTX
, nodeToClientStateQueryCodec :: Codec (LocalStateQuery blk (Query blk))
failure m bytesLSQ
}

nodeToClientCodecs
:: forall m blk. (IOLike m, RunNode blk)
=> NodeToClientVersion
-> NodeToClientCodecs blk DeserialiseFailure m ByteString ByteString ByteString
nodeToClientCodecs NodeToClientV_1 = NodeToClientCodecs {
nodeToClientChainSyncCodec = staticLocalChainSyncCodec
, nodeToClientTxSubmissionCodec = staticLocalTxSubmissionCodec
, nodeToClientStateQueryCodec = staticLocalStateQueryCodec
}

staticBlockFetchCodecSerialised
:: forall m blk. (IOLike m, RunNode blk)
=> Codec (BlockFetch (Serialised blk)) DeserialiseFailure m ByteString
staticBlockFetchCodecSerialised
= codecBlockFetchSerialised
(nodeEncodeHeaderHash (Proxy @blk))
(nodeDecodeHeaderHash (Proxy @blk))
staticBlockFetchCodecSerialised =
codecBlockFetchSerialised
(nodeEncodeHeaderHash (Proxy @blk))
(nodeDecodeHeaderHash (Proxy @blk))

staticTxSubmissionCodec
:: forall m blk. (IOLike m, RunNode blk)
=> Codec (TxSubmission (GenTxId blk) (GenTx blk)) DeserialiseFailure m ByteString
staticTxSubmissionCodec
= codecTxSubmission
nodeEncodeGenTxId
nodeDecodeGenTxId
nodeEncodeGenTx
nodeDecodeGenTx
staticTxSubmissionCodec =
codecTxSubmission
nodeEncodeGenTxId
nodeDecodeGenTxId
nodeEncodeGenTx
nodeDecodeGenTx

staticLocalChainSyncCodec
:: forall m blk. (IOLike m, RunNode blk)
=> Codec (ChainSync (Serialised blk) (Tip blk)) DeserialiseFailure m ByteString
staticLocalChainSyncCodec
= codecChainSyncSerialised
(encodePoint (nodeEncodeHeaderHash (Proxy @blk)))
(decodePoint (nodeDecodeHeaderHash (Proxy @blk)))
(encodeTip (nodeEncodeHeaderHash (Proxy @blk)))
(decodeTip (nodeDecodeHeaderHash (Proxy @blk)))
staticLocalChainSyncCodec =
codecChainSyncSerialised
(encodePoint (nodeEncodeHeaderHash (Proxy @blk)))
(decodePoint (nodeDecodeHeaderHash (Proxy @blk)))
(encodeTip (nodeEncodeHeaderHash (Proxy @blk)))
(decodeTip (nodeDecodeHeaderHash (Proxy @blk)))

staticLocalTxSubmissionCodec
:: forall m blk. (IOLike m, RunNode blk)
=> Codec (LocalTxSubmission (GenTx blk) (ApplyTxErr blk)) DeserialiseFailure m ByteString
staticLocalTxSubmissionCodec
= codecLocalTxSubmission
nodeEncodeGenTx
nodeDecodeGenTx
(nodeEncodeApplyTxError (Proxy @blk))
(nodeDecodeApplyTxError (Proxy @blk))
staticLocalTxSubmissionCodec =
codecLocalTxSubmission
nodeEncodeGenTx
nodeDecodeGenTx
(nodeEncodeApplyTxError (Proxy @blk))
(nodeDecodeApplyTxError (Proxy @blk))

staticLocalStateQueryCodec
:: forall m blk. (IOLike m, RunNode blk)
=> Codec (LocalStateQuery blk (Query blk)) DeserialiseFailure m ByteString
staticLocalStateQueryCodec
= codecLocalStateQuery
(encodePoint (nodeEncodeHeaderHash (Proxy @blk)))
(decodePoint (nodeDecodeHeaderHash (Proxy @blk)))
nodeEncodeQuery
nodeDecodeQuery
nodeEncodeResult
nodeDecodeResult
staticLocalStateQueryCodec =
codecLocalStateQuery
(encodePoint (nodeEncodeHeaderHash (Proxy @blk)))
(decodePoint (nodeDecodeHeaderHash (Proxy @blk)))
nodeEncodeQuery
nodeDecodeQuery
nodeEncodeResult
nodeDecodeResult

-- | Id codecs used in tests.
--
Expand Down

0 comments on commit 9653e01

Please sign in to comment.