Skip to content

Commit a13dda7

Browse files
runtime: replacing vote caches with fd_vote_states_t
1 parent 04a5f05 commit a13dda7

39 files changed

+1591
-1767
lines changed

src/discof/replay/fd_exec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
static inline ulong
1919
generate_stake_weight_msg( fd_exec_slot_ctx_t * slot_ctx,
2020
ulong epoch,
21-
fd_vote_accounts_global_t const * vote_accounts,
21+
fd_vote_states_t const * vote_states,
2222
ulong * stake_weight_msg_out ) {
2323
fd_stake_weight_msg_t * stake_weight_msg = (fd_stake_weight_msg_t *)fd_type_pun( stake_weight_msg_out );
2424
fd_vote_stake_weight_t * stake_weights = stake_weight_msg->weights;
25-
ulong staked_cnt = fd_stake_weights_by_node( vote_accounts, stake_weights );
25+
ulong staked_cnt = fd_stake_weights_by_node( vote_states, stake_weights );
2626
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
2727

2828
stake_weight_msg->epoch = epoch;

src/discof/replay/fd_replay_tile.c

Lines changed: 36 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -355,33 +355,29 @@ publish_stake_weights( fd_replay_tile_ctx_t * ctx,
355355
fd_exec_slot_ctx_t * slot_ctx ) {
356356
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
357357

358-
fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( slot_ctx->bank );
359-
fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( epoch_stakes );
360-
361-
if( epoch_stakes_root!=NULL ) {
358+
fd_vote_states_t const * vote_states_prev_prev = fd_bank_vote_states_prev_prev_locking_query( slot_ctx->bank );
359+
do {
362360
ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk );
363-
ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, fd_bank_slot_get( slot_ctx->bank ) );
364-
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, epoch - 1, epoch_stakes, stake_weights_msg );
365-
ulong stake_weights_sig = 4UL;
361+
ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, fd_bank_slot_get( slot_ctx->bank ) );
362+
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, epoch - 1, vote_states_prev_prev, stake_weights_msg );
363+
ulong stake_weights_sig = 4UL;
366364
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
367365
ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark );
368366
FD_LOG_NOTICE(("sending current epoch stake weights - epoch: %lu, stake_weight_cnt: %lu, start_slot: %lu, slot_cnt: %lu", stake_weights_msg[0], stake_weights_msg[1], stake_weights_msg[2], stake_weights_msg[3]));
369-
}
370-
371-
fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank );
372-
fd_vote_accounts_global_t const * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_query( slot_ctx->bank );
373-
fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( next_epoch_stakes );
367+
} while( 0 );
368+
fd_bank_vote_states_prev_prev_end_locking_query( slot_ctx->bank );
374369

375-
if( next_epoch_stakes_root!=NULL ) {
370+
fd_vote_states_t const * vote_states_prev = fd_bank_vote_states_prev_locking_query( slot_ctx->bank );
371+
do {
376372
ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk );
377373
ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, fd_bank_slot_get( slot_ctx->bank ) ); /* epoch */
378-
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, epoch, next_epoch_stakes, stake_weights_msg );
379-
ulong stake_weights_sig = 4UL;
374+
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, epoch, vote_states_prev, stake_weights_msg );
375+
ulong stake_weights_sig = 4UL;
380376
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
381377
ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark );
382378
FD_LOG_NOTICE(("sending next epoch stake weights - epoch: %lu, stake_weight_cnt: %lu, start_slot: %lu, slot_cnt: %lu", stake_weights_msg[0], stake_weights_msg[1], stake_weights_msg[2], stake_weights_msg[3]));
383-
}
384-
fd_bank_next_epoch_stakes_end_locking_query( slot_ctx->bank );
379+
} while( 0 );
380+
fd_bank_vote_states_prev_end_locking_query( slot_ctx->bank );
385381
}
386382

