Skip to content

Commit

Permalink
genesis: add chain id to sui system object
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Dec 9, 2022
1 parent 0935cc2 commit 409fd39
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 13 deletions.
3 changes: 3 additions & 0 deletions crates/sui-config/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use sui_adapter::adapter::MoveVM;
use sui_adapter::{adapter, execution_mode};
use sui_types::base_types::ObjectID;
use sui_types::base_types::TransactionDigest;
use sui_types::chain_id::ChainId;
use sui_types::crypto::{AuthorityPublicKey, ToFromBytes};
use sui_types::crypto::{AuthorityPublicKeyBytes, AuthoritySignature};
use sui_types::gas::SuiGasStatus;
Expand Down Expand Up @@ -539,6 +540,7 @@ pub fn generate_genesis_system_object(
let mut temporary_store =
TemporaryStore::new(&*store, InputObjects::new(vec![]), genesis_digest);

let chain_id = ChainId::TESTING;
let mut pubkeys = Vec::new();
let mut network_pubkeys = Vec::new();
let mut proof_of_possessions = Vec::new();
Expand Down Expand Up @@ -572,6 +574,7 @@ pub fn generate_genesis_system_object(
&ident_str!("create").to_owned(),
vec![],
vec![
CallArg::Pure(bcs::to_bytes(&chain_id).unwrap()),
CallArg::Pure(bcs::to_bytes(&pubkeys).unwrap()),
CallArg::Pure(bcs::to_bytes(&network_pubkeys).unwrap()),
CallArg::Pure(bcs::to_bytes(&proof_of_possessions).unwrap()),
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ expression: genesis.sui_system_object()
---
info:
id: "0x0000000000000000000000000000000000000005"
chain_id: 127
epoch: 0
validators:
validator_stake: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ expression: common_costs_estimate
---
{
"MergeCoin": {
"computation_cost": 5905,
"storage_cost": 8717,
"computation_cost": 5912,
"storage_cost": 8728,
"storage_rebate": 0
},
"Publish": {
"computation_cost": 6685,
"storage_cost": 9803,
"computation_cost": 6692,
"storage_cost": 9814,
"storage_rebate": 0
},
"SharedCounterAssertValue": {
Expand All @@ -29,8 +29,8 @@ expression: common_costs_estimate
"storage_rebate": 0
},
"SplitCoin": {
"computation_cost": 5883,
"storage_cost": 8685,
"computation_cost": 5890,
"storage_cost": 8695,
"storage_rebate": 0
},
"TransferPortionSuiCoin": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ expression: common_costs_actual
---
{
"MergeCoin": {
"computation_cost": 708,
"computation_cost": 709,
"storage_cost": 32,
"storage_rebate": 0
},
"Publish": {
"computation_cost": 957,
"computation_cost": 958,
"storage_cost": 119,
"storage_rebate": 0
},
Expand All @@ -29,7 +29,7 @@ expression: common_costs_actual
"storage_rebate": 15
},
"SplitCoin": {
"computation_cost": 818,
"computation_cost": 819,
"storage_cost": 80,
"storage_rebate": 0
},
Expand Down
4 changes: 3 additions & 1 deletion crates/sui-framework/docs/genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ It will create a singleton SuiSystemState object, which contains
all the information we need in the system.


<pre><code><b>fun</b> <a href="genesis.md#0x2_genesis_create">create</a>(validator_pubkeys: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_network_pubkeys: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_proof_of_possessions: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_sui_addresses: <a href="">vector</a>&lt;<b>address</b>&gt;, validator_names: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_net_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_stakes: <a href="">vector</a>&lt;u64&gt;, validator_gas_prices: <a href="">vector</a>&lt;u64&gt;, validator_commission_rates: <a href="">vector</a>&lt;u64&gt;, ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
<pre><code><b>fun</b> <a href="genesis.md#0x2_genesis_create">create</a>(chain_id: u8, validator_pubkeys: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_network_pubkeys: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_proof_of_possessions: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_sui_addresses: <a href="">vector</a>&lt;<b>address</b>&gt;, validator_names: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_net_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_stakes: <a href="">vector</a>&lt;u64&gt;, validator_gas_prices: <a href="">vector</a>&lt;u64&gt;, validator_commission_rates: <a href="">vector</a>&lt;u64&gt;, ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
</code></pre>


Expand All @@ -85,6 +85,7 @@ all the information we need in the system.


<pre><code><b>fun</b> <a href="genesis.md#0x2_genesis_create">create</a>(
chain_id: u8,
validator_pubkeys: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;,
validator_network_pubkeys: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;,
validator_proof_of_possessions: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;,
Expand Down Expand Up @@ -136,6 +137,7 @@ all the information we need in the system.
i = i + 1;
};
<a href="sui_system.md#0x2_sui_system_create">sui_system::create</a>(
chain_id,
validators,
sui_supply,
storage_fund,
Expand Down
11 changes: 10 additions & 1 deletion crates/sui-framework/docs/sui_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ The top-level object containing all information of the Sui system.
</dt>
<dd>

</dd>
<dt>
<code>chain_id: u8</code>
</dt>
<dd>
Id of the chain, value in the range [1, 127].
</dd>
<dt>
<code>epoch: u64</code>
Expand Down Expand Up @@ -230,7 +236,7 @@ Create a new SuiSystemState object and make it shared.
This function will be called only once in genesis.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="sui_system.md#0x2_sui_system_create">create</a>(validators: <a href="">vector</a>&lt;<a href="validator.md#0x2_validator_Validator">validator::Validator</a>&gt;, sui_supply: <a href="balance.md#0x2_balance_Supply">balance::Supply</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, storage_fund: <a href="balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, max_validator_candidate_count: u64, min_validator_stake: u64, storage_gas_price: u64)
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="sui_system.md#0x2_sui_system_create">create</a>(chain_id: u8, validators: <a href="">vector</a>&lt;<a href="validator.md#0x2_validator_Validator">validator::Validator</a>&gt;, sui_supply: <a href="balance.md#0x2_balance_Supply">balance::Supply</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, storage_fund: <a href="balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, max_validator_candidate_count: u64, min_validator_stake: u64, storage_gas_price: u64)
</code></pre>


Expand All @@ -240,18 +246,21 @@ This function will be called only once in genesis.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="sui_system.md#0x2_sui_system_create">create</a>(
chain_id: u8,
validators: <a href="">vector</a>&lt;Validator&gt;,
sui_supply: Supply&lt;SUI&gt;,
storage_fund: Balance&lt;SUI&gt;,
max_validator_candidate_count: u64,
min_validator_stake: u64,
storage_gas_price: u64,
) {
<b>assert</b>!(chain_id &gt;= 1 && chain_id &lt;= 127, 1);
<b>let</b> validators = <a href="validator_set.md#0x2_validator_set_new">validator_set::new</a>(validators);
<b>let</b> reference_gas_price = <a href="validator_set.md#0x2_validator_set_derive_reference_gas_price">validator_set::derive_reference_gas_price</a>(&validators);
<b>let</b> state = <a href="sui_system.md#0x2_sui_system_SuiSystemState">SuiSystemState</a> {
// Use a hardcoded ID.
id: <a href="object.md#0x2_object_sui_system_state">object::sui_system_state</a>(),
chain_id,
epoch: 0,
validators,
sui_supply,
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-framework/sources/governance/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module sui::genesis {
/// It will create a singleton SuiSystemState object, which contains
/// all the information we need in the system.
fun create(
chain_id: u8,
validator_pubkeys: vector<vector<u8>>,
validator_network_pubkeys: vector<vector<u8>>,
validator_proof_of_possessions: vector<vector<u8>>,
Expand Down Expand Up @@ -79,6 +80,7 @@ module sui::genesis {
i = i + 1;
};
sui_system::create(
chain_id,
validators,
sui_supply,
storage_fund,
Expand Down
5 changes: 5 additions & 0 deletions crates/sui-framework/sources/governance/sui_system.move
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ module sui::sui_system {
/// The top-level object containing all information of the Sui system.
struct SuiSystemState has key {
id: UID,
/// Id of the chain, value in the range [1, 127].
chain_id: u8,
/// The current epoch ID, starting from 0.
epoch: u64,
/// Contains all information about the validators.
Expand Down Expand Up @@ -75,18 +77,21 @@ module sui::sui_system {
/// Create a new SuiSystemState object and make it shared.
/// This function will be called only once in genesis.
public(friend) fun create(
chain_id: u8,
validators: vector<Validator>,
sui_supply: Supply<SUI>,
storage_fund: Balance<SUI>,
max_validator_candidate_count: u64,
min_validator_stake: u64,
storage_gas_price: u64,
) {
assert!(chain_id >= 1 && chain_id <= 127, 1);
let validators = validator_set::new(validators);
let reference_gas_price = validator_set::derive_reference_gas_price(&validators);
let state = SuiSystemState {
// Use a hardcoded ID.
id: object::sui_system_state(),
chain_id,
epoch: 0,
validators,
sui_supply,
Expand Down
1 change: 1 addition & 0 deletions crates/sui-framework/tests/governance_test_utils.move
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module sui::governance_test_utils {
validators: vector<Validator>, sui_supply_amount: u64, storage_fund_amount: u64
) {
sui_system::create(
127,
validators,
balance::create_supply_for_testing(sui_supply_amount), // sui_supply
balance::create_for_testing<SUI>(storage_fund_amount), // storage_fund
Expand Down
10 changes: 10 additions & 0 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,12 @@
}
}
},
"ChainId": {
"description": "Note: u7 in a u8 is uleb-compatible, and any usage of this should be aware that this field maybe updated to be uleb64 in the future",
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
"CommitteeInfoResponse": {
"type": "object",
"required": [
Expand Down Expand Up @@ -4727,6 +4733,7 @@
"description": "Rust version of the Move sui::sui_system::SuiSystemState type",
"type": "object",
"required": [
"chain_id",
"epoch",
"info",
"parameters",
Expand All @@ -4737,6 +4744,9 @@
"validators"
],
"properties": {
"chain_id": {
"$ref": "#/components/schemas/ChainId"
},
"epoch": {
"type": "integer",
"format": "uint64",
Expand Down
4 changes: 3 additions & 1 deletion crates/sui-types/src/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

/// Note: u7 in a u8 is uleb-compatible, and any usage of this should be aware
/// that this field maybe updated to be uleb64 in the future
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize)]
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, schemars::JsonSchema,
)]
pub struct ChainId(u8);

impl ChainId {
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-types/src/sui_system_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::base_types::{AuthorityName, SuiAddress};
use crate::chain_id::ChainId;
use crate::collection_types::{VecMap, VecSet};
use crate::committee::{Committee, CommitteeWithNetAddresses, StakeUnit};
use crate::crypto::AuthorityPublicKeyBytes;
Expand Down Expand Up @@ -139,6 +140,7 @@ pub struct ValidatorSet {
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)]
pub struct SuiSystemState {
pub info: UID,
pub chain_id: ChainId,
pub epoch: u64,
pub validators: ValidatorSet,
pub treasury_cap: Supply,
Expand Down
2 changes: 2 additions & 0 deletions crates/test-utils/src/sui_system_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use bcs::to_bytes;
use sui_types::balance::{Balance, Supply};
use sui_types::base_types::SuiAddress;
use sui_types::chain_id::ChainId;
use sui_types::collection_types::VecMap;
use sui_types::committee::EpochId;
use sui_types::crypto::{
Expand Down Expand Up @@ -79,6 +80,7 @@ pub fn test_sui_system_state(epoch: EpochId, validators: Vec<Validator>) -> SuiS
};
SuiSystemState {
info: UID::new(SUI_SYSTEM_STATE_OBJECT_ID),
chain_id: ChainId::TESTING,
epoch,
validators: validator_set,
treasury_cap: Supply { value: 0 },
Expand Down

0 comments on commit 409fd39

Please sign in to comment.