From c516ad3eb157c887e2d60fe5f1914cffe2b546df Mon Sep 17 00:00:00 2001 From: zoz <97761083+0xzoz@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:09:07 -0800 Subject: [PATCH] [fix] toy rng chain halt (#133) Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> --- .../sources/ol_sources/tower_state.move | 35 ++++++++----------- tools/rescue/src/rescue_tx.rs | 6 ++-- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/framework/libra-framework/sources/ol_sources/tower_state.move b/framework/libra-framework/sources/ol_sources/tower_state.move index 4fd559591..7cbc15f3f 100644 --- a/framework/libra-framework/sources/ol_sources/tower_state.move +++ b/framework/libra-framework/sources/ol_sources/tower_state.move @@ -163,15 +163,6 @@ module ol_framework::tower_state { exists(addr) } - // /// is onboarding - // public fun is_onboarding(addr: address): bool acquires TowerProofHistory { - // let count = get_count_in_epoch(addr); - // let state = borrow_global(addr); - - // count < 2 && - // state.epochs_since_last_account_creation < 2 - // } - // Creates proof blob object from input parameters // Permissions: PUBLIC, ANYONE can call this function. public fun create_proof_blob( @@ -415,15 +406,17 @@ module ol_framework::tower_state { // that had proofs this epoch let outgoing_miners = get_miner_list(); let vals_len = vector::length(&outgoing_miners); - let i = 0; - while (i < vals_len) { - let val = vector::borrow(&outgoing_miners, i); - - // For testing: don't call update_metrics unless there is account state for the address. - if (exists(*val)){ - update_epoch_metrics_vals(vm, *val); - }; - i = i + 1; + if (vals_len > 0) { + let i = 0; + while (i < vals_len) { + let val = vector::borrow(&outgoing_miners, i); + + // For testing: don't call update_metrics unless there is account state for the address. + if (exists(*val)){ + update_epoch_metrics_vals(vm, *val); + }; + i = i + 1; + }; }; epoch_reset(vm); @@ -598,16 +591,16 @@ module ol_framework::tower_state { this_miner_index = this_miner_index / count_miners; k = k + 1; }; - // double check - if (count_miners < this_miner_index) return 0; + // double check length of vector + if (this_miner_index >= count_miners ) return 0; let miner_addr = vector::borrow
(&all_miners, this_miner_index); let vec = if (exists(*miner_addr)) { *&borrow_global(*miner_addr).previous_proof_hash } else { return 0 }; + if (vector::is_empty(&vec)) { return 0 }; // take the last bit (B) from their last proof hash. - n = (vector::pop_back(&mut vec) as u64); this_miner_index = n; // randomize selection of next validator i = i + 1; diff --git a/tools/rescue/src/rescue_tx.rs b/tools/rescue/src/rescue_tx.rs index 3164a20b5..97a722efa 100644 --- a/tools/rescue/src/rescue_tx.rs +++ b/tools/rescue/src/rescue_tx.rs @@ -6,16 +6,16 @@ use move_core_types::language_storage::CORE_CODE_ADDRESS; use std::path::PathBuf; #[derive(Parser)] -/// Start a libra node +/// Create a rescue transaction using the path of the node db pub struct RescueTxOpts { #[clap(short, long)] /// directory enclosing the `/db` folder of the node pub data_path: PathBuf, #[clap(short, long)] - /// directory to read/write or the rescue.blob. Will default to db_path/rescue.blob + /// directory to read/write for the rescue.blob. Will default to db_path/rescue.blob pub blob_path: Option, #[clap(short, long)] - /// directory to read/write or the rescue.blob + /// directory for the script to be executed pub script_path: Option, #[clap(long)] /// directory to read/write or the rescue.blob