Skip to content

Commit 6e4d6df

Browse files
removing more
1 parent 53b8308 commit 6e4d6df

File tree

4 files changed

+26
-156
lines changed

4 files changed

+26
-156
lines changed

src/flamenco/runtime/context/fd_exec_slot_ctx.c

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -94,46 +94,6 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx,
9494
fd_vote_accounts_pair_global_t_mapnode_t * manifest_vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( manifest_vote_accounts );
9595
fd_vote_accounts_pair_global_t_mapnode_t * manifest_vote_accounts_root = fd_vote_accounts_vote_accounts_root_join( manifest_vote_accounts );
9696

97-
fd_vote_accounts_global_t * curr_epoch_stakes = fd_bank_curr_epoch_stakes_locking_modify( slot_ctx->bank );
98-
uchar * curr_epoch_stakes_pool_mem = (uchar *)fd_ulong_align_up( (ulong)curr_epoch_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() );
99-
fd_vote_accounts_pair_global_t_mapnode_t * curr_epoch_stakes_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( curr_epoch_stakes_pool_mem, 50000UL ) );
100-
fd_vote_accounts_pair_global_t_mapnode_t * curr_epoch_stakes_root = NULL;
101-
uchar * acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)curr_epoch_stakes_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL );
102-
103-
for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum( manifest_vote_accounts_pool, manifest_vote_accounts_root );
104-
n;
105-
n = fd_vote_accounts_pair_global_t_map_successor( manifest_vote_accounts_pool, n ) ) {
106-
107-
fd_vote_accounts_pair_global_t_mapnode_t * elem = fd_vote_accounts_pair_global_t_map_acquire( curr_epoch_stakes_pool );
108-
FD_TEST( elem );
109-
110-
elem->elem.stake = n->elem.stake;
111-
elem->elem.key = n->elem.key;
112-
113-
elem->elem.value.lamports = n->elem.value.lamports;
114-
elem->elem.value.data_len = 0UL;
115-
elem->elem.value.data_offset = 0UL;
116-
elem->elem.value.owner = n->elem.value.owner;
117-
elem->elem.value.executable = n->elem.value.executable;
118-
elem->elem.value.rent_epoch = n->elem.value.rent_epoch;
119-
120-
elem->elem.value.data_offset = (ulong)(acc_region_curr - (uchar *)&elem->elem.value);;
121-
elem->elem.value.data_len = n->elem.value.data_len;
122-
123-
uchar * manifest_data = fd_solana_account_data_join( &n->elem.value );
124-
memcpy( acc_region_curr, manifest_data, n->elem.value.data_len );
125-
acc_region_curr += n->elem.value.data_len;
126-
127-
fd_vote_accounts_pair_global_t_map_insert(
128-
curr_epoch_stakes_pool,
129-
&curr_epoch_stakes_root,
130-
elem );
131-
}
132-
133-
fd_vote_accounts_vote_accounts_pool_update( curr_epoch_stakes, curr_epoch_stakes_pool );
134-
fd_vote_accounts_vote_accounts_root_update( curr_epoch_stakes, curr_epoch_stakes_root );
135-
fd_bank_curr_epoch_stakes_end_locking_modify( slot_ctx->bank );
136-
13797
fd_bank_epoch_set( slot_ctx->bank, manifest->bank.epoch );
13898

13999
/* Move EpochStakes */
@@ -217,7 +177,7 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx,
217177
fd_vote_accounts_pair_global_t_mapnode_t * pool = vote_accounts_next_stakes_pool;
218178
fd_vote_accounts_pair_global_t_mapnode_t * root = vote_accounts_next_stakes_root;
219179

220-
acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL );
180+
uchar * acc_region_curr = (uchar *)fd_ulong_align_up( (ulong)next_epoch_stakes_pool + fd_vote_accounts_pair_global_t_map_footprint( 50000UL ), 8UL );
221181

