-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move] Recovery mode for epoch boundary (#1090)
* refactor DebugMode into Recovery Mode. Prevent payments until recovery is complete * set epoch explicitly * add tests for recovery mode * Squashed commit of the following: commit 9114a6ce380248b1f666d782d8e50add7e2f8795 Author: 0o-de-lally <[email protected]> Date: Sun Apr 24 13:52:04 2022 -0400 include more vouch tests commit 074e222 Author: 0o-de-lally <[email protected]> Date: Sun Apr 24 10:43:29 2022 -0400 Vouch tx (#1088) * vouch tx scaffold * patch * cli for vouch * cargo fix * rename script * stdlib build * No longer check for Autopay in Audit. Remove deprecated tests * drawks thinks my commit history is sloppy :). This commit is a patch on a failing functional test for epoch boundary validator audit checking. * in recovery mode make the fixed validator set case expire after # epochs * patch integration test for test-autopay grep, to use updated values from the proof of burn patches
- Loading branch information
1 parent
c8fadfc
commit bd62f62
Showing
17 changed files
with
866 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/////////////////////////////////////////////////////////////////////////// | ||
// 0L Module | ||
// Recovery Mode | ||
/////////////////////////////////////////////////////////////////////////// | ||
// For when an admin upgrade or network halt recovery needs to be exectuted. | ||
// For use for example in preventing front running by miners and validators | ||
// for rewards while the network is unstable. | ||
/////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
|
||
address 0x1 { | ||
module RecoveryMode { | ||
|
||
use 0x1::CoreAddresses; | ||
use 0x1::DiemConfig; | ||
use 0x1::DiemSystem; | ||
use 0x1::Vector; | ||
use 0x1::Testnet; | ||
use 0x1::StagingNet; | ||
|
||
struct RecoveryMode has copy, key, drop, store{ | ||
// set this if a validator set needs to be overriden | ||
// if list is empty, it will use validator set. | ||
fixed_set: vector<address>, | ||
epoch_ends: u64, | ||
} | ||
|
||
// private function so that it can only be called by vm session. | ||
// should never be used in production. | ||
fun init_recovery(vm: &signer, vals: vector<address>, epoch_ends: u64) { | ||
if (!is_recovery()) { | ||
move_to<RecoveryMode>(vm, RecoveryMode { | ||
fixed_set: vals, | ||
epoch_ends, | ||
}); | ||
} | ||
} | ||
|
||
public fun maybe_remove_debug_at_epoch(vm: &signer) acquires RecoveryMode { | ||
CoreAddresses::assert_vm(vm); | ||
if (!exists<RecoveryMode>(CoreAddresses::VM_RESERVED_ADDRESS())) return; | ||
|
||
let enough_vals = if ( | ||
Testnet::is_testnet() || | ||
StagingNet::is_staging_net() | ||
){ true } | ||
else { (DiemSystem::validator_set_size() >= 21) }; | ||
let d = borrow_global<RecoveryMode>(CoreAddresses::VM_RESERVED_ADDRESS()); | ||
|
||
let enough_epochs = DiemConfig::get_current_epoch() >= d.epoch_ends; | ||
|
||
|
||
// In the case that we set a fixed group of validators. Make it expire after enough time has passed. | ||
if (enough_epochs) { | ||
if (Vector::length(&d.fixed_set) > 0) { | ||
remove_debug(vm); | ||
} else { | ||
// Otherwise, we are keeping the same validator selection logic. | ||
// In that case the system needs to pick enough validators for this to disable. | ||
if (enough_vals){ | ||
remove_debug(vm); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
fun remove_debug(vm: &signer) acquires RecoveryMode { | ||
CoreAddresses::assert_vm(vm); | ||
if (is_recovery()) { | ||
_ = move_from<RecoveryMode>(CoreAddresses::VM_RESERVED_ADDRESS()); | ||
} | ||
} | ||
|
||
public fun is_recovery(): bool { | ||
exists<RecoveryMode>(CoreAddresses::VM_RESERVED_ADDRESS()) | ||
} | ||
|
||
public fun get_debug_vals(): vector<address> acquires RecoveryMode { | ||
if (is_recovery()) { | ||
let d = borrow_global<RecoveryMode>(CoreAddresses::VM_RESERVED_ADDRESS()); | ||
*&d.fixed_set | ||
} else { | ||
Vector::empty<address>() | ||
} | ||
} | ||
|
||
|
||
/////////////// TEST HELPERS /////////////////// | ||
|
||
public fun test_init_recovery(vm: &signer, vals: vector<address>, epoch_ends: u64) { | ||
CoreAddresses::assert_vm(vm); | ||
if (Testnet::is_testnet()) { | ||
init_recovery(vm, vals, epoch_ends); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.