Line data Source code
1 : #include "fd_sysvar_rent.h" 2 : #include "fd_sysvar.h" 3 : #include "../fd_acc_mgr.h" 4 : #include "../fd_system_ids.h" 5 : #include "fd_sysvar_base.h" 6 : 7 : #include <assert.h> 8 : 9 : void 10 : fd_sysvar_rent_write( fd_bank_t * bank, 11 : fd_accdb_user_t * accdb, 12 : fd_funk_txn_xid_t const * xid, 13 : fd_capture_ctx_t * capture_ctx, 14 0 : fd_rent_t const * rent ) { 15 : 16 0 : uchar enc[ FD_SYSVAR_RENT_BINCODE_SZ ] = {0}; 17 : 18 0 : fd_bincode_encode_ctx_t ctx = { 19 0 : .data = enc, 20 0 : .dataend = enc + FD_SYSVAR_RENT_BINCODE_SZ, 21 0 : }; 22 0 : if( FD_UNLIKELY( fd_rent_encode( rent, &ctx ) ) ) { 23 0 : FD_LOG_ERR(( "fd_rent_encode failed" )); 24 0 : } 25 : 26 0 : fd_sysvar_account_update( bank, accdb, xid, capture_ctx, &fd_sysvar_rent_id, enc, FD_SYSVAR_RENT_BINCODE_SZ ); 27 0 : } 28 : 29 : void 30 : fd_sysvar_rent_init( fd_bank_t * bank, 31 : fd_accdb_user_t * accdb, 32 : fd_funk_txn_xid_t const * xid, 33 0 : fd_capture_ctx_t * capture_ctx ) { 34 0 : fd_rent_t const * rent = fd_bank_rent_query( bank ); 35 0 : fd_sysvar_rent_write( bank, accdb, xid, capture_ctx, rent ); 36 0 : } 37 : 38 : fd_rent_t const * 39 : fd_sysvar_rent_read( fd_funk_t * funk, 40 : fd_funk_txn_xid_t const * xid, 41 0 : fd_rent_t * rent ) { 42 0 : fd_txn_account_t acc[1]; 43 0 : int rc = fd_txn_account_init_from_funk_readonly( acc, &fd_sysvar_rent_id, funk, xid ); 44 0 : if( FD_UNLIKELY( rc!=FD_ACC_MGR_SUCCESS ) ) { 45 0 : return NULL; 46 0 : } 47 : 48 : /* This check is needed as a quirk of the fuzzer. If a sysvar account 49 : exists in the accounts database, but doesn't have any lamports, 50 : this means that the account does not exist. This wouldn't happen 51 : in a real execution environment. */ 52 0 : if( FD_UNLIKELY( fd_txn_account_get_lamports( acc )==0UL ) ) { 53 0 : return NULL; 54 0 : } 55 : 56 0 : return fd_bincode_decode_static( 57 0 : rent, rent, 58 0 : fd_txn_account_get_data( acc ), 59 0 : fd_txn_account_get_data_len( acc ), 60 0 : NULL ); 61 0 : }