Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_alpenglow_fd_footer_cache_h 2 : #define HEADER_fd_src_flamenco_alpenglow_fd_footer_cache_h 3 : 4 : /* fd_footer_cache is replay's footer verify cache, kept across footers: 5 : a memo of recent footer cert H(m)s keyed by the signing payload, 6 : evicting oldest first, and one vote lthash memo slot per rank: the 7 : vote account image replay last stored for that rank and its lthash. */ 8 : 9 : #include "../fd_flamenco_base.h" 10 : #include "../../ballet/bls/fd_bls.h" 11 : #include "../../ballet/lthash/fd_lthash.h" 12 : #include "../../choreo/votor/ag_votor_base.h" 13 : #include "../runtime/program/vote/fd_vote_codec.h" 14 : 15 0 : #define FD_FOOTER_CACHE_ALIGN (64UL) 16 0 : #define FD_FOOTER_CACHE_MAGIC (0xf17eda2cef0c0000UL) /* firedancer footer cache ver 0 */ 17 : 18 : #define FD_FOOTER_CACHE_MSG_MAX (64UL) 19 0 : #define FD_FOOTER_CACHE_MSG_CNT (64UL) 20 : 21 0 : #define FD_FOOTER_CACHE_MEMO_DATA_MAX FD_VOTE_STATE_V4_SZ 22 : 23 : struct __attribute__((aligned(64))) fd_footer_cache_memo { 24 : fd_lthash_value_t lthash; 25 : uchar pubkey[ 32 ]; 26 : uchar owner [ 32 ]; 27 : ulong lamports; /* 0 if empty */ 28 : ulong data_len; 29 : int executable; 30 : uchar data[ FD_FOOTER_CACHE_MEMO_DATA_MAX ]; 31 : }; 32 : typedef struct fd_footer_cache_memo fd_footer_cache_memo_t; 33 : 34 : struct __attribute__((aligned(FD_FOOTER_CACHE_ALIGN))) fd_footer_cache { 35 : ulong magic; /* ==FD_FOOTER_CACHE_MAGIC */ 36 : ulong next; 37 : 38 : struct { 39 : ulong sz; /* 0 if empty */ 40 : uchar msg[ FD_FOOTER_CACHE_MSG_MAX ]; 41 : blst_p2_affine h; 42 : } e[ FD_FOOTER_CACHE_MSG_CNT ]; 43 : 44 : fd_footer_cache_memo_t memo[ AG_VAT_MAX ]; 45 : }; 46 : typedef struct fd_footer_cache fd_footer_cache_t; 47 : 48 : FD_PROTOTYPES_BEGIN 49 : 50 : FD_FN_CONST ulong 51 : fd_footer_cache_align( void ); 52 : 53 : FD_FN_CONST ulong 54 : fd_footer_cache_footprint( void ); 55 : 56 : void * 57 : fd_footer_cache_new( void * shmem ); 58 : 59 : fd_footer_cache_t * 60 : fd_footer_cache_join( void * shcache ); 61 : 62 : /* fd_footer_cache_hash_msg sets h to H(msg), from the cache if there, 63 : otherwise computed and inserted. msg_sz must be in 64 : [1,FD_FOOTER_CACHE_MSG_MAX]. */ 65 : 66 : void 67 : fd_footer_cache_hash_msg( fd_footer_cache_t * cache, 68 : uchar const * msg, 69 : ulong msg_sz, 70 : blst_p2_affine * h ); 71 : 72 : blst_p2_affine const * 73 : fd_footer_cache_hash_query( fd_footer_cache_t const * cache, 74 : uchar const * msg, 75 : ulong msg_sz ); 76 : 77 : void 78 : fd_footer_cache_hash_insert( fd_footer_cache_t * cache, 79 : uchar const * msg, 80 : ulong msg_sz, 81 : blst_p2_affine const * h ); 82 : 83 : fd_lthash_value_t const * 84 : fd_footer_cache_memo_query( fd_footer_cache_memo_t const * memo, 85 : uchar const pubkey[ static FD_HASH_FOOTPRINT ], 86 : uchar const owner[ static FD_HASH_FOOTPRINT ], 87 : ulong lamports, 88 : int executable, 89 : uchar const * data, 90 : ulong data_len ); 91 : 92 : int 93 : fd_footer_cache_memo_insert( fd_footer_cache_memo_t * memo, 94 : uchar const pubkey[ static FD_HASH_FOOTPRINT ], 95 : uchar const owner[ static FD_HASH_FOOTPRINT ], 96 : ulong lamports, 97 : int executable, 98 : uchar const * data, 99 : ulong data_len ); 100 : 101 : FD_PROTOTYPES_END 102 : 103 : #endif /* HEADER_fd_src_flamenco_alpenglow_fd_footer_cache_h */