Module sui_system::sui_system_state_inner
- Struct ExecutionTimeObservationChunkKey
- Struct SystemParameters
- Struct SystemParametersV2
- Struct SuiSystemStateInner
- Struct SuiSystemStateInnerV2
- Struct SystemEpochInfoEvent
- Constants
- Function create
- Function create_system_parameters
- Function v1_to_v2
- Function request_add_validator_candidate
- Function request_remove_validator_candidate
- Function request_add_validator
- Function request_remove_validator
- Function request_set_gas_price
- Function set_candidate_validator_gas_price
- Function request_set_commission_rate
- Function set_candidate_validator_commission_rate
- Function request_add_stake
- Function request_add_stake_mul_coin
- Function request_withdraw_stake
- Function convert_to_fungible_staked_sui
- Function redeem_fungible_staked_sui
- Function report_validator
- Function undo_report_validator
- Function report_validator_impl
- Function undo_report_validator_impl
- Function rotate_operation_cap
- Function update_validator_name
- Function update_validator_description
- Function update_validator_image_url
- Function update_validator_project_url
- Function update_validator_next_epoch_network_address
- Function update_candidate_validator_network_address
- Function update_validator_next_epoch_p2p_address
- Function update_candidate_validator_p2p_address
- Function update_validator_next_epoch_primary_address
- Function update_candidate_validator_primary_address
- Function update_validator_next_epoch_worker_address
- Function update_candidate_validator_worker_address
- Function update_validator_next_epoch_protocol_pubkey
- Function update_candidate_validator_protocol_pubkey
- Function update_validator_next_epoch_worker_pubkey
- Function update_candidate_validator_worker_pubkey
- Function update_validator_next_epoch_network_pubkey
- Function update_candidate_validator_network_pubkey
- Function advance_epoch
- Function epoch
- Function protocol_version
- Function system_state_version
- Function genesis_system_state_version
- Function epoch_start_timestamp_ms
- Function validator_stake_amount
- Function active_validator_voting_powers
- Function validator_staking_pool_id
- Function validator_staking_pool_mappings
- Function get_reporters_of
- Function get_storage_fund_total_balance
- Function get_storage_fund_object_rebates
- Function validator_address_by_pool_id
- Function pool_exchange_rates
- Function active_validator_addresses
- Function extract_coin_balance
- Function store_execution_time_estimates
- Function store_execution_time_estimates_v2
- Function validators
- Function validators_mut
- Function extra_fields
- Function extra_fields_mut
- Macro function mul_div
use std::address;
use std::ascii;
use std::bcs;
use std::internal;
use std::option;
use std::string;
use std::type_name;
use std::u128;
use std::u64;
use std::vector;
use sui::accumulator;
use sui::accumulator_settlement;
use sui::address;
use sui::bag;
use sui::balance;
use sui::bcs;
use sui::coin;
use sui::config;
use sui::deny_list;
use sui::dynamic_field;
use sui::dynamic_object_field;
use sui::event;
use sui::funds_accumulator;
use sui::hash;
use sui::hex;
use sui::object;
use sui::party;
use sui::priority_queue;
use sui::protocol_config;
use sui::sui;
use sui::table;
use sui::table_vec;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::url;
use sui::vec_map;
use sui::vec_set;
use sui::versioned;
use sui_system::stake_subsidy;
use sui_system::staking_pool;
use sui_system::storage_fund;
use sui_system::validator;
use sui_system::validator_cap;
use sui_system::validator_set;
use sui_system::validator_wrapper;
use sui_system::voting_power;
Struct ExecutionTimeObservationChunkKey
public struct ExecutionTimeObservationChunkKey has copy, drop, store
Fields
- chunk_index: u64
Struct SystemParameters
A list of system config parameters.
public struct SystemParameters has store
Fields
- epoch_duration_ms: u64
- The duration of an epoch, in milliseconds.
- stake_subsidy_start_epoch: u64
- The starting epoch in which stake subsidies start being paid out
- max_validator_count: u64
-
Deprecated.
Maximum number of active validators at any moment.
We do not allow the number of validators in any epoch to go above this. - min_validator_joining_stake: u64
-
Deprecated.
Lower-bound on the amount of stake required to become a validator. - validator_low_stake_threshold: u64
- Validators with stake amount below validator_low_stake_threshold are considered to have low stake and will be escorted out of the validator set after being below this threshold for more than validator_low_stake_grace_period number of epochs.
- validator_very_low_stake_threshold: u64
-
Deprecated.
Validators with stake below validator_very_low_stake_threshold will be removed immediately at epoch change, no grace period. - validator_low_stake_grace_period: u64
- A validator can have stake below validator_low_stake_threshold for this many epochs before being kicked out.
- extra_fields: sui::bag::Bag
- Any extra fields that's not defined statically.
Struct SystemParametersV2
Added min_validator_count.
public struct SystemParametersV2 has store
Fields
- epoch_duration_ms: u64
- The duration of an epoch, in milliseconds.
- stake_subsidy_start_epoch: u64
- The starting epoch in which stake subsidies start being paid out
- min_validator_count: u64
- Minimum number of active validators at any moment.
- max_validator_count: u64
-
Maximum number of active validators at any moment.
We do not allow the number of validators in any epoch to go above this. - min_validator_joining_stake: u64
-
Deprecated.
Lower-bound on the amount of stake required to become a validator. - validator_low_stake_threshold: u64
-
Deprecated.
Validators with stake amount below validator_low_stake_threshold are considered to have low stake and will be escorted out of the validator set after being below this threshold for more than validator_low_stake_grace_period number of epochs. - validator_very_low_stake_threshold: u64
-
Deprecated.
Validators with stake below validator_very_low_stake_threshold will be removed immediately at epoch change, no grace period. - validator_low_stake_grace_period: u64
- A validator can have stake below validator_low_stake_threshold for this many epochs before being kicked out.
- extra_fields: sui::bag::Bag
- Any extra fields that's not defined statically.
Struct SuiSystemStateInner
The top-level object containing all information of the Sui system.
public struct SuiSystemStateInner has store
Fields
- epoch: u64
- The current epoch ID, starting from 0.
- protocol_version: u64
- The current protocol version, starting from 1.
- system_state_version: u64
-
The current version of the system state data structure type.
This is always the same as SuiSystemState.version. Keeping a copy here so that we know what version it is by inspecting SuiSystemStateInner as well. - validators: sui_system::validator_set::ValidatorSet
- Contains all information about the validators.
- storage_fund: sui_system::storage_fund::StorageFund
- The storage fund.
- parameters: sui_system::sui_system_state_inner::SystemParameters
- A list of system config parameters.
- reference_gas_price: u64
- The reference gas price for the current epoch.
- validator_report_records: sui::vec_map::VecMap<address, sui::vec_set::VecSet<address>>
-
A map storing the records of validator reporting each other.
There is an entry in the map for each validator that has been reported at least once. The entry VecSet contains all the validators that reported them. If a validator has never been reported they don't have an entry in this map.
This map persists across epoch: a peer continues being in a reported state until the reporter doesn't explicitly remove their report.
Note that in case we want to support validator address change in future, the reports should be based on validator ids - stake_subsidy: sui_system::stake_subsidy::StakeSubsidy
- Schedule of stake subsidies given out each epoch.
- safe_mode: bool
-
Whether the system is running in a downgraded safe mode due to a non-recoverable bug.
This is set whenever we failed to execute advance_epoch, and ended up executing advance_epoch_safe_mode.
It can be reset once we are able to successfully execute advance_epoch.
The rest of the fields starting with safe_mode_ are accumulated during safe mode when advance_epoch_safe_mode is executed. They will eventually be processed once we are out of safe mode. - safe_mode_storage_rewards: sui::balance::Balance<sui::sui::SUI>
- safe_mode_computation_rewards: sui::balance::Balance<sui::sui::SUI>
- safe_mode_storage_rebates: u64
- safe_mode_non_refundable_storage_fee: u64
- epoch_start_timestamp_ms: u64
- Unix timestamp of the current epoch start
- extra_fields: sui::bag::Bag
- Any extra fields that's not defined statically.
Struct SuiSystemStateInnerV2
Uses SystemParametersV2 as the parameters.
public struct SuiSystemStateInnerV2 has store
Fields
- epoch: u64
- The current epoch ID, starting from 0.
- protocol_version: u64
- The current protocol version, starting from 1.
- system_state_version: u64
-
The current version of the system state data structure type.
This is always the same as SuiSystemState.version. Keeping a copy here so that we know what version it is by inspecting SuiSystemStateInner as well. - validators: sui_system::validator_set::ValidatorSet
- Contains all information about the validators.
- storage_fund: sui_system::storage_fund::StorageFund
- The storage fund.
- parameters: sui_system::sui_system_state_inner::SystemParametersV2
- A list of system config parameters.
- reference_gas_price: u64
- The reference gas price for the current epoch.
- validator_report_records: sui::vec_map::VecMap<address, sui::vec_set::VecSet<address>>
-
A map storing the records of validator reporting each other.
There is an entry in the map for each validator that has been reported at least once. The entry VecSet contains all the validators that reported them. If a validator has never been reported they don't have an entry in this map.
This map persists across epoch: a peer continues being in a reported state until the reporter doesn't explicitly remove their report.
Note that in case we want to support validator address change in future, the reports should be based on validator ids - stake_subsidy: sui_system::stake_subsidy::StakeSubsidy
- Schedule of stake subsidies given out each epoch.
- safe_mode: bool
-
Whether the system is running in a downgraded safe mode due to a non-recoverable bug.
This is set whenever we failed to execute advance_epoch, and ended up executing advance_epoch_safe_mode.
It can be reset once we are able to successfully execute advance_epoch.
The rest of the fields starting with safe_mode_ are accumulated during safe mode when advance_epoch_safe_mode is executed. They will eventually be processed once we are out of safe mode. - safe_mode_storage_rewards: sui::balance::Balance<sui::sui::SUI>
- safe_mode_computation_rewards: sui::balance::Balance<sui::sui::SUI>
- safe_mode_storage_rebates: u64
- safe_mode_non_refundable_storage_fee: u64
- epoch_start_timestamp_ms: u64
- Unix timestamp of the current epoch start
- extra_fields: sui::bag::Bag
- Any extra fields that's not defined statically.
Struct SystemEpochInfoEvent
Event containing system-level epoch information, emitted during the epoch advancement transaction.
public struct SystemEpochInfoEvent has copy, drop
Fields
- epoch: u64
- protocol_version: u64
- reference_gas_price: u64
- total_stake: u64
- storage_fund_reinvestment: u64
- storage_charge: u64
- storage_rebate: u64
- storage_fund_balance: u64
- stake_subsidy_amount: u64
- total_gas_fees: u64
- total_stake_rewards_distributed: u64
- leftover_storage_fund_inflow: u64
Constants
const ENotValidator: u64 = 0;
const ELimitExceeded: u64 = 1;
const ENotSystemAddress: u64 = 2;
const ECannotReportOneself: u64 = 3;
const EReportRecordNotFound: u64 = 4;
const EBpsTooLarge: u64 = 5;
const ESafeModeGasNotProcessed: u64 = 7;
const EAdvancedToWrongEpoch: u64 = 8;
const BASIS_POINT_DENOMINATOR: u64 = 10000;
const ACTIVE_VALIDATOR_ONLY: u8 = 1;
const ACTIVE_OR_PENDING_VALIDATOR: u8 = 2;
const ANY_VALIDATOR: u8 = 3;
const SYSTEM_STATE_VERSION_V1: u64 = 1;
const EXTRA_FIELD_EXECUTION_TIME_ESTIMATES_KEY: u64 = 0;
const EXTRA_FIELD_EXECUTION_TIME_ESTIMATES_CHUNK_COUNT_KEY: u64 = 1;
Function create
Create a new SuiSystemState object and make it shared.
This function will be called only once in genesis.
public(package) fun create(validators: vector<sui_system::validator::Validator>, initial_storage_fund: sui::balance::Balance<sui::sui::SUI>, protocol_version: u64, epoch_start_timestamp_ms: u64, parameters: sui_system::sui_system_state_inner::SystemParameters, stake_subsidy: sui_system::stake_subsidy::StakeSubsidy, ctx: &mut sui::tx_context::TxContext): sui_system::sui_system_state_inner::SuiSystemStateInner
Function create_system_parameters
public(package) fun create_system_parameters(epoch_duration_ms: u64, stake_subsidy_start_epoch: u64, max_validator_count: u64, min_validator_joining_stake: u64, validator_low_stake_threshold: u64, validator_very_low_stake_threshold: u64, validator_low_stake_grace_period: u64, ctx: &mut sui::tx_context::TxContext): sui_system::sui_system_state_inner::SystemParameters
Function v1_to_v2
public(package) fun v1_to_v2(self: sui_system::sui_system_state_inner::SuiSystemStateInner): sui_system::sui_system_state_inner::SuiSystemStateInnerV2
Function request_add_validator_candidate
Can be called by anyone who wishes to become a validator candidate and starts accruing delegated
stakes in their staking pool. Once they have at least MIN_VALIDATOR_JOINING_STAKE amount of stake they
can call request_add_validator to officially become an active validator at the next epoch.
Aborts if the caller is already a pending or active validator, or a validator candidate.
Note: proof_of_possession MUST be a valid signature using sui_address and protocol_pubkey_bytes.
To produce a valid PoP, run [fn test_proof_of_possession].
public(package) fun request_add_validator_candidate(self: &mut sui_system::sui_system_state_inner::SuiSystemStateInnerV2, pubkey_bytes: vector<u8>, network_pubkey_bytes: vector<u8>, worker_pubkey_bytes: vector<u8>, proof_of_possession: vector<u8>, name: vector<u8>, description: vector<u8>, image_url: vector<u8>, project_url: vector<u8>, net_address: vector<u8>, p2p_address: vector<u8>, primary_address: vector<u8>, worker_address: vector<u8>, gas_price: u64, commission_rate: u64, ctx: &mut sui::tx_context::TxContext)
Function request_remove_validator_candidate
Called by a validator candidate to remove themselves from the candidacy. After this call their staking pool becomes deactivate.
public(package) fun request_remove_validator_candidate(self: &mut sui_system::sui_system_state_inner::SuiSystemStateInnerV2, ctx: &mut sui::tx_context::TxContext)
Function request_add_validator
Called by a validator candidate to add themselves to the active validator set beginning next epoch.
Aborts if the validator is a duplicate with one of the pending or active validators, or if the amount of
stake the validator has doesn't meet the min threshold, or if the number of new validators for the next
epoch has already reached the maximum.
public(package) fun request_add_validator(self: &mut sui_system::sui_system_state_inner::SuiSystemStateInnerV2, ctx: &sui::tx_context::TxContext)
Function request_remove_validator
A validator can call this function to request a removal in the next epoch.
We use the sender of ctx to look up the validator
(i.e. sender must match the sui_address in the validator).
At the end of the epoch, the validator object will be returned to the sui_address
of the validator.
public(package) fun request_remove_validator(self: &mut sui_system::sui_system_state_inner::SuiSystemStateInnerV2, ctx: &sui::tx_context::TxContext)
Function request_set_gas_price
A validator can call this function to submit a new gas price quote, to be used for the reference gas price calculation at the end of the epoch.
public(package) fun request_set_gas_price(self: &mut sui_system::sui_system_state_inner::SuiSystemStateInnerV2, cap: &sui_system::validator_cap::UnverifiedValidatorOperationCap, new_gas_price: u64)