Skip to content

Commit

Permalink
refactor jail function at epoch boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Feb 23, 2023
1 parent 21e39aa commit 6990356
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 145 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
- [Function `reconfigure`](#0x1_EpochBoundary_reconfigure)
- [Function `process_fullnodes`](#0x1_EpochBoundary_process_fullnodes)
- [Function `process_validators`](#0x1_EpochBoundary_process_validators)
- [Function `process_jail`](#0x1_EpochBoundary_process_jail)
- [Function `propose_new_set`](#0x1_EpochBoundary_propose_new_set)
- [Function `reset_counters`](#0x1_EpochBoundary_reset_counters)


<pre><code><b>use</b> <a href="AutoPay.md#0x1_AutoPay">0x1::AutoPay</a>;
<pre><code><b>use</b> <a href="Audit.md#0x1_Audit">0x1::Audit</a>;
<b>use</b> <a href="AutoPay.md#0x1_AutoPay">0x1::AutoPay</a>;
<b>use</b> <a href="CoreAddresses.md#0x1_CoreAddresses">0x1::CoreAddresses</a>;
<b>use</b> <a href="Debug.md#0x1_Debug">0x1::Debug</a>;
<b>use</b> <a href="DiemAccount.md#0x1_DiemAccount">0x1::DiemAccount</a>;
Expand All @@ -23,6 +25,7 @@
<b>use</b> <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/FixedPoint32.md#0x1_FixedPoint32">0x1::FixedPoint32</a>;
<b>use</b> <a href="FullnodeSubsidy.md#0x1_FullnodeSubsidy">0x1::FullnodeSubsidy</a>;
<b>use</b> <a href="Globals.md#0x1_Globals">0x1::Globals</a>;
<b>use</b> <a href="Jail.md#0x1_Jail">0x1::Jail</a>;
<b>use</b> <a href="ProofOfFee.md#0x1_ProofOfFee">0x1::ProofOfFee</a>;
<b>use</b> <a href="RecoveryMode.md#0x1_RecoveryMode">0x1::RecoveryMode</a>;
<b>use</b> <a href="Stats.md#0x1_Stats">0x1::Stats</a>;
Expand Down Expand Up @@ -208,6 +211,50 @@



</details>

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

## Function `process_jail`



<pre><code><b>fun</b> <a href="EpochBoundary.md#0x1_EpochBoundary_process_jail">process_jail</a>(vm: &signer, outgoing_compliant_set: &vector&lt;<b>address</b>&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="EpochBoundary.md#0x1_EpochBoundary_process_jail">process_jail</a>(vm: &signer, outgoing_compliant_set: &vector&lt;<b>address</b>&gt;) {
<b>let</b> all_previous_vals = <a href="DiemSystem.md#0x1_DiemSystem_get_val_set_addr">DiemSystem::get_val_set_addr</a>();
<b>let</b> i = 0;
<b>while</b> (i &lt; <a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_length">Vector::length</a>&lt;<b>address</b>&gt;(&all_previous_vals)) {
<b>let</b> addr = *<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_borrow">Vector::borrow</a>(&all_previous_vals, i);
// <b>let</b> case = <a href="Cases.md#0x1_Cases_get_case">Cases::get_case</a>(vm, addr, height_start, height_now);

// TODO: <a href="Cases.md#0x1_Cases">Cases</a> will be deprecated <b>with</b> removal of Proof of Height
<b>if</b> (
// <b>if</b> they are compliant, remove the consecutive fail, otherwise jail
<a href="Audit.md#0x1_Audit_val_audit_passing">Audit::val_audit_passing</a>(addr) &&
<a href="../../../../../../../DPN/releases/artifacts/current/build/MoveStdlib/docs/Vector.md#0x1_Vector_contains">Vector::contains</a>(outgoing_compliant_set, &addr)
) {
// len_proven_nodes = len_proven_nodes + 1;
// also reset the jail counter for any successful unjails
<a href="Jail.md#0x1_Jail_remove_consecutive_fail">Jail::remove_consecutive_fail</a>(vm, addr);
} <b>else</b> {

<a href="Jail.md#0x1_Jail_jail">Jail::jail</a>(vm, addr);
};
i = i+ 1;
};
}
</code></pre>



</details>

<a name="0x1_EpochBoundary_propose_new_set"></a>
Expand Down Expand Up @@ -319,10 +366,10 @@

print(&800900105);
<a href="RecoveryMode.md#0x1_RecoveryMode_maybe_remove_debug_at_epoch">RecoveryMode::maybe_remove_debug_at_epoch</a>(vm);
// Reconfig should be the last event.
// Reconfigure the network
print(&800900106);

// Reconfig should be the last event.
// Reconfigure the network
<a href="DiemSystem.md#0x1_DiemSystem_bulk_update_validators">DiemSystem::bulk_update_validators</a>(vm, proposed_set);
print(&800900107);
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module EpochBoundary {
use DiemFramework::AutoPay;
use DiemFramework::Epoch;
use DiemFramework::DiemConfig;
// use DiemFramework::Audit;
use DiemFramework::Audit;
use DiemFramework::DiemAccount;
// use DiemFramework::Burn;
use DiemFramework::FullnodeSubsidy;
Expand All @@ -30,7 +30,7 @@ module EpochBoundary {
// use DiemFramework::StagingNet;
use DiemFramework::RecoveryMode;
// use DiemFramework::Cases;
// use DiemFramework::Jail;
use DiemFramework::Jail;
// use DiemFramework::Vouch;

//// V6 ////
Expand Down Expand Up @@ -138,27 +138,29 @@ module EpochBoundary {
Subsidy::process_fees(vm, outgoing_compliant_set);
}

// fun process_jail() {
// let i = 0;
// while (i < Vector::length<address>(&previous_set)) {
// let addr = *Vector::borrow(&previous_set, i);
// let case = Cases::get_case(vm, addr, height_start, height_now);

// if (
// // we care about nodes that are performing consensus correctly, case 1 and 2.
// case < 3 &&
// Audit::val_audit_passing(addr)
// ) {
// len_proven_nodes = len_proven_nodes + 1;
// // also reset the jail counter for any successful unjails
// Jail::remove_consecutive_fail(vm, addr);
// } else {
fun process_jail(vm: &signer, outgoing_compliant_set: &vector<address>) {
let all_previous_vals = DiemSystem::get_val_set_addr();
let i = 0;
while (i < Vector::length<address>(&all_previous_vals)) {
let addr = *Vector::borrow(&all_previous_vals, i);
// let case = Cases::get_case(vm, addr, height_start, height_now);

// TODO: Cases will be deprecated with removal of Proof of Height
if (
// if they are compliant, remove the consecutive fail, otherwise jail
Audit::val_audit_passing(addr) &&
Vector::contains(outgoing_compliant_set, &addr)
) {
// len_proven_nodes = len_proven_nodes + 1;
// also reset the jail counter for any successful unjails
Jail::remove_consecutive_fail(vm, addr);
} else {

// Jail::jail(vm, addr);
// };
// i = i+ 1;
// };
// }
Jail::jail(vm, addr);
};
i = i+ 1;
};
}

fun propose_new_set(vm: &signer, outgoing_compliant_set: &vector<address>): vector<address>
{
Expand Down Expand Up @@ -234,59 +236,12 @@ module EpochBoundary {

print(&800900105);
RecoveryMode::maybe_remove_debug_at_epoch(vm);
// Reconfig should be the last event.
// Reconfigure the network
print(&800900106);

// Reconfig should be the last event.
// Reconfigure the network
DiemSystem::bulk_update_validators(vm, proposed_set);
print(&800900107);
}

// // NOTE: this was previously in propose_new_set since it used the same loop.
// // copied implementation from Teams proposal.
// fun elect_validators(
// vm: &signer, nominal_subsidy_per: u64, proposed_set: &vector<address>
// ) {
// print(&800800100);
// CoreAddresses::assert_vm(vm);
// DiemAccount::migrate_cumu_deposits(vm); // may need to populate data on a migration.
// print(&800800101);
// Burn::reset_ratios(vm);
// print(&800800102);
// // 50% of the current per validator reward
// let burn_value = nominal_subsidy_per / 2;
// print(&800800103);
// let vals_to_burn = if (
// !Testnet::is_testnet() &&
// !StagingNet::is_staging_net() &&
// DiemConfig::get_current_epoch() > 290 &&
// // bump up to epoch 290 so people can discuss.
// // only implement this burn at a steady state with 90/100 validator
// // positions full. Will make the burn amount much smaller over time.
// Vector::length<address>(proposed_set) > 90
// ) {
// print(&800800104);
// //// V6 ////
// // CONSENSUS CRITICAL
// // pick the top N bidders in proof of fee.
// &ValidatorUniverse::get_eligible_validators()
// } else {
// print(&800800105);
// proposed_set
// };
// print(&800800106);
// print(vals_to_burn);
// let i = 0;
// while (i < Vector::length<address>(vals_to_burn)) {
// let addr = *Vector::borrow(vals_to_burn, i);
// print(&addr);
// print(&burn_value);


// Burn::epoch_start_burn(vm, addr, burn_value);
// i = i + 1;
// };
// print(&800800107);
// }
}
}
97 changes: 26 additions & 71 deletions diem-move/diem-framework/DPN/sources/0L/EpochBoundary.move
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module EpochBoundary {
use DiemFramework::AutoPay;
use DiemFramework::Epoch;
use DiemFramework::DiemConfig;
// use DiemFramework::Audit;
use DiemFramework::Audit;
use DiemFramework::DiemAccount;
// use DiemFramework::Burn;
use DiemFramework::FullnodeSubsidy;
Expand All @@ -30,7 +30,7 @@ module EpochBoundary {
// use DiemFramework::StagingNet;
use DiemFramework::RecoveryMode;
// use DiemFramework::Cases;
// use DiemFramework::Jail;
use DiemFramework::Jail;
// use DiemFramework::Vouch;

//// V6 ////
Expand Down Expand Up @@ -138,27 +138,29 @@ module EpochBoundary {
Subsidy::process_fees(vm, outgoing_compliant_set);
}

// fun process_jail() {
// let i = 0;
// while (i < Vector::length<address>(&previous_set)) {
// let addr = *Vector::borrow(&previous_set, i);
// let case = Cases::get_case(vm, addr, height_start, height_now);

// if (
// // we care about nodes that are performing consensus correctly, case 1 and 2.
// case < 3 &&
// Audit::val_audit_passing(addr)
// ) {
// len_proven_nodes = len_proven_nodes + 1;
// // also reset the jail counter for any successful unjails
// Jail::remove_consecutive_fail(vm, addr);
// } else {
fun process_jail(vm: &signer, outgoing_compliant_set: &vector<address>) {
let all_previous_vals = DiemSystem::get_val_set_addr();
let i = 0;
while (i < Vector::length<address>(&all_previous_vals)) {
let addr = *Vector::borrow(&all_previous_vals, i);
// let case = Cases::get_case(vm, addr, height_start, height_now);

// TODO: Cases will be deprecated with removal of Proof of Height
if (
// if they are compliant, remove the consecutive fail, otherwise jail
Audit::val_audit_passing(addr) &&
Vector::contains(outgoing_compliant_set, &addr)
) {
// len_proven_nodes = len_proven_nodes + 1;
// also reset the jail counter for any successful unjails
Jail::remove_consecutive_fail(vm, addr);
} else {

// Jail::jail(vm, addr);
// };
// i = i+ 1;
// };
// }
Jail::jail(vm, addr);
};
i = i+ 1;
};
}

fun propose_new_set(vm: &signer, outgoing_compliant_set: &vector<address>): vector<address>
{
Expand Down Expand Up @@ -234,59 +236,12 @@ module EpochBoundary {

print(&800900105);
RecoveryMode::maybe_remove_debug_at_epoch(vm);
// Reconfig should be the last event.
// Reconfigure the network
print(&800900106);

// Reconfig should be the last event.
// Reconfigure the network
DiemSystem::bulk_update_validators(vm, proposed_set);
print(&800900107);
}

// // NOTE: this was previously in propose_new_set since it used the same loop.
// // copied implementation from Teams proposal.
// fun elect_validators(
// vm: &signer, nominal_subsidy_per: u64, proposed_set: &vector<address>
// ) {
// print(&800800100);
// CoreAddresses::assert_vm(vm);
// DiemAccount::migrate_cumu_deposits(vm); // may need to populate data on a migration.
// print(&800800101);
// Burn::reset_ratios(vm);
// print(&800800102);
// // 50% of the current per validator reward
// let burn_value = nominal_subsidy_per / 2;
// print(&800800103);
// let vals_to_burn = if (
// !Testnet::is_testnet() &&
// !StagingNet::is_staging_net() &&
// DiemConfig::get_current_epoch() > 290 &&
// // bump up to epoch 290 so people can discuss.
// // only implement this burn at a steady state with 90/100 validator
// // positions full. Will make the burn amount much smaller over time.
// Vector::length<address>(proposed_set) > 90
// ) {
// print(&800800104);
// //// V6 ////
// // CONSENSUS CRITICAL
// // pick the top N bidders in proof of fee.
// &ValidatorUniverse::get_eligible_validators()
// } else {
// print(&800800105);
// proposed_set
// };
// print(&800800106);
// print(vals_to_burn);
// let i = 0;
// while (i < Vector::length<address>(vals_to_burn)) {
// let addr = *Vector::borrow(vals_to_burn, i);
// print(&addr);
// print(&burn_value);


// Burn::epoch_start_burn(vm, addr, burn_value);
// i = i + 1;
// };
// print(&800800107);
// }
}
}

0 comments on commit 6990356

Please sign in to comment.