@@ -16,15 +16,14 @@ static const ulong bits_per_block = 8 * sizeof(ulong);
16
16
17
17
void
18
18
fd_sysvar_slot_history_set ( fd_slot_history_global_t * history ,
19
- ulong i ,
20
- fd_wksp_t * wksp ) {
19
+ ulong i ) {
21
20
if ( FD_UNLIKELY ( i > history -> next_slot && i - history -> next_slot >= slot_history_max_entries ) ) {
22
21
FD_LOG_WARNING (( "Ignoring out of bounds (i=%lu next_slot=%lu)" , i , history -> next_slot ));
23
22
return ;
24
23
}
25
24
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 );
28
27
ulong blocks_len = inner -> blocks_len ;
29
28
30
29
// Skipped slots, delete them from history
@@ -58,25 +57,28 @@ fd_sysvar_slot_history_write_history( fd_exec_slot_ctx_t * slot_ctx,
58
57
void
59
58
fd_sysvar_slot_history_init ( fd_exec_slot_ctx_t * slot_ctx , fd_spad_t * runtime_spad ) {
60
59
/* Create a new slot history instance */
61
- fd_slot_history_global_t history = {0 };
62
60
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 ;
66
65
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 ) );
69
70
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 );
71
77
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 ;
74
78
75
79
/* 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 );
80
82
}
81
83
82
84
/* 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
111
113
fd_slot_history_global_t * history = fd_slot_history_decode_global ( mem , & ctx );
112
114
113
115
/* 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 );
115
117
history -> next_slot = slot_ctx -> slot_bank .slot + 1 ;
116
118
117
119
ulong sz = slot_history_min_account_size ;
@@ -181,11 +183,12 @@ int
181
183
fd_sysvar_slot_history_find_slot ( fd_slot_history_global_t const * history ,
182
184
ulong slot ,
183
185
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 );
185
188
if ( FD_UNLIKELY ( !inner ) ) {
186
189
FD_LOG_ERR (( "Unable to find slot history inner" ));
187
190
}
188
- ulong * blocks = fd_wksp_laddr_fast ( wksp , inner -> blocks_gaddr );
191
+ ulong * blocks = ( ulong * )(( uchar * ) inner + inner -> blocks_offset );
189
192
if ( FD_UNLIKELY ( !blocks ) ) {
190
193
FD_LOG_ERR (( "Unable to find slot history blocks" ));
191
194
}
0 commit comments