222182
for( fd_vote_accounts_pair_global_t_mapnode_t * n = fd_vote_accounts_pair_global_t_map_minimum( pool, root );
223183
n;

src/flamenco/runtime/fd_bank.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ FD_PROTOTYPES_BEGIN
185185
/* in epoch E, these are the stakes at the end of epoch */ \
186186
/* E-1 and they determined the leader schedule for epoch */ \
187187
/* E+1. */ \
188-
X(fd_vote_accounts_global_t, curr_epoch_stakes, 200000000UL, 128UL, 1, 0, 1 ) /* Stakes being accumulated in current epoch */ \
189188
X(fd_epoch_rewards_t, epoch_rewards, FD_EPOCH_REWARDS_FOOTPRINT, FD_EPOCH_REWARDS_ALIGN, 1, 1, 1 ) /* Epoch rewards */ \
190189
X(fd_epoch_leaders_t, epoch_leaders, FD_RUNTIME_MAX_EPOCH_LEADERS, FD_EPOCH_LEADERS_ALIGN, 1, 1, 1 ) /* Epoch leaders. If our system supports 100k vote accs, */ \
191190
/* then there can be 100k unique leaders in the worst */ \
@@ -258,10 +257,6 @@ FD_PROTOTYPES_BEGIN
258257
#define POOL_T fd_bank_stake_delegations_t
259258
#include "../../util/tmpl/fd_pool.c"
260259

261-
#define POOL_NAME fd_bank_curr_epoch_stakes_pool
262-
#define POOL_T fd_bank_curr_epoch_stakes_t
263-
#include "../../util/tmpl/fd_pool.c"
264-
265260
#define POOL_NAME fd_bank_vote_states_pool
266261
#define POOL_T fd_bank_vote_states_t
267262
#include "../../util/tmpl/fd_pool.c"

src/flamenco/runtime/fd_runtime.c

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,22 +1373,6 @@ fd_update_epoch_stakes( fd_exec_slot_ctx_t * slot_ctx ) {
13731373
static void
13741374
fd_update_next_epoch_stakes( fd_exec_slot_ctx_t * slot_ctx ) {
13751375

1376-
/* FIXME: This is technically not correct, since the vote accounts
1377-
could be laid out after the stake delegations from fd_stakes.
1378-
The correct solution is to split out the stake delgations from the
1379-
vote accounts in fd_stakes. */
1380-
1381-
/* Copy stakes->vote_accounts into next_epoch_stakes */
1382-
fd_vote_accounts_global_t const * vote_stakes = fd_bank_curr_epoch_stakes_locking_query( slot_ctx->bank );
1383-
1384-
fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify( slot_ctx->bank );
1385-
fd_memcpy( next_epoch_stakes, vote_stakes, fd_bank_next_epoch_stakes_footprint );
1386-
fd_bank_next_epoch_stakes_end_locking_modify( slot_ctx->bank );
1387-
1388-
fd_bank_curr_epoch_stakes_end_locking_query( slot_ctx->bank );
1389-
1390-
/********************************************************************/
1391-
13921376
fd_vote_states_t * vote_states_prev = fd_bank_vote_states_prev_locking_modify( slot_ctx->bank );
13931377
fd_vote_states_t const * vote_states = fd_bank_vote_states_locking_query( slot_ctx->bank );
13941378
fd_memcpy( vote_states_prev, vote_states, fd_bank_vote_states_footprint );
@@ -2184,10 +2168,8 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
21842168
fd_stake_delegations_t * stake_delegations = fd_stake_delegations_join( fd_stake_delegations_new( fd_bank_stake_delegations_locking_modify( slot_ctx->bank ), 5000UL ) );
21852169
FD_TEST( stake_delegations );
21862170

2187-
fd_vote_accounts_global_t * vote_accounts = fd_bank_curr_epoch_stakes_locking_modify( slot_ctx->bank );
2188-
uchar * vacc_pool_mem = (uchar *)fd_ulong_align_up( (ulong)vote_accounts + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() );
2189-
fd_vote_accounts_pair_global_t_mapnode_t * vacc_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( vacc_pool_mem, 5000UL ) );
2190-
fd_vote_accounts_pair_global_t_mapnode_t * vacc_root = NULL;
2171+
fd_vote_states_t * vote_states = fd_vote_states_join( fd_vote_states_new( fd_bank_vote_states_locking_modify( slot_ctx->bank ), 5000UL ) );
2172+
FD_TEST( vote_states );
21912173

21922174
fd_acc_lamports_t capitalization = 0UL;
21932175

@@ -2200,27 +2182,8 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
22002182
capitalization = fd_ulong_sat_add( capitalization, acc->account.lamports );
22012183

22022184
if( !memcmp(acc->account.owner.key, fd_solana_vote_program_id.key, sizeof(fd_pubkey_t)) ) {
2203-
/* Vote Program Account */
2204-
fd_vote_accounts_pair_global_t_mapnode_t * node = fd_vote_accounts_pair_global_t_map_acquire(vacc_pool);
2205-
FD_TEST( node );
2206-
2207-
fd_memcpy(node->elem.key.key, acc->key.key, sizeof(fd_pubkey_t));
2208-
node->elem.stake = acc->account.lamports;
2209-
node->elem.value = (fd_solana_account_global_t){
2210-
.lamports = acc->account.lamports,
2211-
.data_len = acc->account.data_len,
2212-
.data_offset = 0UL, /* FIXME: remove this field from the cache altogether. */
2213-
.owner = acc->account.owner,
2214-
.executable = acc->account.executable,
2215-
.rent_epoch = acc->account.rent_epoch
2216-
};
2217-
fd_solana_account_data_update( &node->elem.value, acc->account.data );
2218-
2219-
fd_vote_accounts_pair_global_t_map_insert( vacc_pool, &vacc_root, node );
2220-
2221-
FD_LOG_INFO(( "Adding genesis vote account: key=%s stake=%lu",
2222-
FD_BASE58_ENC_32_ALLOCA( node->elem.key.key ),
2223-
node->elem.stake ));
2185+
2186+
fd_vote_states_update_from_account( vote_states, &acc->key, acc->account.data, acc->account.data_len );
22242187
} else if( !memcmp( acc->account.owner.key, fd_solana_stake_program_id.key, sizeof(fd_pubkey_t) ) ) {
22252188
FD_SPAD_FRAME_BEGIN( runtime_spad ) {
22262189

@@ -2305,7 +2268,6 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
23052268
fd_vote_states_update_from_account( vote_states_prev_prev, &acc->key, acc->account.data, acc->account.data_len );
23062269
fd_vote_states_update_from_account( vote_states_prev, &acc->key, acc->account.data, acc->account.data_len );
23072270
}
2308-
23092271
}
23102272

23112273
fd_bank_vote_states_prev_prev_end_locking_modify( slot_ctx->bank );
@@ -2314,9 +2276,7 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
23142276

23152277
fd_bank_epoch_set( slot_ctx->bank, 0UL );
23162278

2317-
fd_vote_accounts_vote_accounts_pool_update( vote_accounts, vacc_pool );
2318-
fd_vote_accounts_vote_accounts_root_update( vote_accounts, vacc_root );
2319-
fd_bank_curr_epoch_stakes_end_locking_modify( slot_ctx->bank );
2279+
fd_bank_vote_states_end_locking_modify( slot_ctx->bank );
23202280

23212281
fd_bank_stake_delegations_end_locking_modify( slot_ctx->bank );
23222282

src/flamenco/runtime/tests/harness/fd_block_harness.c

Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
/* Stripped down version of `fd_refresh_vote_accounts()` that simply refreshes the stake delegation amount
55
for each of the vote accounts using the stake delegations cache. */
66
static void
7-
fd_runtime_fuzz_block_refresh_vote_accounts( fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool,
8-
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root,
9-
fd_vote_states_t * vote_states,
10-
fd_stake_delegations_t * stake_delegations ) {
7+
fd_runtime_fuzz_block_refresh_vote_accounts( fd_vote_states_t * vote_states,
8+
fd_stake_delegations_t * stake_delegations ) {
119
fd_stake_delegation_map_t * map = fd_stake_delegations_get_map( stake_delegations );
1210
fd_stake_delegation_t * pool = fd_stake_delegations_get_pool( stake_delegations );
1311

@@ -20,12 +18,6 @@ fd_runtime_fuzz_block_refresh_vote_accounts( fd_vote_accounts_pair_global_t_mapn
2018
ulong stake = node->stake;
2119

2220
/* Find the voter in the vote accounts cache and update their delegation amount */
23-
fd_vote_accounts_pair_global_t_mapnode_t vode_node[1];
24-
fd_memcpy( vode_node->elem.key.uc, voter_pubkey, sizeof(fd_pubkey_t) );
25-
fd_vote_accounts_pair_global_t_mapnode_t * found_node = fd_vote_accounts_pair_global_t_map_find( vote_accounts_pool, vote_accounts_root, vode_node );
26-
if( FD_LIKELY( found_node ) ) {
27-
found_node->elem.stake += stake;
28-
}
2921
fd_vote_state_ele_t * vote_state = fd_vote_states_query( vote_states, voter_pubkey );
3022
ulong vote_stake = vote_state->stake;
3123
fd_vote_states_update_stake( vote_states, voter_pubkey, vote_stake + stake );
@@ -37,12 +29,10 @@ fd_runtime_fuzz_block_refresh_vote_accounts( fd_vote_accounts_pair_global_t_mapn
3729
from the current present account state. This function also registers a vote timestamp
3830
for the vote account */
3931
static void
40-
fd_runtime_fuzz_block_register_vote_account( fd_exec_slot_ctx_t * slot_ctx,
41-
fd_vote_states_t * vote_states,
42-
fd_vote_accounts_pair_global_t_mapnode_t * pool,
43-
fd_vote_accounts_pair_global_t_mapnode_t ** root,
44-
fd_pubkey_t * pubkey,
45-
fd_spad_t * spad ) {
32+
fd_runtime_fuzz_block_register_vote_account( fd_exec_slot_ctx_t * slot_ctx,
33+
fd_vote_states_t * vote_states,
34+
fd_pubkey_t * pubkey,
35+
fd_spad_t * spad ) {
4636
FD_TXN_ACCOUNT_DECL( acc );
4737
if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( acc, pubkey, slot_ctx->funk, slot_ctx->funk_txn ) ) ) {
4838
return;
@@ -70,32 +60,11 @@ fd_runtime_fuzz_block_register_vote_account( fd_exec_slot_ctx_t *
7060
return;
7161
}
7262

73-
/* Nothing to do if the account already exists in the cache */
74-
fd_vote_accounts_pair_global_t_mapnode_t existing_node[1];
75-
fd_memcpy( existing_node->elem.key.uc, pubkey, sizeof(fd_pubkey_t) );
76-
if( fd_vote_accounts_pair_global_t_map_find( pool, *root, existing_node ) ) {
77-
return;
78-
}
79-
80-
/* At this point, the node is new and needs to be inserted into the cache. */
81-
fd_vote_accounts_pair_global_t_mapnode_t * node_to_insert = fd_vote_accounts_pair_global_t_map_acquire( pool );
82-
fd_memcpy( node_to_insert->elem.key.uc, pubkey, sizeof(fd_pubkey_t) );
83-
84-
ulong account_dlen = fd_txn_account_get_data_len( acc );
85-
node_to_insert->elem.stake = 0UL; // This will get set later
86-
node_to_insert->elem.value.executable = !!fd_txn_account_is_executable( acc );
87-
node_to_insert->elem.value.lamports = fd_txn_account_get_lamports( acc );
88-
node_to_insert->elem.value.rent_epoch = fd_txn_account_get_rent_epoch( acc );
89-
node_to_insert->elem.value.data_len = account_dlen;
90-
91-
uchar * data = fd_spad_alloc( spad, alignof(uchar), account_dlen );
92-
memcpy( data, fd_txn_account_get_data( acc ), account_dlen );
93-
fd_solana_account_data_update( &node_to_insert->elem.value, data );
94-
95-
fd_vote_accounts_pair_global_t_map_insert( pool, root, node_to_insert );
96-
97-
fd_vote_states_update_from_account( vote_states, pubkey, data, account_dlen );
98-
fd_vote_states_update_stake( vote_states, pubkey, node_to_insert->elem.stake );
63+
fd_vote_states_update_from_account(
64+
vote_states,
65+
acc->pubkey,
66+
fd_txn_account_get_data( acc ),
67+
fd_txn_account_get_data_len( acc ) );
9968
}
10069

10170
/* Stores an entry in the stake delegations cache for the given vote account. Deserializes and uses the present
@@ -285,11 +254,6 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
285254
vote_states_prev_prev = fd_vote_states_join( fd_vote_states_new( vote_states_prev_prev, FD_RUNTIME_MAX_VOTE_ACCOUNTS ) );
286255
fd_bank_vote_states_prev_prev_end_locking_modify( slot_ctx->bank );
287256

288-
fd_vote_accounts_global_t * curr_stakes = fd_bank_curr_epoch_stakes_locking_modify( slot_ctx->bank );
289-
uchar * pool_mem = (uchar *)fd_ulong_align_up( (ulong)curr_stakes + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_t_map_align() );
290-
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, vote_acct_max ) );
291-
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = NULL;
292-
293257
fd_stake_delegations_t * stake_delegations = fd_bank_stake_delegations_locking_modify( slot_ctx->bank );
294258
stake_delegations = fd_stake_delegations_join( fd_stake_delegations_new( stake_delegations, FD_RUNTIME_MAX_STAKE_ACCOUNTS ) );
295259

@@ -302,12 +266,11 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
302266
/* Update vote accounts cache for epoch T */
303267
fd_pubkey_t pubkey;
304268
memcpy( &pubkey, test_ctx->acct_states[i].address, sizeof(fd_pubkey_t) );
305-
fd_runtime_fuzz_block_register_vote_account( slot_ctx,
306-
vote_states,
307-
vote_accounts_pool,
308-
&vote_accounts_root,
309-
&pubkey,
310-
runner->spad );
269+
fd_runtime_fuzz_block_register_vote_account(
270+
slot_ctx,
271+
vote_states,
272+
&pubkey,
273+
runner->spad );
311274

312275
/* Update the stake delegations cache for epoch T */
313276
fd_runtime_fuzz_block_register_stake_delegation( slot_ctx,
@@ -316,17 +279,9 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
316279
}
317280

318281
/* Refresh vote accounts to calculate stake delegations */
319-
fd_runtime_fuzz_block_refresh_vote_accounts( vote_accounts_pool,
320-
vote_accounts_root,
321-
vote_states,
322-
stake_delegations );
282+
fd_runtime_fuzz_block_refresh_vote_accounts( vote_states, stake_delegations );
323283
fd_bank_vote_states_end_locking_modify( slot_ctx->bank );
324284

325-
326-
fd_vote_accounts_vote_accounts_pool_update( curr_stakes, vote_accounts_pool );
327-
fd_vote_accounts_vote_accounts_root_update( curr_stakes, vote_accounts_root );
328-
329-
fd_bank_curr_epoch_stakes_end_locking_modify( slot_ctx->bank );
330285
fd_bank_stake_delegations_end_locking_modify( slot_ctx->bank );
331286

332287
/* Finish init epoch bank sysvars */
@@ -344,9 +299,9 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
344299
fd_runtime_fuzz_refresh_program_cache( slot_ctx, test_ctx->acct_states, test_ctx->acct_states_count, runner->spad );
345300

346301
fd_vote_accounts_global_t * vote_accounts = fd_bank_next_epoch_stakes_locking_modify( slot_ctx->bank );
347-
pool_mem = (uchar *)fd_ulong_align_up( (ulong)vote_accounts + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() );
348-
vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, vote_acct_max ) );
349-
vote_accounts_root = NULL;
302+
uchar * pool_mem = (uchar *)fd_ulong_align_up( (ulong)vote_accounts + sizeof(fd_vote_accounts_global_t), fd_vote_accounts_pair_global_t_map_align() );
303+
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_pair_global_t_map_join( fd_vote_accounts_pair_global_t_map_new( pool_mem, vote_acct_max ) );
304+
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = NULL;
350305

351306
/* Update vote cache for epoch T-1 */
352307
vote_states_prev = fd_bank_vote_states_prev_locking_modify( slot_ctx->bank );

0 commit comments

Comments
 (0)