Line data Source code
1 : #include "fd_sysvar_rent.h" 2 : #include "fd_sysvar.h" 3 : #include "../fd_system_ids.h" 4 : #include "../context/fd_exec_slot_ctx.h" 5 : #include <assert.h> 6 : 7 : void 8 : fd_sysvar_rent_write( fd_exec_slot_ctx_t * slot_ctx, 9 0 : fd_rent_t const * rent ) { 10 : 11 0 : uchar enc[ 32 ]; 12 : 13 0 : ulong sz = fd_rent_size( rent ); 14 0 : FD_TEST( sz<=sizeof(enc) ); 15 0 : memset( enc, 0, sz ); 16 : 17 0 : fd_bincode_encode_ctx_t ctx; 18 0 : ctx.data = enc; 19 0 : ctx.dataend = enc + sz; 20 0 : if( fd_rent_encode( rent, &ctx ) ) 21 0 : FD_LOG_ERR(("fd_rent_encode failed")); 22 : 23 0 : fd_sysvar_set( slot_ctx->bank, slot_ctx->funk, slot_ctx->funk_txn, &fd_sysvar_owner_id, &fd_sysvar_rent_id, enc, sz, slot_ctx->slot ); 24 0 : } 25 : 26 : void 27 0 : fd_sysvar_rent_init( fd_exec_slot_ctx_t * slot_ctx ) { 28 0 : fd_rent_t const * rent = fd_bank_rent_query( slot_ctx->bank ); 29 0 : fd_sysvar_rent_write( slot_ctx, rent ); 30 0 : } 31 : 32 : fd_rent_t const * 33 : fd_sysvar_rent_read( fd_funk_t * funk, 34 : fd_funk_txn_t * funk_txn, 35 0 : fd_spad_t * spad ) { 36 0 : FD_TXN_ACCOUNT_DECL( acc ); 37 0 : int rc = fd_txn_account_init_from_funk_readonly( acc, &fd_sysvar_rent_id, funk, funk_txn ); 38 0 : if( FD_UNLIKELY( rc!=FD_ACC_MGR_SUCCESS ) ) { 39 0 : return NULL; 40 0 : } 41 : 42 : /* This check is needed as a quirk of the fuzzer. If a sysvar account 43 : exists in the accounts database, but doesn't have any lamports, 44 : this means that the account does not exist. This wouldn't happen 45 : in a real execution environment. */ 46 0 : if( FD_UNLIKELY( acc->vt->get_lamports( acc )==0 ) ) { 47 0 : return NULL; 48 0 : } 49 : 50 0 : int err; 51 0 : return fd_bincode_decode_spad( 52 0 : rent, spad, 53 0 : acc->vt->get_data( acc ), 54 0 : acc->vt->get_data_len( acc ), 55 0 : &err ); 56 0 : }