Skip to content

Commit c9e6e6c

Browse files
runtime: refactor pt 2
1 parent 3122ac4 commit c9e6e6c

File tree

92 files changed

+3269
-3276
lines changed

Some content is hidden

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

92 files changed

+3269
-3276
lines changed

contrib/test/run_unit_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -euo pipefail
88
JOBS=0
99
NUMA_IDX=0
1010
PAGE_SZ=gigantic
11-
JOB_MEM=$((1<<31)) # 2GiB
11+
JOB_MEM=$((1<<32)) # 4GiB
1212
PAGE_CNT=
1313
TESTS=
1414
VERBOSE=0

src/disco/bundle/fd_bundle_crank.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ fd_bundle_crank_gen_init( void * mem,
200200

201201
uint cerr[1];
202202
do {
203-
char seed[13] = "TIP_ACCOUNT_0"; /* Not NUL terminated */
203+
char seed[13];
204+
fd_memcpy( seed, "TIP_ACCOUNT_0", 13 ); /* Not NUL terminated */
204205
uchar const * seed_ptr[1] = { (uchar const *)seed };
205206
ulong seed_len = 13;
206207
for( ulong i=0UL; i<8UL; i++ ) {
@@ -213,7 +214,8 @@ fd_bundle_crank_gen_init( void * mem,
213214
} while( 0 );
214215

215216
do {
216-
char seed[14] = "CONFIG_ACCOUNT"; /* Not NUL terminated */
217+
char seed[14];
218+
fd_memcpy( seed, "CONFIG_ACCOUNT", 14 ); /* Not NUL terminated */
217219
ulong seed_len = 14;
218220
uchar out_bump[1];
219221
uchar const * seed_ptr[1] = { (uchar const *)seed };
@@ -265,10 +267,10 @@ fd_bundle_crank_update_epoch( fd_bundle_crank_gen_t * g,
265267
uchar vote_pubkey [32];
266268
ulong epoch;
267269
} seeds[1] = {{
268-
.tip_distr_acct = "TIP_DISTRIBUTION_ACCOUNT",
269-
.vote_pubkey = { EXPAND_ARR32( g->crank3->validator_vote_account, 0 ) },
270-
.epoch = epoch
270+
.vote_pubkey = { EXPAND_ARR32( g->crank3->validator_vote_account, 0 ) },
271+
.epoch = epoch
271272
}};
273+
memcpy( seeds->tip_distr_acct, "TIP_DISTRIBUTION_ACCOUNT", 24 );
272274
FD_STATIC_ASSERT( sizeof(seeds)==24UL+32UL+8UL, seed_struct );
273275
ulong seed_len = sizeof(seeds);
274276
uint custom_err[1];

src/discof/bank/fd_bank_tile.c

Lines changed: 73 additions & 60 deletions
Large diffs are not rendered by default.

src/discof/exec/fd_exec_tile.c

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
#include "../../util/pod/fd_pod_format.h"
55
#include "../../discof/replay/fd_exec.h"
6+
#include "../../flamenco/fd_flamenco.h"
67
#include "../../flamenco/runtime/context/fd_capture_ctx.h"
78
#include "../../flamenco/runtime/fd_bank.h"
8-
#include "../../flamenco/runtime/fd_exec_stack.h"
99
#include "../../flamenco/runtime/fd_runtime.h"
10+
#include "../../flamenco/progcache/fd_progcache_user.h"
11+
#include "../../flamenco/log_collector/fd_log_collector.h"
1012
#include "../../disco/metrics/fd_metrics.h"
1113

1214
#include "../../funk/fd_funk.h"
@@ -38,14 +40,6 @@ typedef struct fd_exec_tile_ctx {
3840
fd_sha512_t sha_mem[ FD_TXN_ACTUAL_SIG_MAX ];
3941
fd_sha512_t * sha_lj[ FD_TXN_ACTUAL_SIG_MAX ];
4042

41-
/* Data structures related to managing and executing the transaction.
42-
The fd_txn_p_t is refreshed with every transaction and is sent
43-
from the dispatch/replay tile. The fd_exec_txn_ctx_t * is a valid
44-
local join that lives in the top-most frame of the spad that is
45-
setup when the exec tile is booted; its members are refreshed on
46-
the slot/epoch boundary. */
47-
fd_exec_txn_ctx_t txn_ctx[1];
48-
4943
/* Capture context for debugging runtime execution. */
5044
fd_capture_ctx_t * capture_ctx;
5145
uchar * solcap_publish_buffer_ptr;
@@ -67,8 +61,13 @@ typedef struct fd_exec_tile_ctx {
6761
ulong slot;
6862
ulong dispatch_time_comp;
6963

70-
fd_exec_stack_t exec_stack;
7164
fd_exec_accounts_t exec_accounts;
65+
fd_log_collector_t log_collector;
66+
67+
fd_bank_t * bank;
68+
69+
fd_txn_in_t txn_in;
70+
fd_txn_out_t txn_out;
7271

7372
/* tracing_mem is staging memory to dump instructions/transactions
7473
into protobuf files. tracing_mem is staging memory to output vm
@@ -77,6 +76,8 @@ typedef struct fd_exec_tile_ctx {
7776
uchar dumping_mem[ FD_SPAD_FOOTPRINT( 1UL<<28UL ) ] __attribute__((aligned(FD_SPAD_ALIGN)));
7877
uchar tracing_mem[ FD_MAX_INSTRUCTION_STACK_DEPTH ][ FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT ] __attribute__((aligned(FD_RUNTIME_VM_TRACE_STATIC_ALIGN)));
7978

79+
fd_runtime_t runtime;
80+
8081
} fd_exec_tile_ctx_t;
8182

8283
FD_FN_CONST static inline ulong
@@ -127,37 +128,32 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
127128
case FD_EXEC_TT_TXN_EXEC: {
128129
/* Execute. */
129130
fd_exec_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
130-
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
131-
FD_TEST( bank );
132-
ctx->txn_ctx->err.exec_err = fd_runtime_prepare_and_execute_txn( bank,
133-
ctx->txn_ctx,
134-
&msg->txn,
135-
ctx->capture_ctx,
136-
&ctx->exec_stack,
137-
&ctx->exec_accounts,
138-
ctx->dumping_mem,
139-
&ctx->tracing_mem[0][0] );
131+
ctx->bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
132+
FD_TEST( ctx->bank );
133+
ctx->txn_in.txn = &msg->txn;
134+
ctx->txn_in.exec_accounts = &ctx->exec_accounts;
135+
136+
fd_runtime_prepare_and_execute_txn( &ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
140137

141138
/* Commit. */
142-
if( FD_LIKELY( ctx->txn_ctx->err.is_committable ) ) {
143-
fd_funk_txn_xid_t xid = (fd_funk_txn_xid_t){ .ul = { fd_bank_slot_get( bank ), bank->idx } };
144-
fd_runtime_finalize_txn( ctx->funk, ctx->progcache, ctx->txncache, &xid, ctx->txn_ctx, bank, ctx->capture_ctx, NULL );
139+
if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
140+
fd_runtime_commit_txn( &ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
145141
}
146142

147143
if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
148144
/* Copy the txn signature to the signature out link so the
149145
dedup/pack tiles can drop already executed transactions. */
150146
memcpy( fd_chunk_to_laddr( ctx->exec_sig_out->mem, ctx->exec_sig_out->chunk ),
151-
(uchar *)ctx->txn_ctx->txn.payload + TXN( &ctx->txn_ctx->txn )->signature_off,
147+
(uchar *)ctx->txn_in.txn->payload + TXN( ctx->txn_in.txn )->signature_off,
152148
64UL );
153149
fd_stem_publish( stem, ctx->exec_sig_out->idx, 0UL, ctx->exec_sig_out->chunk, 64UL, 0UL, 0UL, 0UL );
154150
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 );
155151
}
156152

157153
/* Notify replay. */
158-
ctx->txn_idx = msg->txn_idx;
159-
ctx->dispatch_time_comp = tspub;
160-
ctx->slot = fd_bank_slot_get( bank );
154+
ctx->txn_idx = msg->txn_idx;
155+
ctx->dispatch_time_comp = tspub;
156+
ctx->slot = fd_bank_slot_get( ctx->bank );
161157
ctx->pending_txn_finalized_msg = 1;
162158

163159
break;
@@ -274,21 +270,7 @@ unprivileged_init( fd_topo_t * topo,
274270
ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem ) );
275271
FD_TEST( ctx->txncache );
276272

277-
/********************************************************************/
278-
/* setup txn ctx */
279-
/********************************************************************/
280-
281-
FD_TEST( fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( ctx->txn_ctx ) ) );
282-
283-
if( FD_UNLIKELY( !fd_funk_join( ctx->txn_ctx->funk, shfunk ) ) ) {
284-
FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
285-
}
286-
ctx->txn_ctx->progcache = fd_progcache_join( ctx->txn_ctx->_progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT );
287-
if( FD_UNLIKELY( !ctx->txn_ctx->progcache ) ) {
288-
FD_LOG_CRIT(( "fd_progcache_join() failed" ));
289-
}
290-
ctx->txn_ctx->status_cache = ctx->txncache;
291-
ctx->txn_ctx->bundle.is_bundle = 0;
273+
ctx->txn_in.bundle.is_bundle = 0;
292274

293275
/********************************************************************/
294276
/* Capture context */
@@ -318,6 +300,22 @@ unprivileged_init( fd_topo_t * topo,
318300
}
319301

320302
ctx->pending_txn_finalized_msg = 0;
303+
304+
/********************************************************************/
305+
/* Runtime */
306+
/********************************************************************/
307+
308+
ctx->runtime = (fd_runtime_t) {
309+
.funk = ctx->funk,
310+
.status_cache = ctx->txncache,
311+
.progcache = ctx->progcache,
312+
.log = {
313+
.dumping_mem = ctx->dumping_mem,
314+
.tracing_mem = &ctx->tracing_mem[0][0],
315+
.log_collector = &ctx->log_collector,
316+
.capture_ctx = ctx->capture_ctx,
317+
}
318+
};
321319
}
322320

323321
/* Publish the next account update event buffered in the capture tile to the replay tile
@@ -370,14 +368,14 @@ static void
370368
publish_txn_finalized_msg( fd_exec_tile_ctx_t * ctx,
371369
fd_stem_context_t * stem ) {
372370
fd_exec_task_done_msg_t * msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
373-
msg->bank_idx = ctx->txn_ctx->bank->idx;
371+
msg->bank_idx = ctx->bank->idx;
374372
msg->txn_exec->txn_idx = ctx->txn_idx;
375-
msg->txn_exec->err = !ctx->txn_ctx->err.is_committable;
373+
msg->txn_exec->err = !ctx->txn_out.err.is_committable;
376374
msg->txn_exec->slot = ctx->slot;
377-
msg->txn_exec->start_shred_idx = ctx->txn_ctx->txn.start_shred_idx;
378-
msg->txn_exec->end_shred_idx = ctx->txn_ctx->txn.end_shred_idx;
375+
msg->txn_exec->start_shred_idx = ctx->txn_in.txn->start_shred_idx;
376+
msg->txn_exec->end_shred_idx = ctx->txn_in.txn->end_shred_idx;
379377
if( FD_UNLIKELY( msg->txn_exec->err ) ) {
380-
FD_LOG_WARNING(( "txn failed to execute, bad block detected err=%d", ctx->txn_ctx->err.txn_err ));
378+
FD_LOG_WARNING(( "txn failed to execute, bad block detected err=%d", ctx->txn_out.err.txn_err ));
381379
}
382380

383381
fd_stem_publish( stem, ctx->exec_replay_out->idx, (FD_EXEC_TT_TXN_EXEC<<32)|ctx->tile_idx, ctx->exec_replay_out->chunk, sizeof(*msg), 0UL, ctx->dispatch_time_comp, fd_frag_meta_ts_comp( fd_tickcount() ) );

src/discof/replay/fd_replay_tile.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "../../flamenco/runtime/tests/fd_dump_pb.h"
3636

3737
#include <errno.h>
38+
#include <stdio.h>
3839

3940
/* Replay concepts:
4041
@@ -615,17 +616,9 @@ replay_block_start( fd_replay_tile_t * ctx,
615616
}
616617

617618
int is_epoch_boundary = 0;
618-
fd_runtime_block_pre_execute_process_new_epoch(
619-
ctx->banks,
620-
bank,
621-
ctx->accdb,
622-
&xid,
623-
ctx->capture_ctx,
624-
&ctx->runtime_stack,
625-
&is_epoch_boundary );
619+
fd_runtime_block_execute_prepare( ctx->banks, bank, ctx->accdb, &ctx->runtime_stack, ctx->capture_ctx, &is_epoch_boundary );
626620
if( FD_UNLIKELY( is_epoch_boundary ) ) publish_stake_weights( ctx, stem, bank, 1 );
627621

628-
FD_TEST( !fd_runtime_block_execute_prepare( bank, ctx->accdb, &xid, &ctx->runtime_stack, ctx->capture_ctx ) );
629622
return bank;
630623
}
631624

@@ -753,9 +746,6 @@ replay_block_finalize( fd_replay_tile_t * ctx,
753746

754747
FD_TEST( !(bank->flags&FD_BANK_FLAGS_FROZEN) );
755748

756-
ulong slot = fd_bank_slot_get( bank );
757-
fd_funk_txn_xid_t xid = { .ul = { slot, bank->idx } };
758-
759749
/* Set poh hash in bank. */
760750
fd_hash_t * poh = fd_sched_get_poh( ctx->sched, bank->idx );
761751
fd_bank_poh_set( bank, *poh );
@@ -764,13 +754,15 @@ replay_block_finalize( fd_replay_tile_t * ctx,
764754
fd_bank_shred_cnt_set( bank, fd_sched_get_shred_cnt( ctx->sched, bank->idx ) );
765755

766756
/* Do hashing and other end-of-block processing. */
767-
fd_runtime_block_execute_finalize( bank, ctx->accdb, &xid, ctx->capture_ctx, 1 );
757+
fd_runtime_block_execute_finalize( bank, ctx->accdb, ctx->capture_ctx );
768758

769759
/* Copy out cost tracker fields before freezing */
770760
fd_replay_slot_completed_t * slot_info = fd_chunk_to_laddr( ctx->replay_out->mem, ctx->replay_out->chunk );
771761
cost_tracker_snap( bank, slot_info );
772762

773763
/* fetch identity / vote balance updates infrequently */
764+
ulong slot = fd_bank_slot_get( bank );
765+
fd_funk_txn_xid_t xid = { .ul = { slot, bank->idx } };
774766
slot_info->identity_balance = FD_UNLIKELY( slot%4096==0UL ) ? get_identity_balance( ctx, xid ) : ULONG_MAX;
775767

776768
/* Mark the bank as frozen. */
@@ -863,18 +855,9 @@ prepare_leader_bank( fd_replay_tile_t * ctx,
863855
}
864856

865857
int is_epoch_boundary = 0;
866-
fd_runtime_block_pre_execute_process_new_epoch(
867-
ctx->banks,
868-
ctx->leader_bank,
869-
ctx->accdb,
870-
&xid,
871-
ctx->capture_ctx,
872-
&ctx->runtime_stack,
873-
&is_epoch_boundary );
858+
fd_runtime_block_execute_prepare( ctx->banks, ctx->leader_bank, ctx->accdb, &ctx->runtime_stack, ctx->capture_ctx, &is_epoch_boundary );
874859
if( FD_UNLIKELY( is_epoch_boundary ) ) publish_stake_weights( ctx, stem, ctx->leader_bank, 1 );
875860

876-
FD_TEST( !fd_runtime_block_execute_prepare( ctx->leader_bank, ctx->accdb, &xid, &ctx->runtime_stack, ctx->capture_ctx ) );
877-
878861
/* Now that a bank has been created for the leader slot, increment the
879862
reference count until we are done with the leader slot. */
880863
ctx->leader_bank->refcnt++;
@@ -902,12 +885,12 @@ fini_leader_bank( fd_replay_tile_t * ctx,
902885
if( FD_UNLIKELY( !txn_map->map ) ) {
903886
FD_LOG_ERR(( "Could not find valid funk transaction map" ));
904887
}
905-
fd_funk_txn_xid_t xid = { .ul = { curr_slot, ctx->leader_bank->idx } };
906888

907-
fd_runtime_block_execute_finalize( ctx->leader_bank, ctx->accdb, &xid, ctx->capture_ctx, 1 );
889+
fd_runtime_block_execute_finalize( ctx->leader_bank, ctx->accdb, ctx->capture_ctx );
908890

909891
fd_replay_slot_completed_t * slot_info = fd_chunk_to_laddr( ctx->replay_out->mem, ctx->replay_out->chunk );
910892
cost_tracker_snap( ctx->leader_bank, slot_info );
893+
fd_funk_txn_xid_t xid = { .ul = { curr_slot, ctx->leader_bank->idx } };
911894
slot_info->identity_balance = FD_UNLIKELY( curr_slot%4096==0UL ) ? get_identity_balance( ctx, xid ) : ULONG_MAX;
912895

913896
fd_banks_mark_bank_frozen( ctx->banks, ctx->leader_bank );
@@ -1043,8 +1026,10 @@ init_after_snapshot( fd_replay_tile_t * ctx ) {
10431026
fd_sha256_hash( poh->hash, 32UL, poh->hash );
10441027
}
10451028

1046-
FD_TEST( !fd_runtime_block_execute_prepare( bank, ctx->accdb, &xid, &ctx->runtime_stack, ctx->capture_ctx ) );
1047-
fd_runtime_block_execute_finalize( bank, ctx->accdb, &xid, ctx->capture_ctx, 1 );
1029+
int is_epoch_boundary = 0;
1030+
fd_runtime_block_execute_prepare( ctx->banks, bank, ctx->accdb, &ctx->runtime_stack, ctx->capture_ctx, &is_epoch_boundary );
1031+
FD_TEST( !is_epoch_boundary );
1032+
fd_runtime_block_execute_finalize( bank, ctx->accdb, ctx->capture_ctx );
10481033

10491034
snapshot_slot = 0UL;
10501035
}

src/flamenco/fd_flamenco_base.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ typedef struct fd_bank fd_bank_t;
6767
struct fd_banks;
6868
typedef struct fd_banks fd_banks_t;
6969

70-
struct fd_exec_txn_ctx;
71-
typedef struct fd_exec_txn_ctx fd_exec_txn_ctx_t;
72-
7370
struct fd_exec_instr_ctx;
7471
typedef struct fd_exec_instr_ctx fd_exec_instr_ctx_t;
7572

@@ -97,8 +94,17 @@ typedef struct fd_progcache fd_progcache_t;
9794
union fd_runtime_stack;
9895
typedef union fd_runtime_stack fd_runtime_stack_t;
9996

100-
struct fd_exec_stack;
101-
typedef struct fd_exec_stack fd_exec_stack_t;
97+
struct fd_runtime;
98+
typedef struct fd_runtime fd_runtime_t;
99+
100+
struct fd_txn_in;
101+
typedef struct fd_txn_in fd_txn_in_t;
102+
103+
struct fd_txn_out;
104+
typedef struct fd_txn_out fd_txn_out_t;
105+
106+
struct fd_log_collector;
107+
typedef struct fd_log_collector fd_log_collector_t;
102108

103109
struct fd_account_meta {
104110
uchar owner[32];
@@ -110,15 +116,6 @@ struct fd_account_meta {
110116
};
111117
typedef struct fd_account_meta fd_account_meta_t;
112118

113-
/* fd_rawtxn_b_t is a convenience type to store a pointer to a
114-
serialized transaction. Should probably be removed in the future. */
115-
116-
struct fd_rawtxn_b {
117-
void * raw;
118-
ushort txn_sz;
119-
};
120-
typedef struct fd_rawtxn_b fd_rawtxn_b_t;
121-
122119
FD_PROTOTYPES_BEGIN
123120

124121
/* fd_acct_addr_cstr converts the given Solana address into a base58-

0 commit comments

Comments
 (0)