diff --git a/Cargo.lock b/Cargo.lock index 7d52c720ec..488cec29a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1764,7 +1764,7 @@ dependencies = [ [[package]] name = "diem-config" -version = "5.1.3" +version = "5.2.0" dependencies = [ "bcs", "diem-crypto", @@ -2222,7 +2222,7 @@ dependencies = [ [[package]] name = "diem-management" -version = "5.1.3" +version = "5.2.0" dependencies = [ "anyhow", "bcs", @@ -2341,7 +2341,7 @@ dependencies = [ [[package]] name = "diem-node" -version = "5.1.3" +version = "5.2.0" dependencies = [ "backup-service", "consensus", @@ -6023,7 +6023,7 @@ dependencies = [ [[package]] name = "ol" -version = "5.1.3" +version = "5.2.0" dependencies = [ "abscissa_core", "abscissa_tokio", @@ -6170,7 +6170,7 @@ dependencies = [ [[package]] name = "onboard" -version = "5.1.3" +version = "5.2.0" dependencies = [ "abscissa_core", "anyhow", @@ -6195,7 +6195,7 @@ dependencies = [ "serde_json", "thiserror", "toml", - "tower 5.1.3", + "tower 5.2.0", "txs", "wait-timeout", "zip", @@ -9117,7 +9117,7 @@ dependencies = [ [[package]] name = "tower" -version = "5.1.3" +version = "5.2.0" dependencies = [ "abscissa_core", "ajson", @@ -9341,7 +9341,7 @@ dependencies = [ [[package]] name = "txs" -version = "5.1.3" +version = "5.2.0" dependencies = [ "abscissa_core", "ajson", diff --git a/config/Cargo.toml b/config/Cargo.toml index 618a34551b..16f95fac81 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diem-config" -version = "5.1.3" +version = "5.2.0" authors = ["Diem Association "] description = "Diem diem-config" repository = "https://github.com/diem/diem" diff --git a/config/management/Cargo.toml b/config/management/Cargo.toml index d552bd0b17..a6b68ced47 100644 --- a/config/management/Cargo.toml +++ b/config/management/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diem-management" -version = "5.1.3" +version = "5.2.0" authors = ["Diem Association "] description = "Diem Management is a tool used to manage the configuration of a Diem Node" repository = "https://github.com/diem/diem" diff --git a/config/src/config/consensus_config.rs b/config/src/config/consensus_config.rs index bf5657cb73..26a3257631 100644 --- a/config/src/config/consensus_config.rs +++ b/config/src/config/consensus_config.rs @@ -34,7 +34,7 @@ impl Default for ConsensusConfig { max_pruned_blocks_in_mem: 100, mempool_txn_pull_timeout_ms: 1000, mempool_executed_txn_timeout_ms: 1000, - round_initial_timeout_ms: 1000, + round_initial_timeout_ms: 5000, //////// 0L //////// proposer_type: ConsensusProposerType::LeaderReputation(LeaderReputationConfig { active_weights: 99, inactive_weights: 1, diff --git a/config/src/config/mempool_config.rs b/config/src/config/mempool_config.rs index f414454910..574bf14901 100644 --- a/config/src/config/mempool_config.rs +++ b/config/src/config/mempool_config.rs @@ -43,11 +43,11 @@ impl Default for MempoolConfig { shared_mempool_tick_interval_ms: 5_000, //////// 0L //////// shared_mempool_backoff_interval_ms: 3_000, //////// 0L //////// shared_mempool_batch_size: 100, - shared_mempool_ack_timeout_ms: 2_000, - shared_mempool_max_concurrent_inbound_syncs: 2, + shared_mempool_ack_timeout_ms: 20_000, ///////// 0L ///////// + shared_mempool_max_concurrent_inbound_syncs: 10, ///////// 0L ///////// max_broadcasts_per_peer: 5, //////// 0L //////// mempool_snapshot_interval_secs: 180, - capacity: 1_000, ///////// 0L //////// Reduce size of mempool due to VDF cost. + capacity: 100, ///////// 0L //////// Reduce size of mempool due to VDF cost. capacity_per_user: 1, // no reason for a given user to be ablet to submit more than tree txs to mempool. default_failovers: 3, system_transaction_timeout_secs: 1000, //////// 0L //////// transacitons should timeout under this time diff --git a/config/src/config/state_sync_config.rs b/config/src/config/state_sync_config.rs index 643bea97a6..64b4ab5323 100644 --- a/config/src/config/state_sync_config.rs +++ b/config/src/config/state_sync_config.rs @@ -41,7 +41,7 @@ impl Default for StateSyncConfig { client_commit_timeout_ms: 5_000, long_poll_timeout_ms: 10_000, max_chunk_limit: 1_000, - max_timeout_ms: 120_000, + max_timeout_ms: 1_200_000, mempool_commit_timeout_ms: 5_000, multicast_timeout_ms: 30_000, sync_request_timeout_ms: 60_000, //////// 0L ///////// diff --git a/diem-node/Cargo.toml b/diem-node/Cargo.toml index bcd307951a..9ddec51073 100644 --- a/diem-node/Cargo.toml +++ b/diem-node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diem-node" -version = "5.1.3" +version = "5.2.0" authors = ["Diem Association "] description = "Diem node" repository = "https://github.com/diem/diem" diff --git a/language/diem-framework/modules/0L/EpochBoundary.move b/language/diem-framework/modules/0L/EpochBoundary.move index a8001011ff..c4a330d01b 100644 --- a/language/diem-framework/modules/0L/EpochBoundary.move +++ b/language/diem-framework/modules/0L/EpochBoundary.move @@ -105,9 +105,9 @@ module EpochBoundary { let miner_subsidy = count * proof_price; // don't pay while we are in recovery mode, since that creates a frontrunning opportunity - if (!RecoveryMode::is_recovery()){ + // if (!RecoveryMode::is_recovery()){ FullnodeSubsidy::distribute_fullnode_subsidy(vm, addr, miner_subsidy); - } + // } }; diff --git a/language/diem-framework/modules/0L/Oracle.move b/language/diem-framework/modules/0L/Oracle.move index 0ff39418a4..085fd3aee1 100644 --- a/language/diem-framework/modules/0L/Oracle.move +++ b/language/diem-framework/modules/0L/Oracle.move @@ -28,6 +28,7 @@ address 0x1 { const DELEGATION_NOT_ENABLED: u64 = 150002; const VOTE_ALREADY_DELEGATED: u64 = 150003; const DELEGATION_NOT_PRESENT: u64 = 150004; + const DUPLICATE_VOTE: u64 = 150005; struct Oracles has key { upgrade: UpgradeOracle @@ -178,7 +179,9 @@ address 0x1 { }; // if the sender has voted, do nothing - if (Vector::contains
(&upgrade_oracle.validators_voted, &sender)) {return}; + if (Vector::contains
(&upgrade_oracle.validators_voted, &sender)) { + assert(false, Errors::invalid_argument(DUPLICATE_VOTE)); + }; let vote_weight = get_weight(sender, VOTE_TYPE_UPGRADE); @@ -198,6 +201,33 @@ address 0x1 { }; } + + public fun revoke_my_votes(sender: &signer) acquires Oracles, VoteDelegation { + let addr = Signer::address_of(sender); + revoke_vote(addr); + + let del = borrow_global(Signer::address_of(sender)); + let l = Vector::length
(&del.delegates); + let i = 0; + while (i < l) { + let addr = *Vector::borrow
(&del.delegates, i); + revoke_vote(addr); + i = i + 1; + }; + + } + + fun revoke_vote(addr: address) acquires Oracles{ + let upgrade_oracle = &mut borrow_global_mut(CoreAddresses::DIEM_ROOT_ADDRESS()).upgrade; + let (is_found, idx) = Vector::index_of
(&upgrade_oracle.validators_voted, &addr); + + if (is_found) { + Vector::remove(&mut upgrade_oracle.votes, idx); + Vector::remove(&mut upgrade_oracle.validators_voted, idx); + tally_upgrade(upgrade_oracle, VOTE_TYPE_UPGRADE); + }; + + } fun increment_vote_count(vote_counts: &mut vector, data: vector, validator: address, vote_weight: u64) { let data_hash = Hash::sha2_256(copy data); @@ -266,10 +296,20 @@ address 0x1 { total_weight: 0, }; } + + fun vm_expire_upgrade(vm: &signer) acquires Oracles { + assert(Signer::address_of(vm) == CoreAddresses::DIEM_ROOT_ADDRESS(), Errors::requires_role(150003)); + let upgrade_oracle = &mut borrow_global_mut(CoreAddresses::DIEM_ROOT_ADDRESS()).upgrade; + let threshold = get_threshold(VOTE_TYPE_PROPORTIONAL_VOTING_POWER); + + let result = check_consensus(&upgrade_oracle.vote_counts, threshold); + upgrade_oracle.consensus = result; + upgrade_oracle.vote_window = DiemBlock::get_current_block_height() - 1; + } // check to see if threshold is reached every time receiving a vote // TODO: Not sure we still want to do this every time as tallying is more costly when using node weight (as the threshold must be summed), fine for now. - fun tally_upgrade (upgrade_oracle: &mut UpgradeOracle, type: u8) { + fun tally_upgrade(upgrade_oracle: &mut UpgradeOracle, type: u8) { let threshold = get_threshold(type); let result = check_consensus(&upgrade_oracle.vote_counts, threshold); diff --git a/language/diem-framework/modules/0L/Upgrade.move b/language/diem-framework/modules/0L/Upgrade.move index b5210019f2..2d54dc8f2e 100644 --- a/language/diem-framework/modules/0L/Upgrade.move +++ b/language/diem-framework/modules/0L/Upgrade.move @@ -8,7 +8,6 @@ module Upgrade { use 0x1::Errors; use 0x1::Signer; use 0x1::Vector; - // use 0x1::DiemTimestamp; /// Structs for UpgradePayload resource struct UpgradePayload has key { diff --git a/language/diem-framework/modules/0L_transaction_scripts/ol_oracle.move b/language/diem-framework/modules/0L_transaction_scripts/ol_oracle.move index d53b345134..209e5a207d 100644 --- a/language/diem-framework/modules/0L_transaction_scripts/ol_oracle.move +++ b/language/diem-framework/modules/0L_transaction_scripts/ol_oracle.move @@ -6,6 +6,10 @@ module OracleScripts { Oracle::handler(&sender, id, data); } + public(script) fun ol_revoke_vote(sender: signer) { + Oracle::revoke_my_votes(&sender); + } + /// A validator (Alice) can delegate the authority for the operation of an upgrade to another validator (Bob). When Oracle delegation happens, effectively the consensus voting power of Alice, is added to Bob only for the effect of calculating the preference on electing a stdlib binary. Whatever binary Bob proposes, Alice will also propose without needing to be submitting transactions. public(script) fun ol_delegate_vote(sender: signer, dest: address) { diff --git a/language/diem-framework/modules/doc/EpochBoundary.md b/language/diem-framework/modules/doc/EpochBoundary.md index 4c4a58ebcf..a10ac70563 100644 --- a/language/diem-framework/modules/doc/EpochBoundary.md +++ b/language/diem-framework/modules/doc/EpochBoundary.md @@ -269,7 +269,7 @@ // can't be more than index of accounts i < Vector::length(&top_accounts) && // the new proposed set can only only expand by 15% - Vector::length(&proposed_set) < len_proven_nodes + max_unproven_nodes && + Vector::length(&proposed_set) < (len_proven_nodes + max_unproven_nodes) && // Validator set can only be as big as the maximum set size Vector::length(&proposed_set) < Globals::get_max_validators_per_set() ) { @@ -305,7 +305,7 @@ // if we are failing to qualify anyone. Pick top 1/2 of validator set by proposals. They are probably online. - if (Vector::length<address>(&proposed_set) <= 3) proposed_set = Stats::get_sorted_vals_by_props(vm, Vector::length<address>(&proposed_set) / 2); + if (Vector::length<address>(&proposed_set) <= 3) proposed_set = Stats::get_sorted_vals_by_props(vm, Vector::length<address>(&top_accounts) / 2); // If still failing...in extreme case if we cannot qualify anyone. Don't change the validator set. diff --git a/language/diem-framework/modules/doc/Globals.md b/language/diem-framework/modules/doc/Globals.md index eaf56b8d63..70ad3c4823 100644 --- a/language/diem-framework/modules/doc/Globals.md +++ b/language/diem-framework/modules/doc/Globals.md @@ -24,6 +24,8 @@ This module provides global variables and constants that have no specific owner - [Function `get_epoch_mining_thres_upper`](#0x1_Globals_get_epoch_mining_thres_upper) - [Function `get_unlock`](#0x1_Globals_get_unlock) - [Function `get_min_blocks_epoch`](#0x1_Globals_get_min_blocks_epoch) +- [Function `get_vouch_threshold`](#0x1_Globals_get_vouch_threshold) +- [Function `get_signing_threshold`](#0x1_Globals_get_signing_threshold) - [Function `get_constants`](#0x1_Globals_get_constants) @@ -113,6 +115,18 @@ epoch by a miner to remain compliant
+
+
+vouch_threshold: u64 +
+
+ +
+
+signing_threshold_pct: u64 +
+
+
@@ -381,6 +395,56 @@ Get the mining threshold + + + + +## Function `get_vouch_threshold` + +Get the threshold for unrelated vouchers per validator + + +
public fun get_vouch_threshold(): u64
+
+ + + +
+Implementation + + +
public fun get_vouch_threshold(): u64 {
+  get_constants().vouch_threshold
+}
+
+ + + +
+ + + +## Function `get_signing_threshold` + +Get the threshold of number of signed blocks in an epoch per validator + + +
public fun get_signing_threshold(): u64
+
+ + + +
+Implementation + + +
public fun get_signing_threshold(): u64 {
+  get_constants().signing_threshold_pct
+}
+
+ + +
@@ -414,6 +478,8 @@ Get the constants for the current network epoch_mining_thres_upper: 1000, // upper bound unlimited epoch_slow_wallet_unlock: 10, min_blocks_per_epoch: 0, + vouch_threshold: 0, + signing_threshold_pct: 3, } }; @@ -428,6 +494,8 @@ Get the constants for the current network epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof. epoch_slow_wallet_unlock: 10000000, min_blocks_per_epoch: 1000, + vouch_threshold: 0, + signing_threshold_pct: 3, } } else { return GlobalConstants { @@ -445,6 +513,8 @@ Get the constants for the current network epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof. epoch_slow_wallet_unlock: 1000 * COIN_SCALING_FACTOR, // approx 10 years for largest accounts in genesis. min_blocks_per_epoch: 10000, + vouch_threshold: 2, // Production is 2 vouchers per validator + signing_threshold_pct: 3, } } } diff --git a/language/diem-framework/modules/doc/Oracle.md b/language/diem-framework/modules/doc/Oracle.md index d954b52341..bc20acc93b 100644 --- a/language/diem-framework/modules/doc/Oracle.md +++ b/language/diem-framework/modules/doc/Oracle.md @@ -15,10 +15,13 @@ - [Function `handler`](#0x1_Oracle_handler) - [Function `upgrade_handler`](#0x1_Oracle_upgrade_handler) - [Function `upgrade_handler_hash`](#0x1_Oracle_upgrade_handler_hash) +- [Function `revoke_my_votes`](#0x1_Oracle_revoke_my_votes) +- [Function `revoke_vote`](#0x1_Oracle_revoke_vote) - [Function `increment_vote_count`](#0x1_Oracle_increment_vote_count) - [Function `increment_vote_count_hash`](#0x1_Oracle_increment_vote_count_hash) - [Function `check_consensus`](#0x1_Oracle_check_consensus) - [Function `enter_new_upgrade_round`](#0x1_Oracle_enter_new_upgrade_round) +- [Function `vm_expire_upgrade`](#0x1_Oracle_vm_expire_upgrade) - [Function `tally_upgrade`](#0x1_Oracle_tally_upgrade) - [Function `check_upgrade`](#0x1_Oracle_check_upgrade) - [Function `get_weight`](#0x1_Oracle_get_weight) @@ -535,7 +538,9 @@ }; // if the sender has voted, do nothing - if (Vector::contains<address>(&upgrade_oracle.validators_voted, &sender)) {return}; + if (Vector::contains<address>(&upgrade_oracle.validators_voted, &sender)) { + assert(false, Errors::invalid_argument(VOTE_TYPE_INVALID)); + }; let vote_weight = get_weight(sender, VOTE_TYPE_UPGRADE); @@ -559,6 +564,63 @@ + + + + +## Function `revoke_my_votes` + + + +
public fun revoke_my_votes(sender: &signer)
+
+ + + +
+Implementation + + +
public fun revoke_my_votes(sender: &signer) acquires Oracles {
+  let addr = Signer::address_of(sender);
+  revoke_vote(addr);
+}
+
+ + + +
+ + + +## Function `revoke_vote` + + + +
fun revoke_vote(addr: address)
+
+ + + +
+Implementation + + +
fun revoke_vote(addr: address) acquires Oracles{
+  let upgrade_oracle = &mut borrow_global_mut<Oracles>(CoreAddresses::DIEM_ROOT_ADDRESS()).upgrade;
+  let (is_found, idx) = Vector::index_of<address>(&upgrade_oracle.validators_voted, &addr);
+
+  if (is_found) {
+    Vector::remove(&mut upgrade_oracle.votes, idx);
+    Vector::remove(&mut upgrade_oracle.validators_voted, idx);
+    tally_upgrade(upgrade_oracle, VOTE_TYPE_UPGRADE);
+  };
+
+}
+
+ + +
@@ -706,6 +768,34 @@ + + + + +## Function `vm_expire_upgrade` + + + +
fun vm_expire_upgrade(vm: &signer)
+
+ + + +
+Implementation + + +
fun vm_expire_upgrade(vm: &signer) acquires Oracles {
+  assert(Signer::address_of(vm) == CoreAddresses::DIEM_ROOT_ADDRESS(), Errors::requires_role(150003));
+  let upgrade_oracle = &mut borrow_global_mut<Oracles>(CoreAddresses::DIEM_ROOT_ADDRESS()).upgrade;
+  let threshold = get_threshold(VOTE_TYPE_PROPORTIONAL_VOTING_POWER);
+  let result = check_consensus(&upgrade_oracle.vote_counts, threshold);
+  upgrade_oracle.consensus = result
+}
+
+ + +
@@ -723,7 +813,7 @@ Implementation -
fun tally_upgrade (upgrade_oracle: &mut UpgradeOracle, type: u8) {
+
fun tally_upgrade(upgrade_oracle: &mut UpgradeOracle, type: u8) {
   let threshold = get_threshold(type);
   let result = check_consensus(&upgrade_oracle.vote_counts, threshold);
 
diff --git a/language/diem-framework/modules/doc/Stats.md b/language/diem-framework/modules/doc/Stats.md
index 8668e5ca4c..a04e8d7f44 100644
--- a/language/diem-framework/modules/doc/Stats.md
+++ b/language/diem-framework/modules/doc/Stats.md
@@ -29,6 +29,7 @@
 
use 0x1::CoreAddresses;
 use 0x1::Errors;
 use 0x1::FixedPoint32;
+use 0x1::Globals;
 use 0x1::Signer;
 use 0x1::Testnet;
 use 0x1::Vector;
@@ -331,7 +332,10 @@
   assert(sender == CoreAddresses::DIEM_ROOT_ADDRESS(), Errors::requires_role(190006));
   let range = height_end-height_start;
   // TODO: Change to 5 percent
-  let threshold_signing = FixedPoint32::multiply_u64(range, FixedPoint32::create_from_rational(5, 100));
+  let threshold_signing = FixedPoint32::multiply_u64(
+    range,
+    FixedPoint32::create_from_rational(Globals::get_signing_threshold(), 100)
+  );
   if (node_current_votes(vm, node_addr) >  threshold_signing) { return true };
   return false
 }
diff --git a/language/diem-framework/modules/doc/TowerState.md b/language/diem-framework/modules/doc/TowerState.md
index 3dd834bcc7..b32e91fa38 100644
--- a/language/diem-framework/modules/doc/TowerState.md
+++ b/language/diem-framework/modules/doc/TowerState.md
@@ -23,6 +23,7 @@
 -  [Function `genesis_helper`](#0x1_TowerState_genesis_helper)
 -  [Function `commit_state`](#0x1_TowerState_commit_state)
 -  [Function `commit_state_by_operator`](#0x1_TowerState_commit_state_by_operator)
+-  [Function `check_difficulty`](#0x1_TowerState_check_difficulty)
 -  [Function `verify_and_update_state`](#0x1_TowerState_verify_and_update_state)
 -  [Function `update_epoch_metrics_vals`](#0x1_TowerState_update_epoch_metrics_vals)
 -  [Function `node_above_thresh`](#0x1_TowerState_node_above_thresh)
@@ -442,9 +443,9 @@ the miner last created a new account
       });
     } else {
       move_to<VDFDifficulty>(vm, VDFDifficulty {
-        difficulty: 5000000,
+        difficulty: 120000000,
         security: 512,
-        prev_diff: 5000000,
+        prev_diff: 120000000,
         prev_sec: 512,
       });
     }
@@ -739,7 +740,7 @@ Permissions: PUBLIC, ANYONE
 ) acquires TowerProofHistory, TowerList, TowerCounter, VDFDifficulty {
   // Get address, assumes the sender is the signer.
   let miner_addr = Signer::address_of(miner_sign);
-  let diff = borrow_global_mut<VDFDifficulty>(CoreAddresses::VM_RESERVED_ADDRESS());
+  // let diff = borrow_global<VDFDifficulty>(CoreAddresses::VM_RESERVED_ADDRESS());
 
   // This may be the 0th proof of an end user that hasn't had tower state initialized
   if (!is_init(miner_addr)) {
@@ -755,27 +756,28 @@ Permissions: PUBLIC, ANYONE
     return
   };
 
+  check_difficulty(miner_addr, &proof);
 
-  // Skip this check on local tests, we need tests to send different difficulties.
-  if (!Testnet::is_testnet()){
-    // Get vdf difficulty constant. Will be different in tests than in production.
+  // // Skip this check on local tests, we need tests to send different difficulties.
+  // if (!Testnet::is_testnet()){
+  //   // Get vdf difficulty constant. Will be different in tests than in production.
 
-    // need to also give allowance for user's first proof in epoch to be in the last proof.
-    if (get_count_in_epoch(miner_addr) == 0) {
-      // first proof in this epoch, can be either the previous difficulty or the current one
-      let is_diff = &proof.difficulty == &diff.difficulty ||
-      &proof.difficulty == &diff.prev_diff;
+  //   // need to also give allowance for user's first proof in epoch to be in the last proof.
+  //   if (get_count_in_epoch(miner_addr) == 0) {
+  //     // first proof in this epoch, can be either the previous difficulty or the current one
+  //     let is_diff = &proof.difficulty == &diff.difficulty ||
+  //     &proof.difficulty == &diff.prev_diff;
 
-      let is_sec = &proof.difficulty == &diff.security ||
-      &proof.difficulty == &diff.prev_sec;
+  //     let is_sec = &proof.security == &diff.security ||
+  //     &proof.security == &diff.prev_sec;
 
-      assert(is_diff, Errors::invalid_argument(130102));
-      assert(is_sec, Errors::invalid_argument(13010202));
-    } else {
-      assert(&proof.difficulty == &diff.difficulty, Errors::invalid_argument(130102));
-      assert(&proof.security == &diff.security, Errors::invalid_argument(13010202));
-    };
-  };
+  //     assert(is_diff, Errors::invalid_argument(130102));
+  //     assert(is_sec, Errors::invalid_argument(13010202));
+  //   } else {
+  //     assert(&proof.difficulty == &diff.difficulty, Errors::invalid_argument(130102));
+  //     assert(&proof.security == &diff.security, Errors::invalid_argument(13010202));
+  //   };
+  // };
   // Process the proof
   verify_and_update_state(miner_addr, proof, true);
 }
@@ -804,7 +806,7 @@ Permissions: PUBLIC, ANYONE
   operator_sig: &signer,
   miner_addr: address,
   proof: Proof
-) acquires TowerProofHistory, TowerList, TowerCounter {
+) acquires TowerProofHistory, TowerList, TowerCounter, VDFDifficulty {
 
   // Check the signer is in fact an operator delegated by the owner.
 
@@ -816,19 +818,55 @@ Permissions: PUBLIC, ANYONE
   // 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()){
-    assert(&proof.difficulty == &Globals::get_vdf_difficulty_baseline(), Errors::invalid_argument(130105));
-    assert(&proof.security == &Globals::get_vdf_difficulty_baseline(), Errors::invalid_state(130106));
-  };
+  check_difficulty(miner_addr, &proof);
 
   // Process the proof
   verify_and_update_state(miner_addr, proof, true);
 
-  // TODO: The operator mining needs its own struct to count mining.
-  // For now it is implicit there is only 1 operator per validator,
-  // and that the fullnode state is the place to count.
-  // This will require a breaking change to TowerState
-  // FullnodeState::inc_proof_by_operator(operator_sig, miner_addr);
+}
+
+ + + + + + + +## Function `check_difficulty` + + + +
fun check_difficulty(miner_addr: address, proof: &TowerState::Proof)
+
+ + + +
+Implementation + + +
fun check_difficulty(miner_addr: address, proof: &Proof) acquires TowerProofHistory, VDFDifficulty {
+  if (!Testnet::is_testnet()){
+    // Get vdf difficulty constant. Will be different in tests than in production.ex
+    let diff = borrow_global<VDFDifficulty>(CoreAddresses::VM_RESERVED_ADDRESS());
+
+    // need to also give allowance for user's first proof in epoch to be in the last proof.
+    if (get_count_in_epoch(miner_addr) == 0) {
+      // first proof in this epoch, can be either the previous difficulty or the current one
+      let is_diff = &proof.difficulty == &diff.difficulty ||
+      &proof.difficulty == &diff.prev_diff;
+
+      let is_sec = &proof.security == &diff.security ||
+      &proof.security == &diff.prev_sec;
+
+      assert(is_diff, Errors::invalid_argument(130102));
+      assert(is_sec, Errors::invalid_argument(13010202));
+    } else {
+      assert(&proof.difficulty == &diff.difficulty, Errors::invalid_argument(130102));
+      assert(&proof.security == &diff.security, Errors::invalid_argument(13010202));
+    };
+  };
+
 }
 
diff --git a/language/diem-framework/modules/doc/Vouch.md b/language/diem-framework/modules/doc/Vouch.md index 48867f4cfa..cb60a37ecc 100644 --- a/language/diem-framework/modules/doc/Vouch.md +++ b/language/diem-framework/modules/doc/Vouch.md @@ -20,9 +20,8 @@
use 0x1::Ancestry;
 use 0x1::CoreAddresses;
 use 0x1::DiemSystem;
+use 0x1::Globals;
 use 0x1::Signer;
-use 0x1::StagingNet;
-use 0x1::Testnet;
 use 0x1::ValidatorUniverse;
 use 0x1::Vector;
 
@@ -355,15 +354,11 @@
public fun unrelated_buddies_above_thresh(val: address): bool acquires Vouch{
-  if (Testnet::is_testnet() || StagingNet::is_staging_net()) {
-    return true
-  };
-
   if (!exists<Vouch>(val)) return false;
 
   let len = Vector::length(&unrelated_buddies(val));
 
-  (len >= 4) // TODO: move to Globals
+  (len >= Globals::get_vouch_threshold())
 }
 
diff --git a/language/diem-framework/modules/doc/ol_oracle.md b/language/diem-framework/modules/doc/ol_oracle.md index ae7a5ae46b..c8b3782072 100644 --- a/language/diem-framework/modules/doc/ol_oracle.md +++ b/language/diem-framework/modules/doc/ol_oracle.md @@ -6,6 +6,7 @@ - [Function `ol_oracle_tx`](#0x1_OracleScripts_ol_oracle_tx) +- [Function `ol_revoke_vote`](#0x1_OracleScripts_ol_revoke_vote) - [Function `ol_delegate_vote`](#0x1_OracleScripts_ol_delegate_vote) - [Function `ol_enable_delegation`](#0x1_OracleScripts_ol_enable_delegation) - [Function `ol_remove_delegation`](#0x1_OracleScripts_ol_remove_delegation) @@ -38,6 +39,30 @@ +
+ + + +## Function `ol_revoke_vote` + + + +
public(script) fun ol_revoke_vote(sender: signer)
+
+ + + +
+Implementation + + +
public(script) fun ol_revoke_vote(sender: signer) {
+    Oracle::revoke_my_votes(&sender);
+}
+
+ + +
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/EpochBoundary.md b/language/diem-framework/releases/artifacts/current/docs/modules/EpochBoundary.md index 4c4a58ebcf..a10ac70563 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/EpochBoundary.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/EpochBoundary.md @@ -269,7 +269,7 @@ // can't be more than index of accounts i < Vector::length(&top_accounts) && // the new proposed set can only only expand by 15% - Vector::length(&proposed_set) < len_proven_nodes + max_unproven_nodes && + Vector::length(&proposed_set) < (len_proven_nodes + max_unproven_nodes) && // Validator set can only be as big as the maximum set size Vector::length(&proposed_set) < Globals::get_max_validators_per_set() ) { @@ -305,7 +305,7 @@ // if we are failing to qualify anyone. Pick top 1/2 of validator set by proposals. They are probably online. - if (Vector::length<address>(&proposed_set) <= 3) proposed_set = Stats::get_sorted_vals_by_props(vm, Vector::length<address>(&proposed_set) / 2); + if (Vector::length<address>(&proposed_set) <= 3) proposed_set = Stats::get_sorted_vals_by_props(vm, Vector::length<address>(&top_accounts) / 2); // If still failing...in extreme case if we cannot qualify anyone. Don't change the validator set. diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Globals.md b/language/diem-framework/releases/artifacts/current/docs/modules/Globals.md index eaf56b8d63..70ad3c4823 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/Globals.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Globals.md @@ -24,6 +24,8 @@ This module provides global variables and constants that have no specific owner - [Function `get_epoch_mining_thres_upper`](#0x1_Globals_get_epoch_mining_thres_upper) - [Function `get_unlock`](#0x1_Globals_get_unlock) - [Function `get_min_blocks_epoch`](#0x1_Globals_get_min_blocks_epoch) +- [Function `get_vouch_threshold`](#0x1_Globals_get_vouch_threshold) +- [Function `get_signing_threshold`](#0x1_Globals_get_signing_threshold) - [Function `get_constants`](#0x1_Globals_get_constants) @@ -113,6 +115,18 @@ epoch by a miner to remain compliant
+
+
+vouch_threshold: u64 +
+
+ +
+
+signing_threshold_pct: u64 +
+
+
@@ -381,6 +395,56 @@ Get the mining threshold + + + + +## Function `get_vouch_threshold` + +Get the threshold for unrelated vouchers per validator + + +
public fun get_vouch_threshold(): u64
+
+ + + +
+Implementation + + +
public fun get_vouch_threshold(): u64 {
+  get_constants().vouch_threshold
+}
+
+ + + +
+ + + +## Function `get_signing_threshold` + +Get the threshold of number of signed blocks in an epoch per validator + + +
public fun get_signing_threshold(): u64
+
+ + + +
+Implementation + + +
public fun get_signing_threshold(): u64 {
+  get_constants().signing_threshold_pct
+}
+
+ + +
@@ -414,6 +478,8 @@ Get the constants for the current network epoch_mining_thres_upper: 1000, // upper bound unlimited epoch_slow_wallet_unlock: 10, min_blocks_per_epoch: 0, + vouch_threshold: 0, + signing_threshold_pct: 3, } }; @@ -428,6 +494,8 @@ Get the constants for the current network epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof. epoch_slow_wallet_unlock: 10000000, min_blocks_per_epoch: 1000, + vouch_threshold: 0, + signing_threshold_pct: 3, } } else { return GlobalConstants { @@ -445,6 +513,8 @@ Get the constants for the current network epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof. epoch_slow_wallet_unlock: 1000 * COIN_SCALING_FACTOR, // approx 10 years for largest accounts in genesis. min_blocks_per_epoch: 10000, + vouch_threshold: 2, // Production is 2 vouchers per validator + signing_threshold_pct: 3, } } } diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Oracle.md b/language/diem-framework/releases/artifacts/current/docs/modules/Oracle.md index d954b52341..bc20acc93b 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/Oracle.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Oracle.md @@ -15,10 +15,13 @@ - [Function `handler`](#0x1_Oracle_handler) - [Function `upgrade_handler`](#0x1_Oracle_upgrade_handler) - [Function `upgrade_handler_hash`](#0x1_Oracle_upgrade_handler_hash) +- [Function `revoke_my_votes`](#0x1_Oracle_revoke_my_votes) +- [Function `revoke_vote`](#0x1_Oracle_revoke_vote) - [Function `increment_vote_count`](#0x1_Oracle_increment_vote_count) - [Function `increment_vote_count_hash`](#0x1_Oracle_increment_vote_count_hash) - [Function `check_consensus`](#0x1_Oracle_check_consensus) - [Function `enter_new_upgrade_round`](#0x1_Oracle_enter_new_upgrade_round) +- [Function `vm_expire_upgrade`](#0x1_Oracle_vm_expire_upgrade) - [Function `tally_upgrade`](#0x1_Oracle_tally_upgrade) - [Function `check_upgrade`](#0x1_Oracle_check_upgrade) - [Function `get_weight`](#0x1_Oracle_get_weight) @@ -535,7 +538,9 @@ }; // if the sender has voted, do nothing - if (Vector::contains<address>(&upgrade_oracle.validators_voted, &sender)) {return}; + if (Vector::contains<address>(&upgrade_oracle.validators_voted, &sender)) { + assert(false, Errors::invalid_argument(VOTE_TYPE_INVALID)); + }; let vote_weight = get_weight(sender, VOTE_TYPE_UPGRADE); @@ -559,6 +564,63 @@ + + + + +## Function `revoke_my_votes` + + + +
public fun revoke_my_votes(sender: &signer)
+
+ + + +
+Implementation + + +
public fun revoke_my_votes(sender: &signer) acquires Oracles {
+  let addr = Signer::address_of(sender);
+  revoke_vote(addr);
+}
+
+ + + +
+ + + +## Function `revoke_vote` + + + +
fun revoke_vote(addr: address)
+
+ + + +
+Implementation + + +
fun revoke_vote(addr: address) acquires Oracles{
+  let upgrade_oracle = &mut borrow_global_mut<Oracles>(CoreAddresses::DIEM_ROOT_ADDRESS()).upgrade;
+  let (is_found, idx) = Vector::index_of<address>(&upgrade_oracle.validators_voted, &addr);
+
+  if (is_found) {
+    Vector::remove(&mut upgrade_oracle.votes, idx);
+    Vector::remove(&mut upgrade_oracle.validators_voted, idx);
+    tally_upgrade(upgrade_oracle, VOTE_TYPE_UPGRADE);
+  };
+
+}
+
+ + +
@@ -706,6 +768,34 @@ + + + + +## Function `vm_expire_upgrade` + + + +
fun vm_expire_upgrade(vm: &signer)
+
+ + + +
+Implementation + + +
fun vm_expire_upgrade(vm: &signer) acquires Oracles {
+  assert(Signer::address_of(vm) == CoreAddresses::DIEM_ROOT_ADDRESS(), Errors::requires_role(150003));
+  let upgrade_oracle = &mut borrow_global_mut<Oracles>(CoreAddresses::DIEM_ROOT_ADDRESS()).upgrade;
+  let threshold = get_threshold(VOTE_TYPE_PROPORTIONAL_VOTING_POWER);
+  let result = check_consensus(&upgrade_oracle.vote_counts, threshold);
+  upgrade_oracle.consensus = result
+}
+
+ + +
@@ -723,7 +813,7 @@ Implementation -
fun tally_upgrade (upgrade_oracle: &mut UpgradeOracle, type: u8) {
+
fun tally_upgrade(upgrade_oracle: &mut UpgradeOracle, type: u8) {
   let threshold = get_threshold(type);
   let result = check_consensus(&upgrade_oracle.vote_counts, threshold);
 
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Stats.md b/language/diem-framework/releases/artifacts/current/docs/modules/Stats.md
index 8668e5ca4c..a04e8d7f44 100644
--- a/language/diem-framework/releases/artifacts/current/docs/modules/Stats.md
+++ b/language/diem-framework/releases/artifacts/current/docs/modules/Stats.md
@@ -29,6 +29,7 @@
 
use 0x1::CoreAddresses;
 use 0x1::Errors;
 use 0x1::FixedPoint32;
+use 0x1::Globals;
 use 0x1::Signer;
 use 0x1::Testnet;
 use 0x1::Vector;
@@ -331,7 +332,10 @@
   assert(sender == CoreAddresses::DIEM_ROOT_ADDRESS(), Errors::requires_role(190006));
   let range = height_end-height_start;
   // TODO: Change to 5 percent
-  let threshold_signing = FixedPoint32::multiply_u64(range, FixedPoint32::create_from_rational(5, 100));
+  let threshold_signing = FixedPoint32::multiply_u64(
+    range,
+    FixedPoint32::create_from_rational(Globals::get_signing_threshold(), 100)
+  );
   if (node_current_votes(vm, node_addr) >  threshold_signing) { return true };
   return false
 }
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md b/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md
index 3dd834bcc7..b32e91fa38 100644
--- a/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md
+++ b/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md
@@ -23,6 +23,7 @@
 -  [Function `genesis_helper`](#0x1_TowerState_genesis_helper)
 -  [Function `commit_state`](#0x1_TowerState_commit_state)
 -  [Function `commit_state_by_operator`](#0x1_TowerState_commit_state_by_operator)
+-  [Function `check_difficulty`](#0x1_TowerState_check_difficulty)
 -  [Function `verify_and_update_state`](#0x1_TowerState_verify_and_update_state)
 -  [Function `update_epoch_metrics_vals`](#0x1_TowerState_update_epoch_metrics_vals)
 -  [Function `node_above_thresh`](#0x1_TowerState_node_above_thresh)
@@ -442,9 +443,9 @@ the miner last created a new account
       });
     } else {
       move_to<VDFDifficulty>(vm, VDFDifficulty {
-        difficulty: 5000000,
+        difficulty: 120000000,
         security: 512,
-        prev_diff: 5000000,
+        prev_diff: 120000000,
         prev_sec: 512,
       });
     }
@@ -739,7 +740,7 @@ Permissions: PUBLIC, ANYONE
 ) acquires TowerProofHistory, TowerList, TowerCounter, VDFDifficulty {
   // Get address, assumes the sender is the signer.
   let miner_addr = Signer::address_of(miner_sign);
-  let diff = borrow_global_mut<VDFDifficulty>(CoreAddresses::VM_RESERVED_ADDRESS());
+  // let diff = borrow_global<VDFDifficulty>(CoreAddresses::VM_RESERVED_ADDRESS());
 
   // This may be the 0th proof of an end user that hasn't had tower state initialized
   if (!is_init(miner_addr)) {
@@ -755,27 +756,28 @@ Permissions: PUBLIC, ANYONE
     return
   };
 
+  check_difficulty(miner_addr, &proof);
 
-  // Skip this check on local tests, we need tests to send different difficulties.
-  if (!Testnet::is_testnet()){
-    // Get vdf difficulty constant. Will be different in tests than in production.
+  // // Skip this check on local tests, we need tests to send different difficulties.
+  // if (!Testnet::is_testnet()){
+  //   // Get vdf difficulty constant. Will be different in tests than in production.
 
-    // need to also give allowance for user's first proof in epoch to be in the last proof.
-    if (get_count_in_epoch(miner_addr) == 0) {
-      // first proof in this epoch, can be either the previous difficulty or the current one
-      let is_diff = &proof.difficulty == &diff.difficulty ||
-      &proof.difficulty == &diff.prev_diff;
+  //   // need to also give allowance for user's first proof in epoch to be in the last proof.
+  //   if (get_count_in_epoch(miner_addr) == 0) {
+  //     // first proof in this epoch, can be either the previous difficulty or the current one
+  //     let is_diff = &proof.difficulty == &diff.difficulty ||
+  //     &proof.difficulty == &diff.prev_diff;
 
-      let is_sec = &proof.difficulty == &diff.security ||
-      &proof.difficulty == &diff.prev_sec;
+  //     let is_sec = &proof.security == &diff.security ||
+  //     &proof.security == &diff.prev_sec;
 
-      assert(is_diff, Errors::invalid_argument(130102));
-      assert(is_sec, Errors::invalid_argument(13010202));
-    } else {
-      assert(&proof.difficulty == &diff.difficulty, Errors::invalid_argument(130102));
-      assert(&proof.security == &diff.security, Errors::invalid_argument(13010202));
-    };
-  };
+  //     assert(is_diff, Errors::invalid_argument(130102));
+  //     assert(is_sec, Errors::invalid_argument(13010202));
+  //   } else {
+  //     assert(&proof.difficulty == &diff.difficulty, Errors::invalid_argument(130102));
+  //     assert(&proof.security == &diff.security, Errors::invalid_argument(13010202));
+  //   };
+  // };
   // Process the proof
   verify_and_update_state(miner_addr, proof, true);
 }
@@ -804,7 +806,7 @@ Permissions: PUBLIC, ANYONE
   operator_sig: &signer,
   miner_addr: address,
   proof: Proof
-) acquires TowerProofHistory, TowerList, TowerCounter {
+) acquires TowerProofHistory, TowerList, TowerCounter, VDFDifficulty {
 
   // Check the signer is in fact an operator delegated by the owner.
 
@@ -816,19 +818,55 @@ Permissions: PUBLIC, ANYONE
   // 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()){
-    assert(&proof.difficulty == &Globals::get_vdf_difficulty_baseline(), Errors::invalid_argument(130105));
-    assert(&proof.security == &Globals::get_vdf_difficulty_baseline(), Errors::invalid_state(130106));
-  };
+  check_difficulty(miner_addr, &proof);
 
   // Process the proof
   verify_and_update_state(miner_addr, proof, true);
 
-  // TODO: The operator mining needs its own struct to count mining.
-  // For now it is implicit there is only 1 operator per validator,
-  // and that the fullnode state is the place to count.
-  // This will require a breaking change to TowerState
-  // FullnodeState::inc_proof_by_operator(operator_sig, miner_addr);
+}
+
+ + + + + + + +## Function `check_difficulty` + + + +
fun check_difficulty(miner_addr: address, proof: &TowerState::Proof)
+
+ + + +
+Implementation + + +
fun check_difficulty(miner_addr: address, proof: &Proof) acquires TowerProofHistory, VDFDifficulty {
+  if (!Testnet::is_testnet()){
+    // Get vdf difficulty constant. Will be different in tests than in production.ex
+    let diff = borrow_global<VDFDifficulty>(CoreAddresses::VM_RESERVED_ADDRESS());
+
+    // need to also give allowance for user's first proof in epoch to be in the last proof.
+    if (get_count_in_epoch(miner_addr) == 0) {
+      // first proof in this epoch, can be either the previous difficulty or the current one
+      let is_diff = &proof.difficulty == &diff.difficulty ||
+      &proof.difficulty == &diff.prev_diff;
+
+      let is_sec = &proof.security == &diff.security ||
+      &proof.security == &diff.prev_sec;
+
+      assert(is_diff, Errors::invalid_argument(130102));
+      assert(is_sec, Errors::invalid_argument(13010202));
+    } else {
+      assert(&proof.difficulty == &diff.difficulty, Errors::invalid_argument(130102));
+      assert(&proof.security == &diff.security, Errors::invalid_argument(13010202));
+    };
+  };
+
 }
 
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Vouch.md b/language/diem-framework/releases/artifacts/current/docs/modules/Vouch.md index 48867f4cfa..cb60a37ecc 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/Vouch.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/Vouch.md @@ -20,9 +20,8 @@
use 0x1::Ancestry;
 use 0x1::CoreAddresses;
 use 0x1::DiemSystem;
+use 0x1::Globals;
 use 0x1::Signer;
-use 0x1::StagingNet;
-use 0x1::Testnet;
 use 0x1::ValidatorUniverse;
 use 0x1::Vector;
 
@@ -355,15 +354,11 @@
public fun unrelated_buddies_above_thresh(val: address): bool acquires Vouch{
-  if (Testnet::is_testnet() || StagingNet::is_staging_net()) {
-    return true
-  };
-
   if (!exists<Vouch>(val)) return false;
 
   let len = Vector::length(&unrelated_buddies(val));
 
-  (len >= 4) // TODO: move to Globals
+  (len >= Globals::get_vouch_threshold())
 }
 
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/ol_oracle.md b/language/diem-framework/releases/artifacts/current/docs/modules/ol_oracle.md index ae7a5ae46b..c8b3782072 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/ol_oracle.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/ol_oracle.md @@ -6,6 +6,7 @@ - [Function `ol_oracle_tx`](#0x1_OracleScripts_ol_oracle_tx) +- [Function `ol_revoke_vote`](#0x1_OracleScripts_ol_revoke_vote) - [Function `ol_delegate_vote`](#0x1_OracleScripts_ol_delegate_vote) - [Function `ol_enable_delegation`](#0x1_OracleScripts_ol_enable_delegation) - [Function `ol_remove_delegation`](#0x1_OracleScripts_ol_remove_delegation) @@ -38,6 +39,30 @@ +
+ + + +## Function `ol_revoke_vote` + + + +
public(script) fun ol_revoke_vote(sender: signer)
+
+ + + +
+Implementation + + +
public(script) fun ol_revoke_vote(sender: signer) {
+    Oracle::revoke_my_votes(&sender);
+}
+
+ + +
diff --git a/language/diem-framework/releases/artifacts/current/modules/023_Stats.mv b/language/diem-framework/releases/artifacts/current/modules/023_Stats.mv deleted file mode 100644 index 93b4ca32ee..0000000000 Binary files a/language/diem-framework/releases/artifacts/current/modules/023_Stats.mv and /dev/null differ diff --git a/language/diem-framework/releases/artifacts/current/modules/024_StagingNet.mv b/language/diem-framework/releases/artifacts/current/modules/024_StagingNet.mv deleted file mode 100644 index e83a2a6717..0000000000 Binary files a/language/diem-framework/releases/artifacts/current/modules/024_StagingNet.mv and /dev/null differ diff --git a/language/diem-framework/releases/artifacts/current/modules/025_Hash.mv b/language/diem-framework/releases/artifacts/current/modules/025_Hash.mv deleted file mode 100644 index cd88b742d2..0000000000 Binary files a/language/diem-framework/releases/artifacts/current/modules/025_Hash.mv and /dev/null differ diff --git a/language/diem-framework/releases/artifacts/current/modules/026_GAS.mv b/language/diem-framework/releases/artifacts/current/modules/026_GAS.mv deleted file mode 100644 index a793c6e901..0000000000 Binary files a/language/diem-framework/releases/artifacts/current/modules/026_GAS.mv and /dev/null differ diff --git a/language/diem-framework/releases/artifacts/current/modules/027_Globals.mv b/language/diem-framework/releases/artifacts/current/modules/027_Globals.mv deleted file mode 100644 index a34033cdf3..0000000000 Binary files a/language/diem-framework/releases/artifacts/current/modules/027_Globals.mv and /dev/null differ diff --git a/language/diem-framework/releases/artifacts/current/modules/036_Vouch.mv b/language/diem-framework/releases/artifacts/current/modules/036_Vouch.mv index e8b30a089b..ef336bee81 100644 Binary files a/language/diem-framework/releases/artifacts/current/modules/036_Vouch.mv and b/language/diem-framework/releases/artifacts/current/modules/036_Vouch.mv differ diff --git a/language/diem-framework/releases/artifacts/current/transaction_script_builder.rs b/language/diem-framework/releases/artifacts/current/transaction_script_builder.rs index 0d178afe98..1600bf834d 100644 --- a/language/diem-framework/releases/artifacts/current/transaction_script_builder.rs +++ b/language/diem-framework/releases/artifacts/current/transaction_script_builder.rs @@ -2273,6 +2273,8 @@ pub enum ScriptFunctionCall { /// Alice can remove Bob as the delegate with this function. OlRemoveDelegation {}, + OlRevokeVote {}, + /// # Summary /// Transfers a given number of coins in a specified currency from one account to another. /// Transfers over a specified amount defined on-chain that are between two different VASPs, or @@ -3712,6 +3714,7 @@ impl ScriptFunctionCall { ram, } => encode_ol_reconfig_bulk_update_setup_script_function(alice, bob, carol, sha, ram), OlRemoveDelegation {} => encode_ol_remove_delegation_script_function(), + OlRevokeVote {} => encode_ol_revoke_vote_script_function(), PeerToPeerWithMetadata { currency, payee, @@ -5174,6 +5177,18 @@ pub fn encode_ol_remove_delegation_script_function() -> TransactionPayload { )) } +pub fn encode_ol_revoke_vote_script_function() -> TransactionPayload { + TransactionPayload::ScriptFunction(ScriptFunction::new( + ModuleId::new( + AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), + ident_str!("OracleScripts").to_owned(), + ), + ident_str!("ol_revoke_vote").to_owned(), + vec![], + vec![], + )) +} + /// # Summary /// Transfers a given number of coins in a specified currency from one account to another. /// Transfers over a specified amount defined on-chain that are between two different VASPs, or @@ -8621,6 +8636,16 @@ fn decode_ol_remove_delegation_script_function( } } +fn decode_ol_revoke_vote_script_function( + payload: &TransactionPayload, +) -> Option { + if let TransactionPayload::ScriptFunction(_script) = payload { + Some(ScriptFunctionCall::OlRevokeVote {}) + } else { + None + } +} + fn decode_peer_to_peer_with_metadata_script_function( payload: &TransactionPayload, ) -> Option { @@ -9557,6 +9582,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy&1 | tee ${DATA_PATH}/logs/node.log diff --git a/language/diem-tools/writeset-transaction-generator/src/main.rs b/language/diem-tools/writeset-transaction-generator/src/main.rs index bbe4b02d2c..a2982335e5 100644 --- a/language/diem-tools/writeset-transaction-generator/src/main.rs +++ b/language/diem-tools/writeset-transaction-generator/src/main.rs @@ -56,6 +56,8 @@ enum Command { UpdateStdlib {}, #[structopt(name = "rescue")] Rescue { addresses: Vec}, + #[structopt(name = "upgrade-expire")] + UpgradeExpire { addresses: Vec }, #[structopt(name = "recovery")] RecoveryMode { addresses: Vec }, // #[structopt(name = "hotfix")] @@ -169,6 +171,7 @@ fn main() -> Result<()> { opt.block_height.expect("need to provide --block-height"), ), Command::Rescue { addresses } => ol_writset_encode_rescue(opt.db.unwrap(), addresses, opt.recovery_epoch), + Command::UpgradeExpire { addresses } => ol_writeset_oracle_expire(opt.db.unwrap(), addresses, opt.recovery_epoch.expect("need to provide --recovery-epoch")), Command::Timestamp {} => ol_writset_update_timestamp( opt.db.unwrap(), opt.block_height.expect("need to provide --block-height"), diff --git a/language/diem-tools/writeset-transaction-generator/src/ol_changesets/migrations.rs b/language/diem-tools/writeset-transaction-generator/src/ol_changesets/migrations.rs index 53f46fd62c..c44bfce905 100644 --- a/language/diem-tools/writeset-transaction-generator/src/ol_changesets/migrations.rs +++ b/language/diem-tools/writeset-transaction-generator/src/ol_changesets/migrations.rs @@ -207,3 +207,32 @@ pub fn parse_makewhole_file(makewhole_file: PathBuf) -> Result Result { + + let db = DiemDebugger::db(path)?; + let v = db.get_latest_version()?; + + db.run_session_at_version(v, None, |session| { + let mut gas_status = GasStatus::new_unmetered(); + let log_context = NoContextLog::new(); + let args = vec![ + MoveValue::Signer(diem_root_address()), + ]; + + session + .execute_function( + &ModuleId::new( + account_config::CORE_CODE_ADDRESS, + Identifier::new("Oracle").unwrap(), + ), + &Identifier::new("vm_expire_upgrade").unwrap(), + vec![], + serialize_values(&args), + &mut gas_status, + &log_context, + ) + .unwrap(); // TODO: don't use unwraps. + Ok(()) + }) +} diff --git a/language/diem-tools/writeset-transaction-generator/src/ol_changesets/reconfig.rs b/language/diem-tools/writeset-transaction-generator/src/ol_changesets/reconfig.rs index 91f74c0ef2..598f2f86c9 100644 --- a/language/diem-tools/writeset-transaction-generator/src/ol_changesets/reconfig.rs +++ b/language/diem-tools/writeset-transaction-generator/src/ol_changesets/reconfig.rs @@ -8,13 +8,11 @@ use diem_transaction_replay::DiemDebugger; use diem_types::{ account_address::AccountAddress, account_config::{diem_root_address, NewEpochEvent}, + block_metadata::DiemBlockResource, contract_event::ContractEvent, transaction::{ChangeSet, TransactionArgument}, }; -use move_core_types::{ - language_storage::TypeTag, - move_resource::MoveStructType, -}; +use move_core_types::{language_storage::TypeTag, move_resource::MoveStructType}; use ol_types::epoch_timer::EpochTimerResource; use resource_viewer::AnnotatedMoveValue; @@ -43,7 +41,8 @@ pub fn ol_bulk_validators_changeset(path: PathBuf, vals: Vec) -> wrapper::function_changeset_from_db(path, vec![fnwrap]) } -pub fn ol_reconfig_changeset(path: PathBuf, height_now: u64) -> Result { +pub fn ol_reconfig_changeset(path: PathBuf) -> Result { + let height_now = ol_get_internal_blockheight(path.clone())?; let txn_args = vec![ TransactionArgument::Address(diem_root_address()), TransactionArgument::U64(height_now), @@ -71,18 +70,18 @@ pub fn mfg_epoch_event(epoch: u64, seq: u64) -> Result { )) } - -// TODO this doesn't work. +// TODO this doesn't work. Causes issues with epoch seq number already being bumped. pub fn ol_reset_epoch_counters( path: PathBuf, vals: Vec, - block_height: u64, + // block_height: u64, ) -> Result { + let block_height = ol_get_internal_blockheight(path.clone())?; let txn_args = vec![ TransactionArgument::Address(diem_root_address()), - TransactionArgument::AddressVector(vals), - TransactionArgument::AddressVector(vec![]), - TransactionArgument::U64(block_height + 1), + TransactionArgument::AddressVector(vals), // new validator set + TransactionArgument::AddressVector(vec![]), // outgoing compliant + TransactionArgument::U64(block_height + 1), // start of epoch ]; let fnwrap = FunctionWrapper { @@ -94,6 +93,20 @@ pub fn ol_reset_epoch_counters( wrapper::function_changeset_from_db(path, vec![fnwrap]) } +pub fn ol_expire_oracle_upgrade(path: PathBuf) -> Result { + let txn_args = vec![ + TransactionArgument::Address(diem_root_address()), + ]; + + let fnwrap = FunctionWrapper { + module_name: "Oracle".to_string(), + function_name: "vm_expire_upgrade".to_string(), + txn_args, + }; + + wrapper::function_changeset_from_db(path, vec![fnwrap]) +} + pub fn ol_epoch_timestamp_update(path: PathBuf) -> Result { let db = DiemDebugger::db(path)?; let v = db.get_latest_version()?; @@ -133,7 +146,6 @@ pub fn ol_epoch_timestamp_update(path: PathBuf) -> Result { bail!("could not get epoch timer state") } - pub fn ol_increment_timestamp(path: PathBuf) -> Result { let start = SystemTime::now(); let now = start.duration_since(UNIX_EPOCH)?; @@ -153,3 +165,36 @@ pub fn ol_increment_timestamp(path: PathBuf) -> Result { wrapper::function_changeset_from_db(path, vec![fnwrap]) } + +fn ol_get_internal_blockheight(path: PathBuf) -> Result { + let db = DiemDebugger::db(path)?; + let v = db.get_latest_version()?; + + // TODO: HELP! there must be a better way to get a MoveResource from db + if let Some(acc) = db.annotate_account_state_at_version(AccountAddress::ZERO, v, false)? { + let key = DiemBlockResource::struct_tag(); + let move_str = acc + .0 + .get(&key) + .expect("cannot get a value for DiemBlockResource"); + + // confirm the field exists. + let height = move_str.value.iter().find_map(|item| { + if let AnnotatedMoveValue::U64(u) = item.1 { + match item.0.as_str() { + "height" => Some(u), + _ => None, + } + } else { + None + } + }); + + match height { + Some(h) => return Ok(h), + None => bail!("could not get internal block height"), + } + }; + + bail!("could not get epoch height") +} diff --git a/language/diem-tools/writeset-transaction-generator/src/ol_changesets/wrapper.rs b/language/diem-tools/writeset-transaction-generator/src/ol_changesets/wrapper.rs index 2127f76896..b52f35ff83 100644 --- a/language/diem-tools/writeset-transaction-generator/src/ol_changesets/wrapper.rs +++ b/language/diem-tools/writeset-transaction-generator/src/ol_changesets/wrapper.rs @@ -30,7 +30,8 @@ pub fn function_changeset_from_db( let db = DiemDebugger::db(path)?; let v = db.get_latest_version()?; - dbg!(&v); + println!("Using DB at version: {}", &v); + db.run_session_at_version(v, None, |session| { let mut gas_status = GasStatus::new_unmetered(); let log_context = NoContextLog::new(); diff --git a/language/diem-tools/writeset-transaction-generator/src/ol_writesets.rs b/language/diem-tools/writeset-transaction-generator/src/ol_writesets.rs index a905c73271..e2f2ab1f40 100644 --- a/language/diem-tools/writeset-transaction-generator/src/ol_writesets.rs +++ b/language/diem-tools/writeset-transaction-generator/src/ol_writesets.rs @@ -24,7 +24,7 @@ pub fn ol_writeset_force_boundary( vals: Vec, block_height: u64, ) -> WriteSetPayload { - let cs = reconfig::ol_reset_epoch_counters(path, vals, block_height).unwrap(); + let cs = reconfig::ol_reset_epoch_counters(path, vals).unwrap(); WriteSetPayload::Direct(cs) } @@ -37,7 +37,7 @@ pub fn ol_writeset_stdlib_upgrade(path: PathBuf, height_now: u64) -> WriteSetPay // Take the stdlib upgrade change set. let stdlib_cs = encode_stdlib_upgrade_transaction(); - let reconfig = reconfig::ol_reconfig_changeset(path, height_now).unwrap(); + let reconfig = reconfig::ol_reconfig_changeset(path).unwrap(); WriteSetPayload::Direct(merge_change_set(stdlib_cs, reconfig).unwrap()) } @@ -47,7 +47,7 @@ pub fn ol_writeset_set_stagingnet(path: PathBuf, height_now: u64) -> WriteSetPay // Take the stdlib upgrade change set. let testnet = testnet::ol_staging_net_changeset(path.clone()).unwrap(); - let reconfig = reconfig::ol_reconfig_changeset(path, height_now).unwrap(); + let reconfig = reconfig::ol_reconfig_changeset(path).unwrap(); WriteSetPayload::Direct(merge_change_set(testnet, reconfig).unwrap()) } @@ -57,7 +57,7 @@ pub fn ol_writeset_set_testnet(path: PathBuf, height_now: u64) -> WriteSetPayloa // Take the stdlib upgrade change set. let testnet = testnet::ol_testnet_changeset(path.clone()).unwrap(); - let reconfig = reconfig::ol_reconfig_changeset(path, height_now).unwrap(); + let reconfig = reconfig::ol_reconfig_changeset(path).unwrap(); WriteSetPayload::Direct(merge_change_set(testnet, reconfig).unwrap()) } @@ -94,14 +94,15 @@ pub fn ol_writset_encode_rescue(path: PathBuf, vals: Vec, recove let stdlib_cs = stdlib::ol_fresh_stlib_changeset(path.clone()).unwrap(); // Changing the validators creates a new epoch boundary. But does not run the reconfiguration. - let boundary = reconfig::ol_bulk_validators_changeset(path.clone(), vals).unwrap(); + let boundary = reconfig::ol_reset_epoch_counters(path.clone(), vals.clone()).unwrap(); + let mut all_cs = vec![stdlib_cs, boundary]; // set recovery mode if the option was passed by commandline if let Some(end_epoch) = recovery_epoch { // NOTE: we are not using a fixed validator set here. Just using usual validator selection. - let recovery = stdlib::ol_set_epoch_recovery_mode(path.clone(), vec![], end_epoch).unwrap(); + let recovery = stdlib::ol_set_epoch_recovery_mode(path.clone(), vals, end_epoch).unwrap(); all_cs.push(recovery) } @@ -139,7 +140,7 @@ pub fn ol_writset_encode_migrations( let recovery = stdlib::ol_set_epoch_recovery_mode(path.clone(), vec![], recovery_epoch).unwrap(); - let boundary = reconfig::ol_reset_epoch_counters(path.clone(), vals, block_height).unwrap(); + let boundary = reconfig::ol_reset_epoch_counters(path.clone(), vals).unwrap(); // let new_cs = merge_change_set(stdlib_cs, boundary).unwrap(); let new_cs = merge_vec_changeset(vec![ancestry, makewhole, vouch, boundary, recovery]).unwrap(); @@ -147,6 +148,13 @@ pub fn ol_writset_encode_migrations( WriteSetPayload::Direct(new_cs) } +pub fn ol_writeset_oracle_expire(path: PathBuf, vals: Vec, recovery_epoch: u64,) -> WriteSetPayload { + let oracle_expiry = migrations::ol_expire_oracle_upgrade(path.clone()).unwrap(); + let recovery = + stdlib::ol_set_epoch_recovery_mode(path.clone(), vec![], recovery_epoch).unwrap(); + let new_cs = merge_vec_changeset(vec![oracle_expiry, recovery]).unwrap(); + WriteSetPayload::Direct(new_cs) +} /// set the EpochBoundary debug mode. pub fn ol_writeset_recovery_mode( path: PathBuf, @@ -171,21 +179,21 @@ pub fn ol_writset_update_timestamp(path: PathBuf, height_now: u64) -> WriteSetPa // Take the stdlib upgrade change set. let reconfig = - reconfig::ol_reconfig_changeset(path, height_now).expect("could not get reconfig writeset"); + reconfig::ol_reconfig_changeset(path).expect("could not get reconfig writeset"); WriteSetPayload::Direct(merge_change_set(timestamp, reconfig).unwrap()) } -pub fn ol_create_reconfig_payload(path: PathBuf, height_now: u64) -> WriteSetPayload { +pub fn ol_create_reconfig_payload(path: PathBuf, _height_now: u64) -> WriteSetPayload { WriteSetPayload::Direct( - reconfig::ol_reconfig_changeset(path, height_now) + reconfig::ol_reconfig_changeset(path) .expect("could not create reconfig change set"), ) } -pub fn ol_writeset_update_epoch_time(path: PathBuf, height_now: u64) -> WriteSetPayload { +pub fn ol_writeset_update_epoch_time(path: PathBuf, _height_now: u64) -> WriteSetPayload { let epoch_time = reconfig::ol_epoch_timestamp_update(path.clone()).unwrap(); - let reconfig = reconfig::ol_reconfig_changeset(path, height_now).unwrap(); + let reconfig = reconfig::ol_reconfig_changeset(path).unwrap(); WriteSetPayload::Direct(merge_change_set(epoch_time, reconfig).unwrap()) } diff --git a/language/move-lang/functional-tests/tests/0L/oracle/upgrade_delegation.move b/language/move-lang/functional-tests/tests/0L/oracle/upgrade_delegation.move index cbf5af10d3..e9dd3b25a3 100644 --- a/language/move-lang/functional-tests/tests/0L/oracle/upgrade_delegation.move +++ b/language/move-lang/functional-tests/tests/0L/oracle/upgrade_delegation.move @@ -28,6 +28,9 @@ script { } //check: EXECUTED +//// JIM PROXIES LUCY to vote on upgrades +//// THOMAS PROXIES ALICE to vote on upgrades + //! new-transaction //! sender: lucy script { @@ -156,6 +159,7 @@ script { // check: EXECUTED +// THOMAS SHOULD NOT BE ABLE TO VOTE, SINCE ALICE ALREADY VOTED FOR THEM //! new-transaction @@ -177,108 +181,4 @@ script { } } } -// check: EXECUTED - - - -//! new-transaction -//! sender: lucy -script { - use 0x1::Oracle; - use 0x1::Vector; - use 0x1::Upgrade; - use 0x1::Hash; - fun main(sender: signer){ - if (Oracle::delegation_enabled_upgrade()) { - let id = 2; - let data = b"hello"; - let hash = Hash::sha2_256(data); - Oracle::handler(&sender, id, hash); - let vec = Oracle::test_helper_query_oracle_votes(); - let e = *Vector::borrow
(&vec, 3); - assert(e == @{{lucy}}, 7357123401011000); - let e = *Vector::borrow
(&vec, 4); - assert(e == @{{jim}}, 7357123401011000); - - assert(Upgrade::has_upgrade() == false, 7357123401011000); - assert(Oracle::test_helper_check_upgrade() == false, 7357123401011001); - } - } -} -// check: EXECUTED - - -//! new-transaction -//! sender: jim -script { - use 0x1::Oracle; - use 0x1::Vector; - fun main(sender: signer){ - if (Oracle::delegation_enabled_upgrade()) { - let id = 1; - let data = b"hello"; - Oracle::handler(&sender, id, data); - // ensure jim's vote is not counted twice - let vec = Oracle::test_helper_query_oracle_votes(); - let e = Vector::length
(&vec); - assert(e == 5, 7357123401011002); - } - } -} -// check: EXECUTED - -//! new-transaction -//! sender: charlie -script { - use 0x1::Oracle; - use 0x1::Vector; - use 0x1::Upgrade; - use 0x1::Hash; - fun main(sender: signer){ - if (Oracle::delegation_enabled_upgrade()) { - let id = 2; - let data = b"hello"; - let hash = Hash::sha2_256(data); - Oracle::handler(&sender, id, hash); - let vec = Oracle::test_helper_query_oracle_votes(); - let e = *Vector::borrow
(&vec, 5); - assert(e == @{{charlie}}, 7357123401011000); - - assert(Upgrade::has_upgrade() == false, 7357123401011000); - assert(Oracle::test_helper_check_upgrade() == true, 7357123401011001); - } - } -} -// check: EXECUTED - - - - -// //! block-prologue -// //! proposer: bob -// //! block-time: 1 -// //! round: 2 - -// //! block-prologue -// //! proposer: bob -// //! block-time: 2 -// //! round: 2 - -// //! new-transaction -// //! sender: diemroot -// script { -// use 0x1::Upgrade; -// use 0x1::Vector; -// fun main(){ -// let (upgraded_version, payload, voters, height) = Upgrade::retrieve_latest_history(); - -// let validators = Vector::empty
(); -// Vector::push_back(&mut validators, @{{alice}}); -// Vector::push_back(&mut validators, @{{charlie}}); -// assert(upgraded_version == 0, 7357123401011000); -// assert(payload == b"hello", 7357123401011000); -// assert(Vector::compare(&voters, &validators), 7357123401011000); -// assert(height == 1, 7357123401011000); -// } -// } -// // check: EXECUTED +// check: ABORTED diff --git a/language/move-lang/functional-tests/tests/0L/oracle/upgrade_revoke.move b/language/move-lang/functional-tests/tests/0L/oracle/upgrade_revoke.move new file mode 100644 index 0000000000..a05a90de67 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/oracle/upgrade_revoke.move @@ -0,0 +1,65 @@ +//! account: alice, 1000000, 0, validator +//! account: bob, 1000000, 0, validator +//! account: charlie, 1000000, 0, validator + +//! new-transaction +//! sender: alice +script { + use 0x1::Oracle; + use 0x1::Vector; + use 0x1::Upgrade; + + fun main(sender: signer){ + let id = 1; + let data = b"hello"; + Oracle::handler(&sender, id, data); + let vec = Oracle::test_helper_query_oracle_votes(); + + let e = *Vector::borrow
(&vec, 0); + assert(e == @{{alice}}, 735701); + + assert(Upgrade::has_upgrade() == false, 735702); + + // revoke the vote + Oracle::revoke_my_votes(&sender); + let vec = Oracle::test_helper_query_oracle_votes(); + + let len = Vector::length
(&vec); + assert(len == 0, 735703); + } +} +// check: EXECUTED + + +/// VOTES AGAIN FOR DIFFERENT PAYLOAD + + +//! new-transaction +//! sender: alice +script { + use 0x1::Oracle; + use 0x1::Vector; + use 0x1::Upgrade; + + fun main(sender: signer){ + let id = 1; + let data = b"NEW PAYLOAD"; + Oracle::handler(&sender, id, data); + let vec = Oracle::test_helper_query_oracle_votes(); + + let e = *Vector::borrow
(&vec, 0); + assert(e == @{{alice}}, 735704); + + assert(Upgrade::has_upgrade() == false, 735705); + + // duplicated vote + let id = 1; + let data = b"hello"; + Oracle::handler(&sender, id, data); + let vec = Oracle::test_helper_query_oracle_votes(); + + let len = Vector::length
(&vec); + assert(len == 1, 735706); + } +} +// check: EXECUTED \ No newline at end of file diff --git a/language/move-lang/functional-tests/tests/0L/oracle/upgrade_revoke_delegation.move b/language/move-lang/functional-tests/tests/0L/oracle/upgrade_revoke_delegation.move new file mode 100644 index 0000000000..040e223112 --- /dev/null +++ b/language/move-lang/functional-tests/tests/0L/oracle/upgrade_revoke_delegation.move @@ -0,0 +1,58 @@ +//! account: alice, 1000000, 0, validator +//! account: bob, 1000000, 0, validator + + + +//! new-transaction +//! sender: diemroot +script { + use 0x1::TowerState; + use 0x1::NodeWeight; + fun main(sender: signer) { + TowerState::test_helper_set_weight_vm(&sender, @{{alice}}, 10); + assert(NodeWeight::proof_of_weight(@{{alice}}) == 10, 735701); + TowerState::test_helper_set_weight_vm(&sender, @{{bob}}, 10); + assert(NodeWeight::proof_of_weight(@{{bob}}) == 10, 735702); + } +} +//check: EXECUTED + +//// JIM PROXIES LUCY to vote on upgrades +//// THOMAS PROXIES ALICE to vote on upgrades + +//! new-transaction +//! sender: bob +script { + use 0x1::Oracle; + fun main(sender: signer){ + Oracle::enable_delegation(&sender); + Oracle::delegate_vote(&sender, @{{alice}}); + } +} +// check: EXECUTED + +//! new-transaction +//! sender: alice +script { + use 0x1::Oracle; + use 0x1::Vector; + fun main(sender: signer){ + let id = 1; + let data = b"bello"; + Oracle::handler(&sender, id, data); + let vec = Oracle::test_helper_query_oracle_votes(); + + let e = *Vector::borrow
(&vec, 0); + assert(e == @{{alice}}, 735703); + let e = *Vector::borrow
(&vec, 1); + assert(e == @{{bob}}, 735704); + + Oracle::revoke_my_votes(&sender); + + let vec = Oracle::test_helper_query_oracle_votes(); + assert(Vector::length
(&vec) == 0, 735705); + + } +} +// check: EXECUTED + diff --git a/language/move-lang/functional-tests/tests/0L/recovery_mode/recovery_mode_fullnode_pay.move b/language/move-lang/functional-tests/tests/0L/recovery_mode/recovery_mode_fullnode_pay.depr similarity index 100% rename from language/move-lang/functional-tests/tests/0L/recovery_mode/recovery_mode_fullnode_pay.move rename to language/move-lang/functional-tests/tests/0L/recovery_mode/recovery_mode_fullnode_pay.depr diff --git a/ol/changelog/5_2_0.md b/ol/changelog/5_2_0.md new file mode 100644 index 0000000000..a223e5171b --- /dev/null +++ b/ol/changelog/5_2_0.md @@ -0,0 +1,106 @@ +## 5.2.0 + +This upgrade impacts Carpe, Stdlib, and Node binaries. + +Upgrade steps: +1. Roll out Carpe updates to users (backwards compatible with 5.1.2 chain) +2. Vote on Move stdlib upgrade +3. Validator operators deploy new binaries (backwards compatible with 5.1.2 chain) +4. Validators update config files + + +## Deployment +``` +git fetch && git checkout release-v5.2.0 -f && git pull + +``` + +### Vote on stdlib + +The stdlib payload hash for voting is: 2a8ae2cdd6f9cb941332d521380a681785f406af4e2b788da6132d46f7524172 + + +Execute a lazy vote from a validator in the validator set with: +`txs oracle-upgrade --vote -h 2a8ae2cdd6f9cb941332d521380a681785f406af4e2b788da6132d46f7524172` + +Or build from source and vote: +``` +cd libra +make stdlib +txs oracle-upgrade --vote -f + +``` + +### Upgrade Node + +#### Install Binaries + +The usual upgrade can be done from source with +``` +# stop your services. Note: Use ctrl+c instead of killall which may cause db corruption +cd libra +make bins install +``` + +#### Update config files +You will want to use new validator.node.yaml, which is universal -- no need to switch between fullnode and validator mode. It also includes some minor parameter changes. + +Write the new validator yaml file is a single command. +``` +ol init --val + +``` + +v5.2.0 standardizes the chain_id field of the 0L.toml file. You may have an issue starting `ol` and `tower`. Edit the 0L.toml file and set the chain_id to "MAINNET". + +``` +[chain_info] +chain_id = "MAINNET" + +``` + +#### Restarting the validator +`ol start` is now considered stable. It is a daemon that you can use the start tool to manage the different services (web monitor, tower, diem-node) and restart them. Assuming you can start your node once normally (`diem-node -f ~/.0L/validator.node.yaml`) without errors, you can attempt to use it. + +It's one command: +``` +ol start + +# In another terminal you can tail the logs +tail -f ~/.0L/logs/node.log +tail -f ~/.0L/logs/tower.log +``` + +### Summary + +### Changes + +##### Move Changes + +New Tower Proof Design, preparing for dynamic VDFs +- Every epoch can have a different VDF difficulty. Currently it is fixed, futurely it can use a simple RNG based on the epoch's past VDF proofs. +- The first (genesis) proof of an account always has a fixed parameter. +- On each epoch there is a grace on the 1st proof which can alternatively use the previous epoch's difficulty or the ajusted difficulty. +- New datastructures so related Rust tools can retrieve the current proof parameters from chain. + +A number of fixes to Validator Set managment +- Fixes to implementation of selecting validator set, where the validator set can only add a limited number of of unproven nodes. This behavior was erratic on 5.1.3. +- Reduces the Signing threshold from 5% of blocks to 3%. https://github.com/OLSF/libra/pull/1152 +- Reduces the Voucher threshold from 4 to 2. +- Validators do not get kicked out of the validator set if their vouchers fall out. The vouch mechanism only checks on joining initially or re-joining after jailed. +Adds jailing implementation. Validators must unjail themselves if they get kicked out of validator set. - This is because unattended nodes are rejoining validator set with mining, though they need attention. + +##### Rust Changes + +Node: +- Init tools creates a unified node yaml file so validators don't need to switch between fullnode and validator node mode. +- Node will not panic if safety rules are not initialized. This was an issue for using unified validator.node.yaml file https://github.com/OLSF/libra/pull/1153 +- `ol start` patches to become more reliable. + +Tower: +- changes to allow for dynamic VDF proofs +- allows tower to restart from latest proof on chain. This way users do not need to download all tower proofs from explorer if they lose their local proofs. + +Txs +- Tool for unjailing self, or unjailing a vouchee. `txs val-set --unjail` or `txs val-set --unjail --vouchee
` + diff --git a/ol/cli/Cargo.toml b/ol/cli/Cargo.toml index fb66057cfa..85d05cd0c1 100644 --- a/ol/cli/Cargo.toml +++ b/ol/cli/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ol" authors = [] -version = "5.1.3" +version = "5.2.0" edition = "2018" [dependencies] diff --git a/ol/documentation/network-upgrades/disaster-recovery.md b/ol/documentation/network-upgrades/disaster-recovery.md index 1cb3ef4622..902fe2ffd0 100644 --- a/ol/documentation/network-upgrades/disaster-recovery.md +++ b/ol/documentation/network-upgrades/disaster-recovery.md @@ -74,10 +74,11 @@ cd libra/language/diem-tools/writeset-transaction-generator export VALS = -// save a writset transaction binary -make tx +// save a writset transaction binary, for example of the "rescue" transaction set. +// Compiles a new stdlib from source, updates the validator set with VALS, and enters recovery mode until RECOVERY_EPOCH. +make tx-rescue -// check it can be applied to the db +// check those transactions can be applied to the db make check // commit the writset to db at rest diff --git a/ol/documentation/node-ops/validators/1_validator_cheatsheet.md b/ol/documentation/node-ops/validators/1_validator_cheatsheet.md new file mode 100644 index 0000000000..7a55185250 --- /dev/null +++ b/ol/documentation/node-ops/validators/1_validator_cheatsheet.md @@ -0,0 +1,6 @@ + +### Check what the state of your DB +First your node needs to be running, then execute this command. +``` +db-backup one-shot query node-state +``` \ No newline at end of file diff --git a/ol/onboard/Cargo.toml b/ol/onboard/Cargo.toml index 7d142cee6c..5aebaacbed 100644 --- a/ol/onboard/Cargo.toml +++ b/ol/onboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "onboard" -version = "5.1.3" +version = "5.2.0" edition = "2018" authors = ["0L contributors"] description = "0L onboarding wizard" diff --git a/ol/tower/Cargo.toml b/ol/tower/Cargo.toml index 5561afb3f4..0ef878fba5 100644 --- a/ol/tower/Cargo.toml +++ b/ol/tower/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tower" -version = "5.1.3" +version = "5.2.0" edition = "2018" authors = ["0L contributors"] description = "0L tower" diff --git a/ol/tower/src/backlog.rs b/ol/tower/src/backlog.rs index d9b31d2b24..137ea072b7 100644 --- a/ol/tower/src/backlog.rs +++ b/ol/tower/src/backlog.rs @@ -61,9 +61,13 @@ pub fn process_backlog(config: &AppCfg, tx_params: &TxParams) -> Result<(), TxEr info!("Backlog: resubmitting missing proofs. Remaining in epoch: {}, already submitted in this backlog: {}", remaining_in_epoch, submitted_now); while i <= current_proof_number && submitted_now <= remaining_in_epoch { - let path = PathBuf::from(format!("{}/{}_{}.json", blocks_dir.display(), FILENAME, i)); info!("submitting proof {}, in this backlog: {}", i, submitted_now); - let file = File::open(&path).map_err(|e| Error::from(e))?; + + let path = PathBuf::from(format!("{}/{}_{}.json", blocks_dir.display(), FILENAME, i)); + + let file = File::open(&path).map_err(|e| { + anyhow!("failed to open file: {:?}, message, {}", &path.to_str(), e.to_string()) + })?; let reader = BufReader::new(file); let block: VDFProof = serde_json::from_reader(reader).map_err(|e| Error::from(e))?; diff --git a/ol/txs/Cargo.toml b/ol/txs/Cargo.toml index 3e98d65b31..4557f3d4fa 100644 --- a/ol/txs/Cargo.toml +++ b/ol/txs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "txs" authors = [] -version = "5.1.3" +version = "5.2.0" edition = "2018" [dependencies] diff --git a/ol/txs/src/commands/oracle_upgrade_cmd.rs b/ol/txs/src/commands/oracle_upgrade_cmd.rs index 2f5a0b761f..9507accf64 100644 --- a/ol/txs/src/commands/oracle_upgrade_cmd.rs +++ b/ol/txs/src/commands/oracle_upgrade_cmd.rs @@ -18,6 +18,8 @@ use std::{fs, io::prelude::*, path::PathBuf, process::exit}; pub struct OracleUpgradeCmd { #[options(short = "v", help = "Do the vote tx")] vote: bool, + #[options(help = "revoke all votes")] + revoke: bool, #[options(short = "f", help = "Path of upgrade file")] upgrade_file_path: Option, #[options(short = "h", help = "Use hash instead of binary")] @@ -63,6 +65,8 @@ impl Runnable for OracleUpgradeCmd { transaction_builder::encode_ol_remove_delegation_script_function() } else if let Some(destination) = self.delegate { transaction_builder::encode_ol_delegate_vote_script_function(destination) + } else if self.revoke { + transaction_builder::encode_ol_revoke_vote_script_function() } else { println!("Nothing to do from command line args. Did you mean to pass --vote?"); exit(1);