Skip to content

Commit

Permalink
[tower] tower sunset (0LNetworkCommunity#214)
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com>
  • Loading branch information
0xzoz and 0o-de-lally committed Mar 24, 2024
1 parent 0cc99be commit 18cc612
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
6 changes: 2 additions & 4 deletions framework/libra-framework/sources/ol_sources/oracle.move
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ module ol_framework::oracle {
use ol_framework::epoch_helper;
use std::error;

// use diem_std::debug::print;
friend diem_framework::genesis;

friend ol_framework::epoch_boundary;
friend ol_framework::tower_state;

Expand Down Expand Up @@ -187,9 +185,9 @@ module ol_framework::oracle {

fun increment_stats(provider_addr: address, tower: &mut Tower, time: u64, signature_bytes: vector<u8>) acquires GlobalCounter, ProviderList {

// update the global state
// update the global state
let global = borrow_global_mut<GlobalCounter>(@ol_framework);
// is this a proof in a new epoch?
// is this a proof in a new epoch?
let current_epoch = epoch_helper::get_current_epoch();

// if this is the first proof this epoch;
Expand Down
46 changes: 37 additions & 9 deletions framework/libra-framework/sources/ol_sources/tests/tower.test.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ module ol_framework::test_tower {
use diem_framework::timestamp;
use std::vector;
use ol_framework::oracle;

// use std::debug::print;

#[test(root = @ol_framework)]
fun epoch_changes_difficulty(root: signer) {
mock::genesis_n_vals(&root, 4);
// mock::ol_initialize_coin(&root);

mock::tower_default(&root); // make all the validators initialize towers
// because we need randomness for the toy rng

Expand All @@ -40,7 +37,6 @@ module ol_framework::test_tower {
#[test(root = @ol_framework, cousin_alice = @0x87515d94a244235a1433d7117bc0cb154c613c2f4b1e67ca8d98a542ee3f59f5)]
fun init_tower_state(root: signer, cousin_alice: signer){
mock::ol_test_genesis(&root);
// mock::ol_initialize_coin(&root);
timestamp::fast_forward_seconds(1);
ol_account::create_account(&root, signer::address_of(&cousin_alice));

Expand All @@ -58,7 +54,6 @@ module ol_framework::test_tower {
#[test(root = @ol_framework)]
fun toy_rng_state(root: signer) {
mock::genesis_n_vals(&root, 4);
// mock::ol_initialize_coin(&root);

mock::tower_default(&root); // make all the validators initialize towers
// because we need randomness for the toy rng
Expand All @@ -71,9 +66,7 @@ module ol_framework::test_tower {

#[test(root = @ol_framework)]
fun toy_rng_minimal(root: signer) {
// use diem_std::debug::print;
mock::genesis_n_vals(&root, 1);
// mock::ol_initialize_coin(&root);

mock::tower_default(&root); // make all the validators initialize towers
// because we need randomness for the toy rng
Expand All @@ -88,7 +81,7 @@ module ol_framework::test_tower {
fun miner_receives_reward(root: signer, cousin_alice: signer) {
let a_addr = signer::address_of(&cousin_alice);
let vals = mock::genesis_n_vals(&root, 5);
// mock::ol_initialize_coin(&root);

mock::pof_default();
ol_account::create_account(&root, a_addr);
proof_of_fee::fill_seats_and_get_price(&root, 5, &vals, &vals);
Expand Down Expand Up @@ -156,7 +149,42 @@ module ol_framework::test_tower {

let count_post_reset = oracle::get_exact_count(a_addr);
assert!(count_post_reset==1, 7347004);

}

#[test(root = @ol_framework, cousin_alice =
@0x87515d94a244235a1433d7117bc0cb154c613c2f4b1e67ca8d98a542ee3f59f5)]
#[expected_failure(abort_code = 196618, location = ol_framework::tower_state)]
fun test_sunset(root: signer, cousin_alice: signer) {
let a_addr = signer::address_of(&cousin_alice);
let _vals = mock::genesis_n_vals(&root, 5);

ol_account::create_account(&root, a_addr);
tower_state::minerstate_commit(
&cousin_alice,
vdf_fixtures::alice_0_easy_chal(),
vdf_fixtures::alice_0_easy_sol(),
vdf_fixtures::easy_difficulty(),
vdf_fixtures::security(),
);

timestamp::fast_forward_seconds(10);
tower_state::minerstate_commit(
&cousin_alice,
vdf_fixtures::alice_1_easy_chal(),
vdf_fixtures::alice_1_easy_sol(),
vdf_fixtures::easy_difficulty(),
vdf_fixtures::security(),
);


tower_state::tower_sunset(&root);

tower_state::minerstate_commit(
&cousin_alice,
vdf_fixtures::alice_1_easy_chal(),
vdf_fixtures::alice_1_easy_sol(),
vdf_fixtures::easy_difficulty(),
vdf_fixtures::security(),
);
}
}
34 changes: 34 additions & 0 deletions framework/libra-framework/sources/ol_sources/tower_state.move
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
///////////////////////////////////////////////////////////////////
// DEPRECATION NOTICE
// this module's funtions will be removed shortly after the Tower Sunset
///////////////////////////////////////////////////////////////////
module ol_framework::tower_state {
use std::error;
use std::signer;
Expand Down Expand Up @@ -33,6 +36,9 @@ module ol_framework::tower_state {
const EALREADY_INITIALIZED: u64 = 8;
/// Not testnet
const ENOT_TESTNET: u64 = 9;
/// Tower game is over. All coins were mined, and every last coin has been
/// mined. Thank you Tower!
const ETOWER_GAME_OVER: u64 = 10;

/// A list of all miners' addresses
// reset at epoch boundary
Expand All @@ -46,6 +52,20 @@ module ol_framework::tower_state {
miners_above_thresh: u64,
}

// Thank you Tower, we wouldn't be here without you
struct TowerGameOver has key {
// Now it's time to say good night
// Good night sleep tight
// Now the sun turns out his light
// Good night sleep tight
// Dream sweet dreams for me (dream sweet)
// Dream sweet dreams for you

// Close your eyes and I'll close mine
// Good night sleep tight
// Now the moon begins to shine
}


/// Struct to store information about a VDF proof submitted
/// `challenge`: the seed for the proof
Expand Down Expand Up @@ -100,6 +120,17 @@ module ol_framework::tower_state {
init_miner_list(root);
init_tower_counter(root, 0);
}

/// Sunsets the tower game
public fun tower_sunset(framework_sig: &signer) {
move_to<TowerGameOver>(framework_sig, TowerGameOver {});
}

#[view]
public fun is_game_over():bool {
exists<TowerGameOver>(@ol_framework)
}

// Create the difficulty struct
public(friend) fun init_difficulty(vm: &signer) {
system_addresses::assert_ol(vm);
Expand Down Expand Up @@ -205,6 +236,7 @@ module ol_framework::tower_state {
miner_sign: &signer,
proof: Proof
) acquires TowerProofHistory, TowerList, TowerCounter {
assert!(!is_game_over(), error::invalid_state(ETOWER_GAME_OVER));
// Get address, assumes the sender is the signer.
let miner_addr = signer::address_of(miner_sign);
oracle::init_provider(miner_sign);
Expand Down Expand Up @@ -237,6 +269,8 @@ module ol_framework::tower_state {
difficulty: u64,
security: u64,
) acquires TowerCounter, TowerList, TowerProofHistory {
assert!(!is_game_over(), error::invalid_state(ETOWER_GAME_OVER));

let proof = create_proof_blob(
challenge,
solution,
Expand Down

0 comments on commit 18cc612

Please sign in to comment.