Module 0x3::sui_system_state_inner
- 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
use 0x1::option;
use 0x1::vector;
use 0x2::bag;
use 0x2::balance;
use 0x2::coin;
use 0x2::event;
use 0x2::object;
use 0x2::pay;
use 0x2::sui;
use 0x2::table;
use 0x2::transfer;
use 0x2::tx_context;
use 0x2::vec_map;
use 0x2::vec_set;
use 0x3::stake_subsidy;
use 0x3::staking_pool;
use 0x3::storage_fund;
use 0x3::validator;
use 0x3::validator_cap;
use 0x3::validator_set;
Struct SystemParameters
A list of system config parameters.
struct SystemParameters has store
Fields
Struct SystemParametersV2
Added min_validator_count.
struct SystemParametersV2 has store
Fields
Struct SuiSystemStateInner
The top-level object containing all information of the Sui system.
struct SuiSystemStateInner has store
Fields
Struct SuiSystemStateInnerV2
Uses SystemParametersV2 as the parameters.
struct SuiSystemStateInnerV2 has store
Fields
Struct SystemEpochInfoEvent
Event containing system-level epoch information, emitted during the epoch advancement transaction.
struct SystemEpochInfoEvent has copy, drop
Fields
Constants
const ENotSystemAddress: u64 = 2;
const ACTIVE_OR_PENDING_VALIDATOR: u8 = 2;
const ACTIVE_VALIDATOR_ONLY: u8 = 1;
const ANY_VALIDATOR: u8 = 3;
const BASIS_POINT_DENOMINATOR: u128 = 10000;
const EAdvancedToWrongEpoch: u64 = 8;
const EBpsTooLarge: u64 = 5;
const ECannotReportOneself: u64 = 3;
const ELimitExceeded: u64 = 1;
const ENotValidator: u64 = 0;
const EReportRecordNotFound: u64 = 4;
const ESafeModeGasNotProcessed: u64 = 7;
const SYSTEM_STATE_VERSION_V1: u64 = 1;
Function create
Create a new SuiSystemState object and make it shared. This function will be called only once in genesis.
public(friend) fun create(validators: vector<validator::Validator>, initial_storage_fund: balance::Balance<sui::SUI>, protocol_version: u64, epoch_start_timestamp_ms: u64, parameters: sui_system_state_inner::SystemParameters, stake_subsidy: stake_subsidy::StakeSubsidy, ctx: &mut tx_context::TxContext): sui_system_state_inner::SuiSystemStateInner
Implementation
Function create_system_parameters
public(friend) 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 tx_context::TxContext): sui_system_state_inner::SystemParameters
Implementation
Function v1_to_v2
public(friend) fun v1_to_v2(self: sui_system_state_inner::SuiSystemStateInner): sui_system_state_inner::SuiSystemStateInnerV2
Implementation
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(friend) fun request_add_validator_candidate(self: &mut 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 tx_context::TxContext)
Implementation
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(friend) fun request_remove_validator_candidate(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, ctx: &mut tx_context::TxContext)
Implementation
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(friend) fun request_add_validator(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, ctx: &tx_context::TxContext)
Implementation
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(friend) fun request_remove_validator(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, ctx: &tx_context::TxContext)
Implementation
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(friend) fun request_set_gas_price(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, cap: &validator_cap::UnverifiedValidatorOperationCap, new_gas_price: u64)
Implementation
Function set_candidate_validator_gas_price
This function is used to set new gas price for candidate validators
public(friend) fun set_candidate_validator_gas_price(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, cap: &validator_cap::UnverifiedValidatorOperationCap, new_gas_price: u64)
Implementation
Function request_set_commission_rate
A validator can call this function to set a new commission rate, updated at the end of the epoch.
public(friend) fun request_set_commission_rate(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, new_commission_rate: u64, ctx: &tx_context::TxContext)
Implementation
Function set_candidate_validator_commission_rate
This function is used to set new commission rate for candidate validators
public(friend) fun set_candidate_validator_commission_rate(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, new_commission_rate: u64, ctx: &tx_context::TxContext)
Implementation
Function request_add_stake
Add stake to a validator's staking pool.
public(friend) fun request_add_stake(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, stake: coin::Coin<sui::SUI>, validator_address: address, ctx: &mut tx_context::TxContext): staking_pool::StakedSui
Implementation
Function request_add_stake_mul_coin
Add stake to a validator's staking pool using multiple coins.
public(friend) fun request_add_stake_mul_coin(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, stakes: vector<coin::Coin<sui::SUI>>, stake_amount: option::Option<u64>, validator_address: address, ctx: &mut tx_context::TxContext): staking_pool::StakedSui
Implementation
Function request_withdraw_stake
Withdraw some portion of a stake from a validator's staking pool.
public(friend) fun request_withdraw_stake(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, staked_sui: staking_pool::StakedSui, ctx: &tx_context::TxContext): balance::Balance<sui::SUI>
Implementation
Function convert_to_fungible_staked_sui
public(friend) fun convert_to_fungible_staked_sui(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, staked_sui: staking_pool::StakedSui, ctx: &mut tx_context::TxContext): staking_pool::FungibleStakedSui
Implementation
Function redeem_fungible_staked_sui
public(friend) fun redeem_fungible_staked_sui(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, fungible_staked_sui: staking_pool::FungibleStakedSui, ctx: &tx_context::TxContext): balance::Balance<sui::SUI>
Implementation
Function report_validator
Report a validator as a bad or non-performant actor in the system. Succeeds if all the following are satisfied:
- both the reporter in cap and the input reportee_addr are active validators.
- reporter and reportee not the same address.
- the cap object is still valid. This function is idempotent.
public(friend) fun report_validator(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, cap: &validator_cap::UnverifiedValidatorOperationCap, reportee_addr: address)
Implementation
Function undo_report_validator
Undo a report_validator action. Aborts if
- the reportee is not a currently active validator or
- the sender has not previously reported the reportee_addr, or
- the cap is not valid
public(friend) fun undo_report_validator(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, cap: &validator_cap::UnverifiedValidatorOperationCap, reportee_addr: address)
Implementation
Function report_validator_impl
fun report_validator_impl(verified_cap: validator_cap::ValidatorOperationCap, reportee_addr: address, validator_report_records: &mut vec_map::VecMap<address, vec_set::VecSet<address>>)
Implementation
Function undo_report_validator_impl
fun undo_report_validator_impl(verified_cap: validator_cap::ValidatorOperationCap, reportee_addr: address, validator_report_records: &mut vec_map::VecMap<address, vec_set::VecSet<address>>)
Implementation
Function rotate_operation_cap
Create a new UnverifiedValidatorOperationCap, transfer it to the validator and registers it. The original object is thus revoked.
public(friend) fun rotate_operation_cap(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, ctx: &mut tx_context::TxContext)
Implementation
Function update_validator_name
Update a validator's name.
public(friend) fun update_validator_name(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, name: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_description
Update a validator's description
public(friend) fun update_validator_description(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, description: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_image_url
Update a validator's image url
public(friend) fun update_validator_image_url(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, image_url: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_project_url
Update a validator's project url
public(friend) fun update_validator_project_url(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, project_url: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_next_epoch_network_address
Update a validator's network address. The change will only take effects starting from the next epoch.
public(friend) fun update_validator_next_epoch_network_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, network_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_candidate_validator_network_address
Update candidate validator's network address.
public(friend) fun update_candidate_validator_network_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, network_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_next_epoch_p2p_address
Update a validator's p2p address. The change will only take effects starting from the next epoch.
public(friend) fun update_validator_next_epoch_p2p_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, p2p_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_candidate_validator_p2p_address
Update candidate validator's p2p address.
public(friend) fun update_candidate_validator_p2p_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, p2p_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_next_epoch_primary_address
Update a validator's narwhal primary address. The change will only take effects starting from the next epoch.
public(friend) fun update_validator_next_epoch_primary_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, primary_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_candidate_validator_primary_address
Update candidate validator's narwhal primary address.
public(friend) fun update_candidate_validator_primary_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, primary_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_next_epoch_worker_address
Update a validator's narwhal worker address. The change will only take effects starting from the next epoch.
public(friend) fun update_validator_next_epoch_worker_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, worker_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_candidate_validator_worker_address
Update candidate validator's narwhal worker address.
public(friend) fun update_candidate_validator_worker_address(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, worker_address: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_next_epoch_protocol_pubkey
Update a validator's public key of protocol key and proof of possession. The change will only take effects starting from the next epoch.
public(friend) fun update_validator_next_epoch_protocol_pubkey(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, protocol_pubkey: vector<u8>, proof_of_possession: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_candidate_validator_protocol_pubkey
Update candidate validator's public key of protocol key and proof of possession.
public(friend) fun update_candidate_validator_protocol_pubkey(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, protocol_pubkey: vector<u8>, proof_of_possession: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_next_epoch_worker_pubkey
Update a validator's public key of worker key. The change will only take effects starting from the next epoch.
public(friend) fun update_validator_next_epoch_worker_pubkey(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, worker_pubkey: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_candidate_validator_worker_pubkey
Update candidate validator's public key of worker key.
public(friend) fun update_candidate_validator_worker_pubkey(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, worker_pubkey: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_validator_next_epoch_network_pubkey
Update a validator's public key of network key. The change will only take effects starting from the next epoch.
public(friend) fun update_validator_next_epoch_network_pubkey(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, network_pubkey: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function update_candidate_validator_network_pubkey
Update candidate validator's public key of network key.
public(friend) fun update_candidate_validator_network_pubkey(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, network_pubkey: vector<u8>, ctx: &tx_context::TxContext)
Implementation
Function advance_epoch
This function should be called at the end of an epoch, and advances the system to the next epoch. It does the following things:
- Add storage charge to the storage fund.
- Burn the storage rebates from the storage fund. These are already refunded to transaction sender's gas coins.
- Distribute computation charge to validator stake.
- Update all validators.
public(friend) fun advance_epoch(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, new_epoch: u64, next_protocol_version: u64, storage_reward: balance::Balance<sui::SUI>, computation_reward: balance::Balance<sui::SUI>, storage_rebate_amount: u64, non_refundable_storage_fee_amount: u64, storage_fund_reinvest_rate: u64, reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, ctx: &mut tx_context::TxContext): balance::Balance<sui::SUI>
Implementation
Function epoch
Return the current epoch number. Useful for applications that need a coarse-grained concept of time, since epochs are ever-increasing and epoch changes are intended to happen every 24 hours.
public(friend) fun epoch(self: &sui_system_state_inner::SuiSystemStateInnerV2): u64
Implementation
Function protocol_version
public(friend) fun protocol_version(self: &sui_system_state_inner::SuiSystemStateInnerV2): u64
Implementation
Function system_state_version
public(friend) fun system_state_version(self: &sui_system_state_inner::SuiSystemStateInnerV2): u64
Implementation
Function genesis_system_state_version
This function always return the genesis system state version, which is used to create the system state in genesis. It should never change for a given network.
public(friend) fun genesis_system_state_version(): u64
Implementation
Function epoch_start_timestamp_ms
Returns unix timestamp of the start of current epoch
public(friend) fun epoch_start_timestamp_ms(self: &sui_system_state_inner::SuiSystemStateInnerV2): u64
Implementation
Function validator_stake_amount
Returns the total amount staked with validator_addr. Aborts if validator_addr is not an active validator.
public(friend) fun validator_stake_amount(self: &sui_system_state_inner::SuiSystemStateInnerV2, validator_addr: address): u64
Implementation
Function active_validator_voting_powers
Returns the voting power for validator_addr. Aborts if validator_addr is not an active validator.
public(friend) fun active_validator_voting_powers(self: &sui_system_state_inner::SuiSystemStateInnerV2): vec_map::VecMap<address, u64>
Implementation
Function validator_staking_pool_id
Returns the staking pool id of a given validator. Aborts if validator_addr is not an active validator.
public(friend) fun validator_staking_pool_id(self: &sui_system_state_inner::SuiSystemStateInnerV2, validator_addr: address): object::ID
Implementation
Function validator_staking_pool_mappings
Returns reference to the staking pool mappings that map pool ids to active validator addresses
public(friend) fun validator_staking_pool_mappings(self: &sui_system_state_inner::SuiSystemStateInnerV2): &table::Table<object::ID, address>
Implementation
Function get_reporters_of
Returns all the validators who are currently reporting addr
public(friend) fun get_reporters_of(self: &sui_system_state_inner::SuiSystemStateInnerV2, addr: address): vec_set::VecSet<address>
Implementation
Function get_storage_fund_total_balance
public(friend) fun get_storage_fund_total_balance(self: &sui_system_state_inner::SuiSystemStateInnerV2): u64
Implementation
Function get_storage_fund_object_rebates
public(friend) fun get_storage_fund_object_rebates(self: &sui_system_state_inner::SuiSystemStateInnerV2): u64
Implementation
Function validator_address_by_pool_id
public(friend) fun validator_address_by_pool_id(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, pool_id: &object::ID): address
Implementation
Function pool_exchange_rates
public(friend) fun pool_exchange_rates(self: &mut sui_system_state_inner::SuiSystemStateInnerV2, pool_id: &object::ID): &table::Table<u64, staking_pool::PoolTokenExchangeRate>
Implementation
Function active_validator_addresses
public(friend) fun active_validator_addresses(self: &sui_system_state_inner::SuiSystemStateInnerV2): vector<address>
Implementation
Function extract_coin_balance
Extract required Balance from vector of Coin
fun extract_coin_balance(coins: vector<coin::Coin<sui::SUI>>, amount: option::Option<u64>, ctx: &mut tx_context::TxContext): balance::Balance<sui::SUI>