Line data Source code
1 : #ifndef HEADER_fd_src_choreo_votor_ag_cert_serde_h 2 : #define HEADER_fd_src_choreo_votor_ag_cert_serde_h 3 : 4 : #include "ag_cert.h" 5 : #include "ag_bls_serde.h" 6 : 7 42 : #define AG_CERT_DE_SUCCESS ( 0) 8 54 : #define AG_CERT_DE_ERR_SZ (-1) /* Io(ReadSizeLimit), TrailingBytes, PreallocationSizeLimit, LengthEncodingOverflow */ 9 0 : #define AG_CERT_DE_ERR_INVAL (-2) /* InvalidTagEncoding, InvalidValue */ 10 : 11 : FD_STATIC_ASSERT( AG_BLS_DE_SUCCESS ==AG_CERT_DE_SUCCESS, ag_cert_serde ); 12 : FD_STATIC_ASSERT( AG_BLS_DE_ERR_SZ ==AG_CERT_DE_ERR_SZ, ag_cert_serde ); 13 : FD_STATIC_ASSERT( AG_BLS_DE_ERR_INVAL==AG_CERT_DE_ERR_INVAL, ag_cert_serde ); 14 : 15 171 : #define AG_CERT_SERDE_TAG_FINAL ( 7) /* WireConsensusMessageKind::FinalizeCert #[wincode(tag = 7)] */ 16 0 : #define AG_CERT_SERDE_TAG_FAST_FINAL ( 8) /* WireConsensusMessageKind::FastFinalizeCert #[wincode(tag = 8)] */ 17 0 : #define AG_CERT_SERDE_TAG_NOTAR ( 9) /* WireConsensusMessageKind::NotarCert #[wincode(tag = 9)] */ 18 0 : #define AG_CERT_SERDE_TAG_NOTAR_FALLBACK (10) /* WireConsensusMessageKind::NotarFallbackCert #[wincode(tag = 10)] */ 19 0 : #define AG_CERT_SERDE_TAG_SKIP (11) /* WireConsensusMessageKind::SkipCert #[wincode(tag = 11)] */ 20 : 21 : FD_STATIC_ASSERT( AG_CERT_KIND_FINAL +7==AG_CERT_SERDE_TAG_FINAL, ag_cert_serde ); 22 : FD_STATIC_ASSERT( AG_CERT_KIND_FAST_FINAL +7==AG_CERT_SERDE_TAG_FAST_FINAL, ag_cert_serde ); 23 : FD_STATIC_ASSERT( AG_CERT_KIND_NOTAR +7==AG_CERT_SERDE_TAG_NOTAR, ag_cert_serde ); 24 : FD_STATIC_ASSERT( AG_CERT_KIND_NOTAR_FALLBACK+7==AG_CERT_SERDE_TAG_NOTAR_FALLBACK, ag_cert_serde ); 25 : FD_STATIC_ASSERT( AG_CERT_KIND_SKIP +7==AG_CERT_SERDE_TAG_SKIP, ag_cert_serde ); 26 : 27 : struct ag_cert_serde { 28 : uchar version; /* VersionedWireConsensusMessage::V1 (u8 tag) */ 29 : uchar tag; /* WireConsensusMessageKind (u8 tag) */ 30 : ulong slot; /* WireSlotCertMessage::slot (Slot) */ 31 : uchar const * block_id; /* Block::block_id (Hash) */ 32 : uchar const * signature; /* WireCertSignature::signature (BLSSignature) */ 33 : ulong bitmap_sz; /* WireCertSignature::bitmap len (u64) */ 34 : uchar const * bitmap; /* WireCertSignature::bitmap (Vec<u8>) */ 35 : ushort shred_version; /* WireConsensusMessageV1::shred_version (u16) */ 36 : }; 37 : typedef struct ag_cert_serde ag_cert_serde_t; 38 : 39 96 : #define AG_CERT_SER_HDR_SZ( has_block_id ) ( sizeof(uchar) /* version */ + \ 40 96 : sizeof(uchar) /* kind */ + \ 41 96 : sizeof(ulong) /* slot */ + \ 42 96 : ( (has_block_id) ? sizeof(ag_block_hash_t) : 0UL ) /* block_id */ + \ 43 96 : FD_BLS_SIG_SZ /* signature */ + \ 44 96 : sizeof(ulong) /* bitmap_sz */ ) 45 : 46 : #define AG_CERT_SER_MAX ( AG_CERT_SER_HDR_SZ( 1 ) + \ 47 : AG_BLS_AGG_PAIR_SER_MAX + \ 48 : sizeof(ushort) /* shred_version */ ) 49 : 50 : FD_PROTOTYPES_BEGIN 51 : 52 : ulong 53 : ag_cert_ser( ag_cert_t const * self, 54 : uchar buf[ static AG_CERT_SER_MAX ] ); 55 : 56 : int 57 : ag_cert_de( ag_cert_t * cert, 58 : uchar const * buf, 59 : ulong buf_sz ); 60 : 61 : FD_PROTOTYPES_END 62 : 63 : #endif /* HEADER_fd_src_choreo_votor_ag_cert_serde_h */