Skip to content

flamenco: fix stakes_history_entry type #4983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/flamenco/runtime/program/fd_stake_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ fd_stake_history_ele_binary_search_const( fd_stake_history_t const * history,
while ( start<=end ) {
ulong mid = start + ( end - start ) / 2UL;
if( history->fd_stake_history[mid].epoch==epoch ) {
return &history->fd_stake_history[mid];
return &history->fd_stake_history[mid].entry;
} else if( history->fd_stake_history[mid].epoch<epoch ) {
if ( mid==0 ) return NULL;
end = mid - 1;
Expand Down Expand Up @@ -480,7 +480,7 @@ fd_stake_history_ele_query_const( fd_stake_history_t const * history,
ulong e = (off + history->fd_stake_history_offset) & (history->fd_stake_history_size - 1);

if ( history->fd_stake_history[e].epoch == epoch ) {
return &history->fd_stake_history[e];
return &history->fd_stake_history[e].entry;
}

// if the epoch did not match, we do a binary search
Expand Down
14 changes: 7 additions & 7 deletions src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx ) {
}

void
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
fd_stake_history_entry_t * entry,
fd_spad_t * runtime_spad ) {
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
fd_epoch_stake_history_entry_pair_t * pair,
fd_spad_t * runtime_spad ) {
// Need to make this maybe zero copies of map...
fd_stake_history_t * stake_history = fd_sysvar_stake_history_read( slot_ctx, runtime_spad );

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

stake_history->fd_stake_history[ idx ].epoch = entry->epoch;
stake_history->fd_stake_history[ idx ].activating = entry->activating;
stake_history->fd_stake_history[ idx ].effective = entry->effective;
stake_history->fd_stake_history[ idx ].deactivating = entry->deactivating;
stake_history->fd_stake_history[ idx ].epoch = pair->epoch;
stake_history->fd_stake_history[ idx ].entry.activating = pair->entry.activating;
stake_history->fd_stake_history[ idx ].entry.effective = pair->entry.effective;
stake_history->fd_stake_history[ idx ].entry.deactivating = pair->entry.deactivating;

write_stake_history( slot_ctx, stake_history );
}
8 changes: 4 additions & 4 deletions src/flamenco/runtime/sysvar/fd_sysvar_stake_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* FD_SYSVAR_STAKE_HISTORY_CAP is the max number of entries that the
"stake history" sysvar will include.

https://github.com/anza-xyz/agave/blob/6398ddf6ab8a8f81017bf675ab315a70067f0bf0/sdk/program/src/stake_history.rs#L12 */

#define FD_SYSVAR_STAKE_HISTORY_CAP (512UL)
Expand All @@ -21,9 +21,9 @@ fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx );

/* Update the stake history sysvar account - called during epoch boundary*/
void
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
fd_stake_history_entry_t * entry,
fd_spad_t * runtime_spad );
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
fd_epoch_stake_history_entry_pair_t * pair,
fd_spad_t * runtime_spad );

FD_PROTOTYPES_END

Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/runtime/tests/harness/fd_txn_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner,
/* Provide default stake history if not provided */
if( !slot_ctx->sysvar_cache->has_stake_history ) {
// Provide a 0-set default entry
fd_stake_history_entry_t entry = {0};
fd_epoch_stake_history_entry_pair_t entry = {0};
fd_sysvar_stake_history_init( slot_ctx );
fd_sysvar_stake_history_update( slot_ctx, &entry, runner->spad );
}
Expand Down
10 changes: 6 additions & 4 deletions src/flamenco/stakes/fd_stakes.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,13 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx,
runtime_spad );

/* https://github.com/anza-xyz/agave/blob/v2.1.6/runtime/src/stakes.rs#L359 */
fd_stake_history_entry_t new_elem = {
fd_epoch_stake_history_entry_pair_t new_elem = {
.epoch = stakes->epoch,
.effective = accumulator.effective,
.activating = accumulator.activating,
.deactivating = accumulator.deactivating
.entry = {
.effective = accumulator.effective,
.activating = accumulator.activating,
.deactivating = accumulator.deactivating
}
};

fd_sysvar_stake_history_update( slot_ctx, &new_elem, runtime_spad );
Expand Down
12 changes: 10 additions & 2 deletions src/flamenco/types/fd_fuzz_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,21 @@ void *fd_stake_history_entry_generate( void *mem, void **alloc_mem, fd_rng_t * r
fd_stake_history_entry_t *self = (fd_stake_history_entry_t *) mem;
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_stake_history_entry_t);
fd_stake_history_entry_new(mem);
self->epoch = fd_rng_ulong( rng );
self->effective = fd_rng_ulong( rng );
self->activating = fd_rng_ulong( rng );
self->deactivating = fd_rng_ulong( rng );
return mem;
}

void *fd_epoch_stake_history_entry_pair_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
fd_epoch_stake_history_entry_pair_t *self = (fd_epoch_stake_history_entry_pair_t *) mem;
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_epoch_stake_history_entry_pair_t);
fd_epoch_stake_history_entry_pair_new(mem);
self->epoch = fd_rng_ulong( rng );
fd_stake_history_entry_generate( &self->entry, alloc_mem, rng );
return mem;
}

void *fd_stake_history_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
fd_stake_history_t *self = (fd_stake_history_t *) mem;
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_stake_history_t);
Expand All @@ -258,7 +266,7 @@ void *fd_stake_history_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
self->fd_stake_history_size = 512;
self->fd_stake_history_offset = 0;
for( ulong i=0; i<self->fd_stake_history_len; i++ ) {
fd_stake_history_entry_generate( self->fd_stake_history + i, alloc_mem, rng );
fd_epoch_stake_history_entry_pair_generate( self->fd_stake_history + i, alloc_mem, rng );
}
return mem;
}
Expand Down
62 changes: 48 additions & 14 deletions src/flamenco/types/fd_types.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions src/flamenco/types/fd_types.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/flamenco/types/fd_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,24 @@
"name": "stake_history_entry",
"type": "struct",
"fields": [
{ "name": "epoch", "type": "ulong" },
{ "name": "effective", "type": "ulong" },
{ "name": "activating", "type": "ulong" },
{ "name": "deactivating", "type": "ulong" }
]
},
{
"name": "epoch_stake_history_entry_pair",
"type": "struct",
"fields": [
{ "name": "epoch", "type": "ulong" },
{ "name": "entry", "type": "stake_history_entry" }
]
},
{
"name": "stake_history",
"type": "struct",
"fields": [
{ "name": "fd_stake_history", "type": "static_vector", "element": "stake_history_entry", "size": 512 }
{ "name": "fd_stake_history", "type": "static_vector", "element": "epoch_stake_history_entry_pair", "size": 512 }
],
"comment": "https://github.com/firedancer-io/solana/blob/v1.17/sdk/program/src/stake_history.rs#L12-L75"
},
Expand Down
Loading
Loading