Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_accdb_fd_accdb_lineage_h 2 : #define HEADER_fd_src_flamenco_accdb_fd_accdb_lineage_h 3 : 4 : /* fd_accdb_lineage.h provides an API for filtering account database 5 : records by fork graph lineage. */ 6 : 7 : #include "../../funk/fd_funk_txn.h" 8 : 9 : 10 : #define FD_ACCDB_MAX_DEPTH_MAX (8192UL) 11 : 12 : struct fd_accdb_lineage { 13 : 14 : /* Current fork cache */ 15 : fd_funk_txn_xid_t fork[ FD_ACCDB_MAX_DEPTH_MAX ]; 16 : ulong fork_depth; 17 : 18 : uint txn_idx[ FD_ACCDB_MAX_DEPTH_MAX ]; 19 : 20 : /* Current funk txn cache */ 21 : ulong tip_txn_idx; /* ==ULONG_MAX if tip is root */ 22 : 23 : ulong max_depth; 24 : }; 25 : 26 : #define FD_ACCDB_LINEAGE_FOOTPRINT (sizeof(fd_accdb_lineage_t)) 27 : 28 : typedef struct fd_accdb_lineage fd_accdb_lineage_t; 29 : 30 : FD_PROTOTYPES_BEGIN 31 : 32 : /* fd_accdb_lineage_has_xid returns 1 if the given record XID is part of 33 : the current lineage, otherwise 0. */ 34 : 35 : FD_FN_UNUSED static int 36 : fd_accdb_lineage_has_xid( fd_accdb_lineage_t const * lineage, 37 92034 : fd_funk_txn_xid_t const * rec_xid ) { 38 92034 : ulong const fork_depth = lineage->fork_depth; 39 92034 : if( fd_funk_txn_xid_eq_root( rec_xid ) ) return 1; 40 96637 : for( ulong i=0UL; i<fork_depth; i++ ) { 41 96615 : if( fd_funk_txn_xid_eq( &lineage->fork[i], rec_xid ) ) return 1; 42 96615 : } 43 22 : return 0; 44 86762 : } 45 : 46 : /* fd_accdb_lineage_set_fork pivots the lineage object to the lineage 47 : from database root to the given XID (tip). */ 48 : 49 : void 50 : fd_accdb_lineage_set_fork_slow( fd_accdb_lineage_t * lineage, 51 : fd_funk_t const * funk, 52 : fd_funk_txn_xid_t const * xid ); 53 : 54 : static inline void 55 : fd_accdb_lineage_set_fork( fd_accdb_lineage_t * lineage, 56 : fd_funk_t const * funk, 57 351951 : fd_funk_txn_xid_t const * xid ) { 58 : /* Skip if already on the correct fork */ 59 351951 : if( FD_LIKELY( (!!lineage->fork_depth) & (!!fd_funk_txn_xid_eq( &lineage->fork[ 0 ], xid ) ) ) ) return; 60 3572 : fd_accdb_lineage_set_fork_slow( lineage, funk, xid ); /* switch fork */ 61 3572 : } 62 : 63 : /* fd_accdb_lineage_is_tip returns 1 if xid equals the tip of the 64 : current lineage, otherwise 0. */ 65 : 66 : static inline int 67 : fd_accdb_lineage_is_tip( fd_accdb_lineage_t const * lineage, 68 0 : fd_funk_txn_xid_t const * xid ) { 69 0 : if( lineage->fork_depth==0UL ) return 0; 70 0 : return fd_funk_txn_xid_eq( &lineage->fork[ 0 ], xid ); 71 0 : } 72 : 73 : /* fd_accdb_lineage_write_check verifies whether the tip of the current 74 : lineage is writable (not frozen). Aborts the app with FD_LOG_CRIT 75 : if writes to the tip of this lineage are not allowed. */ 76 : 77 : fd_funk_txn_t * 78 : fd_accdb_lineage_write_check( fd_accdb_lineage_t const * lineage, 79 : fd_funk_t const * funk ); 80 : 81 : FD_PROTOTYPES_END 82 : 83 : #endif /* HEADER_fd_src_flamenco_accdb_fd_accdb_lineage_h */