From dc610c24b56cb137ffcbdd63a5336e742e899429 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Sat, 23 Mar 2024 22:17:37 +0000 Subject: [PATCH 1/2] scaffold tower game over --- .../sources/ol_sources/tower_state.move | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/framework/libra-framework/sources/ol_sources/tower_state.move b/framework/libra-framework/sources/ol_sources/tower_state.move index 63675be46..513781cc5 100644 --- a/framework/libra-framework/sources/ol_sources/tower_state.move +++ b/framework/libra-framework/sources/ol_sources/tower_state.move @@ -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; @@ -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 @@ -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 @@ -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(framework_sig, TowerGameOver {}); + } + + #[view] + public fun is_game_over():bool { + exists(@ol_framework) + } + // Create the difficulty struct public(friend) fun init_difficulty(vm: &signer) { system_addresses::assert_ol(vm); @@ -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); @@ -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, From 4a579571fac0068a43e8201c2002b83400a16e98 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Sat, 23 Mar 2024 22:47:35 +0000 Subject: [PATCH 2/2] add test for sunset --- .../sources/ol_sources/oracle.move | 6 +-- .../sources/ol_sources/tests/tower.test.move | 46 +++++++++++++++---- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/framework/libra-framework/sources/ol_sources/oracle.move b/framework/libra-framework/sources/ol_sources/oracle.move index 1ee6a2f2f..b9bacf8b6 100644 --- a/framework/libra-framework/sources/ol_sources/oracle.move +++ b/framework/libra-framework/sources/ol_sources/oracle.move @@ -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; @@ -187,9 +185,9 @@ module ol_framework::oracle { fun increment_stats(provider_addr: address, tower: &mut Tower, time: u64, signature_bytes: vector) acquires GlobalCounter, ProviderList { - // update the global state + // update the global state let global = borrow_global_mut(@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; diff --git a/framework/libra-framework/sources/ol_sources/tests/tower.test.move b/framework/libra-framework/sources/ol_sources/tests/tower.test.move index 66b011a5a..8ac32ba9c 100644 --- a/framework/libra-framework/sources/ol_sources/tests/tower.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/tower.test.move @@ -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 @@ -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)); @@ -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 @@ -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 @@ -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); @@ -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(), + ); + } }