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 12 : fd_rent_t const * rent ) {
15 :
16 12 : uchar enc[ FD_SYSVAR_RENT_BINCODE_SZ ] = {0};
17 :
18 12 : fd_bincode_encode_ctx_t ctx = {
19 12 : .data = enc,
20 12 : .dataend = enc + FD_SYSVAR_RENT_BINCODE_SZ,
21 12 : };
22 12 : if( FD_UNLIKELY( fd_rent_encode( rent, &ctx ) ) ) {
23 0 : FD_LOG_ERR(( "fd_rent_encode failed" ));
24 0 : }
25 :
26 12 : fd_sysvar_account_update( bank, accdb, xid, capture_ctx, &fd_sysvar_rent_id, enc, FD_SYSVAR_RENT_BINCODE_SZ );
27 12 : }
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 12 : fd_rent_t * rent ) {
42 12 : fd_accdb_ro_t ro[1];
43 12 : 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 12 : 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 12 : rent = fd_bincode_decode_static(
57 12 : rent, rent,
58 12 : fd_accdb_ref_data_const( ro ),
59 12 : fd_accdb_ref_data_sz ( ro ),
60 12 : NULL );
61 12 : fd_accdb_close_ro( accdb, ro );
62 12 : return rent;
63 12 : }
|