Skip to content

Commit

Permalink
Vouch validators fixes
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <[email protected]>
  • Loading branch information
hemulin and 0o-de-lally authored Oct 30, 2023
1 parent dc9f71f commit 059df06
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 70 deletions.
5 changes: 2 additions & 3 deletions framework/libra-framework/sources/modified_source/stake.move
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,10 @@ module diem_framework::stake {


//////// 0L ////////
// TODO: v7
#[view]
/// Returns the validator's state.
public fun is_valid(addr: address): bool acquires ValidatorSet{
get_validator_state(addr) == VALIDATOR_STATUS_ACTIVE
public fun is_valid(addr: address): bool {
exists<ValidatorConfig>(addr)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module diem_framework::epoch_boundary {
use std::vector;
use std::error;

use diem_std::debug::print;
// use diem_std::debug::print;

friend diem_framework::block;

Expand Down Expand Up @@ -179,7 +179,7 @@ module diem_framework::epoch_boundary {

subsidize_from_infra_escrow(root);

print(borrow_global<BoundaryStatus>(@ol_framework))
// print(borrow_global<BoundaryStatus>(@ol_framework))
}

// TODO: instrument all of this
Expand Down
29 changes: 18 additions & 11 deletions framework/libra-framework/sources/ol_sources/globals.move
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,25 @@ module ol_framework::globals {
};

if (testnet::is_staging_net()) {
// All numbers like MAINNET except shorter epochs of 30 mins
// and minimum mining of 1 proof
return GlobalConstants {
epoch_length: 60 * 40, // 40 mins, enough for a hard miner proof.
val_set_at_genesis: 100,
subsidy_ceiling_gas: 8640000 * get_coin_scaling_factor(),
vdf_difficulty_baseline: 100, //3000000000,
epoch_length: 60 * 30, // 30 mins, enough for a hard miner proof.
val_set_at_genesis: 100, // max expected for BFT limits.
// See DiemVMConfig for gas constants:
// Target max gas units per transaction 100000000
// target max block time: 2 secs
// target transaction per sec max gas: 20
// uses "scaled representation", since there are no decimals.
subsidy_ceiling_gas: 8640000 * get_coin_scaling_factor(), // subsidy amount assumes 24 hour epoch lengths. Also needs to be adjusted for coin_scale the onchain representation of human readable value.
vdf_difficulty_baseline: 120000000, // wesolowski proof, new parameters. Benchmark available in docs/delay_tower/benchmarking
vdf_security_baseline: 512,
epoch_mining_thres_lower: 1, // in testnet, staging, we don't want
// to wait too long between proofs.
epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof.
epoch_slow_wallet_unlock: 1000 * get_coin_scaling_factor(),
min_blocks_per_epoch: 1000,
validator_vouch_threshold: 0,
// NOTE Reviewers: this goes back to v5 params since the VDF cryptograpy will actually not be changed
epoch_mining_thres_lower: 1, // lower bound, allows for some operator error
epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof
epoch_slow_wallet_unlock: 1000 * get_coin_scaling_factor(), // approx 10 years for largest accounts in genesis.
min_blocks_per_epoch: 10000,
validator_vouch_threshold: 2, // Production must be more than 1 vouch validator (at least 2)
signing_threshold_pct: 3,
}
} else {
Expand All @@ -148,7 +155,7 @@ module ol_framework::globals {
epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof
epoch_slow_wallet_unlock: 1000 * get_coin_scaling_factor(), // approx 10 years for largest accounts in genesis.
min_blocks_per_epoch: 10000,
validator_vouch_threshold: 1, // Production must be more than 1 vouch validator (at least 2)
validator_vouch_threshold: 2, // Production must be more than 1 vouch validator (at least 2)
signing_threshold_pct: 3,
}
}
Expand Down
26 changes: 13 additions & 13 deletions framework/libra-framework/sources/ol_sources/oracle.move
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ module ol_framework::oracle {
use ol_framework::epoch_helper;
use std::error;

use diem_std::debug::print;
// use diem_std::debug::print;

friend ol_framework::epoch_boundary;
friend ol_framework::tower_state;

/// You need a minimum of three Vouches on your account, and of unrelated
/// buddies. Meaning: they don't come from the same ancestry of accounts.
/// You need a minimum of Vouches on your account for this task.
/// They also must be of unrelated buddies.
/// Meaning: they don't come from the same ancestry of accounts.
/// Go meet more people!
const ENOT_THREE_UNRELATED_VOUCHERS: u64 = 1;
const ENOT_ENOUGH_UNRELATED_VOUCHERS: u64 = 1;
/// You'll need to have some vouches by accounts in the miner community.
/// We check if you had any vouchers (buddies) among the successful miners of the
/// previous epoch.
const ENEED_THREE_FRIENDS_IN_MINER_COMMUNITY: u64 = 2;
/// We check if you had any vouchers (buddies) among the successful
/// miners of the previous epoch.
const ENEED_MORE_FRIENDS_IN_MINER_COMMUNITY: u64 = 2;

/// somehow your submission is behind the blockchains's time
const ETIME_IS_IN_PAST_WHAAAT: u64 = 3;
Expand Down Expand Up @@ -141,11 +142,11 @@ module ol_framework::oracle {
{
// must have 3 accounts who are unrelated vouching for you.
let frens = vouch::true_friends(provider_addr);
assert!(vector::length(&frens) > 2, error::invalid_state(ENOT_THREE_UNRELATED_VOUCHERS));
assert!(vector::length(&frens) > 2, error::invalid_state(ENOT_ENOUGH_UNRELATED_VOUCHERS));
// in the previous epoch of successful miners, you'll need to have 3 unrelated vouchers there as well.
let previous_epoch_list = &borrow_global<ProviderList>(@ol_framework).previous_epoch_list;
let (_, count_buddies) = vouch::true_friends_in_list(provider_addr, previous_epoch_list);
assert!(count_buddies > 2, error::invalid_state(ENEED_THREE_FRIENDS_IN_MINER_COMMUNITY));
assert!(count_buddies > 2, error::invalid_state(ENEED_MORE_FRIENDS_IN_MINER_COMMUNITY));

};

Expand Down Expand Up @@ -184,7 +185,6 @@ module ol_framework::oracle {
}

fun increment_stats(provider_addr: address, tower: &mut Tower, time: u64, signature_bytes: vector<u8>,) acquires GlobalCounter, ProviderList {
print(&333);

// update the global state
let global = borrow_global_mut<GlobalCounter>(@ol_framework);
Expand All @@ -205,12 +205,12 @@ module ol_framework::oracle {

// also check if the tower is now above the threshold
if (tower.count_proofs_in_epoch > globals::get_epoch_mining_thres_lower()) {
print(&333001);
// print(&333001);
global.proofs_in_epoch_above_thresh = global.proofs_in_epoch_above_thresh + 1;
// also add to the provider list which would be elegible for rewards
let provider_list = borrow_global_mut<ProviderList>(@ol_framework);
vector::push_back(&mut provider_list.current_above_threshold, provider_addr);
print(provider_list);
// print(provider_list);
};


Expand Down Expand Up @@ -285,7 +285,7 @@ module ol_framework::oracle {
// print(&coin_value);

let provider_list = borrow_global_mut<ProviderList>(@ol_framework).current_above_threshold;
print(&provider_list);
// print(&provider_list);
let len = vector::length(&provider_list);

if (len == 0) return (0, 0);
Expand Down
26 changes: 19 additions & 7 deletions framework/libra-framework/sources/ol_sources/proof_of_fee.move
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@ module ol_framework::proof_of_fee {
return (filtered_vals, bids)
}

#[view]
/// checks if the validator has enough vouchers in the current set (prior to entry)
/// @params incoming address to be evaluated
/// @returns (above_threshold, count_validators) if
public fun get_valid_vouchers_in_set(incoming_addr: address): (bool, u64) {
let val_set = stake::get_current_validators();
let (frens_in_val_set, _found) = vouch::true_friends_in_list(incoming_addr, &val_set);
let threshold = globals::get_validator_vouch_threshold();
let count_in_set = vector::length(&frens_in_val_set);

(count_in_set >= threshold, count_in_set)
}


// Here we place the bidders into their seats.
// The order of the bids will determine placement.
// One important aspect of picking the next validator set:
Expand Down Expand Up @@ -387,14 +401,13 @@ module ol_framework::proof_of_fee {
// we can't seat validators that were just jailed
// NOTE: epoch reconfigure needs to reset the jail
// before calling the proof of fee.
if (jail::is_jailed(val)) vector::push_back(&mut errors, EIS_JAILED); // 33
// we can't seat validators who don't have minimum viable vouches
if (jail::is_jailed(val)) vector::push_back(&mut errors, EIS_JAILED); //13

let val_set = stake::get_current_validators();
let (frens_in_val_set, _found) = vouch::true_friends_in_list(val, &val_set);
let threshold = globals::get_validator_vouch_threshold();
if (vector::length(&frens_in_val_set) < threshold) vector::push_back(&mut errors, ETOO_FEW_VOUCHES); // 14
// we can't seat validators who don't have minimum viable vouches
let (is_above_thresh, _count) = get_valid_vouchers_in_set(val);
if (!is_above_thresh) vector::push_back(&mut errors, ETOO_FEW_VOUCHES); // 14

// check if current BIDS are valid
let (bid_pct, expire) = current_bid(val);
if (bid_pct == 0) vector::push_back(&mut errors, EBID_IS_ZERO); // 15
// Skip if the bid expired. belt and suspenders, this should have been checked in the sorting above.
Expand All @@ -405,7 +418,6 @@ module ol_framework::proof_of_fee {
// or if the bid expired.
let unlocked_coins = slow_wallet::unlocked_amount(val);
let (_, entry_fee, _, _) = get_consensus_reward();
// let coin_required = fixed_point32::multiply_u64(baseline_reward, bid_as_fixedpoint(bid_pct));

if (unlocked_coins < entry_fee) vector::push_back(&mut errors, ELOW_UNLOCKED_COIN_BALANCE); // 17

Expand Down
2 changes: 1 addition & 1 deletion framework/libra-framework/sources/ol_sources/testnet.move
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module ol_framework::testnet {
}

public fun is_staging_net(): bool {
chain_id::get() == 2
chain_id::get() == 2 // TESTNET named chain
}

#[test_only]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module ol_framework::test_pof {

mock_good_bid(&root, &alice);

// need to unset testnet for vouch to be tested
testnet::unset(&root);

let val_set = stake::get_current_validators();
Expand Down Expand Up @@ -169,15 +170,12 @@ module ol_framework::test_pof {
mock_good_bid(&root, &alice);

// needs friends
// vouch::test_set_buddies(alice, set);
let (_err, pass) = proof_of_fee::audit_qualification(alice);
assert!(pass, 1002);

// has a bid which IS expired
// test runner is at epoch 1, they put expiry at 0.
// TODO: Improve this test by doing more advanced epochs
mock::mock_all_vals_good_performance(&root);
mock::trigger_epoch(&root);
// we just need to increment for testing expiry
reconfiguration::test_helper_increment_epoch_dont_reconfigure();


let a_sig = account::create_signer_for_test(alice);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ module ol_framework::test_tower {
use ol_framework::proof_of_fee;
use ol_framework::stake;
use diem_framework::timestamp;
// use diem_framework::coin;
// use ol_framework::gas_coin::LibraCoin as GasCoin;
use std::vector;

use std::debug::print;
// use std::debug::print;

#[test(root = @ol_framework)]
fun epoch_changes_difficulty(root: signer) {
Expand Down Expand Up @@ -106,8 +104,8 @@ module ol_framework::test_tower {
vdf_fixtures::security(),
);

let count_pre = tower_state::get_count_in_epoch(a_addr);
print(&count_pre);
// let count_pre = tower_state::get_count_in_epoch(a_addr);
// print(&count_pre);

// all vals compliant
mock::mock_all_vals_good_performance(&root);
Expand Down
18 changes: 1 addition & 17 deletions framework/libra-framework/sources/ol_sources/vouch.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module ol_framework::vouch {
use ol_framework::epoch_helper;

use diem_framework::system_addresses;
// use diem_framework::stake;
use diem_framework::transaction_fee;

friend diem_framework::genesis;
Expand Down Expand Up @@ -160,13 +159,6 @@ module ol_framework::vouch {
false
}

// #[view]
// public fun buddies_in_validator_set(val: address): vector<address> acquires MyVouches {
// let current_set = stake::get_current_validators();
// let (list, _) = buddies_in_list(val, &current_set);
// list
// }

/// for a given list find and count any of my vouchers
public fun true_friends_in_list(addr: address, list: &vector<address>): (vector<address>, u64) acquires MyVouches {

Expand All @@ -189,15 +181,7 @@ module ol_framework::vouch {
}


// #[view]
// public fun true_friends_above_thresh(addr: address, list: &vector<address>, threshold: u64): bool acquires MyVouches{
// if (!exists<MyVouches>(addr)) return false;

// let (found_in_list, _found) = true_friends_in_list(addr, list);

// return vector::length(&found_in_list) > threshold
// }

// TODO: move to globals
// the cost to verify a vouch. Coins are burned.
fun vouch_cost_microlibra(): u64 {
1000
Expand Down
8 changes: 4 additions & 4 deletions tools/config/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ pub fn initialize_validator(
) -> anyhow::Result<()> {
let (.., keys) =
libra_wallet::keys::refresh_validator_files(mnem, home_path.clone(), keep_legacy_address)?;
OLProgress::complete("Initialized validator key files");
OLProgress::complete("initialized validator key files");

// TODO: set validator fullnode configs. Not NONE
let effective_username = username.unwrap_or("default_username"); // Use default if None
SetValidatorConfiguration::new(home_path.clone(), effective_username.to_owned(), host, None)
.set_config_files()?;
OLProgress::complete("Saved validator registration files locally");
OLProgress::complete("saved validator registration files locally");

node_yaml::save_validator_yaml(home_path.clone())?;
OLProgress::complete("Saved validator node yaml file locally");
OLProgress::complete("saved validator node yaml file locally");

// TODO: nice to have
// also for convenience create a local user libra.yaml file so the
Expand All @@ -46,7 +46,7 @@ pub fn initialize_validator(
"could not initialize configs at {}",
cfg.workspace.node_home.to_str().unwrap()
))?;
OLProgress::complete("Saved a user libra.yaml file locally");
OLProgress::complete("saved a user libra.yaml file locally");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tools/txs/src/txs_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl TxsCli {
.await?;

if self.tx_cost.is_some() && self.tx_profile.is_some() {
println!("ERROR: --tx-cost and --txs-profile are mutually exclusive. Either set the costs explicitly or choose a profile in libra.yaml, exiting");
println!("ERROR: --tx-cost and --tx-profile are mutually exclusive. Either set the costs explicitly or choose a profile in libra.yaml, exiting");
}
let tx_cost = self
.tx_cost
Expand Down

0 comments on commit 059df06

Please sign in to comment.