Skip to content

Commit a955f35

Browse files
wip
1 parent fa0c236 commit a955f35

24 files changed

+273
-192
lines changed

src/discof/bank/fd_bank_tile.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct {
5555
for non-bundle execution. */
5656
fd_exec_txn_ctx_t txn_ctx[ FD_PACK_MAX_TXN_PER_BUNDLE ];
5757
fd_exec_accounts_t exec_accounts[ FD_PACK_MAX_TXN_PER_BUNDLE ];
58+
fd_txn_in_t txn_in[ FD_PACK_MAX_TXN_PER_BUNDLE ];
5859
fd_txn_out_t txn_out[ FD_PACK_MAX_TXN_PER_BUNDLE ];
5960
fd_exec_stack_t exec_stack;
6061

@@ -173,6 +174,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
173174
for( ulong i=0UL; i<txn_cnt; i++ ) {
174175
fd_txn_p_t * txn = (fd_txn_p_t *)( dst + (i*sizeof(fd_txn_p_t)) );
175176
fd_exec_txn_ctx_t * txn_ctx = &ctx->txn_ctx[ 0 ];
177+
fd_txn_in_t * txn_in = &ctx->txn_in[ 0 ];
176178
fd_txn_out_t * txn_out = &ctx->txn_out[ 0 ];
177179
ctx->txn_ctx->bundle.is_bundle = 0;
178180

@@ -186,12 +188,14 @@ handle_microblock( fd_bank_ctx_t * ctx,
186188
txn->flags &= ~FD_TXN_P_FLAGS_SANITIZE_SUCCESS;
187189
txn->flags &= ~FD_TXN_P_FLAGS_EXECUTE_SUCCESS;
188190

191+
txn_in->txn = *txn;
192+
189193
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, ctx->_bank_idx );
190194
FD_TEST( bank );
191195
txn_out->err.exec_err = fd_runtime_prepare_and_execute_txn( &ctx->runtime,
192196
bank,
197+
txn_in,
193198
txn_ctx,
194-
txn,
195199
txn_out,
196200
NULL,
197201
&ctx->exec_accounts[0],
@@ -231,15 +235,15 @@ handle_microblock( fd_bank_ctx_t * ctx,
231235
if that happens. We cannot reject the transaction here as there
232236
would be no way to undo the partially applied changes to the bank
233237
in finalize anyway. */
234-
fd_runtime_commit_txn( &ctx->runtime, bank, txn_out, txn_ctx, NULL, &tips );
238+
fd_runtime_commit_txn( &ctx->runtime, bank, txn_in, txn_out, txn_ctx, NULL, &tips );
235239

236240
if( FD_UNLIKELY( !txn_out->err.is_committable ) ) {
237241
/* If the transaction failed to fit into the block, we need to
238242
updated the transaction flag with the error code. */
239243
txn->flags = (txn->flags & 0x00FFFFFFU) | ((uint)(-txn_out->err.exec_err)<<24);
240244
fd_cost_tracker_t * cost_tracker = fd_bank_cost_tracker_locking_modify( bank );
241-
uchar * signature = (uchar *)txn_ctx->txn.payload + TXN( &txn_ctx->txn )->signature_off;
242-
int res = fd_cost_tracker_calculate_cost_and_add( cost_tracker, txn_out, txn_ctx );
245+
uchar * signature = (uchar *)txn_in->txn.payload + TXN( &txn_in->txn )->signature_off;
246+
int res = fd_cost_tracker_calculate_cost_and_add( cost_tracker, txn_in, txn_out, txn_ctx );
243247
FD_LOG_HEXDUMP_WARNING(( "txn", txn->payload, txn->payload_sz ));
244248
FD_LOG_CRIT(( "transaction %s failed to fit into block despite pack guaranteeing it would "
245249
"(res=%d) [block_cost=%lu, vote_cost=%lu, allocated_accounts_data_size=%lu, "
@@ -272,7 +276,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
272276
/* The account keys in the transaction context are laid out such
273277
that first the non-alt accounts are laid out, then the writable
274278
alt accounts, and finally the read-only alt accounts. */
275-
fd_txn_t * txn_descriptor = TXN( &txn_ctx->txn );
279+
fd_txn_t * txn_descriptor = TXN( &txn_in->txn );
276280
fd_acct_addr_t const * writable_alt = fd_type_pun_const( txn_out->accounts.account_keys+txn_descriptor->acct_addr_cnt );
277281
fd_pack_rebate_sum_add_txn( ctx->rebater, txn, &writable_alt, 1UL );
278282

@@ -367,6 +371,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
367371

368372
fd_txn_p_t * txn = &txns[ i ];
369373
fd_exec_txn_ctx_t * txn_ctx = &ctx->txn_ctx[ i ];
374+
fd_txn_in_t * txn_in = &ctx->txn_in[ i ];
370375
fd_txn_out_t * txn_out = &ctx->txn_out[ i ];
371376
txn_ctx->bundle.is_bundle = 1;
372377

@@ -377,17 +382,20 @@ handle_bundle( fd_bank_ctx_t * ctx,
377382
txn->flags = (txn->flags & 0x00FFFFFFU) | ((uint)(-FD_RUNTIME_TXN_ERR_BUNDLE_PEER)<<24);
378383
continue;
379384
}
385+
386+
txn_in->txn = *txn;
387+
380388
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, ctx->_bank_idx );
381389
FD_TEST( bank );
382390
txn_ctx->bundle.is_bundle = 1;
383-
txn_out->err.exec_err = fd_runtime_prepare_and_execute_txn( &ctx->runtime, bank, txn_ctx, txn, txn_out, NULL, &ctx->exec_accounts[ i ], NULL, NULL );
391+
txn_out->err.exec_err = fd_runtime_prepare_and_execute_txn( &ctx->runtime, bank, txn_in, txn_ctx, txn_out, NULL, &ctx->exec_accounts[ i ], NULL, NULL );
384392
txn->flags = (txn->flags & 0x00FFFFFFU) | ((uint)(-txn_out->err.exec_err)<<24);
385393
if( FD_UNLIKELY( !txn_out->err.is_committable || txn_out->err.exec_err!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
386394
execution_success = 0;
387395
continue;
388396
}
389397

390-
writable_alt[i] = fd_type_pun_const( txn_out->accounts.account_keys+TXN( &txn_ctx->txn )->acct_addr_cnt );
398+
writable_alt[i] = fd_type_pun_const( txn_out->accounts.account_keys+TXN( &txn_in->txn )->acct_addr_cnt );
391399
}
392400

393401
/* If all of the transactions in the bundle executed successfully, we
@@ -399,15 +407,16 @@ handle_bundle( fd_bank_ctx_t * ctx,
399407
for( ulong i=0UL; i<txn_cnt; i++ ) {
400408

401409
fd_exec_txn_ctx_t * txn_ctx = &ctx->txn_ctx[ i ];
410+
fd_txn_in_t * txn_in = &ctx->txn_in[ i ];
402411
fd_txn_out_t * txn_out = &ctx->txn_out[ i ];
403-
uchar * signature = (uchar *)txn_ctx->txn.payload + TXN( &txn_ctx->txn )->signature_off;
412+
uchar * signature = (uchar *)txn_in->txn.payload + TXN( &txn_in->txn )->signature_off;
404413

405414
txns[ i ].flags |= FD_TXN_P_FLAGS_EXECUTE_SUCCESS | FD_TXN_P_FLAGS_SANITIZE_SUCCESS;
406-
fd_runtime_commit_txn( &ctx->runtime, bank, txn_out, txn_ctx, NULL, &tips[ i ] );
415+
fd_runtime_commit_txn( &ctx->runtime, bank, txn_in, txn_out, txn_ctx, NULL, &tips[ i ] );
407416
if( FD_UNLIKELY( !txn_out->err.is_committable ) ) {
408417
txns[ i ].flags = (txns[ i ].flags & 0x00FFFFFFU) | ((uint)(-txn_out->err.exec_err)<<24);
409418
fd_cost_tracker_t * cost_tracker = fd_bank_cost_tracker_locking_modify( bank );
410-
int res = fd_cost_tracker_calculate_cost_and_add( cost_tracker, txn_out, txn_ctx );
419+
int res = fd_cost_tracker_calculate_cost_and_add( cost_tracker, txn_in, txn_out, txn_ctx );
411420
FD_LOG_HEXDUMP_WARNING(( "txn", txns[ i ].payload, txns[ i ].payload_sz ));
412421
FD_LOG_CRIT(( "transaction %s failed to fit into block despite pack guaranteeing it would "
413422
"(res=%d) [block_cost=%lu, vote_cost=%lu, allocated_accounts_data_size=%lu, "

src/discof/exec/fd_exec_tile.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ typedef struct fd_exec_tile_ctx {
7474
fd_exec_stack_t exec_stack;
7575
fd_exec_accounts_t exec_accounts;
7676

77-
fd_txn_out_t txn_out;
77+
fd_txn_in_t txn_in;
78+
fd_txn_out_t txn_out;
7879

7980
/* tracing_mem is staging memory to dump instructions/transactions
8081
into protobuf files. tracing_mem is staging memory to output vm
@@ -137,26 +138,27 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
137138
fd_exec_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
138139
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
139140
FD_TEST( bank );
141+
ctx->txn_in.txn = msg->txn;
140142
ctx->txn_out.err.exec_err = fd_runtime_prepare_and_execute_txn( &ctx->runtime,
141-
bank,
142-
ctx->txn_ctx,
143-
&msg->txn,
144-
&ctx->txn_out,
145-
ctx->capture_ctx,
146-
&ctx->exec_accounts,
147-
ctx->dumping_mem,
148-
&ctx->tracing_mem[0][0] );
143+
bank,
144+
&ctx->txn_in,
145+
ctx->txn_ctx,
146+
&ctx->txn_out,
147+
ctx->capture_ctx,
148+
&ctx->exec_accounts,
149+
ctx->dumping_mem,
150+
&ctx->tracing_mem[0][0] );
149151

150152
/* Commit. */
151153
if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
152-
fd_runtime_commit_txn( &ctx->runtime, bank, &ctx->txn_out, ctx->txn_ctx, ctx->capture_ctx, NULL );
154+
fd_runtime_commit_txn( &ctx->runtime, bank, &ctx->txn_in, &ctx->txn_out, ctx->txn_ctx, ctx->capture_ctx, NULL );
153155
}
154156

155157
if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
156158
/* Copy the txn signature to the signature out link so the
157159
dedup/pack tiles can drop already executed transactions. */
158160
memcpy( fd_chunk_to_laddr( ctx->exec_sig_out->mem, ctx->exec_sig_out->chunk ),
159-
(uchar *)ctx->txn_ctx->txn.payload + TXN( &ctx->txn_ctx->txn )->signature_off,
161+
(uchar *)ctx->txn_in.txn.payload + TXN( &ctx->txn_in.txn )->signature_off,
160162
64UL );
161163
fd_stem_publish( stem, ctx->exec_sig_out->idx, 0UL, ctx->exec_sig_out->chunk, 64UL, 0UL, 0UL, 0UL );
162164
ctx->exec_sig_out->chunk = fd_dcache_compact_next( ctx->exec_sig_out->chunk, 64UL, ctx->exec_sig_out->chunk0, ctx->exec_sig_out->wmark );
@@ -399,8 +401,8 @@ publish_txn_finalized_msg( fd_exec_tile_ctx_t * ctx,
399401
msg->txn_exec->txn_idx = ctx->txn_idx;
400402
msg->txn_exec->err = !ctx->txn_out.err.is_committable;
401403
msg->txn_exec->slot = ctx->slot;
402-
msg->txn_exec->start_shred_idx = ctx->txn_ctx->txn.start_shred_idx;
403-
msg->txn_exec->end_shred_idx = ctx->txn_ctx->txn.end_shred_idx;
404+
msg->txn_exec->start_shred_idx = ctx->txn_in.txn.start_shred_idx;
405+
msg->txn_exec->end_shred_idx = ctx->txn_in.txn.end_shred_idx;
404406
if( FD_UNLIKELY( msg->txn_exec->err ) ) {
405407
FD_LOG_WARNING(( "txn failed to execute, bad block detected err=%d", ctx->txn_out.err.txn_err ));
406408
}

src/flamenco/fd_flamenco_base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ typedef struct fd_exec_stack fd_exec_stack_t;
103103
struct fd_runtime;
104104
typedef struct fd_runtime fd_runtime_t;
105105

106+
struct fd_txn_in;
107+
typedef struct fd_txn_in fd_txn_in_t;
108+
106109
struct fd_txn_out;
107110
typedef struct fd_txn_out fd_txn_out_t;
108111

src/flamenco/runtime/context/fd_exec_instr_ctx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ fd_exec_instr_ctx_try_borrow_account( fd_exec_instr_ctx_t const * ctx,
4747
/* Get the account from the transaction context using idx_in_txn.
4848
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L600-L602 */
4949
fd_txn_account_t * txn_account = NULL;
50-
int err = fd_exec_txn_ctx_get_account_at_index( ctx->txn_out,
50+
int err = fd_exec_txn_ctx_get_account_at_index( ctx->txn_in,
51+
ctx->txn_out,
5152
ctx->txn_ctx,
5253
idx_in_txn,
5354
&txn_account,

src/flamenco/runtime/context/fd_exec_instr_ctx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct fd_exec_instr_ctx {
1818
fd_instr_info_t const * instr; /* The instruction info for this instruction */
1919
fd_exec_txn_ctx_t * txn_ctx; /* The transaction context for this instruction */
2020
fd_runtime_t * runtime; /* The runtime for this instruction */
21+
fd_txn_in_t const * txn_in; /* The input for this instruction */
2122
fd_txn_out_t * txn_out; /* The output for this instruction */
2223
fd_sysvar_cache_t const * sysvar_cache;
2324

src/flamenco/runtime/context/fd_exec_txn_ctx.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ fd_exec_txn_ctx_find_index_of_account( fd_txn_out_t const * txn_out,
7979
}
8080

8181
int
82-
fd_exec_txn_ctx_get_account_at_index( fd_txn_out_t * txn_out,
82+
fd_exec_txn_ctx_get_account_at_index( fd_txn_in_t const * txn_in,
83+
fd_txn_out_t * txn_out,
8384
fd_exec_txn_ctx_t * txn_ctx,
8485
ushort idx,
8586
fd_txn_account_t * * account,
@@ -92,7 +93,7 @@ fd_exec_txn_ctx_get_account_at_index( fd_txn_out_t * txn_out,
9293
*account = txn_account;
9394

9495
if( FD_LIKELY( condition != NULL ) ) {
95-
if( FD_UNLIKELY( !condition( *account, txn_out, txn_ctx, idx ) ) ) {
96+
if( FD_UNLIKELY( !condition( *account, txn_in, txn_out, txn_ctx, idx ) ) ) {
9697
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT;
9798
}
9899
}
@@ -101,7 +102,8 @@ fd_exec_txn_ctx_get_account_at_index( fd_txn_out_t * txn_out,
101102
}
102103

103104
int
104-
fd_exec_txn_ctx_get_account_with_key( fd_txn_out_t * txn_out,
105+
fd_exec_txn_ctx_get_account_with_key( fd_txn_in_t const * txn_in,
106+
fd_txn_out_t * txn_out,
105107
fd_exec_txn_ctx_t * ctx,
106108
fd_pubkey_t const * pubkey,
107109
fd_txn_account_t * * account,
@@ -111,15 +113,17 @@ fd_exec_txn_ctx_get_account_with_key( fd_txn_out_t * txn_out,
111113
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT;
112114
}
113115

114-
return fd_exec_txn_ctx_get_account_at_index( txn_out,
116+
return fd_exec_txn_ctx_get_account_at_index( txn_in,
117+
txn_out,
115118
ctx,
116119
(uchar)index,
117120
account,
118121
condition );
119122
}
120123

121124
int
122-
fd_exec_txn_ctx_get_executable_account( fd_txn_out_t * txn_out,
125+
fd_exec_txn_ctx_get_executable_account( fd_txn_in_t const * txn_in,
126+
fd_txn_out_t * txn_out,
123127
fd_exec_txn_ctx_t * ctx,
124128
fd_pubkey_t const * pubkey,
125129
fd_txn_account_t * * account,
@@ -129,7 +133,8 @@ fd_exec_txn_ctx_get_executable_account( fd_txn_out_t * txn_out,
129133
borrowed account since it reflects changes from prior instructions. Referencing the
130134
read-only executable accounts list is incorrect behavior when the program
131135
data account is written to in a prior instruction (e.g. program upgrade + invoke within the same txn) */
132-
int err = fd_exec_txn_ctx_get_account_with_key( txn_out,
136+
int err = fd_exec_txn_ctx_get_account_with_key( txn_in,
137+
txn_out,
133138
ctx,
134139
pubkey,
135140
account,
@@ -144,7 +149,7 @@ fd_exec_txn_ctx_get_executable_account( fd_txn_out_t * txn_out,
144149
*account = txn_account;
145150

146151
if( FD_LIKELY( condition != NULL ) ) {
147-
if( FD_UNLIKELY( !condition( *account, txn_out, ctx, i ) ) ) {
152+
if( FD_UNLIKELY( !condition( *account, txn_in, txn_out, ctx, i ) ) ) {
148153
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT;
149154
}
150155
}
@@ -203,12 +208,15 @@ fd_txn_account_has_bpf_loader_upgradeable( const fd_pubkey_t * account_keys,
203208
204209
https://github.com/anza-xyz/agave/blob/v2.1.11/sdk/program/src/message/sanitized.rs#L38-L47 */
205210
int
206-
fd_exec_txn_ctx_account_is_writable_idx( fd_txn_out_t const * txn_out, fd_exec_txn_ctx_t const * txn_ctx, ushort idx ) {
211+
fd_exec_txn_ctx_account_is_writable_idx( fd_txn_in_t const * txn_in,
212+
fd_txn_out_t const * txn_out,
213+
fd_exec_txn_ctx_t const * txn_ctx,
214+
ushort idx ) {
207215
uint bpf_upgradeable = fd_txn_account_has_bpf_loader_upgradeable( txn_out->accounts.account_keys, txn_out->accounts.accounts_cnt );
208216
return fd_exec_txn_account_is_writable_idx_flat( fd_bank_slot_get( txn_ctx->bank ),
209217
idx,
210218
&txn_out->accounts.account_keys[idx],
211-
TXN( &txn_ctx->txn ),
219+
TXN( &txn_in->txn ),
212220
fd_bank_features_query( txn_ctx->bank ),
213221
bpf_upgradeable );
214222
}
@@ -246,9 +254,11 @@ fd_exec_txn_account_is_writable_idx_flat( const ulong slot,
246254

247255
int
248256
fd_txn_account_check_exists( fd_txn_account_t * acc,
257+
fd_txn_in_t const * txn_in,
249258
fd_txn_out_t * txn_out,
250259
fd_exec_txn_ctx_t const * ctx,
251260
ushort idx ) {
261+
(void) txn_in;
252262
(void) txn_out;
253263
(void) ctx;
254264
(void) idx;
@@ -257,29 +267,34 @@ fd_txn_account_check_exists( fd_txn_account_t * acc,
257267

258268
int
259269
fd_txn_account_check_is_writable( fd_txn_account_t * acc,
270+
fd_txn_in_t const * txn_in,
260271
fd_txn_out_t * txn_out,
261272
fd_exec_txn_ctx_t const * ctx,
262273
ushort idx ) {
263274
(void) txn_out;
264275
(void) acc;
265-
return fd_exec_txn_ctx_account_is_writable_idx( txn_out, ctx, idx );
276+
return fd_exec_txn_ctx_account_is_writable_idx( txn_in, txn_out, ctx, idx );
266277
}
267278

268279
int
269280
fd_txn_account_check_fee_payer_writable( fd_txn_account_t * acc,
281+
fd_txn_in_t const * txn_in,
270282
fd_txn_out_t * txn_out,
271283
fd_exec_txn_ctx_t const * ctx,
272284
ushort idx ) {
285+
(void) ctx;
273286
(void) txn_out;
274287
(void) acc;
275-
return fd_txn_is_writable( TXN( &ctx->txn ), idx );
288+
return fd_txn_is_writable( TXN( &txn_in->txn ), idx );
276289
}
277290

278291
int
279292
fd_txn_account_check_borrow_mut( fd_txn_account_t * acc,
293+
fd_txn_in_t const * txn_in,
280294
fd_txn_out_t * txn_out,
281295
fd_exec_txn_ctx_t const * ctx,
282296
ushort idx ) {
297+
(void) txn_in;
283298
(void) txn_out;
284299
(void) ctx;
285300
(void) idx;

0 commit comments

Comments
 (0)