Skip to content

Commit

Permalink
[core] Diem node upgrade restart (#946)
Browse files Browse the repository at this point in the history
* enable the dispatch to Move to trigger a new epoch event for upgrade

* no panics in diem_vm when attempting upgrade.

* Version bump. Include stdlib compiles.
  • Loading branch information
0o-de-lally authored Jan 19, 2022
1 parent 2ae2e76 commit de35536
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 74 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diem-config"
version = "5.0.9"
version = "5.0.11"
authors = ["Diem Association <[email protected]>"]
description = "Diem diem-config"
repository = "https://github.com/diem/diem"
Expand Down
2 changes: 1 addition & 1 deletion config/management/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diem-management"
version = "5.0.9"
version = "5.0.11"
authors = ["Diem Association <[email protected]>"]
description = "Diem Management is a tool used to manage the configuration of a Diem Node"
repository = "https://github.com/diem/diem"
Expand Down
2 changes: 1 addition & 1 deletion diem-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diem-node"
version = "5.0.9"
version = "5.0.11"
authors = ["Diem Association <[email protected]>"]
description = "Diem node"
repository = "https://github.com/diem/diem"
Expand Down
10 changes: 5 additions & 5 deletions language/diem-framework/modules/doc/DiemConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ Emit a <code><a href="DiemConfig.md#0x1_DiemConfig_NewEpochEvent">NewEpochEvent<
this is used only in upgrade scenarios.


<pre><code><b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>()
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer)
</code></pre>


Expand All @@ -992,13 +992,13 @@ this is used only in upgrade scenarios.
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>() <b>acquires</b> <a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a> {

<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer) <b>acquires</b> <a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a> {
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_vm">CoreAddresses::assert_vm</a>(vm);
<b>assert</b>(<b>exists</b>&lt;<a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>()), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_not_published">Errors::not_published</a>(<a href="DiemConfig.md#0x1_DiemConfig_ECONFIGURATION">ECONFIGURATION</a>));
<b>let</b> config_ref = borrow_global_mut&lt;<a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>());

// Don't increment
// config_ref.epoch = 1;
// Must increment otherwise the diem-nodes lose track due <b>to</b> safety-rules.
config_ref.epoch = config_ref.epoch + 1;

<a href="../../../../../../move-stdlib/docs/Event.md#0x1_Event_emit_event">Event::emit_event</a>&lt;<a href="DiemConfig.md#0x1_DiemConfig_NewEpochEvent">NewEpochEvent</a>&gt;(
&<b>mut</b> config_ref.events,
Expand Down
38 changes: 35 additions & 3 deletions language/diem-framework/modules/doc/Upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -18,6 +19,8 @@


<pre><code><b>use</b> <a href="CoreAddresses.md#0x1_CoreAddresses">0x1::CoreAddresses</a>;
<b>use</b> <a href="DiemConfig.md#0x1_DiemConfig">0x1::DiemConfig</a>;
<b>use</b> <a href="Epoch.md#0x1_Epoch">0x1::Epoch</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer">0x1::Signer</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Vector.md#0x1_Vector">0x1::Vector</a>;
Expand Down Expand Up @@ -179,6 +182,35 @@ Structs for UpgradeHistory resource



</details>

<a name="0x1_Upgrade_upgrade_reconfig"></a>

## Function `upgrade_reconfig`



<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer) <b>acquires</b> <a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a> {
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_vm">CoreAddresses::assert_vm</a>(vm);
<a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(vm);
<b>let</b> new_epoch_height = <a href="Epoch.md#0x1_Epoch_get_timer_height_start">Epoch::get_timer_height_start</a>(vm) + 2; // This is janky, but there's no other way <b>to</b> get the current block height, unless the prologue gives it <b>to</b> us. The upgrade reconfigure happens on round 2, so we'll increment the new start by 2 from previous.
<a href="Epoch.md#0x1_Epoch_reset_timer">Epoch::reset_timer</a>(vm, new_epoch_height);
<a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">DiemConfig::upgrade_reconfig</a>(vm);

}
</code></pre>



</details>

<a name="0x1_Upgrade_reset_payload"></a>
Expand All @@ -187,7 +219,7 @@ Structs for UpgradeHistory resource



<pre><code><b>public</b> <b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(account: &signer)
<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(vm: &signer)
</code></pre>


Expand All @@ -196,8 +228,8 @@ Structs for UpgradeHistory resource
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(account: &signer) <b>acquires</b> <a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a> {
<b>assert</b>(<a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account) == <a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>(), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_requires_role">Errors::requires_role</a>(210003));
<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(vm: &signer) <b>acquires</b> <a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a> {
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_vm">CoreAddresses::assert_vm</a>(vm);
<b>assert</b>(<b>exists</b>&lt;<a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>()), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_not_published">Errors::not_published</a>(210003));
<b>let</b> temp = borrow_global_mut&lt;<a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>());
temp.payload = <a href="../../../../../../move-stdlib/docs/Vector.md#0x1_Vector_empty">Vector::empty</a>&lt;u8&gt;();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ Emit a <code><a href="DiemConfig.md#0x1_DiemConfig_NewEpochEvent">NewEpochEvent<
this is used only in upgrade scenarios.


<pre><code><b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>()
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer)
</code></pre>


