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