-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2356f17
commit 7a34721
Showing
11 changed files
with
1,033 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "fd_sysvar.h" | ||
#include "../context/fd_exec_epoch_ctx.h" | ||
#include "../context/fd_exec_slot_ctx.h" | ||
#include "fd_sysvar_rent.h" | ||
|
||
int | ||
fd_sysvar_set( fd_exec_slot_ctx_t * slot_ctx, | ||
uchar const * owner, | ||
fd_pubkey_t const * pubkey, | ||
uchar * data, | ||
ulong sz, | ||
ulong slot, | ||
ulong lamports ) { | ||
|
||
fd_acc_mgr_t * acc_mgr = slot_ctx->acc_mgr; | ||
fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; | ||
|
||
FD_BORROWED_ACCOUNT_DECL(rec); | ||
|
||
int err = fd_acc_mgr_modify( acc_mgr, funk_txn, pubkey, 1, sz, rec ); | ||
if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) | ||
return FD_ACC_MGR_ERR_READ_FAILED; | ||
|
||
fd_memcpy(rec->data, data, sz); | ||
// What is the correct behavior here? Where is this code in the | ||
// solana code base? Do I only adjust the lamports if the data | ||
// increases but not decreases? I am inventing money here... | ||
fd_acc_lamports_t lamports_before = rec->meta->info.lamports; | ||
rec->meta->info.lamports = (lamports == 0UL) ? fd_rent_exempt_minimum_balance2( &slot_ctx->epoch_ctx->epoch_bank.rent, sz ) : lamports; | ||
slot_ctx->slot_bank.capitalization = fd_ulong_sat_sub( | ||
fd_ulong_sat_add( | ||
slot_ctx->slot_bank.capitalization, | ||
rec->meta->info.lamports), | ||
lamports_before); | ||
// FD_LOG_DEBUG(("fd_sysvar_set: capitalization={%lu} increased by lamports: %lu for pubkey %32J", slot_ctx->slot_bank.capitalization, (rec->meta->info.lamports - lamports_before), pubkey)); | ||
|
||
|
||
rec->meta->dlen = sz; | ||
fd_memcpy(rec->meta->info.owner, owner, 32); | ||
rec->meta->slot = slot; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef HEADER_fd_src_flamenco_runtime_fd_sysvar_h | ||
#define HEADER_fd_src_flamenco_runtime_fd_sysvar_h | ||
|
||
#include "../../fd_flamenco_base.h" | ||
|
||
int | ||
fd_sysvar_set( fd_exec_slot_ctx_t * state, | ||
uchar const * owner, | ||
fd_pubkey_t const * pubkey, | ||
uchar * data, | ||
ulong sz, | ||
ulong slot, | ||
ulong lamports ); | ||
|
||
#endif /* HEADER_fd_src_flamenco_runtime_fd_sysvar_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include "fd_sysvar_stake_history.h" | ||
#include "../context/fd_exec_slot_ctx.h" | ||
#include "../../types/fd_types.h" | ||
#include "fd_sysvar.h" | ||
#include "../fd_system_ids.h" | ||
|
||
void | ||
write_stake_history( fd_exec_slot_ctx_t * slot_ctx, | ||
fd_stake_history_t * stake_history ) { | ||
/* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/sysvar/stake_history.rs#L12 */ | ||
uchar enc[16392] = {0}; | ||
|
||
fd_bincode_encode_ctx_t encode = | ||
{ .data = enc, | ||
.dataend = enc + sizeof(enc) }; | ||
if( FD_UNLIKELY( fd_stake_history_encode( stake_history, &encode )!=FD_BINCODE_SUCCESS ) ) | ||
FD_LOG_ERR(("fd_stake_history_encode failed")); | ||
|
||
fd_sysvar_set( slot_ctx, fd_sysvar_owner_id.key, &fd_sysvar_stake_history_id, enc, sizeof(enc), slot_ctx->slot_bank.slot, 0UL ); | ||
} | ||
|
||
fd_stake_history_t * | ||
fd_sysvar_stake_history_read( fd_stake_history_t * result, | ||
fd_exec_slot_ctx_t * slot_ctx, | ||
fd_valloc_t * valloc ) { | ||
|
||
FD_BORROWED_ACCOUNT_DECL(stake_rec); | ||
int err = fd_acc_mgr_view( slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_stake_history_id, stake_rec); | ||
if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) | ||
return NULL; | ||
|
||
fd_bincode_decode_ctx_t ctx = { | ||
.data = stake_rec->const_data, | ||
.dataend = (char *) stake_rec->const_data + stake_rec->const_meta->dlen, | ||
.valloc = *valloc | ||
}; | ||
|
||
if( FD_UNLIKELY( fd_stake_history_decode( result, &ctx )!=FD_BINCODE_SUCCESS ) ) | ||
return NULL; | ||
return result; | ||
} | ||
|
||
void | ||
fd_sysvar_stake_history_init( fd_exec_slot_ctx_t * slot_ctx ) { | ||
fd_stake_history_t stake_history = { | ||
.pool = fd_stake_history_pool_alloc( slot_ctx->valloc ), | ||
.treap = fd_stake_history_treap_alloc( slot_ctx->valloc ) | ||
}; | ||
write_stake_history( slot_ctx, &stake_history ); | ||
} | ||
|
||
void | ||
fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx, | ||
fd_stake_history_entry_t * entry ) { | ||
// Need to make this maybe zero copies of map... | ||
fd_stake_history_t stake_history; | ||
fd_sysvar_stake_history_read( &stake_history, slot_ctx, &slot_ctx->valloc ); | ||
|
||
if (fd_stake_history_treap_ele_cnt( stake_history.treap ) == fd_stake_history_treap_ele_max( stake_history.treap )) { | ||
fd_stake_history_treap_fwd_iter_t iter = fd_stake_history_treap_fwd_iter_init( stake_history.treap, stake_history.pool ); | ||
fd_stake_history_entry_t * ele = fd_stake_history_treap_fwd_iter_ele( iter, stake_history.pool ); | ||
stake_history.treap = fd_stake_history_treap_ele_remove( stake_history.treap, ele, stake_history.pool ); | ||
fd_stake_history_pool_ele_release( stake_history.pool, ele ); | ||
} | ||
|
||
ulong idx = fd_stake_history_pool_idx_acquire( stake_history.pool ); | ||
|
||
stake_history.pool[ idx ].epoch = entry->epoch; | ||
stake_history.pool[ idx ].activating = entry->activating; | ||
stake_history.pool[ idx ].effective = entry->effective; | ||
stake_history.pool[ idx ].deactivating = entry->deactivating; | ||
stake_history.treap = fd_stake_history_treap_idx_insert( stake_history.treap, idx, stake_history.pool ); | ||
|
||
|
||
write_stake_history( slot_ctx, &stake_history); | ||
fd_bincode_destroy_ctx_t destroy = { .valloc = slot_ctx->valloc }; | ||
fd_stake_history_destroy( &stake_history, &destroy ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef HEADER_fd_src_flamenco_runtime_fd_sysvar_stake_history_h | ||
#define HEADER_fd_src_flamenco_runtime_fd_sysvar_stake_history_h | ||
|
||
#include "../../fd_flamenco_base.h" | ||
#include "../fd_executor.h" | ||
|
||
FD_PROTOTYPES_BEGIN | ||
|
||
/* The stake history sysvar contains the history of cluster-wide activations and de-activations per-epoch. Updated at the start of each epoch. */ | ||
|
||
/* Initialize the stake history sysvar account. */ | ||
void | ||
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_PROTOTYPES_END | ||
|
||
#endif /* HEADER_fd_src_flamenco_runtime_fd_sysvar_stake_history_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ifdef FD_HAS_INT128 | ||
$(call add-hdrs,fd_stakes.h) | ||
$(call add-objs,fd_stakes,fd_flamenco) | ||
# TODO this should not depend on fd_funk | ||
$(call make-bin,fd_stakes_from_snapshot,fd_stakes_from_snapshot,fd_flamenco fd_funk fd_ballet fd_util) | ||
endif |
Oops, something went wrong.