Line data Source code
1 : #include "fd_acc_mgr.h" 2 : #include "../../funk/fd_funk.h" 3 : 4 : fd_account_meta_t const * 5 : fd_funk_get_acc_meta_readonly( fd_funk_t const * funk, 6 : fd_funk_txn_xid_t const * xid, 7 : fd_pubkey_t const * pubkey, 8 69 : fd_funk_txn_xid_t * out_xid ) { 9 69 : fd_funk_rec_key_t id = fd_funk_acc_key( pubkey ); 10 : 11 : /* When we access this pointer later on in the execution pipeline, we assume that 12 : nothing else will change that account. If the account is writable in the solana txn, 13 : then we copy the data. If the account is read-only, we do not. This is safe because of 14 : the read-write locks that the solana transaction holds on the account. */ 15 : 16 69 : for(;;) { 17 : 18 : /* Locate the account record */ 19 : 20 69 : fd_funk_rec_query_t query[1]; 21 69 : fd_funk_rec_t const * rec = fd_funk_rec_query_try_global( funk, xid, &id, out_xid, query ); 22 69 : if( FD_UNLIKELY( !rec ) ) { 23 3 : return NULL; 24 3 : } 25 : 26 : /* Read account balance */ 27 : 28 66 : void const * raw = fd_funk_val( rec, fd_funk_wksp( funk ) ); 29 66 : fd_account_meta_t const * metadata = fd_type_pun_const( raw ); 30 66 : ulong const lamports = metadata->lamports; 31 66 : if( FD_UNLIKELY( !lamports ) ) { 32 : /* This account is awaiting deletion */ 33 0 : return NULL; 34 0 : } 35 : 36 : /* Recover from overruns (e.g. account rooted) */ 37 : 38 66 : if( FD_LIKELY( fd_funk_rec_map_query_test( query )==FD_MAP_SUCCESS ) ) { 39 66 : return metadata; 40 66 : } 41 : 42 66 : } 43 69 : }