crates/sui-framework/docs/sui_system/validator_set.md
ValidatorSetValidatorEpochInfoEventValidatorEpochInfoEventV2ValidatorJoinEventValidatorLeaveEventVotingPowerAdmissionStartEpochKeynewrequest_add_validator_candidaterequest_remove_validator_candidaterequest_add_validatorcan_joinget_voting_power_thresholdsassert_no_pending_or_active_duplicatesrequest_remove_validatorrequest_add_stakerequest_withdraw_stakeconvert_to_fungible_staked_suiredeem_fungible_staked_suiadvance_epochupdate_validator_positions_and_calculate_total_stakeeffectuate_staged_metadataderive_reference_gas_pricetotal_stakevalidator_total_stake_amountvalidator_stake_amountvalidator_voting_powervalidator_staking_pool_idstaking_pool_mappingsvalidator_address_by_pool_idpool_exchange_ratesvalidator_by_pool_idnext_epoch_validator_countis_active_validator_by_sui_addressis_duplicate_with_active_validatoris_duplicate_validatorcount_duplicates_vecis_duplicate_with_pending_validatorcount_duplicates_tablevecget_candidate_or_active_validator_mutfind_validatorfind_validator_from_table_vecget_validator_indicesany_validatorany_validator_mutactive_validatoractive_validator_mutpending_validatorpending_validator_mutcandidate_validatorcandidate_validator_mutget_validator_refget_active_or_pending_or_candidate_validator_refverify_capprocess_pending_removalsprocess_validator_departureclean_report_records_leaving_validatorsort_removal_listprocess_pending_stakes_and_withdrawscalculate_total_stakesadjust_stake_and_gas_pricecompute_reward_adjustmentscompute_slashed_validatorscompute_unadjusted_reward_distributioncompute_adjusted_reward_distributiondistribute_rewardemit_validator_epoch_eventssum_voting_power_by_addressesactive_validatorsis_validator_candidateis_active_validatoris_inactive_validatoris_at_risk_validatoractive_validator_addressesmul_divget_active_validator_refget_pending_validator_ref<a name="sui_system_validator_set_ValidatorSet"></a>
ValidatorSet<a name="sui_system_validator_set_ValidatorEpochInfoEvent"></a>
ValidatorEpochInfoEventEvent containing staking and rewards related information of each validator, emitted during epoch advancement.
<pre><code><b>public</b> <b>struct</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorEpochInfoEvent">ValidatorEpochInfoEvent</a> <b>has</b> <b>copy</b>, drop </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>epoch: u64</code> </dt> <dd> </dd> <dt> <code>validator_address: <b>address</b></code> </dt> <dd> </dd> <dt> <code>reference_gas_survey_quote: u64</code> </dt> <dd> </dd> <dt> <code>stake: u64</code> </dt> <dd> </dd> <dt> <code>commission_rate: u64</code> </dt> <dd> </dd> <dt> <code>pool_staking_reward: u64</code> </dt> <dd> </dd> <dt> <code>storage_fund_staking_reward: u64</code> </dt> <dd> </dd> <dt> <code>pool_token_exchange_rate: <a href="../sui_system/staking_pool.md#sui_system_staking_pool_PoolTokenExchangeRate">sui_system::staking_pool::PoolTokenExchangeRate</a></code> </dt> <dd> </dd> <dt> <code>tallying_rule_reporters: vector<<b>address</b>></code> </dt> <dd> </dd> <dt> <code>tallying_rule_global_score: u64</code> </dt> <dd> </dd> </dl> </details><a name="sui_system_validator_set_ValidatorEpochInfoEventV2"></a>
ValidatorEpochInfoEventV2V2 of ValidatorEpochInfoEvent containing more information about the validator.
<pre><code><b>public</b> <b>struct</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorEpochInfoEventV2">ValidatorEpochInfoEventV2</a> <b>has</b> <b>copy</b>, drop </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>epoch: u64</code> </dt> <dd> </dd> <dt> <code>validator_address: <b>address</b></code> </dt> <dd> </dd> <dt> <code>reference_gas_survey_quote: u64</code> </dt> <dd> </dd> <dt> <code>stake: u64</code> </dt> <dd> </dd> <dt> <code><a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>: u64</code> </dt> <dd> </dd> <dt> <code>commission_rate: u64</code> </dt> <dd> </dd> <dt> <code>pool_staking_reward: u64</code> </dt> <dd> </dd> <dt> <code>storage_fund_staking_reward: u64</code> </dt> <dd> </dd> <dt> <code>pool_token_exchange_rate: <a href="../sui_system/staking_pool.md#sui_system_staking_pool_PoolTokenExchangeRate">sui_system::staking_pool::PoolTokenExchangeRate</a></code> </dt> <dd> </dd> <dt> <code>tallying_rule_reporters: vector<<b>address</b>></code> </dt> <dd> </dd> <dt> <code>tallying_rule_global_score: u64</code> </dt> <dd> </dd> </dl> </details><a name="sui_system_validator_set_ValidatorJoinEvent"></a>
ValidatorJoinEventEvent emitted every time a new validator joins the committee. The epoch value corresponds to the first epoch this change takes place.
<pre><code><b>public</b> <b>struct</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorJoinEvent">ValidatorJoinEvent</a> <b>has</b> <b>copy</b>, drop </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>epoch: u64</code> </dt> <dd> </dd> <dt> <code>validator_address: <b>address</b></code> </dt> <dd> </dd> <dt> <code>staking_pool_id: <a href="../sui/object.md#sui_object_ID">sui::object::ID</a></code> </dt> <dd> </dd> </dl> </details><a name="sui_system_validator_set_ValidatorLeaveEvent"></a>
ValidatorLeaveEventEvent emitted every time a validator leaves the committee. The epoch value corresponds to the first epoch this change takes place.
<pre><code><b>public</b> <b>struct</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorLeaveEvent">ValidatorLeaveEvent</a> <b>has</b> <b>copy</b>, drop </code></pre> <details> <summary>Fields</summary> <dl> <dt> <code>epoch: u64</code> </dt> <dd> </dd> <dt> <code>validator_address: <b>address</b></code> </dt> <dd> </dd> <dt> <code>staking_pool_id: <a href="../sui/object.md#sui_object_ID">sui::object::ID</a></code> </dt> <dd> </dd> <dt> <code>is_voluntary: bool</code> </dt> <dd> </dd> </dl> </details><a name="sui_system_validator_set_VotingPowerAdmissionStartEpochKey"></a>
VotingPowerAdmissionStartEpochKeyKey for the <code>extra_fields</code> bag to store the start epoch of allowing admission of new validators based on a minimum voting power rather than a minimum stake.
<pre><code><b>public</b> <b>struct</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_VotingPowerAdmissionStartEpochKey">VotingPowerAdmissionStartEpochKey</a> <b>has</b> <b>copy</b>, drop, store </code></pre> <details> <summary>Fields</summary> <dl> </dl> </details><a name="@Constants_0"></a>
<a name="sui_system_validator_set_ENonValidatorInReportRecords"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENonValidatorInReportRecords">ENonValidatorInReportRecords</a>: u64 = 0; </code></pre><a name="sui_system_validator_set_EInvalidStakeAdjustmentAmount"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EInvalidStakeAdjustmentAmount">EInvalidStakeAdjustmentAmount</a>: u64 = 1; </code></pre><a name="sui_system_validator_set_EDuplicateValidator"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EDuplicateValidator">EDuplicateValidator</a>: u64 = 2; </code></pre><a name="sui_system_validator_set_ENoPoolFound"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENoPoolFound">ENoPoolFound</a>: u64 = 3; </code></pre><a name="sui_system_validator_set_ENotAValidator"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAValidator">ENotAValidator</a>: u64 = 4; </code></pre><a name="sui_system_validator_set_EMinJoiningStakeNotReached"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EMinJoiningStakeNotReached">EMinJoiningStakeNotReached</a>: u64 = 5; </code></pre><a name="sui_system_validator_set_EAlreadyValidatorCandidate"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EAlreadyValidatorCandidate">EAlreadyValidatorCandidate</a>: u64 = 6; </code></pre><a name="sui_system_validator_set_EValidatorNotCandidate"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EValidatorNotCandidate">EValidatorNotCandidate</a>: u64 = 7; </code></pre><a name="sui_system_validator_set_ENotValidatorCandidate"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotValidatorCandidate">ENotValidatorCandidate</a>: u64 = 8; </code></pre><a name="sui_system_validator_set_EStakingBelowThreshold"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EStakingBelowThreshold">EStakingBelowThreshold</a>: u64 = 10; </code></pre><a name="sui_system_validator_set_EValidatorAlreadyRemoved"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EValidatorAlreadyRemoved">EValidatorAlreadyRemoved</a>: u64 = 11; </code></pre><a name="sui_system_validator_set_ENotAPendingValidator"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAPendingValidator">ENotAPendingValidator</a>: u64 = 12; </code></pre><a name="sui_system_validator_set_EValidatorSetEmpty"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EValidatorSetEmpty">EValidatorSetEmpty</a>: u64 = 13; </code></pre><a name="sui_system_validator_set_EInvalidCap"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EInvalidCap">EInvalidCap</a>: u64 = 101; </code></pre><a name="sui_system_validator_set_EInvalidValidatorSelector"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EInvalidValidatorSelector">EInvalidValidatorSelector</a>: u64 = 14; </code></pre><a name="sui_system_validator_set_ACTIVE_VALIDATOR_ONLY"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ACTIVE_VALIDATOR_ONLY">ACTIVE_VALIDATOR_ONLY</a>: u8 = 1; </code></pre><a name="sui_system_validator_set_ACTIVE_OR_PENDING_VALIDATOR"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ACTIVE_OR_PENDING_VALIDATOR">ACTIVE_OR_PENDING_VALIDATOR</a>: u8 = 2; </code></pre><a name="sui_system_validator_set_ANY_VALIDATOR"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ANY_VALIDATOR">ANY_VALIDATOR</a>: u8 = 3; </code></pre><a name="sui_system_validator_set_BASIS_POINT_DENOMINATOR"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_BASIS_POINT_DENOMINATOR">BASIS_POINT_DENOMINATOR</a>: u64 = 10000; </code></pre><a name="sui_system_validator_set_MIN_STAKING_THRESHOLD"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_MIN_STAKING_THRESHOLD">MIN_STAKING_THRESHOLD</a>: u64 = 1000000000; </code></pre><a name="sui_system_validator_set_PHASE_LENGTH"></a>
<pre><code><b>const</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_PHASE_LENGTH">PHASE_LENGTH</a>: u64 = 14; </code></pre><a name="sui_system_validator_set_new"></a>
new<a name="sui_system_validator_set_request_add_validator_candidate"></a>
request_add_validator_candidateCalled by <code><a href="../sui_system/sui_system.md#sui_system_sui_system">sui_system</a></code> to add a new validator candidate.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_add_validator_candidate">request_add_validator_candidate</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>, ctx: &<b>mut</b> <a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_add_validator_candidate">request_add_validator_candidate</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: Validator, ctx: &<b>mut</b> TxContext, ) { // The next assertions are not critical <b>for</b> the protocol, but they are here to catch problematic configs earlier. <b>assert</b>!( !self.<a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_active_validator">is_duplicate_with_active_validator</a>(&<a href="../sui_system/validator.md#sui_system_validator">validator</a>) && !self.<a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_pending_validator">is_duplicate_with_pending_validator</a>(&<a href="../sui_system/validator.md#sui_system_validator">validator</a>), <a href="../sui_system/validator_set.md#sui_system_validator_set_EDuplicateValidator">EDuplicateValidator</a>, ); <b>let</b> validator_address = <a href="../sui_system/validator.md#sui_system_validator">validator</a>.sui_address(); <b>assert</b>!(!self.validator_candidates.contains(validator_address), <a href="../sui_system/validator_set.md#sui_system_validator_set_EAlreadyValidatorCandidate">EAlreadyValidatorCandidate</a>); <b>assert</b>!(<a href="../sui_system/validator.md#sui_system_validator">validator</a>.is_preactive(), <a href="../sui_system/validator_set.md#sui_system_validator_set_EValidatorNotCandidate">EValidatorNotCandidate</a>); // Add <a href="../sui_system/validator.md#sui_system_validator">validator</a> to the candidates mapping and the pool id mappings so that users can start // staking with this candidate. self.<a href="../sui_system/validator_set.md#sui_system_validator_set_staking_pool_mappings">staking_pool_mappings</a>.add(<a href="../sui_system/validator.md#sui_system_validator">validator</a>.staking_pool_id(), validator_address); self.validator_candidates.add(<a href="../sui_system/validator.md#sui_system_validator">validator</a>.sui_address(), <a href="../sui_system/validator.md#sui_system_validator">validator</a>.wrap_v1(ctx)); } </code></pre> </details><a name="sui_system_validator_set_request_remove_validator_candidate"></a>
request_remove_validator_candidateCalled by <code><a href="../sui_system/sui_system.md#sui_system_sui_system">sui_system</a></code> to remove a validator candidate, and move them to <code>inactive_validators</code>.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_remove_validator_candidate">request_remove_validator_candidate</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, ctx: &<b>mut</b> <a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_remove_validator_candidate">request_remove_validator_candidate</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, ctx: &<b>mut</b> TxContext, ) { <b>let</b> validator_address = ctx.sender(); <b>assert</b>!(self.validator_candidates.contains(validator_address), <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotValidatorCandidate">ENotValidatorCandidate</a>); <b>let</b> <b>mut</b> <a href="../sui_system/validator.md#sui_system_validator">validator</a> = self.validator_candidates.remove(validator_address).destroy(); <b>assert</b>!(<a href="../sui_system/validator.md#sui_system_validator">validator</a>.is_preactive(), <a href="../sui_system/validator_set.md#sui_system_validator_set_EValidatorNotCandidate">EValidatorNotCandidate</a>); <b>let</b> staking_pool_id = <a href="../sui_system/validator.md#sui_system_validator">validator</a>.staking_pool_id(); // Remove the <a href="../sui_system/validator.md#sui_system_validator">validator</a>'s staking pool from mappings. self.<a href="../sui_system/validator_set.md#sui_system_validator_set_staking_pool_mappings">staking_pool_mappings</a>.remove(staking_pool_id); // Deactivate the staking pool. <a href="../sui_system/validator.md#sui_system_validator">validator</a>.deactivate(ctx.epoch()); // Add to the inactive tables. self.inactive_validators.add(staking_pool_id, <a href="../sui_system/validator.md#sui_system_validator">validator</a>.wrap_v1(ctx)); } </code></pre> </details><a name="sui_system_validator_set_request_add_validator"></a>
request_add_validatorCalled by <code><a href="../sui_system/sui_system.md#sui_system_sui_system">sui_system</a></code> to add a new validator to <code>pending_active_validators</code>, which will be processed at the end of epoch.
Aborts if the validator contains duplicate metadata values with an active or pending validator.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_add_validator">request_add_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, ctx: &<a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_add_validator">request_add_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, ctx: &TxContext) { <b>let</b> validator_address = ctx.sender(); <b>assert</b>!(self.validator_candidates.contains(validator_address), <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotValidatorCandidate">ENotValidatorCandidate</a>); <b>let</b> <a href="../sui_system/validator.md#sui_system_validator">validator</a> = self.validator_candidates.remove(validator_address).destroy(); <b>assert</b>!( !self.<a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_active_validator">is_duplicate_with_active_validator</a>(&<a href="../sui_system/validator.md#sui_system_validator">validator</a>) && !self.<a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_pending_validator">is_duplicate_with_pending_validator</a>(&<a href="../sui_system/validator.md#sui_system_validator">validator</a>), <a href="../sui_system/validator_set.md#sui_system_validator_set_EDuplicateValidator">EDuplicateValidator</a>, ); <b>assert</b>!(<a href="../sui_system/validator.md#sui_system_validator">validator</a>.is_preactive(), <a href="../sui_system/validator_set.md#sui_system_validator_set_EValidatorNotCandidate">EValidatorNotCandidate</a>); <b>assert</b>!(self.<a href="../sui_system/validator_set.md#sui_system_validator_set_can_join">can_join</a>(<a href="../sui_system/validator.md#sui_system_validator">validator</a>.<a href="../sui_system/validator_set.md#sui_system_validator_set_total_stake">total_stake</a>(), ctx), <a href="../sui_system/validator_set.md#sui_system_validator_set_EMinJoiningStakeNotReached">EMinJoiningStakeNotReached</a>); self.pending_active_validators.push_back(<a href="../sui_system/validator.md#sui_system_validator">validator</a>); } </code></pre> </details><a name="sui_system_validator_set_can_join"></a>
can_joinReturn <code><b>true</b></code> if a candidate validator with <code>stake</code> will have sufficeint voting power to join the validator set
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_can_join">can_join</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, stake: u64, ctx: &<a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_can_join">can_join</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, stake: u64, ctx: &TxContext): bool { <b>let</b> (min_joining_voting_power, _, _) = self.<a href="../sui_system/validator_set.md#sui_system_validator_set_get_voting_power_thresholds">get_voting_power_thresholds</a>(ctx); // <b>if</b> the <a href="../sui_system/validator.md#sui_system_validator">validator</a> will have at least `min_joining_voting_power` after joining, they can join. // this formula comes from SIP-39: https://github.com/sui-foundation/sips/blob/main/sips/sip-39.md <b>let</b> future_total_stake = self.<a href="../sui_system/validator_set.md#sui_system_validator_set_total_stake">total_stake</a> + stake; <b>let</b> future_validator_voting_power = <a href="../sui_system/voting_power.md#sui_system_voting_power_derive_raw_voting_power">voting_power::derive_raw_voting_power</a>( stake, future_total_stake, ); future_validator_voting_power >= min_joining_voting_power } </code></pre> </details><a name="sui_system_validator_set_get_voting_power_thresholds"></a>
get_voting_power_thresholdsreturn (min, low, very low voting power) thresholds
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_get_voting_power_thresholds">get_voting_power_thresholds</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, ctx: &<a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (u64, u64, u64) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_get_voting_power_thresholds">get_voting_power_thresholds</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, ctx: &TxContext): (u64, u64, u64) { <b>let</b> start_epoch = { <b>let</b> key = <a href="../sui_system/validator_set.md#sui_system_validator_set_VotingPowerAdmissionStartEpochKey">VotingPowerAdmissionStartEpochKey</a>(); <b>if</b> (self.extra_fields.contains(key)) self.extra_fields[key] <b>else</b> ctx.epoch() + 1 // will give us the phase 1 values }; // these numbers come from SIP-39: https://github.com/sui-foundation/sips/blob/main/sips/sip-39.md <b>let</b> curr_epoch = ctx.epoch(); <b>if</b> (curr_epoch < start_epoch + <a href="../sui_system/validator_set.md#sui_system_validator_set_PHASE_LENGTH">PHASE_LENGTH</a>) (12, 8, 4) // phase 1 <b>else</b> <b>if</b> (curr_epoch < start_epoch + (2 * <a href="../sui_system/validator_set.md#sui_system_validator_set_PHASE_LENGTH">PHASE_LENGTH</a>)) (6, 4, 2) // phase 2 <b>else</b> (3, 2, 1) // phase 3 } </code></pre> </details><a name="sui_system_validator_set_assert_no_pending_or_active_duplicates"></a>
assert_no_pending_or_active_duplicates<a name="sui_system_validator_set_request_remove_validator"></a>
request_remove_validatorCalled by <code><a href="../sui_system/sui_system.md#sui_system_sui_system">sui_system</a></code>, to remove a validator. The index of the validator is added to <code>pending_removals</code> and will be processed at the end of epoch. Only an active validator can request to be removed.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_remove_validator">request_remove_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, ctx: &<a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_remove_validator">request_remove_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, ctx: &TxContext) { <b>let</b> validator_address = ctx.sender(); <b>let</b> validator_index = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>( &self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, validator_address, ).destroy_or!(<b>abort</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAValidator">ENotAValidator</a>); <b>assert</b>!(!self.pending_removals.contains(&validator_index), <a href="../sui_system/validator_set.md#sui_system_validator_set_EValidatorAlreadyRemoved">EValidatorAlreadyRemoved</a>); self.pending_removals.push_back(validator_index); } </code></pre> </details><a name="sui_system_validator_set_request_add_stake"></a>
request_add_stakeCalled by <code><a href="../sui_system/sui_system.md#sui_system_sui_system">sui_system</a></code>, to add a new stake to the validator. This request is added to the validator's staking pool's pending stake entries, processed at the end of the epoch. Aborts in case the staking amount is smaller than MIN_STAKING_THRESHOLD
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_add_stake">request_add_stake</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, validator_address: <b>address</b>, stake: <a href="../sui/balance.md#sui_balance_Balance">sui::balance::Balance</a><<a href="../sui/sui.md#sui_sui_SUI">sui::sui::SUI</a>>, ctx: &<b>mut</b> <a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): <a href="../sui_system/staking_pool.md#sui_system_staking_pool_StakedSui">sui_system::staking_pool::StakedSui</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_request_add_stake">request_add_stake</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, validator_address: <b>address</b>, stake: Balance<SUI>, ctx: &<b>mut</b> TxContext, ): StakedSui { <b>let</b> sui_amount = stake.value(); <b>assert</b>!(sui_amount >= <a href="../sui_system/validator_set.md#sui_system_validator_set_MIN_STAKING_THRESHOLD">MIN_STAKING_THRESHOLD</a>, <a href="../sui_system/validator_set.md#sui_system_validator_set_EStakingBelowThreshold">EStakingBelowThreshold</a>); self .<a href="../sui_system/validator_set.md#sui_system_validator_set_get_candidate_or_active_validator_mut">get_candidate_or_active_validator_mut</a>(validator_address) .<a href="../sui_system/validator_set.md#sui_system_validator_set_request_add_stake">request_add_stake</a>(stake, ctx.sender(), ctx) } </code></pre> </details><a name="sui_system_validator_set_request_withdraw_stake"></a>
request_withdraw_stakeCalled by <code><a href="../sui_system/sui_system.md#sui_system_sui_system">sui_system</a></code>, to withdraw some share of a stake from the validator. The share to withdraw is denoted by <code>principal_withdraw_amount</code>. One of two things occurs in this function:
<a name="sui_system_validator_set_convert_to_fungible_staked_sui"></a>
convert_to_fungible_staked_sui<a name="sui_system_validator_set_redeem_fungible_staked_sui"></a>
redeem_fungible_staked_sui<a name="sui_system_validator_set_advance_epoch"></a>
advance_epochUpdate the validator set at the end of epoch. It does the following things:
<a name="sui_system_validator_set_update_validator_positions_and_calculate_total_stake"></a>
update_validator_positions_and_calculate_total_stakeThis function does the following:
<a name="sui_system_validator_set_effectuate_staged_metadata"></a>
effectuate_staged_metadataEffectuate pending next epoch metadata if they are staged.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_effectuate_staged_metadata">effectuate_staged_metadata</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_effectuate_staged_metadata">effectuate_staged_metadata</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>) { self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>.do_mut!(|v| v.<a href="../sui_system/validator_set.md#sui_system_validator_set_effectuate_staged_metadata">effectuate_staged_metadata</a>()); } </code></pre> </details><a name="sui_system_validator_set_derive_reference_gas_price"></a>
derive_reference_gas_priceCalled by <code><a href="../sui_system/sui_system.md#sui_system_sui_system">sui_system</a></code> to derive reference gas price for the new epoch. Derive the reference gas price based on the gas price quote submitted by each validator. The returned gas price should be greater than or equal to 2/3 of the validators submitted gas price, weighted by stake.
<pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_derive_reference_gas_price">derive_reference_gas_price</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>): u64 </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_derive_reference_gas_price">derive_reference_gas_price</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>): u64 { <b>let</b> entries = self .<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a> .map_ref!(|v| pq::new_entry(v.gas_price(), v.<a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>())); // Build a priority queue that will pop entries with gas price from the highest to the lowest. <b>let</b> <b>mut</b> pq = pq::new(entries); <b>let</b> <b>mut</b> sum = 0; <b>let</b> threshold = <a href="../sui_system/voting_power.md#sui_system_voting_power_total_voting_power">voting_power::total_voting_power</a>() - <a href="../sui_system/voting_power.md#sui_system_voting_power_quorum_threshold">voting_power::quorum_threshold</a>(); <b>let</b> <b>mut</b> result = 0; <b>while</b> (sum < threshold) { <b>let</b> (gas_price, <a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>) = pq.pop_max(); result = gas_price; sum = sum + <a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>; }; result } </code></pre> </details><a name="sui_system_validator_set_total_stake"></a>
total_stake<a name="sui_system_validator_set_validator_total_stake_amount"></a>
validator_total_stake_amount<a name="sui_system_validator_set_validator_stake_amount"></a>
validator_stake_amount<a name="sui_system_validator_set_validator_voting_power"></a>
validator_voting_power<a name="sui_system_validator_set_validator_staking_pool_id"></a>
validator_staking_pool_id<a name="sui_system_validator_set_staking_pool_mappings"></a>
staking_pool_mappings<a name="sui_system_validator_set_validator_address_by_pool_id"></a>
validator_address_by_pool_id<a name="sui_system_validator_set_pool_exchange_rates"></a>
pool_exchange_rates<a name="sui_system_validator_set_validator_by_pool_id"></a>
validator_by_pool_id<a name="sui_system_validator_set_next_epoch_validator_count"></a>
next_epoch_validator_countGet the total number of validators in the next epoch.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_next_epoch_validator_count">next_epoch_validator_count</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>): u64 </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_next_epoch_validator_count">next_epoch_validator_count</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>): u64 { self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>.length() - self.pending_removals.length() + self.pending_active_validators.length() } </code></pre> </details><a name="sui_system_validator_set_is_active_validator_by_sui_address"></a>
is_active_validator_by_sui_addressReturns true iff the address exists in active validators.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_active_validator_by_sui_address">is_active_validator_by_sui_address</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, validator_address: <b>address</b>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_active_validator_by_sui_address">is_active_validator_by_sui_address</a>( self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, validator_address: <b>address</b>, ): bool { <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(&self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, validator_address).is_some() } </code></pre> </details><a name="sui_system_validator_set_is_duplicate_with_active_validator"></a>
is_duplicate_with_active_validatorChecks whether <code>new_validator</code> is duplicate with any currently active validators. It differs from <code><a href="../sui_system/validator_set.md#sui_system_validator_set_is_active_validator_by_sui_address">is_active_validator_by_sui_address</a></code> in that the former checks only the sui address but this function looks at more metadata.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_active_validator">is_duplicate_with_active_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, new_validator: &<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_active_validator">is_duplicate_with_active_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, new_validator: &Validator): bool { <a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_validator">is_duplicate_validator</a>(&self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, new_validator) } </code></pre> </details><a name="sui_system_validator_set_is_duplicate_validator"></a>
is_duplicate_validator<a name="sui_system_validator_set_count_duplicates_vec"></a>
count_duplicates_vec<a name="sui_system_validator_set_is_duplicate_with_pending_validator"></a>
is_duplicate_with_pending_validatorChecks whether <code>new_validator</code> is duplicate with any currently pending validators.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_pending_validator">is_duplicate_with_pending_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, new_validator: &<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_duplicate_with_pending_validator">is_duplicate_with_pending_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, new_validator: &Validator): bool { <a href="../sui_system/validator_set.md#sui_system_validator_set_count_duplicates_tablevec">count_duplicates_tablevec</a>(&self.pending_active_validators, new_validator) > 0 } </code></pre> </details><a name="sui_system_validator_set_count_duplicates_tablevec"></a>
count_duplicates_tablevec<a name="sui_system_validator_set_get_candidate_or_active_validator_mut"></a>
get_candidate_or_active_validator_mutGet mutable reference to either a candidate or an active validator by address.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_get_candidate_or_active_validator_mut">get_candidate_or_active_validator_mut</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, validator_address: <b>address</b>): &<b>mut</b> <a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_get_candidate_or_active_validator_mut">get_candidate_or_active_validator_mut</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, validator_address: <b>address</b>, ): &<b>mut</b> Validator { <b>if</b> (self.validator_candidates.contains(validator_address)) { self.<a href="../sui_system/validator_set.md#sui_system_validator_set_candidate_validator_mut">candidate_validator_mut</a>(validator_address) } <b>else</b> { self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validator_mut">active_validator_mut</a>(validator_address) } } </code></pre> </details><a name="sui_system_validator_set_find_validator"></a>
find_validatorFind validator by <code>validator_address</code>, in <code>validators</code>. Returns (true, index) if the validator is found, and the index is its index in the list. If not found, returns (false, 0).
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(validators: &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, validator_address: <b>address</b>): <a href="../std/option.md#std_option_Option">std::option::Option</a><u64> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(validators: &vector<Validator>, validator_address: <b>address</b>): Option<u64> { validators.find_index!(|v| v.sui_address() == validator_address) } </code></pre> </details><a name="sui_system_validator_set_find_validator_from_table_vec"></a>
find_validator_from_table_vecFind validator by <code>validator_address</code>, in <code>validators</code>. Returns (true, index) if the validator is found, and the index is its index in the list. If not found, returns (false, 0).
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator_from_table_vec">find_validator_from_table_vec</a>(validators: &<a href="../sui/table_vec.md#sui_table_vec_TableVec">sui::table_vec::TableVec</a><<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, validator_address: <b>address</b>): <a href="../std/option.md#std_option_Option">std::option::Option</a><u64> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator_from_table_vec">find_validator_from_table_vec</a>( validators: &TableVec<Validator>, validator_address: <b>address</b>, ): Option<u64> { <b>let</b> length = validators.length(); <b>let</b> <b>mut</b> i = 0; <b>while</b> (i < length) { <b>let</b> v = &validators[i]; <b>if</b> (v.sui_address() == validator_address) { <b>return</b> option::some(i) }; i = i + 1; }; option::none() } </code></pre> </details><a name="sui_system_validator_set_get_validator_indices"></a>
get_validator_indicesGiven a vector of validator addresses, return their indices in the validator set. Aborts if any address isn't in the given validator set.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_get_validator_indices">get_validator_indices</a>(validators: &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, validator_addresses: &vector<<b>address</b>>): vector<u64> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_get_validator_indices">get_validator_indices</a>( validators: &vector<Validator>, validator_addresses: &vector<<b>address</b>>, ): vector<u64> { <b>let</b> <b>mut</b> res = vector[]; validator_addresses.do_ref!(|addr| { <b>let</b> idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(validators, *addr).destroy_or!(<b>abort</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAValidator">ENotAValidator</a>); res.push_back(idx); }); res } </code></pre> </details><a name="sui_system_validator_set_any_validator"></a>
any_validatorGet reference to validator in any state: active, pending, or candidate.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_any_validator">any_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_any_validator">any_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &Validator { <b>let</b> active_idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(&self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>); <b>if</b> (active_idx.is_some()) { <b>return</b> &self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>[active_idx.destroy_some()] }; <b>let</b> pending_idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator_from_table_vec">find_validator_from_table_vec</a>( &self.pending_active_validators, <a href="../sui_system/validator.md#sui_system_validator">validator</a>, ); <b>if</b> (pending_idx.is_some()) { <b>return</b> &self.pending_active_validators[pending_idx.destroy_some()] }; self.validator_candidates[<a href="../sui_system/validator.md#sui_system_validator">validator</a>].load_validator_maybe_upgrade() } </code></pre> </details><a name="sui_system_validator_set_any_validator_mut"></a>
any_validator_mutGet mutable reference to validator in any state: active, pending, or candidate.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_any_validator_mut">any_validator_mut</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<b>mut</b> <a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_any_validator_mut">any_validator_mut</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<b>mut</b> Validator { <b>let</b> active_idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(&self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>); <b>if</b> (active_idx.is_some()) { <b>return</b> &<b>mut</b> self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>[active_idx.destroy_some()] }; <b>let</b> pending_idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator_from_table_vec">find_validator_from_table_vec</a>( &self.pending_active_validators, <a href="../sui_system/validator.md#sui_system_validator">validator</a>, ); <b>if</b> (pending_idx.is_some()) { <b>return</b> &<b>mut</b> self.pending_active_validators[pending_idx.destroy_some()] }; self.validator_candidates[<a href="../sui_system/validator.md#sui_system_validator">validator</a>].load_validator_maybe_upgrade() } </code></pre> </details><a name="sui_system_validator_set_active_validator"></a>
active_validatorGet reference to an active validator by address.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_active_validator">active_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_active_validator">active_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &Validator { <b>let</b> idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(&self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>).destroy_or!(<b>abort</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAValidator">ENotAValidator</a>); &self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>[idx] } </code></pre> </details><a name="sui_system_validator_set_active_validator_mut"></a>
active_validator_mutGet mutable reference to an active validator by address.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_active_validator_mut">active_validator_mut</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<b>mut</b> <a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_active_validator_mut">active_validator_mut</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>, ): &<b>mut</b> Validator { <b>let</b> idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(&self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>).destroy_or!(<b>abort</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAValidator">ENotAValidator</a>); &<b>mut</b> self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>[idx] } </code></pre> </details><a name="sui_system_validator_set_pending_validator"></a>
pending_validatorGet reference to a pending validator by address.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_pending_validator">pending_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_pending_validator">pending_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &Validator { <b>let</b> idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator_from_table_vec">find_validator_from_table_vec</a>(&self.pending_active_validators, <a href="../sui_system/validator.md#sui_system_validator">validator</a>).destroy_or!( <b>abort</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAPendingValidator">ENotAPendingValidator</a>, ); &self.pending_active_validators[idx] } </code></pre> </details><a name="sui_system_validator_set_pending_validator_mut"></a>
pending_validator_mutGet mutable reference to a pending validator by address.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_pending_validator_mut">pending_validator_mut</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<b>mut</b> <a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_pending_validator_mut">pending_validator_mut</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>, ): &<b>mut</b> Validator { <b>let</b> idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator_from_table_vec">find_validator_from_table_vec</a>( &self.pending_active_validators, <a href="../sui_system/validator.md#sui_system_validator">validator</a>, ).destroy_or!(<b>abort</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotAPendingValidator">ENotAPendingValidator</a>); &<b>mut</b> self.pending_active_validators[idx] } </code></pre> </details><a name="sui_system_validator_set_candidate_validator"></a>
candidate_validatorGet mutable reference to a candidate validator by address.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_candidate_validator">candidate_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_candidate_validator">candidate_validator</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &Validator { <b>assert</b>!(self.validator_candidates.contains(<a href="../sui_system/validator.md#sui_system_validator">validator</a>), <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotValidatorCandidate">ENotValidatorCandidate</a>); self.validator_candidates[<a href="../sui_system/validator.md#sui_system_validator">validator</a>].load_validator_maybe_upgrade() } </code></pre> </details><a name="sui_system_validator_set_candidate_validator_mut"></a>
candidate_validator_mutGet mutable reference to a candidate validator by address.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_candidate_validator_mut">candidate_validator_mut</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>): &<b>mut</b> <a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_candidate_validator_mut">candidate_validator_mut</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <b>address</b>, ): &<b>mut</b> Validator { <b>assert</b>!(self.validator_candidates.contains(<a href="../sui_system/validator.md#sui_system_validator">validator</a>), <a href="../sui_system/validator_set.md#sui_system_validator_set_ENotValidatorCandidate">ENotValidatorCandidate</a>); self.validator_candidates[<a href="../sui_system/validator.md#sui_system_validator">validator</a>].load_validator_maybe_upgrade() } </code></pre> </details><a name="sui_system_validator_set_get_validator_ref"></a>
get_validator_ref<a name="sui_system_validator_set_get_active_or_pending_or_candidate_validator_ref"></a>
get_active_or_pending_or_candidate_validator_ref<a name="sui_system_validator_set_verify_cap"></a>
verify_capVerify the capability is valid for a Validator. If <code>active_validator_only</code> is true, only verify the Cap for an active validator. Otherwise, verify the Cap for au either active or pending validator.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_verify_cap">verify_cap</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, cap: &<a href="../sui_system/validator_cap.md#sui_system_validator_cap_UnverifiedValidatorOperationCap">sui_system::validator_cap::UnverifiedValidatorOperationCap</a>, which_validator: u8): <a href="../sui_system/validator_cap.md#sui_system_validator_cap_ValidatorOperationCap">sui_system::validator_cap::ValidatorOperationCap</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_verify_cap">verify_cap</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, cap: &UnverifiedValidatorOperationCap, which_validator: u8, ): ValidatorOperationCap { <b>let</b> cap_address = *cap.unverified_operation_cap_address(); <b>let</b> <a href="../sui_system/validator.md#sui_system_validator">validator</a> = match (which_validator) { <a href="../sui_system/validator_set.md#sui_system_validator_set_ACTIVE_VALIDATOR_ONLY">ACTIVE_VALIDATOR_ONLY</a> => self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validator">active_validator</a>(cap_address), <a href="../sui_system/validator_set.md#sui_system_validator_set_ACTIVE_OR_PENDING_VALIDATOR">ACTIVE_OR_PENDING_VALIDATOR</a> => { <b>let</b> active_idx = <a href="../sui_system/validator_set.md#sui_system_validator_set_find_validator">find_validator</a>(&self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, cap_address); <b>if</b> (active_idx.is_some()) { &self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>[active_idx.destroy_some()] } <b>else</b> { self.<a href="../sui_system/validator_set.md#sui_system_validator_set_pending_validator">pending_validator</a>(cap_address) } }, <a href="../sui_system/validator_set.md#sui_system_validator_set_ANY_VALIDATOR">ANY_VALIDATOR</a> => self.<a href="../sui_system/validator_set.md#sui_system_validator_set_any_validator">any_validator</a>(cap_address), _ => <b>abort</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_EInvalidValidatorSelector">EInvalidValidatorSelector</a>, }; <b>assert</b>!(<a href="../sui_system/validator.md#sui_system_validator">validator</a>.operation_cap_id() == &object::id(cap), <a href="../sui_system/validator_set.md#sui_system_validator_set_EInvalidCap">EInvalidCap</a>); cap.into_verified() } </code></pre> </details><a name="sui_system_validator_set_process_pending_removals"></a>
process_pending_removalsProcess the pending withdraw requests. For each pending request, the validator is removed from <code>validators</code> and its staking pool is put into the <code>inactive_validators</code> table.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_process_pending_removals">process_pending_removals</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, validator_report_records: &<b>mut</b> <a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><<b>address</b>, <a href="../sui/vec_set.md#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<b>address</b>>>, ctx: &<b>mut</b> <a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_process_pending_removals">process_pending_removals</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, validator_report_records: &<b>mut</b> VecMap<<b>address</b>, VecSet<<b>address</b>>>, ctx: &<b>mut</b> TxContext, ) { <a href="../sui_system/validator_set.md#sui_system_validator_set_sort_removal_list">sort_removal_list</a>(&<b>mut</b> self.pending_removals); self.pending_removals.length().do!(|_| { <b>let</b> index = self.pending_removals.pop_back(); <b>let</b> <a href="../sui_system/validator.md#sui_system_validator">validator</a> = self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>.remove(index); self.<a href="../sui_system/validator_set.md#sui_system_validator_set_process_validator_departure">process_validator_departure</a>( <a href="../sui_system/validator.md#sui_system_validator">validator</a>, validator_report_records, <b>true</b>, // the <a href="../sui_system/validator.md#sui_system_validator">validator</a> removes itself voluntarily ctx, ); }); } </code></pre> </details><a name="sui_system_validator_set_process_validator_departure"></a>
process_validator_departureRemove <code><a href="../sui_system/validator.md#sui_system_validator">validator</a></code> from <code>self</code> and return the amount of stake that was removed
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_process_validator_departure">process_validator_departure</a>(self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, <a href="../sui_system/validator.md#sui_system_validator">validator</a>: <a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>, validator_report_records: &<b>mut</b> <a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><<b>address</b>, <a href="../sui/vec_set.md#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<b>address</b>>>, is_voluntary: bool, ctx: &<b>mut</b> <a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): u64 </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_process_validator_departure">process_validator_departure</a>( self: &<b>mut</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <b>mut</b> <a href="../sui_system/validator.md#sui_system_validator">validator</a>: Validator, validator_report_records: &<b>mut</b> VecMap<<b>address</b>, VecSet<<b>address</b>>>, is_voluntary: bool, ctx: &<b>mut</b> TxContext, ): u64 { <b>let</b> new_epoch = ctx.epoch() + 1; <b>let</b> validator_address = <a href="../sui_system/validator.md#sui_system_validator">validator</a>.sui_address(); <b>let</b> validator_pool_id = <a href="../sui_system/validator.md#sui_system_validator">validator</a>.staking_pool_id(); // Remove the <a href="../sui_system/validator.md#sui_system_validator">validator</a> from our tables. self.<a href="../sui_system/validator_set.md#sui_system_validator_set_staking_pool_mappings">staking_pool_mappings</a>.remove(validator_pool_id); <b>if</b> (self.at_risk_validators.contains(&validator_address)) { self.at_risk_validators.remove(&validator_address); }; <a href="../sui_system/validator_set.md#sui_system_validator_set_clean_report_records_leaving_validator">clean_report_records_leaving_validator</a>(validator_report_records, validator_address); event::emit(<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorLeaveEvent">ValidatorLeaveEvent</a> { epoch: new_epoch, validator_address, staking_pool_id: <a href="../sui_system/validator.md#sui_system_validator">validator</a>.staking_pool_id(), is_voluntary, }); // Deactivate the <a href="../sui_system/validator.md#sui_system_validator">validator</a> and its staking pool <b>let</b> removed_stake = <a href="../sui_system/validator.md#sui_system_validator">validator</a>.<a href="../sui_system/validator_set.md#sui_system_validator_set_total_stake">total_stake</a>(); <a href="../sui_system/validator.md#sui_system_validator">validator</a>.deactivate(new_epoch); self .inactive_validators .add( validator_pool_id, <a href="../sui_system/validator.md#sui_system_validator">validator</a>.wrap_v1(ctx), ); removed_stake } </code></pre> </details><a name="sui_system_validator_set_clean_report_records_leaving_validator"></a>
clean_report_records_leaving_validator<a name="sui_system_validator_set_sort_removal_list"></a>
sort_removal_listSort all the pending removal indexes.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_sort_removal_list">sort_removal_list</a>(withdraw_list: &<b>mut</b> vector<u64>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_sort_removal_list">sort_removal_list</a>(withdraw_list: &<b>mut</b> vector<u64>) { <b>let</b> length = withdraw_list.length(); <b>let</b> <b>mut</b> i = 1; <b>while</b> (i < length) { <b>let</b> cur = withdraw_list[i]; <b>let</b> <b>mut</b> j = i; <b>while</b> (j > 0) { j = j - 1; <b>if</b> (withdraw_list[j] > cur) { withdraw_list.swap(j, j + 1); } <b>else</b> { <b>break</b> }; }; i = i + 1; }; } </code></pre> </details><a name="sui_system_validator_set_process_pending_stakes_and_withdraws"></a>
process_pending_stakes_and_withdrawsProcess all active validators' pending stake deposits and withdraws.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_process_pending_stakes_and_withdraws">process_pending_stakes_and_withdraws</a>(validators: &<b>mut</b> vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, ctx: &<a href="../sui/tx_context.md#sui_tx_context_TxContext">sui::tx_context::TxContext</a>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_process_pending_stakes_and_withdraws">process_pending_stakes_and_withdraws</a>(validators: &<b>mut</b> vector<Validator>, ctx: &TxContext) { validators.do_mut!(|v| v.<a href="../sui_system/validator_set.md#sui_system_validator_set_process_pending_stakes_and_withdraws">process_pending_stakes_and_withdraws</a>(ctx)) } </code></pre> </details><a name="sui_system_validator_set_calculate_total_stakes"></a>
calculate_total_stakesCalculate the total active validator stake.
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_calculate_total_stakes">calculate_total_stakes</a>(validators: &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>): u64 </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_calculate_total_stakes">calculate_total_stakes</a>(validators: &vector<Validator>): u64 { <b>let</b> <b>mut</b> stake = 0; validators.do_ref!(|v| stake = stake + v.<a href="../sui_system/validator_set.md#sui_system_validator_set_total_stake">total_stake</a>()); stake } </code></pre> </details><a name="sui_system_validator_set_adjust_stake_and_gas_price"></a>
adjust_stake_and_gas_priceProcess the pending stake changes for each validator.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_adjust_stake_and_gas_price">adjust_stake_and_gas_price</a>(validators: &<b>mut</b> vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_adjust_stake_and_gas_price">adjust_stake_and_gas_price</a>(validators: &<b>mut</b> vector<Validator>) { validators.do_mut!(|v| v.<a href="../sui_system/validator_set.md#sui_system_validator_set_adjust_stake_and_gas_price">adjust_stake_and_gas_price</a>()) } </code></pre> </details><a name="sui_system_validator_set_compute_reward_adjustments"></a>
compute_reward_adjustmentsCompute both the individual reward adjustments and total reward adjustment for staking rewards as well as storage fund rewards.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_reward_adjustments">compute_reward_adjustments</a>(slashed_validator_indices: vector<u64>, reward_slashing_rate: u64, unadjusted_staking_reward_amounts: &vector<u64>, unadjusted_storage_fund_reward_amounts: &vector<u64>): (u64, <a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><u64, u64>, u64, <a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><u64, u64>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_reward_adjustments">compute_reward_adjustments</a>( slashed_validator_indices: vector<u64>, reward_slashing_rate: u64, unadjusted_staking_reward_amounts: &vector<u64>, unadjusted_storage_fund_reward_amounts: &vector<u64>, ): ( u64, // sum of staking reward adjustments VecMap<u64, u64>, // mapping of individual <a href="../sui_system/validator.md#sui_system_validator">validator</a>'s staking reward adjustment from index -> amount u64, // sum of storage fund reward adjustments VecMap<u64, u64>, // mapping of individual <a href="../sui_system/validator.md#sui_system_validator">validator</a>'s storage fund reward adjustment from index -> amount ) { <b>let</b> <b>mut</b> total_staking_reward_adjustment = 0; <b>let</b> <b>mut</b> individual_staking_reward_adjustments = vec_map::empty(); <b>let</b> <b>mut</b> total_storage_fund_reward_adjustment = 0; <b>let</b> <b>mut</b> individual_storage_fund_reward_adjustments = vec_map::empty(); slashed_validator_indices.destroy!(|validator_index| { // Use the slashing rate to compute the amount of staking rewards slashed from this punished <a href="../sui_system/validator.md#sui_system_validator">validator</a>. <b>let</b> unadjusted_staking_reward = unadjusted_staking_reward_amounts[validator_index]; <b>let</b> staking_reward_adjustment = <a href="../sui_system/validator_set.md#sui_system_validator_set_mul_div">mul_div</a>!( unadjusted_staking_reward, reward_slashing_rate, <a href="../sui_system/validator_set.md#sui_system_validator_set_BASIS_POINT_DENOMINATOR">BASIS_POINT_DENOMINATOR</a>, ); // Insert into individual mapping and record into the total adjustment sum. individual_staking_reward_adjustments.insert(validator_index, staking_reward_adjustment); total_staking_reward_adjustment = total_staking_reward_adjustment + staking_reward_adjustment; // Do the same thing <b>for</b> storage fund rewards. <b>let</b> unadjusted_storage_fund_reward = unadjusted_storage_fund_reward_amounts[ validator_index, ]; <b>let</b> storage_fund_reward_adjustment = <a href="../sui_system/validator_set.md#sui_system_validator_set_mul_div">mul_div</a>!( unadjusted_storage_fund_reward, reward_slashing_rate, <a href="../sui_system/validator_set.md#sui_system_validator_set_BASIS_POINT_DENOMINATOR">BASIS_POINT_DENOMINATOR</a>, ); individual_storage_fund_reward_adjustments.insert( validator_index, storage_fund_reward_adjustment, ); total_storage_fund_reward_adjustment = total_storage_fund_reward_adjustment + storage_fund_reward_adjustment; }); ( total_staking_reward_adjustment, individual_staking_reward_adjustments, total_storage_fund_reward_adjustment, individual_storage_fund_reward_adjustments, ) } </code></pre> </details><a name="sui_system_validator_set_compute_slashed_validators"></a>
compute_slashed_validatorsProcess the validator report records of the epoch and return the addresses of the non-performant validators according to the input threshold.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_slashed_validators">compute_slashed_validators</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, validator_report_records: <a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><<b>address</b>, <a href="../sui/vec_set.md#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<b>address</b>>>): vector<<b>address</b>> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_slashed_validators">compute_slashed_validators</a>( self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, <b>mut</b> validator_report_records: VecMap<<b>address</b>, VecSet<<b>address</b>>>, ): vector<<b>address</b>> { <b>let</b> <b>mut</b> slashed_validators = vector[]; <b>while</b> (!validator_report_records.is_empty()) { <b>let</b> (validator_address, reporters) = validator_report_records.pop(); <b>assert</b>!( self.<a href="../sui_system/validator_set.md#sui_system_validator_set_is_active_validator_by_sui_address">is_active_validator_by_sui_address</a>(validator_address), <a href="../sui_system/validator_set.md#sui_system_validator_set_ENonValidatorInReportRecords">ENonValidatorInReportRecords</a>, ); // Sum up the voting power of validators that have reported this <a href="../sui_system/validator.md#sui_system_validator">validator</a> and check <b>if</b> it <b>has</b> // passed the slashing threshold. <b>let</b> reporter_votes = <a href="../sui_system/validator_set.md#sui_system_validator_set_sum_voting_power_by_addresses">sum_voting_power_by_addresses</a>( &self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>, &reporters.into_keys(), ); <b>if</b> (reporter_votes >= <a href="../sui_system/voting_power.md#sui_system_voting_power_quorum_threshold">voting_power::quorum_threshold</a>()) { slashed_validators.push_back(validator_address); } }; slashed_validators } </code></pre> </details><a name="sui_system_validator_set_compute_unadjusted_reward_distribution"></a>
compute_unadjusted_reward_distributionGiven the current list of active validators, the total stake and total reward, calculate the amount of reward each validator should get, without taking into account the tallying rule results. Returns the unadjusted amounts of staking reward and storage fund reward for each validator.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_unadjusted_reward_distribution">compute_unadjusted_reward_distribution</a>(validators: &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, total_voting_power: u64, total_staking_reward: u64, total_storage_fund_reward: u64): (vector<u64>, vector<u64>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_unadjusted_reward_distribution">compute_unadjusted_reward_distribution</a>( validators: &vector<Validator>, total_voting_power: u64, total_staking_reward: u64, total_storage_fund_reward: u64, ): (vector<u64>, vector<u64>) { <b>let</b> <b>mut</b> staking_reward_amounts = vector[]; <b>let</b> <b>mut</b> storage_fund_reward_amounts = vector[]; <b>let</b> length = validators.length(); <b>let</b> storage_fund_reward_per_validator = total_storage_fund_reward / length; validators.do_ref!(|<a href="../sui_system/validator.md#sui_system_validator">validator</a>| { // Integer divisions will truncate the results. Because of this, we expect that at the end // there will be some reward remaining in `total_staking_reward`. // Use u128 to avoid multiplication overflow. <b>let</b> <a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a> = <a href="../sui_system/validator.md#sui_system_validator">validator</a>.<a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>(); <b>let</b> reward_amount = <a href="../sui_system/validator_set.md#sui_system_validator_set_mul_div">mul_div</a>!(<a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>, total_staking_reward, total_voting_power); staking_reward_amounts.push_back(reward_amount); // Storage fund's share of the rewards are equally distributed among validators. storage_fund_reward_amounts.push_back(storage_fund_reward_per_validator); }); (staking_reward_amounts, storage_fund_reward_amounts) } </code></pre> </details><a name="sui_system_validator_set_compute_adjusted_reward_distribution"></a>
compute_adjusted_reward_distributionUse the reward adjustment info to compute the adjusted rewards each validator should get. Returns the staking rewards each validator gets and the storage fund rewards each validator gets. The staking rewards are shared with the stakers while the storage fund ones are not.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_adjusted_reward_distribution">compute_adjusted_reward_distribution</a>(validators: &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, total_voting_power: u64, total_slashed_validator_voting_power: u64, unadjusted_staking_reward_amounts: vector<u64>, unadjusted_storage_fund_reward_amounts: vector<u64>, total_staking_reward_adjustment: u64, individual_staking_reward_adjustments: <a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><u64, u64>, total_storage_fund_reward_adjustment: u64, individual_storage_fund_reward_adjustments: <a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><u64, u64>): (vector<u64>, vector<u64>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_compute_adjusted_reward_distribution">compute_adjusted_reward_distribution</a>( validators: &vector<Validator>, total_voting_power: u64, total_slashed_validator_voting_power: u64, unadjusted_staking_reward_amounts: vector<u64>, unadjusted_storage_fund_reward_amounts: vector<u64>, total_staking_reward_adjustment: u64, individual_staking_reward_adjustments: VecMap<u64, u64>, total_storage_fund_reward_adjustment: u64, individual_storage_fund_reward_adjustments: VecMap<u64, u64>, ): (vector<u64>, vector<u64>) { <b>let</b> total_unslashed_validator_voting_power = total_voting_power - total_slashed_validator_voting_power; <b>let</b> <b>mut</b> adjusted_staking_reward_amounts = vector[]; <b>let</b> <b>mut</b> adjusted_storage_fund_reward_amounts = vector[]; <b>let</b> length = validators.length(); <b>let</b> num_unslashed_validators = length - individual_staking_reward_adjustments.length(); length.do!(|i| { <b>let</b> <a href="../sui_system/validator.md#sui_system_validator">validator</a> = &validators[i]; // Integer divisions will truncate the results. Because of this, we expect that at the end // there will be some reward remaining in `total_reward`. // Use u128 to avoid multiplication overflow. <b>let</b> <a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a> = <a href="../sui_system/validator.md#sui_system_validator">validator</a>.<a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>(); // Compute adjusted staking reward. <b>let</b> unadjusted_staking_reward_amount = unadjusted_staking_reward_amounts[i]; // If the <a href="../sui_system/validator.md#sui_system_validator">validator</a> is one of the slashed ones, then subtract the adjustment. <b>let</b> adjusted_staking_reward_amount = <b>if</b> ( individual_staking_reward_adjustments.contains(&i) ) { <b>let</b> adjustment = individual_staking_reward_adjustments[&i]; unadjusted_staking_reward_amount - adjustment } <b>else</b> { // Otherwise the slashed rewards should be distributed among the unslashed // validators so add the corresponding adjustment. <b>let</b> adjustment = <a href="../sui_system/validator_set.md#sui_system_validator_set_mul_div">mul_div</a>!( total_staking_reward_adjustment, <a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>, total_unslashed_validator_voting_power, ); unadjusted_staking_reward_amount + adjustment }; adjusted_staking_reward_amounts.push_back(adjusted_staking_reward_amount); // Compute adjusted storage fund reward. <b>let</b> unadjusted_storage_fund_reward_amount = unadjusted_storage_fund_reward_amounts[i]; // If the <a href="../sui_system/validator.md#sui_system_validator">validator</a> is one of the slashed ones, then subtract the adjustment. <b>let</b> adjusted_storage_fund_reward_amount = <b>if</b> ( individual_storage_fund_reward_adjustments.contains(&i) ) { <b>let</b> adjustment = individual_storage_fund_reward_adjustments[&i]; unadjusted_storage_fund_reward_amount - adjustment } <b>else</b> { // Otherwise the slashed rewards should be equally distributed among the unslashed validators. <b>let</b> adjustment = total_storage_fund_reward_adjustment / num_unslashed_validators; unadjusted_storage_fund_reward_amount + adjustment }; adjusted_storage_fund_reward_amounts.push_back(adjusted_storage_fund_reward_amount); }); (adjusted_staking_reward_amounts, adjusted_storage_fund_reward_amounts) } </code></pre> </details><a name="sui_system_validator_set_distribute_reward"></a>
distribute_reward<a name="sui_system_validator_set_emit_validator_epoch_events"></a>
emit_validator_epoch_eventsEmit events containing information of each validator for the epoch, including stakes, rewards, performance, etc.
<pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_emit_validator_epoch_events">emit_validator_epoch_events</a>(new_epoch: u64, vs: &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, pool_staking_reward_amounts: &vector<u64>, storage_fund_staking_reward_amounts: &vector<u64>, report_records: &<a href="../sui/vec_map.md#sui_vec_map_VecMap">sui::vec_map::VecMap</a><<b>address</b>, <a href="../sui/vec_set.md#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<b>address</b>>>, slashed_validators: &vector<<b>address</b>>) </code></pre> <details> <summary>Implementation</summary> <pre><code><b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_emit_validator_epoch_events">emit_validator_epoch_events</a>( new_epoch: u64, vs: &vector<Validator>, pool_staking_reward_amounts: &vector<u64>, storage_fund_staking_reward_amounts: &vector<u64>, report_records: &VecMap<<b>address</b>, VecSet<<b>address</b>>>, slashed_validators: &vector<<b>address</b>>, ) { <b>let</b> length = vs.length(); length.do!(|i| { <b>let</b> v = &vs[i]; <b>let</b> validator_address = v.sui_address(); <b>let</b> tallying_rule_reporters = <b>if</b> (report_records.contains(&validator_address)) { report_records[&validator_address].into_keys() } <b>else</b> { vector[] }; <b>let</b> tallying_rule_global_score = <b>if</b> (slashed_validators.contains(&validator_address)) { 0 } <b>else</b> { 1 }; event::emit(<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorEpochInfoEventV2">ValidatorEpochInfoEventV2</a> { epoch: new_epoch, validator_address, reference_gas_survey_quote: v.gas_price(), stake: v.<a href="../sui_system/validator_set.md#sui_system_validator_set_total_stake">total_stake</a>(), <a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>: v.<a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>(), commission_rate: v.commission_rate(), pool_staking_reward: pool_staking_reward_amounts[i], storage_fund_staking_reward: storage_fund_staking_reward_amounts[i], pool_token_exchange_rate: v.pool_token_exchange_rate_at_epoch(new_epoch), tallying_rule_reporters, tallying_rule_global_score, }); }); } </code></pre> </details><a name="sui_system_validator_set_sum_voting_power_by_addresses"></a>
sum_voting_power_by_addressesSum up the total stake of a given list of validator addresses.
<pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_sum_voting_power_by_addresses">sum_voting_power_by_addresses</a>(vs: &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>>, addresses: &vector<<b>address</b>>): u64 </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_sum_voting_power_by_addresses">sum_voting_power_by_addresses</a>(vs: &vector<Validator>, addresses: &vector<<b>address</b>>): u64 { <b>let</b> <b>mut</b> sum = 0; addresses.do_ref!(|addr| { <b>let</b> <a href="../sui_system/validator.md#sui_system_validator">validator</a> = <a href="../sui_system/validator_set.md#sui_system_validator_set_get_validator_ref">get_validator_ref</a>(vs, *addr); sum = sum + <a href="../sui_system/validator.md#sui_system_validator">validator</a>.<a href="../sui_system/voting_power.md#sui_system_voting_power">voting_power</a>(); }); sum } </code></pre> </details><a name="sui_system_validator_set_active_validators"></a>
active_validatorsReturn the active validators in <code>self</code>
<pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>): &vector<<a href="../sui_system/validator.md#sui_system_validator_Validator">sui_system::validator::Validator</a>> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>): &vector<Validator> { &self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a> } </code></pre> </details><a name="sui_system_validator_set_is_validator_candidate"></a>
is_validator_candidateReturns true if the <code>addr</code> is a validator candidate.
<pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_validator_candidate">is_validator_candidate</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, addr: <b>address</b>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_validator_candidate">is_validator_candidate</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, addr: <b>address</b>): bool { self.validator_candidates.contains(addr) } </code></pre> </details><a name="sui_system_validator_set_is_active_validator"></a>
is_active_validatorReturns true if <code>addr</code> is an active validator
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_active_validator">is_active_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, addr: <b>address</b>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_active_validator">is_active_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, addr: <b>address</b>): bool { self.<a href="../sui_system/validator_set.md#sui_system_validator_set_active_validators">active_validators</a>.any!(|v| v.sui_address() == addr) } </code></pre> </details><a name="sui_system_validator_set_is_inactive_validator"></a>
is_inactive_validatorReturns true if the staking pool identified by <code>staking_pool_id</code> is of an inactive validator.
<pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_inactive_validator">is_inactive_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, staking_pool_id: <a href="../sui/object.md#sui_object_ID">sui::object::ID</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_inactive_validator">is_inactive_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, staking_pool_id: ID): bool { self.inactive_validators.contains(staking_pool_id) } </code></pre> </details><a name="sui_system_validator_set_is_at_risk_validator"></a>
is_at_risk_validatorReturn true if <code>addr</code> is currently an at-risk validator below the minimum stake for removal
<pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_at_risk_validator">is_at_risk_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">sui_system::validator_set::ValidatorSet</a>, addr: <b>address</b>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b>(package) <b>fun</b> <a href="../sui_system/validator_set.md#sui_system_validator_set_is_at_risk_validator">is_at_risk_validator</a>(self: &<a href="../sui_system/validator_set.md#sui_system_validator_set_ValidatorSet">ValidatorSet</a>, addr: <b>address</b>): bool { self.at_risk_validators.contains(&addr) } </code></pre> </details><a name="sui_system_validator_set_active_validator_addresses"></a>
active_validator_addresses<a name="sui_system_validator_set_mul_div"></a>
mul_div<a name="sui_system_validator_set_get_active_validator_ref"></a>
get_active_validator_ref<a name="sui_system_validator_set_get_pending_validator_ref"></a>
get_pending_validator_ref