Expand All @@ -992,13 +992,13 @@ this is used only in upgrade scenarios.
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>() <b>acquires</b> <a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a> {

<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer) <b>acquires</b> <a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a> {
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_vm">CoreAddresses::assert_vm</a>(vm);
<b>assert</b>(<b>exists</b>&lt;<a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>()), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_not_published">Errors::not_published</a>(<a href="DiemConfig.md#0x1_DiemConfig_ECONFIGURATION">ECONFIGURATION</a>));
<b>let</b> config_ref = borrow_global_mut&lt;<a href="DiemConfig.md#0x1_DiemConfig_Configuration">Configuration</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>());

// Don't increment
// config_ref.epoch = 1;
// Must increment otherwise the diem-nodes lose track due <b>to</b> safety-rules.
config_ref.epoch = config_ref.epoch + 1;

<a href="../../../../../../move-stdlib/docs/Event.md#0x1_Event_emit_event">Event::emit_event</a>&lt;<a href="DiemConfig.md#0x1_DiemConfig_NewEpochEvent">NewEpochEvent</a>&gt;(
&<b>mut</b> config_ref.events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -18,6 +19,8 @@


<pre><code><b>use</b> <a href="CoreAddresses.md#0x1_CoreAddresses">0x1::CoreAddresses</a>;
<b>use</b> <a href="DiemConfig.md#0x1_DiemConfig">0x1::DiemConfig</a>;
<b>use</b> <a href="Epoch.md#0x1_Epoch">0x1::Epoch</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer">0x1::Signer</a>;
<b>use</b> <a href="../../../../../../move-stdlib/docs/Vector.md#0x1_Vector">0x1::Vector</a>;
Expand Down Expand Up @@ -179,6 +182,35 @@ Structs for UpgradeHistory resource



</details>

<a name="0x1_Upgrade_upgrade_reconfig"></a>

## Function `upgrade_reconfig`



<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_upgrade_reconfig">upgrade_reconfig</a>(vm: &signer) <b>acquires</b> <a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a> {
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_vm">CoreAddresses::assert_vm</a>(vm);
<a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(vm);
<b>let</b> new_epoch_height = <a href="Epoch.md#0x1_Epoch_get_timer_height_start">Epoch::get_timer_height_start</a>(vm) + 2; // This is janky, but there's no other way <b>to</b> get the current block height, unless the prologue gives it <b>to</b> us. The upgrade reconfigure happens on round 2, so we'll increment the new start by 2 from previous.
<a href="Epoch.md#0x1_Epoch_reset_timer">Epoch::reset_timer</a>(vm, new_epoch_height);
<a href="DiemConfig.md#0x1_DiemConfig_upgrade_reconfig">DiemConfig::upgrade_reconfig</a>(vm);

}
</code></pre>



</details>

<a name="0x1_Upgrade_reset_payload"></a>
Expand All @@ -187,7 +219,7 @@ Structs for UpgradeHistory resource



<pre><code><b>public</b> <b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(account: &signer)
<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(vm: &signer)
</code></pre>


Expand All @@ -196,8 +228,8 @@ Structs for UpgradeHistory resource
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(account: &signer) <b>acquires</b> <a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a> {
<b>assert</b>(<a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account) == <a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>(), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_requires_role">Errors::requires_role</a>(210003));
<pre><code><b>fun</b> <a href="Upgrade.md#0x1_Upgrade_reset_payload">reset_payload</a>(vm: &signer) <b>acquires</b> <a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a> {
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_vm">CoreAddresses::assert_vm</a>(vm);
<b>assert</b>(<b>exists</b>&lt;<a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>()), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_not_published">Errors::not_published</a>(210003));
<b>let</b> temp = borrow_global_mut&lt;<a href="Upgrade.md#0x1_Upgrade_UpgradePayload">UpgradePayload</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>());
temp.payload = <a href="../../../../../../move-stdlib/docs/Vector.md#0x1_Vector_empty">Vector::empty</a>&lt;u8&gt;();
Expand Down
Binary file not shown.
Binary file not shown.
16 changes: 9 additions & 7 deletions language/diem-framework/releases/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,22 +133,24 @@ pub fn name_for_script(bytes: &[u8]) -> Result<String> {

//////// 0L ////////
// Update stdlib with a byte string, used as part of the upgrade oracle
pub fn import_stdlib(lib_bytes: &Vec<u8>) -> Vec<CompiledModule> {
let modules : Vec<CompiledModule> = bcs::from_bytes::<Vec<Vec<u8>>>(lib_bytes)
.unwrap_or(vec![]) // set as empty array if err occurred
pub fn import_stdlib(lib_bytes: &Vec<u8>) -> Result<Vec<CompiledModule>> {
let modules : Vec<CompiledModule> = bcs::from_bytes::<Vec<Vec<u8>>>(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)
}


Expand Down
Binary file modified language/diem-framework/staged/stdlib.mv
Binary file not shown.
9 changes: 7 additions & 2 deletions language/diem-vm/src/diem_transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit de35536

Please sign in to comment.