Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move] patch thermostat on epoch boundary, add instrumentation #87

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,6 @@ module diem_framework::stake {
system_addresses::assert_ol(root);
let validator_address = signer::address_of(validator);
if (!account::exists_at(signer::address_of(validator))) {
// account::create_account_for_test(validator_address);
ol_account::create_account(root, validator_address);
};

Expand Down
14 changes: 14 additions & 0 deletions framework/libra-framework/sources/ol_sources/epoch_boundary.move
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ module diem_framework::epoch_boundary {

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

pof_thermo_success: bool,
pof_thermo_increase: bool,
pof_thermo_amount: u64,
}

public fun initialize(framework: &signer) {
Expand Down Expand Up @@ -139,6 +143,10 @@ module diem_framework::epoch_boundary {

infra_subsize_amount: 0,
infra_subsizize_success: false,

pof_thermo_success: false,
pof_thermo_increase: false,
pof_thermo_amount: 0,
});
}
}
Expand Down Expand Up @@ -179,6 +187,12 @@ module diem_framework::epoch_boundary {

subsidize_from_infra_escrow(root);

let (t_success, t_increase, t_amount) =
proof_of_fee::reward_thermostat(root);
status.pof_thermo_success = t_success;
status.pof_thermo_increase = t_increase;
status.pof_thermo_amount = t_amount;

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

Expand Down
55 changes: 32 additions & 23 deletions framework/libra-framework/sources/ol_sources/proof_of_fee.move
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module ol_framework::proof_of_fee {
/// not enough coin balance
const ELOW_UNLOCKED_COIN_BALANCE: u64 = 17;


// A struct on the validators account which indicates their
// latest bid (and epoch)
struct ProofOfFeeAuction has key {
Expand All @@ -69,7 +70,7 @@ module ol_framework::proof_of_fee {
median_history: vector<u64>,
}
public fun init_genesis_baseline_reward(vm: &signer) {
if (signer::address_of(vm) != @ol_framework) return;
system_addresses::assert_ol(vm);

if (!exists<ConsensusReward>(@ol_framework)) {
move_to<ConsensusReward>(
Expand Down Expand Up @@ -427,13 +428,16 @@ module ol_framework::proof_of_fee {
fun bid_as_fixedpoint(bid_pct: u64): fixed_point32::FixedPoint32 {
fixed_point32::create_from_rational(bid_pct, 1000)
}
// Adjust the reward at the end of the epoch
// as described in the paper, the epoch reward needs to be adjustable
// given that the implicit bond needs to be sufficient, eg 5-10x the reward.
public fun reward_thermostat(vm: &signer) acquires ConsensusReward {
if (signer::address_of(vm) != @ol_framework) {
return
};
/// Adjust the reward at the end of the epoch
/// as described in the paper, the epoch reward needs to be adjustable
/// given that the implicit bond needs to be sufficient, eg 5-10x the reward.
/// @return Tuple (bool, bool, u64)
/// 0: did the thermostat run,
/// 1: did it increment, or decrease, bool
/// 2: how much
/// if the thermostat returns (false, false, 0), it means there was an error running
public fun reward_thermostat(vm: &signer): (bool, bool, u64) acquires ConsensusReward {
system_addresses::assert_ol(vm);
// check the bid history
// if there are 5 days above 95% adjust the reward up by 5%
// adjust by more if it has been 10 days then, 10%
Expand Down Expand Up @@ -492,18 +496,19 @@ module ol_framework::proof_of_fee {
if (epochs_above > long_window) {

// decrease the reward by 10%
let less_ten_pct = (cr.nominal_reward / 10);
cr.nominal_reward = cr.nominal_reward - less_ten_pct;
return (true, false, less_ten_pct)

cr.nominal_reward = cr.nominal_reward - (cr.nominal_reward / 10);
return // return early since we can't increase and decrease simultaneously
} else if (epochs_above > short_window) {
// decrease the reward by 5%
let less_five_pct = (cr.nominal_reward / 20);
cr.nominal_reward = cr.nominal_reward - less_five_pct;

cr.nominal_reward = cr.nominal_reward - (cr.nominal_reward / 20);


return // return early since we can't increase and decrease simultaneously
return (true, false, less_five_pct)
}
};
// return early since we can't increase and decrease simultaneously


// if validators are bidding low percentages
Expand All @@ -517,27 +522,31 @@ module ol_framework::proof_of_fee {


if (epochs_below > long_window) {


// increase the reward by 10%
cr.nominal_reward = cr.nominal_reward + (cr.nominal_reward / 10);
let increase_ten_pct = (cr.nominal_reward / 10);
cr.nominal_reward = cr.nominal_reward + increase_ten_pct;
return (true, true, increase_ten_pct)
} else if (epochs_below > short_window) {


// increase the reward by 5%
cr.nominal_reward = cr.nominal_reward + (cr.nominal_reward / 20);
let increase_five_pct = (cr.nominal_reward / 20);
cr.nominal_reward = cr.nominal_reward + increase_five_pct;
return (true, true, increase_five_pct)
};
// };

// we ran the thermostat but no change was made.
return (true, false, 0)
};

// nominal reward is zero, there's a problem
return (false, false, 0)
}

/// find the median bid to push to history
// this is needed for reward_thermostat
public fun set_history(vm: &signer, proposed_validators: &vector<address>) acquires ProofOfFeeAuction, ConsensusReward {
if (signer::address_of(vm) != @ol_framework) {
return
};

system_addresses::assert_ol(vm);

let median_bid = get_median(proposed_validators);
// push to history
Expand Down
Loading