LCOV - code coverage report
Current view: top level - flamenco/types - fd_types_custom.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 26 40 65.0 %
Date: 2026-03-19 18:19:27 Functions: 13 3249 0.4 %

          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        8804 : #define FD_HASH_FOOTPRINT   (32UL)
      13             : #define FD_HASH_ALIGN       (8UL)
      14         392 : #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      141977 :             fd_hash_t const * b ) {
      34      141977 :   return 0==memcmp( a, b, sizeof(fd_hash_t) );
      35      141977 : }
      36             : 
      37             : FD_FN_PURE static inline int
      38             : fd_hash_eq1( fd_hash_t a,
      39           0 :              fd_hash_t b ) {
      40           0 :   return
      41           0 :     ( a.ul[0]==b.ul[0] ) & ( a.ul[1]==b.ul[1] ) &
      42           0 :     ( a.ul[2]==b.ul[2] ) & ( a.ul[3]==b.ul[3] );
      43           0 : }
      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        3208 : #define fd_pubkey_new                     fd_hash_new
      66        4298 : #define fd_pubkey_encode                  fd_hash_encode
      67             : #define fd_pubkey_destroy                 fd_hash_destroy
      68        1327 : #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       39056 : #define fd_pubkey_decode_inner            fd_hash_decode_inner
      72             : #define fd_pubkey_decode_footprint        fd_hash_decode_footprint
      73       11852 : #define fd_pubkey_decode_footprint_inner  fd_hash_decode_footprint_inner
      74             : #define fd_pubkey_decode                  fd_hash_decode
      75       15201 : #define fd_pubkey_eq                      fd_hash_eq
      76             : 
      77             : typedef struct fd_rust_duration fd_rust_duration_t;
      78             : 
      79             : void
      80             : fd_rust_duration_normalize ( fd_rust_duration_t * );
      81             : 
      82             : int
      83             : fd_rust_duration_footprint_validator ( fd_bincode_decode_ctx_t * ctx );
      84             : 
      85             : int fd_tower_sync_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
      86             : void fd_tower_sync_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx );
      87             : 
      88             : FD_PROTOTYPES_END
      89             : 
      90           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 }
      91             : static const fd_pubkey_t FD_DUMMY_ACCOUNT_PUBKEY = { .uc = FD_DUMMY_ACCOUNT };
      92             : 
      93             : struct fd_vote_stake_weight {
      94             :   fd_pubkey_t vote_key; /* vote account pubkey */
      95             :   fd_pubkey_t id_key;   /* validator identity pubkey */
      96             :   ulong       stake;    /* total stake by vote account */
      97             : };
      98             : typedef struct fd_vote_stake_weight fd_vote_stake_weight_t;
      99             : 
     100             : #define SORT_NAME sort_vote_weights_by_stake_vote
     101           0 : #define SORT_KEY_T fd_vote_stake_weight_t
     102           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))
     103             : #include "../../util/tmpl/fd_sort.c"
     104             : 
     105             : struct fd_stake_weight {
     106             :   fd_pubkey_t key;      /* validator identity pubkey */
     107             :   ulong       stake;    /* total stake by identity */
     108             : };
     109             : typedef struct fd_stake_weight fd_stake_weight_t;
     110             : 
     111             : #define SORT_NAME fd_stake_weight_key_sort
     112           0 : #define SORT_KEY_T fd_stake_weight_t
     113           0 : #define SORT_BEFORE(a,b) (memcmp( (a).key.uc, (b).key.uc, 32UL )<0)
     114             : #include "../../util/tmpl/fd_sort.c"
     115             : 
     116        7688 : static inline void fd_hash_new( fd_hash_t * self ) { (void)self; }
     117      156254 : static inline int fd_hash_encode( fd_hash_t const * self, fd_bincode_encode_ctx_t * ctx ) {
     118      156254 :   return fd_bincode_bytes_encode( (uchar const *)self, sizeof(fd_hash_t), ctx );
     119      156254 : }
     120        1327 : static inline ulong fd_hash_size( fd_hash_t const * self ) { (void)self; return sizeof(fd_hash_t); }
     121           0 : static inline ulong fd_hash_align( void ) { return alignof(fd_hash_t); }
     122       17900 : static inline int fd_hash_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
     123       17900 :   (void)total_sz;
     124       17900 :   if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
     125       17879 :   return fd_bincode_bytes_decode_footprint( sizeof(fd_hash_t), ctx );
     126       17900 : }
     127     5368562 : static inline void fd_hash_decode_inner( void * struct_mem, void ** alloc_mem, fd_bincode_decode_ctx_t * ctx ) {
     128     5368562 :   (void)alloc_mem;
     129     5368562 :   fd_bincode_bytes_decode_unsafe( struct_mem, sizeof(fd_hash_t), ctx );
     130     5368562 :   return;
     131     5368562 : }
     132             : 
     133             : #endif /* HEADER_fd_src_flamenco_types_fd_types_custom_h */

Generated by: LCOV version 1.14