@@ -16,15 +16,14 @@ static const ulong bits_per_block = 8 * sizeof(ulong);
1616
1717void
1818fd_sysvar_slot_history_set ( fd_slot_history_global_t * history ,
19- ulong i ,
20- fd_wksp_t * wksp ) {
19+ ulong i ) {
2120 if ( FD_UNLIKELY ( i > history -> next_slot && i - history -> next_slot >= slot_history_max_entries ) ) {
2221 FD_LOG_WARNING (( "Ignoring out of bounds (i=%lu next_slot=%lu)" , i , history -> next_slot ));
2322 return ;
2423 }
2524
26- fd_slot_history_inner_global_t * inner = fd_wksp_laddr_fast ( wksp , history -> bits .bits_gaddr );
27- ulong * blocks = fd_wksp_laddr_fast ( wksp , inner -> blocks_gaddr );
25+ fd_slot_history_inner_global_t * inner = ( fd_slot_history_inner_global_t * )(( uchar * ) & history -> bits + history -> bits .bits_offset );
26+ ulong * blocks = ( ulong * )(( uchar * ) inner + inner -> blocks_offset );
2827 ulong blocks_len = inner -> blocks_len ;
2928
3029 // Skipped slots, delete them from history
@@ -58,25 +57,28 @@ fd_sysvar_slot_history_write_history( fd_exec_slot_ctx_t * slot_ctx,
5857void
5958fd_sysvar_slot_history_init ( fd_exec_slot_ctx_t * slot_ctx , fd_spad_t * runtime_spad ) {
6059 /* Create a new slot history instance */
61- fd_slot_history_global_t history = {0 };
6260
63- fd_slot_history_inner_global_t * inner = fd_spad_alloc ( runtime_spad ,
64- fd_slot_history_inner_align (),
65- fd_slot_history_inner_footprint () );
61+ /* We need to construct the gaddr-aware slot history object */
62+ ulong total_sz = sizeof (fd_slot_history_global_t ) + alignof(fd_slot_history_global_t ) +
63+ sizeof (fd_slot_history_inner_global_t ) + alignof(fd_slot_history_inner_global_t ) +
64+ (sizeof (ulong ) + alignof(ulong )) * blocks_len ;
6665
67- history .bits .bits_gaddr = fd_wksp_gaddr_fast ( slot_ctx -> runtime_wksp , inner );
68- history .bits .len = slot_history_max_entries ;
66+ uchar * mem = fd_spad_alloc ( runtime_spad , alignof(fd_slot_history_global_t ), total_sz );
67+ fd_slot_history_global_t * history = (fd_slot_history_global_t * )mem ;
68+ fd_slot_history_inner_global_t * inner = (fd_slot_history_inner_global_t * )fd_ulong_align_up ( (ulong )((uchar * )history + sizeof (fd_slot_history_global_t )), alignof(fd_slot_history_inner_global_t ) );
69+ ulong * blocks = (ulong * )fd_ulong_align_up ( (ulong )((uchar * )inner + sizeof (fd_slot_history_inner_global_t )), alignof(ulong ) );
6970
70- ulong * blocks = fd_spad_alloc ( runtime_spad , alignof(ulong ), sizeof (ulong ) * blocks_len );
71+ history -> next_slot = slot_ctx -> slot_bank .slot + 1UL ;
72+ history -> bits .bits_offset = (ulong )((uchar * )inner - (uchar * )history );
73+ history -> bits .len = slot_history_max_entries ;
74+
75+ inner -> blocks_len = blocks_len ;
76+ inner -> blocks_offset = (ulong )((uchar * )blocks - (uchar * )inner );
7177 memset ( blocks , 0 , sizeof (ulong ) * blocks_len );
72- inner -> blocks_gaddr = fd_wksp_gaddr_fast ( slot_ctx -> runtime_wksp , blocks );
73- inner -> blocks_len = blocks_len ;
7478
7579 /* TODO: handle slot != 0 init case */
76- fd_sysvar_slot_history_set ( & history , slot_ctx -> slot_bank .slot , slot_ctx -> runtime_wksp );
77- history .next_slot = slot_ctx -> slot_bank .slot + 1 ;
78-
79- fd_sysvar_slot_history_write_history ( slot_ctx , & history );
80+ fd_sysvar_slot_history_set ( history , slot_ctx -> slot_bank .slot );
81+ fd_sysvar_slot_history_write_history ( slot_ctx , history );
8082}
8183
8284/* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/runtime/src/bank.rs#L2345 */
@@ -111,7 +113,7 @@ fd_sysvar_slot_history_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtim
111113 fd_slot_history_global_t * history = fd_slot_history_decode_global ( mem , & ctx );
112114
113115 /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/slot_history.rs#L48 */
114- fd_sysvar_slot_history_set ( history , slot_ctx -> slot_bank .slot , slot_ctx -> runtime_wksp );
116+ fd_sysvar_slot_history_set ( history , slot_ctx -> slot_bank .slot );
115117 history -> next_slot = slot_ctx -> slot_bank .slot + 1 ;
116118
117119 ulong sz = slot_history_min_account_size ;
@@ -181,11 +183,12 @@ int
181183fd_sysvar_slot_history_find_slot ( fd_slot_history_global_t const * history ,
182184 ulong slot ,
183185 fd_wksp_t * wksp ) {
184- fd_slot_history_inner_global_t * inner = fd_wksp_laddr_fast ( wksp , history -> bits .bits_gaddr );
186+ (void )wksp ;
187+ fd_slot_history_inner_global_t * inner = (fd_slot_history_inner_global_t * )((uchar * )& history -> bits + history -> bits .bits_offset );
185188 if ( FD_UNLIKELY ( !inner ) ) {
186189 FD_LOG_ERR (( "Unable to find slot history inner" ));
187190 }
188- ulong * blocks = fd_wksp_laddr_fast ( wksp , inner -> blocks_gaddr );
191+ ulong * blocks = ( ulong * )(( uchar * ) inner + inner -> blocks_offset );
189192 if ( FD_UNLIKELY ( !blocks ) ) {
190193 FD_LOG_ERR (( "Unable to find slot history blocks" ));
191194 }
0 commit comments