Skip to content

Commit 2dcd192

Browse files
wip
1 parent c6779f4 commit 2dcd192

17 files changed

+76
-66
lines changed

src/flamenco/progcache/test_progcache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ create_test_account( test_env_t * env,
147147
fd_txn_account_set_data( acc, data, data_len );
148148
}
149149

150-
acc->starting_lamports = 1UL;
151-
acc->starting_dlen = data_len;
150+
// acc->starting_lamports = 1UL;
151+
// acc->starting_dlen = data_len;
152152
fd_txn_account_set_lamports( acc, 1UL );
153153
fd_txn_account_set_executable( acc, executable );
154154
fd_txn_account_set_owner( acc, &owner );

src/flamenco/runtime/fd_executor.c

Lines changed: 25 additions & 19 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( runtime, 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

@@ -490,7 +490,8 @@ load_transaction_account( fd_runtime_t * runtime,
490490

491491
/* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L828-L835 */
492492
if( is_writable ) {
493-
acct->starting_lamports = fd_txn_account_get_lamports( acct ); /* TODO: why do we do this everywhere? */
493+
runtime->accounts.starting_lamports[acc_idx] = fd_txn_account_get_lamports( acct );
494+
runtime->accounts.starting_dlen[acc_idx] = fd_txn_account_get_data_len( acct );
494495
}
495496
return fd_ulong_sat_add( base_account_size, fd_txn_account_get_data_len( acct ) );
496497
}
@@ -1069,7 +1070,8 @@ fd_executor_validate_transaction_fee_payer( fd_runtime_t * runtime,
10691070
fd_executor_create_rollback_fee_payer_account( runtime, bank, txn_in, txn_out, total_fee );
10701071

10711072
/* Set the starting lamports (to avoid unbalanced lamports issues in instruction execution) */
1072-
fee_payer_rec->starting_lamports = fd_txn_account_get_lamports( fee_payer_rec ); /* TODO: why do we do this everywhere? */
1073+
runtime->accounts.starting_lamports[FD_FEE_PAYER_TXN_IDX] = fd_txn_account_get_lamports( fee_payer_rec );
1074+
runtime->accounts.starting_dlen[FD_FEE_PAYER_TXN_IDX] = fd_txn_account_get_data_len( fee_payer_rec );
10731075

10741076
txn_out->details.execution_fee = execution_fee;
10751077
txn_out->details.priority_fee = priority_fee;
@@ -1562,7 +1564,7 @@ fd_executor_setup_executable_account( fd_runtime_t * runtime,
15621564
account will not exist within the executable accounts list. */
15631565
fd_pubkey_t * programdata_acc = &program_loader_state->inner.program.programdata_address;
15641566
fd_funk_txn_xid_t xid = { .ul = { fd_bank_slot_get( bank ), bank->idx } };
1565-
if( FD_LIKELY( fd_txn_account_init_from_funk_readonly( &runtime->executable.accounts[ *executable_idx ],
1567+
if( FD_LIKELY( fd_txn_account_init_from_funk_readonly( &runtime->accounts.executables[ *executable_idx ],
15661568
programdata_acc,
15671569
runtime->funk,
15681570
&xid )==0 ) ) {
@@ -1601,7 +1603,7 @@ fd_executor_setup_accounts_for_txn( fd_runtime_t * runtime,
16011603
# endif
16021604

16031605
txn_out->accounts.nonce_idx_in_txn = ULONG_MAX;
1604-
runtime->executable.cnt = executable_idx;
1606+
runtime->accounts.executable_cnt = executable_idx;
16051607

16061608
/* Set up instr infos from the txn descriptor. No Agave equivalent to this function. */
16071609
fd_executor_setup_instr_infos_from_txn_instrs( runtime, bank, txn_in, txn_out );
@@ -1657,11 +1659,12 @@ fd_execute_txn( fd_runtime_t * runtime,
16571659

16581660
/* TODO: This function needs to be split out of fd_execute_txn and be placed
16591661
into the replay tile once it is implemented. */
1660-
return fd_executor_txn_check( bank, txn_out );
1662+
return fd_executor_txn_check( runtime, bank, txn_out );
16611663
}
16621664

16631665
int
1664-
fd_executor_txn_check( fd_bank_t * bank,
1666+
fd_executor_txn_check( fd_runtime_t * runtime,
1667+
fd_bank_t * bank,
16651668
fd_txn_out_t * txn_out ) {
16661669
fd_rent_t const * rent = fd_bank_rent_query( bank );
16671670

@@ -1671,9 +1674,12 @@ fd_executor_txn_check( fd_bank_t * bank,
16711674
ulong ending_lamports_l = 0;
16721675
ulong ending_lamports_h = 0;
16731676

1677+
16741678
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L63 */
16751679
for( ulong idx = 0; idx < txn_out->accounts.accounts_cnt; idx++ ) {
16761680
fd_txn_account_t * b = &txn_out->accounts.accounts[idx];
1681+
ulong starting_lamports = runtime->accounts.starting_lamports[idx];
1682+
ulong starting_dlen = runtime->accounts.starting_dlen[idx];
16771683

16781684
// Was this account written to?
16791685
/* TODO: Clean this logic up... lots of redundant checks with our newer account loading model.
@@ -1697,41 +1703,41 @@ fd_executor_txn_check( fd_bank_t * bank,
16971703
// no-op
16981704
} else {
16991705
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L45-L59 */
1700-
uchar before_uninitialized = b->starting_dlen == ULONG_MAX || b->starting_lamports == 0;
1701-
uchar before_rent_exempt = b->starting_dlen != ULONG_MAX && b->starting_lamports >= fd_rent_exempt_minimum_balance( rent, b->starting_dlen );
1706+
uchar before_uninitialized = starting_dlen == ULONG_MAX || starting_lamports == 0;
1707+
uchar before_rent_exempt = starting_dlen != ULONG_MAX && starting_lamports >= fd_rent_exempt_minimum_balance( rent, starting_dlen );
17021708

17031709
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L50 */
17041710
if( before_uninitialized || before_rent_exempt ) {
17051711
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",
17061712
FD_BASE58_ENC_32_ALLOCA( b->pubkey->uc ),
17071713
fd_txn_account_get_data_len( b ),
1708-
b->starting_dlen,
1714+
starting_dlen,
17091715
fd_txn_account_get_lamports( b ),
1710-
b->starting_lamports,
1716+
starting_lamports,
17111717
fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( b ) ),
1712-
fd_rent_exempt_minimum_balance( rent, b->starting_dlen ) ));
1718+
fd_rent_exempt_minimum_balance( rent, starting_dlen ) ));
17131719
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L104 */
17141720
return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT;
17151721
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L56 */
1716-
} else if( (fd_txn_account_get_data_len( b ) == b->starting_dlen) && fd_txn_account_get_lamports( b ) <= b->starting_lamports ) {
1722+
} else if( (fd_txn_account_get_data_len( b ) == starting_dlen) && fd_txn_account_get_lamports( b ) <= starting_lamports ) {
17171723
// no-op
17181724
} else {
17191725
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",
17201726
FD_BASE58_ENC_32_ALLOCA( b->pubkey->uc ),
17211727
fd_txn_account_get_data_len( b ),
1722-
b->starting_dlen,
1728+
starting_dlen,
17231729
fd_txn_account_get_lamports( b ),
1724-
b->starting_lamports,
1730+
starting_lamports,
17251731
fd_rent_exempt_minimum_balance( rent, fd_txn_account_get_data_len( b ) ),
1726-
fd_rent_exempt_minimum_balance( rent, b->starting_dlen ) ));
1732+
fd_rent_exempt_minimum_balance( rent, starting_dlen ) ));
17271733
/* https://github.com/anza-xyz/agave/blob/b2c388d6cbff9b765d574bbb83a4378a1fc8af32/svm/src/account_rent_state.rs#L104 */
17281734
return FD_RUNTIME_TXN_ERR_INSUFFICIENT_FUNDS_FOR_RENT;
17291735
}
17301736
}
17311737
}
17321738

1733-
if( b->starting_lamports != ULONG_MAX ) {
1734-
fd_uwide_inc( &starting_lamports_h, &starting_lamports_l, starting_lamports_h, starting_lamports_l, b->starting_lamports );
1739+
if( starting_lamports != ULONG_MAX ) {
1740+
fd_uwide_inc( &starting_lamports_h, &starting_lamports_l, starting_lamports_h, starting_lamports_l, starting_lamports );
17351741
}
17361742
}
17371743
}

