LCOV - code coverage report
Current view: top level - flamenco/types - fd_types_custom.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 21 35 60.0 %
Date: 2026-04-30 06:50:00 Functions: 17 3519 0.5 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_types_fd_types_custom_h
       2             : #define HEADER_fd_src_flamenco_types_fd_types_custom_h
       3             : 
       4             : #include "../fd_flamenco_base.h"
       5             : #include "fd_bincode.h"
       6             : #include "../../ballet/bmtree/fd_bmtree.h"
       7             : 
       8             : #define FD_SIGNATURE_ALIGN (8UL)
       9             : 
      10             : /* TODO this should not have packed alignment, but it's misused everywhere */
      11             : 
      12       14094 : #define FD_HASH_FOOTPRINT   (32UL)
      13             : #define FD_HASH_ALIGN       (8UL)
      14        1140 : #define FD_PUBKEY_FOOTPRINT FD_HASH_FOOTPRINT
      15             : #define FD_PUBKEY_ALIGN     FD_HASH_ALIGN
      16             : union __attribute__((packed)) fd_hash {
      17             :   uchar hash[ FD_HASH_FOOTPRINT ];
      18             :   uchar key [ FD_HASH_FOOTPRINT ]; // Making fd_hash and fd_pubkey interchangeable
      19             : 
      20             :   // Generic type specific accessors
      21             :   ulong  ul  [ FD_HASH_FOOTPRINT / sizeof(ulong)  ];
      22             :   uint   ui  [ FD_HASH_FOOTPRINT / sizeof(uint)   ];
      23             :   ushort us  [ FD_HASH_FOOTPRINT / sizeof(ushort) ];
      24             :   uchar  uc  [ FD_HASH_FOOTPRINT                  ];
      25             : };
      26             : typedef union fd_hash fd_hash_t;
      27             : typedef union fd_hash fd_pubkey_t;
      28             : 
      29             : FD_STATIC_ASSERT( sizeof(fd_hash_t) == sizeof(fd_bmtree_node_t), hash incompatibility ); /* various areas of Firedancer code use fd_hash_t as the type for merkle roots */
      30             : 
      31             : FD_FN_PURE static inline int
      32             : fd_hash_eq( fd_hash_t const * a,
      33        7125 :             fd_hash_t const * b ) {
      34        7125 :   return 0==memcmp( a, b, sizeof(fd_hash_t) );
      35        7125 : }
      36             : 
      37             : FD_FN_PURE static inline int
      38             : fd_hash_eq1( fd_hash_t a,
      39         453 :              fd_hash_t b ) {
      40         453 :   return
      41         453 :     ( a.ul[0]==b.ul[0] ) & ( a.ul[1]==b.ul[1] ) &
      42         453 :     ( a.ul[2]==b.ul[2] ) & ( a.ul[3]==b.ul[3] );
      43         453 : }
      44             : 
      45             : union fd_signature {
      46             :   uchar uc[ 64 ];
      47             :   ulong ul[  8 ];
      48             : };
      49             : typedef union fd_signature fd_signature_t;
      50             : 
      51             : 
      52             : FD_FN_PURE
      53             : static inline int
      54             : fd_signature_eq( fd_signature_t const * a,
      55           0 :                  fd_signature_t const * b ) {
      56           0 :   return 0==memcmp( a, b, sizeof(fd_signature_t) );
      57           0 : }
      58             : 
      59             : 
      60             : FD_PROTOTYPES_BEGIN
      61             : 
      62             : #define fd_hash_check_zero(_x) (!((_x)->ul[0] | (_x)->ul[1] | (_x)->ul[2] | (_x)->ul[3]))
      63             : #define fd_hash_set_zero(_x)   {((_x)->ul[0] = 0); ((_x)->ul[1] = 0); ((_x)->ul[2] = 0); ((_x)->ul[3] = 0);}
      64             : 
      65             : #define fd_pubkey_new                     fd_hash_new
      66             : #define fd_pubkey_encode                  fd_hash_encode
      67             : #define fd_pubkey_destroy                 fd_hash_destroy
      68             : #define fd_pubkey_size                    fd_hash_size
      69             : #define fd_pubkey_check_zero              fd_hash_check_zero
      70             : #define fd_pubkey_set_zero                fd_hash_set_zero
      71             : #define fd_pubkey_decode_inner            fd_hash_decode_inner
      72             : #define fd_pubkey_decode_footprint        fd_hash_decode_footprint
      73             : #define fd_pubkey_decode_footprint_inner  fd_hash_decode_footprint_inner
      74             : #define fd_pubkey_decode                  fd_hash_decode
      75        5985 : #define fd_pubkey_eq                      fd_hash_eq
      76             : 
      77             : FD_PROTOTYPES_END
      78             : 
      79           0 : #define FD_DUMMY_ACCOUNT { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }
      80             : static const fd_pubkey_t FD_DUMMY_ACCOUNT_PUBKEY = { .uc = FD_DUMMY_ACCOUNT };
      81             : 
      82             : struct fd_vote_stake_weight {
      83             :   fd_pubkey_t vote_key; /* vote account pubkey */
      84             :   fd_pubkey_t id_key;   /* validator identity pubkey */
      85             :   ulong       stake;    /* total stake by vote account */
      86             : };
      87             : typedef struct fd_vote_stake_weight fd_vote_stake_weight_t;
      88             : 
      89             : #define SORT_NAME sort_vote_weights_by_stake_vote
      90          12 : #define SORT_KEY_T fd_vote_stake_weight_t
      91           6 : #define SORT_BEFORE(a,b) ((a).stake > (b).stake ? 1 : ((a).stake < (b).stake ? 0 : memcmp( (a).vote_key.uc, (b).vote_key.uc, 32UL )>0))
      92             : #include "../../util/tmpl/fd_sort.c"
      93             : 
      94             : struct fd_stake_weight {
      95             :   fd_pubkey_t key;      /* validator identity pubkey */
      96             :   ulong       stake;    /* total stake by identity */
      97             : };
      98             : typedef struct fd_stake_weight fd_stake_weight_t;
      99             : 
     100             : #define SORT_NAME fd_stake_weight_key_sort
     101           0 : #define SORT_KEY_T fd_stake_weight_t
     102           0 : #define SORT_BEFORE(a,b) (memcmp( (a).key.uc, (b).key.uc, 32UL )<0)
     103             : #include "../../util/tmpl/fd_sort.c"
     104             : 
     105             : struct fd_fee_rate_governor {
     106             :   ulong target_lamports_per_signature;
     107             :   ulong target_signatures_per_slot;
     108             :   ulong min_lamports_per_signature;
     109             :   ulong max_lamports_per_signature;
     110             :   uchar burn_percent;
     111             : };
     112             : typedef struct fd_fee_rate_governor fd_fee_rate_governor_t;
     113             : 
     114             : struct fd_inflation {
     115             :   double initial;
     116             :   double terminal;
     117             :   double taper;
     118             :   double foundation;
     119             :   double foundation_term;
     120             :   double unused;
     121             : };
     122             : typedef struct fd_inflation fd_inflation_t;
     123             : 
     124           0 : static inline void fd_hash_new( fd_hash_t * self ) { (void)self; }
     125         462 : static inline int fd_hash_encode( fd_hash_t const * self, fd_bincode_encode_ctx_t * ctx ) {
     126         462 :   return fd_bincode_bytes_encode( (uchar const *)self, sizeof(fd_hash_t), ctx );
     127         462 : }
     128           0 : static inline ulong fd_hash_size( fd_hash_t const * self ) { (void)self; return sizeof(fd_hash_t); }
     129           0 : static inline ulong fd_hash_align( void ) { return alignof(fd_hash_t); }
     130           0 : static inline int fd_hash_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
     131           0 :   (void)total_sz;
     132           0 :   if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
     133           0 :   return fd_bincode_bytes_decode_footprint( sizeof(fd_hash_t), ctx );
     134           0 : }
     135         609 : static inline void fd_hash_decode_inner( void * struct_mem, void ** alloc_mem, fd_bincode_decode_ctx_t * ctx ) {
     136         609 :   (void)alloc_mem;
     137         609 :   fd_bincode_bytes_decode_unsafe( struct_mem, sizeof(fd_hash_t), ctx );
     138         609 :   return;
     139         609 : }
     140             : 
     141             : #endif /* HEADER_fd_src_flamenco_types_fd_types_custom_h */

Generated by: LCOV version 1.14