Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_capture_fd_solcap_proto_h 2 : #define HEADER_fd_src_flamenco_capture_fd_solcap_proto_h 3 : 4 : #include "../fd_flamenco_base.h" 5 : 6 : /* fd_solcap_proto defines the capture data format "solcap". 7 : 8 : solcap is a portable file format for capturing Solana runtime data 9 : suitable for replay and debugging. It is laid out as follows: 10 : 11 : File Header 12 : File Protobuf Object 13 : Chunk 0 14 : Chunk Header 15 : Chunk Protobuf Object 16 : Data ... 17 : Chunk 1 18 : Chunk Header 19 : Chunk Protobuf Object 20 : Data ... 21 : Chunk N ... 22 : 23 : The file header briefly describes the file's content type and points 24 : to the first chunk. Additional metadata, such as slot bounds, are 25 : stored in a Protobuf blob following the header. Currently, the 26 : following content types are implemented: 27 : 28 : SOLCAP_V1_BANK: Bank pre-image, version 0 29 : (assumed to only contain SOLCAP_V1_BANK chunks) 30 : 31 : Capture content is divided into variable-length chunks. Each chunk 32 : contains a fixed-size binary header containing type and length 33 : information. Following the header is a serialized Protobuf object 34 : with chunk-specific information. 35 : 36 : Typically, readers sequentially read in chunks, loading one chunk 37 : into memory at a time. Within a chunk, data structures are laid out 38 : in arbitrary order which requires random access. Random access out- 39 : side of chunks is rarely required. Readers should ignore chunks of 40 : unknown content type. 41 : 42 : Furthermore: 43 : - Byte order is little endian 44 : - There should be no gaps between slots 45 : - Suffix `_foff` ("file offset") refers to an offset from the 46 : beginning of a stream 47 : - Suffix `_coff` ("chunk offset") refers to an offset from the first 48 : byte of the header of the current chunk 49 : 50 : Why a mix of C structs and Protobufs? We prefer the use of Protobuf 51 : to easily support additions to the schema. Fixed-size/fixed-offset 52 : structures are only used to support navigating the file. */ 53 : 54 : /* TODO Pending features: 55 : - Fork support 56 : - Compression 57 : - Chunk Table */ 58 : 59 : /* FD_SOLCAP_V1_FILE_MAGIC identifies a solcap version 0 file. */ 60 : 61 0 : #define FD_SOLCAP_V1_FILE_MAGIC (0x806fe7581b1da4b7UL) 62 : 63 : /* fd_solcap_fhdr_t is the file header of a capture file. */ 64 : 65 : struct fd_solcap_fhdr { 66 : /* 0x00 */ ulong magic; /* ==FD_SOLCAP_V1_NULL_MAGIC */ 67 : /* 0x08 */ ulong chunk0_foff; /* Offset of first chunk from begin of stream */ 68 : 69 : /* Metadata; Protobuf fd_solcap_FileMeta */ 70 : /* 0x10 */ uint meta_sz; 71 : /* 0x14 */ uint _pad14[3]; 72 : }; 73 : 74 : typedef struct fd_solcap_fhdr fd_solcap_fhdr_t; 75 : 76 : /* FD_SOLCAP_V1_{...}_MAGIC identifies a chunk type. 77 : 78 : NULL: ignored chunk -- can be used to patch out existing chunks 79 : ACCT: account chunk 80 : ACTB: account table chunk 81 : BANK: bank hash preimage capture 82 : Metadata Protobuf type fd_solcap_BankChunk */ 83 : 84 0 : #define FD_SOLCAP_V1_MAGIC_MASK (0xfffffffffffff000UL) 85 0 : #define FD_SOLCAP_V1_NULL_MAGIC (0x805fe7580b1da000UL) 86 0 : #define FD_SOLCAP_V1_ACCT_MAGIC (0x805fe7580b1da4bAUL) 87 0 : #define FD_SOLCAP_V1_ACTB_MAGIC (0x805fe7580b1da4bBUL) 88 0 : #define FD_SOLCAP_V1_BANK_MAGIC (0x805fe7580b1da4b8UL) 89 0 : #define FD_SOLCAP_V1_TRXN_MAGIC (0x805fe7580b1da4bCUL) 90 : 91 0 : #define FD_SOLCAP_V1_REWARD_BEGIN_MAGIC (0x805fe7580b1da050UL) 92 0 : #define FD_SOLCAP_V1_REWARD_CALC_MAGIC (0x805fe7580b1da051UL) 93 0 : #define FD_SOLCAP_V1_REWARD_VOTE_MAGIC (0x805fe7580b1da052UL) 94 0 : #define FD_SOLCAP_V1_REWARD_STAKE_MAGIC (0x805fe7580b1da053UL) 95 : 96 : FD_PROTOTYPES_BEGIN 97 : 98 : static inline int 99 0 : fd_solcap_is_chunk_magic( ulong magic ) { 100 0 : return (magic & FD_SOLCAP_V1_MAGIC_MASK) == FD_SOLCAP_V1_NULL_MAGIC; 101 0 : } 102 : 103 : FD_PROTOTYPES_END 104 : 105 : /* fd_solcap_chunk_t is the fixed size header of a chunk. A "chunk 106 : offset" points to the first byte of this structure. Immediately 107 : following this structure is a serialized Protobuf blob, the type of 108 : which is decided by the chunk's magic. meta_sz indicates the size 109 : of such blob. */ 110 : 111 : struct fd_solcap_chunk { 112 : /* 0x00 */ ulong magic; 113 : /* 0x08 */ ulong total_sz; 114 : /* 0x10 */ uint meta_coff; 115 : /* 0x14 */ uint meta_sz; 116 : /* 0x18 */ ulong _pad18; 117 : /* 0x20 */ 118 : }; 119 : 120 : typedef struct fd_solcap_chunk fd_solcap_chunk_t; 121 : 122 : /* fd_solcap_account_tbl_t is an entry of the table of accounts that 123 : were changed in a block. meta_coff points to the chunk offset of a 124 : Protobuf-serialized fd_solcap_AccountMeta object, with serialized 125 : size meta_sz. key is the account address. hash is the account hash 126 : (a leaf of the accounts delta accumulator). data_coff points to the 127 : chunk offset of the account's data, with size data_sz. 128 : 129 : The table of accounts should ideally be sorted to match the order of 130 : accounts in the accounts delta vector. */ 131 : 132 : struct fd_solcap_account_tbl { 133 : /* 0x00 */ uchar key [ 32 ]; 134 : /* 0x20 */ uchar hash [ 32 ]; 135 : /* 0x40 */ long acc_coff; /* chunk offset to account chunk */ 136 : /* 0x48 */ ulong _pad48[3]; 137 : /* 0x60 */ 138 : }; 139 : 140 : typedef struct fd_solcap_account_tbl fd_solcap_account_tbl_t; 141 : 142 : /* Hardcoded limits ***************************************************/ 143 : 144 : /* FD_SOLCAP_FHDR_SZ is the number of bytes occupied by the file header. 145 : Immediately after the file header is the first chunk. */ 146 : 147 0 : #define FD_SOLCAP_FHDR_SZ (256UL) 148 : 149 : /* FD_SOLCAP_ACC_TBL_CNT is the number of entries that fit in the in- 150 : memory buffer for the account table. 151 : 152 : N.b: to support epoch boundaries increase this number to 2097152 */ 153 : 154 0 : #define FD_SOLCAP_ACC_TBL_CNT (8192U) 155 : 156 : /* FD_SOLCAP_FILE_META_FOOTPRINT is the max size of the FileMeta 157 : Protobuf struct. */ 158 : 159 : #define FD_SOLCAP_FILE_META_FOOTPRINT (1024U) 160 : 161 : /* FD_SOLCAP_ACTB_META_FOOTPRINT is the max size of the 162 : AccountChunkMeta Protobuf struct. */ 163 : 164 : #define FD_SOLCAP_ACTB_META_FOOTPRINT (128UL) 165 : 166 : /* FD_SOLCAP_ACCOUNT_META_FOOTPRINT is the max size of the AccountMeta 167 : Protobuf struct. */ 168 : 169 : #define FD_SOLCAP_ACCOUNT_META_FOOTPRINT (1024UL) 170 : 171 : /* FD_SOLCAP_BANK_PREIMAGE_FOOTPRINT is the max size of the BankPreimage 172 : Protobuf struct. */ 173 : 174 : #define FD_SOLCAP_BANK_PREIMAGE_FOOTPRINT (512UL) 175 : 176 : /* FD_SOLCAP_TRANSACTION_FOOTPRINT is the max size of the Transaction 177 : Protobuf struct. */ 178 : 179 : #define FD_SOLCAP_TRANSACTION_FOOTPRINT (128UL) 180 : 181 : #endif /* HEADER_fd_src_flamenco_capture_fd_solcap_proto_h */