LCOV - code coverage report
Current view: top level - flamenco/types - fd_types_custom.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 26 39 66.7 %
Date: 2025-12-23 05:10:01 Functions: 10 3114 0.3 %

          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        1830 : #define FD_HASH_FOOTPRINT   (32UL)
      13           0 : #define FD_HASH_ALIGN       (8UL)
      14           0 : #define FD_PUBKEY_FOOTPRINT FD_HASH_FOOTPRINT
      15           0 : #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             :   uchar uc  [ FD_HASH_FOOTPRINT ];
      24             : };
      25             : typedef union fd_hash fd_hash_t;
      26             : typedef union fd_hash fd_pubkey_t;
      27             : 
      28             : 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 */
      29             : 
      30             : FD_FN_PURE static inline int
      31             : fd_hash_eq( fd_hash_t const * a,
      32        1749 :             fd_hash_t const * b ) {
      33        1749 :   return 0==memcmp( a, b, sizeof(fd_hash_t) );
      34        1749 : }
      35             : 
      36             : FD_FN_PURE static inline int
      37             : fd_hash_eq1( fd_hash_t a,
      38         453 :              fd_hash_t b ) {
      39         453 :   return
      40         453 :     ( a.ul[0]==b.ul[0] ) & ( a.ul[1]==b.ul[1] ) &
      41         453 :     ( a.ul[2]==b.ul[2] ) & ( a.ul[3]==b.ul[3] );
      42         453 : }
      43             : 
      44             : union fd_signature {
      45             :   uchar uc[ 64 ];
      46             :   ulong ul[  8 ];
      47             : };
      48             : typedef union fd_signature fd_signature_t;
      49             : 
      50             : 
      51             : FD_FN_PURE
      52             : static inline int
      53             : fd_signature_eq( fd_signature_t const * a,
      54           0 :                  fd_signature_t const * b ) {
      55           0 :   return 0==memcmp( a, b, sizeof(fd_signature_t) );
      56           0 : }
      57             : 
      58             : 
      59             : FD_PROTOTYPES_BEGIN
      60             : 
      61             : #define fd_hash_check_zero(_x) (!((_x)->ul[0] | (_x)->ul[1] | (_x)->ul[2] | (_x)->ul[3]))
      62             : #define fd_hash_set_zero(_x)   {((_x)->ul[0] = 0); ((_x)->ul[1] = 0); ((_x)->ul[2] = 0); ((_x)->ul[3] = 0);}
      63             : 
      64          24 : #define fd_pubkey_new                     fd_hash_new
      65         756 : #define fd_pubkey_encode                  fd_hash_encode
      66             : #define fd_pubkey_destroy                 fd_hash_destroy
      67           0 : #define fd_pubkey_size                    fd_hash_size
      68             : #define fd_pubkey_check_zero              fd_hash_check_zero
      69             : #define fd_pubkey_set_zero                fd_hash_set_zero
      70           0 : #define fd_pubkey_decode_inner            fd_hash_decode_inner
      71             : #define fd_pubkey_decode_footprint        fd_hash_decode_footprint
      72           0 : #define fd_pubkey_decode_footprint_inner  fd_hash_decode_footprint_inner
      73             : #define fd_pubkey_decode                  fd_hash_decode
      74        1179 : #define fd_pubkey_eq                      fd_hash_eq
      75             : 
      76             : typedef struct fd_rust_duration fd_rust_duration_t;
      77             : 
      78             : void
      79             : fd_rust_duration_normalize ( fd_rust_duration_t * );
      80             : 
      81             : int
      82             : fd_rust_duration_footprint_validator ( fd_bincode_decode_ctx_t * ctx );
      83             : 
      84             : int fd_tower_sync_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
      85             : void fd_tower_sync_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx );
      86             : 
      87             : FD_PROTOTYPES_END
      88             : 
      89             : struct fd_vote_stake_weight {
      90             :   fd_pubkey_t vote_key; /* vote account pubkey */
      91             :   fd_pubkey_t id_key;   /* validator identity pubkey */
      92             :   ulong       stake;    /* total stake by vote account */
      93             : };
      94             : typedef struct fd_vote_stake_weight fd_vote_stake_weight_t;
      95             : 
      96             : #define SORT_NAME sort_vote_weights_by_stake_vote
      97           0 : #define SORT_KEY_T fd_vote_stake_weight_t
      98           0 : #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))
      99             : #include "../../util/tmpl/fd_sort.c"
     100             : 
     101             : struct fd_stake_weight {
     102             :   fd_pubkey_t key;      /* validator identity pubkey */
     103             :   ulong       stake;    /* total stake by identity */
     104             : };
     105             : typedef struct fd_stake_weight fd_stake_weight_t;
     106             : 
     107          24 : static inline void fd_hash_new( fd_hash_t * self ) { (void)self; }
     108         756 : static inline int fd_hash_encode( fd_hash_t const * self, fd_bincode_encode_ctx_t * ctx ) {
     109         756 :   return fd_bincode_bytes_encode( (uchar const *)self, sizeof(fd_hash_t), ctx );
     110         756 : }
     111           0 : static inline ulong fd_hash_size( fd_hash_t const * self ) { (void)self; return sizeof(fd_hash_t); }
     112           0 : static inline ulong fd_hash_align( void ) { return alignof(fd_hash_t); }
     113           3 : static inline int fd_hash_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
     114           3 :   (void)total_sz;
     115           3 :   if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
     116           3 :   return fd_bincode_bytes_decode_footprint( sizeof(fd_hash_t), ctx );
     117           3 : }
     118       33975 : static inline void fd_hash_decode_inner( void * struct_mem, void ** alloc_mem, fd_bincode_decode_ctx_t * ctx ) {
     119       33975 :   (void)alloc_mem;
     120       33975 :   fd_bincode_bytes_decode_unsafe( struct_mem, sizeof(fd_hash_t), ctx );
     121       33975 :   return;
     122       33975 : }
     123             : 
     124             : #endif /* HEADER_fd_src_flamenco_types_fd_types_custom_h */

Generated by: LCOV version 1.14