src/flamenco/runtime/fd_executor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ fd_executor_setup_txn_alut_account_keys( fd_runtime_t * runtime,
105105
*/
106106

107107
int
108-
fd_executor_txn_check( fd_bank_t * bank,
108+
fd_executor_txn_check( fd_runtime_t * runtime,
109+
fd_bank_t * bank,
109110
fd_txn_out_t * txn_out );
110111

111112
void

src/flamenco/runtime/fd_runtime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ fd_runtime_commit_txn( fd_runtime_t * runtime,
12331233
bundle must include a instruction that transfers lamports to
12341234
a specific tip account. Tips accumulated through the slot. */
12351235
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 );
1236+
txn_out->details.tips += fd_ulong_sat_sub( acc_rec->meta->lamports, runtime->accounts.starting_lamports[i] );
12371237
FD_ATOMIC_FETCH_AND_ADD( fd_bank_tips_modify( bank ), txn_out->details.tips );
12381238
}
12391239

@@ -1334,7 +1334,7 @@ fd_runtime_prepare_and_execute_txn( fd_runtime_t * runtime,
13341334
memset( txn_out->details.return_data.program_id.key, 0, sizeof(fd_pubkey_t) );
13351335
fd_compute_budget_details_new( &txn_out->details.compute_budget );
13361336

1337-
runtime->executable.cnt = 0UL;
1337+
runtime->accounts.executable_cnt = 0UL;
13381338
runtime->log.enable_log_collector = 0;
13391339
runtime->instr.info_cnt = 0UL;
13401340
runtime->instr.trace_length = 0UL;
@@ -1794,9 +1794,9 @@ fd_runtime_get_executable_account( fd_runtime_t * runtime,
17941794
return FD_ACC_MGR_SUCCESS;
17951795
}
17961796

1797-
for( ushort i=0; i<runtime->executable.cnt; i++ ) {
1798-
if( memcmp( pubkey->uc, runtime->executable.accounts[i].pubkey->uc, sizeof(fd_pubkey_t) )==0 ) {
1799-
fd_txn_account_t * txn_account = &runtime->executable.accounts[i];
1797+
for( ushort i=0; i<runtime->accounts.executable_cnt; i++ ) {
1798+
if( memcmp( pubkey->uc, runtime->accounts.executables[i].pubkey->uc, sizeof(fd_pubkey_t) )==0 ) {
1799+
fd_txn_account_t * txn_account = &runtime->accounts.executables[i];
18001800
*account = txn_account;
18011801

18021802
if( FD_LIKELY( condition != NULL ) ) {

src/flamenco/runtime/fd_runtime.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ struct fd_runtime {
127127
} stake_program;
128128

129129
struct {
130-
ulong cnt; /* Number of BPF upgradeable loader accounts. */
131-
fd_txn_account_t accounts[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of BPF upgradeable loader program data accounts */
132-
} executable;
130+
ulong executable_cnt; /* Number of BPF upgradeable loader accounts. */
131+
fd_txn_account_t executables[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of BPF upgradeable loader program data accounts */
132+
ulong starting_lamports[ MAX_TX_ACCOUNT_LOCKS ]; /* Starting lamports for each account */
133+
ulong starting_dlen[ MAX_TX_ACCOUNT_LOCKS ]; /* Starting data length for each account */
134+
} accounts;
133135
};
134136
typedef struct fd_runtime fd_runtime_t;
135137

src/flamenco/runtime/fd_txn_account.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ fd_txn_account_new( void * mem,
3232

3333
fd_memcpy( txn_account->pubkey, pubkey, sizeof(fd_pubkey_t) );
3434

35-
txn_account->magic = FD_TXN_ACCOUNT_MAGIC;
36-
37-
txn_account->starting_dlen = meta->dlen;
38-
txn_account->starting_lamports = meta->lamports;
35+
txn_account->magic = FD_TXN_ACCOUNT_MAGIC;
3936

4037
uchar * data = (uchar *)meta + sizeof(fd_account_meta_t);
4138

src/flamenco/runtime/fd_txn_account.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ struct __attribute__((aligned(8UL))) fd_txn_account {
3535
int is_mutable;
3636
long meta_soff;
3737

38-
ulong starting_dlen;
39-
ulong starting_lamports;
40-
4138
/* Provide borrowing semantics. Used for single-threaded logic only,
4239
thus not comparable to a data synchronization lock. */
4340
ushort refcnt_excl;

src/flamenco/runtime/sysvar/fd_sysvar_instructions.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ instructions_serialized_size( fd_instr_info_t const * instrs,
3333

3434
/* https://github.com/anza-xyz/agave/blob/v2.1.1/svm/src/account_loader.rs#L547-L576 */
3535
void
36-
fd_sysvar_instructions_serialize_account( fd_txn_in_t const * txn_in,
36+
fd_sysvar_instructions_serialize_account( fd_runtime_t * runtime,
37+
fd_txn_in_t const * txn_in,
3738
fd_txn_out_t * txn_out,
3839
fd_instr_info_t const * instrs,
3940
ushort instrs_cnt,
40-
ulong txn_idx ) {
41+
ulong acc_idx ) {
4142
ulong serialized_sz = instructions_serialized_size( instrs, instrs_cnt );
4243

4344
fd_txn_account_t * rec = NULL;
@@ -63,7 +64,7 @@ fd_sysvar_instructions_serialize_account( fd_txn_in_t const * txn_in,
6364
- sizeof(fd_account_meta_t) + serialized_sz will always be less than FD_ACC_TOT_SZ_MAX
6465
- at most 127 accounts could be using spad memory right now, so this allocation is safe */
6566
if( !fd_txn_account_is_mutable( rec ) ) {
66-
uchar const * mem = txn_in->exec_accounts->accounts_mem[ txn_idx ];
67+
uchar const * mem = txn_in->exec_accounts->accounts_mem[ acc_idx ];
6768
fd_account_meta_t * meta = (fd_account_meta_t *)mem;
6869
fd_txn_account_t * acc = fd_txn_account_join( fd_txn_account_new( rec, &fd_sysvar_instructions_id, meta, 1 ) );
6970
if( FD_UNLIKELY( !acc ) ) {
@@ -78,7 +79,7 @@ fd_sysvar_instructions_serialize_account( fd_txn_in_t const * txn_in,
7879
fd_txn_account_set_lamports( rec, 0UL );
7980
fd_txn_account_set_executable( rec, 0 );
8081
fd_txn_account_set_data_len( rec, serialized_sz );
81-
rec->starting_lamports = 0UL;
82+
runtime->accounts.starting_lamports[acc_idx] = fd_txn_account_get_lamports( rec );
8283

8384
uchar * serialized_instructions = fd_txn_account_get_data_mut( rec );
8485
ulong offset = 0;

src/flamenco/runtime/sysvar/fd_sysvar_instructions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
FD_PROTOTYPES_BEGIN
99

1010
void
11-
fd_sysvar_instructions_serialize_account( fd_txn_in_t const * txn_in,
11+
fd_sysvar_instructions_serialize_account( fd_runtime_t * runtime,
12+
fd_txn_in_t const * txn_in,
1213
fd_txn_out_t * txn_out,
1314
fd_instr_info_t const * instrs,
1415
ushort instrs_cnt,

src/flamenco/runtime/test_runtime_alut.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ create_test_account( test_ctx_t * ctx,
117117
fd_txn_account_set_data( acc, data, data_len );
118118
}
119119

120-
acc->starting_lamports = lamports;
121-
acc->starting_dlen = data_len;
120+
// acc->starting_lamports = lamports;
121+
// acc->starting_dlen = data_len;
122122
fd_txn_account_set_lamports( acc, lamports );
123123
fd_txn_account_set_executable( acc, executable );
124124
fd_txn_account_set_owner( acc, &owner );

0 commit comments

Comments
 (0)