Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Fixes #522 val join issue (#523)
Browse files Browse the repository at this point in the history
* patch pilot text. Was showing incorrect print on account creation.

* formatting on health print

* ol start doesn't always attempt db restore seems to have false negative

* change move error codes

* entrypoint

* validator universe add_self tx script. build stdlib. add mining make file test.

* exists_jailbit is incorrectly checking for testnet

* closes #522

* if user is onboarding can add self to validator universe.

* add script for adding self to set

* release.yaml to use tar gzip instead of zip

* remove zip dependency from install.sh

* patch onboarding move tests
  • Loading branch information
0o-de-lally authored May 31, 2021
1 parent 9734eed commit 9b01b5e
Show file tree
Hide file tree
Showing 53 changed files with 221 additions and 86 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:
tag: ${{ github.ref }}
overwrite: true
- name: Web
run: cd ol/cli/web-monitor/public/; zip -r web-monitor.zip *
run: cd ol/cli/web-monitor/public/; tar -czvf web-monitor.tar.gz *
- name: Upload Web Files
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ol/cli/web-monitor/public/web-monitor.zip
file: ol/cli/web-monitor/public/web-monitor.tar.gz
file_glob: true
tag: ${{ github.ref }}
overwrite: true
Expand Down
40 changes: 35 additions & 5 deletions client/transaction-builder/src/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,8 @@ pub enum ScriptCall {
currency: TypeTag,
allow_minting: bool,
},

ValAddSelf {},
}

impl ScriptCall {
Expand Down Expand Up @@ -1833,6 +1835,7 @@ impl ScriptCall {
currency,
allow_minting,
} => encode_update_minting_ability_script(currency, allow_minting),
ValAddSelf {} => encode_val_add_self_script(),
}
}

Expand Down Expand Up @@ -3709,6 +3712,10 @@ pub fn encode_update_minting_ability_script(currency: TypeTag, allow_minting: bo
)
}

pub fn encode_val_add_self_script() -> Script {
Script::new(VAL_ADD_SELF_CODE.to_vec(), vec![], vec![])
}

fn decode_add_currency_to_account_script(script: &Script) -> Option<ScriptCall> {
Some(ScriptCall::AddCurrencyToAccount {
currency: script.ty_args().get(0)?.clone(),
Expand Down Expand Up @@ -4061,6 +4068,10 @@ fn decode_update_minting_ability_script(script: &Script) -> Option<ScriptCall> {
})
}

fn decode_val_add_self_script(_script: &Script) -> Option<ScriptCall> {
Some(ScriptCall::ValAddSelf {})
}

type DecoderMap = std::collections::HashMap<
Vec<u8>,
Box<dyn Fn(&Script) -> Option<ScriptCall> + std::marker::Sync + std::marker::Send>,
Expand Down Expand Up @@ -4241,6 +4252,10 @@ static SCRIPT_DECODER_MAP: once_cell::sync::Lazy<DecoderMap> = once_cell::sync::
UPDATE_MINTING_ABILITY_CODE.to_vec(),
Box::new(decode_update_minting_ability_script),
);
map.insert(
VAL_ADD_SELF_CODE.to_vec(),
Box::new(decode_val_add_self_script),
);
map
});

Expand Down Expand Up @@ -4509,11 +4524,11 @@ const JOIN_CODE: &[u8] = &[
108, 102, 16, 101, 120, 105, 115, 116, 115, 95, 106, 97, 105, 108, 101, 100, 98, 105, 116, 10,
105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 14, 105, 115, 95, 105, 110, 95, 117, 110, 105,
118, 101, 114, 115, 101, 9, 105, 115, 95, 106, 97, 105, 108, 101, 100, 11, 117, 110, 106, 97,
105, 108, 95, 115, 101, 108, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 8, 1, 0,
0, 0, 0, 0, 0, 0, 0, 3, 6, 40, 10, 0, 17, 2, 12, 1, 10, 0, 10, 1, 17, 1, 7, 0, 17, 0, 12, 3,
12, 2, 11, 2, 3, 16, 11, 0, 1, 11, 3, 39, 10, 1, 17, 6, 32, 3, 21, 5, 23, 10, 0, 17, 3, 10, 1,
17, 4, 32, 3, 28, 5, 30, 10, 0, 17, 5, 10, 1, 17, 7, 3, 34, 5, 37, 11, 0, 17, 8, 5, 39, 11, 0,
1, 2,
105, 108, 95, 115, 101, 108, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 8, 197,
91, 3, 0, 0, 0, 0, 0, 0, 3, 6, 40, 10, 0, 17, 2, 12, 1, 10, 0, 10, 1, 17, 1, 7, 0, 17, 0, 12,
3, 12, 2, 11, 2, 3, 16, 11, 0, 1, 11, 3, 39, 10, 1, 17, 6, 32, 3, 21, 5, 23, 10, 0, 17, 3, 10,
1, 17, 4, 32, 3, 28, 5, 30, 10, 0, 17, 5, 10, 1, 17, 7, 3, 34, 5, 37, 11, 0, 17, 8, 5, 39, 11,
0, 1, 2,
];