387383
static void
@@ -526,7 +522,6 @@ restore_slot_ctx( fd_replay_tile_ctx_t * ctx,
526522

527523
fd_exec_slot_ctx_t * recovered_slot_ctx = fd_exec_slot_ctx_recover( ctx->slot_ctx,
528524
manifest_global );
529-
530525
if( !recovered_slot_ctx ) {
531526
FD_LOG_ERR(( "Failed to restore slot context from snapshot manifest!" ));
532527
}
@@ -684,20 +679,18 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx ) {
684679
memset( block_id, 0, sizeof(fd_hash_t) );
685680
block_id->key[0] = UCHAR_MAX; /* TODO: would be good to have the actual block id of the snapshot slot */
686681

687-
fd_vote_accounts_global_t const * vote_accounts = fd_bank_curr_epoch_stakes_locking_query( ctx->slot_ctx->bank );
688-
689-
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool = fd_vote_accounts_vote_accounts_pool_join( vote_accounts );
690-
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = fd_vote_accounts_vote_accounts_root_join( vote_accounts );
682+
fd_vote_states_t const * vote_states = fd_bank_vote_states_locking_query( ctx->slot_ctx->bank );
691683

692684
fd_bank_hash_cmp_t * bank_hash_cmp = ctx->bank_hash_cmp;
693-
for( fd_vote_accounts_pair_global_t_mapnode_t * curr = fd_vote_accounts_pair_global_t_map_minimum( vote_accounts_pool, vote_accounts_root );
694-
curr;
695-
curr = fd_vote_accounts_pair_global_t_map_successor( vote_accounts_pool, curr ) ) {
696-
bank_hash_cmp->total_stake += curr->elem.stake;
685+
686+
uchar iter_mem[FD_VOTE_STATE_ITER_FOOTPRINT];
687+
for( fd_vote_states_iter_t * iter = fd_vote_states_iter_init( vote_states, iter_mem ); !fd_vote_states_iter_done( iter ); fd_vote_states_iter_next( iter ) ) {
688+
fd_vote_state_ele_t const * vote_state = fd_vote_states_iter_ele( iter );
689+
bank_hash_cmp->total_stake += vote_state->stake;
697690
}
698691
bank_hash_cmp->watermark = snapshot_slot;
699692

700-
fd_bank_curr_epoch_stakes_end_locking_query( ctx->slot_ctx->bank );
693+
fd_bank_vote_states_end_locking_query( ctx->slot_ctx->bank );
701694

702695
ulong root = snapshot_slot;
703696
if( FD_LIKELY( root > fd_fseq_query( ctx->published_wmark ) ) ) {
@@ -741,8 +734,8 @@ init_from_snapshot( fd_replay_tile_ctx_t * ctx,
741734
fd_bank_lthash_end_locking_query( ctx->slot_ctx->bank );
742735

743736
fd_runtime_update_leaders( ctx->slot_ctx->bank,
744-
fd_bank_slot_get( ctx->slot_ctx->bank ),
745-
ctx->runtime_spad );
737+
fd_bank_slot_get( ctx->slot_ctx->bank ),
738+
ctx->runtime_spad );
746739

747740
fd_runtime_read_genesis( ctx->slot_ctx,
748741
ctx->genesis,
@@ -1054,86 +1047,30 @@ publish_votes_to_plugin( fd_replay_tile_ctx_t * ctx,
10541047
fd_stem_context_t * stem ) {
10551048
uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->votes_plugin_out->mem, ctx->votes_plugin_out->chunk );
10561049

1057-
fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( ctx->slot_ctx->bank );
1058-
fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_pool = fd_vote_accounts_vote_accounts_pool_join( epoch_stakes );
1059-
fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( epoch_stakes );
1060-
1050+
fd_vote_states_t const * vote_states = fd_bank_vote_states_locking_query( ctx->slot_ctx->bank );
10611051
ulong i = 0;
10621052
FD_SPAD_FRAME_BEGIN( ctx->runtime_spad ) {
1063-
for( fd_vote_accounts_pair_global_t_mapnode_t const * n = fd_vote_accounts_pair_global_t_map_minimum_const( epoch_stakes_pool, epoch_stakes_root );
1064-
n && i < FD_CLUSTER_NODE_CNT;
1065-
n = fd_vote_accounts_pair_global_t_map_successor_const( epoch_stakes_pool, n ) ) {
1066-
if( n->elem.stake == 0 ) continue;
1067-
1068-
uchar * data = (uchar *)&n->elem.value + n->elem.value.data_offset;
1069-
ulong data_len = n->elem.value.data_len;
1070-
1071-
int err;
1072-
fd_vote_state_versioned_t * vsv = fd_bincode_decode_spad(
1073-
vote_state_versioned, ctx->runtime_spad,
1074-
data,
1075-
data_len,
1076-
&err );
1077-
if( FD_UNLIKELY( err ) ) {
1078-
FD_LOG_ERR(( "Unexpected failure in decoding vote state %d", err ));
1079-
}
1080-
1081-
fd_pubkey_t node_pubkey;
1082-
ulong commission;
1083-
ulong epoch_credits;
1084-
fd_vote_epoch_credits_t const * _epoch_credits;
1085-
ulong root_slot;
1086-
1087-
switch( vsv->discriminant ) {
1088-
case fd_vote_state_versioned_enum_v0_23_5:
1089-
node_pubkey = vsv->inner.v0_23_5.node_pubkey;
1090-
commission = vsv->inner.v0_23_5.commission;
1091-
_epoch_credits = deq_fd_vote_epoch_credits_t_cnt( vsv->inner.v0_23_5.epoch_credits ) == 0 ? NULL : deq_fd_vote_epoch_credits_t_peek_tail_const( vsv->inner.v0_23_5.epoch_credits );
1092-
epoch_credits = _epoch_credits==NULL ? 0UL : _epoch_credits->credits - _epoch_credits->prev_credits;
1093-
root_slot = vsv->inner.v0_23_5.root_slot;
1094-
break;
1095-
case fd_vote_state_versioned_enum_v1_14_11:
1096-
node_pubkey = vsv->inner.v1_14_11.node_pubkey;
1097-
commission = vsv->inner.v1_14_11.commission;
1098-
_epoch_credits = deq_fd_vote_epoch_credits_t_cnt( vsv->inner.v1_14_11.epoch_credits ) == 0 ? NULL : deq_fd_vote_epoch_credits_t_peek_tail_const( vsv->inner.v1_14_11.epoch_credits );
1099-
epoch_credits = _epoch_credits==NULL ? 0UL : _epoch_credits->credits - _epoch_credits->prev_credits;
1100-
root_slot = vsv->inner.v1_14_11.root_slot;
1101-
break;
1102-
case fd_vote_state_versioned_enum_current:
1103-
node_pubkey = vsv->inner.current.node_pubkey;
1104-
commission = vsv->inner.current.commission;
1105-
_epoch_credits = deq_fd_vote_epoch_credits_t_cnt( vsv->inner.current.epoch_credits ) == 0 ? NULL : deq_fd_vote_epoch_credits_t_peek_tail_const( vsv->inner.current.epoch_credits );
1106-
epoch_credits = _epoch_credits==NULL ? 0UL : _epoch_credits->credits - _epoch_credits->prev_credits;
1107-
root_slot = vsv->inner.v0_23_5.root_slot;
1108-
break;
1109-
default:
1110-
__builtin_unreachable();
1111-
}
1112-
1113-
fd_clock_timestamp_vote_t_mapnode_t query;
1114-
memcpy( query.elem.pubkey.uc, n->elem.key.uc, 32UL );
1115-
fd_clock_timestamp_votes_global_t const * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_query( ctx->slot_ctx->bank );
1116-
fd_clock_timestamp_vote_t_mapnode_t * timestamp_votes_root = fd_clock_timestamp_votes_votes_root_join( clock_timestamp_votes );
1117-
fd_clock_timestamp_vote_t_mapnode_t * timestamp_votes_pool = fd_clock_timestamp_votes_votes_pool_join( clock_timestamp_votes );
1118-
1119-
fd_clock_timestamp_vote_t_mapnode_t * res = fd_clock_timestamp_vote_t_map_find( timestamp_votes_pool, timestamp_votes_root, &query );
1053+
uchar iter_mem[FD_VOTE_STATE_ITER_FOOTPRINT];
1054+
for( fd_vote_states_iter_t * iter = fd_vote_states_iter_init( vote_states, iter_mem ); !fd_vote_states_iter_done( iter ); fd_vote_states_iter_next( iter ) ) {
1055+
fd_vote_state_ele_t const * vote_state = fd_vote_states_iter_ele( iter );
11201056

11211057
fd_vote_update_msg_t * msg = (fd_vote_update_msg_t *)(dst + sizeof(ulong) + i*112U);
11221058
memset( msg, 0, 112U );
1123-
memcpy( msg->vote_pubkey, n->elem.key.uc, sizeof(fd_pubkey_t) );
1124-
memcpy( msg->node_pubkey, node_pubkey.uc, sizeof(fd_pubkey_t) );
1125-
msg->activated_stake = n->elem.stake;
1126-
msg->last_vote = res == NULL ? 0UL : res->elem.slot;
1127-
msg->root_slot = root_slot;
1128-
msg->epoch_credits = epoch_credits;
1129-
msg->commission = (uchar)commission;
1059+
memcpy( msg->vote_pubkey, &vote_state->vote_account, sizeof(fd_pubkey_t) );
1060+
memcpy( msg->node_pubkey, &vote_state->node_account, sizeof(fd_pubkey_t) );
1061+
msg->activated_stake = vote_state->stake;
1062+
msg->last_vote = vote_state->last_vote_slot;
1063+
msg->root_slot = 0UL; /* TODO: needs to be populated in vote_state */
1064+
msg->epoch_credits = 0UL; /* TODO: needs to be populated in vote_state */
1065+
msg->commission = (uchar)vote_state->commission;
11301066
msg->is_delinquent = (uchar)fd_int_if(fd_bank_slot_get( ctx->slot_ctx->bank ) >= 128UL, msg->last_vote <= fd_bank_slot_get( ctx->slot_ctx->bank ) - 128UL, msg->last_vote == 0);
1067+
1068+
11311069
++i;
1132-
fd_bank_clock_timestamp_votes_end_locking_query( ctx->slot_ctx->bank );
11331070
}
11341071
} FD_SPAD_FRAME_END;
11351072

1136-
fd_bank_epoch_stakes_end_locking_query( ctx->slot_ctx->bank );
1073+
fd_bank_vote_states_end_locking_query( ctx->slot_ctx->bank );
11371074

11381075
*(ulong *)dst = i;
11391076

src/discof/restore/utils/fd_ssload.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ fd_ssload_recover( fd_snapshot_manifest_t * manifest,
136136
fd_bank_execution_fees_set( slot_ctx->bank, manifest->collector_fees );
137137
fd_bank_priority_fees_set( slot_ctx->bank, 0UL );
138138

139-
/* FIXME: Remove the magic number here. */
140-
fd_clock_timestamp_votes_global_t * clock_timestamp_votes = fd_bank_clock_timestamp_votes_locking_modify( slot_ctx->bank );
141-
uchar * clock_pool_mem = (uchar *)fd_ulong_align_up( (ulong)clock_timestamp_votes + sizeof(fd_clock_timestamp_votes_global_t), fd_clock_timestamp_vote_t_map_align() );
142-
fd_clock_timestamp_vote_t_mapnode_t * clock_pool = fd_clock_timestamp_vote_t_map_join( fd_clock_timestamp_vote_t_map_new(clock_pool_mem, 30000UL ) );
143-
clock_timestamp_votes->votes_pool_offset = (ulong)fd_clock_timestamp_vote_t_map_leave( clock_pool) - (ulong)clock_timestamp_votes;
144-
clock_timestamp_votes->votes_root_offset = 0UL;
145-
fd_bank_clock_timestamp_votes_end_locking_modify( slot_ctx->bank );
146-
147-
for( ulong i=0UL; i<manifest->vote_accounts_len; i++ ) {
148-
fd_snapshot_manifest_vote_account_t * account = &manifest->vote_accounts[ i ];
149-
fd_pubkey_t vote_account_pubkey;
150-
fd_memcpy( vote_account_pubkey.uc, account->vote_account_pubkey, 32UL );
151-
if( FD_LIKELY( account->last_slot || account->stake ) ) {
152-
fd_vote_record_timestamp_vote_with_slot( &vote_account_pubkey, account->last_timestamp, account->last_slot, slot_ctx->bank );
153-
}
154-
}
155-
156139
/* Update last restart slot
157140
https://github.com/solana-labs/solana/blob/30531d7a5b74f914dde53bfbb0bc2144f2ac92bb/runtime/src/bank.rs#L2152
158141

src/discof/writer/fd_writer_tile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ after_frag( fd_writer_tile_ctx_t * ctx,
341341
ctx->funk,
342342
ctx->funk_txn,
343343
txn_ctx,
344-
ctx->spad,
345344
ctx->bank,
346345
ctx->capture_ctx );
347346

0 commit comments

Comments
 (0)