Skip to content

Commit cd8bd64

Browse files
runtime: removing txn account vtable + refactor constructors
1 parent 4290781 commit cd8bd64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1340
-1287
lines changed

src/discof/restore/fd_snapin_tile.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,24 @@ account_cb( void * _ctx,
133133
}
134134

135135
FD_TXN_ACCOUNT_DECL( rec );
136+
fd_funk_rec_prepare_t prepare = {0};
136137
int err = fd_txn_account_init_from_funk_mutable( rec,
137138
(fd_pubkey_t*)hdr->meta.pubkey,
138139
ctx->funk,
139140
ctx->funk_txn,
140141
/* do_create */ 1,
141-
hdr->meta.data_len );
142+
hdr->meta.data_len,
143+
&prepare );
142144
if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) FD_LOG_ERR(( "fd_txn_account_init_from_funk_mutable failed (%d)", err ));
143145

144-
rec->vt->set_data_len( rec, hdr->meta.data_len );
145-
rec->vt->set_slot( rec, ctx->ssparse->accv_slot );
146-
rec->vt->set_hash( rec, &hdr->hash );
147-
rec->vt->set_info( rec, &hdr->info );
146+
fd_txn_account_set_data_len( rec, hdr->meta.data_len );
147+
fd_txn_account_set_slot( rec, ctx->ssparse->accv_slot );
148+
fd_txn_account_set_hash( rec, &hdr->hash );
149+
fd_txn_account_set_meta_info( rec, &hdr->info );
148150

149-
ctx->acc_data = rec->vt->get_data_mut( rec );
151+
ctx->acc_data = fd_txn_account_get_data_mut( rec );
150152
ctx->metrics.accounts_inserted++;
151-
fd_txn_account_mutable_fini( rec, ctx->funk, ctx->funk_txn );
153+
fd_txn_account_mutable_fini( rec, ctx->funk, ctx->funk_txn, &prepare );
152154
}
153155

154156
static void

src/flamenco/rewards/fd_rewards.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -821,31 +821,33 @@ calculate_rewards_and_distribute_vote_rewards( fd_exec_slot_ctx_t * slot_ctx,
821821

822822
fd_pubkey_t const * vote_pubkey = &vote_reward_node->elem.pubkey;
823823
FD_TXN_ACCOUNT_DECL( vote_rec );
824+
fd_funk_rec_prepare_t prepare = {0};
824825

825826
if( FD_UNLIKELY( fd_txn_account_init_from_funk_mutable( vote_rec,
826827
vote_pubkey,
827828
slot_ctx->funk,
828829
slot_ctx->funk_txn,
829830
1,
830-
0UL ) != FD_ACC_MGR_SUCCESS ) ) {
831+
0UL,
832+
&prepare )!=FD_ACC_MGR_SUCCESS ) ) {
831833
FD_LOG_ERR(( "Unable to modify vote account" ));
832834
}
833835

834-
vote_rec->vt->set_slot( vote_rec, fd_bank_slot_get( slot_ctx->bank ) );
836+
fd_txn_account_set_slot( vote_rec, fd_bank_slot_get( slot_ctx->bank ) );
835837

836-
if( FD_UNLIKELY( vote_rec->vt->checked_add_lamports( vote_rec, vote_reward_node->elem.vote_rewards ) ) ) {
838+
if( FD_UNLIKELY( fd_txn_account_checked_add_lamports( vote_rec, vote_reward_node->elem.vote_rewards ) ) ) {
837839
FD_LOG_ERR(( "Adding lamports to vote account would cause overflow" ));
838840
}
839841

840-
fd_txn_account_mutable_fini( vote_rec, slot_ctx->funk, slot_ctx->funk_txn );
842+
fd_txn_account_mutable_fini( vote_rec, slot_ctx->funk, slot_ctx->funk_txn, &prepare );
841843

842844
distributed_rewards = fd_ulong_sat_add( distributed_rewards, vote_reward_node->elem.vote_rewards );
843845

844846
if( capture_ctx ) {
845847
fd_solcap_write_vote_account_payout( capture_ctx->capture,
846848
vote_pubkey,
847849
fd_bank_slot_get( slot_ctx->bank ),
848-
vote_rec->vt->get_lamports( vote_rec ),
850+
fd_txn_account_get_lamports( vote_rec ),
849851
(long)vote_reward_node->elem.vote_rewards );
850852
}
851853
}
@@ -875,16 +877,18 @@ distribute_epoch_reward_to_stake_acc( fd_exec_slot_ctx_t * slot_ctx,
875877
ulong reward_lamports,
876878
ulong new_credits_observed ) {
877879
FD_TXN_ACCOUNT_DECL( stake_acc_rec );
880+
fd_funk_rec_prepare_t prepare = {0};
878881
if( FD_UNLIKELY( fd_txn_account_init_from_funk_mutable( stake_acc_rec,
879882
stake_pubkey,
880883
slot_ctx->funk,
881884
slot_ctx->funk_txn,
882885
0,
883-
0UL ) != FD_ACC_MGR_SUCCESS ) ) {
886+
0UL,
887+
&prepare )!=FD_ACC_MGR_SUCCESS ) ) {
884888
FD_LOG_ERR(( "Unable to modify stake account" ));
885889
}
886890

