Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 52b3024
Author: 0o-de-lally <[email protected]>
Date:   Fri Nov 10 16:53:24 2023 -0500

    [move] various account state patches from testnet (0LNetworkCommunity#96)

commit 2c0838b
Author: 0o-de-lally <[email protected]>
Date:   Fri Nov 10 18:05:00 2023 +0000

    patch fullnode downloads url

commit 2ef4734
Author: zoz <[email protected]>
Date:   Sat Nov 11 03:37:06 2023 +1100

    [tools] update fullnode-init command (0LNetworkCommunity#95)

commit 1319077
Author: 0o-de-lally <[email protected]>
Date:   Fri Nov 10 11:07:53 2023 -0500

    [ci] publish ubuntu bins for CI use (0LNetworkCommunity#91)

commit b6477bb
Author: 0o-de-lally <[email protected]>
Date:   Fri Nov 10 11:07:36 2023 -0500

    [tools] better env setup tools util/dev_setup.sh (0LNetworkCommunity#93)
  • Loading branch information
0o-de-lally committed Nov 10, 2023
1 parent b00051a commit ccc9bda
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 95 deletions.
35 changes: 18 additions & 17 deletions framework/libra-framework/sources/modified_source/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ module diem_framework::genesis {

//////// 0L ////////
use diem_framework::validator_universe;
// use ol_framework::ol_account;
use ol_framework::ol_account;
use ol_framework::musical_chairs;
use ol_framework::proof_of_fee;
use ol_framework::slow_wallet;
use ol_framework::gas_coin::{Self, LibraCoin as GasCoin};
use ol_framework::gas_coin;
use ol_framework::infra_escrow;
use ol_framework::tower_state;
use ol_framework::safe;
Expand All @@ -44,6 +44,8 @@ module diem_framework::genesis {
use ol_framework::testnet;
use ol_framework::epoch_boundary;
use ol_framework::sacred_cows;
#[test_only]
use ol_framework::gas_coin::LibraCoin as GasCoin;
//////// end 0L ////////


Expand Down Expand Up @@ -228,15 +230,12 @@ module diem_framework::genesis {

/// This creates an funds an account if it doesn't exist.
/// If it exists, it just returns the signer.
fun create_account(_diem_framework: &signer, account_address: address, _balance: u64): signer {
if (account::exists_at(account_address)) {
create_signer(account_address)
} else {
let account = account::create_account(account_address);
// coin::register<GasCoin>(&account);
coin::register<GasCoin>(&account);
account
}
fun create_account(diem_framework: &signer, account_address: address, _balance: u64): signer {
if (!account::exists_at(account_address)) {
ol_account::create_account(diem_framework, account_address);
};

create_signer(account_address)
}

fun create_initialize_validators_with_commission(
Expand All @@ -255,13 +254,15 @@ module diem_framework::genesis {
register_one_genesis_validator(diem_framework, validator, false);
vector::push_back(&mut val_addr_list, *&validator.validator_config.owner_address);
// 0x1 code account is calling this contract but the 0x0 VM address is authorized for infra escrow.
infra_escrow::genesis_coin_validator(&create_signer(@0x0), *&validator.validator_config.owner_address);
if (testnet::is_not_mainnet()) {
let sig = create_signer(validator.validator_config.owner_address);
proof_of_fee::set_bid(&sig, 0900, 1000); // make the genesis
// default 90% to align with thermostatic rule in the PoF paper.
// otherwise the thermostatic rule starts kicking-in immediately
infra_escrow::genesis_coin_validator(&create_signer(@0x0),
*&validator.validator_config.owner_address);

// default 90% to align with thermostatic rule in the PoF paper.
// otherwise the thermostatic rule starts kicking-in immediately
let sig = create_signer(validator.validator_config.owner_address);
proof_of_fee::set_bid(&sig, 0900, 1000); // make the genesis

if (testnet::is_not_mainnet()) {
// TODO: this is for testnet purposes only
// unlock some of the genesis validators coins so they can issue
// transactions from epoch 0 in test runners.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ module diem_framework::transaction_fee {

// Initialization.
let (burn_cap, mint_cap) = gas_coin::initialize_for_test(&root);
gas_coin::test_set_final_supply(&root, 100);
store_diem_coin_burn_cap(&root, burn_cap);
initialize_fee_collection_and_distribution(&root, 10);

Expand Down
12 changes: 7 additions & 5 deletions framework/libra-framework/sources/ol_sources/burn.move
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,24 @@ module ol_framework::burn {
/// is much larger than the amount of fees available burn.
/// So we need to find the proportion of the fees that each Fee Maker has
/// produced, and then do a weighted burn/recycle.
/// @return a tuple of 2
/// 0: BOOL, if epoch burn ran correctly
/// 1: U64, how many coins burned
public fun epoch_burn_fees(
vm: &signer,
coins: &mut Coin<GasCoin>,
) acquires UserBurnPreference, BurnCounter {
): (bool, u64) acquires UserBurnPreference, BurnCounter {
system_addresses::assert_ol(vm);

// get the total fees made. This will likely be different than
// the value of Coins, since some have already been spent on validator rewards.
let total_fees_made = fee_maker::get_all_fees_made();

// extract fees
// let coins = transaction_fee::root_withdraw_all(vm);

let available_to_burn = coin::value(coins);
if (available_to_burn == 0) {
// don't destroy, let the caller handle empty coins
return
return (false, 0)
};

// get the list of fee makers
Expand Down Expand Up @@ -102,6 +103,7 @@ module ol_framework::burn {
let leftover = coin::extract(coins, remainder);
burn_and_track(leftover);
// Note: we are still retruning an empty coin to be destroyed by the caller
(true, total_fees_made)
}


Expand Down Expand Up @@ -179,4 +181,4 @@ module ol_framework::burn {

//////// TEST HELPERS ////////

}
}
55 changes: 36 additions & 19 deletions framework/libra-framework/sources/ol_sources/epoch_boundary.move
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module diem_framework::epoch_boundary {


// I just checked in, to see what condition my condition was in.
struct BoundaryStatus has key {
struct BoundaryStatus has key, drop {
security_bill_count: u64,
security_bill_amount: u64,
security_bill_success: bool,
Expand All @@ -61,9 +61,11 @@ module diem_framework::epoch_boundary {
oracle_pay_amount: u64,
oracle_pay_success: bool,

epoch_burn_fees: u64, // TODO
epoch_burn_success: bool, // TODO
slow_wallet_drip: bool, // TODO
epoch_burn_fees: u64,
epoch_burn_success: bool,

slow_wallet_drip_amount: u64,
slow_wallet_drip_success: bool,
// Process Incoming
// musical chairs
incoming_compliant: vector<address>,
Expand All @@ -85,8 +87,8 @@ module diem_framework::epoch_boundary {
incoming_final_set_size: u64,
incoming_reconfig_success: bool,

infra_subsize_amount: u64, // TODO
infra_subsizize_success: bool, // TODO
infra_subsidize_amount: u64, // TODO
infra_subsidize_success: bool, // TODO

pof_thermo_success: bool,
pof_thermo_increase: bool,
Expand All @@ -95,7 +97,12 @@ module diem_framework::epoch_boundary {

public fun initialize(framework: &signer) {
if (!exists<BoundaryStatus>(@ol_framework)){
move_to(framework, BoundaryStatus {
move_to(framework, reset());
}
}

fun reset(): BoundaryStatus {
BoundaryStatus {
security_bill_count: 0,
security_bill_amount: 0,
security_bill_success: false,
Expand Down Expand Up @@ -123,7 +130,9 @@ module diem_framework::epoch_boundary {
oracle_pay_success: false,
epoch_burn_fees: 0,
epoch_burn_success: false,
slow_wallet_drip: false,

slow_wallet_drip_amount: 0,
slow_wallet_drip_success: false,
// Process Incoming
incoming_compliant: vector::empty(),
incoming_compliant_count: 0,
Expand All @@ -141,14 +150,13 @@ module diem_framework::epoch_boundary {
incoming_actual_vals: vector::empty(),
incoming_reconfig_success: false,

infra_subsize_amount: 0,
infra_subsizize_success: false,
infra_subsidize_amount: 0,
infra_subsidize_success: false,

pof_thermo_success: false,
pof_thermo_increase: false,
pof_thermo_amount: 0,
});
}
}
}


Expand All @@ -159,6 +167,7 @@ module diem_framework::epoch_boundary {
system_addresses::assert_ol(root);

let status = borrow_global_mut<BoundaryStatus>(@ol_framework);
*status = reset();
// bill root service fees;
root_service_billing(root, status);
// run the transactions of donor directed accounts
Expand All @@ -171,6 +180,7 @@ module diem_framework::epoch_boundary {
status.set_fee_makers_success = fee_maker::epoch_reset_fee_maker(root);
// randomize the Tower/Oracle difficulty
tower_state::reconfig(root);
status.tower_state_success = true; // TODO: there isn't much to check here.

let (compliant_vals, n_seats) = musical_chairs::stop_the_music(root, closing_epoch);
status.incoming_compliant_count = vector::length(&compliant_vals);
Expand All @@ -180,12 +190,16 @@ module diem_framework::epoch_boundary {
settle_accounts(root, compliant_vals, status);

// drip coins
slow_wallet::on_new_epoch(root);
let (s_success, s_amount) = slow_wallet::on_new_epoch(root);
status.slow_wallet_drip_amount = s_amount;
status.slow_wallet_drip_success = s_success;

// ======= THIS IS APPROXIMATELY THE BOUNDARY =====
process_incoming_validators(root, status, compliant_vals, n_seats);

subsidize_from_infra_escrow(root);
let (i_success, i_fee) = subsidize_from_infra_escrow(root);
status.infra_subsidize_amount = i_fee;
status.infra_subsidize_success = i_success;

let (t_success, t_increase, t_amount) =
proof_of_fee::reward_thermostat(root);
Expand Down Expand Up @@ -237,13 +251,15 @@ module diem_framework::epoch_boundary {
let (count, amount) = oracle::epoch_boundary(root, &mut oracle_budget);
status.oracle_pay_count = count;
status.oracle_pay_amount = amount;
status.oracle_pay_success = status.oracle_budget == amount;
status.oracle_pay_success = (amount > 0);
// in case there is any dust left
ol_account::merge_coins(&mut all_fees, oracle_budget);
};

// remainder gets burnt according to fee maker preferences
burn::epoch_burn_fees(root, &mut all_fees);
let (b_success, b_fees) = burn::epoch_burn_fees(root, &mut all_fees);
status.epoch_burn_success = b_success;
status.epoch_burn_fees = b_fees;

// coin can finally be destroyed. Up to here we have been extracting from a mutable.
// It's possible there might be some dust, that should get burned
Expand Down Expand Up @@ -317,14 +333,15 @@ module diem_framework::epoch_boundary {
}

// set up rewards subsidy for coming epoch
fun subsidize_from_infra_escrow(root: &signer) {
fun subsidize_from_infra_escrow(root: &signer): (bool, u64) {
system_addresses::assert_ol(root);
let (reward_per, _, _, _ ) = proof_of_fee::get_consensus_reward();
let vals = stake::get_current_validators();
let count_vals = vector::length(&vals);
count_vals = count_vals + ORACLE_PROVIDERS_SEATS;
let total_epoch_budget = count_vals * reward_per;
infra_escrow::epoch_boundary_collection(root, total_epoch_budget);
infra_escrow::epoch_boundary_collection(root,
total_epoch_budget)
}

// all services the root collective security is billing for
Expand Down Expand Up @@ -368,4 +385,4 @@ module diem_framework::epoch_boundary {
epoch_boundary(vm, closing_epoch, epoch_round);
}

}
}
19 changes: 13 additions & 6 deletions framework/libra-framework/sources/ol_sources/infra_escrow.move
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,26 @@ module ol_framework::infra_escrow{
}

/// Helper for epoch boundaries.
/// Collects funds from pledge and places temporarily in network account (TransactionFee account)
public(friend) fun epoch_boundary_collection(root: &signer, amount: u64) {
/// Collects funds from pledge and places temporarily in network account
// (the TransactionFee account)
/// @return tuple of 2
/// 0: if collection succeeded
/// 1: how much was collected
public(friend) fun epoch_boundary_collection(root: &signer, amount: u64):
(bool, u64) {
system_addresses::assert_ol(root);
let opt = pledge_accounts::withdraw_from_all_pledge_accounts(root, amount);

if (option::is_none(&opt)) {
option::destroy_none(opt);
return
return (false, 0)
};
let c = option::extract(&mut opt);
option::destroy_none(opt);

transaction_fee::vm_pay_fee(root, @vm_reserved, c); // don't attribute to the user
let value = coin::value(&c);
transaction_fee::vm_pay_fee(root, @vm_reserved, c); // don't attribute
// to the user
return(true, value)
}


Expand Down Expand Up @@ -101,4 +108,4 @@ module ol_framework::infra_escrow{
option::destroy_none(c_opt);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module ol_framework::gas_coin {
// have been initialized.
move_to(diem_framework, MintCapStore { mint_cap });


coin::destroy_freeze_cap(freeze_cap);
coin::destroy_burn_cap(burn_cap);

Expand Down
4 changes: 3 additions & 1 deletion framework/libra-framework/sources/ol_sources/mock.move
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ module ol_framework::mock {
i = i + 1;
};

if (drip) slow_wallet::slow_wallet_epoch_drip(root, amount);
if (drip) {
slow_wallet::slow_wallet_epoch_drip(root, amount);
};
gas_coin::restore_mint_cap(root, mint_cap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module ol_framework::musical_chairs {
use diem_framework::system_addresses;
use diem_framework::stake;
use ol_framework::grade;
// use ol_framework::testnet;
use std::fixed_point32;
use std::vector;
// use diem_std::debug::print;
Expand All @@ -13,7 +12,7 @@ module ol_framework::musical_chairs {
struct Chairs has key {
// The number of chairs in the game
seats_offered: u64,
// A small history, for future use.
// TODO: A small history, for future use.
history: vector<u64>,
}

Expand Down Expand Up @@ -79,7 +78,9 @@ module ol_framework::musical_chairs {

let num_compliant_nodes = vector::length(&compliant_vals);

// failover, there should not be more compliant nodes than seats that were offered.
// failover, there should not be more compliant nodes than seats that
// were offered.

// return with no changes
if (num_compliant_nodes > chairs.seats_offered) {
return (compliant_vals, chairs.seats_offered)
Expand Down
Loading

0 comments on commit ccc9bda

Please sign in to comment.