From 0b2f2901616bdf243151367d8e31f966d0280c1f Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Thu, 9 Dec 2021 16:35:21 -0500 Subject: [PATCH] Epochs validating and mining metrics fix (#880) * create reproduction of Case 3 validators incorrectly getting epochs_validating_and_mining incremented. * refactor tower update metrics, tests not passing * lazy reset of counters happens at verify stage of towerstate. * functional test for lazy miner state reset * adjust TowerStateResource view to include actual_count_proofs_in_epoch * change json-rpc method for getting miner state. --- json-rpc/src/data.rs | 5 +- json-rpc/src/methods.rs | 2 +- json-rpc/types/src/views.rs | 55 +++++- .../{Reconfigure.move => EpochBoundary.move} | 15 +- .../diem-framework/modules/0L/Globals.move | 4 +- .../diem-framework/modules/0L/TowerState.move | 138 +++++++------- .../ol_miner_state.move | 2 +- .../tests/0L/cases/case_1_reconfig.move | 15 +- .../tests/0L/cases/case_2_reconfig.move | 6 +- .../tests/0L/cases/case_3_reconfig.move | 28 +-- .../tests/0L/cases/case_3_unit.move | 2 + .../fullnode_subsidy/fullnode_reconfig.move | 6 +- .../fullnode_reconfig_two.move | 8 +- .../0L/tower_state/_meta_mock_mining.move | 2 +- .../tower_state/_meta_wrap_commit_state.move | 2 +- .../0L/tower_state/chained_proof_fail.move | 2 +- .../chained_proof_success_easy.move | 2 +- .../chained_proof_success_hard.move | 2 +- .../0L/tower_state/init_miner_state.move | 16 +- .../0L/tower_state/lazy_reset_count.move | 172 ++++++++++++++++++ ...miners_dont_increment_compliant_count.move | 70 +++++++ .../0L/tower_state/prevent_duplicates.move | 2 +- .../update_metrics_above_thresh.move | 2 +- .../update_metrics_below_thresh.move | 6 +- .../trusted_initialized_from_genesis.depr | 24 --- .../trusted_update_accounts.depr | 34 ---- ol/cli/src/node/chain_view.rs | 1 + ol/genesis-tools/src/fork_genesis.rs | 10 - 28 files changed, 443 insertions(+), 190 deletions(-) rename language/diem-framework/modules/0L/{Reconfigure.move => EpochBoundary.move} (92%) create mode 100644 language/move-lang/functional-tests/tests/0L/tower_state/lazy_reset_count.move create mode 100644 language/move-lang/functional-tests/tests/0L/tower_state/miners_dont_increment_compliant_count.move delete mode 100644 language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_initialized_from_genesis.depr delete mode 100644 language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_update_accounts.depr diff --git a/json-rpc/src/data.rs b/json-rpc/src/data.rs index 98389868ad..2f8843b5bb 100644 --- a/json-rpc/src/data.rs +++ b/json-rpc/src/data.rs @@ -295,10 +295,11 @@ pub fn get_miner_state( db: &dyn DbReader, version: u64, account: AccountAddress, - // ledger_info: &LedgerInfoWithSignatures, + ledger_info: &LedgerInfoWithSignatures, ) -> Result { + let epoch = ledger_info.ledger_info().epoch(); match get_account_state(db, account, version)? { - Some(s) => TowerStateResourceView::try_from(s).map_err(Into::into), + Some(s) => TowerStateResourceView::from_state_and_epoch(s, epoch).map_err(Into::into), None => Err(JsonRpcError::internal_error("No account state found".to_owned())), } diff --git a/json-rpc/src/methods.rs b/json-rpc/src/methods.rs index a43c08ee4e..094f043890 100644 --- a/json-rpc/src/methods.rs +++ b/json-rpc/src/methods.rs @@ -381,7 +381,7 @@ impl<'a> Handler<'a> { &self, params: GetTowerStateParams, ) -> Result { - data::get_miner_state(self.service.db.borrow(), self.version(), params.account) + data::get_miner_state(self.service.db.borrow(), self.version(), params.account, &self.ledger_info) } async fn get_oracle_upgrade_state( diff --git a/json-rpc/types/src/views.rs b/json-rpc/types/src/views.rs index ebf90a0671..7352bada84 100644 --- a/json-rpc/types/src/views.rs +++ b/json-rpc/types/src/views.rs @@ -1442,14 +1442,21 @@ pub struct TowerStateResourceView { pub count_proofs_in_epoch: u64, pub epochs_validating_and_mining: u64, pub contiguous_epochs_validating_and_mining: u64, - pub epochs_since_last_account_creation: u64 + pub epochs_since_last_account_creation: u64, + // ADDED FIELDS FROM ORIGINAL MOVE STRUCT + // the actual count of proofs in epoch considering the lazy computation + pub actual_count_proofs_in_epoch: u64 } -impl TryFrom for TowerStateResourceView { - type Error = Error; +impl TowerStateResourceView { + pub fn from_state_and_epoch(state: AccountState, this_epoch: u64) -> Result { - fn try_from(state: AccountState) -> Result { + let mut actual_count_proofs_in_epoch = 0; if let Some(m) = state.get_miner_state()? { + if m.latest_epoch_mining == this_epoch { + actual_count_proofs_in_epoch = m.count_proofs_in_epoch; + } + Ok(TowerStateResourceView { previous_proof_hash: BytesView::from( m.previous_proof_hash), verified_tower_height: m.verified_tower_height, // user's latest verified_tower_height @@ -1457,13 +1464,47 @@ impl TryFrom for TowerStateResourceView { count_proofs_in_epoch: m.count_proofs_in_epoch, epochs_validating_and_mining: m.epochs_validating_and_mining, contiguous_epochs_validating_and_mining: m.contiguous_epochs_validating_and_mining, - epochs_since_last_account_creation: m.epochs_since_last_account_creation + epochs_since_last_account_creation: m.epochs_since_last_account_creation, + // the proof count adjusted for lazy computation + actual_count_proofs_in_epoch, }) } else { bail!("could not get tower state") } - } -} + } +} + +// impl TryFrom for TowerStateResourceView { +// type Error = Error; + +// fn try_from(state: AccountState) -> Result { +// let this_epoch = match state.get_configuration_resource()?{ +// Some(cr) => cr.epoch(), +// None => bail!("cannot get epoch data from account state"), +// }; + +// let mut actual_count_proofs_in_epoch = 0; +// if let Some(m) = state.get_miner_state()? { +// if m.latest_epoch_mining == this_epoch { +// actual_count_proofs_in_epoch = m.count_proofs_in_epoch; +// } + +// Ok(TowerStateResourceView { +// previous_proof_hash: BytesView::from( m.previous_proof_hash), +// verified_tower_height: m.verified_tower_height, // user's latest verified_tower_height +// latest_epoch_mining: m.latest_epoch_mining, +// count_proofs_in_epoch: m.count_proofs_in_epoch, +// epochs_validating_and_mining: m.epochs_validating_and_mining, +// contiguous_epochs_validating_and_mining: m.contiguous_epochs_validating_and_mining, +// epochs_since_last_account_creation: m.epochs_since_last_account_creation, +// // the proof count adjusted for lazy computation +// actual_count_proofs_in_epoch, +// }) +// } else { +// bail!("could not get tower state") +// } +// } +// } //////// 0L //////// #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] diff --git a/language/diem-framework/modules/0L/Reconfigure.move b/language/diem-framework/modules/0L/EpochBoundary.move similarity index 92% rename from language/diem-framework/modules/0L/Reconfigure.move rename to language/diem-framework/modules/0L/EpochBoundary.move index e307538a40..db5489ccad 100644 --- a/language/diem-framework/modules/0L/Reconfigure.move +++ b/language/diem-framework/modules/0L/EpochBoundary.move @@ -8,7 +8,7 @@ address 0x1 { -module EpochBoundary { // TODO: Rename to Boundary +module EpochBoundary { use 0x1::CoreAddresses; use 0x1::Subsidy; use 0x1::NodeWeight; @@ -17,7 +17,6 @@ module EpochBoundary { // TODO: Rename to Boundary use 0x1::Globals; use 0x1::Vector; use 0x1::Stats; - use 0x1::ValidatorUniverse; use 0x1::AutoPay; use 0x1::Epoch; use 0x1::DiemConfig; @@ -43,7 +42,7 @@ module EpochBoundary { // TODO: Rename to Boundary process_fullnodes(vm, nominal_subsidy_per); - process_validators(vm, subsidy_units, outgoing_compliant_set); + process_validators(vm, subsidy_units, *&outgoing_compliant_set); let proposed_set = propose_new_set(vm, height_start, height_now); @@ -52,7 +51,7 @@ module EpochBoundary { // TODO: Rename to Boundary DiemAccount::slow_wallet_epoch_drip(vm, Globals::get_unlock()); // update_validator_withdrawal_limit(vm); }; - reset_counters(vm, proposed_set, height_now) + reset_counters(vm, proposed_set, outgoing_compliant_set, height_now) } // process fullnode subsidy @@ -157,15 +156,13 @@ module EpochBoundary { // TODO: Rename to Boundary proposed_set } - fun reset_counters(vm: &signer, proposed_set: vector
, height_now: u64) { + fun reset_counters(vm: &signer, proposed_set: vector
, outgoing_compliant: vector
, height_now: u64) { // Reset Stats Stats::reconfig(vm, &proposed_set); - // Migrate TowerState list from elegible: in case there is no minerlist - // struct, use eligible for migrate_eligible_validators - let eligible = ValidatorUniverse::get_eligible_validators(vm); - TowerState::reconfig(vm, &eligible); + // Migrate TowerState list from elegible. + TowerState::reconfig(vm, &outgoing_compliant); // Reconfigure the network DiemSystem::bulk_update_validators(vm, proposed_set); diff --git a/language/diem-framework/modules/0L/Globals.move b/language/diem-framework/modules/0L/Globals.move index 45e121a87f..2745c2d1ea 100644 --- a/language/diem-framework/modules/0L/Globals.move +++ b/language/diem-framework/modules/0L/Globals.move @@ -93,7 +93,7 @@ module Globals { max_validators_per_set: 100, subsidy_ceiling_gas: 296 * COIN_SCALING_FACTOR, vdf_difficulty: 100, - epoch_mining_thres_lower: 1, + epoch_mining_thres_lower: 2, // Note: in test harness, the validators are in epoch 0 where they have 1 proof already committed from mock genesis ceremony. epoch_mining_thres_upper: 1000, // upper bound unlimited epoch_slow_wallet_unlock: 10, } @@ -105,7 +105,7 @@ module Globals { max_validators_per_set: 100, subsidy_ceiling_gas: 8640000 * COIN_SCALING_FACTOR, vdf_difficulty: 120000000, - epoch_mining_thres_lower: 1, + epoch_mining_thres_lower: 1, // in testnet, staging, we don't want to wait too long between proofs. epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof. epoch_slow_wallet_unlock: 10000000, } diff --git a/language/diem-framework/modules/0L/TowerState.move b/language/diem-framework/modules/0L/TowerState.move index 2526c38216..8a68f25667 100644 --- a/language/diem-framework/modules/0L/TowerState.move +++ b/language/diem-framework/modules/0L/TowerState.move @@ -5,8 +5,7 @@ /////////////////////////////////////////////////////////////////// address 0x1 { -/// # Summary -/// TODO + module TowerState { use 0x1::Errors; use 0x1::CoreAddresses; @@ -48,15 +47,6 @@ module TowerState { state.proofs_in_epoch = state.proofs_in_epoch + 1; } - // Note: Used only in tests - public fun epoch_reset(vm: &signer) acquires TowerStats { - CoreAddresses::assert_vm(vm); - let state = borrow_global_mut(CoreAddresses::VM_RESERVED_ADDRESS()); - state.proofs_in_epoch = 0; - state.validator_proofs = 0; - state.fullnode_proofs = 0; - } - public fun get_fullnode_proofs(): u64 acquires TowerStats{ let state = borrow_global(CoreAddresses::VM_RESERVED_ADDRESS()); state.fullnode_proofs @@ -131,9 +121,10 @@ module TowerState { /// is onboarding public fun is_onboarding(addr: address): bool acquires TowerProofHistory { + let count = get_count_in_epoch(addr); let state = borrow_global(addr); - state.count_proofs_in_epoch < 2 && + count < 2 && state.epochs_since_last_account_creation < 2 } @@ -180,7 +171,6 @@ module TowerState { // In rust the vm_genesis creates a Signer for the miner. // So the SENDER is not the same and the Signer. - init_miner_state(miner_sig, &challenge, &solution, difficulty, security); // TODO: Move this elsewhere? // Initialize stats for first validator set from rust genesis. @@ -215,7 +205,6 @@ module TowerState { return }; - // Process the proof verify_and_update_state(miner_addr, proof, true); } @@ -234,11 +223,10 @@ module TowerState { // Get address, assumes the sender is the signer. assert(ValidatorConfig::get_operator(miner_addr) == Signer::address_of(operator_sig), Errors::requires_role(130103)); - // Abort if not initialized. Assumes the validator Owner account already has submitted the 0th miner proof in onboarding. assert(exists(miner_addr), Errors::not_published(130104)); - // return early if difficulty and security are not correct. + // Return early if difficulty and security are not correct. // Check vdf difficulty constant. Will be different in tests than in production. // Skip this check on local tests, we need tests to send differentdifficulties. if (!Testnet::is_testnet()){ @@ -264,13 +252,16 @@ module TowerState { proof: Proof, steady_state: bool ) acquires TowerProofHistory, TowerList, TowerStats { + // instead of looping through all miners at end of epcoh the stats are only reset when the miner submits a new proof. + lazy_reset_count_in_epoch(miner_addr); - let miner_history = borrow_global(miner_addr); assert( - miner_history.count_proofs_in_epoch < Globals::get_epoch_mining_thres_upper(), + get_count_in_epoch(miner_addr) < Globals::get_epoch_mining_thres_upper(), Errors::invalid_state(130108) ); + let miner_history = borrow_global(miner_addr); + // If not genesis proof, check hash to ensure the proof continues the chain if (steady_state) { //If not genesis proof, check hash @@ -310,7 +301,7 @@ module TowerState { // So the function presumes the validator is in good standing for that epoch. // Permissions: private function // Function index: 04 - fun update_metrics(account: &signer, miner_addr: address) acquires TowerProofHistory { + fun update_epoch_metrics_vals(account: &signer, miner_addr: address) acquires TowerProofHistory { // The goal of update_metrics is to confirm that a miner participated in consensus during // an epoch, but also that there were mining proofs submitted in that epoch. CoreAddresses::assert_diem_root(account); @@ -324,11 +315,10 @@ module TowerState { // the resource was last emptied. let passed = node_above_thresh(miner_addr); let miner_history = borrow_global_mut(miner_addr); - // Update statistics. if (passed) { - let this_epoch = DiemConfig::get_current_epoch(); - miner_history.latest_epoch_mining = this_epoch; + // let this_epoch = DiemConfig::get_current_epoch(); + // miner_history.latest_epoch_mining = this_epoch; // TODO: Don't need this miner_history.epochs_validating_and_mining = miner_history.epochs_validating_and_mining + 1u64; miner_history.contiguous_epochs_validating_and_mining @@ -346,44 +336,35 @@ module TowerState { /// Checks to see if miner submitted enough proofs to be considered compliant public fun node_above_thresh(miner_addr: address): bool acquires TowerProofHistory { - let miner_history = borrow_global(miner_addr); - miner_history.count_proofs_in_epoch > Globals::get_epoch_mining_thres_lower() + get_count_in_epoch(miner_addr) >= Globals::get_epoch_mining_thres_lower() } - // Used at end of epoch with reconfig bulk_update the TowerState with the vector of validators from current epoch. + // Used at epoch boundary by vm to reset all validator's statistics. // Permissions: PUBLIC, ONLY VM. - public fun reconfig(vm: &signer, migrate_eligible_validators: &vector
) acquires TowerProofHistory, TowerList { + public fun reconfig(vm: &signer, outgoing_validators: &vector
) acquires TowerProofHistory, TowerList { + // Check permissions CoreAddresses::assert_diem_root(vm); - // check TowerList exists, or use eligible_validators to initialize. - // Migration on hot upgrade - if (!exists(@0x0)) { - move_to(vm, TowerList { - list: *migrate_eligible_validators - }); - }; - - let towerlist_state = borrow_global_mut(@0x0); - - // Get list of validators from ValidatorUniverse - // let eligible_validators = ValidatorUniverse::get_eligible_validators(vm); - // Iterate through validators and call update_metrics for each validator that had proofs this epoch - let size = Vector::length
(& *&towerlist_state.list); //TODO: These references are weird + let vals_len = Vector::length
(outgoing_validators); //TODO: These references are weird let i = 0; - while (i < size) { - let val = Vector::borrow(&towerlist_state.list, i); + while (i < vals_len) { + let val = Vector::borrow(outgoing_validators, i); // For testing: don't call update_metrics unless there is account state for the address. if (exists(*val)){ - update_metrics(vm, *val); + update_epoch_metrics_vals(vm, *val); }; i = i + 1; }; - //reset miner list - towerlist_state.list = Vector::empty
(); + // safety + if (exists(@0x0)) { + //reset miner list + let towerlist_state = borrow_global_mut(@0x0); + towerlist_state.list = Vector::empty
(); + }; } // Function to initialize miner state @@ -420,7 +401,6 @@ module TowerState { security, }; - //submit the proof verify_and_update_state(Signer::address_of(miner_sig), proof, false); } @@ -450,8 +430,7 @@ module TowerState { // Get latest epoch mined by node on given address // Permissions: public ony VM can call this function. // Function code: 09 - public fun get_miner_latest_epoch(vm: &signer, addr: address): u64 acquires TowerProofHistory { - CoreAddresses::assert_diem_root(vm); + public fun get_miner_latest_epoch(addr: address): u64 acquires TowerProofHistory { let addr_state = borrow_global(addr); *&addr_state.latest_epoch_mining } @@ -464,8 +443,6 @@ module TowerState { state.epochs_since_last_account_creation = 0; } - - ////////////////////// /// Public Getters /// ///////////////////// @@ -493,7 +470,7 @@ module TowerState { // Returns number of epochs user successfully mined AND validated // Permissions: PUBLIC, ANYONE // TODO: Rename - public fun get_epochs_mining(node_addr: address): u64 acquires TowerProofHistory { + public fun get_epochs_compliant(node_addr: address): u64 acquires TowerProofHistory { if (exists(node_addr)) { return borrow_global(node_addr).epochs_validating_and_mining }; @@ -503,11 +480,23 @@ module TowerState { // returns the number of proofs for a miner in the current epoch public fun get_count_in_epoch(miner_addr: address): u64 acquires TowerProofHistory { if (exists(miner_addr)) { - return borrow_global(miner_addr).count_proofs_in_epoch + let s = borrow_global(miner_addr); + if (s.latest_epoch_mining == DiemConfig::get_current_epoch()) { + return s.count_proofs_in_epoch + }; }; 0 } + // lazily reset proofs_in_epoch intead of looping through list. + // danger: this is a private function. Do not make public. + fun lazy_reset_count_in_epoch(miner_addr: address) acquires TowerProofHistory { + let s = borrow_global_mut(miner_addr); + if (s.latest_epoch_mining < DiemConfig::get_current_epoch()) { + s.count_proofs_in_epoch = 0; + }; + } + // Returns if the miner is above the account creation rate-limit // Permissions: PUBLIC, ANYONE public fun can_create_val_account(node_addr: address): bool acquires TowerProofHistory { @@ -528,7 +517,7 @@ module TowerState { // Initiates a miner for a testnet // Function index: 10 // Permissions: PUBLIC, SIGNER, TEST ONLY - public fun test_helper_init_miner( + public fun test_helper_init_val( miner_sig: &signer, challenge: vector, solution: vector, @@ -559,6 +548,15 @@ module TowerState { // FullnodeState::init(miner_sig); } + // Note: Used only in tests + public fun test_epoch_reset(vm: &signer) acquires TowerStats { + CoreAddresses::assert_vm(vm); + let state = borrow_global_mut(CoreAddresses::VM_RESERVED_ADDRESS()); + state.proofs_in_epoch = 0; + state.validator_proofs = 0; + state.fullnode_proofs = 0; + } + // Function index: 11 // provides a different method to submit from the operator for use in tests // where the operator cannot sign a transaction @@ -600,15 +598,7 @@ module TowerState { public fun test_helper_mock_mining(sender: &signer, count: u64) acquires TowerProofHistory, TowerStats { assert(Testnet::is_testnet(), Errors::invalid_state(130118)); let addr = Signer::address_of(sender); - let state = borrow_global_mut(addr); - state.count_proofs_in_epoch = count; - let i = 0; - while (i < count) { - increment_stats(addr); - i = i + 1; - } - - // FullnodeState::mock_proof(sender, count); + danger_mock_mining(addr, count); } // Function code: 13 @@ -616,9 +606,16 @@ module TowerState { public fun test_helper_mock_mining_vm(vm: &signer, addr: address, count: u64) acquires TowerProofHistory, TowerStats { assert(Testnet::is_testnet(), Errors::invalid_state(130120)); CoreAddresses::assert_diem_root(vm); + danger_mock_mining(addr, count) + } + + fun danger_mock_mining(addr: address, count: u64) acquires TowerProofHistory, TowerStats { + // again for safety + assert(Testnet::is_testnet(), Errors::invalid_state(130118)); + let state = borrow_global_mut(addr); state.count_proofs_in_epoch = count; - + state.latest_epoch_mining = DiemConfig::get_current_epoch(); let i = 0; while (i < count) { increment_stats(addr); @@ -626,13 +623,15 @@ module TowerState { } } + + // Permissions: PUBLIC, VM, TESTING // Get the vm to trigger a reconfig for testing // Function code: 14 public fun test_helper_mock_reconfig(account: &signer, miner_addr: address) acquires TowerProofHistory{ CoreAddresses::assert_diem_root(account); assert(Testnet::is_testnet(), Errors::invalid_state(130122)); - update_metrics(account, miner_addr); + update_epoch_metrics_vals(account, miner_addr); } // Get weight of validator identified by address @@ -646,10 +645,19 @@ module TowerState { *&state.verified_tower_height } + // TODO: remove this and replace tests with get_count_in_epoch public fun test_helper_get_count(account: &signer): u64 acquires TowerProofHistory { assert(Testnet::is_testnet(), 130115014011); let addr = Signer::address_of(account); - borrow_global(addr).count_proofs_in_epoch + get_count_in_epoch(addr) + } + + public fun test_helper_get_nominal_count(miner_addr: address): u64 acquires TowerProofHistory { + assert(Testnet::is_testnet(), Errors::invalid_state(130123)); + assert(exists(miner_addr), Errors::not_published(130124)); + + let state = borrow_global(miner_addr); + *&state.count_proofs_in_epoch } // Function code: 16 diff --git a/language/diem-framework/modules/0L_transaction_scripts/ol_miner_state.move b/language/diem-framework/modules/0L_transaction_scripts/ol_miner_state.move index 32025fca11..b460c9eb5f 100644 --- a/language/diem-framework/modules/0L_transaction_scripts/ol_miner_state.move +++ b/language/diem-framework/modules/0L_transaction_scripts/ol_miner_state.move @@ -45,7 +45,7 @@ use 0x1::Testnet; public(script) fun minerstate_helper(sender: signer) { assert(Testnet::is_testnet(), 01); - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::alice_0_easy_chal(), TestFixtures::alice_0_easy_sol(), diff --git a/language/move-lang/functional-tests/tests/0L/cases/case_1_reconfig.move b/language/move-lang/functional-tests/tests/0L/cases/case_1_reconfig.move index f0b72df6e2..788c2d6ec6 100644 --- a/language/move-lang/functional-tests/tests/0L/cases/case_1_reconfig.move +++ b/language/move-lang/functional-tests/tests/0L/cases/case_1_reconfig.move @@ -22,6 +22,7 @@ script { use 0x1::NodeWeight; use 0x1::GAS::GAS; use 0x1::DiemAccount; + use 0x1::Debug::print; fun main(sender: signer) { // Tests on initial size of validators @@ -29,14 +30,19 @@ script { assert(DiemSystem::is_validator(@{{alice}}) == true, 7357300101021000); assert(DiemSystem::is_validator(@{{eve}}) == true, 7357300101031000); - assert(TowerState::get_count_in_epoch(@{{alice}}) == 1, 7357300101041000); + assert(TowerState::get_count_in_epoch(@{{alice}}) == 0, 7357300101041000); assert(DiemAccount::balance(@{{alice}}) == 1000000, 7357300101051000); assert(NodeWeight::proof_of_weight(@{{alice}}) == 0, 7357300101051000); // Alice continues to mine after genesis. // This test is adapted from chained_from_genesis.move TowerState::test_helper_mock_mining(&sender, 5); + let a = TowerState::get_epochs_compliant(@{{alice}}); + print(&a); + assert(TowerState::get_count_in_epoch(@{{alice}}) == 5, 7357300101071000); + assert(TowerState::node_above_thresh(@{{alice}}), 7357300101081000); + } } // check: EXECUTED @@ -116,6 +122,7 @@ script { use 0x1::DiemAccount; use 0x1::Subsidy; use 0x1::Globals; + use 0x1::TowerState; fun main(_vm: signer) { // We are in a new epoch. @@ -133,7 +140,11 @@ script { let ending_balance = starting_balance + expected_subsidy - operator_refund; assert(DiemAccount::balance(@{{alice}}) == ending_balance, 7357000180113); - assert(NodeWeight::proof_of_weight(@{{alice}}) == 0, 7357000180114); + assert(NodeWeight::proof_of_weight(@{{alice}}) == 0, 7357000180114); + + // Case 1, increments the epochs_validating_and_mining, which is used for rate-limiting onboarding + assert(TowerState::get_epochs_compliant(@{{alice}}) == 1, 7357000180115); + } } //check: EXECUTED \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/cases/case_2_reconfig.move b/language/move-lang/functional-tests/tests/0L/cases/case_2_reconfig.move index d22ca2224b..5e95139ae5 100644 --- a/language/move-lang/functional-tests/tests/0L/cases/case_2_reconfig.move +++ b/language/move-lang/functional-tests/tests/0L/cases/case_2_reconfig.move @@ -136,6 +136,7 @@ script { use 0x1::NodeWeight; use 0x1::GAS::GAS; use 0x1::DiemAccount; + use 0x1::TowerState; fun main(_account: signer) { // We are in a new epoch. @@ -150,6 +151,9 @@ script { assert(DiemAccount::balance(@{{bob}}) == 949991, 7357000180112); //case 2 does not increment weight. - assert(NodeWeight::proof_of_weight(@{{bob}}) == 0, 7357000180113); + assert(NodeWeight::proof_of_weight(@{{bob}}) == 0, 7357000180113); + + //case 2 does not increment epochs_validating and mining. + assert(TowerState::get_epochs_compliant(@{{bob}}) == 0, 7357000180114); } } \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/cases/case_3_reconfig.move b/language/move-lang/functional-tests/tests/0L/cases/case_3_reconfig.move index eecd454b58..944ee2b7b6 100644 --- a/language/move-lang/functional-tests/tests/0L/cases/case_3_reconfig.move +++ b/language/move-lang/functional-tests/tests/0L/cases/case_3_reconfig.move @@ -17,6 +17,8 @@ //! block-time: 1 //! NewBlockEvent +// 1. Set up validator accounts correctly. Test harness was not giving enough gas to operator accounts. TODO: check if this is still true 20211204 + //! new-transaction //! sender: diemroot script { @@ -42,6 +44,8 @@ script { } //check: EXECUTED +// 2. Mock mining on all accounts. + //! new-transaction //! sender: alice script { @@ -137,6 +141,8 @@ script { } //check: EXECUTED +// 3. Test that Carol the Case 3, has correct fixtures + //! new-transaction //! sender: diemroot script { @@ -144,15 +150,8 @@ script { use 0x1::TowerState; use 0x1::GAS::GAS; use 0x1::DiemAccount; - // use 0x1::FullnodeState; fun main(_vm: signer) { - // This is not an onboarding case, steady state. - // FullnodeState::test_set_fullnode_fixtures( - // &vm, @{{carol}}, 0, 0, 0, 200, 200, 1000000 - // ); - - // Tests on initial size of validators assert(DiemSystem::validator_set_size() == 6, 7357000180101); assert(DiemSystem::is_validator(@{{carol}}) == true, 7357000180102); assert(TowerState::test_helper_get_height(@{{carol}}) == 0, 7357000180104); @@ -162,18 +161,14 @@ script { } // check: EXECUTED +// 4. process consensus votes + //! new-transaction //! sender: diemroot script { use 0x1::Vector; use 0x1::Stats; - // use 0x1::FullnodeState; - // This is the the epoch boundary. fun main(vm: signer) { - // This is not an onboarding case, steady state. - // FullnodeState::test_set_fullnode_fixtures( - // &vm, @{{carol}}, 0, 0, 0, 200, 200, 1000000 - // ); let voters = Vector::empty
(); Vector::push_back
(&mut voters, @{{alice}}); @@ -195,6 +190,8 @@ script { } } +// 4. Check carol would be considered a Case 3 at the end of epoch + //! new-transaction //! sender: diemroot script { @@ -226,6 +223,7 @@ script { use 0x1::GAS::GAS; use 0x1::DiemAccount; use 0x1::DiemConfig; + use 0x1::TowerState; fun main(_account: signer) { // We are in a new epoch. @@ -236,6 +234,10 @@ script { assert(DiemAccount::balance(@{{carol}}) == 949991, 7357000180112); assert(NodeWeight::proof_of_weight(@{{carol}}) == 0, 7357000180113); assert(DiemConfig::get_current_epoch() == 2, 7357000180114); + + // Case 3 does not increment epochs_validating and mining (while case 1 does); + assert(TowerState::get_epochs_compliant(@{{alice}}) == 1, 7357000180115); + assert(TowerState::get_epochs_compliant(@{{carol}}) == 0, 7357000180115); } } //check: EXECUTED \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/cases/case_3_unit.move b/language/move-lang/functional-tests/tests/0L/cases/case_3_unit.move index 20bd257f8c..8c09163374 100644 --- a/language/move-lang/functional-tests/tests/0L/cases/case_3_unit.move +++ b/language/move-lang/functional-tests/tests/0L/cases/case_3_unit.move @@ -4,12 +4,14 @@ //! sender: alice script { use 0x1::TowerState; + use 0x1::Debug::print; fun main(sender: signer) { // Alice is the only one that can update her mining stats. // Hence this first transaction. TowerState::test_helper_mock_mining(&sender, 5); + print(&TowerState::get_count_in_epoch(@{{alice}})); assert(TowerState::get_count_in_epoch(@{{alice}}) == 5, 7357300101011000); } } diff --git a/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig.move b/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig.move index 8be180655a..657bd4d774 100644 --- a/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig.move +++ b/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig.move @@ -10,7 +10,7 @@ script { use 0x1::TestFixtures; fun main(sender: signer) { - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::easy_chal(), TestFixtures::easy_sol(), @@ -29,7 +29,7 @@ script { use 0x1::TowerState; fun main(vm: signer) { - TowerState::epoch_reset(&vm); + TowerState::test_epoch_reset(&vm); } } @@ -55,7 +55,7 @@ script { // assert(DiemSystem::validator_set_size() == 5, 7357300101011000); assert(DiemSystem::is_validator(@{{alice}}) == true, 735701); - assert(TowerState::get_count_in_epoch(@{{alice}}) == 1, 735702); + assert(TowerState::get_count_in_epoch(@{{alice}}) == 0, 735702); assert(DiemAccount::balance(@{{alice}}) == 1000000, 735703); assert(NodeWeight::proof_of_weight(@{{alice}}) == 0, 735704); diff --git a/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig_two.move b/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig_two.move index 4e274636ed..7747579e38 100644 --- a/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig_two.move +++ b/language/move-lang/functional-tests/tests/0L/fullnode_subsidy/fullnode_reconfig_two.move @@ -12,7 +12,7 @@ script { fun main(sender: signer) { // add one proof and init the state. - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::easy_chal(), TestFixtures::easy_sol(), @@ -30,7 +30,7 @@ script { fun main(sender: signer) { // add one proof and init the state. - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::easy_chal(), TestFixtures::easy_sol(), @@ -48,7 +48,7 @@ script { use 0x1::TowerState; fun main(vm: signer) { - TowerState::epoch_reset(&vm); + TowerState::test_epoch_reset(&vm); } } @@ -74,7 +74,7 @@ script { // assert(DiemSystem::validator_set_size() == 5, 7357300101011000); assert(DiemSystem::is_validator(@{{alice}}) == true, 735701); - assert(TowerState::get_count_in_epoch(@{{alice}}) == 1, 735702); + assert(TowerState::get_count_in_epoch(@{{alice}}) == 0, 735702); assert(DiemAccount::balance(@{{alice}}) == 1000000, 735703); assert(NodeWeight::proof_of_weight(@{{alice}}) == 0, 735704); diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/_meta_mock_mining.move b/language/move-lang/functional-tests/tests/0L/tower_state/_meta_mock_mining.move index 9bb713ca0b..79a8c9c40d 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/_meta_mock_mining.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/_meta_mock_mining.move @@ -21,7 +21,7 @@ script { fun main(sender: signer) { assert(TowerState::get_count_in_epoch(@{{alice}}) == 5, 73570001); TowerState::test_helper_mock_reconfig(&sender, @{{alice}}); - assert(TowerState::get_epochs_mining(@{{alice}}) == 1, 73570002); + assert(TowerState::get_epochs_compliant(@{{alice}}) == 1, 73570002); } } //check: EXECUTED \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/_meta_wrap_commit_state.move b/language/move-lang/functional-tests/tests/0L/tower_state/_meta_wrap_commit_state.move index a8aee96de2..ca1d3f9a12 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/_meta_wrap_commit_state.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/_meta_wrap_commit_state.move @@ -13,7 +13,7 @@ script { fun main(sender: signer) { // Testing that state can be initialized, and a proof submitted as if it were genesis. // buildign block for other tests. - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::easy_chal(), TestFixtures::easy_sol(), diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_fail.move b/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_fail.move index 2d8d0a6665..dd82820d46 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_fail.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_fail.move @@ -15,7 +15,7 @@ script { let height_after = 0; - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::easy_chal(), TestFixtures::easy_sol(), diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_easy.move b/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_easy.move index 8c88a73582..d8dedfd4ed 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_easy.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_easy.move @@ -12,7 +12,7 @@ script { fun main(sender: signer) { let height_after = 0; - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::alice_0_easy_chal(), TestFixtures::alice_0_easy_sol(), diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_hard.move b/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_hard.move index 3e6032b553..3c95b80701 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_hard.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/chained_proof_success_hard.move @@ -12,7 +12,7 @@ script { fun main(sender: signer) { let height_after = 0; - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::alice_0_hard_chal(), TestFixtures::alice_0_hard_sol(), diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/init_miner_state.move b/language/move-lang/functional-tests/tests/0L/tower_state/init_miner_state.move index a29ececc04..439a7786db 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/init_miner_state.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/init_miner_state.move @@ -1,12 +1,16 @@ //! account: dummy-prevents-genesis-reload, 100000 ,0, validator +//! account: alice, 10000000GAS + +// Alice is an end-user, and submits a VDF Proof -// Alice Submit VDF Proof //! new-transaction -//! account: alice, 10000000GAS + //! sender: alice script { use 0x1::TowerState; use 0x1::TestFixtures; +use 0x1::Debug::print; +use 0x1::Vector; fun main(sender: signer) { TowerState::init_miner_state( @@ -16,6 +20,14 @@ fun main(sender: signer) { TestFixtures::easy_difficulty(), TestFixtures::security(), ); + + print(&TowerState::get_epochs_compliant(@{{alice}})); + assert(TowerState::get_tower_height(@{{alice}}) == 0, 735701); + assert(TowerState::get_epochs_compliant(@{{alice}}) == 0, 735702); + assert(TowerState::get_count_in_epoch(@{{alice}}) == 1, 735703); + print(&TowerState::get_miner_list()); + assert(Vector::length
(&TowerState::get_miner_list()) == 2, 735704); // includes the dummy validator from genesis + } } // check: EXECUTED diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/lazy_reset_count.move b/language/move-lang/functional-tests/tests/0L/tower_state/lazy_reset_count.move new file mode 100644 index 0000000000..937b708ae5 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/tower_state/lazy_reset_count.move @@ -0,0 +1,172 @@ +//! account: bob, 100000, 0, validator +//! account: alice, 10000000GAS + +// 1. alice is onboarded as an end-user, and submits first proof (through Carpe app for example). + +// Alice Submit VDF Proof +//! new-transaction +//! sender: alice +script { + use 0x1::TowerState; + use 0x1::TestFixtures; + use 0x1::DiemConfig; + use 0x1::Debug::print; + + // SIMULATES A MINER ONBOARDING PROOF (proof_0.json) + fun main(sender: signer) { + print(&DiemConfig::get_current_epoch()); + + TowerState::init_miner_state( + &sender, + &TestFixtures::alice_0_easy_chal(), + &TestFixtures::alice_0_easy_sol(), + TestFixtures::easy_difficulty(), + TestFixtures::security(), + ); + + assert(TowerState::test_helper_get_height(@{{alice}}) == 0, 10008001); + assert(TowerState::get_epochs_compliant(@{{alice}}) == 0, 735701); + + // the last epoch mining is this one. + assert(TowerState::get_miner_latest_epoch(@{{alice}}) == DiemConfig::get_current_epoch(), 735702); + // initialization created one proof. + // With Lazy computation, is number will not change on the next epochboundary. + // if will only change after the next mining proof is submitted. + assert(TowerState::get_count_in_epoch(@{{alice}}) == 1, 735703); + // the nominal count will match the expected count in epoch. + assert(TowerState::test_helper_get_nominal_count(@{{alice}}) == 1, 735704); + + } +} +// check: EXECUTED + +// 2. one epoch with no mining from alice. Should not change nominal count. + + +////////////////////////////////////////////// +///// Trigger reconfiguration at 61 seconds //// +//! block-prologue +//! proposer: bob +//! block-time: 61000000 +//! round: 15 + +///// TEST RECONFIGURATION IS HAPPENING //// +// check: NewEpochEvent +////////////////////////////////////////////// + + +//! new-transaction +//! sender: diemroot +script { + use 0x1::DiemConfig; + use 0x1::TowerState; + use 0x1::Debug::print; + + // SIMULATES THE SECOND PROOF OF THE MINER (proof_1.json) + fun main(_: signer) { + print(&DiemConfig::get_current_epoch()); + print(&TowerState::get_count_in_epoch(@{{alice}})); + + // the latest epoch mining cannot be the current epoch. + assert(TowerState::get_miner_latest_epoch(@{{alice}}) != DiemConfig::get_current_epoch(), 735701); + // Lazy would mean no change from before epoch boundary in nominal count + assert(TowerState::test_helper_get_nominal_count(@{{alice}}) == 1, 735703); + + // but the helpers know the actual count in epoch is 0. + assert(TowerState::get_count_in_epoch(@{{alice}}) == 0, 735703); + + + } +} + + +// 3. ONCE AGAIN. Just to be sure. Add one epoch with no mining from alice. Should not change nominal count. + +////////////////////////////////////////////// +///// Trigger reconfiguration at 61 seconds //// +//! block-prologue +//! proposer: bob +//! block-time: 125000000 +//! round: 30 + +///// TEST RECONFIGURATION IS HAPPENING //// +// check: NewEpochEvent +////////////////////////////////////////////// + + +//! new-transaction +//! sender: diemroot +script { + use 0x1::DiemConfig; + use 0x1::TowerState; + use 0x1::Debug::print; + + // SIMULATES THE SECOND PROOF OF THE MINER (proof_1.json) + fun main(_: signer) { + print(&DiemConfig::get_current_epoch()); + print(&TowerState::get_count_in_epoch(@{{alice}})); + + // the latest epoch mining cannot be the current epoch. + assert(TowerState::get_miner_latest_epoch(@{{alice}}) != DiemConfig::get_current_epoch(), 735704); + + // Lazy would mean no change from before epoch boundary in nominal count + assert(TowerState::test_helper_get_nominal_count(@{{alice}}) == 1, 735705); + + // but the helpers know the actual count in epoch is 0. + assert(TowerState::get_count_in_epoch(@{{alice}}) == 0, 735706); + + + } +} + + +// 4. Alice finally sends a new miner proof, and the nominal epochs info is reset. + + +//! new-transaction +//! sender: alice +script { + use 0x1::TowerState; + use 0x1::TestFixtures; + use 0x1::DiemConfig; + use 0x1::Debug::print; + + // SIMULATES THE SECOND PROOF OF THE MINER (proof_1.json) + fun main(sender: signer) { + let before = TowerState::get_tower_height(@{{alice}}); + + print(&before); + // assert(TowerState::test_helper_get_height(@{{alice}}) == 0, 10008001); + + let proof = TowerState::create_proof_blob( + TestFixtures::alice_1_easy_chal(), + TestFixtures::alice_1_easy_sol(), + TestFixtures::easy_difficulty(), + TestFixtures::security(), + ); + TowerState::commit_state(&sender, proof); + + let after = TowerState::get_tower_height(@{{alice}}); + + print(&after); + + // the cumulative tower height has increased + assert(after > before , 735707); + + // HOWEVER the nominal count is just 1 (it was reset to 0 and then a new proof was added) + + assert(TowerState::test_helper_get_nominal_count(@{{alice}}) == 1, 735708); + + // Now everthing should match as expected + + // the latest epoch mining is the current epoch. + assert(TowerState::get_miner_latest_epoch(@{{alice}}) == DiemConfig::get_current_epoch(), 735709); + + // Lazy would mean no change from before epoch boundary in nominal count + assert(TowerState::test_helper_get_nominal_count(@{{alice}}) == TowerState::get_count_in_epoch(@{{alice}}), 735710); + + } +} +// check: EXECUTED + + diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/miners_dont_increment_compliant_count.move b/language/move-lang/functional-tests/tests/0L/tower_state/miners_dont_increment_compliant_count.move new file mode 100644 index 0000000000..e9e0c2ae28 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/tower_state/miners_dont_increment_compliant_count.move @@ -0,0 +1,70 @@ +//! account: dummy-prevents-genesis-reload, 100000 ,0, validator +//! account: alice, 10000000GAS + +// Alice Submit VDF Proof +//! new-transaction +//! sender: alice +script { + use 0x1::TowerState; + use 0x1::TestFixtures; + + // SIMULATES A MINER ONBOARDING PROOF (proof_0.json) + fun main(sender: signer) { + TowerState::test_helper_init_val( + &sender, + TestFixtures::alice_0_easy_chal(), + TestFixtures::alice_0_easy_sol(), + TestFixtures::easy_difficulty(), + TestFixtures::security(), + ); + + // check for initialized TowerState + assert(TowerState::test_helper_get_height(@{{alice}}) == 0, 10008001); + + // Note: test helper mocks init of a VALIDATOR, not end-user account + assert(TowerState::get_epochs_compliant(@{{alice}}) == 1, 735701); + } +} +// check: EXECUTED + + +//! new-transaction +//! sender: alice +script { + use 0x1::TowerState; + use 0x1::TestFixtures; + + // SIMULATES THE SECOND PROOF OF THE MINER (proof_1.json) + fun main(sender: signer) { + assert(TowerState::test_helper_get_height(@{{alice}}) == 0, 10008001); + let height_after = 1; + + let proof = TowerState::create_proof_blob( + TestFixtures::alice_1_easy_chal(), + TestFixtures::alice_1_easy_sol(), + TestFixtures::easy_difficulty(), + TestFixtures::security(), + ); + TowerState::commit_state(&sender, proof); + + let verified_height = TowerState::test_helper_get_height(@{{alice}}); + assert(verified_height == height_after, 10008002); + } +} +// check: EXECUTED + + +//! new-transaction +//! sender: diemroot +script { + use 0x1::EpochBoundary; + use 0x1::TowerState; + + // SIMULATES THE SECOND PROOF OF THE MINER (proof_1.json) + fun main(vm: signer) { + EpochBoundary::reconfigure(&vm, 100); + + // no change from before epoch boundary + assert(TowerState::get_epochs_compliant(@{{alice}}) == 1, 735701); + } +} \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/prevent_duplicates.move b/language/move-lang/functional-tests/tests/0L/tower_state/prevent_duplicates.move index b3fc55b346..1188e42288 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/prevent_duplicates.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/prevent_duplicates.move @@ -11,7 +11,7 @@ script { use 0x1::TestFixtures; fun main(sender: signer) { - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::easy_chal(), TestFixtures::easy_sol(), diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_above_thresh.move b/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_above_thresh.move index 08e6a6e3e6..8df69a1503 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_above_thresh.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_above_thresh.move @@ -10,7 +10,7 @@ script { // SIMULATES A MINER ONBOARDING PROOF (proof_0.json) fun main(sender: signer) { - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::alice_0_easy_chal(), TestFixtures::alice_0_easy_sol(), diff --git a/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_below_thresh.move b/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_below_thresh.move index 5884bc3e01..4a568883a4 100644 --- a/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_below_thresh.move +++ b/language/move-lang/functional-tests/tests/0L/tower_state/update_metrics_below_thresh.move @@ -11,7 +11,7 @@ script { // SIMULATES A MINER ONBOARDING PROOF (proof_0.json) fun main(sender: signer) { let height_after = 0; - TowerState::test_helper_init_miner( + TowerState::test_helper_init_val( &sender, TestFixtures::easy_chal(), TestFixtures::easy_sol(), @@ -40,14 +40,14 @@ script { //update_metrics assert(TowerState::test_helper_get_height(@{{alice}}) == 0, 10009001); - assert(TowerState::get_miner_latest_epoch(sender, @{{alice}}) == 1, 10009002); + assert(TowerState::get_miner_latest_epoch(@{{alice}}) == 1, 10009002); assert(TowerState::get_count_in_epoch(@{{alice}}) == 1, 10009003); assert(TowerState::test_helper_get_contiguous_vm(sender, @{{alice}}) == 0, 10009005); TowerState::test_helper_mock_reconfig(sender, @{{alice}}); assert(TowerState::test_helper_get_height(@{{alice}}) == 0, 10009006); - assert(TowerState::get_miner_latest_epoch(sender, @{{alice}}) == 1, 10009007); + assert(TowerState::get_miner_latest_epoch(@{{alice}}) == 1, 10009007); assert(TowerState::get_count_in_epoch(@{{alice}}) == 0, 10009008); assert(TowerState::test_helper_get_contiguous_vm(sender, @{{alice}}) == 0, 10009010); } diff --git a/language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_initialized_from_genesis.depr b/language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_initialized_from_genesis.depr deleted file mode 100644 index 76e1d2aec6..0000000000 --- a/language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_initialized_from_genesis.depr +++ /dev/null @@ -1,24 +0,0 @@ -// Do not add validators here, the settings added here will overwrite the genesis defaults which is what we are checking for. - -//! new-transaction -//! sender: diemroot -script { - use 0x1::DiemSystem; - // use 0x1::DiemAccount; - // use 0x1::GAS::GAS; - use 0x1::TrustedAccounts; - use 0x1::Vector; - - fun main(_account: signer) { - let num_validators = DiemSystem::validator_set_size(); - let index = 0; - while (index < num_validators) { - let addr = DiemSystem::get_ith_validator_address(index); - let (test, _ ) = TrustedAccounts::get_trusted(addr); - let len = Vector::length
(&test); - assert(len == 0, 7357130101051000); - index = index + 1; - }; - } -} -// check: "Keep(EXECUTED)" \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_update_accounts.depr b/language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_update_accounts.depr deleted file mode 100644 index 4e8a70d0ec..0000000000 --- a/language/move-lang/functional-tests/tests/0L/trusted_accounts/trusted_update_accounts.depr +++ /dev/null @@ -1,34 +0,0 @@ -// Do not add validators here, the settings added here will overwrite the genesis defaults which is what we are checking for. -//! account: alice, 1, 0, validator -//! account: bob, 1, 0 -//! account: carol, 1, 0 - - -//! new-transaction -//! sender: alice -script { - use 0x1::Signer; - use 0x1::TrustedAccounts; - use 0x1::Vector; - - fun main(account: signer) { - let addr = Signer::address_of(&account); - let (my_before, _ ) = TrustedAccounts::get_trusted(addr); - let len = Vector::length
(&my_before); - assert(len == 0, 7357130101011000); - - let vec_my = Vector::singleton
(@{{alice}}); - let vec_follow = Vector::singleton
(@{{bob}}); - - TrustedAccounts::update( - &account, - vec_my, //update_my - vec_follow, //update_follow - ); - - let (my_after, _ ) = TrustedAccounts::get_trusted(addr); - let len = Vector::length
(&my_after); - assert(len == 1, 7357130101021000); - } -} -// check: "Keep(EXECUTED)" \ No newline at end of file diff --git a/ol/cli/src/node/chain_view.rs b/ol/cli/src/node/chain_view.rs index 54922ceed4..a463479931 100644 --- a/ol/cli/src/node/chain_view.rs +++ b/ol/cli/src/node/chain_view.rs @@ -103,6 +103,7 @@ pub struct ValsConfigStats { } impl Node { + // TODO: this should return a result and no functions below should use unwrap() /// fetch state from system address 0x0 pub fn refresh_chain_info(&mut self) -> (Option, Option>) { // let mut client = client::pick_client(); diff --git a/ol/genesis-tools/src/fork_genesis.rs b/ol/genesis-tools/src/fork_genesis.rs index 7ae116df73..f02417895e 100644 --- a/ol/genesis-tools/src/fork_genesis.rs +++ b/ol/genesis-tools/src/fork_genesis.rs @@ -116,16 +116,6 @@ pub fn migrate_account(legacy: &LegacyRecovery) -> Result { // Restore Miner State if let Some(m) = &legacy.miner_state { - // TODO: confirm no transformation is needed since the serialization remains the same. - // let new = TowerStateResource { - // previous_proof_hash: m.previous_proof_hash, - // verified_tower_height: m.verified_tower_height, - // latest_epoch_mining: m.latest_epoch_mining, - // count_proofs_in_epoch: m.count_proofs_in_epoch, - // epochs_validating_and_mining: m.epochs_validating_and_mining, - // contiguous_epochs_validating_and_mining: m.contiguous_epochs_validating_and_mining, - // epochs_since_last_account_creation: m.epochs_since_last_account_creation, - // }; write_set_mut.push(( AccessPath::new(account, TowerStateResource::resource_path()), WriteOp::Value(bcs::to_bytes(&m).unwrap()),