Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_alpenglow_fd_block_marker_serde_h 2 : #define HEADER_fd_src_flamenco_alpenglow_fd_block_marker_serde_h 3 : 4 : #include "fd_block_marker.h" 5 : 6 747 : #define FD_BLOCK_MARKER_DE_SUCCESS ( 0) 7 4401 : #define FD_BLOCK_MARKER_DE_ERR_SZ (-1) /* Io(ReadSizeLimit), PreallocationSizeLimit, Custom("LengthPrefixed: inner serialized size does not match length prefix") */ 8 27 : #define FD_BLOCK_MARKER_DE_ERR_INVAL (-2) /* InvalidTagEncoding, InvalidValue */ 9 3 : #define FD_BLOCK_MARKER_DE_ERR_UNSUPPORTED (-3) /* no wincode error: BlockMarkerV1::GenesisCertificate decodes in agave but fd_block_marker_t cannot carry it */ 10 : 11 : /* BlockMarkerV1: https://github.com/anza-xyz/agave/blob/v4.3.0-beta.0/entry/src/block_component.rs#L380-L386 */ 12 : 13 93 : #define FD_BLOCK_MARKER_SERDE_TAG_FOOTER (0) /* BlockMarkerV1::BlockFooter (implicit tag 0) */ 14 96 : #define FD_BLOCK_MARKER_SERDE_TAG_HEADER (1) /* BlockMarkerV1::BlockHeader (implicit tag 1) */ 15 6 : #define FD_BLOCK_MARKER_SERDE_TAG_UPDATE_PARENT (2) /* BlockMarkerV1::UpdateParent (implicit tag 2) */ 16 3 : #define FD_BLOCK_MARKER_SERDE_TAG_GENESIS_CERT (3) /* BlockMarkerV1::GenesisCertificate (implicit tag 3) */ 17 : 18 : FD_STATIC_ASSERT( FD_BLOCK_MARKER_KIND_FOOTER ==FD_BLOCK_MARKER_SERDE_TAG_FOOTER, fd_block_marker_serde ); 19 : FD_STATIC_ASSERT( FD_BLOCK_MARKER_KIND_HEADER ==FD_BLOCK_MARKER_SERDE_TAG_HEADER, fd_block_marker_serde ); 20 : FD_STATIC_ASSERT( FD_BLOCK_MARKER_KIND_UPDATE_PARENT==FD_BLOCK_MARKER_SERDE_TAG_UPDATE_PARENT, fd_block_marker_serde ); 21 : FD_STATIC_ASSERT( FD_BLOCK_MARKER_KIND_GENESIS_CERT ==FD_BLOCK_MARKER_SERDE_TAG_GENESIS_CERT, fd_block_marker_serde ); 22 : 23 135 : #define FD_BLOCK_MARKER_PREAMBLE_SZ ( sizeof(ulong) /* entry_cnt */ + \ 24 135 : sizeof(ushort) /* version */ + \ 25 135 : sizeof(uchar) /* tag */ + \ 26 135 : sizeof(ushort) /* length */ ) 27 : 28 : #define FD_BLOCK_HEADER_SER_SZ ( sizeof(uchar) /* version */ + \ 29 : sizeof(ulong) /* parent_slot */ + \ 30 : sizeof(fd_hash_t) /* parent_block_id */ ) 31 : 32 : #define FD_UPDATE_PARENT_SER_SZ ( sizeof(uchar) /* version */ + \ 33 : sizeof(ulong) /* new_parent_slot */ + \ 34 : sizeof(fd_hash_t) /* new_parent_block_id */ ) 35 : 36 348 : #define FD_BLOCK_BITMAP_SER_HDR_SZ ( sizeof(uchar) /* version */ + \ 37 348 : sizeof(ushort) /* bit_cnt */ ) 38 : 39 234 : #define FD_BLOCK_BITMAP_SER_SZ( bit_cnt ) ( FD_BLOCK_BITMAP_SER_HDR_SZ + ((bit_cnt)+7UL)/8UL /* base2 payload */ ) 40 : 41 : #define FD_BLOCK_VOTES_AGGREGATE_SER_HDR_SZ ( FD_BLS_SIG_COMPRESSED_SZ /* signature */ + \ 42 : sizeof(ushort) /* bitmap_sz */ ) 43 : 44 : #define FD_BLOCK_VOTES_AGGREGATE_SER_SZ( bit_cnt ) ( FD_BLOCK_VOTES_AGGREGATE_SER_HDR_SZ + \ 45 : FD_BLOCK_BITMAP_SER_SZ( bit_cnt ) /* bitmap */ ) 46 : 47 : #define FD_BLOCK_VOTES_AGGREGATE_SER_MAX ( FD_BLOCK_VOTES_AGGREGATE_SER_SZ( AG_VAT_MAX ) ) 48 : 49 : #define FD_BLOCK_FINAL_CERT_SER_HDR_SZ ( sizeof(ulong) /* slot */ + \ 50 : sizeof(fd_hash_t) /* block_id */ ) 51 : 52 : #define FD_BLOCK_FINAL_CERT_SER_MAX ( FD_BLOCK_FINAL_CERT_SER_HDR_SZ /* slot, block_id */ + \ 53 : FD_BLOCK_VOTES_AGGREGATE_SER_MAX /* final_aggregate */ + \ 54 : sizeof(uchar) /* has_notar_aggregate */ + \ 55 : FD_BLOCK_VOTES_AGGREGATE_SER_MAX /* notar_aggregate */ ) 56 : 57 : #define FD_BLOCK_REWARD_CERT_SER_CU16_MAX (3UL) /* a ShortU16 is at most three bytes */ 58 : 59 : #define FD_BLOCK_SKIP_REWARD_CERT_SER_HDR_SZ ( sizeof(ulong) /* slot */ + \ 60 : FD_BLS_SIG_COMPRESSED_SZ /* signature */ ) 61 : 62 : #define FD_BLOCK_SKIP_REWARD_CERT_SER_MAX ( FD_BLOCK_SKIP_REWARD_CERT_SER_HDR_SZ /* slot, signature */ + \ 63 : FD_BLOCK_REWARD_CERT_SER_CU16_MAX /* bitmap_sz */ + \ 64 : FD_BLOCK_BITMAP_SER_SZ( AG_VAT_MAX ) /* bitmap */ ) 65 : 66 : #define FD_BLOCK_NOTAR_REWARD_CERT_SER_HDR_SZ ( sizeof(ulong) /* slot */ + \ 67 : sizeof(fd_hash_t) /* block_id */ + \ 68 : FD_BLS_SIG_COMPRESSED_SZ /* signature */ ) 69 : 70 : #define FD_BLOCK_NOTAR_REWARD_CERT_SER_MAX ( FD_BLOCK_NOTAR_REWARD_CERT_SER_HDR_SZ /* slot, block_id, signature */ + \ 71 : FD_BLOCK_REWARD_CERT_SER_CU16_MAX /* bitmap_sz */ + \ 72 : FD_BLOCK_BITMAP_SER_SZ( AG_VAT_MAX ) /* bitmap */ ) 73 : 74 : #define FD_BLOCK_FOOTER_SER_HDR_SZ ( sizeof(uchar) /* version */ + \ 75 : sizeof(fd_hash_t) /* bank_hash */ + \ 76 : sizeof(ulong) /* block_producer_time_nanos */ + \ 77 : sizeof(uchar) /* user_agent_len */ ) 78 : 79 : #define FD_BLOCK_FOOTER_SER_MAX ( FD_BLOCK_MARKER_PREAMBLE_SZ /* preamble */ + \ 80 : FD_BLOCK_FOOTER_SER_HDR_SZ /* fixed fields */ + \ 81 : FD_BLOCK_FOOTER_USER_AGENT_MAX /* user_agent */ + \ 82 : sizeof(uchar) /* has_block_final_cert */ + \ 83 : FD_BLOCK_FINAL_CERT_SER_MAX /* block_final_cert */ + \ 84 : sizeof(uchar) /* has_skip_reward_cert */ + \ 85 : FD_BLOCK_SKIP_REWARD_CERT_SER_MAX /* skip_reward_cert */ + \ 86 : sizeof(uchar) /* has_notar_reward_cert */ + \ 87 : FD_BLOCK_NOTAR_REWARD_CERT_SER_MAX /* notar_reward_cert */ ) 88 : 89 : #define FD_BLOCK_MARKER_SER_MAX ( FD_BLOCK_FOOTER_SER_MAX ) /* the footer is the widest marker */ 90 : 91 : FD_STATIC_ASSERT( FD_BLOCK_MARKER_PREAMBLE_SZ == 13UL, fd_block_marker_serde ); 92 : FD_STATIC_ASSERT( FD_BLOCK_HEADER_SER_SZ == 41UL, fd_block_marker_serde ); 93 : FD_STATIC_ASSERT( FD_UPDATE_PARENT_SER_SZ == 41UL, fd_block_marker_serde ); 94 : FD_STATIC_ASSERT( FD_BLOCK_BITMAP_SER_HDR_SZ == 3UL, fd_block_marker_serde ); 95 : FD_STATIC_ASSERT( FD_BLOCK_BITMAP_SER_SZ( AG_VAT_MAX ) == 253UL, fd_block_marker_serde ); 96 : FD_STATIC_ASSERT( FD_BLOCK_VOTES_AGGREGATE_SER_HDR_SZ == 98UL, fd_block_marker_serde ); 97 : FD_STATIC_ASSERT( FD_BLOCK_VOTES_AGGREGATE_SER_MAX == 351UL, fd_block_marker_serde ); 98 : FD_STATIC_ASSERT( FD_BLOCK_FINAL_CERT_SER_HDR_SZ == 40UL, fd_block_marker_serde ); 99 : FD_STATIC_ASSERT( FD_BLOCK_FINAL_CERT_SER_MAX == 743UL, fd_block_marker_serde ); 100 : FD_STATIC_ASSERT( FD_BLOCK_SKIP_REWARD_CERT_SER_HDR_SZ == 104UL, fd_block_marker_serde ); 101 : FD_STATIC_ASSERT( FD_BLOCK_SKIP_REWARD_CERT_SER_MAX == 360UL, fd_block_marker_serde ); 102 : FD_STATIC_ASSERT( FD_BLOCK_NOTAR_REWARD_CERT_SER_HDR_SZ == 136UL, fd_block_marker_serde ); 103 : FD_STATIC_ASSERT( FD_BLOCK_NOTAR_REWARD_CERT_SER_MAX == 392UL, fd_block_marker_serde ); 104 : FD_STATIC_ASSERT( FD_BLOCK_FOOTER_SER_HDR_SZ == 42UL, fd_block_marker_serde ); 105 : FD_STATIC_ASSERT( FD_BLOCK_FOOTER_SER_MAX ==1808UL, fd_block_marker_serde ); 106 : FD_STATIC_ASSERT( FD_BLOCK_FOOTER_SER_MAX-FD_BLOCK_MARKER_PREAMBLE_SZ<=(ulong)USHORT_MAX, fd_block_marker_serde ); /* LengthPrefixed::len is a u16 */ 107 : 108 : FD_PROTOTYPES_BEGIN 109 : 110 : ulong 111 : fd_block_marker_ser( fd_block_marker_t const * self, 112 : uchar buf[ static FD_BLOCK_MARKER_SER_MAX ] ); 113 : 114 : int 115 : fd_block_marker_de( fd_block_marker_t * self, 116 : uchar const * buf, 117 : ulong buf_sz ); 118 : 119 : FD_PROTOTYPES_END 120 : 121 : #endif /* HEADER_fd_src_flamenco_alpenglow_fd_block_marker_serde_h */