Skip to content

Commit 19e06ea

Browse files
Merge pull request #1155 from MinaProtocol/dkijania/mesa_preflight
documentation for preflight network for mesa
2 parents 9b7fe57 + d0d1b04 commit 19e06ea

File tree

3 files changed

+452
-0
lines changed

3 files changed

+452
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
title: Archive Upgrade
3+
sidebar_label: Archive Upgrade
4+
hide_title: true
5+
description: A guide on how to upgrade your Mina archive node to the Mesa version.
6+
keywords:
7+
- Mesa
8+
- upgrade
9+
- archive
10+
- mina archive node
11+
- archive node
12+
---
13+
14+
# Archive Upgrade
15+
16+
To successfully upgrade the archive database into the Mesa version of the Mina network, you must ensure that your environment meets the foundational requirements.
17+
18+
## Migration host
19+
20+
- PostgreSQL database for database server
21+
- If you use Docker, then any of the supported OS by Mina (bullseye, focal, noble, bookworm or jammy) with at least 32 GB of RAM
22+
- gsutil application from Google Cloud Suite in version 5 or later
23+
- (Optional) Docker in version 23.0 or later
24+
25+
## Archive database
26+
27+
One of the most obvious prerequisites is a Mainnet database. If you don't have an existing database with Devnet/Mainnet archive data,
28+
you can always download it from the O1Labs Google Cloud bucket.
29+
30+
## Upgrade process
31+
32+
### Upgrade script
33+
34+
Assuming that you have a PostgreSQL database with Mainnet archive data, in order to upgrade it to Mesa version, you need to run SQL upgrade script.
35+
We put all efforts to make the upgrade process as smooth as possible. Script can be run on archive node which is online or offline.
36+
Script can be run multiple times, it will skip steps that were already completed. It also performs sanity checks before each step to ensure that the upgrade process is successful.
37+
Finally it creates new table (version) in the database to keep track of the upgrade process.
38+
39+
#### Getting the script
40+
41+
You can find the SQL upgrade script in the Mina repository on GitHub. Make sure to download the latest version of the script before proceeding.
42+
You can download the script directly using the following command:
43+
44+
```bash
45+
curl -O https://raw.githubusercontent.com/MinaProtocol/mina/refs/heads/mesa/src/app/archive/upgrade_to_mesa.sql
46+
```
47+
48+
We also ship the script in the Mina archive Docker image and Debian package.
49+
50+
```bash
51+
docker run --rm gcr.io/o1labs-192920/mina-archive-mesa:4.0.0-preflight1-b649c79-bookworm-mesa cat /etc/mina/archive/upgrade-to-mesa.sql > upgrade-to-mesa.sql
52+
```
53+
54+
```bash
55+
# Setup the Mina repository and install the archive package
56+
# See preflight-network.mdx for detailed repository setup instructions
57+
58+
apt-get install mina-archive-mesa=4.0.0-preflight1-b649c79
59+
60+
# View the upgrade and downgrade scripts
61+
cat /etc/mina/archive/upgrade-to-mesa.sql
62+
cat /etc/mina/archive/downgrade-to-berkeley.sql
63+
```
64+
65+
#### Running the script
66+
67+
:::caution Database Backup
68+
69+
Before running the upgrade script, **backup your archive database**. The upgrade modifies the database schema.
70+
71+
```bash
72+
pg_dump -U <username> <database> > berkeley-archive-backup.sql
73+
```
74+
75+
:::
76+
77+
To run the upgrade script, execute the following command:
78+
79+
```bash
80+
psql -U <username> -d <database> -f upgrade-to-mesa.sql
81+
```
82+
83+
Make sure to replace `<username>` and `<database>` with your actual PostgreSQL username and database name.
84+
85+
86+
#### Rollback
87+
88+
You can rollback the upgrade process by restoring the database from a backup taken before running the upgrade script.
89+
Another is to run rollback script which is part of the upgrade script. It will drop all tables and other database objects created by the upgrade script.
90+
It will also update the version table to reflect the rollback.
91+
92+
##### Running the rollback script
93+
94+
To run the rollback script, you need to execute the following command:
95+
96+
```bash
97+
psql -U <username> -d <database> -f /etc/mina/archive/downgrade-to-berkeley.sql
98+
```
99+
100+
Make sure to replace `<username>` and `<database>` with your actual PostgreSQL username and database name.
101+
102+
103+
### Post-upgrade steps
104+
105+
After successfully running the upgrade script, you DO NOT need to restart your archive node or Rosetta API.
106+
Changes in upgrade script are backward compatible and will be picked up by the archive node and Rosetta API automatically.
107+
108+
### Verification
109+
To verify that the upgrade was successful, you can check the version table in the PostgreSQL database.
110+
111+
You can do this by running the following command:
112+
```bash
113+
psql -U <username> -d <database> -c "SELECT * FROM version;"
114+
```
115+
Make sure to replace `<username>` and `<database>` with your actual PostgreSQL username and database name.
116+
117+
If the upgrade was successful, you should see the new version number in the output.
118+
119+
We put a lot of effort into making the upgrade process as smooth as possible.
120+
However, if you encounter any issues or need assistance, please reach out to the Mina community on [Discord](https://discord.gg/minaprotocol) or [GitHub Discussions](https://github.com/MinaProtocol/mina/discussions).
121+
122+
## Appendix: Database Schema Changes
123+
124+
Below we present details of what was changed in the archive node database schema between Berkeley and Mesa versions.
125+
126+
### Zkapp_state_nullable Additional Columns
127+
128+
The `zkapp_state_nullable` table has been modified to include new columns `element8` through `element31` which are nullable and can store additional state information for zkApps.
129+
130+
```sql
131+
, element8 int REFERENCES zkapp_field(id)
132+
...
133+
, element31 int REFERENCES zkapp_field(id)
134+
);
135+
```
136+
137+
This expansion allows zkApps to store up to 31 state elements instead of the previous 8, significantly increasing the state storage capacity for complex smart contracts.
138+
139+
### Version Table
140+
141+
We also introduced a new table `version` to keep track of the database schema version.
142+
The purpose of this table is to help with future database migrations. The table tracks which migration scripts were applied and when.
143+
Ultimately it helps to determine the current version of the database schema and helps to avoid applying the same migration script multiple times.
144+
145+
This table is created if it does not exist already. Rollback and upgrade scripts will insert a new row with the version number and timestamp when the script was applied.
146+
147+
```sql
148+
CREATE TABLE IF NOT EXISTS version (
149+
version_num INT PRIMARY KEY,
150+
applied_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
151+
);
152+
```
153+
154+
The version table provides:
155+
- **Migration tracking**: Records which migrations have been applied
156+
- **Timestamp tracking**: Shows when each migration was executed
157+
- **Idempotency**: Prevents duplicate migration runs
158+
- **Version identification**: Easily identify the current database schema version

0 commit comments

Comments
 (0)