diff --git a/Cargo.lock b/Cargo.lock index 1295a480eb..9687e04ab9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1730,7 +1730,7 @@ dependencies = [ [[package]] name = "diem-config" -version = "5.0.9" +version = "5.0.11" dependencies = [ "bcs", "diem-crypto", @@ -2187,7 +2187,7 @@ dependencies = [ [[package]] name = "diem-management" -version = "5.0.9" +version = "5.0.11" dependencies = [ "anyhow", "bcs", @@ -2306,7 +2306,7 @@ dependencies = [ [[package]] name = "diem-node" -version = "5.0.9" +version = "5.0.11" dependencies = [ "backup-service", "consensus", @@ -5637,7 +5637,7 @@ dependencies = [ [[package]] name = "ol" -version = "5.0.9" +version = "5.0.11" dependencies = [ "abscissa_core", "abscissa_tokio", @@ -5783,7 +5783,7 @@ dependencies = [ [[package]] name = "onboard" -version = "5.0.9" +version = "5.0.11" dependencies = [ "abscissa_core", "anyhow", @@ -5808,7 +5808,7 @@ dependencies = [ "serde_json", "thiserror", "toml", - "tower 5.0.9", + "tower 5.0.11", "txs", "wait-timeout", "zip", @@ -8566,7 +8566,7 @@ dependencies = [ [[package]] name = "tower" -version = "5.0.9" +version = "5.0.11" dependencies = [ "abscissa_core", "ajson", @@ -8790,7 +8790,7 @@ dependencies = [ [[package]] name = "txs" -version = "5.0.9" +version = "5.0.11" dependencies = [ "abscissa_core", "ajson", diff --git a/config/Cargo.toml b/config/Cargo.toml index 75a9d83324..9fede8988b 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diem-config" -version = "5.0.9" +version = "5.0.11" 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 a338616d04..f43dc62575 100644 --- a/config/management/Cargo.toml +++ b/config/management/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diem-management" -version = "5.0.9" +version = "5.0.11" 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/diem-node/Cargo.toml b/diem-node/Cargo.toml index 89988dfa77..aed02f0120 100644 --- a/diem-node/Cargo.toml +++ b/diem-node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diem-node" -version = "5.0.9" +version = "5.0.11" authors = ["Diem Association "] description = "Diem node" repository = "https://github.com/diem/diem" diff --git a/language/diem-framework/modules/doc/DiemConfig.md b/language/diem-framework/modules/doc/DiemConfig.md index 5651b084d2..3067a57f7c 100644 --- a/language/diem-framework/modules/doc/DiemConfig.md +++ b/language/diem-framework/modules/doc/DiemConfig.md @@ -983,7 +983,7 @@ Emit a NewEpochEvent< this is used only in upgrade scenarios. -
fun upgrade_reconfig()
+
public(friend) fun upgrade_reconfig(vm: &signer)
 
@@ -992,13 +992,13 @@ this is used only in upgrade scenarios. Implementation -
fun upgrade_reconfig() acquires Configuration {
-
+
public(friend) fun upgrade_reconfig(vm: &signer) acquires Configuration {
+    CoreAddresses::assert_vm(vm);
     assert(exists<Configuration>(CoreAddresses::DIEM_ROOT_ADDRESS()), Errors::not_published(ECONFIGURATION));
     let config_ref = borrow_global_mut<Configuration>(CoreAddresses::DIEM_ROOT_ADDRESS());
 
-    // Don't increment
-    // config_ref.epoch = 1;
+    // Must increment otherwise the diem-nodes lose track due to safety-rules.
+    config_ref.epoch = config_ref.epoch + 1;
 
     Event::emit_event<NewEpochEvent>(
         &mut config_ref.events,
diff --git a/language/diem-framework/modules/doc/Upgrade.md b/language/diem-framework/modules/doc/Upgrade.md
index 5b22ebea0c..70e75df4d9 100644
--- a/language/diem-framework/modules/doc/Upgrade.md
+++ b/language/diem-framework/modules/doc/Upgrade.md
@@ -10,6 +10,7 @@
 -  [Resource `UpgradeHistory`](#0x1_Upgrade_UpgradeHistory)
 -  [Function `initialize`](#0x1_Upgrade_initialize)
 -  [Function `set_update`](#0x1_Upgrade_set_update)
+-  [Function `upgrade_reconfig`](#0x1_Upgrade_upgrade_reconfig)
 -  [Function `reset_payload`](#0x1_Upgrade_reset_payload)
 -  [Function `record_history`](#0x1_Upgrade_record_history)
 -  [Function `retrieve_latest_history`](#0x1_Upgrade_retrieve_latest_history)
@@ -18,6 +19,8 @@
 
 
 
use 0x1::CoreAddresses;
+use 0x1::DiemConfig;
+use 0x1::Epoch;
 use 0x1::Errors;
 use 0x1::Signer;
 use 0x1::Vector;
@@ -179,6 +182,35 @@ Structs for UpgradeHistory resource
 
 
 
+
+
+
+
+## Function `upgrade_reconfig`
+
+
+
+
fun upgrade_reconfig(vm: &signer)
+
+ + + +
+Implementation + + +
fun upgrade_reconfig(vm: &signer) acquires UpgradePayload {
+    CoreAddresses::assert_vm(vm);
+    reset_payload(vm);
+    let new_epoch_height = Epoch::get_timer_height_start(vm) + 2; // This is janky, but there's no other way to get the current block height, unless the prologue gives it to us. The upgrade reconfigure happens on round 2, so we'll increment the new start by 2 from previous.
+    Epoch::reset_timer(vm, new_epoch_height);
+    DiemConfig::upgrade_reconfig(vm);
+
+}
+
+ + +
@@ -187,7 +219,7 @@ Structs for UpgradeHistory resource -
public fun reset_payload(account: &signer)
+
fun reset_payload(vm: &signer)
 
@@ -196,8 +228,8 @@ Structs for UpgradeHistory resource Implementation -
public fun reset_payload(account: &signer) acquires UpgradePayload {
-    assert(Signer::address_of(account) == CoreAddresses::DIEM_ROOT_ADDRESS(), Errors::requires_role(210003));
+
fun reset_payload(vm: &signer) acquires UpgradePayload {
+    CoreAddresses::assert_vm(vm);
     assert(exists<UpgradePayload>(CoreAddresses::DIEM_ROOT_ADDRESS()), Errors::not_published(210003));
     let temp = borrow_global_mut<UpgradePayload>(CoreAddresses::DIEM_ROOT_ADDRESS());
     temp.payload = Vector::empty<u8>();
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/DiemConfig.md b/language/diem-framework/releases/artifacts/current/docs/modules/DiemConfig.md
index 5651b084d2..3067a57f7c 100644
--- a/language/diem-framework/releases/artifacts/current/docs/modules/DiemConfig.md
+++ b/language/diem-framework/releases/artifacts/current/docs/modules/DiemConfig.md
@@ -983,7 +983,7 @@ Emit a NewEpochEvent<
 this is used only in upgrade scenarios.
 
 
-
fun upgrade_reconfig()
+
public(friend) fun upgrade_reconfig(vm: &signer)
 
@@ -992,13 +992,13 @@ this is used only in upgrade scenarios. Implementation -
fun upgrade_reconfig() acquires Configuration {
-
+
public(friend) fun upgrade_reconfig(vm: &signer) acquires Configuration {
+    CoreAddresses::assert_vm(vm);
     assert(exists<Configuration>(CoreAddresses::DIEM_ROOT_ADDRESS()), Errors::not_published(ECONFIGURATION));
     let config_ref = borrow_global_mut<Configuration>(CoreAddresses::DIEM_ROOT_ADDRESS());
 
-    // Don't increment
-    // config_ref.epoch = 1;
+    // Must increment otherwise the diem-nodes lose track due to safety-rules.
+    config_ref.epoch = config_ref.epoch + 1;
 
     Event::emit_event<NewEpochEvent>(
         &mut config_ref.events,
diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/Upgrade.md b/language/diem-framework/releases/artifacts/current/docs/modules/Upgrade.md
index 5b22ebea0c..70e75df4d9 100644
--- a/language/diem-framework/releases/artifacts/current/docs/modules/Upgrade.md
+++ b/language/diem-framework/releases/artifacts/current/docs/modules/Upgrade.md
@@ -10,6 +10,7 @@
 -  [Resource `UpgradeHistory`](#0x1_Upgrade_UpgradeHistory)
 -  [Function `initialize`](#0x1_Upgrade_initialize)
 -  [Function `set_update`](#0x1_Upgrade_set_update)
+-  [Function `upgrade_reconfig`](#0x1_Upgrade_upgrade_reconfig)
 -  [Function `reset_payload`](#0x1_Upgrade_reset_payload)
 -  [Function `record_history`](#0x1_Upgrade_record_history)
 -  [Function `retrieve_latest_history`](#0x1_Upgrade_retrieve_latest_history)
@@ -18,6 +19,8 @@
 
 
 
use 0x1::CoreAddresses;
+use 0x1::DiemConfig;
+use 0x1::Epoch;
 use 0x1::Errors;
 use 0x1::Signer;
 use 0x1::Vector;
@@ -179,6 +182,35 @@ Structs for UpgradeHistory resource
 
 
 
+
+
+
+
+## Function `upgrade_reconfig`
+
+
+
+
fun upgrade_reconfig(vm: &signer)
+
+ + + +
+Implementation + + +
fun upgrade_reconfig(vm: &signer) acquires UpgradePayload {
+    CoreAddresses::assert_vm(vm);
+    reset_payload(vm);
+    let new_epoch_height = Epoch::get_timer_height_start(vm) + 2; // This is janky, but there's no other way to get the current block height, unless the prologue gives it to us. The upgrade reconfigure happens on round 2, so we'll increment the new start by 2 from previous.
+    Epoch::reset_timer(vm, new_epoch_height);
+    DiemConfig::upgrade_reconfig(vm);
+
+}
+
+ + +
@@ -187,7 +219,7 @@ Structs for UpgradeHistory resource -
public fun reset_payload(account: &signer)
+
fun reset_payload(vm: &signer)
 
@@ -196,8 +228,8 @@ Structs for UpgradeHistory resource Implementation -
public fun reset_payload(account: &signer) acquires UpgradePayload {
-    assert(Signer::address_of(account) == CoreAddresses::DIEM_ROOT_ADDRESS(), Errors::requires_role(210003));
+
fun reset_payload(vm: &signer) acquires UpgradePayload {
+    CoreAddresses::assert_vm(vm);
     assert(exists<UpgradePayload>(CoreAddresses::DIEM_ROOT_ADDRESS()), Errors::not_published(210003));
     let temp = borrow_global_mut<UpgradePayload>(CoreAddresses::DIEM_ROOT_ADDRESS());
     temp.payload = Vector::empty<u8>();
diff --git a/language/diem-framework/releases/artifacts/current/modules/012_DiemConfig.mv b/language/diem-framework/releases/artifacts/current/modules/012_DiemConfig.mv
index 422af7d468..9ee588ce0c 100644
Binary files a/language/diem-framework/releases/artifacts/current/modules/012_DiemConfig.mv and b/language/diem-framework/releases/artifacts/current/modules/012_DiemConfig.mv differ
diff --git a/language/diem-framework/releases/artifacts/current/modules/068_Upgrade.mv b/language/diem-framework/releases/artifacts/current/modules/068_Upgrade.mv
index 5dec301117..ca3673149d 100644
Binary files a/language/diem-framework/releases/artifacts/current/modules/068_Upgrade.mv and b/language/diem-framework/releases/artifacts/current/modules/068_Upgrade.mv differ
diff --git a/language/diem-framework/releases/src/lib.rs b/language/diem-framework/releases/src/lib.rs
index 010afaa421..15dd9fb56e 100644
--- a/language/diem-framework/releases/src/lib.rs
+++ b/language/diem-framework/releases/src/lib.rs
@@ -2,7 +2,7 @@
 // SPDX-License-Identifier: Apache-2.0
 
 use anyhow::{bail, Result};
-use diem_types::transaction::ScriptFunction;
+use diem_types::{transaction::ScriptFunction, vm_status::{StatusCode, VMStatus}};
 use include_dir::{include_dir, Dir};
 use move_binary_format::file_format::CompiledModule;
 use once_cell::sync::Lazy;
@@ -133,22 +133,24 @@ pub fn name_for_script(bytes: &[u8]) -> Result {
 
 //////// 0L ////////
 // Update stdlib with a byte string, used as part of the upgrade oracle
-pub fn import_stdlib(lib_bytes: &Vec) -> Vec {
-    let modules : Vec = bcs::from_bytes::>>(lib_bytes)
-        .unwrap_or(vec![]) // set as empty array if err occurred
+pub fn import_stdlib(lib_bytes: &Vec) -> Result> {
+    let modules : Vec = bcs::from_bytes::>>(lib_bytes)? // set as empty array if err occurred
         .into_iter()
-        .map(|bytes| CompiledModule::deserialize(&bytes).unwrap())
+        .filter_map(|bytes| CompiledModule::deserialize(&bytes).ok())
         .collect();
 
     // verify the compiled module
     let mut verified_modules = vec![];
     for module in modules {
-        verify_module(&module).expect("stdlib module failed to verify");
+        verify_module(&module)
+        .map_err(|_| VMStatus::Error(StatusCode::CODE_DESERIALIZATION_ERROR))?;
+
+        // TODO: Do we still need to run dependency checker?
         // DependencyChecker::verify_module(&module, &verified_modules)
         //     .expect("stdlib module dependency failed to verify");
         verified_modules.push(module)
     }
-    verified_modules
+    Ok(verified_modules)
 }
 
 
diff --git a/language/diem-framework/staged/stdlib.mv b/language/diem-framework/staged/stdlib.mv
index 0f6cc7de89..a221d09fa5 100644
Binary files a/language/diem-framework/staged/stdlib.mv and b/language/diem-framework/staged/stdlib.mv differ
diff --git a/language/diem-vm/src/diem_transaction_executor.rs b/language/diem-vm/src/diem_transaction_executor.rs
index 68ee12fe33..223add9add 100644
--- a/language/diem-vm/src/diem_transaction_executor.rs
+++ b/language/diem-vm/src/diem_transaction_executor.rs
@@ -527,14 +527,19 @@ impl DiemVM {
 
             //////// 0L ////////
             // Apply upgrade for Upgrade oracle
-            self.0.apply_stdlib_upgrade(
+            match self.0.apply_stdlib_upgrade(
                 &mut session,
                 &storage,
                 block_metadata.clone(),
                 &txn_data,
                 &mut gas_status,
                 log_context,
-            )?;
+            ) {
+                Ok(_) => {},
+                Err(e) => {
+                  println!("0L ==== stdlib upgrade: aborting. Message: {:?}", &e);
+                },
+            };
         }
 
         SYSTEM_TRANSACTIONS_EXECUTED.inc();
diff --git a/language/diem-vm/src/diem_vm.rs b/language/diem-vm/src/diem_vm.rs
index a41f410abe..323f214a66 100644
--- a/language/diem-vm/src/diem_vm.rs
+++ b/language/diem-vm/src/diem_vm.rs
@@ -513,56 +513,52 @@ impl DiemVMImpl {
                 println!("0L ==== stdlib upgrade: upgrade payload elected in previous epoch");
 
                 // publish the agreed stdlib
-                let new_stdlib = import_stdlib(&payload);
+                let new_stdlib = import_stdlib(&payload)
+                    .map_err(|_|{ 
+                        println!("faliled to import stdlib"); 
+                        VMStatus::Error(StatusCode::STDLIB_UPGRADE_ERROR)
+                      })?;
                 let mut counter = 0;
                 for module in new_stdlib {
                     let mut bytes = vec![];
                     module
                         .serialize(&mut bytes)
-                        .expect("Failed to serialize module");
+                        .map_err(|_|{ 
+                          println!("faliled to serialize stdlib"); 
+                          VMStatus::Error(StatusCode::STDLIB_UPGRADE_ERROR)
+                        })?;
                     session.revise_module(
                         bytes, 
                         account_config::CORE_CODE_ADDRESS, 
                         gas_status, 
                         log_context
-                    ).expect("Failed to publish module");
+                    ).map_err(|_|{ 
+                      println!("faliled to publish module");
+                      VMStatus::Error(StatusCode::STDLIB_UPGRADE_ERROR)
+                    })?;
+
                     counter += 1;
                 }
 
                 println!("0L ==== stdlib upgrade: published {} modules", counter);
 
-                // TODO: This will be deprecated in v5.0.11, see below.
+                // trigger a reconfiguration of type Upgrade
                 let args = vec![
                     MoveValue::Signer(txn_data.sender),
                 ];
                 session.execute_function(
                     &UPGRADE_MODULE,
-                    &RESET_PAYLOAD,
+                    &UPGRADE_RECONFIG,
                     vec![],
                     serialize_values(&args),
-                    // txn_data.sender(),
                     gas_status,
                     log_context,
-                ).expect("Couldn't reset payload");
-                info!("==== stdlib upgrade: end upgrade at time: {} ====", timestamp);
+                ).map_err(|_|{ 
+                  println!("Couldn't trigger upgrade reconfig event");
+                  VMStatus::Error(StatusCode::STDLIB_UPGRADE_ERROR)
+                })?;
 
-                ///////////////////////////////////////////
-
-                // ENABLE THIS CODE ON V5.0.11
-                // trigger a reconfiguration of type Upgrade
-                // let args = vec![
-                //     MoveValue::Signer(txn_data.sender),
-                // ];
-                // session.execute_function(
-                //     &UPGRADE_MODULE,
-                //     &UPGRADE_RECONFIG,
-                //     vec![],
-                //     serialize_values(&args),
-                //     gas_status,
-                //     log_context,
-                // ).expect("Couldn't trigger upgrade reconfig event");
-
-                ///////////////////////////////////////////
+                println!("0L ==== successfully triggered upgrade reconfig event");
 
                 println!("==== stdlib upgrade: end upgrade at time: {} ====", timestamp);
             }
diff --git a/language/diem-vm/src/system_module_names.rs b/language/diem-vm/src/system_module_names.rs
index fa1e6ee03e..e392471f9b 100644
--- a/language/diem-vm/src/system_module_names.rs
+++ b/language/diem-vm/src/system_module_names.rs
@@ -38,14 +38,9 @@ pub static CHECK_UPGRADE: Lazy =
     Lazy::new(|| Identifier::new("check_upgrade").unwrap());
 static UPGRADE_MODULE_NAME: Lazy =
     Lazy::new(|| Identifier::new("Upgrade").unwrap());
-
-// TODO: this will be deprecated in 5.0.11
-pub static RESET_PAYLOAD: Lazy =
-    Lazy::new(|| Identifier::new("reset_payload").unwrap());
-
 pub static UPGRADE_RECONFIG: Lazy =
     Lazy::new(|| Identifier::new("upgrade_reconfig").unwrap());
-//////// 0L end ////////    
+//////// 0L end ////////
 
 // Names for special functions and structs
 pub const SCRIPT_PROLOGUE_NAME: &IdentStr = ident_str!("script_prologue");
diff --git a/language/move-core/types/src/vm_status.rs b/language/move-core/types/src/vm_status.rs
index d251e6754f..7b62b0d2cd 100644
--- a/language/move-core/types/src/vm_status.rs
+++ b/language/move-core/types/src/vm_status.rs
@@ -636,6 +636,8 @@ pub enum StatusCode {
     VM_MAX_TYPE_DEPTH_REACHED = 4024,
     VM_MAX_VALUE_DEPTH_REACHED = 4025,
 
+    //////// 0L /////////
+    STDLIB_UPGRADE_ERROR = 9001,
     // A reserved status to represent an unknown vm status.
     // this is std::u64::MAX, but we can't pattern match on that, so put the hardcoded value in
     UNKNOWN_STATUS = 18446744073709551615,
diff --git a/ol/changelog/5_0_10.md b/ol/changelog/5_0_10.md
index f46b8e3478..d98b9e7ea1 100644
--- a/ol/changelog/5_0_10.md
+++ b/ol/changelog/5_0_10.md
@@ -1,6 +1,6 @@
 ## 5.0.10
 
-Resolving the Move Cache issue (https://github.com/OLSF/libra/issues/941) will require a two step upgrade process. 
+Resolving the Move Cache issue (https://github.com/OLSF/libra/issues/941) will require a two-step upgrade process. 
 
 1. Initially Move changes will be propagated (on chain Hot Upgrade) then, 
 2. later Rust changes will be propagated (Node Upgrade). Read about upgrade types here: ol/documentation/network-upgrades/upgrades.md
@@ -34,7 +34,7 @@ txs oracle-upgrade -v -h 
 
 ### Summary
 
-This upgrade corrects behavior of vfn.node.yaml config creator, and provides tooling for updating on-chain node discovery information (update IP addresses).
+Hot Upgrades in the production mainnet run into issues due to Move VM caches not being invalidated when the 0L upgrade is triggered.
 
 ### Changes
 
diff --git a/ol/cli/Cargo.toml b/ol/cli/Cargo.toml
index e2bb1331f0..d8e9c920ef 100644
--- a/ol/cli/Cargo.toml
+++ b/ol/cli/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "ol"
 authors = []
-version = "5.0.9"
+version = "5.0.11"
 edition = "2018"
 
 [dependencies]
diff --git a/ol/documentation/node-ops/validators/validator_onboarding_hard_mode.md b/ol/documentation/node-ops/validators/validator_onboarding_hard_mode.md
index ea7c389cf7..6e3593c6d3 100644
--- a/ol/documentation/node-ops/validators/validator_onboarding_hard_mode.md
+++ b/ol/documentation/node-ops/validators/validator_onboarding_hard_mode.md
@@ -3,7 +3,7 @@
 - TWO unix hosts, one for Validator Node, and one for the Private Fullnode ("VFN").
 0L code targets Ubuntu 20.4
 - Recommended specs: 
-  - Validator: 250G harddrive, 8 core CPU, 16G RaM
+  - Validator: 250G harddrive, 8 core CPU, 16G RAM
   - VFN: 100G storage, 2 core CPU, 8G RAM
 - Separate static IP addresses for the machines, or appropriate DNS mapping.
 
diff --git a/ol/onboard/Cargo.toml b/ol/onboard/Cargo.toml
index 75204a899d..bbb9b47f04 100644
--- a/ol/onboard/Cargo.toml
+++ b/ol/onboard/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "onboard"
-version = "5.0.9"
+version = "5.0.11"
 edition = "2018"
 authors = ["0L contributors"]
 description = "0L onboarding wizard"
diff --git a/ol/tower/Cargo.toml b/ol/tower/Cargo.toml
index 57d868758c..94204d2102 100644
--- a/ol/tower/Cargo.toml
+++ b/ol/tower/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "tower"
-version = "5.0.9"
+version = "5.0.11"
 edition = "2018"
 authors = ["0L contributors"]
 description = "0L tower"
diff --git a/ol/txs/Cargo.toml b/ol/txs/Cargo.toml
index 2cdff1cbe3..65729412a0 100644
--- a/ol/txs/Cargo.toml
+++ b/ol/txs/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "txs"
 authors = []
-version = "5.0.9"
+version = "5.0.11"
 edition = "2018"
 
 [dependencies]