Skip to content

Commit

Permalink
Merge branch 'main' into dynamic-vdf
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Jul 26, 2022
2 parents 34b3e6a + 1fa8761 commit 55c5156
Show file tree
Hide file tree
Showing 30 changed files with 512 additions and 26,003 deletions.
10 changes: 6 additions & 4 deletions config/management/genesis/src/ol_node_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,19 @@ fn make_validator_cfg(output_dir: PathBuf, namespace: &str, seed_addresses: Opti
vfn_net.listen_address = format!("/ip4/0.0.0.0/tcp/{}", DEFAULT_VFN_PORT).parse()?;

let mut pub_net = NetworkConfig::network_with_id(NetworkId::Public);
pub_net.listen_address = format!("/ip4/0.0.0.0/tcp/{}", DEFAULT_PUB_PORT).parse()?;

pub_net.listen_address = format!("/ip4/127.0.0.1/tcp/{}", DEFAULT_PUB_PORT).parse()?; // Don't fullnode sync requests

// This ID is how the Validator node identifies themselves on their private VFN network.
// same ID as being used in the validator network.
vfn_net.identity = network_id.clone();
pub_net.identity = network_id;
// Note that the the public network has no setting, so that it is randomly generated.
vfn_net.identity = network_id;

if let Some(s) = seed_addresses {
vfn_net.seed_addrs = s.clone();
pub_net.seed_addrs = s;
}

pub_net.discovery_method = DiscoveryMethod::Onchain;

c.full_node_networks = vec![vfn_net.to_owned(), pub_net.to_owned()];

Expand Down
12 changes: 11 additions & 1 deletion language/diem-framework/modules/0L/Jail.move
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ address 0x1 {
}
}

public fun self_unjail(sender: &signer) acquires Jail {
// only a validator can un-jail themselves.
let self = Signer::address_of(sender);

// check the node has been mining before unjailing.
assert(TowerState::node_above_thresh(self), 100104);
unjail(self);
}


