Line data Source code
1 : #include "fd_sysvar_rent.h" 2 : #include "fd_sysvar.h" 3 : #include "../fd_system_ids.h" 4 : #include "fd_sysvar_base.h" 5 : #include "../../accdb/fd_accdb_sync.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_accdb_user_t * accdb, 40 : fd_funk_txn_xid_t const * xid, 41 0 : fd_rent_t * rent ) { 42 0 : fd_accdb_ro_t ro[1]; 43 0 : if( FD_UNLIKELY( !fd_accdb_open_ro( accdb, ro, xid, &fd_sysvar_rent_id ) ) ) { 44 0 : return NULL; 45 0 : } 46 : 47 : /* This check is needed as a quirk of the fuzzer. If a sysvar account 48 : exists in the accounts database, but doesn't have any lamports, 49 : this means that the account does not exist. This wouldn't happen 50 : in a real execution environment. */ 51 0 : if( FD_UNLIKELY( fd_accdb_ref_lamports( ro )==0UL ) ) { 52 0 : fd_accdb_close_ro( accdb, ro ); 53 0 : return NULL; 54 0 : } 55 : 56 0 : rent = fd_bincode_decode_static( 57 0 : rent, rent, 58 0 : fd_accdb_ref_data_const( ro ), 59 0 : fd_accdb_ref_data_sz ( ro ) ); 60 0 : fd_accdb_close_ro( accdb, ro ); 61 0 : return rent; 62 0 : }