Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions crates/sui-framework/docs/sui-system/sui_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ the SuiSystemStateInner version, or vice versa.
- [Function `update_candidate_validator_network_pubkey`](#0x3_sui_system_update_candidate_validator_network_pubkey)
- [Function `validator_address_by_pool_id`](#0x3_sui_system_validator_address_by_pool_id)
- [Function `pool_exchange_rates`](#0x3_sui_system_pool_exchange_rates)
- [Function `is_staking_pool_active`](#0x3_sui_system_is_staking_pool_active)
- [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)
Expand Down Expand Up @@ -1409,6 +1410,34 @@ Getter of the pool token exchange rate of a staking pool. Works for both active



</details>

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

## Function `is_staking_pool_active`



<pre><code><b>public</b> <b>fun</b> <a href="sui_system.md#0x3_sui_system_is_staking_pool_active">is_staking_pool_active</a>(wrapper: &<b>mut</b> <a href="sui_system.md#0x3_sui_system_SuiSystemState">sui_system::SuiSystemState</a>, staking_pool_id: &<a href="../sui-framework/object.md#0x2_object_ID">object::ID</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="sui_system.md#0x3_sui_system_is_staking_pool_active">is_staking_pool_active</a>(
wrapper: &<b>mut</b> <a href="sui_system.md#0x3_sui_system_SuiSystemState">SuiSystemState</a>,
staking_pool_id: &ID
): bool {
<b>let</b> self = <a href="sui_system.md#0x3_sui_system_load_system_state_mut">load_system_state_mut</a>(wrapper);
self.<a href="sui_system.md#0x3_sui_system_is_staking_pool_active">is_staking_pool_active</a>(staking_pool_id)
}
</code></pre>



</details>

<a name="0x3_sui_system_active_validator_addresses"></a>
Expand Down
28 changes: 28 additions & 0 deletions crates/sui-framework/docs/sui-system/sui_system_state_inner.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ title: Module `0x3::sui_system_state_inner`
- [Function `get_storage_fund_object_rebates`](#0x3_sui_system_state_inner_get_storage_fund_object_rebates)
- [Function `validator_address_by_pool_id`](#0x3_sui_system_state_inner_validator_address_by_pool_id)
- [Function `pool_exchange_rates`](#0x3_sui_system_state_inner_pool_exchange_rates)
- [Function `is_staking_pool_active`](#0x3_sui_system_state_inner_is_staking_pool_active)
- [Function `active_validator_addresses`](#0x3_sui_system_state_inner_active_validator_addresses)
- [Function `extract_coin_balance`](#0x3_sui_system_state_inner_extract_coin_balance)

Expand Down Expand Up @@ -2632,6 +2633,33 @@ Returns all the validators who are currently reporting <code>addr</code>



</details>

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

## Function `is_staking_pool_active`



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="sui_system_state_inner.md#0x3_sui_system_state_inner_is_staking_pool_active">is_staking_pool_active</a>(self: &<b>mut</b> <a href="sui_system_state_inner.md#0x3_sui_system_state_inner_SuiSystemStateInnerV2">sui_system_state_inner::SuiSystemStateInnerV2</a>, staking_pool_id: &<a href="../sui-framework/object.md#0x2_object_ID">object::ID</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(package) <b>fun</b> <a href="sui_system_state_inner.md#0x3_sui_system_state_inner_is_staking_pool_active">is_staking_pool_active</a>(
self: &<b>mut</b> <a href="sui_system_state_inner.md#0x3_sui_system_state_inner_SuiSystemStateInnerV2">SuiSystemStateInnerV2</a>,
staking_pool_id: &ID
): bool {
self.validators.<a href="sui_system_state_inner.md#0x3_sui_system_state_inner_is_staking_pool_active">is_staking_pool_active</a>(staking_pool_id)
}
</code></pre>



</details>

<a name="0x3_sui_system_state_inner_active_validator_addresses"></a>
Expand Down
32 changes: 32 additions & 0 deletions crates/sui-framework/docs/sui-system/validator_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ title: Module `0x3::validator_set`
- [Function `staking_pool_mappings`](#0x3_validator_set_staking_pool_mappings)
- [Function `validator_address_by_pool_id`](#0x3_validator_set_validator_address_by_pool_id)
- [Function `pool_exchange_rates`](#0x3_validator_set_pool_exchange_rates)
- [Function `is_staking_pool_active`](#0x3_validator_set_is_staking_pool_active)
- [Function `next_epoch_validator_count`](#0x3_validator_set_next_epoch_validator_count)
- [Function `is_active_validator_by_sui_address`](#0x3_validator_set_is_active_validator_by_sui_address)
- [Function `is_duplicate_with_active_validator`](#0x3_validator_set_is_duplicate_with_active_validator)
Expand Down Expand Up @@ -1547,6 +1548,37 @@ gas price, weighted by stake.



</details>

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

## Function `is_staking_pool_active`



<pre><code><b>public</b> <b>fun</b> <a href="validator_set.md#0x3_validator_set_is_staking_pool_active">is_staking_pool_active</a>(self: &<b>mut</b> <a href="validator_set.md#0x3_validator_set_ValidatorSet">validator_set::ValidatorSet</a>, staking_pool_id: &<a href="../sui-framework/object.md#0x2_object_ID">object::ID</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="validator_set.md#0x3_validator_set_is_staking_pool_active">is_staking_pool_active</a>(self: &<b>mut</b> <a href="validator_set.md#0x3_validator_set_ValidatorSet">ValidatorSet</a>, staking_pool_id: &ID): bool {
<b>if</b> (self.staking_pool_mappings.contains(*staking_pool_id)) {
<b>let</b> validator_address = self.staking_pool_mappings[*staking_pool_id];
<b>let</b> validator_index_opt = <a href="validator_set.md#0x3_validator_set_find_validator">find_validator</a>(&self.active_validators, validator_address);

validator_index_opt.is_some()
} <b>else</b> { // <a href="validator.md#0x3_validator">validator</a> is inactive
<b>false</b>
}
}
</code></pre>



</details>

<a name="0x3_validator_set_next_epoch_validator_count"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,14 @@ module sui_system::sui_system {
self.pool_exchange_rates(pool_id)
}

public fun is_staking_pool_active(
wrapper: &mut SuiSystemState,
staking_pool_id: &ID
): bool {
let self = load_system_state_mut(wrapper);
self.is_staking_pool_active(staking_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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,13 @@ module sui_system::sui_system_state_inner {
validators.pool_exchange_rates(pool_id)
}

public(package) fun is_staking_pool_active(
self: &mut SuiSystemStateInnerV2,
staking_pool_id: &ID
): bool {
self.validators.is_staking_pool_active(staking_pool_id)
}

public(package) fun active_validator_addresses(self: &SuiSystemStateInnerV2): vector<address> {
let validator_set = &self.validators;
validator_set.active_validator_addresses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ module sui_system::validator_set {
validator.get_staking_pool_ref().exchange_rates()
}

public fun is_staking_pool_active(self: &mut ValidatorSet, staking_pool_id: &ID): bool {
if (self.staking_pool_mappings.contains(*staking_pool_id)) {
let validator_address = self.staking_pool_mappings[*staking_pool_id];
let validator_index_opt = find_validator(&self.active_validators, validator_address);

validator_index_opt.is_some()
} else { // validator is inactive
false
}
}

/// Get the total number of validators in the next epoch.
public(package) fun next_epoch_validator_count(self: &ValidatorSet): u64 {
self.active_validators.length() - self.pending_removals.length() + self.pending_active_validators.length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,4 +1125,73 @@ module sui_system::sui_system_tests {
scenario_val.end();
}

#[test]
fun test_is_staking_pool_active() {
let mut scenario_val = test_scenario::begin(@0x0);
let scenario = &mut scenario_val;

set_up_sui_system_state(vector[@0x1]);

// 1. add candidate validator
scenario.next_tx(@0x2);
let mut system_state = scenario.take_shared<SuiSystemState>();
let pubkey = x"99f25ef61f8032b914636460982c5cc6f134ef1ddae76657f2cbfec1ebfc8d097374080df6fcf0dcb8bc4b0d8e0af5d80ebbff2b4c599f54f42d6312dfc314276078c1cc347ebbbec5198be258513f386b930d02c2749a803e2330955ebd1a10";
let pop = x"b01cc86f421beca7ab4cfca87c0799c4d038c199dd399fbec1924d4d4367866dba9e84d514710b91feb65316e4ceef43";
system_state.request_add_validator_candidate_for_testing(
pubkey,
vector[215, 64, 85, 185, 231, 116, 69, 151, 97, 79, 4, 183, 20, 70, 84, 51, 211, 162, 115, 221, 73, 241, 240, 171, 192, 25, 232, 106, 175, 162, 176, 43],
vector[148, 117, 212, 171, 44, 104, 167, 11, 177, 100, 4, 55, 17, 235, 117, 45, 117, 84, 159, 49, 14, 159, 239, 246, 237, 21, 83, 166, 112, 53, 62, 199],
pop,
b"ValidatorName2",
b"description2",
b"image_url2",
b"project_url2",
b"/ip4/127.0.0.2/tcp/80",
b"/ip4/127.0.0.2/udp/80",
b"/ip4/168.168.168.168/udp/80",
b"/ip4/168.168.168.168/udp/80",
1,
0,
scenario.ctx(),
);
let staking_pool_id = system_state.candidate_validator_by_address(@0x2).staking_pool_id();

// 2. validator candidate staking pools are inactive
assert!(!system_state.is_staking_pool_active(&staking_pool_id), 0);
test_scenario::return_shared(system_state);

stake_with(@0x0, @0x2, 1_000_000, scenario);

// 3. mark candidate as pending active validator
scenario.next_tx(@0x2);
let mut system_state = scenario.take_shared<SuiSystemState>();
system_state.request_add_validator(scenario.ctx());

// 4. validator is pending activation, but is not active yet
assert!(!system_state.is_staking_pool_active(&staking_pool_id), 0);
test_scenario::return_shared(system_state);

advance_epoch(scenario);

// 5. validator is active now
scenario.next_tx(@0x2);
let mut system_state = scenario.take_shared<SuiSystemState>();
assert!(system_state.is_staking_pool_active(&staking_pool_id), 0);

// 6. remove validator
system_state.request_remove_validator(scenario.ctx());
assert!(system_state.is_staking_pool_active(&staking_pool_id), 0);

test_scenario::return_shared(system_state);

advance_epoch(scenario);

// 7. validator is inactive now
let mut system_state = scenario.take_shared<SuiSystemState>();
assert!(!system_state.is_staking_pool_active(&staking_pool_id), 0);
test_scenario::return_shared(system_state);

scenario_val.end();
}

}
Binary file modified crates/sui-framework/packages_compiled/sui-system
Binary file not shown.
9 changes: 9 additions & 0 deletions crates/sui-framework/published_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ validator_address_by_pool_id
pool_exchange_rates
public(package) fun
0x3::validator_set
is_staking_pool_active
public fun
0x3::validator_set
next_epoch_validator_count
public(package) fun
0x3::validator_set
Expand Down Expand Up @@ -868,6 +871,9 @@ validator_address_by_pool_id
pool_exchange_rates
public(package) fun
0x3::sui_system_state_inner
is_staking_pool_active
public(package) fun
0x3::sui_system_state_inner
active_validator_addresses
public(package) fun
0x3::sui_system_state_inner
Expand Down Expand Up @@ -994,6 +1000,9 @@ validator_address_by_pool_id
pool_exchange_rates
public fun
0x3::sui_system
is_staking_pool_active
public fun
0x3::sui_system
active_validator_addresses
public fun
0x3::sui_system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,56 +240,56 @@ validators:
next_epoch_worker_address: ~
extra_fields:
id:
id: "0x16578006efdc72b0cf4af52c7041769be271a76d29b8f34b86a1d68013d8a88f"
id: "0xd355036cd0ea94e1656eec61784b4b6a49a6cbe12faf13adc162563dbb336e03"
size: 0
voting_power: 10000
operation_cap_id: "0xe9a0ddf35b90054400a2cffa042cc8cd13c315a89a7fb3b660e0c3d395ddf2b9"
operation_cap_id: "0x28d8f40f38656a1f80322c69e316cc47ffda246904e4fbf819633a56893f3dbf"
gas_price: 1000
staking_pool:
id: "0xe8c4a71d1b5abb43eae33b7fd748857f77b0b96e39bc2bea9338d3283ace96a2"
id: "0x8f72a329c943e11cb613f2496457442ca16ed0ce2d7562cca114f80a942a6b28"
activation_epoch: 0
deactivation_epoch: ~
sui_balance: 20000000000000000
rewards_pool:
value: 0
pool_token_balance: 20000000000000000
exchange_rates:
id: "0x4680ae9c79f637c2d442bb7b1ee316b430e7667bd5bef5d3d9d6698fe83b0b14"
id: "0x4860bfe3af0b754b1d2aa5b605ccf0208277c2f5e13b4948e3dbbd90e741aa14"
size: 1
pending_stake: 0
pending_total_sui_withdraw: 0
pending_pool_token_withdraw: 0
extra_fields:
id:
id: "0x7651a29637fabc6534ba02e496f2700d94a02989e828cc7e923c655c6720b29c"
id: "0x2229ebaea6ec55ba511d40a799a8c906daf8ed0559898159b26a6a2a0c081963"
size: 0
commission_rate: 200
next_epoch_stake: 20000000000000000
next_epoch_gas_price: 1000
next_epoch_commission_rate: 200
extra_fields:
id:
id: "0xc44d348b8dc5dd36ce408ef476da3c00981ade6c8738f78fe8dfbdeb1fb4ebf4"
id: "0x6bc4ed87927711d8a20a83f530bd15220bc233ad5fc058215357789edcefdfd6"
size: 0
pending_active_validators:
contents:
id: "0xc88fc24de4cd34f57fb3f8bc7129e4fd0568fe1fc614ee254b91010be81e416f"
id: "0x40622f221ccb79ca180a281cb453a616cd9c542b8a6fb6706268e9405c9b0281"
size: 0
pending_removals: []
staking_pool_mappings:
id: "0xe3e3c63a2fa241502b3bf9f5b3cfdf17949f7f0c7eec2bbfe068b7a80898c5e3"
id: "0x4e9ef5df90bc10782f6d4323bafbe5cdd472c015f8670588030916de42159a4f"
size: 1
inactive_validators:
id: "0xa3343f8bc654c133844d7902df6547c5f93e69be4556e4e0d9d8eb475d37fda3"
id: "0x46f04a775674612f37a1aa6fa12eaa51bcbcc9660ee1fd2abebe7365b920a9d4"
size: 0
validator_candidates:
id: "0x36b7cbbb1e000e15f0bf117393656a83bd3920db9351522e49cfcb88fa35cfb7"
id: "0x0b4c665aeb7cf92813b28e3e11890b453a29f9f567bf2c57ee04431149108b29"
size: 0
at_risk_validators:
contents: []
extra_fields:
id:
id: "0x8a970125484c6bd90c89a0e350983ced38d3d998756eb9b7da10f50208a1b19b"
id: "0x5df8fc499d4545ec4129aa08757d7857befda3b53f5829adb1394721ed9290b7"
size: 0
storage_fund:
total_object_storage_rebates:
Expand All @@ -306,7 +306,7 @@ parameters:
validator_low_stake_grace_period: 7
extra_fields:
id:
id: "0x2ec53040183de634d6c7dd84f599514b5dec168e357b7ca5886ba9e803bed2cf"
id: "0x34e1dbf28f0430fda55b790157a164f7e44454bd98b4a16bf56e516bcdf678be"
size: 0
reference_gas_price: 1000
validator_report_records:
Expand All @@ -320,7 +320,7 @@ stake_subsidy:
stake_subsidy_decrease_rate: 1000
extra_fields:
id:
id: "0xdacf345d4ada91c2cd1918e4d7c305bc9696444680b49c2bcd549b6bc1bafec1"
id: "0xccb973dc3e6e39b6804d0dd49484032f849f99dfc558bd18d384b497a42b0197"
size: 0
safe_mode: false
safe_mode_storage_rewards:
Expand All @@ -332,6 +332,5 @@ safe_mode_non_refundable_storage_fee: 0
epoch_start_timestamp_ms: 10
extra_fields:
id:
id: "0xb6984ac32dd8af5599ce3ba4201c5f636ba4c907704b40e965f3d8c61fee77d2"
id: "0xed3b16d5352bcea990d44fe9f768b794d27f161da35976e473aca2062008e82d"
size: 0

Loading