LCOV - code coverage report
Current view: top level - flamenco/types - fd_types_custom.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 26 44 59.1 %
Date: 2025-08-05 05:04:49 Functions: 6 1863 0.3 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_types_custom
       2             : #define HEADER_fd_src_flamenco_runtime_fd_types_custom
       3             : 
       4             : #include "../fd_flamenco_base.h"
       5             : #include "fd_types_meta.h"
       6             : #include "fd_bincode.h"
       7             : #include "../../ballet/bmtree/fd_bmtree.h"
       8             : #include "../../ballet/ed25519/fd_ed25519.h"
       9             : #include "../../ballet/txn/fd_txn.h"
      10             : 
      11           0 : #define FD_HASH_FOOTPRINT (32UL)
      12           0 : #define FD_HASH_ALIGN (8UL)
      13           0 : #define FD_PUBKEY_FOOTPRINT FD_HASH_FOOTPRINT
      14           0 : #define FD_PUBKEY_ALIGN FD_HASH_ALIGN
      15             : #define FD_SIGNATURE_ALIGN (8UL)
      16             : 
      17             : /* TODO this should not have packed alignment, but it's misused everywhere */
      18             : 
      19             : union __attribute__((packed)) fd_hash {
      20             :   uchar hash[ FD_HASH_FOOTPRINT ];
      21             :   uchar key [ FD_HASH_FOOTPRINT ]; // Making fd_hash and fd_pubkey interchangeable
      22             : 
      23             :   // Generic type specific accessors
      24             :   ulong ul  [ FD_HASH_FOOTPRINT / sizeof(ulong) ];
      25             :   uint  ui  [ FD_HASH_FOOTPRINT / sizeof(uint)  ];
      26             :   uchar uc  [ FD_HASH_FOOTPRINT ];
      27             : };
      28             : typedef union fd_hash fd_hash_t;
      29             : typedef union fd_hash fd_pubkey_t;
      30             : 
      31             : 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 */
      32             : 
      33             : FD_FN_PURE static inline int
      34             : fd_hash_eq( fd_hash_t const * a,
      35         570 :             fd_hash_t const * b ) {
      36         570 :   return 0==memcmp( a, b, sizeof(fd_hash_t) );
      37         570 : }
      38             : 
      39             : FD_FN_PURE static inline int
      40             : fd_hash_eq1( fd_hash_t a,
      41         453 :              fd_hash_t b ) {
      42         453 :   return
      43         453 :     ( a.ul[0]==b.ul[0] ) & ( a.ul[1]==b.ul[1] ) &
      44         453 :     ( a.ul[2]==b.ul[2] ) & ( a.ul[3]==b.ul[3] );
      45         453 : }
      46             : 
      47             : union fd_signature {
      48             :   uchar uc[ 64 ];
      49             :   ulong ul[  8 ];
      50             : };
      51             : 
      52             : typedef union fd_signature fd_signature_t;
      53             : 
      54             : FD_PROTOTYPES_BEGIN
      55             : 
      56             : #define fd_hash_check_zero(_x) (!((_x)->ul[0] | (_x)->ul[1] | (_x)->ul[2] | (_x)->ul[3]))
      57             : #define fd_hash_set_zero(_x)   {((_x)->ul[0] = 0); ((_x)->ul[1] = 0); ((_x)->ul[2] = 0); ((_x)->ul[3] = 0);}
      58             : 
      59          24 : #define fd_pubkey_new                     fd_hash_new
      60         966 : #define fd_pubkey_encode                  fd_hash_encode
      61             : #define fd_pubkey_destroy                 fd_hash_destroy
      62           0 : #define fd_pubkey_size                    fd_hash_size
      63             : #define fd_pubkey_check_zero              fd_hash_check_zero
      64             : #define fd_pubkey_set_zero                fd_hash_set_zero
      65         273 : #define fd_pubkey_walk                    fd_hash_walk
      66         483 : #define fd_pubkey_decode_inner            fd_hash_decode_inner
      67             : #define fd_pubkey_decode_footprint        fd_hash_decode_footprint
      68          66 : #define fd_pubkey_decode_footprint_inner  fd_hash_decode_footprint_inner
      69             : #define fd_pubkey_decode                  fd_hash_decode
      70           0 : #define fd_pubkey_eq                      fd_hash_eq
      71             : 
      72             : struct __attribute__((aligned(8UL))) fd_option_slot {
      73             :   uchar is_some;
      74             :   ulong slot;
      75             : };
      76             : typedef struct fd_option_slot fd_option_slot_t;
      77             : 
      78             : /* Index structure needed for transaction status (metadata) blocks */
      79             : struct fd_txnstatusidx {
      80             :     fd_ed25519_sig_t sig;
      81             :     ulong offset;
      82             :     ulong status_sz;
      83             : };
      84             : typedef struct fd_txnstatusidx fd_txnstatusidx_t;
      85             : 
      86             : /* IPv4 ***************************************************************/
      87             : 
      88             : typedef uint fd_gossip_ip4_addr_t;
      89             : #define FD_GOSSIP_IP4_ADDR_ALIGN alignof(fd_gossip_ip4_addr_t)
      90             : 
      91             : /* IPv6 ***************************************************************/
      92             : 
      93             : union fd_gossip_ip6_addr {
      94             :   uchar  uc[ 16 ];
      95             :   ushort us[  8 ];
      96             :   uint   ul[  4 ];
      97             : };
      98             : 
      99             : typedef union fd_gossip_ip6_addr fd_gossip_ip6_addr_t;
     100             : #define FD_GOSSIP_IP6_ADDR_ALIGN alignof(fd_gossip_ip6_addr_t)
     101             : 
     102             : int
     103             : fd_solana_vote_account_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
     104             : 
     105             : int
     106             : fd_solana_vote_account_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
     107             : 
     108             : void *
     109             : fd_solana_vote_account_decode( void * mem, fd_bincode_decode_ctx_t * ctx );
     110             : 
     111             : void
     112             : fd_solana_vote_account_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx );
     113             : 
     114             : /* Transaction wrapper ************************************************/
     115             : 
     116             : /* fd_flamenco_txn_t is yet another fd_txn_t wrapper.
     117             :    This should die as soon as we have a better stubs generator. */
     118             : 
     119             : struct fd_flamenco_txn {
     120             :   union {
     121             :     uchar                  txn_buf[ FD_TXN_MAX_SZ ];
     122             :     __extension__ fd_txn_t txn[0];
     123             :   };
     124             :   uchar raw[ FD_TXN_MTU ];
     125             :   ulong raw_sz;
     126             : };
     127             : 
     128             : typedef struct fd_flamenco_txn fd_flamenco_txn_t;
     129             : 
     130             : 
     131             : static inline void
     132           3 : fd_flamenco_txn_new( fd_flamenco_txn_t * self FD_FN_UNUSED ) {}
     133             : 
     134             : static inline void
     135           0 : fd_flamenco_txn_destroy( fd_flamenco_txn_t const * self FD_FN_UNUSED ) {}
     136             : 
     137             : FD_FN_CONST static inline ulong
     138           0 : fd_flamenco_txn_size( fd_flamenco_txn_t const * self ) {
     139           0 :   return self->raw_sz;
     140           0 : }
     141             : 
     142             : static inline int
     143             : fd_flamenco_txn_encode( fd_flamenco_txn_t const * self,
     144           0 :                         fd_bincode_encode_ctx_t * ctx ) {
     145           0 :   return fd_bincode_bytes_encode( self->raw, self->raw_sz, ctx );
     146           0 : }
     147             : 
     148             : 
     149             : int FD_FN_UNUSED
     150             : fd_flamenco_txn_encode_global( fd_flamenco_txn_t const * self,
     151             :                                fd_bincode_encode_ctx_t * ctx );
     152             : 
     153             : void * FD_FN_UNUSED
     154             : fd_flamenco_txn_decode_global( void *                    mem,
     155             :                                fd_bincode_decode_ctx_t * ctx );
     156             : 
     157             : static inline void
     158             : fd_flamenco_txn_walk( void *                    w,
     159             :                       fd_flamenco_txn_t const * self,
     160             :                       fd_types_walk_fn_t        fun,
     161             :                       char const *              name,
     162             :                       uint                      level,
     163           9 :                       uint                      varint ) {
     164           9 :   (void) varint;
     165             : 
     166           9 :   static uchar const zero[ 64 ]={0};
     167           9 :   fd_txn_t const *   txn  = self->txn;
     168           9 :   uchar const *      sig0 = zero;
     169             : 
     170           9 :   if( FD_LIKELY( txn->signature_cnt > 0 ) )
     171           9 :     sig0 = fd_txn_get_signatures( txn, self->raw )[0];
     172             : 
     173             :   /* For now, just print the transaction's signature */
     174           9 :   fun( w, sig0, name, FD_FLAMENCO_TYPE_SIG512, "txn", level, 0 );
     175           9 : }
     176             : 
     177             : static inline ulong
     178           6 : fd_flamenco_txn_align( void ) {
     179           6 :   return alignof(fd_flamenco_txn_t);
     180           6 : }
     181             : 
     182             : static inline ulong
     183           0 : fd_flamenco_txn_footprint( void ) {
     184           0 :   return sizeof(fd_flamenco_txn_t);
     185           0 : }
     186             : 
     187             : int
     188             : fd_flamenco_txn_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
     189             : 
     190             : int
     191             : fd_flamenco_txn_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
     192             : 
     193             : void *
     194             : fd_flamenco_txn_decode( void * mem, fd_bincode_decode_ctx_t * ctx );
     195             : 
     196             : void
     197             : fd_flamenco_txn_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx );
     198             : 
     199             : /* Represents the lamport balance associated with an account. */
     200             : typedef ulong fd_acc_lamports_t;
     201             : 
     202             : typedef struct fd_rust_duration fd_rust_duration_t;
     203             : 
     204             : void
     205             : fd_rust_duration_normalize ( fd_rust_duration_t * );
     206             : 
     207             : int
     208             : fd_rust_duration_footprint_validator ( fd_bincode_decode_ctx_t * ctx );
     209             : 
     210             : void fd_vote_accounts_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx );
     211             : void fd_vote_accounts_decode_inner_global( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx );
     212             : 
     213             : int fd_tower_sync_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
     214             : void fd_tower_sync_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx );
     215             : 
     216             : FD_PROTOTYPES_END
     217             : 
     218             : struct fd_vote_stake_weight {
     219             :   fd_pubkey_t vote_key; /* vote account pubkey */
     220             :   fd_pubkey_t id_key;   /* validator identity pubkey */
     221             :   ulong       stake;    /* total stake by vote account */
     222             : };
     223             : typedef struct fd_vote_stake_weight fd_vote_stake_weight_t;
     224             : 
     225             : #define SORT_NAME sort_vote_weights_by_stake_vote
     226           0 : #define SORT_KEY_T fd_vote_stake_weight_t
     227           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))
     228             : #include "../../util/tmpl/fd_sort.c"
     229             : 
     230             : struct fd_stake_weight {
     231             :   fd_pubkey_t key;      /* validator identity pubkey */
     232             :   ulong       stake;    /* total stake by identity */
     233             : };
     234             : typedef struct fd_stake_weight fd_stake_weight_t;
     235             : 
     236             : struct fd_stake_weight_t_mapnode {
     237             :     fd_stake_weight_t elem;
     238             :     ulong redblack_parent;
     239             :     ulong redblack_left;
     240             :     ulong redblack_right;
     241             :     int redblack_color;
     242             : };
     243             : typedef struct fd_stake_weight_t_mapnode fd_stake_weight_t_mapnode_t;
     244             : #define REDBLK_T fd_stake_weight_t_mapnode_t
     245             : #define REDBLK_NAME fd_stake_weight_t_map
     246             : #define REDBLK_IMPL_STYLE 1
     247             : #include "../../util/tmpl/fd_redblack.c"
     248             : 
     249             : #endif /* HEADER_fd_src_flamenco_runtime_fd_types_custom */

Generated by: LCOV version 1.14