Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_stakes_fd_stakes_h
2 : #define HEADER_fd_src_flamenco_stakes_fd_stakes_h
3 :
4 : #include "fd_stake_delegations.h"
5 : #include "fd_stake_types.h"
6 : #include "fd_stake_weight.h"
7 : #include "fd_vote_stakes.h"
8 : #include "../types/fd_cast.h"
9 :
10 : FD_PROTOTYPES_BEGIN
11 :
12 : fd_stake_state_t const *
13 : fd_stakes_get_state( fd_acc_t const * acc );
14 :
15 : fd_stake_history_entry_t
16 : stake_activating_and_deactivating( fd_delegation_t const * self,
17 : ulong target_epoch,
18 : fd_stake_history_t const * stake_history,
19 : ulong * new_rate_activation_epoch );
20 :
21 : /* Caller must ensure cluster_portion is nonzero. */
22 :
23 : static inline ulong
24 : fd_stake_calculate_change_allowance_float( ulong current_epoch,
25 : ulong account_portion,
26 : ulong cluster_portion,
27 : ulong cluster_effective,
28 0 : ulong * new_rate_activation_epoch ) {
29 0 : double weight = (double)account_portion / (double)cluster_portion;
30 0 : double warmup_cooldown_rate = fd_stake_delegations_warmup_cooldown_rate_to_double( fd_stake_warmup_cooldown_rate( current_epoch, new_rate_activation_epoch ) );
31 0 : double newly_changed_cluster_stake = (double)cluster_effective * warmup_cooldown_rate;
32 0 : return fd_rust_cast_double_to_ulong( weight * newly_changed_cluster_stake );
33 0 : }
34 :
35 : ulong
36 : fd_stake_calculate_activation_allowance( ulong current_epoch,
37 : ulong account_activating_stake,
38 : fd_stake_history_entry_t const * prev_epoch_cluster_state,
39 : ulong * opt_rate_change_activation_epoch );
40 :
41 : /* https://github.com/anza-xyz/agave/blob/v4.2.0-beta.1/runtime/src/stake_delegation.rs#L27-L41 */
42 : fd_stake_history_entry_t
43 : fd_delegation_activation_status( fd_delegation_t const * delegation,
44 : ulong target_epoch,
45 : fd_stake_history_t const * stake_history,
46 : ulong * new_rate_activation_epoch,
47 : int use_fixed_point_stake_math );
48 :
49 : int
50 : fd_delegation_is_inactive( fd_delegation_t const * delegation,
51 : ulong target_epoch,
52 : fd_stake_history_t const * stake_history,
53 : ulong * new_rate_activation_epoch,
54 : int use_fixed_point_stake_math );
55 :
56 : fd_stake_history_entry_t
57 : fd_stake_delegation_activation_status( fd_stake_delegation_t const * delegation,
58 : ulong target_epoch,
59 : fd_stake_history_t const * stake_history,
60 : ulong * new_rate_activation_epoch,
61 : int use_fixed_point_stake_math );
62 :
63 : int
64 : fd_stake_delegation_is_inactive( fd_stake_delegation_t const * delegation,
65 : ulong target_epoch,
66 : fd_stake_history_t const * stake_history,
67 : ulong * new_rate_activation_epoch,
68 : int use_fixed_point_stake_math );
69 :
70 : /* fd_stake_weights_by_node converts Stakes (unordered list of (vote
71 : acc, active stake) tuples) to an ordered list of (stake, vote pubkey, node
72 : identity) sorted by (stake descending, vote pubkey descending).
73 :
74 : iter_kind selects the vote stakes set: FD_VOTE_STAKES_ITER_T_1 (next
75 : epoch), T_2 (current epoch) or T_3 (previous epoch).
76 :
77 : weights points to an array suitable to hold ...
78 :
79 : fd_vote_accounts_pair_t_map_size( accs->vote_accounts_pool,
80 : accs->vote_accounts_root )
81 :
82 : ... items. On return, weights be an ordered list.
83 :
84 : Returns the number of items in weights (which is <= no of vote accs). */
85 :
86 : ulong
87 : fd_stake_weights_by_node( fd_vote_stakes_t const * vote_stakes,
88 : ulong fork_id,
89 : int iter_kind,
90 : fd_vote_stake_weight_t * weights );
91 :
92 : void
93 : fd_stakes_activate_epoch( fd_bank_t * bank,
94 : fd_runtime_stack_t * runtime_stack,
95 : fd_accdb_t * accdb,
96 : fd_capture_ctx_t * capture_ctx,
97 : fd_stake_delegations_t * stake_delegations,
98 : ulong * new_rate_activation_epoch );
99 :
100 : /* rewarded_epoch selects the epoch whose effective delegated stakes
101 : should be accumulated for rewards. ULONG_MAX disables this work. */
102 : void
103 : fd_refresh_vote_accounts( fd_bank_t * bank,
104 : fd_accdb_t * accdb,
105 : fd_runtime_stack_t * runtime_stack,
106 : fd_stake_delegations_t const * stake_delegations,
107 : fd_stake_history_t const * history,
108 : ulong rewarded_epoch,
109 : ulong * new_rate_activation_epoch );
110 :
111 : /* fd_stakes_update_delegation is used to maintain the in-memory cache
112 : of the stake delegations that is used at the epoch boundary. Entries
113 : in the cache will be inserted/updated/removed based on the state of
114 : the stake account. */
115 :
116 : void
117 : fd_stakes_update_stake_delegation( fd_pubkey_t const * pubkey,
118 : fd_acc_t const * acc,
119 : fd_bank_t * bank,
120 : fd_txn_in_t const * txn_in );
121 :
122 : FD_PROTOTYPES_END
123 :
124 : #endif /* HEADER_fd_src_flamenco_stakes_fd_stakes_h */
|