Skip to content

Commit 5fe21ce

Browse files
wip
1 parent c6779f4 commit 5fe21ce

File tree

11 files changed

+57
-69
lines changed

11 files changed

+57
-69
lines changed

src/flamenco/fd_flamenco_base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ struct fd_account {
123123
typedef struct fd_account fd_account_t;
124124

125125
FD_FN_PURE static inline uchar *
126-
fd_account_data( fd_account_t const * acc ) {
127-
return (uchar *)( acc->meta+1 );
126+
fd_account_meta_data( fd_account_meta_t const * meta ) {
127+
return (uchar *)( meta+1 );
128128
}
129129

130130
FD_PROTOTYPES_BEGIN

src/flamenco/runtime/fd_executor.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ load_transaction_account( fd_runtime_t * runtime,
462462
fd_txn_account_t * acct,
463463
uchar is_writable,
464464
uchar unknown_acc,
465-
ulong txn_idx ) {
465+
ulong acc_idx ) {
466466

467467
/* Handling the sysvar instructions account explictly.
468468
https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L817-L824 */
@@ -471,7 +471,7 @@ load_transaction_account( fd_runtime_t * runtime,
471471
constructed by the SVM and modified within each transaction's
472472
instruction execution only, so it incurs a loaded size cost
473473
of 0. */
474-
fd_sysvar_instructions_serialize_account( txn_in, txn_out, (fd_instr_info_t const *)runtime->instr.infos, TXN( txn_in->txn )->instr_cnt, txn_idx );
474+
fd_sysvar_instructions_serialize_account( txn_in, txn_out, (fd_instr_info_t const *)runtime->instr.infos, TXN( txn_in->txn )->instr_cnt, acc_idx );
475475
return 0UL;
476476
}
477477

@@ -491,6 +491,7 @@ load_transaction_account( fd_runtime_t * runtime,
491491
/* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L828-L835 */
492492
if( is_writable ) {
493493
acct->starting_lamports = fd_txn_account_get_lamports( acct ); /* TODO: why do we do this everywhere? */
494+
txn_out->accounts.starting_lamports[ acc_idx ] = txn_out->accounts.metas[ acc_idx ]->lamports;
494495
}
495496
return fd_ulong_sat_add( base_account_size, fd_txn_account_get_data_len( acct ) );
496497
}
@@ -1421,12 +1422,12 @@ fd_execute_instr( fd_runtime_t * runtime,
14211422
}
14221423

14231424
void
1424-
fd_executor_reclaim_account( fd_txn_account_t * account,
1425+
fd_executor_reclaim_account( fd_account_meta_t * meta,
14251426
ulong slot ) {
1426-
fd_txn_account_set_slot( account, slot );
1427-
if( FD_UNLIKELY( fd_txn_account_get_lamports( account )==0UL ) ) {
1428-
fd_txn_account_set_data_len( account, 0UL );
1429-
fd_txn_account_clear_owner( account );
1427+
meta->slot = slot;
1428+
if( FD_UNLIKELY( meta->lamports==0UL ) ) {
1429+
meta->dlen = 0UL;
1430+
fd_memset( meta->owner, 0, sizeof(fd_pubkey_t) );
14301431
}
14311432
}
14321433

@@ -1702,28 +1703,12 @@ fd_executor_txn_check( fd_bank_t * bank,
17021703

17031704
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L50 */
17041705
if( before_uninitialized || before_rent_exempt ) {
1705-
FD_LOG_DEBUG(( "Rent exempt error for %s Curr len %lu Starting len %lu Curr lamports %lu Starting lamports %lu Curr exempt %lu Starting exempt %lu",
1706-
FD_BASE58_ENC_32_ALLOCA( b->pubkey->uc ),
1707-
fd_txn_account_get_data_len( b ),
1708-
b->starting_dlen,
1709-
fd_txn_account_get_lamports( b ),
1710-
b->starting_lamports,
1711-
fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( b ) ),
1712-
fd_rent_exempt_minimum_balance( rent, b->starting_dlen ) ));
17131706
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L104 */
17141707
return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT;
17151708
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L56 */
17161709
} else if( (fd_txn_account_get_data_len( b ) == b->starting_dlen) && fd_txn_account_get_lamports( b ) <= b->starting_lamports ) {
17171710
// no-op
17181711
} else {
1719-
FD_LOG_DEBUG(( "Rent exempt error for %s Curr len %lu Starting len %lu Curr lamports %lu Starting lamports %lu Curr exempt %lu Starting exempt %lu",
1720-
FD_BASE58_ENC_32_ALLOCA( b->pubkey->uc ),
1721-
fd_txn_account_get_data_len( b ),
1722-
b->starting_dlen,
1723-
fd_txn_account_get_lamports( b ),
1724-
b->starting_lamports,
1725-
fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( b ) ),
1726-
fd_rent_exempt_minimum_balance( rent, b->starting_dlen ) ));
17271712
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L104 */
17281713
return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT;
17291714
}

src/flamenco/runtime/fd_executor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ fd_executor_txn_check( fd_bank_t * bank,
109109
fd_txn_out_t * txn_out );
110110

111111
void
112-
fd_executor_reclaim_account( fd_txn_account_t * account,
113-
ulong slot );
112+
fd_executor_reclaim_account( fd_account_meta_t * meta,
113+
ulong slot );
114114

115115
/* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a
116116
human readable cstr. The lifetime of the returned pointer is

src/flamenco/runtime/fd_runtime.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -973,14 +973,14 @@ fd_runtime_pre_execute_check( fd_runtime_t * runtime,
973973
https://github.com/anza-xyz/agave/blob/v2.1.14/runtime/src/bank.rs#L4116
974974
975975
In any case, we should always add the dlen of the fee payer. */
976-
txn_out->details.loaded_accounts_data_size = fd_txn_account_get_data_len( &txn_out->accounts.accounts[FD_FEE_PAYER_TXN_IDX] );
976+
txn_out->details.loaded_accounts_data_size = txn_out->accounts.metas[ FD_FEE_PAYER_TXN_IDX ]->dlen;
977977

978978
/* Special case handling for if a nonce account is present in the transaction. */
979979
if( txn_out->accounts.nonce_idx_in_txn!=ULONG_MAX ) {
980980
/* If the nonce account is not the fee payer, then we separately add the dlen of the nonce account. Otherwise, we would
981981
be double counting the dlen of the fee payer. */
982982
if( txn_out->accounts.nonce_idx_in_txn!=FD_FEE_PAYER_TXN_IDX ) {
983-
txn_out->details.loaded_accounts_data_size += fd_txn_account_get_data_len( txn_out->accounts.rollback_nonce );
983+
txn_out->details.loaded_accounts_data_size += txn_out->accounts.metas[ txn_out->accounts.nonce_idx_in_txn ]->dlen;
984984
}
985985
}
986986
}
@@ -1232,22 +1232,22 @@ fd_runtime_commit_txn( fd_runtime_t * runtime,
12321232
/* Tips for bundles are collected in the bank: a user submitting a
12331233
bundle must include a instruction that transfers lamports to
12341234
a specific tip account. Tips accumulated through the slot. */
1235-
if( fd_pack_tip_is_tip_account( fd_type_pun( acc_rec->pubkey->uc ) ) ) {
1236-
txn_out->details.tips += fd_ulong_sat_sub( acc_rec->meta->lamports, acc_rec->starting_lamports );
1235+
if( fd_pack_tip_is_tip_account( fd_type_pun( txn_out->accounts.pubkeys[i].uc ) ) ) {
1236+
txn_out->details.tips += fd_ulong_sat_sub( txn_out->accounts.metas[i]->lamports, txn_out->accounts.starting_lamports[i] );
12371237
FD_ATOMIC_FETCH_AND_ADD( fd_bank_tips_modify( bank ), txn_out->details.tips );
12381238
}
12391239

1240-
if( 0==memcmp( fd_txn_account_get_owner( acc_rec ), &fd_solana_vote_program_id, sizeof(fd_pubkey_t) ) ) {
1241-
fd_stakes_update_vote_state( acc_rec, bank );
1240+
if( 0==memcmp( txn_out->accounts.metas[i]->owner, &fd_solana_vote_program_id, sizeof(fd_pubkey_t) ) ) {
1241+
fd_stakes_update_vote_state( &txn_out->accounts.account_keys[i], txn_out->accounts.metas[i], bank );
12421242
}
12431243

1244-
if( 0==memcmp( fd_txn_account_get_owner( acc_rec ), &fd_solana_stake_program_id, sizeof(fd_pubkey_t) ) ) {
1244+
if( 0==memcmp( txn_out->accounts.metas[i]->owner, &fd_solana_stake_program_id, sizeof(fd_pubkey_t) ) ) {
12451245
fd_stakes_update_stake_delegation( acc_rec, bank );
12461246
}
12471247

12481248
/* Reclaim any accounts that have 0-lamports, now that any related
12491249
cache updates have been applied. */
1250-
fd_executor_reclaim_account( &txn_out->accounts.accounts[i], fd_bank_slot_get( bank ) );
1250+
fd_executor_reclaim_account( txn_out->accounts.metas[i], fd_bank_slot_get( bank ) );
12511251

12521252
fd_runtime_save_account( runtime->funk, &xid, &txn_out->accounts.accounts[i], bank, runtime->log.capture_ctx );
12531253
}

src/flamenco/runtime/fd_runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ struct fd_txn_out {
219219

220220
fd_pubkey_t pubkeys[ MAX_TX_ACCOUNT_LOCKS ];
221221
fd_account_meta_t * metas[ MAX_TX_ACCOUNT_LOCKS ];
222+
ulong starting_lamports[ MAX_TX_ACCOUNT_LOCKS ];
222223
} accounts;
223224
};
224225
typedef struct fd_txn_out fd_txn_out_t;

src/flamenco/runtime/program/fd_vote_program.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,22 +2721,22 @@ fd_vote_program_execute( fd_exec_instr_ctx_t * ctx ) {
27212721
/**********************************************************************/
27222722

27232723
uint
2724-
fd_vote_state_versions_is_correct_and_initialized( fd_txn_account_t * vote_account ) {
2724+
fd_vote_state_versions_is_correct_and_initialized( fd_account_meta_t const * meta ) {
27252725
// https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L885
2726-
uint data_len_check = fd_txn_account_get_data_len( vote_account )==FD_VOTE_STATE_V3_SZ;
2726+
uint data_len_check = meta->dlen==FD_VOTE_STATE_V3_SZ;
27272727
uchar test_data[DEFAULT_PRIOR_VOTERS_OFFSET] = {0};
27282728
uint data_check = memcmp((
2729-
fd_txn_account_get_data( vote_account )+VERSION_OFFSET), test_data, DEFAULT_PRIOR_VOTERS_OFFSET)!=0;
2729+
fd_account_meta_data( meta )+VERSION_OFFSET), test_data, DEFAULT_PRIOR_VOTERS_OFFSET)!=0;
27302730
if (data_check && data_len_check) {
27312731
return 1;
27322732
}
27332733

27342734
// VoteState1_14_11::is_correct_size_and_initialized
27352735
// https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/vote_state_1_14_11.rs#L58
2736-
data_len_check = fd_txn_account_get_data_len( vote_account )==FD_VOTE_STATE_V2_SZ;
2736+
data_len_check = meta->dlen==FD_VOTE_STATE_V2_SZ;
27372737
uchar test_data_1_14_11[DEFAULT_PRIOR_VOTERS_OFFSET_1_14_11] = {0};
27382738
data_check = memcmp( (
2739-
fd_txn_account_get_data( vote_account )+VERSION_OFFSET), test_data_1_14_11, DEFAULT_PRIOR_VOTERS_OFFSET_1_14_11)!=0;
2739+
fd_account_meta_data( meta )+VERSION_OFFSET), test_data_1_14_11, DEFAULT_PRIOR_VOTERS_OFFSET_1_14_11)!=0;
27402740
return data_check && data_len_check;
27412741
}
27422742

@@ -2756,26 +2756,27 @@ fd_vote_convert_to_current( fd_vote_state_versioned_t * self,
27562756
}
27572757

27582758
void
2759-
fd_vote_store_account( fd_txn_account_t * vote_account,
2760-
fd_bank_t * bank ) {
2759+
fd_vote_store_account( fd_pubkey_t const * vote_account,
2760+
fd_account_meta_t const * meta,
2761+
fd_bank_t * bank ) {
27612762

27622763
fd_vote_states_t * vote_states = fd_bank_vote_states_locking_modify( bank );
27632764

2764-
if( fd_txn_account_get_lamports( vote_account )==0UL ) {
2765-
fd_vote_states_remove( vote_states, vote_account->pubkey );
2765+
if( meta->lamports==0UL ) {
2766+
fd_vote_states_remove( vote_states, vote_account );
27662767
fd_bank_vote_states_end_locking_modify( bank );
27672768
return;
27682769
}
27692770

2770-
if( !fd_vote_state_versions_is_correct_and_initialized( vote_account ) ) {
2771-
fd_vote_states_remove( vote_states, vote_account->pubkey );
2771+
if( !fd_vote_state_versions_is_correct_and_initialized( meta ) ) {
2772+
fd_vote_states_remove( vote_states, vote_account );
27722773
fd_bank_vote_states_end_locking_modify( bank );
27732774
return;
27742775
}
27752776

27762777
fd_vote_states_update_from_account( vote_states,
2777-
vote_account->pubkey,
2778-
fd_txn_account_get_data( vote_account ),
2779-
fd_txn_account_get_data_len( vote_account ) );
2778+
vote_account,
2779+
fd_account_meta_data( meta ),
2780+
meta->dlen );
27802781
fd_bank_vote_states_end_locking_modify( bank );
27812782
}

src/flamenco/runtime/program/fd_vote_program.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fd_vote_program_execute( fd_exec_instr_ctx_t * ctx );
4848

4949
/* https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/vote_state_versions.rs#L90 */
5050
uint
51-
fd_vote_state_versions_is_correct_and_initialized( fd_txn_account_t * vote_account );
51+
fd_vote_state_versions_is_correct_and_initialized( fd_account_meta_t const * meta );
5252

5353
/* An implementation of solana_sdk::transaction_context::BorrowedAccount::get_state
5454
for setting the vote state.
@@ -64,8 +64,9 @@ fd_vote_convert_to_current( fd_vote_state_versioned_t * self,
6464
uchar * landed_votes_mem );
6565

6666
void
67-
fd_vote_store_account( fd_txn_account_t * vote_account,
68-
fd_bank_t * bank );
67+
fd_vote_store_account( fd_pubkey_t const * vote_account,
68+
fd_account_meta_t const * meta,
69+
fd_bank_t * bank );
6970

7071
FD_PROTOTYPES_END
7172

src/flamenco/runtime/tests/fd_block_harness.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ fd_solfuzz_block_register_vote_account( fd_funk_t * funk,
110110
}
111111

112112
/* Account must be initialized correctly */
113-
if( FD_UNLIKELY( !fd_vote_state_versions_is_correct_and_initialized( acc ) ) ) {
113+
if( FD_UNLIKELY( !fd_vote_state_versions_is_correct_and_initialized( acc->meta ) ) ) {
114114
return;
115115
}
116116

117117
fd_vote_states_update_from_account(
118118
vote_states,
119119
acc->pubkey,
120-
fd_txn_account_get_data( acc ),
121-
fd_txn_account_get_data_len( acc ) );
120+
fd_account_meta_data( acc->meta ),
121+
acc->meta->dlen );
122122
}
123123

124124
/* Stores an entry in the stake delegations cache for the given vote

src/flamenco/runtime/tests/test_dump_block.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ register_vote_account_from_funk( fd_funk_t * funk,
235235
}
236236

237237
/* Account must be initialized correctly */
238-
if( FD_UNLIKELY( !fd_vote_state_versions_is_correct_and_initialized( acc ) ) ) {
238+
if( FD_UNLIKELY( !fd_vote_state_versions_is_correct_and_initialized( acc->meta ) ) ) {
239239
return;
240240
}
241241

src/flamenco/stakes/fd_stakes.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,27 @@ fd_stakes_update_stake_delegation( fd_txn_account_t * stake_account,
226226
}
227227

228228
void
229-
fd_stakes_update_vote_state( fd_txn_account_t * vote_account,
230-
fd_bank_t * bank ) {
231-
232-
if( !vote_account->is_mutable ) return;
229+
fd_stakes_update_vote_state( fd_pubkey_t const * vote_account,
230+
fd_account_meta_t const * meta,
231+
fd_bank_t * bank ) {
233232

234233
fd_vote_states_t * vote_states = fd_bank_vote_states_locking_modify( bank );
235234

236-
if( fd_txn_account_get_lamports( vote_account )==0UL ) {
237-
fd_vote_states_remove( vote_states, vote_account->pubkey );
235+
if( meta->lamports==0UL ) {
236+
fd_vote_states_remove( vote_states, vote_account );
238237
fd_bank_vote_states_end_locking_modify( bank );
239238
return;
240239
}
241240

242-
if( !fd_vote_state_versions_is_correct_and_initialized( vote_account ) ) {
243-
fd_vote_states_remove( vote_states, vote_account->pubkey );
241+
if( !fd_vote_state_versions_is_correct_and_initialized( meta ) ) {
242+
fd_vote_states_remove( vote_states, vote_account );
244243
fd_bank_vote_states_end_locking_modify( bank );
245244
return;
246245
}
247246

248247
fd_vote_states_update_from_account( vote_states,
249-
vote_account->pubkey,
250-
fd_txn_account_get_data( vote_account ),
251-
fd_txn_account_get_data_len( vote_account ) );
248+
vote_account,
249+
fd_account_meta_data( meta ),
250+
meta->dlen );
252251
fd_bank_vote_states_end_locking_modify( bank );
253252
}

0 commit comments

Comments
 (0)