Skip to content

Commit

Permalink
[Move] Epoch scheduler (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally authored Feb 3, 2024
1 parent 3640091 commit 999a493
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
1 change: 0 additions & 1 deletion framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module diem_framework::block {
use std::error;
use std::vector;
use std::option;

use diem_framework::account;
use diem_framework::event::{Self, EventHandle};
use diem_framework::reconfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ module diem_framework::genesis {
safe::initialize(&diem_framework_account);
donor_voice::initialize(&diem_framework_account);
epoch_helper::initialize(&diem_framework_account);
epoch_boundary::initialize(&diem_framework_account);
burn::initialize(&diem_framework_account);
match_index::initialize(&diem_framework_account);
fee_maker::initialize(&diem_framework_account);
Expand All @@ -161,6 +160,7 @@ module diem_framework::genesis {
// since the infra_escrow requires a VM signature, we need to initialized it as 0x0 and not 0x1, as the others.
let vm_sig = create_signer(@vm_reserved);
infra_escrow::initialize(&vm_sig);
epoch_boundary::initialize(&vm_sig, &diem_framework_account);


// end 0L
Expand Down
31 changes: 17 additions & 14 deletions framework/libra-framework/sources/ol_sources/epoch_boundary.move
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ module diem_framework::epoch_boundary {
use diem_framework::coin::{Self, Coin};
use std::vector;
use std::error;
use std::signer;
use std::string;


use diem_std::debug::print;

friend diem_framework::diem_governance;
Expand Down Expand Up @@ -116,16 +114,17 @@ module diem_framework::epoch_boundary {
pof_thermo_amount: u64,
}

public fun initialize(framework: &signer) {
let addr = signer::address_of(framework);
if (addr != @ol_framework) return; // don't throw error.

/// initialize structs, requires both signers since BoundaryBit can only be
// accessed by VM
public fun initialize(vm_signer: &signer, framework_signer: &signer) {
system_addresses::assert_vm(vm_signer);
if (!exists<BoundaryStatus>(@ol_framework)){
move_to(framework, reset());
move_to(framework_signer, reset());
};

if (!exists<BoundaryBit>(@ol_framework)) {
move_to(framework, BoundaryBit {
// boundary bit can only be written by VM
if (!exists<BoundaryBit>(@vm_reserved)) {
move_to(vm_signer, BoundaryBit {
ready: false,
closing_epoch: 0,
});
Expand Down Expand Up @@ -195,13 +194,17 @@ module diem_framework::epoch_boundary {
public(friend) fun enable_epoch_trigger(vm_signer: &signer, closing_epoch:
u64) acquires BoundaryBit {

if (!exists<BoundaryBit>(@ol_framework)) {
if (!exists<BoundaryBit>(@vm_reserved)) {
// Just like a prayer, your voice can take me there
// Just like a muse to me, you are a mystery
// Just like a dream, you are not what you seem
// Just like a prayer, no choice your voice can take me there...
move_to(vm_signer, BoundaryBit {
closing_epoch: closing_epoch,
ready: true,
})
} else {
let state = borrow_global_mut<BoundaryBit>(@ol_framework);
let state = borrow_global_mut<BoundaryBit>(@vm_reserved);
state.closing_epoch = closing_epoch;
state.ready = true;
}
Expand All @@ -220,7 +223,7 @@ module diem_framework::epoch_boundary {
let _ = can_trigger(); // will abort if false

// update the state and flip the Bit
let state = borrow_global_mut<BoundaryBit>(@ol_framework);
let state = borrow_global_mut<BoundaryBit>(@vm_reserved);
state.ready = false;

epoch_boundary(root, state.closing_epoch, 0);
Expand All @@ -229,7 +232,7 @@ module diem_framework::epoch_boundary {
#[view]
/// check to see if the epoch Boundary Bit is true
public fun can_trigger(): bool acquires BoundaryBit {
let state = borrow_global_mut<BoundaryBit>(@ol_framework);
let state = borrow_global_mut<BoundaryBit>(@vm_reserved);
assert!(state.ready, ETRIGGER_NOT_READY);
assert!(state.closing_epoch == reconfiguration::get_current_epoch(),
ENOT_SAME_EPOCH);
Expand All @@ -248,8 +251,8 @@ module diem_framework::epoch_boundary {

print(&string::utf8(b"status reset"));
*status = reset();
// bill root service fees;

// bill root service fees;
print(&string::utf8(b"root_service_billing"));
root_service_billing(root, status);

Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.

0 comments on commit 999a493

Please sign in to comment.