public fun vouch_unjail(sender: &signer, addr: address) acquires Jail {
// only a validator can un-jail themselves.
let voucher = Signer::address_of(sender);
Expand All @@ -94,7 +104,7 @@ address 0x1 {
unjail(addr);
}

// private function. User should not be able to unjail self.

fun unjail(addr: address) acquires Jail {
if (exists<Jail>(addr)) {
borrow_global_mut<Jail>(addr).is_jailed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ module ValidatorScripts {
use 0x1::Signer;
use 0x1::ValidatorUniverse;
use 0x1::Vector;
use 0x1::Jail;

const NOT_ABOVE_THRESH_JOIN: u64 = 220101;
const NOT_ABOVE_THRESH_ADD : u64 = 220102;
const VAL_NOT_FOUND : u64 = 220103;
const VAL_NOT_JAILED : u64 = 220104;

// FOR E2E testing
public(script) fun ol_reconfig_bulk_update_setup(
Expand Down Expand Up @@ -37,7 +40,7 @@ module ValidatorScripts {
assert(DiemSystem::is_validator(alice) == true, 4);
}

public(script) fun join(validator: signer) {
public(script) fun self_unjail(validator: signer) {
let addr = Signer::address_of(&validator);
// if is above threshold continue, or raise error.
assert(
Expand All @@ -54,17 +57,36 @@ module ValidatorScripts {
};

// if is jailed, try to unjail
if (ValidatorUniverse::is_jailed(addr)) {
ValidatorUniverse::unjail_self(&validator);
if (Jail::is_jailed(addr)) {
Jail::self_unjail(&validator);
};
}

// public(script) fun leave(validator: signer) {
// let addr = Signer::address_of(&validator);
// if (ValidatorUniverse::is_in_universe(addr)) {
// ValidatorUniverse::remove_self(&validator);
// };
// }
public(script) fun voucher_unjail(voucher: signer, addr: address) {
// if is above threshold continue, or raise error.
assert(
TowerState::node_above_thresh(addr),
Errors::invalid_state(NOT_ABOVE_THRESH_JOIN)
);
// if is not in universe, add back
assert(
TowerState::node_above_thresh(addr),
Errors::invalid_state(VAL_NOT_FOUND)
);

assert(
TowerState::node_above_thresh(addr),
Errors::invalid_state(VAL_NOT_FOUND)
);

assert(
Jail::is_jailed(addr),
Errors::invalid_state(VAL_NOT_JAILED)
);
// if is jailed, try to unjail
Jail::vouch_unjail(&voucher, addr);
}


public(script) fun val_add_self(validator: signer) {
let validator = &validator;
Expand Down
30 changes: 30 additions & 0 deletions language/diem-framework/modules/doc/Jail.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Function `is_jailed`](#0x1_Jail_is_jailed)
- [Function `jail`](#0x1_Jail_jail)
- [Function `remove_consecutive_fail`](#0x1_Jail_remove_consecutive_fail)
- [Function `self_unjail`](#0x1_Jail_self_unjail)
- [Function `vouch_unjail`](#0x1_Jail_vouch_unjail)
- [Function `unjail`](#0x1_Jail_unjail)
- [Function `sort_by_jail`](#0x1_Jail_sort_by_jail)
Expand Down Expand Up @@ -192,6 +193,35 @@



</details>

<a name="0x1_Jail_self_unjail"></a>

## Function `self_unjail`



<pre><code><b>public</b> <b>fun</b> <a href="Jail.md#0x1_Jail_self_unjail">self_unjail</a>(sender: &signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Jail.md#0x1_Jail_self_unjail">self_unjail</a>(sender: &signer) <b>acquires</b> <a href="Jail.md#0x1_Jail">Jail</a> {
// only a validator can un-jail themselves.
<b>let</b> self = <a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(sender);

// check the node has been mining before unjailing.
<b>assert</b>(<a href="TowerState.md#0x1_TowerState_node_above_thresh">TowerState::node_above_thresh</a>(self), 100104);
<a href="Jail.md#0x1_Jail_unjail">unjail</a>(self);
}
</code></pre>



</details>

<a name="0x1_Jail_vouch_unjail"></a>
Expand Down
79 changes: 72 additions & 7 deletions language/diem-framework/modules/doc/ol_validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

- [Constants](#@Constants_0)
- [Function `ol_reconfig_bulk_update_setup`](#0x1_ValidatorScripts_ol_reconfig_bulk_update_setup)
- [Function `join`](#0x1_ValidatorScripts_join)
- [Function `self_unjail`](#0x1_ValidatorScripts_self_unjail)
- [Function `voucher_unjail`](#0x1_ValidatorScripts_voucher_unjail)
- [Function `val_add_self`](#0x1_ValidatorScripts_val_add_self)


<pre><code><b>use</b> <a href="DiemSystem.md#0x1_DiemSystem">0x1::DiemSystem</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="Jail.md#0x1_Jail">0x1::Jail</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer">0x1::Signer</a>;
<b>use</b> <a href="TowerState.md#0x1_TowerState">0x1::TowerState</a>;
<b>use</b> <a href="ValidatorUniverse.md#0x1_ValidatorUniverse">0x1::ValidatorUniverse</a>;
Expand Down Expand Up @@ -44,6 +46,24 @@



<a name="0x1_ValidatorScripts_VAL_NOT_FOUND"></a>



<pre><code><b>const</b> <a href="ol_validator.md#0x1_ValidatorScripts_VAL_NOT_FOUND">VAL_NOT_FOUND</a>: u64 = 220103;
</code></pre>



<a name="0x1_ValidatorScripts_VAL_NOT_JAILED"></a>



<pre><code><b>const</b> <a href="ol_validator.md#0x1_ValidatorScripts_VAL_NOT_JAILED">VAL_NOT_JAILED</a>: u64 = 220104;
</code></pre>



<a name="0x1_ValidatorScripts_ol_reconfig_bulk_update_setup"></a>

## Function `ol_reconfig_bulk_update_setup`
Expand Down Expand Up @@ -89,13 +109,13 @@

</details>

<a name="0x1_ValidatorScripts_join"></a>
<a name="0x1_ValidatorScripts_self_unjail"></a>

## Function `join`
## Function `self_unjail`



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ol_validator.md#0x1_ValidatorScripts_join">join</a>(validator: signer)
<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ol_validator.md#0x1_ValidatorScripts_self_unjail">self_unjail</a>(validator: signer)
</code></pre>


Expand All @@ -104,7 +124,7 @@
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ol_validator.md#0x1_ValidatorScripts_join">join</a>(validator: signer) {
<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ol_validator.md#0x1_ValidatorScripts_self_unjail">self_unjail</a>(validator: signer) {
<b>let</b> addr = <a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(&validator);
// <b>if</b> is above threshold <b>continue</b>, or raise error.
<b>assert</b>(
Expand All @@ -121,14 +141,59 @@
};

// <b>if</b> is jailed, try <b>to</b> unjail
<b>if</b> (<a href="ValidatorUniverse.md#0x1_ValidatorUniverse_is_jailed">ValidatorUniverse::is_jailed</a>(addr)) {
<a href="ValidatorUniverse.md#0x1_ValidatorUniverse_unjail_self">ValidatorUniverse::unjail_self</a>(&validator);
<b>if</b> (<a href="Jail.md#0x1_Jail_is_jailed">Jail::is_jailed</a>(addr)) {
<a href="Jail.md#0x1_Jail_self_unjail">Jail::self_unjail</a>(&validator);
};
}
</code></pre>



</details>

<a name="0x1_ValidatorScripts_voucher_unjail"></a>

## Function `voucher_unjail`



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ol_validator.md#0x1_ValidatorScripts_voucher_unjail">voucher_unjail</a>(voucher: signer, addr: address)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="ol_validator.md#0x1_ValidatorScripts_voucher_unjail">voucher_unjail</a>(voucher: signer, addr: address) {
// <b>if</b> is above threshold <b>continue</b>, or raise error.
<b>assert</b>(
<a href="TowerState.md#0x1_TowerState_node_above_thresh">TowerState::node_above_thresh</a>(addr),
<a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="ol_validator.md#0x1_ValidatorScripts_NOT_ABOVE_THRESH_JOIN">NOT_ABOVE_THRESH_JOIN</a>)
);
// <b>if</b> is not in universe, add back
<b>assert</b>(
<a href="TowerState.md#0x1_TowerState_node_above_thresh">TowerState::node_above_thresh</a>(addr),
<a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="ol_validator.md#0x1_ValidatorScripts_VAL_NOT_FOUND">VAL_NOT_FOUND</a>)
);

<b>assert</b>(
<a href="TowerState.md#0x1_TowerState_node_above_thresh">TowerState::node_above_thresh</a>(addr),
<a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="ol_validator.md#0x1_ValidatorScripts_VAL_NOT_FOUND">VAL_NOT_FOUND</a>)
);

<b>assert</b>(
<a href="Jail.md#0x1_Jail_is_jailed">Jail::is_jailed</a>(addr),
<a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="ol_validator.md#0x1_ValidatorScripts_VAL_NOT_JAILED">VAL_NOT_JAILED</a>)
);
// <b>if</b> is jailed, try <b>to</b> unjail
<a href="Jail.md#0x1_Jail_vouch_unjail">Jail::vouch_unjail</a>(&voucher, addr);
}
</code></pre>



</details>

<a name="0x1_ValidatorScripts_val_add_self"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Function `is_jailed`](#0x1_Jail_is_jailed)
- [Function `jail`](#0x1_Jail_jail)
- [Function `remove_consecutive_fail`](#0x1_Jail_remove_consecutive_fail)
- [Function `self_unjail`](#0x1_Jail_self_unjail)
- [Function `vouch_unjail`](#0x1_Jail_vouch_unjail)
- [Function `unjail`](#0x1_Jail_unjail)
- [Function `sort_by_jail`](#0x1_Jail_sort_by_jail)
Expand Down Expand Up @@ -192,6 +193,35 @@



</details>

<a name="0x1_Jail_self_unjail"></a>

## Function `self_unjail`



<pre><code><b>public</b> <b>fun</b> <a href="Jail.md#0x1_Jail_self_unjail">self_unjail</a>(sender: &signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Jail.md#0x1_Jail_self_unjail">self_unjail</a>(sender: &signer) <b>acquires</b> <a href="Jail.md#0x1_Jail">Jail</a> {
// only a validator can un-jail themselves.
<b>let</b> self = <a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(sender);

// check the node has been mining before unjailing.
<b>assert</b>(<a href="TowerState.md#0x1_TowerState_node_above_thresh">TowerState::node_above_thresh</a>(self), 100104);
<a href="Jail.md#0x1_Jail_unjail">unjail</a>(self);
}
</code></pre>



</details>

<a name="0x1_Jail_vouch_unjail"></a>
Expand Down
Loading

0 comments on commit 55c5156

Please sign in to comment.