Line data Source code
1 : #ifndef HEADER_fd_src_choreo_vote_fd_voter_h 2 : #define HEADER_fd_src_choreo_vote_fd_voter_h 3 : 4 : #include "../../flamenco/runtime/fd_system_ids.h" 5 : #include "../../flamenco/runtime/program/fd_vote_program.h" 6 : #include "../../flamenco/txn/fd_txn_generate.h" 7 : #include "../fd_choreo_base.h" 8 : #include "../forks/fd_forks.h" 9 : 10 : struct fd_voter { 11 : fd_pubkey_t vote_acc_addr; 12 : fd_pubkey_t validator_identity; 13 : fd_pubkey_t vote_authority; 14 : }; 15 : typedef struct fd_voter fd_voter_t; 16 : 17 : /* fd_voter_{align,footprint} return the required alignment and 18 : footprint of a memory region suitable for use as voter. align is 19 : double cache line to mitigate false sharing. */ 20 : 21 : FD_FN_CONST static inline ulong 22 0 : fd_voter_align( void ) { 23 0 : return alignof( fd_voter_t ); 24 0 : } 25 : 26 : FD_FN_CONST static inline ulong 27 0 : fd_voter_footprint( void ) { 28 0 : return sizeof( fd_voter_t ); 29 0 : } 30 : 31 : /* fd_voter_new formats an unused memory region for use as a voter. mem 32 : is a non-NULL pointer to this region in the local address space with 33 : the required footprint and alignment. */ 34 : 35 : void * 36 : fd_voter_new( void * mem ); 37 : 38 : /* fd_voter_join joins the caller to the voter. voter points to the 39 : first byte of the memory region backing the voter in the caller's 40 : address space. 41 : 42 : Returns a pointer in the local address space to voter on success. */ 43 : 44 : fd_voter_t * 45 : fd_voter_join( void * voter ); 46 : 47 : /* fd_voter_leave leaves a current local join. Returns a pointer to the 48 : underlying shared memory region on success and NULL on failure (logs 49 : details). Reasons for failure include voter is NULL. */ 50 : 51 : void * 52 : fd_voter_leave( fd_voter_t const * voter ); 53 : 54 : /* fd_voter_delete unformats a memory region used as a voter. Assumes 55 : only the local process is joined to the region. Returns a pointer to 56 : the underlying shared memory region or NULL if used obviously in 57 : error (e.g. voter is obviously not a voter ... logs details). The 58 : ownership of the memory region is transferred to the caller. */ 59 : 60 : void * 61 : fd_voter_delete( void * voter ); 62 : 63 : /* fd_voter_txn_generate generates a vote txn using the TowerSync ix. */ 64 : 65 : ulong 66 : fd_voter_txn_generate( fd_voter_t const * voter, 67 : fd_compact_vote_state_update_t const * vote_update, 68 : fd_hash_t const * recent_blockhash, 69 : uchar txn_meta_out[static FD_TXN_MAX_SZ], 70 : uchar txn_out[static FD_TXN_MTU] ); 71 : 72 : /* fd_voter_txn_parse parses a txn and returns a pointer to an 73 : fd_vote_instruction_t. Assumes caller is currently in a scratch 74 : scope and allocates memory using fd_scratch_virtual(). Lifetime of 75 : the returned pointer is lifetime of the caller's scratch scope when 76 : calling this function. */ 77 : 78 : // fd_vote_instruction_t * 79 : // fd_voter_txn_parse( uchar txn[static FD_TXN_MTU], ulong txn_sz, ); 80 : 81 : #endif