forked from smartcontracts/simple-optimism-node
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmigrate.sh
executable file
·136 lines (117 loc) · 5.17 KB
/
migrate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
set -e
# Function to display usage
usage() {
echo "Usage: $0 <operation> <network> <source_dir> [destination_dir]"
echo " <operation> Either pre or full"
echo " <network> Network name (mainnet, alfajores, or baklava)"
echo " <source_dir> Source datadir directory (the value of the '--datadir' flag for the celo L1 client)"
echo " [destination_dir] Optional destination datadir directory (should be used as the value for the '--datadir'"
echo " flag for the celo L2 client), if omitted './envs/<network>/datadir' will be used"
exit 1
}
# Check the number of arguments
if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then
usage
fi
# Assign positional arguments to variables
operation=$1
network=$2
source_dir=$3
destination_dir="${4:-./envs/$network/datadir}"
# Validate the operation
if [ "$operation" != "pre" ] && [ "$operation" != "full" ]; then
echo "Invalid operation: $operation"
usage
fi
# Validate network name
if [ "$network" != "mainnet" ] && [ "$network" != "alfajores" ] && [ "$network" != "baklava" ]; then
echo "Invalid network name: $network"
usage
fi
# Print parsed arguments
echo "Network: $network"
echo "Source Directory: $source_dir"
echo "Destination Directory: $destination_dir"
echo "" # Blank line to separate from any failure output
# Check if source directory exists
if [ ! -d "${source_dir}" ]; then
printf "\033[0;31mError: Source directory does not exist\033[0m\n"
exit 1
fi
# Convert source directory to absolute path
source_dir=$(readlink -f "$source_dir")
cel2_migration_tool_image="us-west1-docker.pkg.dev/devopsre/celo-blockchain-public/cel2-migration-tool"
cel2_migration_tool_tag="celo-v2.0.0-rc4"
# Run check-db continuity script to ensure source db has no data gaps
if docker run --platform=linux/amd64 -it --rm \
-v "${source_dir}/celo/chaindata:/old-db" \
"${cel2_migration_tool_image}:${cel2_migration_tool_tag}" \
check-db \
--db-path /old-db \
--fail-fast; then
printf "\033[0;32mDB check completed successfully. No gaps or missing data detected.\033[0m\n"
else
printf "\033[0;31mDB check failed with exit code $?. If the logs indicate that the db is missing data, please retry with another source db. You can visit https://docs.celo.org/cel2/operators/migrate-node for instructions on how to check whether a db has missing data.\033[0m\n"
exit $?
fi
# Ensure destination directory exists for chaindata
mkdir -p "${destination_dir}/geth/chaindata"
# Convert destination directory to absolute path
destination_dir=$(readlink -f "$destination_dir")
if [ "${operation}" = "pre" ]; then
docker run --platform=linux/amd64 -it --rm \
-v "${source_dir}/celo/chaindata:/old-db" \
-v "${destination_dir}/geth/chaindata:/new-db" \
"${cel2_migration_tool_image}:${cel2_migration_tool_tag}" \
"${operation}" \
--old-db /old-db \
--new-db /new-db
exit 0
fi
# We need the OP_NODE__RPC_ENDPOINT to know where to connect to the L1 node.
if ! test -e "${network}.env"; then
echo "Network environment file not found: ${network}.env"
echo "If this repo is up to date with the remote main branch, then the ${network} config has not yet been published."
fi
. "${network}.env"
# Get MIGRATION_BLOCK_NUMBER and MIGRATION_BLOCK_TIME.
. "./envs/${network}/migration-config/migration.env"
# Gather required migration files
migration_config_dir="./envs/${network}/migration-config"
mkdir -p "$migration_config_dir"
(
cd "$migration_config_dir"
wget -N "https://storage.googleapis.com/cel2-rollup-files/${network}/config.json"
wget -N "https://storage.googleapis.com/cel2-rollup-files/${network}/deployment-l1.json"
wget -N "https://storage.googleapis.com/cel2-rollup-files/${network}/l2-allocs.json"
)
docker run --platform=linux/amd64 -it --rm \
-v "${source_dir}/celo/chaindata:/old-db" \
-v "${destination_dir}/geth/chaindata:/new-db" \
-v "${migration_config_dir}:/migration-config" \
-v "./envs/${network}/config:/out-config" \
"${cel2_migration_tool_image}:${cel2_migration_tool_tag}" \
"${operation}" \
--old-db /old-db \
--new-db /new-db \
--deploy-config /migration-config/config.json \
--l1-deployments /migration-config/deployment-l1.json \
--l2-allocs /migration-config/l2-allocs.json \
--l1-rpc "${OP_NODE__RPC_ENDPOINT}" \
--outfile.rollup-config /out-config/rollup.json \
--outfile.genesis /out-config/genesis.json \
--migration-block-time="$MIGRATION_BLOCK_TIME" \
--migration-block-number="$MIGRATION_BLOCK_NUMBER"
# Put a blank line before the summary
echo ""
# Use git to check if the rollup.json or genesis.json files have changed, if so then something went wrong with the migration.
# Note in the case that this is the first migration then the check will pass.
if git diff --quiet "./envs/${network}/config/rollup.json" "./envs/${network}/config/genesis.json"; then
printf "\033[0;32mMigration successful\033[0m\n"
else
printf "\033[0;31mMigration failed, output rollup.json and genesis.json do not match stored versions\033[0m\n"
# Display the diff for the rollup.json and genesis.json files
git diff "./envs/${network}/config/rollup.json" "./envs/${network}/config/genesis.json"
exit 1
fi