Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_capture_fd_solcap_writer_h 2 : #define HEADER_fd_src_flamenco_capture_fd_solcap_writer_h 3 : 4 : #include "fd_solcap_proto.h" 5 : #include "../types/fd_types_custom.h" 6 : 7 : /* fd_solcap_writer_t produces pcapng dumps containing solcap packets. 8 : 9 : Each solcap write function is responsible for encoding and writing 10 : out a specific type of chunk. They provide both a header, which 11 : contains information about type of chunk, size, and slot number, 12 : and the chunk data. 13 : 14 : Note: The functionality is limited to the writing of solcap v2 files 15 : Nishk (TODO): Write docs for solcap writer 16 : */ 17 : 18 : FD_PROTOTYPES_BEGIN 19 : 20 : /* Maximum fragment size for account data. Must be <= USHORT_MAX (65535) 21 : because fd_frag_meta_t stores sz as a ushort. */ 22 0 : #define SOLCAP_WRITE_ACCOUNT_DATA_MTU (65535UL) 23 : 24 : struct fd_solcap_writer { 25 : int fd; 26 : }; 27 : typedef struct fd_solcap_writer fd_solcap_writer_t; 28 : 29 : ulong 30 : fd_solcap_writer_align( void ); 31 : 32 : ulong 33 : fd_solcap_writer_footprint( void ); 34 : 35 : fd_solcap_writer_t * 36 : fd_solcap_writer_init( fd_solcap_writer_t * writer, 37 : int fd ); 38 : 39 : /* fd_solcap_write_account_hdr writes an account update EPB header. 40 : Writes EPB + internal chunk header + account metadata. Account data 41 : must be written separately via fd_solcap_write_data. Returns the 42 : total block_len for use when writing the footer. */ 43 : 44 : uint 45 : fd_solcap_write_account_hdr( fd_solcap_writer_t * writer, 46 : fd_solcap_buf_msg_t * msg_hdr, 47 : fd_solcap_account_update_hdr_t * account_update ); 48 : 49 : /* fd_solcap_write_data writes raw data bytes to the capture file. 50 : This is used for continuation fragments of any message type that 51 : spans multiple link fragments (e.g., large account data). */ 52 : uint 53 : fd_solcap_write_data( fd_solcap_writer_t * writer, 54 : void const * data, 55 : ulong data_sz ); 56 : 57 : /* fd_solcap_write_bank_preimage writes a complete bank preimage EPB. 58 : Contains bank hash, prev hash, accounts hash, PoH hash, and sig count. 59 : Returns block_len for the footer. */ 60 : 61 : uint 62 : fd_solcap_write_bank_preimage( fd_solcap_writer_t * writer, 63 : fd_solcap_buf_msg_t * msg_hdr, 64 : fd_solcap_bank_preimage_t * bank_preimage ); 65 : 66 : /* fd_solcap_write_stake_rewards_begin writes a stake rewards begin EPB. 67 : Marks the start of epoch rewards distribution with inflation and 68 : point totals. Returns block_len for the footer. */ 69 : 70 : uint 71 : fd_solcap_write_stake_rewards_begin( fd_solcap_writer_t * writer, 72 : fd_solcap_buf_msg_t * msg_hdr, 73 : fd_solcap_stake_rewards_begin_t * stake_rewards_begin ); 74 : 75 : /* fd_solcap_write_stake_reward_event writes a stake reward event EPB. 76 : Captures individual reward calculation for a stake/vote account pair. 77 : Returns block_len for the footer. */ 78 : 79 : uint 80 : fd_solcap_write_stake_reward_event( fd_solcap_writer_t * writer, 81 : fd_solcap_buf_msg_t * msg_hdr, 82 : fd_solcap_stake_reward_event_t * stake_reward_event ); 83 : 84 : /* fd_solcap_write_stake_account_payout writes a stake payout EPB. 85 : Captures stake account state changes during reward distribution. 86 : Returns block_len for the footer. */ 87 : 88 : uint 89 : fd_solcap_write_stake_account_payout( fd_solcap_writer_t * writer, 90 : fd_solcap_buf_msg_t * msg_hdr, 91 : fd_solcap_stake_account_payout_t * stake_account_payout ); 92 : 93 : /* fd_solcap_write_ftr writes the PCapNG block footer. Adds padding to 94 : align to 4-byte boundary, then writes the redundant block length. 95 : Must be called after each message to complete the EPB. */ 96 : 97 : uint 98 : fd_solcap_write_ftr( fd_solcap_writer_t * writer, 99 : uint block_len_redundant ); 100 : 101 : FD_PROTOTYPES_END 102 : 103 : #endif /* HEADER_fd_src_flamenco_capture_fd_solcap_writer_h */