const LEAVE_CODE: &[u8] = &[
Expand Down Expand Up @@ -4800,3 +4815,18 @@ const UPDATE_MINTING_ABILITY_CODE: &[u8] = &[
97, 116, 101, 95, 109, 105, 110, 116, 105, 110, 103, 95, 97, 98, 105, 108, 105, 116, 121, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 4, 11, 0, 10, 1, 56, 0, 2,
];

const VAL_ADD_SELF_CODE: &[u8] = &[
161, 28, 235, 11, 1, 0, 0, 0, 6, 1, 0, 8, 3, 8, 25, 5, 33, 18, 7, 51, 110, 8, 161, 1, 16, 6,
177, 1, 10, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 1, 5, 1, 2, 0, 2, 6, 3, 4, 0, 3, 7, 3, 5, 0,
3, 8, 4, 2, 0, 1, 3, 2, 6, 12, 5, 1, 1, 1, 6, 12, 1, 5, 0, 3, 5, 1, 3, 6, 69, 114, 114, 111,
114, 115, 10, 77, 105, 110, 101, 114, 83, 116, 97, 116, 101, 6, 83, 105, 103, 110, 101, 114,
17, 86, 97, 108, 105, 100, 97, 116, 111, 114, 85, 110, 105, 118, 101, 114, 115, 101, 13, 105,
110, 118, 97, 108, 105, 100, 95, 115, 116, 97, 116, 101, 17, 110, 111, 100, 101, 95, 97, 98,
111, 118, 101, 95, 116, 104, 114, 101, 115, 104, 10, 97, 100, 100, 114, 101, 115, 115, 95, 111,
102, 8, 97, 100, 100, 95, 115, 101, 108, 102, 14, 105, 115, 95, 105, 110, 95, 117, 110, 105,
118, 101, 114, 115, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 8, 198, 91, 3, 0,
0, 0, 0, 0, 0, 3, 6, 27, 10, 0, 17, 2, 12, 1, 10, 0, 10, 1, 17, 1, 7, 0, 17, 0, 12, 3, 12, 2,
11, 2, 3, 16, 11, 0, 1, 11, 3, 39, 10, 1, 17, 4, 32, 3, 21, 5, 24, 11, 0, 17, 3, 5, 26, 11, 0,
1, 2,
];
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ fun main(vm: &signer) {
let expected = 1000000 + 576000;
assert(bal == expected, 7357401003);

assert(!ValidatorUniverse::exists_jailedbit(eve_addr), 7357401004);
assert(!ValidatorUniverse::is_in_universe(eve_addr), 7357401005);
// validator should have jailedbit
assert(ValidatorUniverse::exists_jailedbit(eve_addr), 7357401004);
// validator should be in universe if just joined.
assert(ValidatorUniverse::is_in_universe(eve_addr), 7357401005);
// should not be jailed
assert(!ValidatorUniverse::is_jailed(eve_addr), 7357401006);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ script {
use 0x1::Vector;
fun main(vm: &signer) {
// Tests on initial size of validators
// New validator is not in this set.
assert(LibraSystem::validator_set_size() == 4, 7357000180101);
assert(LibraSystem::is_validator({{alice}}) == true, 7357000180102);
assert(!LibraSystem::is_validator(0x3DC18D1CF61FAAC6AC70E3A63F062E4B), 7357000180103);
let len = Vector::length<address>(&ValidatorUniverse::get_eligible_validators(vm));
assert(len == 4 , 7357000180104);
// Is in validator universe
assert(len == 5 , 7357000180104);
}
}
// check: EXECUTED
Expand All @@ -119,10 +121,10 @@ script {

fun main(vm: &signer) {
// Tests on initial size of validators
assert(LibraSystem::validator_set_size() == 4, 7357000180101);
assert(LibraSystem::is_validator({{alice}}) == true, 7357000180102);
assert(LibraSystem::is_validator({{bob}}) == true, 7357000180103);
assert(LibraSystem::is_validator(0x3DC18D1CF61FAAC6AC70E3A63F062E4B) == false, 7357000180103);
assert(LibraSystem::validator_set_size() == 4, 7357000180201);
assert(LibraSystem::is_validator({{alice}}) == true, 7357000180202);
assert(LibraSystem::is_validator({{bob}}) == true, 7357000180203);
assert(LibraSystem::is_validator(0x3DC18D1CF61FAAC6AC70E3A63F062E4B) == false, 7357000180204);

// Mock everyone being a CASE 1
let voters = Vector::empty<address>();
Expand All @@ -137,14 +139,12 @@ script {
MinerState::test_helper_mock_mining_vm(vm, {{dave}}, 20);
MinerState::test_helper_mock_mining_vm(vm, 0x3DC18D1CF61FAAC6AC70E3A63F062E4B, 20);

// check the new account is in the list of eligible
let len = Vector::length<address>(&ValidatorUniverse::get_eligible_validators(vm));
assert(len == 4 , 7357000180104);

// Adding eve to validator universe - would be done by self
ValidatorUniverse::test_helper_add_self_onboard(vm, 0x3DC18D1CF61FAAC6AC70E3A63F062E4B);
assert(len == 5 , 7357000180205);

let len = Vector::length<address>(&ValidatorUniverse::get_eligible_validators(vm));
assert(len == 5 , 7357000180104);
assert(len == 5 , 7357000180206);

let i = 1;
while (i < 16) {
Expand All @@ -169,11 +169,11 @@ script {
use 0x1::Vector;
fun main(vm: &signer) {
// Tests on initial size of validators
assert(LibraSystem::validator_set_size() == 5, 7357000200101);
assert(LibraSystem::is_validator({{alice}}) == true, 7357000200102);
assert(LibraSystem::is_validator(0x3DC18D1CF61FAAC6AC70E3A63F062E4B), 7357000200103);
assert(LibraSystem::validator_set_size() == 5, 7357000200301);
assert(LibraSystem::is_validator({{alice}}) == true, 7357000200302);
assert(LibraSystem::is_validator(0x3DC18D1CF61FAAC6AC70E3A63F062E4B), 7357000200303);
let len = Vector::length<address>(&ValidatorUniverse::get_eligible_validators(vm));
assert(LibraSystem::validator_set_size() == len, 7357000200104);
assert(LibraSystem::validator_set_size() == len, 7357000200304);
}
}
// check: EXECUTED
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ use 0x1::TestFixtures;
use 0x1::ValidatorConfig;
use 0x1::Roles;
use 0x1::Signer;
use 0x1::Debug::print;
use 0x1::ValidatorUniverse;

// Test Prefix: 1301
fun main(sender: &signer) {
// // Scenario: Bob, an existing validator, is sending a transaction for Eve, with a challenge and proof not yet submitted to the chain.
// Scenario: Bob, an existing validator, is sending a transaction for Eve, with a challenge and proof not yet submitted to the chain.
let challenge = TestFixtures::eve_0_easy_chal();
let solution = TestFixtures::eve_0_easy_sol();
// // Parse key and check
// Parse key and check
let (eve_addr, _auth_key) = VDF::extract_address_from_challenge(&challenge);
assert(eve_addr == 0x3DC18D1CF61FAAC6AC70E3A63F062E4B, 401);

Expand Down Expand Up @@ -56,16 +55,13 @@ fun main(sender: &signer) {
//Check the validator has 0 proof of weight.
assert(NodeWeight::proof_of_weight(eve_addr) == 0, 7357130101071000);

// Check the account exists and the balance is 0
// TODO: Needs some balance
print(&LibraAccount::balance<GAS>(eve_addr));
// Check the account exists and the balance has the onboarding amount.
assert(LibraAccount::balance<GAS>(eve_addr) == 1000000, 7357130101081000);

// Should not automatically be in validator universe
// Needs to mine and submit the join transaction.
assert(!ValidatorUniverse::is_in_universe(eve_addr), 7357130101091000);
// Does not have a jailedbit since was not added to validator universe yet.
assert(!ValidatorUniverse::exists_jailedbit(eve_addr), 7357130101101000);
// Automatically is a candidate for validator set.
assert(ValidatorUniverse::is_in_universe(eve_addr), 7357130101091000);
// Should have a jailed bit.
assert(ValidatorUniverse::exists_jailedbit(eve_addr), 7357130101101000);
}
}
// check: EXECUTED
Expand All @@ -75,14 +71,12 @@ fun main(sender: &signer) {
script {
use 0x1::MinerState;
use 0x1::Testnet;
// use 0x1::ValidatorUniverse;

fun main(vm: &signer) {
Testnet::remove_testnet(vm); // need to remove testnet for this test, since testnet does not ratelimit account creation.

// check is rate-limited
assert(MinerState::can_create_val_account({{bob}}) == false, 7357130101091000);

// let universe = ValidatorUniverse::get_eligible_validators(vm);
// print(&universe);
}
}
Binary file modified language/stdlib/compiled/stdlib/025_Libra.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified language/stdlib/compiled/stdlib/048_Subsidy.mv
Binary file not shown.
Binary file modified language/stdlib/compiled/stdlib/050_Reconfigure.mv
Binary file not shown.
Binary file modified language/stdlib/compiled/stdlib/055_Genesis.mv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 6 additions & 2 deletions language/stdlib/modules/0L/LibraAccount.move
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module LibraAccount {
use 0x1::Testnet::is_testnet;
use 0x1::FIFO;
use 0x1::FixedPoint32;
use 0x1::ValidatorUniverse;

/// An `address` is a Libra Account if it has a published LibraAccount resource.
resource struct LibraAccount {
Expand Down Expand Up @@ -400,7 +401,7 @@ module LibraAccount {
// This function has no permissions, it doesn't check the signer. And it exceptionally is moving a resource to a different account than the signer.
// LibraAccount is the only code in the VM which can place a resource in an account. As such the module and especially this function has an attack surface.

/////// 0L ////////
/////// 0L ////////
//Function code: 01
public fun create_user_account_with_proof(
challenge: &vector<u8>,
Expand Down Expand Up @@ -451,7 +452,7 @@ module LibraAccount {
&Globals::get_difficulty(),
solution
);
assert(valid, Errors::invalid_argument(120102));
assert(valid, Errors::invalid_argument(120103));

// check there's enough balance for bootstrapping both operator and validator account
assert(balance<GAS>(sender_addr) >= 2 * BOOTSTRAP_COIN_VALUE, Errors::limit_exceeded(EINSUFFICIENT_BALANCE));
Expand Down Expand Up @@ -486,6 +487,9 @@ module LibraAccount {
op_fullnode_network_addresses
);

// user can join validator universe list, but will only join if the mining is above the threshold in the preceeding period.
ValidatorUniverse::add_self(&new_signer);

make_account(new_signer, auth_key_prefix);
make_account(new_op_account, op_auth_key_prefix);

Expand Down
22 changes: 12 additions & 10 deletions language/stdlib/modules/0L/ValidatorUniverse.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ address 0x1 {
use 0x1::Signer;
use 0x1::Testnet;
use 0x1::Vector;

use 0x1::FullnodeState;
// resource for tracking the universe of accounts that have submitted a mined proof correctly, with the epoch number.
resource struct ValidatorUniverse {
validators: vector<address>
Expand Down Expand Up @@ -42,8 +42,12 @@ address 0x1 {
public fun add_self(sender: &signer) acquires ValidatorUniverse, JailedBit {
let addr = Signer::address_of(sender);
// Miner can only add self to set if the mining is above a threshold.
assert(MinerState::node_above_thresh(sender, addr), 220102014010);
add(sender);
if (FullnodeState::is_onboarding(addr)) {
add(sender);
} else {
assert(MinerState::node_above_thresh(sender, addr), 220102014010);
add(sender);
}
}

fun add(sender: &signer) acquires ValidatorUniverse, JailedBit {
Expand Down Expand Up @@ -117,6 +121,10 @@ address 0x1 {
borrow_global_mut<JailedBit>(addr).is_jailed = false;
}

public fun exists_jailedbit(addr: address): bool {
exists<JailedBit>(addr)
}

public fun is_jailed(validator: address): bool acquires JailedBit {
if (!exists<JailedBit>(validator)) {
return false
Expand All @@ -126,19 +134,13 @@ address 0x1 {

public fun genesis_helper(vm: &signer, validator: &signer) acquires ValidatorUniverse, JailedBit {
assert(Signer::address_of(vm) == CoreAddresses::LIBRA_ROOT_ADDRESS(), 220101014010);
// let addr = Signer::address_of(sender);
// MinerState::node_above_thresh(sender, addr);
add(validator);
}

//////// TEST ////////
public fun exists_jailedbit(addr: address): bool {
assert(Testnet::is_testnet()== true, 130115014011);
exists<JailedBit>(addr)
}

public fun test_helper_add_self_onboard(vm: &signer, addr:address) acquires ValidatorUniverse {
assert(Testnet::is_testnet()== true, 130115014011);
assert(Testnet::is_testnet()== true, 220116014011);
assert(Signer::address_of(vm) == CoreAddresses::LIBRA_ROOT_ADDRESS(), 220101015010);
let state = borrow_global_mut<ValidatorUniverse>(CoreAddresses::LIBRA_ROOT_ADDRESS());
Vector::push_back<address>(&mut state.validators, addr);
Expand Down
5 changes: 4 additions & 1 deletion language/stdlib/modules/doc/LibraAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ before and after every transaction.
<b>use</b> <a href="VDF.md#0x1_VDF">0x1::VDF</a>;
<b>use</b> <a href="ValidatorConfig.md#0x1_ValidatorConfig">0x1::ValidatorConfig</a>;
<b>use</b> <a href="ValidatorOperatorConfig.md#0x1_ValidatorOperatorConfig">0x1::ValidatorOperatorConfig</a>;
<b>use</b> <a href="ValidatorUniverse.md#0x1_ValidatorUniverse">0x1::ValidatorUniverse</a>;
<b>use</b> <a href="Vector.md#0x1_Vector">0x1::Vector</a>;
</code></pre>

Expand Down Expand Up @@ -1322,7 +1323,7 @@ Initialize this module. This is only callable from genesis.
&<a href="Globals.md#0x1_Globals_get_difficulty">Globals::get_difficulty</a>(),
solution
);
<b>assert</b>(valid, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(120102));
<b>assert</b>(valid, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(120103));

// check there's enough balance for bootstrapping both operator and validator account
<b>assert</b>(<a href="LibraAccount.md#0x1_LibraAccount_balance">balance</a>&lt;<a href="GAS.md#0x1_GAS">GAS</a>&gt;(sender_addr) &gt;= 2 * <a href="LibraAccount.md#0x1_LibraAccount_BOOTSTRAP_COIN_VALUE">BOOTSTRAP_COIN_VALUE</a>, <a href="Errors.md#0x1_Errors_limit_exceeded">Errors::limit_exceeded</a>(<a href="LibraAccount.md#0x1_LibraAccount_EINSUFFICIENT_BALANCE">EINSUFFICIENT_BALANCE</a>));
Expand Down Expand Up @@ -1357,6 +1358,8 @@ Initialize this module. This is only callable from genesis.
op_fullnode_network_addresses
);

<a href="ValidatorUniverse.md#0x1_ValidatorUniverse_add_self">ValidatorUniverse::add_self</a>(&new_signer);

<a href="LibraAccount.md#0x1_LibraAccount_make_account">make_account</a>(new_signer, auth_key_prefix);
<a href="LibraAccount.md#0x1_LibraAccount_make_account">make_account</a>(new_op_account, op_auth_key_prefix);

Expand Down
Loading

0 comments on commit 9b01b5e

Please sign in to comment.