Skip to content

Commit adaf37e

Browse files
flamenco: fix stakes_history_entry type
1 parent 19343bd commit adaf37e

File tree

10 files changed

+108
-29
lines changed

10 files changed

+108
-29
lines changed

src/flamenco/runtime/program/fd_stake_program.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ fd_stake_history_ele_binary_search_const( fd_stake_history_t const * history,
450450
while ( start<=end ) {
451451
ulong mid = start + ( end - start ) / 2UL;
452452
if( history->fd_stake_history[mid].epoch==epoch ) {
453-
return &history->fd_stake_history[mid];
453+
return &history->fd_stake_history[mid].entry;
454454
} else if( history->fd_stake_history[mid].epoch<epoch ) {
455455
if ( mid==0 ) return NULL;
456456
end = mid - 1;
@@ -480,7 +480,7 @@ fd_stake_history_ele_query_const( fd_stake_history_t const * history,
480480
ulong e = (off + history->fd_stake_history_offset) & (history->fd_stake_history_size - 1);
481481

482482
if ( history->fd_stake_history[e].epoch == epoch ) {
483-
return &history->fd_stake_history[e];
483+
return &history->fd_stake_history[e].entry;
484484
}
485485

486486
// if the epoch did not match, we do a binary search

src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx ) {
4444
}
4545

4646
void
47-
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
48-
fd_stake_history_entry_t * entry,
49-
fd_spad_t * runtime_spad ) {
47+
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
48+
fd_epoch_stake_history_entry_pair_t * pair,
49+
fd_spad_t * runtime_spad ) {
5050
// Need to make this maybe zero copies of map...
5151
fd_stake_history_t * stake_history = fd_sysvar_stake_history_read( slot_ctx, runtime_spad );
5252

@@ -63,10 +63,10 @@ fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
6363
// This should be done with a bit mask
6464
ulong idx = stake_history->fd_stake_history_offset;
6565

66-
stake_history->fd_stake_history[ idx ].epoch = entry->epoch;
67-
stake_history->fd_stake_history[ idx ].activating = entry->activating;
68-
stake_history->fd_stake_history[ idx ].effective = entry->effective;
69-
stake_history->fd_stake_history[ idx ].deactivating = entry->deactivating;
66+
stake_history->fd_stake_history[ idx ].epoch = pair->epoch;
67+
stake_history->fd_stake_history[ idx ].entry.activating = pair->entry.activating;
68+
stake_history->fd_stake_history[ idx ].entry.effective = pair->entry.effective;
69+
stake_history->fd_stake_history[ idx ].entry.deactivating = pair->entry.deactivating;
7070

7171
write_stake_history( slot_ctx, stake_history );
7272
}

src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx );
2121

2222
/* Update the stake history sysvar account - called during epoch boundary*/
2323
void
24-
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
25-
fd_stake_history_entry_t * entry,
26-
fd_spad_t * runtime_spad );
24+
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
25+
fd_epoch_stake_history_entry_pair_t * pair,
26+
fd_spad_t * runtime_spad );
2727

2828
FD_PROTOTYPES_END
2929

src/flamenco/runtime/tests/harness/fd_txn_harness.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner,
144144
/* Provide default stake history if not provided */
145145
if( !slot_ctx->sysvar_cache->has_stake_history ) {
146146
// Provide a 0-set default entry
147-
fd_stake_history_entry_t entry = {0};
147+
fd_epoch_stake_history_entry_pair_t entry = {0};
148148
fd_sysvar_stake_history_init( slot_ctx );
149149
fd_sysvar_stake_history_update( slot_ctx, &entry, runner->spad );
150150
}

src/flamenco/stakes/fd_stakes.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,13 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx,
672672
runtime_spad );
673673

674674
/* https://github.com/anza-xyz/agave/blob/v2.1.6/runtime/src/stakes.rs#L359 */
675-
fd_stake_history_entry_t new_elem = {
675+
fd_epoch_stake_history_entry_pair_t new_elem = {
676676
.epoch = stakes->epoch,
677-
.effective = accumulator.effective,
678-
.activating = accumulator.activating,
679-
.deactivating = accumulator.deactivating
677+
.entry = {
678+
.effective = accumulator.effective,
679+
.activating = accumulator.activating,
680+
.deactivating = accumulator.deactivating
681+
}
680682
};
681683

682684
fd_sysvar_stake_history_update( slot_ctx, &new_elem, runtime_spad );

src/flamenco/types/fd_fuzz_types.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ void *fd_stake_history_entry_generate( void *mem, void **alloc_mem, fd_rng_t * r
250250
return mem;
251251
}
252252

253+
void *fd_epoch_stake_history_entry_pair_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
254+
fd_epoch_stake_history_entry_pair_t *self = (fd_epoch_stake_history_entry_pair_t *) mem;
255+
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_epoch_stake_history_entry_pair_t);
256+
fd_epoch_stake_history_entry_pair_new(mem);
257+
self->epoch = fd_rng_ulong( rng );
258+
fd_stake_history_entry_generate( &self->entry, alloc_mem, rng );
259+
return mem;
260+
}
261+
253262
void *fd_stake_history_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
254263
fd_stake_history_t *self = (fd_stake_history_t *) mem;
255264
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_stake_history_t);
@@ -258,7 +267,7 @@ void *fd_stake_history_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
258267
self->fd_stake_history_size = 512;
259268
self->fd_stake_history_offset = 0;
260269
for( ulong i=0; i<self->fd_stake_history_len; i++ ) {
261-
fd_stake_history_entry_generate( self->fd_stake_history + i, alloc_mem, rng );
270+
fd_epoch_stake_history_entry_pair_generate( self->fd_stake_history + i, alloc_mem, rng );
262271
}
263272
return mem;
264273
}

src/flamenco/types/fd_types.c

+47-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/types/fd_types.h

+21-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/types/fd_types.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,19 @@
169169
{ "name": "deactivating", "type": "ulong" }
170170
]
171171
},
172+
{
173+
"name": "epoch_stake_history_entry_pair",
174+
"type": "struct",
175+
"fields": [
176+
{ "name": "epoch", "type": "ulong" },
177+
{ "name": "entry", "type": "stake_history_entry" }
178+
]
179+
},
172180
{
173181
"name": "stake_history",
174182
"type": "struct",
175183
"fields": [
176-
{ "name": "fd_stake_history", "type": "static_vector", "element": "stake_history_entry", "size": 512 }
184+
{ "name": "fd_stake_history", "type": "static_vector", "element": "epoch_stake_history_entry_pair", "size": 512 }
177185
],
178186
"comment": "https://github.com/firedancer-io/solana/blob/v1.17/sdk/program/src/stake_history.rs#L12-L75"
179187
},

src/flamenco/types/fd_types_reflect_generated.c

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)