-
Notifications
You must be signed in to change notification settings - Fork 32
Add NodeToNode Codec for PerasCertDiffusion #1658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: peras-staging
Are you sure you want to change the base?
Conversation
Move encode/decode functions for certs to proper file
9c03877
to
124925a
Compare
Given what we said in the weekly meeting today, I think this should be enough to complete ticket tweag/cardano-peras#85. Let me know if I missed something :) |
encodePerasRoundNo :: PerasRoundNo -> CBOR.Encoding | ||
encodePerasRoundNo (PerasRoundNo{..}) = | ||
CBOR.encodeWord64 unPerasRoundNo | ||
|
||
decodePerasRoundNo :: forall s. CBOR.Decoder s PerasRoundNo | ||
decodePerasRoundNo = | ||
PerasRoundNo <$> CBOR.decodeWord64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encodePerasRoundNo pcCertRound | ||
<> (encodePoint (encodeRawHash p) pcCertBoostedBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we serialize a self-contained entity (like a cert/block/tx/whatever), we want it to be valid CBOR by itself. Currently, this isn't valid, but rather the juxtaposition of two valid CBOR items. To make it well-formed, you can add add a encodeListLen 2
. (Dually, the decoder should use decodeListLenOf 2
.)
Related: We should eventually test stuff like this; I created tweag/cardano-peras#103 for that.
Also see the validFlatTerm
function for testing such stuff interactively, eg:
Λ import Codec.CBOR.Encoding
Λ import Codec.CBOR.FlatTerm
Λ validFlatTerm $ toFlatTerm $ encodeWord64 123 <> encodeWord64 456
False
Λ validFlatTerm $ toFlatTerm $ encodeListLen 2 <> encodeWord64 123 <> encodeWord64 456
True
in a cabal repl -b cborg
.
encodePerasCert :: forall blk. ConvertRawHash blk => Proxy blk -> PerasCert blk -> CBOR.Encoding | ||
encodePerasCert p (PerasCert{..}) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of exposing en-/decoding functions, we could also already define a SerialiseNodeToNode
instace for PerasCert
(which will be required by tweag/cardano-peras#73 in any case)
Closes github.com/tweag/cardano-peras/issues/85.