Skip to content

Commit b76f293

Browse files
two-heartripatel-fd
authored andcommitted
chore: turn memcpys to assignments where possible
1 parent a45a011 commit b76f293

25 files changed

+130
-128
lines changed

src/choreo/forks/fd_forks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ slot_ctx_restore( ulong slot,
245245
continue;
246246
}
247247

248-
fd_memcpy( &slot_ctx_out->slot_bank, slot_bank, sizeof(fd_slot_bank_t) );
248+
slot_ctx_out->slot_bank = *slot_bank;
249249
FD_TEST( !fd_runtime_sysvar_cache_load( slot_ctx_out, runtime_spad ) );
250250

251251
if( FD_LIKELY( fd_funk_rec_query_test( query ) == FD_FUNK_SUCCESS ) ) {

src/disco/gui/fd_gui.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ fd_gui_poll( fd_gui_t * gui ) {
514514
fd_gui_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
515515
fd_http_server_ws_broadcast( gui->http );
516516

517-
memcpy( gui->summary.tile_stats_reference, gui->summary.tile_stats_current, sizeof(struct fd_gui_tile_stats) );
517+
*gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
518518
fd_gui_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current );
519519
fd_gui_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
520520
fd_http_server_ws_broadcast( gui->http );
@@ -566,7 +566,7 @@ fd_gui_handle_gossip_update( fd_gui_t * gui,
566566
if( FD_UNLIKELY( !found ) ) {
567567
fd_memcpy( removed[ removed_cnt++ ].uc, gui->gossip.peers[ i ].pubkey->uc, 32UL );
568568
if( FD_LIKELY( i+1UL!=gui->gossip.peer_cnt ) ) {
569-
fd_memcpy( &gui->gossip.peers[ i ], &gui->gossip.peers[ gui->gossip.peer_cnt-1UL ], sizeof(struct fd_gui_gossip_peer) );
569+
gui->gossip.peers[ i ] = gui->gossip.peers[ gui->gossip.peer_cnt-1UL ];
570570
gui->gossip.peer_cnt--;
571571
i--;
572572
}
@@ -690,7 +690,8 @@ fd_gui_handle_vote_account_update( fd_gui_t * gui,
690690
if( FD_UNLIKELY( !found ) ) {
691691
fd_memcpy( removed[ removed_cnt++ ].uc, gui->vote_account.vote_accounts[ i ].vote_account->uc, 32UL );
692692
if( FD_LIKELY( i+1UL!=gui->vote_account.vote_account_cnt ) ) {
693-
fd_memcpy( &gui->vote_account.vote_accounts[ i ], &gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt-1UL ], sizeof(struct fd_gui_vote_account) );
693+
gui->vote_account.vote_accounts[ i ] = gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt-1UL ];
694+
gui->vote_account.vote_accounts[ i ] = gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt-1UL ];
694695
gui->vote_account.vote_account_cnt--;
695696
i--;
696697
}

src/discof/exec/fd_exec_tile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ during_frag( fd_exec_tile_ctx_t * ctx,
426426

427427
if( FD_LIKELY( sig==EXEC_NEW_TXN_SIG ) ) {
428428
fd_runtime_public_txn_msg_t * txn = (fd_runtime_public_txn_msg_t *)fd_chunk_to_laddr( ctx->replay_in_mem, chunk );
429-
fd_memcpy( &ctx->txn, &txn->txn, sizeof(fd_txn_p_t) );
429+
ctx->txn = txn->txn;
430430
execute_txn( ctx );
431431
return;
432432
} else if( sig==EXEC_NEW_SLOT_SIG ) {

src/discof/restart/fd_restart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fd_restart_recv_heaviest_fork( fd_restart_t * restart,
160160
msg->from.key, sizeof(fd_pubkey_t) )==0 ) ) {
161161
FD_LOG_WARNING(( "Received a restart_heaviest_fork message: slot=%lu, hash=%s",
162162
msg->last_slot, FD_BASE58_ENC_32_ALLOCA( &msg->last_slot_hash ) ));
163-
fd_memcpy( &restart->coordinator_heaviest_fork_bank_hash, &msg->last_slot_hash, sizeof(fd_hash_t) );
163+
restart->coordinator_heaviest_fork_bank_hash = msg->last_slot_hash;
164164
restart->coordinator_heaviest_fork_slot = msg->last_slot;
165165
restart->coordinator_heaviest_fork_ready = 1;
166166
} else {
@@ -204,7 +204,7 @@ fd_restart_find_heaviest_fork_bank_hash( fd_restart_t * restart,
204204
} else if( FD_UNLIKELY( restart->heaviest_fork_slot==restart->funk_root ) ) {
205205
FD_LOG_NOTICE(( "Found bank hash of slot%lu in funk: %s",
206206
restart->funk_root, FD_BASE58_ENC_32_ALLOCA( &restart->root_bank_hash ) ));
207-
fd_memcpy( &restart->heaviest_fork_bank_hash, &restart->root_bank_hash, sizeof(fd_hash_t) );
207+
restart->heaviest_fork_bank_hash = restart->root_bank_hash;
208208
restart->heaviest_fork_ready = 1;
209209

210210
*out_need_repair = 0;

src/discof/restart/fd_restart_tile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ after_frag( fd_restart_tile_ctx_t * ctx,
356356
fd_funk_txn_end_write( ctx->funk );
357357

358358
/* Copy the bank hash of HeaviestForkSlot to fd_restart_t */
359-
fd_memcpy( &ctx->restart->heaviest_fork_bank_hash, &slot_bank->banks_hash, sizeof(fd_hash_t) );
359+
ctx->restart->heaviest_fork_bank_hash = slot_bank->banks_hash;
360360
ctx->restart->heaviest_fork_ready = 1;
361361
}
362362
}

src/discof/rpcserver/fd_rpc_service.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,7 @@ fd_webserver_ws_closed(ulong conn_id, void * cb_arg) {
25112511
fd_rpc_global_ctx_t * subs = ctx->global;
25122512
for( ulong i = 0; i < subs->sub_cnt; ++i ) {
25132513
if( subs->sub_list[i].conn_id == conn_id ) {
2514-
fd_memcpy( &subs->sub_list[i], &subs->sub_list[--(subs->sub_cnt)], sizeof(struct fd_ws_subscription) );
2514+
subs->sub_list[i] = subs->sub_list[--(subs->sub_cnt)];
25152515
--i;
25162516
}
25172517
}
@@ -2581,7 +2581,7 @@ fd_rpc_replay_after_frag(fd_rpc_ctx_t * ctx, fd_replay_notif_msg_t * msg) {
25812581
subs->perf_sample_ts = ts;
25822582
}
25832583

2584-
fd_memcpy( &subs->last_slot_notify, msg, sizeof(fd_replay_notif_msg_t) );
2584+
subs->last_slot_notify = *msg;
25852585
fd_hash_t * h = &subs->recent_blockhash[msg->slot_exec.slot % MAX_RECENT_BLOCKHASHES];
25862586
fd_hash_copy( h, &msg->slot_exec.block_hash );
25872587

src/discoh/bank/fd_bank_abi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,12 @@ fd_bank_abi_resolve_address_lookup_tables( void const * bank,
391391
for( ulong j=0UL; j<lut->writable_cnt; j++ ) {
392392
uchar idx = payload[ lut->writable_off+j ];
393393
if( FD_UNLIKELY( idx>=active_addresses_len ) ) return FD_BANK_ABI_TXN_INIT_ERR_INVALID_LOOKUP_INDEX;
394-
memcpy( &out_lut_accts[ writable_idx++ ], addresses+idx, sizeof(fd_acct_addr_t) );
394+
out_lut_accts[ writable_idx++ ] = addresses[ idx ];
395395
}
396396
for( ulong j=0UL; j<lut->readonly_cnt; j++ ) {
397397
uchar idx = payload[ lut->readonly_off+j ];
398398
if( FD_UNLIKELY( idx>=active_addresses_len ) ) return FD_BANK_ABI_TXN_INIT_ERR_INVALID_LOOKUP_INDEX;
399-
memcpy( &out_lut_accts[ txn->addr_table_adtl_writable_cnt+readable_idx++ ], addresses+idx, sizeof(fd_acct_addr_t) );
399+
out_lut_accts[ txn->addr_table_adtl_writable_cnt+readable_idx++ ] = addresses[ idx ];
400400
}
401401
}
402402

src/discoh/bank/fd_bank_tile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
473473
all the data around. */
474474
fd_txn_p_t bundle_txn_temp[ 5UL ];
475475
for( ulong i=0UL; i<txn_cnt; i++ ) {
476-
fd_memcpy( bundle_txn_temp+i, txns+i, sizeof(fd_txn_p_t) );
476+
bundle_txn_temp[ i ] = txns[ i ];
477477
}
478478

479479
for( ulong i=0UL; i<txn_cnt; i++ ) {

src/flamenco/capture/fd_solcap_writer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ fd_solcap_write_account2( fd_solcap_writer_t * writer,
422422

423423
if( writer->account_idx < FD_SOLCAP_ACC_TBL_CNT ) {
424424
fd_solcap_account_tbl_t * account = &writer->accounts[ writer->account_idx ];
425-
memcpy( account, tbl, sizeof(fd_solcap_account_tbl_t) );
425+
*account = *tbl;
426426

427427
/* Since we don't yet know the final position of the account table,
428428
we temporarily store a global offset. This will later get

src/flamenco/rewards/fd_rewards.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ calculate_points_range( fd_epoch_info_pair_t const * stake_infos,
331331

332332
/* Check that the vote account is present in our cache */
333333
fd_vote_info_pair_t_mapnode_t query_key;
334-
fd_pubkey_t const * voter_acc = &stake->delegation.voter_pubkey;
335-
fd_memcpy( &query_key.elem.account, voter_acc, sizeof(fd_pubkey_t) );
334+
query_key.elem.account = stake->delegation.voter_pubkey;
336335
fd_vote_info_pair_t_mapnode_t * vote_state_info = fd_vote_info_pair_t_map_find( task_args->vote_states_pool, task_args->vote_states_root, &query_key );
337336
if( FD_UNLIKELY( vote_state_info==NULL ) ) {
338337
FD_LOG_DEBUG(( "vote account missing from cache" ));
@@ -460,7 +459,7 @@ calculate_stake_vote_rewards_account( fd_epoch_info_t const *
460459

461460
fd_pubkey_t const * voter_acc = &stake->delegation.voter_pubkey;
462461
fd_vote_info_pair_t_mapnode_t key;
463-
fd_memcpy( &key.elem.account, voter_acc, sizeof(fd_pubkey_t) );
462+
key.elem.account = *voter_acc;
464463
fd_vote_info_pair_t_mapnode_t * vote_state_entry = fd_vote_info_pair_t_map_find( temp_info->vote_states_pool,
465464
temp_info->vote_states_root,
466465
&key );
@@ -503,7 +502,7 @@ calculate_stake_vote_rewards_account( fd_epoch_info_t const *
503502

504503
// Find and update the vote reward node in the local map
505504
fd_vote_reward_t_mapnode_t vote_map_key[1];
506-
fd_memcpy( &vote_map_key->elem.pubkey, voter_acc, sizeof(fd_pubkey_t) );
505+
vote_map_key->elem.pubkey = *voter_acc;
507506
fd_vote_reward_t_mapnode_t * vote_reward_node = fd_vote_reward_t_map_find( result->vote_reward_map_pool, result->vote_reward_map_root, vote_map_key );
508507
if( FD_UNLIKELY( vote_reward_node==NULL ) ) {
509508
FD_LOG_WARNING(( "vote account is missing from the vote rewards pool" ));
@@ -513,8 +512,8 @@ calculate_stake_vote_rewards_account( fd_epoch_info_t const *
513512
vote_reward_node = fd_vote_reward_t_map_find( vote_reward_map_pool, vote_reward_map_root, vote_map_key );
514513

515514
if( vote_reward_node==NULL ) {
516-
vote_reward_node = fd_vote_reward_t_map_acquire( vote_reward_map_pool );
517-
fd_memcpy( &vote_reward_node->elem.pubkey, voter_acc, sizeof(fd_pubkey_t) );
515+
vote_reward_node = fd_vote_reward_t_map_acquire( vote_reward_map_pool );
516+
vote_reward_node->elem.pubkey = *voter_acc;
518517
vote_reward_node->elem.commission = commission;
519518
vote_reward_node->elem.vote_rewards = calculated_stake_rewards->voter_rewards;
520519
vote_reward_node->elem.needs_store = 1;
@@ -643,7 +642,7 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct
643642
fd_pubkey_t const * voter_pubkey = &vote_info->elem.account;
644643
fd_vote_reward_t_mapnode_t * vote_reward_node = fd_vote_reward_t_map_acquire( result->vote_reward_map_pool );
645644

646-
fd_memcpy( &vote_reward_node->elem.pubkey, voter_pubkey, sizeof(fd_pubkey_t) );
645+
vote_reward_node->elem.pubkey = *voter_pubkey;
647646
vote_reward_node->elem.vote_rewards = 0UL;
648647
vote_reward_node->elem.needs_store = 0;
649648

@@ -850,7 +849,7 @@ calculate_rewards_for_partitioning( fd_exec_slot_ctx_t * slot_
850849
result->foundation_rate = rewards.foundation_rate;
851850
result->prev_epoch_duration_in_years = rewards.prev_epoch_duration_in_years;
852851
result->capitalization = slot_bank->capitalization;
853-
fd_memcpy( &result->point_value, &validator_result->point_value, sizeof(fd_point_value_t) );
852+
result->point_value = validator_result->point_value;
854853
}
855854

856855
/* Calculate rewards from previous epoch and distribute vote rewards
@@ -922,8 +921,8 @@ calculate_rewards_and_distribute_vote_rewards( fd_exec_slot_ctx_t *
922921
slot_ctx->slot_bank.capitalization += result->distributed_rewards;
923922

924923
/* Cheap because this doesn't copy all the rewards, just pointers to the dlist */
925-
fd_memcpy( &result->stake_rewards_by_partition, &rewards_calc_result->stake_rewards_by_partition, sizeof(fd_stake_reward_calculation_partitioned_t) );
926-
fd_memcpy( &result->point_value, &rewards_calc_result->point_value, sizeof(fd_point_value_t) );
924+
result->stake_rewards_by_partition = rewards_calc_result->stake_rewards_by_partition;
925+
result->point_value = rewards_calc_result->point_value;
927926
}
928927

929928
/* Distributes a single partitioned reward to a single stake account */
@@ -997,8 +996,7 @@ set_epoch_reward_status_active( fd_exec_slot_ctx_t * slot_ctx,
997996
FD_LOG_NOTICE(( "Setting epoch reward status as active" ));
998997
slot_ctx->slot_bank.epoch_reward_status.discriminant = fd_epoch_reward_status_enum_Active;
999998
slot_ctx->slot_bank.epoch_reward_status.inner.Active.distribution_starting_block_height = distribution_starting_block_height;
1000-
1001-
fd_memcpy( &slot_ctx->slot_bank.epoch_reward_status.inner.Active.partitioned_stake_rewards, partitioned_rewards, sizeof(fd_partitioned_stake_rewards_t) );
999+
slot_ctx->slot_bank.epoch_reward_status.inner.Active.partitioned_stake_rewards = *partitioned_rewards;
10021000
}
10031001

10041002
/* Process reward credits for a partition of rewards.

src/flamenco/runtime/context/fd_exec_slot_ctx.c

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -241,55 +241,59 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx,
241241

242242
/* Copy over fields */
243243

244-
slot_ctx->slot_bank.parent_signature_cnt = oldbank->signature_count;
245-
slot_ctx->slot_bank.tick_height = oldbank->tick_height;
244+
slot_ctx->slot_bank.parent_signature_cnt = oldbank->signature_count;
245+
slot_ctx->slot_bank.tick_height = oldbank->tick_height;
246246

247-
if( oldbank->blockhash_queue.last_hash )
247+
if( oldbank->blockhash_queue.last_hash ) {
248248
slot_bank->poh = *oldbank->blockhash_queue.last_hash;
249+
}
249250
slot_bank->slot = oldbank->slot;
250-
slot_bank->prev_slot = oldbank->parent_slot;
251-
fd_memcpy(&slot_bank->banks_hash, &oldbank->hash, sizeof(oldbank->hash));
252-
fd_memcpy(&slot_ctx->slot_bank.prev_banks_hash, &oldbank->parent_hash, sizeof(oldbank->parent_hash));
253-
fd_memcpy(&slot_bank->fee_rate_governor, &oldbank->fee_rate_governor, sizeof(oldbank->fee_rate_governor));
254-
slot_bank->lamports_per_signature = manifest->lamports_per_signature;
255-
slot_ctx->prev_lamports_per_signature = manifest->lamports_per_signature;
256-
slot_ctx->slot_bank.parent_signature_cnt = oldbank->signature_count;
257-
if( oldbank->hashes_per_tick )
258-
epoch_bank->hashes_per_tick = *oldbank->hashes_per_tick;
259-
else
260-
epoch_bank->hashes_per_tick = 0;
261-
epoch_bank->ticks_per_slot = oldbank->ticks_per_slot;
262-
fd_memcpy(&epoch_bank->ns_per_slot, &oldbank->ns_per_slot, sizeof(oldbank->ns_per_slot));
263-
epoch_bank->genesis_creation_time = oldbank->genesis_creation_time;
264-
epoch_bank->slots_per_year = oldbank->slots_per_year;
265-
slot_bank->max_tick_height = oldbank->max_tick_height;
266-
fd_memcpy( &epoch_bank->inflation, &oldbank->inflation, sizeof(fd_inflation_t) );
267-
fd_memcpy( &epoch_bank->epoch_schedule, &oldbank->epoch_schedule, sizeof(fd_epoch_schedule_t) );
268-
epoch_bank->rent = oldbank->rent_collector.rent;
269-
fd_memcpy( &epoch_bank->rent, &oldbank->rent_collector.rent, sizeof(fd_rent_t) );
270-
fd_memcpy( &epoch_bank->rent_epoch_schedule, &oldbank->rent_collector.epoch_schedule, sizeof(fd_epoch_schedule_t) );
271-
272-
if( manifest->epoch_account_hash )
273-
slot_bank->epoch_account_hash = *manifest->epoch_account_hash;
274-
275-
slot_bank->collected_rent = oldbank->collected_rent;
251+
slot_bank->prev_slot = oldbank->parent_slot;
252+
slot_bank->banks_hash = oldbank->hash;
253+
slot_ctx->slot_bank.prev_banks_hash = oldbank->parent_hash;
254+
slot_bank->fee_rate_governor = oldbank->fee_rate_governor;
255+
slot_bank->lamports_per_signature = manifest->lamports_per_signature;
256+
slot_ctx->prev_lamports_per_signature = manifest->lamports_per_signature;
257+
slot_ctx->slot_bank.parent_signature_cnt = oldbank->signature_count;
258+
if( oldbank->hashes_per_tick ) {
259+
epoch_bank->hashes_per_tick = *oldbank->hashes_per_tick;
260+
} else {
261+
epoch_bank->hashes_per_tick = 0;
262+
}
263+
epoch_bank->ticks_per_slot = oldbank->ticks_per_slot;
264+
epoch_bank->ns_per_slot = oldbank->ns_per_slot;
265+
epoch_bank->genesis_creation_time = oldbank->genesis_creation_time;
266+
epoch_bank->slots_per_year = oldbank->slots_per_year;
267+
slot_bank->max_tick_height = oldbank->max_tick_height;
268+
epoch_bank->inflation = oldbank->inflation;
269+
epoch_bank->epoch_schedule = oldbank->epoch_schedule;
270+
epoch_bank->rent = oldbank->rent_collector.rent;
271+
epoch_bank->rent_epoch_schedule = oldbank->rent_collector.epoch_schedule;
272+
273+
if( manifest->epoch_account_hash ) {
274+
slot_bank->epoch_account_hash = *manifest->epoch_account_hash;
275+
}
276+
277+
slot_bank->collected_rent = oldbank->collected_rent;
276278
// did they not change the bank?!
277-
slot_bank->collected_execution_fees = oldbank->collector_fees;
278-
slot_bank->collected_priority_fees = 0;
279-
slot_bank->capitalization = oldbank->capitalization;
280-
slot_bank->block_height = oldbank->block_height;
281-
slot_bank->transaction_count = oldbank->transaction_count;
282-
if ( oldbank->blockhash_queue.last_hash ) {
283-
slot_bank->block_hash_queue.last_hash = fd_valloc_malloc( valloc, FD_HASH_ALIGN, FD_HASH_FOOTPRINT );
284-
*slot_bank->block_hash_queue.last_hash = *oldbank->blockhash_queue.last_hash;
279+
slot_bank->collected_execution_fees = oldbank->collector_fees;
280+
slot_bank->collected_priority_fees = 0;
281+
slot_bank->capitalization = oldbank->capitalization;
282+
slot_bank->block_height = oldbank->block_height;
283+
slot_bank->transaction_count = oldbank->transaction_count;
284+
285+
if( oldbank->blockhash_queue.last_hash ) {
286+
slot_bank->block_hash_queue.last_hash = fd_valloc_malloc( valloc, FD_HASH_ALIGN, FD_HASH_FOOTPRINT );
287+
*slot_bank->block_hash_queue.last_hash = *oldbank->blockhash_queue.last_hash;
285288
} else {
286-
slot_bank->block_hash_queue.last_hash = NULL;
289+
slot_bank->block_hash_queue.last_hash = NULL;
287290
}
288291

289-
/* FIXME: Avoid using magic number for allocations */
290292
slot_bank->block_hash_queue.last_hash_index = oldbank->blockhash_queue.last_hash_index;
291-
slot_bank->block_hash_queue.max_age = oldbank->blockhash_queue.max_age;
292-
slot_bank->block_hash_queue.ages_root = NULL;
293+
slot_bank->block_hash_queue.max_age = oldbank->blockhash_queue.max_age;
294+
slot_bank->block_hash_queue.ages_root = NULL;
295+
296+
/* FIXME: Avoid using magic number for allocations */
293297
uchar * pool_mem = fd_spad_alloc( runtime_spad, fd_hash_hash_age_pair_t_map_align(), fd_hash_hash_age_pair_t_map_footprint( 400 ) );
294298
slot_bank->block_hash_queue.ages_pool = fd_hash_hash_age_pair_t_map_join( fd_hash_hash_age_pair_t_map_new( pool_mem, 400 ) );
295299
for ( ulong i = 0; i < oldbank->blockhash_queue.ages_len; i++ ) {

0 commit comments

Comments
 (0)