@@ -2920,11 +2920,15 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
2920
2920
2921
2921
/* Derive epoch stakes */
2922
2922
2923
- fd_vote_accounts_pair_t_mapnode_t * vacc_pool = NULL ;
2924
- fd_vote_accounts_pair_t_mapnode_t * vacc_root = NULL ;
2925
- FD_TEST ( vacc_pool );
2923
+ fd_stakes_global_t * stakes_global = fd_bank_stakes_locking_modify ( slot_ctx -> bank );
2926
2924
2927
- fd_delegation_pair_t_mapnode_t * sacc_pool = NULL ;
2925
+ uchar * vacc_pool_mem = (uchar * )fd_ulong_align_up ( (ulong )stakes_global + sizeof (fd_stakes_global_t ), fd_vote_accounts_pair_global_t_map_align () );
2926
+ 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 ) );
2927
+ fd_vote_accounts_pair_global_t_mapnode_t * vacc_root = NULL ;
2928
+
2929
+
2930
+ uchar * sacc_pool_mem = (uchar * )fd_ulong_align_up ( (ulong )vacc_pool + fd_vote_accounts_pair_global_t_map_footprint ( 5000UL ), fd_delegation_pair_t_map_align () );
2931
+ fd_delegation_pair_t_mapnode_t * sacc_pool = fd_delegation_pair_t_map_join ( fd_delegation_pair_t_map_new ( sacc_pool_mem , 5000UL ) );
2928
2932
fd_delegation_pair_t_mapnode_t * sacc_root = NULL ;
2929
2933
2930
2934
fd_acc_lamports_t capitalization = 0UL ;
@@ -2939,59 +2943,22 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
2939
2943
2940
2944
if ( !memcmp (acc -> account .owner .key , fd_solana_vote_program_id .key , sizeof (fd_pubkey_t )) ) {
2941
2945
/* Vote Program Account */
2942
- fd_vote_accounts_pair_t_mapnode_t * node = fd_vote_accounts_pair_t_map_acquire (vacc_pool );
2946
+ fd_vote_accounts_pair_global_t_mapnode_t * node = fd_vote_accounts_pair_global_t_map_acquire (vacc_pool );
2943
2947
FD_TEST ( node );
2944
2948
2945
- /* FIXME: Reimplement when we try to fix genesis. */
2946
- // fd_vote_block_timestamp_t last_timestamp = {0};
2947
- // fd_pubkey_t node_pubkey = {0};
2948
- // FD_SPAD_FRAME_BEGIN( runtime_spad ) {
2949
- // /* Deserialize content */
2950
- // fd_vote_state_versioned_t vs[1];
2951
- // fd_bincode_decode_ctx_t decode = {
2952
- // .data = acc->account.data,
2953
- // .dataend = acc->account.data + acc->account.data_len,
2954
- // .valloc = fd_spad_virtual( runtime_spad )
2955
- // };
2956
- // int decode_err = fd_vote_state_versioned_decode( vs, &decode );
2957
- // if( FD_UNLIKELY( decode_err!=FD_BINCODE_SUCCESS ) ) {
2958
- // FD_LOG_WARNING(( "fd_vote_state_versioned_decode failed (%d)", decode_err ));
2959
- // return;
2960
- // }
2961
-
2962
- // switch( vs->discriminant )
2963
- // {
2964
- // case fd_vote_state_versioned_enum_current:
2965
- // last_timestamp = vs->inner.current.last_timestamp;
2966
- // node_pubkey = vs->inner.current.node_pubkey;
2967
- // break;
2968
- // case fd_vote_state_versioned_enum_v0_23_5:
2969
- // last_timestamp = vs->inner.v0_23_5.last_timestamp;
2970
- // node_pubkey = vs->inner.v0_23_5.node_pubkey;
2971
- // break;
2972
- // case fd_vote_state_versioned_enum_v1_14_11:
2973
- // last_timestamp = vs->inner.v1_14_11.last_timestamp;
2974
- // node_pubkey = vs->inner.v1_14_11.node_pubkey;
2975
- // break;
2976
- // default:
2977
- // __builtin_unreachable();
2978
- // }
2979
-
2980
- // } FD_SPAD_FRAME_END;
2981
-
2982
- // fd_memcpy(node->elem.key.key, acc->key.key, sizeof(fd_pubkey_t));
2983
- // node->elem.stake = acc->account.lamports;
2984
- // node->elem.value = (fd_solana_vote_account_t){
2985
- // .lamports = acc->account.lamports,
2986
- // .node_pubkey = node_pubkey,
2987
- // .last_timestamp_ts = last_timestamp.timestamp,
2988
- // .last_timestamp_slot = last_timestamp.slot,
2989
- // .owner = acc->account.owner,
2990
- // .executable = acc->account.executable,
2991
- // .rent_epoch = acc->account.rent_epoch
2992
- // };
2993
-
2994
- fd_vote_accounts_pair_t_map_insert ( vacc_pool , & vacc_root , node );
2949
+ fd_memcpy (node -> elem .key .key , acc -> key .key , sizeof (fd_pubkey_t ));
2950
+ node -> elem .stake = acc -> account .lamports ;
2951
+ node -> elem .value = (fd_solana_account_global_t ){
2952
+ .lamports = acc -> account .lamports ,
2953
+ .data_len = acc -> account .data_len ,
2954
+ .data_offset = 0UL , /* FIXME: remove this field from the cache altogether. */
2955
+ .owner = acc -> account .owner ,
2956
+ .executable = acc -> account .executable ,
2957
+ .rent_epoch = acc -> account .rent_epoch
2958
+ };
2959
+ fd_solana_account_data_update ( & node -> elem .value , acc -> account .data );
2960
+
2961
+ fd_vote_accounts_pair_global_t_map_insert ( vacc_pool , & vacc_root , node );
2995
2962
2996
2963
FD_LOG_INFO (( "Adding genesis vote account: key=%s stake=%lu" ,
2997
2964
FD_BASE58_ENC_32_ALLOCA ( node -> elem .key .key ),
@@ -3062,51 +3029,104 @@ fd_runtime_init_bank_from_genesis( fd_exec_slot_ctx_t * slot_ctx,
3062
3029
// slot_ctx->slot_bank.epoch_stakes.vote_accounts_pool = fd_vote_accounts_pair_t_map_join( fd_vote_accounts_pair_t_map_new( pool_mem, FD_HASH_FOOTPRINT * 400 ) );
3063
3030
// slot_ctx->slot_bank.epoch_stakes.vote_accounts_root = NULL;
3064
3031
3065
- // fd_vote_accounts_pair_t_mapnode_t * next_pool = fd_exec_epoch_ctx_next_epoch_stakes_join( slot_ctx->epoch_ctx );
3066
- // fd_vote_accounts_pair_t_mapnode_t * next_root = NULL;
3067
3032
3068
- // for( fd_vote_accounts_pair_t_mapnode_t *n = fd_vote_accounts_pair_t_map_minimum( vacc_pool, vacc_root );
3069
- // n;
3070
- // n = fd_vote_accounts_pair_t_map_successor( vacc_pool, n )) {
3071
- // fd_vote_accounts_pair_t_mapnode_t * e = fd_vote_accounts_pair_t_map_acquire( slot_ctx->slot_bank.epoch_stakes.vote_accounts_pool );
3072
- // e->elem = n->elem;
3073
- // fd_vote_accounts_pair_t_map_insert( slot_ctx->slot_bank.epoch_stakes.vote_accounts_pool, &slot_ctx->slot_bank.epoch_stakes.vote_accounts_root, e );
3033
+ fd_vote_accounts_global_t * epoch_stakes = fd_bank_epoch_stakes_locking_modify ( slot_ctx -> bank );
3034
+ uchar * pool_mem = (uchar * )fd_ulong_align_up ( (ulong )epoch_stakes + sizeof (fd_vote_accounts_global_t ), fd_vote_accounts_pair_t_map_align () );
3035
+ 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 , 50000UL ) );
3036
+ fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root = NULL ;
3074
3037
3075
- // fd_vote_accounts_pair_t_mapnode_t * next_e = fd_vote_accounts_pair_t_map_acquire( next_pool );
3076
- // next_e->elem = n->elem;
3077
- // fd_vote_accounts_pair_t_map_insert( next_pool, &next_root, next_e );
3078
- // }
3038
+ uchar * epoch_stakes_vote_acc_region_curr = (uchar * )fd_ulong_align_up ( (ulong )vote_accounts_pool + fd_vote_accounts_pair_global_t_map_footprint ( 50000UL ), 8UL );
3039
+
3040
+ fd_vote_accounts_global_t * next_epoch_stakes = fd_bank_next_epoch_stakes_locking_modify ( slot_ctx -> bank );
3041
+ uchar * next_pool_mem = (uchar * )fd_ulong_align_up ( (ulong )next_epoch_stakes + sizeof (fd_vote_accounts_global_t ), fd_vote_accounts_pair_t_map_align () );
3042
+ fd_vote_accounts_pair_global_t_mapnode_t * next_pool = fd_vote_accounts_pair_global_t_map_join ( fd_vote_accounts_pair_global_t_map_new ( next_pool_mem , 50000UL ) );
3043
+ fd_vote_accounts_pair_global_t_mapnode_t * next_root = NULL ;
3044
+
3045
+ uchar * next_epoch_stakes_acc_region_curr = (uchar * )fd_ulong_align_up ( (ulong )next_pool + fd_vote_accounts_pair_global_t_map_footprint ( 50000UL ), 8UL );
3046
+
3047
+ for ( ulong i = 0UL ; i < genesis_block -> accounts_len ; i ++ ) {
3048
+ fd_pubkey_account_pair_t const * acc = & genesis_block -> accounts [i ];
3049
+
3050
+ if ( !memcmp ( acc -> account .owner .key , fd_solana_vote_program_id .key , sizeof (fd_pubkey_t ) ) ) {
3051
+
3052
+ /* Insert into the epoch_stakes vote accounts map */
3053
+ fd_vote_accounts_pair_global_t_mapnode_t * e = fd_vote_accounts_pair_global_t_map_acquire ( vote_accounts_pool );
3054
+ FD_TEST ( e );
3055
+ e -> elem .key = acc -> key ;
3056
+ e -> elem .stake = acc -> account .lamports ;
3057
+ e -> elem .value = (fd_solana_account_global_t ){
3058
+ .lamports = acc -> account .lamports ,
3059
+ .data_len = acc -> account .data_len ,
3060
+ .data_offset = 0UL , /* FIXME: remove this field from the cache altogether. */
3061
+ .owner = acc -> account .owner ,
3062
+ .executable = acc -> account .executable ,
3063
+ .rent_epoch = acc -> account .rent_epoch
3064
+ };
3065
+
3066
+ memcpy ( epoch_stakes_vote_acc_region_curr , acc -> account .data , acc -> account .data_len );
3067
+ e -> elem .value .data_offset = (ulong )(epoch_stakes_vote_acc_region_curr - (uchar * )& e -> elem .value );
3068
+ epoch_stakes_vote_acc_region_curr += acc -> account .data_len ;
3069
+
3070
+ fd_vote_accounts_pair_global_t_map_insert ( vote_accounts_pool , & vote_accounts_root , e );
3071
+
3072
+ /* Insert into the next_epoch_stakes vote accounts map */
3073
+ /* FIXME: is this correct? */
3074
+ fd_vote_accounts_pair_global_t_mapnode_t * next_e = fd_vote_accounts_pair_global_t_map_acquire ( next_pool );
3075
+ FD_TEST ( next_e );
3076
+ next_e -> elem .key = acc -> key ;
3077
+ next_e -> elem .stake = acc -> account .lamports ;
3078
+ next_e -> elem .value = (fd_solana_account_global_t ){
3079
+ .lamports = acc -> account .lamports ,
3080
+ .data_len = acc -> account .data_len ,
3081
+ .data_offset = 0UL , /* FIXME: remove this field from the cache altogether. */
3082
+ .owner = acc -> account .owner ,
3083
+ .executable = acc -> account .executable ,
3084
+ .rent_epoch = acc -> account .rent_epoch
3085
+ };
3086
+
3087
+ memcpy ( next_epoch_stakes_acc_region_curr , acc -> account .data , acc -> account .data_len );
3088
+ next_e -> elem .value .data_offset = (ulong )(next_epoch_stakes_acc_region_curr - (uchar * )& next_e -> elem .value );
3089
+ next_epoch_stakes_acc_region_curr += acc -> account .data_len ;
3090
+
3091
+ fd_vote_accounts_pair_global_t_map_insert ( next_pool , & next_root , next_e );
3092
+ }
3093
+
3094
+ }
3079
3095
3080
3096
for ( fd_delegation_pair_t_mapnode_t * n = fd_delegation_pair_t_map_minimum ( sacc_pool , sacc_root );
3081
3097
n ;
3082
3098
n = fd_delegation_pair_t_map_successor ( sacc_pool , n )) {
3083
- fd_vote_accounts_pair_t_mapnode_t query_voter = {0 };
3099
+ fd_vote_accounts_pair_global_t_mapnode_t query_voter = {0 };
3084
3100
query_voter .elem .key = n -> elem .delegation .voter_pubkey ;
3085
3101
3086
- fd_vote_accounts_pair_t_mapnode_t * voter = fd_vote_accounts_pair_t_map_find ( vacc_pool , vacc_root , & query_voter );
3102
+ fd_vote_accounts_pair_global_t_mapnode_t * voter = fd_vote_accounts_pair_global_t_map_find ( vacc_pool , vacc_root , & query_voter );
3087
3103
3088
3104
if ( !!voter ) {
3089
3105
voter -> elem .stake = fd_ulong_sat_add ( voter -> elem .stake , n -> elem .delegation .stake );
3090
3106
}
3091
3107
}
3092
3108
3093
- // epoch_bank->next_epoch_stakes = (fd_vote_accounts_t){
3094
- // .vote_accounts_pool = next_pool,
3095
- // .vote_accounts_root = next_root,
3096
- // };
3109
+ fd_vote_accounts_vote_accounts_pool_update ( epoch_stakes , vote_accounts_pool );
3110
+ fd_vote_accounts_vote_accounts_root_update ( epoch_stakes , vote_accounts_root );
3111
+
3112
+
3113
+ fd_vote_accounts_vote_accounts_pool_update ( next_epoch_stakes , next_pool );
3114
+ fd_vote_accounts_vote_accounts_root_update ( next_epoch_stakes , next_root );
3115
+
3116
+ fd_bank_epoch_stakes_end_locking_modify ( slot_ctx -> bank );
3117
+
3118
+ fd_bank_next_epoch_stakes_end_locking_modify ( slot_ctx -> bank );
3119
+
3120
+
3121
+
3122
+ stakes_global -> epoch = 0UL ;
3123
+ stakes_global -> unused = 0UL ;
3097
3124
3098
- /* Initializes the stakes cache in the Bank structure. */
3099
- // epoch_bank->stakes = (fd_stakes_t){
3100
- // .stake_delegations_pool = sacc_pool,
3101
- // .stake_delegations_root = sacc_root,
3102
- // .epoch = 0UL,
3103
- // .unused = 0UL,
3104
- // .vote_accounts = (fd_vote_accounts_t){
3105
- // .vote_accounts_pool = vacc_pool,
3106
- // .vote_accounts_root = vacc_root
3107
- // },
3108
- // .stake_history = {0}
3109
- // };
3125
+ fd_vote_accounts_vote_accounts_pool_update ( & stakes_global -> vote_accounts , vacc_pool );
3126
+ fd_vote_accounts_vote_accounts_root_update ( & stakes_global -> vote_accounts , vacc_root );
3127
+ fd_stakes_stake_delegations_pool_update ( stakes_global , sacc_pool );
3128
+ fd_stakes_stake_delegations_root_update ( stakes_global , sacc_root );
3129
+ fd_bank_stakes_end_locking_modify ( slot_ctx -> bank );
3110
3130
3111
3131
fd_bank_capitalization_set ( slot_ctx -> bank , capitalization );
3112
3132
@@ -3144,6 +3164,8 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx,
3144
3164
3145
3165
fd_bank_total_compute_units_used_set ( slot_ctx -> bank , 0UL );
3146
3166
3167
+ fd_runtime_init_program ( slot_ctx , runtime_spad );
3168
+
3147
3169
fd_sysvar_slot_history_update ( slot_ctx , runtime_spad );
3148
3170
3149
3171
fd_runtime_update_leaders ( slot_ctx -> bank , 0 , runtime_spad );
@@ -3220,13 +3242,19 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
3220
3242
fd_memcpy ( genesis_hash_bm , buf , sizeof (fd_hash_t ) );
3221
3243
3222
3244
if ( !is_snapshot ) {
3245
+ /* Create a new Funk transaction for slot 0 */
3246
+ fd_funk_txn_start_write ( slot_ctx -> funk );
3247
+ fd_funk_txn_xid_t xid = { 0 };
3248
+ xid .ul [1 ] = 0UL ;
3249
+ xid .ul [0 ] = 0UL ;
3250
+ slot_ctx -> funk_txn = fd_funk_txn_prepare ( slot_ctx -> funk , NULL , & xid , 1 );
3251
+ fd_funk_txn_end_write ( slot_ctx -> funk );
3252
+
3223
3253
fd_runtime_init_bank_from_genesis ( slot_ctx ,
3224
3254
genesis_block ,
3225
3255
& genesis_hash ,
3226
3256
runtime_spad );
3227
3257
3228
- fd_runtime_init_program ( slot_ctx , runtime_spad );
3229
-
3230
3258
FD_LOG_DEBUG (( "start genesis accounts - count: %lu" , genesis_block -> accounts_len ));
3231
3259
3232
3260
for ( ulong i = 0 ; i < genesis_block -> accounts_len ; i ++ ) {
0 commit comments