Skip to main content

Module sui_system::voting_power

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::protocol_config;
use sui::sui;
use sui::table;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::url;
use sui::vec_map;
use sui::vec_set;
use sui_system::staking_pool;
use sui_system::validator;
use sui_system::validator_cap;

Struct VotingPowerInfo

Deprecated. Use VotingPowerInfoV2 instead.

public struct VotingPowerInfo has drop
Click to open
Fields
validator_index: u64
voting_power: u64

Struct VotingPowerInfoV2

public struct VotingPowerInfoV2 has drop
Click to open
Fields
validator_index: u64
voting_power: u64
stake: u64

Constants

Set total_voting_power as 10_000 by convention. Individual voting powers can be interpreted as easily understandable basis points (e.g., voting_power: 100 = 1%, voting_power: 1 = 0.01%) rather than opaque quantities whose meaning changes from epoch to epoch as the total amount staked shifts.
Fixing the total voting power allows clients to hardcode the quorum threshold and total_voting power rather than recomputing these.

const TOTAL_VOTING_POWER: u64 = 10000;

Quorum threshold for our fixed voting power--any message signed by this much voting power can be trusted up to BFT assumptions

const QUORUM_THRESHOLD: u64 = 6667;
const MAX_VOTING_POWER: u64 = 1000;
const ETotalPowerMismatch: u64 = 1;
const ERelativePowerMismatch: u64 = 2;
const EVotingPowerOverThreshold: u64 = 3;
const EInvalidVotingPower: u64 = 4;

Function set_voting_power

Set the voting power of all validators.
Each validator's voting power is initialized using their stake. We then attempt to cap their voting power at MAX_VOTING_POWER. If MAX_VOTING_POWER is not a feasible cap, we pick the lowest possible cap.

public(package) fun set_voting_power(validators: &mut vector<sui_system::validator::Validator>, total_stake: u64)

Function init_voting_power_info

Create the initial voting power of each validator, set using their stake, but capped using threshold.
We also perform insertion sort while creating the voting power list, by maintaining the list in descending order using voting power.
Anything beyond the threshold is added to the remaining_power, which is also returned.

fun init_voting_power_info(validators: &vector<sui_system::validator::Validator>, threshold: u64, total_stake: u64): (vector<sui_system::voting_power::VotingPowerInfoV2>, u64)

Function derive_raw_voting_power

public(package) fun derive_raw_voting_power(stake: u64, total_stake: u64): u64

Function insert

Insert new_info to info_list as part of insertion sort, such that info_list is always sorted using stake, in descending order.

fun insert(info_list: &mut vector<sui_system::voting_power::VotingPowerInfoV2>, new_info: sui_system::voting_power::VotingPowerInfoV2)

Function adjust_voting_power

Distribute remaining_power to validators that are not capped at threshold.

fun adjust_voting_power(info_list: &mut vector<sui_system::voting_power::VotingPowerInfoV2>, threshold: u64, remaining_power: u64)

Function update_voting_power

Update validators with the decided voting power.

fun update_voting_power(validators: &mut vector<sui_system::validator::Validator>, info_list: vector<sui_system::voting_power::VotingPowerInfoV2>)

Function check_invariants

Check a few invariants that must hold after setting the voting power.

fun check_invariants(v: &vector<sui_system::validator::Validator>)

Function total_voting_power

Return the (constant) total voting power

public fun total_voting_power(): u64

Function quorum_threshold

Return the (constant) quorum threshold

public fun quorum_threshold(): u64