LCOV - code coverage report
Current view: top level - choreo/votor - ag_vote.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 50 55 90.9 %
Date: 2026-09-17 04:28:31 Functions: 24 70 34.3 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_choreo_votor_ag_vote_h
       2             : #define HEADER_fd_src_choreo_votor_ag_vote_h
       3             : 
       4             : #include "ag_votor_base.h"
       5             : #include "../../ballet/bls/fd_bls.h"
       6             : 
       7       59619 : #define AG_VOTE_KIND_NOTAR           (0U)
       8        7311 : #define AG_VOTE_KIND_FINAL           (1U)
       9       10653 : #define AG_VOTE_KIND_SKIP            (2U)
      10        2604 : #define AG_VOTE_KIND_NOTAR_FALLBACK  (3U)
      11        1215 : #define AG_VOTE_KIND_SKIP_FALLBACK   (4U)
      12             : 
      13             : #define AG_VOTE_CSTR_MAX (256UL)
      14             : 
      15             : typedef void
      16             : (* fd_bls_sign_fn)( void *         ctx,
      17             :                     fd_bls_sig_t * sig,
      18             :                     uchar const *  payload,
      19             :                     ulong          payload_sz );
      20             : struct ag_vote_notar {
      21             :   ulong           slot;
      22             :   ag_block_hash_t block_hash;
      23             :   fd_bls_sig_t    sig;
      24             :   ushort          rank;
      25             :   ushort          shred_version;
      26             : };
      27             : typedef struct ag_vote_notar ag_vote_notar_t;
      28             : 
      29             : struct ag_vote_final {
      30             :   ulong        slot;
      31             :   fd_bls_sig_t sig;
      32             :   ushort       rank;
      33             :   ushort       shred_version;
      34             : };
      35             : typedef struct ag_vote_final ag_vote_final_t;
      36             : 
      37             : struct ag_vote_skip {
      38             :   ulong        slot;
      39             :   fd_bls_sig_t sig;
      40             :   ushort       rank;
      41             :   ushort       shred_version;
      42             : };
      43             : typedef struct ag_vote_skip ag_vote_skip_t;
      44             : 
      45             : struct ag_vote_notar_fallback {
      46             :   ulong           slot;
      47             :   ag_block_hash_t block_hash;
      48             :   fd_bls_sig_t    sig;
      49             :   ushort          rank;
      50             :   ushort          shred_version;
      51             : };
      52             : typedef struct ag_vote_notar_fallback ag_vote_notar_fallback_t;
      53             : 
      54             : struct ag_vote_skip_fallback {
      55             :   ulong        slot;
      56             :   fd_bls_sig_t sig;
      57             :   ushort       rank;
      58             :   ushort       shred_version;
      59             : };
      60             : typedef struct ag_vote_skip_fallback ag_vote_skip_fallback_t;
      61             : 
      62             : struct ag_vote {
      63             :   uint   kind;
      64             :   ushort shred_version;
      65             :   union {
      66             :     ag_vote_notar_t          notar;
      67             :     ag_vote_final_t          final;
      68             :     ag_vote_skip_t           skip;
      69             :     ag_vote_notar_fallback_t notar_fallback;
      70             :     ag_vote_skip_fallback_t  skip_fallback;
      71             :   };
      72             : };
      73             : typedef struct ag_vote ag_vote_t;
      74             : 
      75             : FD_PROTOTYPES_BEGIN
      76             : 
      77             : FD_FN_PURE static inline ulong
      78       18138 : ag_vote_slot( ag_vote_t const * self ) {
      79       18138 :   switch( self->kind ) {
      80       12837 :   case AG_VOTE_KIND_NOTAR:          return self->notar.slot;
      81        1854 :   case AG_VOTE_KIND_FINAL:          return self->final.slot;
      82        2652 :   case AG_VOTE_KIND_SKIP:           return self->skip.slot;
      83         687 :   case AG_VOTE_KIND_NOTAR_FALLBACK: return self->notar_fallback.slot;
      84         108 :   case AG_VOTE_KIND_SKIP_FALLBACK:  return self->skip_fallback.slot;
      85           0 :   default:                          FD_LOG_CRIT(( "unreachable" ));
      86       18138 :   }
      87       18138 : }
      88             : 
      89             : FD_FN_PURE static inline uchar const *
      90        8718 : ag_vote_block_hash( ag_vote_t const * self ) {
      91        8718 :   switch( self->kind ) {
      92        5760 :   case AG_VOTE_KIND_NOTAR:          return self->notar.block_hash;
      93         957 :   case AG_VOTE_KIND_FINAL:          return NULL;
      94        1389 :   case AG_VOTE_KIND_SKIP:           return NULL;
      95         531 :   case AG_VOTE_KIND_NOTAR_FALLBACK: return self->notar_fallback.block_hash;
      96          81 :   case AG_VOTE_KIND_SKIP_FALLBACK:  return NULL;
      97           0 :   default:                          FD_LOG_CRIT(( "unreachable" ));
      98        8718 :   }
      99        8718 : }
     100             : 
     101             : FD_FN_PURE static inline fd_bls_sig_t const *
     102        5031 : ag_vote_sig( ag_vote_t const * self ) {
     103        5031 :   switch( self->kind ) {
     104        3651 :   case AG_VOTE_KIND_NOTAR:          return &self->notar.sig;
     105         393 :   case AG_VOTE_KIND_FINAL:          return &self->final.sig;
     106         873 :   case AG_VOTE_KIND_SKIP:           return &self->skip.sig;
     107          99 :   case AG_VOTE_KIND_NOTAR_FALLBACK: return &self->notar_fallback.sig;
     108          15 :   case AG_VOTE_KIND_SKIP_FALLBACK:  return &self->skip_fallback.sig;
     109           0 :   default:                          FD_LOG_CRIT(( "unreachable" ));
     110        5031 :   }
     111        5031 : }
     112             : 
     113             : FD_FN_PURE static inline ushort
     114       18054 : ag_vote_rank( ag_vote_t const * self ) {
     115       18054 :   switch( self->kind ) {
     116       14145 :   case AG_VOTE_KIND_NOTAR:          return self->notar.rank;
     117        1509 :   case AG_VOTE_KIND_FINAL:          return self->final.rank;
     118        2055 :   case AG_VOTE_KIND_SKIP:           return self->skip.rank;
     119         309 :   case AG_VOTE_KIND_NOTAR_FALLBACK: return self->notar_fallback.rank;
     120          36 :   case AG_VOTE_KIND_SKIP_FALLBACK:  return self->skip_fallback.rank;
     121           0 :   default:                          FD_LOG_CRIT(( "unreachable" ));
     122       18054 :   }
     123       18054 : }
     124             : 
     125             : FD_FN_PURE static inline ushort
     126        5037 : ag_vote_shred_version( ag_vote_t const * self ) {
     127        5037 :   switch( self->kind ) {
     128        3648 :   case AG_VOTE_KIND_NOTAR:          return self->notar.shred_version;
     129         393 :   case AG_VOTE_KIND_FINAL:          return self->final.shred_version;
     130         876 :   case AG_VOTE_KIND_SKIP:           return self->skip.shred_version;
     131         102 :   case AG_VOTE_KIND_NOTAR_FALLBACK: return self->notar_fallback.shred_version;
     132          18 :   case AG_VOTE_KIND_SKIP_FALLBACK:  return self->skip_fallback.shred_version;
     133           0 :   default:                          FD_LOG_CRIT(( "unreachable" ));
     134        5037 :   }
     135        5037 : }
     136             : 
     137             : ag_vote_t
     138             : ag_vote_construct_notar( fd_bls_sign_fn        sign_fn,
     139             :                          void *                sign_ctx,
     140             :                          ulong                 slot,
     141             :                          ag_block_hash_t const hash,
     142             :                          ushort                rank,
     143             :                          ushort                shred_version );
     144             : 
     145             : ag_vote_t
     146             : ag_vote_construct_final( fd_bls_sign_fn sign_fn,
     147             :                          void *         sign_ctx,
     148             :                          ulong          slot,
     149             :                          ushort         rank,
     150             :                          ushort         shred_version );
     151             : 
     152             : ag_vote_t
     153             : ag_vote_construct_skip( fd_bls_sign_fn sign_fn,
     154             :                         void *         sign_ctx,
     155             :                         ulong          slot,
     156             :                         ushort         rank,
     157             :                         ushort         shred_version );
     158             : 
     159             : ag_vote_t
     160             : ag_vote_construct_notar_fallback( fd_bls_sign_fn        sign_fn,
     161             :                                   void *                sign_ctx,
     162             :                                   ulong                 slot,
     163             :                                   ag_block_hash_t const hash,
     164             :                                   ushort                rank,
     165             :                                   ushort                shred_version );
     166             : 
     167             : ag_vote_t
     168             : ag_vote_construct_skip_fallback( fd_bls_sign_fn sign_fn,
     169             :                                  void *         sign_ctx,
     170             :                                  ulong          slot,
     171             :                                  ushort         rank,
     172             :                                  ushort         shred_version );
     173             : 
     174             : char *
     175             : ag_vote_to_cstr( ag_vote_t const * self,
     176             :                  char              cstr[ static AG_VOTE_CSTR_MAX ] );
     177             : 
     178             : FD_PROTOTYPES_END
     179             : 
     180             : #endif

Generated by: LCOV version 1.14