Line data Source code
1 : #ifndef HEADER_fd_src_choreo_tower_fd_tower_file_h 2 : #define HEADER_fd_src_choreo_tower_fd_tower_file_h 3 : 4 : /* Reads and writes Agave's tower file, tower-1_9-<pubkey>.bin, bincode 5 : of SavedTowerVersions::Current, a 64 byte Ed25519 signature by the 6 : node identity over a Tower1_14_11 body. */ 7 : 8 : #include "fd_tower.h" 9 : #include "fd_tower_serdes.h" 10 : 11 : /* FD_TOWER_FILE_MAX is the largest file we read. The signature is at 12 : FD_TOWER_FILE_SIG_OFF and covers [FD_TOWER_FILE_DATA_OFF, size). */ 13 0 : #define FD_TOWER_FILE_MAX (8192UL) 14 30 : #define FD_TOWER_FILE_SIG_OFF (4UL) /* u32 kind precedes the signature */ 15 72 : #define FD_TOWER_FILE_DATA_OFF (4UL+64UL+8UL) /* kind, signature, data_sz */ 16 : 17 : /* Return codes of fd_tower_file_de. */ 18 3 : #define FD_TOWER_FILE_SUCCESS ( 0) 19 3 : #define FD_TOWER_FILE_ERR_SIZE (-1) /* truncated, too large, or the lengths disagree */ 20 0 : #define FD_TOWER_FILE_ERR_VERSION (-2) /* not SavedTowerVersions::Current, or the last vote is not a TowerSync */ 21 0 : #define FD_TOWER_FILE_ERR_SIG (-3) /* the signature does not verify under identity */ 22 0 : #define FD_TOWER_FILE_ERR_IDENTITY (-4) /* the node pubkey in the file is not identity (Agave's WrongTower) */ 23 3 : #define FD_TOWER_FILE_ERR_TOWER (-5) /* thresholds, votes, root or lockouts are not a tower Agave writes */ 24 : 25 : /* A decoded and verified tower file. bank_hash and block_id belong 26 : to the last vote, votes[votes_cnt-1]. */ 27 : struct fd_tower_file { 28 : fd_tower_vote_t votes[ FD_TOWER_VOTE_MAX ]; 29 : ulong votes_cnt; 30 : ulong root; 31 : fd_hash_t bank_hash; 32 : fd_hash_t block_id; 33 : ulong timestamp_slot; 34 : long timestamp; 35 : }; 36 : typedef struct fd_tower_file fd_tower_file_t; 37 : 38 : FD_PROTOTYPES_BEGIN 39 : 40 : /* fd_tower_file_de verifies the signature under identity, checks that 41 : the file is for identity, the two checks Agave makes, and decodes 42 : into out. A tower without a root is rejected, Agave always writes 43 : one and cannot restore a tower without it. Returns 44 : FD_TOWER_FILE_SUCCESS, or an FD_TOWER_FILE_ERR_* code with out left 45 : untouched. */ 46 : int 47 : fd_tower_file_de( uchar const * buf, 48 : ulong buf_sz, 49 : fd_pubkey_t const * identity, 50 : fd_tower_file_t * out ); 51 : 52 : /* fd_tower_file_ser writes the tower file into a caller-owned buffer, 53 : except the signature. The vote state fields Agave does not restore 54 : from are not populated. Returns the file size. */ 55 : ulong 56 : fd_tower_file_ser( fd_compact_tower_sync_serde_t const * sync, 57 : fd_pubkey_t const * identity, 58 : uchar buf[ static FD_TOWER_FILE_MAX ] ); 59 : 60 : FD_PROTOTYPES_END 61 : 62 : #endif /* HEADER_fd_src_choreo_tower_fd_tower_file_h */