Skip to content

Commit

Permalink
add p2p address on chain
Browse files Browse the repository at this point in the history
  • Loading branch information
longbowlu committed Feb 27, 2023
1 parent c77678c commit e3a0d15
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 3 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 @@ -949,6 +949,7 @@ pub fn generate_genesis_system_object(
let mut proof_of_possessions = Vec::new();
let mut sui_addresses = Vec::new();
let mut network_addresses = Vec::new();
let mut p2p_addresses = Vec::new();
let mut consensus_addresses = Vec::new();
let mut worker_addresses = Vec::new();
let mut names = Vec::new();
Expand All @@ -970,6 +971,7 @@ pub fn generate_genesis_system_object(
proof_of_possessions.push(proof_of_possession.as_ref().to_vec());
sui_addresses.push(validator.sui_address());
network_addresses.push(validator.network_address());
p2p_addresses.push(validator.p2p_address());
consensus_addresses.push(validator.narwhal_primary_address());
worker_addresses.push(validator.narwhal_worker_address());
names.push(validator.name().to_owned().into_bytes());
Expand Down Expand Up @@ -998,6 +1000,7 @@ pub fn generate_genesis_system_object(
CallArg::Pure(bcs::to_bytes(&image_url).unwrap()),
CallArg::Pure(bcs::to_bytes(&project_url).unwrap()),
CallArg::Pure(bcs::to_bytes(&network_addresses).unwrap()),
CallArg::Pure(bcs::to_bytes(&p2p_addresses).unwrap()),
CallArg::Pure(bcs::to_bytes(&consensus_addresses).unwrap()),
CallArg::Pure(bcs::to_bytes(&worker_addresses).unwrap()),
CallArg::Pure(bcs::to_bytes(&stakes).unwrap()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ validators:
image_url: ""
project_url: ""
net_address: []
p2p_address: []
consensus_address: []
worker_address: []
next_epoch_stake: 1
Expand Down Expand Up @@ -481,6 +482,7 @@ validators:
image_url: ""
project_url: ""
net_address: []
p2p_address: []
consensus_address: []
worker_address: []
next_epoch_stake: 1
Expand Down
6 changes: 5 additions & 1 deletion crates/sui-framework/docs/genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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_worker_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_descriptions: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_image_urls: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_project_urls: <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_consensus_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_worker_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;, protocol_version: u64, epoch_start_timestamp_ms: u64, 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>(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_worker_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_descriptions: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_image_urls: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_project_urls: <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_p2p_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_consensus_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, validator_worker_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;, protocol_version: u64, epoch_start_timestamp_ms: u64, ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
</code></pre>


Expand All @@ -96,6 +96,7 @@ all the information we need in the system.
validator_image_urls: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;,
validator_project_urls: <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_p2p_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;,
validator_consensus_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;,
validator_worker_addresses: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;,
validator_stakes: <a href="">vector</a>&lt;u64&gt;,
Expand All @@ -117,6 +118,7 @@ all the information we need in the system.
&& <a href="_length">vector::length</a>(&validator_image_urls) == count
&& <a href="_length">vector::length</a>(&validator_project_urls) == count
&& <a href="_length">vector::length</a>(&validator_net_addresses) == count
&& <a href="_length">vector::length</a>(&validator_p2p_addresses) == count
&& <a href="_length">vector::length</a>(&validator_consensus_addresses) == count
&& <a href="_length">vector::length</a>(&validator_worker_addresses) == count
&& <a href="_length">vector::length</a>(&validator_gas_prices) == count
Expand All @@ -135,6 +137,7 @@ all the information we need in the system.
<b>let</b> image_url = *<a href="_borrow">vector::borrow</a>(&validator_image_urls, i);
<b>let</b> project_url = *<a href="_borrow">vector::borrow</a>(&validator_project_urls, i);
<b>let</b> net_address = *<a href="_borrow">vector::borrow</a>(&validator_net_addresses, i);
<b>let</b> p2p_address = *<a href="_borrow">vector::borrow</a>(&validator_p2p_addresses, i);
<b>let</b> consensus_address = *<a href="_borrow">vector::borrow</a>(&validator_consensus_addresses, i);
<b>let</b> worker_address = *<a href="_borrow">vector::borrow</a>(&validator_worker_addresses, i);
<b>let</b> <a href="stake.md#0x2_stake">stake</a> = *<a href="_borrow">vector::borrow</a>(&validator_stakes, i);
Expand All @@ -151,6 +154,7 @@ all the information we need in the system.
image_url,
project_url,
net_address,
p2p_address,
consensus_address,
worker_address,
<a href="balance.md#0x2_balance_increase_supply">balance::increase_supply</a>(&<b>mut</b> sui_supply, <a href="stake.md#0x2_stake">stake</a>),
Expand Down
4 changes: 3 additions & 1 deletion crates/sui-framework/docs/sui_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ The <code><a href="validator.md#0x2_validator">validator</a></code> object needs
The amount of stake in the <code><a href="validator.md#0x2_validator">validator</a></code> object must meet the requirements.


<pre><code><b>public</b> entry <b>fun</b> <a href="sui_system.md#0x2_sui_system_request_add_validator">request_add_validator</a>(self: &<b>mut</b> <a href="sui_system.md#0x2_sui_system_SuiSystemState">sui_system::SuiSystemState</a>, pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, network_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, worker_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, proof_of_possession: <a href="">vector</a>&lt;u8&gt;, name: <a href="">vector</a>&lt;u8&gt;, description: <a href="">vector</a>&lt;u8&gt;, image_url: <a href="">vector</a>&lt;u8&gt;, project_url: <a href="">vector</a>&lt;u8&gt;, net_address: <a href="">vector</a>&lt;u8&gt;, consensus_address: <a href="">vector</a>&lt;u8&gt;, worker_address: <a href="">vector</a>&lt;u8&gt;, <a href="stake.md#0x2_stake">stake</a>: <a href="coin.md#0x2_coin_Coin">coin::Coin</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, gas_price: u64, commission_rate: u64, ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
<pre><code><b>public</b> entry <b>fun</b> <a href="sui_system.md#0x2_sui_system_request_add_validator">request_add_validator</a>(self: &<b>mut</b> <a href="sui_system.md#0x2_sui_system_SuiSystemState">sui_system::SuiSystemState</a>, pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, network_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, worker_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, proof_of_possession: <a href="">vector</a>&lt;u8&gt;, name: <a href="">vector</a>&lt;u8&gt;, description: <a href="">vector</a>&lt;u8&gt;, image_url: <a href="">vector</a>&lt;u8&gt;, project_url: <a href="">vector</a>&lt;u8&gt;, net_address: <a href="">vector</a>&lt;u8&gt;, p2p_address: <a href="">vector</a>&lt;u8&gt;, consensus_address: <a href="">vector</a>&lt;u8&gt;, worker_address: <a href="">vector</a>&lt;u8&gt;, <a href="stake.md#0x2_stake">stake</a>: <a href="coin.md#0x2_coin_Coin">coin::Coin</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, gas_price: u64, commission_rate: u64, ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
</code></pre>


Expand All @@ -445,6 +445,7 @@ The amount of stake in the <code><a href="validator.md#0x2_validator">validator<
image_url: <a href="">vector</a>&lt;u8&gt;,
project_url: <a href="">vector</a>&lt;u8&gt;,
net_address: <a href="">vector</a>&lt;u8&gt;,
p2p_address: <a href="">vector</a>&lt;u8&gt;,
consensus_address: <a href="">vector</a>&lt;u8&gt;,
worker_address: <a href="">vector</a>&lt;u8&gt;,
<a href="stake.md#0x2_stake">stake</a>: Coin&lt;SUI&gt;,
Expand Down Expand Up @@ -472,6 +473,7 @@ The amount of stake in the <code><a href="validator.md#0x2_validator">validator<
image_url,
project_url,
net_address,
p2p_address,
consensus_address,
worker_address,
<a href="coin.md#0x2_coin_into_balance">coin::into_balance</a>(<a href="stake.md#0x2_stake">stake</a>),
Expand Down
12 changes: 11 additions & 1 deletion crates/sui-framework/docs/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
The network address of the validator (could also contain extra info such as port, DNS and etc.).
</dd>
<dt>
<code>p2p_address: <a href="">vector</a>&lt;u8&gt;</code>
</dt>
<dd>
The address of the validator used for p2p activities such as state sync (could also contain extra info such as port, DNS and etc.).
</dd>
<dt>
<code>consensus_address: <a href="">vector</a>&lt;u8&gt;</code>
</dt>
<dd>
Expand Down Expand Up @@ -305,7 +311,7 @@



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="validator.md#0x2_validator_new">new</a>(sui_address: <b>address</b>, pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, network_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, worker_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, proof_of_possession: <a href="">vector</a>&lt;u8&gt;, name: <a href="">vector</a>&lt;u8&gt;, description: <a href="">vector</a>&lt;u8&gt;, image_url: <a href="">vector</a>&lt;u8&gt;, project_url: <a href="">vector</a>&lt;u8&gt;, net_address: <a href="">vector</a>&lt;u8&gt;, consensus_address: <a href="">vector</a>&lt;u8&gt;, worker_address: <a href="">vector</a>&lt;u8&gt;, <a href="stake.md#0x2_stake">stake</a>: <a href="balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, coin_locked_until_epoch: <a href="_Option">option::Option</a>&lt;<a href="epoch_time_lock.md#0x2_epoch_time_lock_EpochTimeLock">epoch_time_lock::EpochTimeLock</a>&gt;, gas_price: u64, commission_rate: u64, ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="validator.md#0x2_validator_Validator">validator::Validator</a>
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="validator.md#0x2_validator_new">new</a>(sui_address: <b>address</b>, pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, network_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, worker_pubkey_bytes: <a href="">vector</a>&lt;u8&gt;, proof_of_possession: <a href="">vector</a>&lt;u8&gt;, name: <a href="">vector</a>&lt;u8&gt;, description: <a href="">vector</a>&lt;u8&gt;, image_url: <a href="">vector</a>&lt;u8&gt;, project_url: <a href="">vector</a>&lt;u8&gt;, net_address: <a href="">vector</a>&lt;u8&gt;, p2p_address: <a href="">vector</a>&lt;u8&gt;, consensus_address: <a href="">vector</a>&lt;u8&gt;, worker_address: <a href="">vector</a>&lt;u8&gt;, <a href="stake.md#0x2_stake">stake</a>: <a href="balance.md#0x2_balance_Balance">balance::Balance</a>&lt;<a href="sui.md#0x2_sui_SUI">sui::SUI</a>&gt;, coin_locked_until_epoch: <a href="_Option">option::Option</a>&lt;<a href="epoch_time_lock.md#0x2_epoch_time_lock_EpochTimeLock">epoch_time_lock::EpochTimeLock</a>&gt;, gas_price: u64, commission_rate: u64, ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="validator.md#0x2_validator_Validator">validator::Validator</a>
</code></pre>


Expand All @@ -325,6 +331,7 @@
image_url: <a href="">vector</a>&lt;u8&gt;,
project_url: <a href="">vector</a>&lt;u8&gt;,
net_address: <a href="">vector</a>&lt;u8&gt;,
p2p_address: <a href="">vector</a>&lt;u8&gt;,
consensus_address: <a href="">vector</a>&lt;u8&gt;,
worker_address: <a href="">vector</a>&lt;u8&gt;,
<a href="stake.md#0x2_stake">stake</a>: Balance&lt;SUI&gt;,
Expand All @@ -336,6 +343,7 @@
<b>assert</b>!(
// TODO: These constants are arbitrary, will adjust once we know more.
<a href="_length">vector::length</a>(&net_address) &lt;= 128
&& <a href="_length">vector::length</a>(&p2p_address) &lt;= 128
&& <a href="_length">vector::length</a>(&name) &lt;= 128
&& <a href="_length">vector::length</a>(&description) &lt;= 150
&& <a href="_length">vector::length</a>(&pubkey_bytes) &lt;= 128,
Expand All @@ -360,6 +368,7 @@
image_url: <a href="url.md#0x2_url_new_unsafe_from_bytes">url::new_unsafe_from_bytes</a>(image_url),
project_url: <a href="url.md#0x2_url_new_unsafe_from_bytes">url::new_unsafe_from_bytes</a>(project_url),
net_address,
p2p_address,
consensus_address,
worker_address,
next_epoch_stake: stake_amount,
Expand Down Expand Up @@ -1117,6 +1126,7 @@ Set the voting power of this validator, called only from validator_set.
self.metadata.sui_address == other.metadata.sui_address
|| self.metadata.name == other.metadata.name
|| self.metadata.net_address == other.metadata.net_address
|| self.metadata.p2p_address == other.metadata.p2p_address
|| self.metadata.pubkey_bytes == other.metadata.pubkey_bytes
}
</code></pre>
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-framework/sources/governance/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module sui::genesis {
validator_image_urls: vector<vector<u8>>,
validator_project_urls: vector<vector<u8>>,
validator_net_addresses: vector<vector<u8>>,
validator_p2p_addresses: vector<vector<u8>>,
validator_consensus_addresses: vector<vector<u8>>,
validator_worker_addresses: vector<vector<u8>>,
validator_stakes: vector<u64>,
Expand All @@ -60,6 +61,7 @@ module sui::genesis {
&& vector::length(&validator_image_urls) == count
&& vector::length(&validator_project_urls) == count
&& vector::length(&validator_net_addresses) == count
&& vector::length(&validator_p2p_addresses) == count
&& vector::length(&validator_consensus_addresses) == count
&& vector::length(&validator_worker_addresses) == count
&& vector::length(&validator_gas_prices) == count
Expand All @@ -78,6 +80,7 @@ module sui::genesis {
let image_url = *vector::borrow(&validator_image_urls, i);
let project_url = *vector::borrow(&validator_project_urls, i);
let net_address = *vector::borrow(&validator_net_addresses, i);
let p2p_address = *vector::borrow(&validator_p2p_addresses, i);
let consensus_address = *vector::borrow(&validator_consensus_addresses, i);
let worker_address = *vector::borrow(&validator_worker_addresses, i);
let stake = *vector::borrow(&validator_stakes, i);
Expand All @@ -94,6 +97,7 @@ module sui::genesis {
image_url,
project_url,
net_address,
p2p_address,
consensus_address,
worker_address,
balance::increase_supply(&mut sui_supply, stake),
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-framework/sources/governance/sui_system.move
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ module sui::sui_system {
image_url: vector<u8>,
project_url: vector<u8>,
net_address: vector<u8>,
p2p_address: vector<u8>,
consensus_address: vector<u8>,
worker_address: vector<u8>,
stake: Coin<SUI>,
Expand Down Expand Up @@ -189,6 +190,7 @@ module sui::sui_system {
image_url,
project_url,
net_address,
p2p_address,
consensus_address,
worker_address,
coin::into_balance(stake),
Expand Down
Loading

0 comments on commit e3a0d15

Please sign in to comment.