Skip to content

Commit

Permalink
add getter for active validator addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
emmazzz committed Jul 20, 2023
1 parent 878c026 commit 7b8aff2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 2 deletions.
27 changes: 27 additions & 0 deletions crates/sui-framework/docs/sui_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ the SuiSystemStateInner version, or vice versa.
- [Function `update_validator_next_epoch_network_pubkey`](#0x3_sui_system_update_validator_next_epoch_network_pubkey)
- [Function `update_candidate_validator_network_pubkey`](#0x3_sui_system_update_candidate_validator_network_pubkey)
- [Function `pool_exchange_rates`](#0x3_sui_system_pool_exchange_rates)
- [Function `active_validator_addresses`](#0x3_sui_system_active_validator_addresses)
- [Function `advance_epoch`](#0x3_sui_system_advance_epoch)
- [Function `load_system_state`](#0x3_sui_system_load_system_state)
- [Function `load_system_state_mut`](#0x3_sui_system_load_system_state_mut)
Expand Down Expand Up @@ -1320,6 +1321,32 @@ Getter of the pool token exchange rate of a staking pool. Works for both active



</details>

<a name="0x3_sui_system_active_validator_addresses"></a>

## Function `active_validator_addresses`

Getter returning addresses of the currently active validators.


<pre><code><b>public</b> <b>fun</b> <a href="sui_system.md#0x3_sui_system_active_validator_addresses">active_validator_addresses</a>(wrapper: &<b>mut</b> <a href="sui_system.md#0x3_sui_system_SuiSystemState">sui_system::SuiSystemState</a>): <a href="">vector</a>&lt;<b>address</b>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="sui_system.md#0x3_sui_system_active_validator_addresses">active_validator_addresses</a>(wrapper: &<b>mut</b> <a href="sui_system.md#0x3_sui_system_SuiSystemState">SuiSystemState</a>): <a href="">vector</a>&lt;<b>address</b>&gt; {
<b>let</b> self = <a href="sui_system.md#0x3_sui_system_load_system_state">load_system_state</a>(wrapper);
<a href="sui_system_state_inner.md#0x3_sui_system_state_inner_active_validator_addresses">sui_system_state_inner::active_validator_addresses</a>(self)
}
</code></pre>



</details>

<a name="0x3_sui_system_advance_epoch"></a>
Expand Down
26 changes: 26 additions & 0 deletions crates/sui-framework/docs/sui_system_state_inner.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
- [Function `get_storage_fund_total_balance`](#0x3_sui_system_state_inner_get_storage_fund_total_balance)
- [Function `get_storage_fund_object_rebates`](#0x3_sui_system_state_inner_get_storage_fund_object_rebates)
- [Function `pool_exchange_rates`](#0x3_sui_system_state_inner_pool_exchange_rates)
- [Function `active_validator_addresses`](#0x3_sui_system_state_inner_active_validator_addresses)
- [Function `extract_coin_balance`](#0x3_sui_system_state_inner_extract_coin_balance)
- [Module Specification](#@Module_Specification_1)

Expand Down Expand Up @@ -2538,6 +2539,31 @@ Returns all the validators who are currently reporting <code>addr</code>



</details>

<a name="0x3_sui_system_state_inner_active_validator_addresses"></a>

## Function `active_validator_addresses`



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="sui_system_state_inner.md#0x3_sui_system_state_inner_active_validator_addresses">active_validator_addresses</a>(self: &<a href="sui_system_state_inner.md#0x3_sui_system_state_inner_SuiSystemStateInnerV2">sui_system_state_inner::SuiSystemStateInnerV2</a>): <a href="">vector</a>&lt;<b>address</b>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="sui_system_state_inner.md#0x3_sui_system_state_inner_active_validator_addresses">active_validator_addresses</a>(self: &<a href="sui_system_state_inner.md#0x3_sui_system_state_inner_SuiSystemStateInnerV2">SuiSystemStateInnerV2</a>): <a href="">vector</a>&lt;<b>address</b>&gt; {
<b>let</b> <a href="validator_set.md#0x3_validator_set">validator_set</a> = &self.validators;
<a href="validator_set.md#0x3_validator_set_active_validator_addresses">validator_set::active_validator_addresses</a>(<a href="validator_set.md#0x3_validator_set">validator_set</a>)
}
</code></pre>



</details>

<a name="0x3_sui_system_state_inner_extract_coin_balance"></a>
Expand Down
34 changes: 34 additions & 0 deletions crates/sui-framework/docs/validator_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
- [Function `active_validators`](#0x3_validator_set_active_validators)
- [Function `is_validator_candidate`](#0x3_validator_set_is_validator_candidate)
- [Function `is_inactive_validator`](#0x3_validator_set_is_inactive_validator)
- [Function `active_validator_addresses`](#0x3_validator_set_active_validator_addresses)
- [Module Specification](#@Module_Specification_1)


Expand Down Expand Up @@ -2861,6 +2862,39 @@ Returns true if the staking pool identified by <code>staking_pool_id</code> is o



</details>

<a name="0x3_validator_set_active_validator_addresses"></a>

## Function `active_validator_addresses`



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="validator_set.md#0x3_validator_set_active_validator_addresses">active_validator_addresses</a>(self: &<a href="validator_set.md#0x3_validator_set_ValidatorSet">validator_set::ValidatorSet</a>): <a href="">vector</a>&lt;<b>address</b>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="validator_set.md#0x3_validator_set_active_validator_addresses">active_validator_addresses</a>(self: &<a href="validator_set.md#0x3_validator_set_ValidatorSet">ValidatorSet</a>): <a href="">vector</a>&lt;<b>address</b>&gt; {
<b>let</b> vs = &self.active_validators;
<b>let</b> res = <a href="">vector</a>[];
<b>let</b> i = 0;
<b>let</b> length = <a href="_length">vector::length</a>(vs);
<b>while</b> (i &lt; length) {
<b>let</b> validator_address = <a href="validator.md#0x3_validator_sui_address">validator::sui_address</a>(<a href="_borrow">vector::borrow</a>(vs, i));
<a href="_push_back">vector::push_back</a>(&<b>mut</b> res, validator_address);
i = i + 1;
};
res
}
</code></pre>



</details>

<a name="@Module_Specification_1"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ module sui_system::sui_system {
sui_system_state_inner::pool_exchange_rates(self, pool_id)
}

/// Getter returning addresses of the currently active validators.
public fun active_validator_addresses(wrapper: &mut SuiSystemState): vector<address> {
let self = load_system_state(wrapper);
sui_system_state_inner::active_validator_addresses(self)
}

/// This function should be called at the end of an epoch, and advances the system to the next epoch.
/// It does the following things:
/// 1. Add storage charge to the storage fund.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,11 @@ module sui_system::sui_system_state_inner {
validator_set::pool_exchange_rates(validators, pool_id)
}

public(friend) fun active_validator_addresses(self: &SuiSystemStateInnerV2): vector<address> {
let validator_set = &self.validators;
validator_set::active_validator_addresses(validator_set)
}

/// Extract required Balance from vector of Coin<SUI>, transfer the remainder back to sender.
fun extract_coin_balance(coins: vector<Coin<SUI>>, amount: option::Option<u64>, ctx: &mut TxContext): Balance<SUI> {
let merged_coin = vector::pop_back(&mut coins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,7 @@ module sui_system::validator_set {
table::contains(&self.inactive_validators, staking_pool_id)
}

#[test_only]
public fun active_validator_addresses(self: &ValidatorSet): vector<address> {
public(friend) fun active_validator_addresses(self: &ValidatorSet): vector<address> {
let vs = &self.active_validators;
let res = vector[];
let i = 0;
Expand Down

0 comments on commit 7b8aff2

Please sign in to comment.