Skip to content

Commit 5e1821b

Browse files
flamenco: fix stakes_history_entry type
1 parent 759c656 commit 5e1821b

File tree

10 files changed

+112
-41
lines changed

10 files changed

+112
-41
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/* FD_SYSVAR_STAKE_HISTORY_CAP is the max number of entries that the
88
"stake history" sysvar will include.
9-
9+
1010
https://github.com/anza-xyz/agave/blob/6398ddf6ab8a8f81017bf675ab315a70067f0bf0/sdk/program/src/stake_history.rs#L12 */
1111

1212
#define FD_SYSVAR_STAKE_HISTORY_CAP (512UL)
@@ -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-2
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,21 @@ void *fd_stake_history_entry_generate( void *mem, void **alloc_mem, fd_rng_t * r
243243
fd_stake_history_entry_t *self = (fd_stake_history_entry_t *) mem;
244244
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_stake_history_entry_t);
245245
fd_stake_history_entry_new(mem);
246-
self->epoch = fd_rng_ulong( rng );
247246
self->effective = fd_rng_ulong( rng );
248247
self->activating = fd_rng_ulong( rng );
249248
self->deactivating = fd_rng_ulong( rng );
250249
return mem;
251250
}
252251

252+
void *fd_epoch_stake_history_entry_pair_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
253+
fd_epoch_stake_history_entry_pair_t *self = (fd_epoch_stake_history_entry_pair_t *) mem;
254+
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_epoch_stake_history_entry_pair_t);
255+
fd_epoch_stake_history_entry_pair_new(mem);
256+
self->epoch = fd_rng_ulong( rng );
257+
fd_stake_history_entry_generate( &self->entry, alloc_mem, rng );
258+
return mem;
259+
}
260+
253261
void *fd_stake_history_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
254262
fd_stake_history_t *self = (fd_stake_history_t *) mem;
255263
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_stake_history_t);
@@ -258,7 +266,7 @@ void *fd_stake_history_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
258266
self->fd_stake_history_size = 512;
259267
self->fd_stake_history_offset = 0;
260268
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 );
269+
fd_epoch_stake_history_entry_pair_generate( self->fd_stake_history + i, alloc_mem, rng );
262270
}
263271
return mem;
264272
}

src/flamenco/types/fd_types.c

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

src/flamenco/types/fd_types.h

+23-4
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-2
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,24 @@
163163
"name": "stake_history_entry",
164164
"type": "struct",
165165
"fields": [
166-
{ "name": "epoch", "type": "ulong" },
167166
{ "name": "effective", "type": "ulong" },
168167
{ "name": "activating", "type": "ulong" },
169168
{ "name": "deactivating", "type": "ulong" }
170169
]
171170
},
171+
{
172+
"name": "epoch_stake_history_entry_pair",
173+
"type": "struct",
174+
"fields": [
175+
{ "name": "epoch", "type": "ulong" },
176+
{ "name": "entry", "type": "stake_history_entry" }
177+
]
178+
},
172179
{
173180
"name": "stake_history",
174181
"type": "struct",
175182
"fields": [
176-
{ "name": "fd_stake_history", "type": "static_vector", "element": "stake_history_entry", "size": 512 }
183+
{ "name": "fd_stake_history", "type": "static_vector", "element": "epoch_stake_history_entry_pair", "size": 512 }
177184
],
178185
"comment": "https://github.com/firedancer-io/solana/blob/v1.17/sdk/program/src/stake_history.rs#L12-L75"
179186
},

0 commit comments

Comments
 (0)