887-
stake_acc_rec->vt->set_slot( stake_acc_rec, fd_bank_slot_get( slot_ctx->bank ) );
891+
fd_txn_account_set_slot( stake_acc_rec, fd_bank_slot_get( slot_ctx->bank ) );
888892

889893
fd_stake_state_v2_t stake_state[1] = {0};
890894
if( fd_stake_get_state( stake_acc_rec, stake_state ) != 0 ) {
@@ -897,7 +901,7 @@ distribute_epoch_reward_to_stake_acc( fd_exec_slot_ctx_t * slot_ctx,
897901
return 1;
898902
}
899903

900-
if( stake_acc_rec->vt->checked_add_lamports( stake_acc_rec, reward_lamports ) ) {
904+
if( fd_txn_account_checked_add_lamports( stake_acc_rec, reward_lamports ) ) {
901905
FD_LOG_DEBUG(( "failed to add lamports to stake account" ));
902906
return 1;
903907
}
@@ -911,7 +915,7 @@ distribute_epoch_reward_to_stake_acc( fd_exec_slot_ctx_t * slot_ctx,
911915
fd_solcap_write_stake_account_payout( capture_ctx->capture,
912916
stake_pubkey,
913917
fd_bank_slot_get( slot_ctx->bank ),
914-
stake_acc_rec->vt->get_lamports( stake_acc_rec ),
918+
fd_txn_account_get_lamports( stake_acc_rec ),
915919
(long)reward_lamports,
916920
new_credits_observed,
917921
(long)( new_credits_observed-old_credits_observed ),
@@ -923,7 +927,7 @@ distribute_epoch_reward_to_stake_acc( fd_exec_slot_ctx_t * slot_ctx,
923927
FD_LOG_ERR(( "write_stake_state failed" ));
924928
}
925929

926-
fd_txn_account_mutable_fini( stake_acc_rec, slot_ctx->funk, slot_ctx->funk_txn );
930+
fd_txn_account_mutable_fini( stake_acc_rec, slot_ctx->funk, slot_ctx->funk_txn, &prepare );
927931

928932
return 0;
929933
}
@@ -1097,7 +1101,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_exec_slot_ctx_t * slot_ctx,
10971101
fd_spad_t * runtime_spad ) {
10981102
fd_sysvar_epoch_rewards_t epoch_rewards[1];
10991103
if( FD_UNLIKELY( !fd_sysvar_epoch_rewards_read( slot_ctx->funk, slot_ctx->funk_txn, epoch_rewards ) ) ) {
1100-
FD_LOG_NOTICE(( "Failed to read or decode epoch rewards sysvar - may not have been created yet" ));
1104+
FD_LOG_DEBUG(( "Failed to read or decode epoch rewards sysvar - may not have been created yet" ));
11011105
set_epoch_reward_status_inactive( slot_ctx->bank );
11021106
return;
11031107
}

src/flamenco/runtime/Local.mk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ ifdef FD_HAS_INT128
22
$(call add-hdrs,fd_acc_mgr.h)
33
$(call add-objs,fd_acc_mgr,fd_flamenco)
44

5-
$(call add-hdrs,fd_txn_account.h)
6-
$(call add-objs,fd_txn_account,fd_flamenco)
7-
85
$(call add-hdrs,fd_bank_hash_cmp.h fd_rwseq_lock.h)
96
$(call add-objs,fd_bank_hash_cmp,fd_flamenco)
107

@@ -40,6 +37,11 @@ $(call add-objs, tests/fd_dump_pb,fd_flamenco)
4037

4138
$(call add-hdrs,fd_rent_lists.h)
4239

40+
$(call add-hdrs,fd_txn_account.h)
41+
$(call add-objs,fd_txn_account,fd_flamenco)
42+
$(call make-unit-test,test_txn_account,test_txn_account,fd_flamenco fd_funk fd_ballet fd_util)
43+
$(call run-unit-test,test_txn_account,)
44+
4345
$(call add-hdrs,fd_bank.h)
4446
$(call add-objs,fd_bank,fd_flamenco)
4547
$(call make-unit-test,test_bank,test_bank,fd_flamenco fd_ballet fd_util)

src/flamenco/runtime/context/fd_exec_instr_ctx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fd_exec_instr_ctx_try_borrow_account( fd_exec_instr_ctx_t const * ctx,
138138

139139
/* Return an AccountBorrowFailed error if the write is not acquirable.
140140
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L605 */
141-
int borrow_res = txn_account->vt->try_borrow_mut( txn_account );
141+
int borrow_res = fd_txn_account_try_borrow_mut( txn_account );
142142
if( FD_UNLIKELY( !borrow_res ) ) {
143143
return FD_EXECUTOR_INSTR_ERR_ACC_BORROW_FAILED;
144144
}

src/flamenco/runtime/context/fd_exec_txn_ctx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fd_txn_account_check_exists( fd_txn_account_t * acc,
306306
ushort idx ) {
307307
(void) ctx;
308308
(void) idx;
309-
return fd_account_meta_exists( acc->vt->get_meta( acc ) );
309+
return fd_account_meta_exists( fd_txn_account_get_meta( acc ) );
310310
}
311311

312312
int
@@ -331,5 +331,5 @@ fd_txn_account_check_borrow_mut( fd_txn_account_t * acc,
331331
ushort idx ) {
332332
(void) ctx;
333333
(void) idx;
334-
return acc->vt->is_mutable( acc ) && acc->vt->try_borrow_mut( acc );
334+
return fd_txn_account_is_mutable( acc ) && fd_txn_account_try_borrow_mut( acc );
335335
}

src/flamenco/runtime/fd_acc_mgr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fd_funk_get_acc_meta_readonly( fd_funk_t const * funk,
1515
nothing else will change that account. If the account is writable in the solana txn,
1616
then we copy the data. If the account is read-only, we do not. This is safe because of
1717
the read-write locks that the solana transaction holds on the account. */
18-
for ( ; ; ) {
18+
for( ; ; ) {
1919

2020
fd_funk_rec_query_t query[1];
2121
fd_funk_txn_t const * dummy_txn_out[1];

src/flamenco/runtime/fd_acc_mgr.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ FD_PROTOTYPES_BEGIN
4444
static inline void
4545
fd_account_meta_init( fd_account_meta_t * m ) {
4646
fd_memset( m, 0, sizeof(fd_account_meta_t) );
47-
m->magic = FD_ACCOUNT_META_MAGIC;
48-
m->hlen = sizeof(fd_account_meta_t);
47+
m->magic = FD_ACCOUNT_META_MAGIC;
48+
m->hlen = sizeof(fd_account_meta_t);
49+
m->info.rent_epoch = ULONG_MAX;
4950
}
5051

5152
/* fd_account_meta_exists checks if the account in a funk record exists or was
@@ -68,9 +69,9 @@ fd_account_meta_exists( fd_account_meta_t const * m ) {
6869
has_owner = !!has_owner;
6970
# endif
7071

71-
return ( ( m->info.lamports > 0 ) |
72-
( m->dlen > 0 ) |
73-
( has_owner ) );
72+
return ((m->info.lamports > 0UL) |
73+
(m->dlen > 0UL) |
74+
(has_owner ) );
7475

7576
}
7677

@@ -85,6 +86,11 @@ fd_account_meta_get_data_const( fd_account_meta_t const * m ) {
8586
return ((uchar const *) m) + m->hlen;
8687
}
8788

89+
static inline ulong
90+
fd_account_meta_get_record_sz( fd_account_meta_t const * m ) {
91+
return sizeof(fd_account_meta_t) + m->dlen;
92+
}
93+
8894
/* Funk key handling **************************************************/
8995

9096
/* fd_acc_funk_key returns a fd_funk database key given an account

src/flamenco/runtime/fd_borrowed_account.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ fd_borrowed_account_get_data_mut( fd_borrowed_account_t * borrowed_acct,
1414
}
1515

1616
if ( data_out != NULL )
17-
*data_out = acct->vt->get_data_mut( acct );
17+
*data_out = fd_txn_account_get_data_mut( acct );
1818
if ( dlen_out != NULL )
19-
*dlen_out = acct->vt->get_data_len( acct );
19+
*dlen_out = fd_txn_account_get_data_len( acct );
2020

2121
return FD_EXECUTOR_INSTR_SUCCESS;
2222
}
@@ -52,15 +52,15 @@ fd_borrowed_account_set_owner( fd_borrowed_account_t * borrowed_acct,
5252

5353
/* Don't copy the account if the owner does not change
5454
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L757 */
55-
if( !memcmp( acct->vt->get_owner( acct ), owner, sizeof( fd_pubkey_t ) ) ) {
55+
if( !memcmp( fd_txn_account_get_owner( acct ), owner, sizeof( fd_pubkey_t ) ) ) {
5656
return FD_EXECUTOR_INSTR_SUCCESS;
5757
}
5858

5959
/* Agave self.touch() is a no-op */
6060

6161
/* Copy into owner
6262
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L761 */
63-
acct->vt->set_owner( acct, owner );
63+
fd_txn_account_set_owner( acct, owner );
6464
return FD_EXECUTOR_INSTR_SUCCESS;
6565
}
6666

@@ -73,8 +73,8 @@ fd_borrowed_account_set_lamports( fd_borrowed_account_t * borrowed_acct,
7373

7474
/* An account not owned by the program cannot have its blanace decrease
7575
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L775 */
76-
if( FD_UNLIKELY( ( !fd_borrowed_account_is_owned_by_current_program( borrowed_acct ) ) &&
77-
( lamports < acct->vt->get_lamports( acct ) ) ) ) {
76+
if( FD_UNLIKELY( (!fd_borrowed_account_is_owned_by_current_program( borrowed_acct )) &&
77+
(lamports<fd_txn_account_get_lamports( acct )) ) ) {
7878
return FD_EXECUTOR_INSTR_ERR_EXTERNAL_ACCOUNT_LAMPORT_SPEND;
7979
}
8080

@@ -92,13 +92,13 @@ fd_borrowed_account_set_lamports( fd_borrowed_account_t * borrowed_acct,
9292

9393
/* Don't copy the account if the lamports do not change
9494
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L787 */
95-
if( acct->vt->get_lamports( acct ) == lamports ) {
95+
if( fd_txn_account_get_lamports( acct )==lamports ) {
9696
return FD_EXECUTOR_INSTR_SUCCESS;
9797
}
9898

9999
/* Agave self.touch() is a no-op */
100100

101-
acct->vt->set_lamports( acct, lamports );
101+
fd_txn_account_set_lamports( acct, lamports );
102102
return FD_EXECUTOR_INSTR_SUCCESS;
103103
}
104104

@@ -127,7 +127,7 @@ fd_borrowed_account_set_data_from_slice( fd_borrowed_account_t * borrowed_acct,
127127
}
128128

129129
/* AccountSharedData::set_data_from_slice() */
130-
acct->vt->set_data( acct, data, data_sz );
130+
fd_txn_account_set_data( acct, data, data_sz );
131131

132132
return FD_EXECUTOR_INSTR_SUCCESS;
133133
}
@@ -148,7 +148,7 @@ fd_borrowed_account_set_data_length( fd_borrowed_account_t * borrowed_acct,
148148
return err;
149149
}
150150

151-
ulong old_len = acct->vt->get_data_len( acct );
151+
ulong old_len = fd_txn_account_get_data_len( acct );
152152

153153
/* Don't copy the account if the length does not change
154154
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L886 */
@@ -165,7 +165,7 @@ fd_borrowed_account_set_data_length( fd_borrowed_account_t * borrowed_acct,
165165

166166
/* Resize the account
167167
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L891 */
168-
acct->vt->resize( acct, new_len );
168+
fd_txn_account_resize( acct, new_len );
169169
return FD_EXECUTOR_INSTR_SUCCESS;
170170
}
171171

@@ -177,7 +177,7 @@ fd_borrowed_account_set_executable( fd_borrowed_account_t * borrowed_acct,
177177
/* To become executable an account must be rent exempt
178178
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1003-L1006 */
179179
fd_rent_t const * rent = fd_bank_rent_query( borrowed_acct->instr_ctx->txn_ctx->bank );
180-
if( FD_UNLIKELY( acct->vt->get_lamports( acct ) < fd_rent_exempt_minimum_balance( rent, acct->vt->get_data_len( acct ) ) ) ) {
180+
if( FD_UNLIKELY( fd_txn_account_get_lamports( acct )<fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( acct ) ) ) ) {
181181
return FD_EXECUTOR_INSTR_ERR_EXECUTABLE_ACCOUNT_NOT_RENT_EXEMPT;
182182
}
183183

@@ -208,7 +208,7 @@ fd_borrowed_account_set_executable( fd_borrowed_account_t * borrowed_acct,
208208
/* Agave self.touch() is a no-op */
209209

210210
/* https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1027 */
211-
acct->vt->set_executable( acct, is_executable );
211+
fd_txn_account_set_executable( acct, is_executable );
212212

213213
return FD_EXECUTOR_INSTR_SUCCESS;
214214
}
@@ -219,7 +219,7 @@ fd_borrowed_account_update_accounts_resize_delta( fd_borrowed_account_t * borrow
219219
int * err ) {
220220
fd_exec_instr_ctx_t const * instr_ctx = borrowed_acct->instr_ctx;
221221
fd_txn_account_t * acct = borrowed_acct->acct;
222-
ulong size_delta = fd_ulong_sat_sub( new_len, acct->vt->get_data_len( acct ) );
222+
ulong size_delta = fd_ulong_sat_sub( new_len, fd_txn_account_get_data_len( acct ) );
223223

224224
/* TODO: The size delta should never exceed the value of ULONG_MAX so this
225225
could be replaced with a normal addition. However to match execution with

0 commit comments

Comments
 (0)