Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_leaders_fd_leaders_base_h 2 : #define HEADER_fd_src_flamenco_leaders_fd_leaders_base_h 3 : 4 : #include "../stakes/fd_stake_weight.h" 5 : #include "../runtime/sysvar/fd_sysvar_base.h" 6 : #include "../features/fd_features.h" 7 : 8 592038 : #define MAX_SHRED_DESTS 40200UL /* 200 * 201 - 1 (exclude self) */ 9 6 : #define MAX_SLOTS_PER_EPOCH 432000UL 10 33 : #define MAX_STAKE_WEIGHTS 2000UL /* validator_admission_ticket limit */ 11 : 12 : /* Follows message structure in fd_stake_ci_stake_msg_init. */ 13 : struct fd_stake_weight_msg_t { 14 : ulong epoch; /* Epoch for which the stake weights are valid */ 15 : ulong staked_vote_cnt; /* Number of staked nodes */ 16 : ulong staked_id_cnt; /* Number of staked nodes */ 17 : ulong start_slot; /* Start slot of the epoch */ 18 : ulong slot_cnt; /* Number of slots in the epoch */ 19 : ulong ns_per_slot; /* Slot time duration */ 20 : }; 21 : typedef struct fd_stake_weight_msg_t fd_stake_weight_msg_t; 22 : 23 606 : #define FD_STAKE_CI_STAKE_MSG_HEADER_SZ (sizeof(fd_stake_weight_msg_t)) 24 267 : #define FD_STAKE_CI_STAKE_MSG_RECORD_SZ (sizeof(fd_vote_stake_weight_t)) 25 : #define FD_STAKE_CI_ID_WEIGHT_RECORD_SZ (sizeof(fd_stake_weight_t)) 26 : #define FD_STAKE_CI_STAKE_MSG_SZ (FD_STAKE_CI_STAKE_MSG_HEADER_SZ + MAX_STAKE_WEIGHTS * (FD_STAKE_CI_STAKE_MSG_RECORD_SZ + FD_STAKE_CI_ID_WEIGHT_RECORD_SZ)) 27 : 28 : #define FD_STAKE_OUT_MTU FD_STAKE_CI_STAKE_MSG_SZ 29 : 30 : static inline ulong fd_stake_weight_msg_sz( ulong staked_vote_cnt, 31 0 : ulong staked_id_cnt ) { 32 0 : return FD_STAKE_CI_STAKE_MSG_HEADER_SZ + staked_vote_cnt * FD_STAKE_CI_STAKE_MSG_RECORD_SZ + staked_id_cnt * FD_STAKE_CI_ID_WEIGHT_RECORD_SZ; 33 0 : } 34 : 35 : static inline fd_vote_stake_weight_t * 36 339 : fd_stake_weight_msg_stake_weights( fd_stake_weight_msg_t const * stake_weight_msg ) { 37 339 : return (fd_vote_stake_weight_t *)fd_type_pun( (uchar *)stake_weight_msg + FD_STAKE_CI_STAKE_MSG_HEADER_SZ ); 38 339 : } 39 : 40 : static inline fd_stake_weight_t * 41 267 : fd_stake_weight_msg_id_weights( fd_stake_weight_msg_t const * stake_weight_msg ) { 42 267 : return (fd_stake_weight_t *)fd_type_pun( (uchar *)stake_weight_msg + FD_STAKE_CI_STAKE_MSG_HEADER_SZ + stake_weight_msg->staked_vote_cnt * FD_STAKE_CI_STAKE_MSG_RECORD_SZ ); 43 267 : } 44 : 45 : /* Firedancer only */ 46 : struct fd_epoch_info_msg_t { 47 : ulong epoch; /* Epoch for which the info is valid */ 48 : ulong staked_vote_cnt; /* Number of staked nodes */ 49 : ulong staked_id_cnt; /* Number of staked nodes */ 50 : ulong start_slot; /* Start slot of the epoch */ 51 : ulong slot_cnt; /* Number of slots in the epoch */ 52 : ulong ns_per_slot; /* Slot time duration */ 53 : fd_epoch_schedule_t epoch_schedule; /* Epoch schedule */ 54 : fd_features_t features; /* Feature activation slots */ 55 : }; 56 : typedef struct fd_epoch_info_msg_t fd_epoch_info_msg_t; 57 : 58 429 : #define FD_EPOCH_INFO_MSG_HEADER_SZ (sizeof(fd_epoch_info_msg_t)) 59 3 : #define FD_EPOCH_INFO_MAX_MSG_SZ (FD_EPOCH_INFO_MSG_HEADER_SZ + MAX_STAKE_WEIGHTS * (sizeof(fd_vote_stake_weight_t) + sizeof(fd_stake_weight_t))) 60 3 : #define FD_EPOCH_OUT_MTU FD_EPOCH_INFO_MAX_MSG_SZ 61 : 62 : static inline ulong fd_epoch_info_msg_sz( ulong vote_cnt, 63 12 : ulong id_weight_cnt ) { 64 12 : return FD_EPOCH_INFO_MSG_HEADER_SZ + 65 12 : (vote_cnt * sizeof(fd_vote_stake_weight_t)) + 66 12 : (id_weight_cnt * sizeof(fd_stake_weight_t)); 67 12 : } 68 : 69 : static inline fd_vote_stake_weight_t * 70 210 : fd_epoch_info_msg_stake_weights( fd_epoch_info_msg_t const * epoch_info_msg ) { 71 210 : return (fd_vote_stake_weight_t *)fd_type_pun( (uchar *)epoch_info_msg + FD_EPOCH_INFO_MSG_HEADER_SZ ); 72 210 : } 73 : 74 : static inline fd_stake_weight_t * 75 204 : fd_epoch_info_msg_id_weights( fd_epoch_info_msg_t const * epoch_info_msg ) { 76 204 : return (fd_stake_weight_t *)fd_type_pun( (uchar *)epoch_info_msg + FD_EPOCH_INFO_MSG_HEADER_SZ + epoch_info_msg->staked_vote_cnt * sizeof(fd_vote_stake_weight_t) ); 77 204 : } 78 : 79 : /* compute_id_weights_from_vote_weights() translates vote-based 80 : stake weights into (older) identity-based stake weights. 81 : 82 : Before SIMD-0180, the leader schedule was generated starting from 83 : a list [(id, stake)] where `id` is the validator identity and 84 : `stake` its aggregated stake, and the same list was used to build 85 : the Turbine tree. 86 : 87 : After SIMD-0180, the leader schedule is generated by vote 88 : accounts, i.e. starting from a list [(vote, id, stake)] instead. 89 : This makes it easier to send rewards to the expected vote account. 90 : Notably, turbine tree doesn't change with SIMD-0180, so the old 91 : list [(id, stake)] is still necessary. 92 : 93 : Realistically, there should be a 1:1 relationship between id and 94 : vote, but unfortunately the on chain state allows for a 1:N 95 : relationship (1 id could be associated to N vote accounts). 96 : At the time of writing, testnet has one such example. 97 : id: DtSguGSHVrXdqZU1mKWKocsAjrXMhaC7YJic5xxN1Uom 98 : votes: 99 : - https://solscan.io/account/BbtyLT1ntMFbbXtsJRCZnYjpe7d7TUtyZeGKzod3eNsN?cluster=testnet 100 : - https://solscan.io/account/FFr8Gyjy3Wjeqv6oD4RjbwqD1mVfKycAFxQdASYAfR75?cluster=testnet 101 : 102 : Even when there is a 1:1 relationship, the order of the 2 lists 103 : can be different because validators with the same stake could 104 : be ordered differently by vote vs id. 105 : 106 : Last consideration, this operation is done only once per epoch, twice 107 : at startup. 108 : 109 : The current implementation uses sort in place to avoid extra memory 110 : for a map or tree. */ 111 : ulong 112 : compute_id_weights_from_vote_weights( fd_stake_weight_t * stake_weight, 113 : fd_vote_stake_weight_t const * vote_stake_weight, 114 : ulong staked_cnt ); 115 : 116 : #endif /* HEADER_fd_src_flamenco_leaders_fd_leaders_base_h */