Skip to content

Commit 5120e41

Browse files
0xzoz0o-de-lally
authored andcommitted
[docs] update hot upgrade docs (#210)
1 parent b5511d0 commit 5120e41

File tree

1 file changed

+108
-27
lines changed

1 file changed

+108
-27
lines changed

docs/hot_upgrades.md

Lines changed: 108 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,157 @@
11

2-
# NETWORK HOT UPGRADES
3-
# Overview
4-
The "framework" which contains all the consensus, account, econ policies, etc. for the network is written in Move. This code is stored in the network database, and effectively executed on demand. This means that framework upgrades can occur without redeploying the Move VM itself, or the supporting system code (network node software). It also means the state machine can upgrade without a coordinated halt.
5-
To do this we require two libra tools: `framework` for building the artifacts, and `txs` for proposing, voting, and ultimately deploying the artifacts.
2+
# Network Hot Upgrades
63

7-
# Procedure
8-
## Build Artifacts
4+
## Overview
5+
6+
The "framework" which contains all the consensus, account, econ policies, etc. for the network is written in Move. This code is stored in the network database, and effectively executed on demand. This means that framework upgrades can occur without redeploying the Move VM itself, or the supporting system code (network node software). It also means the state machine can upgrade without a coordinated halt.
7+
8+
- To do this we require two libra tools: `libra-framework` for building the artifacts, and `libra txs` for proposing, voting, and ultimately deploying the artifacts.
9+
10+
## TLDR
11+
- **Fetch the latest release**: `cd libra-framework; git fetch --all; git checkout release-x.x.x`
12+
- **Build framework**: `libra-framework upgrade --output-dir ~/framework_upgrade --framework-local-dir ~/libra-framework/framework/`
13+
- **Propose**: `libra txs governance propose --proposal-script-dir ~/framework_upgrade/1-move-stdlib/ --metadata-url https://www.github.com/0LNetworkCommunity/UpdateProposalTemplate`
14+
- **Validators vote**: `libra txs governance vote --proposal-id <ID>`
15+
- **Resolve**:
16+
17+
1. `libra txs governance resolve --proposal-script-dir ~/framework_upgrade/1-move-stdlib/ --proposal-id 0`
18+
19+
2. `libra txs governance resolve --proposal-script-dir ~/framework_upgrade/2-vendor-stdlib/ --proposal-id 0`
20+
21+
3. `libra txs governance resolve --proposal-script-dir ~/framework_upgrade/3-libra-framework/ --proposal-id 0`
22+
23+
## Upgrade Types: Single and Multiple
24+
25+
When performing upgrades within the network framework, two primary approaches can be employed: single and multiple module upgrades. The key distinction lies in how these upgrades are proposed, voted on, and executed, particularly with respect to handling multiple modules.
26+
27+
### Single Framework Upgrade
28+
A single framework upgrade involves updating a singular set of modules within the framework. This process is straightforward and includes the following steps:
29+
30+
- **Build Framework**: Generate the upgrade Move transaction scripts for the module.
31+
- **Proposal Submission**: Propose the upgrade for the specific framework module.
32+
- **Validator Voting**: Validators within the network vote for or against the proposed upgrade.
33+
- **Achieving Consensus**: The proposal moves forward once it receives support from at least 66% of active validators.
34+
- **Resolution and Deployment**: Resolve the proposal using the exact framework directory that matches the build of the proposed upgrade. This can be done by any validator using the same release branch from the `libra-framework` repository
35+
36+
### Multiple Framework Upgrades
37+
Multiple framework upgrades require a more nuanced approach, especially regarding resolution stages, to ensure a coherent and secure update across several modules.
38+
39+
- **Build Framework**: Similar to a single upgrade, start by generating Move transaction scripts for all relevant modules.
40+
- **Proposal for Initial Module**: Propose the upgrade by using the first module (`1-move-stdlib`). This initial proposal is critical as it kickstarts the governance process for the entire upgrade.
41+
42+
Importantly, the transaction script for upgrading this first module includes a significant addition: **the transaction hash for the subsequent modules** that needs upgrading. These hashes, produced during the artifact building phase, serve as secure identifiers for each module's upgrade script.
43+
44+
- **Validator Voting**: As with single upgrades, validators vote for or against the proposed upgrade.
45+
- **Achieving Consensus and Sequential Resolution**: Once at least 66% of active validators support the proposal, the initial upgrade can be resolved.
46+
- **Sequential Upgrade Execution**: Execute the resolution process for all involved modules, following the order 1-3.
47+
48+
49+
## Upgrade Policy
50+
The diem framework has information in the metadata that controls the policy that a publisher can set for upgrading their modules. These are:
51+
- Arbitrary(0): Allows code upgrades without compatibility checks, for non-shared packages.
52+
- Compatible(1): Requires compatibility checks to ensure no breaking changes in public functions or resource layouts.
53+
- Immutable(2): Prevents any upgrades, ensuring the permanence of critical code.
54+
55+
Due to some circumstances, a publisher may want to downgrade the policy to allow changes to go through that a restrictive policy would not allow. We can do this by building the framework with a flag(`--danger-force-upgrade`) that sets the upgrade policy as Aribitrary
56+
57+
Example
958

10-
### 1. Build a new head.mrb bundle for the framework into `./framework/releases`.
1159
```
12-
cargo r --release release
60+
libra txs governance propose --proposal-script-dir ~/framework_upgrade/3-libra-framework/ --metadata-url https://www.github.com/0LNetworkCommunity/UpdateProposalTemplate --danger-force-upgrade
1361
```
1462

15-
### 2. Build the upgrade Move transaction scripts
63+
## Procedure
64+
65+
We will use this guide to do a multi-step upgrade as this is the most common upgrade that is done.
66+
67+
### Build Artifacts
1668

17-
This will be a Move package which is machine-generated for a one-time execution. It contains bytecode which will be allowed to be executed (by anyone), once there is a vote and agreement on the proposal passing. The on-chain execution is guarded a hash of this transction, which the proposer provides in the proposal transaction (in advance of the vote).
69+
##### 1. Build the upgrade Move transaction scripts
70+
71+
This will be a Move package which is machine-generated for a one-time execution. It contains bytecode which will be allowed to be executed (by anyone), once there is a vote and agreement on the proposal passing. The on-chain execution is guarded with a hash of this transaction, which the proposer provides in the proposal transaction (in advance of the vote).
1872

1973
An upgrade script that is tampered with will yield a different execution hash, and will be prevented from running (it is likely to be blocked by the transaction size limits before entering the mempool).
2074

21-
The `framework upgrade` command will produce a newly compiled Move upgrade transaction script, its binary, and the hash.
75+
The `libra-framework upgrade` command will produce a newly compiled Move upgrade transaction script, its binary, and the hash.
2276

2377
You need to provide:
2478
- `--output-dir`: this directory the upgrade transaction files should be saved to. A new folder called `framework_upgrade` will be created under the output-dir path.
2579

2680
- `--framework-local-dir`: the source code for the framework so that the transaction script can import it as a dependency.
2781

28-
- `--mrb-path`: the compiled bundle of the framework from step #1. By default this is under ``./framework/releases/head.mrb``
82+
Optionally you could provide the flag `--danger-force-upgrade
2983

3084
```
3185
# Note the paths
32-
cargo r --release upgrade \
33-
--output-dir ./framework/releases \
34-
--framework-local-dir ./framework/libra-framework \
35-
--mrb-path ./framework/releases/head.mrb
86+
libra-framework upgrade --output-dir <OUTPUT_DIR> --framework-local-dir <FRAMEWORK_PATH>
87+
88+
# Example
89+
libra-framework upgrade --output-dir ~/framework_upgrade --framework-local-dir ~/libra-framework/framework/
3690
```
91+
:::note
92+
This creates 3 seperate library upgrade script directories
93+
- 1-move-stdlib
94+
- 2-vendor-stdlib
95+
- 3-libra-framework
96+
97+
You will choose depending on which library you want updated
98+
:::
3799

38100
All the artifacts are now created, the proposal transaction can be submitted. But it's a good idea to document this on github first.
39101

40-
### 3. Share the output artifacts on Github.
102+
##### 2. Share the output artifacts on Github.
41103

42104
Create a new repository with the outputted directory. Add a README.md file.
43105

44106
The proposer can add the link to this Github repo in the proposal phase.
45107

46108

47-
## Upgrade Ceremony
48-
### 4. With `txs` anyone (no authority needed) can submit the proposal and metadata. You'll need to provide the actual script compiled path, and an optional URL which contains documentation of the proposal (e.g github).
109+
### Upgrade Ceremony
110+
111+
##### 3. With `txs` anyone (no authority needed) can submit the proposal and metadata. You'll need to provide the actual script compiled path, and an optional URL which contains documentation of the proposal (e.g github).
49112

50113
```
51114
# note the actual script dir
52-
txs upgrade propose --script-dir ./framework/release/framework_upgrade --metadata-url <URL>
115+
libra txs governance propose --proposal-script-dir <PROPOSAL_SCRIPT_DIR> --metadata-url <URL>
116+
117+
# Example
118+
libra txs governance propose --proposal-script-dir ~/framework_upgrade/1-move-stdlib/ --metadata-url https://www.github.com/0LNetworkCommunity/UpdateProposalTemplate
119+
53120
```
54121
If this transaction succeeds it will produce a proposal id, which is a number. Now the proposal is open to voting.
55122

56-
### 5. With `txs` anyone with governance authority (the epoch's validators as of `V7`), can submit a vote in favor (or against it with `--should-fail`).
123+
:::note
124+
You can query the next proposal using this command: ` libra query view --function-id 0x1::diem_governance::get_next_governance_proposal_id`
125+
:::
126+
127+
##### 4. With `libra txs` anyone with governance authority (the epoch's validators as of `V7`), can submit a vote in favor (or against it with `--should-fail`).
57128

58129
We assume the default is to vote in favor. To vote "approve" simply:
59130
```
60-
txs vote --proposal-id <number>
131+
libra txs governance vote --proposal-id <PROPOSAL_ID>
61132
```
62133

63134
If voter would like the proposal to be rejected:
64135
```
65-
txs vote --proposal-id <number> --should-fail
136+
libra txs governance vote --proposal-id <PROPOSAL_ID> --should-fail
66137
```
138+
:::note
139+
You can query to see the for and against votes using this command: ` libra query view --function-id 0x1::diem_governance::get_votes --args <proposal_number>`
140+
:::
67141

68-
After everyone has voted (to reach the consensus threshold of 66% as of `V7`), the proposal will be in a "Resolvable" state. Anyone can resolve it by submitting the upgrade transaction. This means the sender must have the source transaction script for the upgrade (step #2 above).
142+
After everyone has voted (to reach the consensus threshold of 66% as of `V7`), the proposal will be in a "Resolvable" state. Anyone can resolve it by submitting the upgrade transaction. This means the sender must have the source transaction script for the upgrade (step #1 above).
69143

70-
### 6. Use `txs` to resolve a successfully approved proposal
144+
##### 6. Use `txs` to resolve a successfully approved proposal
71145
```
72146
# Note the actual path
73-
txs resolve --proposal-script-dir ./framework/release/framework_upgrade
147+
libra txs governance resolve --proposal-script-dir <PROPOSAL_SCRIPT_DIR> --proposal-id <PROPOSAL_ID>
148+
149+
# Example
150+
1. libra txs governance resolve --proposal-script-dir ~/framework_upgrade/1-move-stdlib/ --proposal-id 0
151+
152+
2. libra txs governance resolve --proposal-script-dir ~/framework_upgrade/2-vendor-stdlib/ --proposal-id 0
153+
154+
3. libra txs governance resolve --proposal-script-dir ~/framework_upgrade/3-libra-framework/ --proposal-id 0
74155
```
75156

76-
If this transction is successful the new bytecode will be written to the VM, and a new epoch will be triggered.
157+
If this transaction is successful the new bytecode will be written to the VM

0 commit comments

Comments
 (0)