forked from smartcontracts/simple-optimism-node
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmigrate.sh
More file actions
executable file
·133 lines (113 loc) · 4.75 KB
/
Copy pathmigrate.sh
File metadata and controls
executable file
·133 lines (113 loc) · 4.75 KB
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
#!/bin/sh
set -e
# NOTE: This script produces a geth-format datadir, which op-reth (the
# execution client used by this setup) cannot read. Run your node with an
# empty DATADIR_PATH instead and serve pre-L2 history via the
# historical-rpc-node service or OP_RETH__HISTORICAL_RPC.
# 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)"
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" ]; 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:celo-migrate-v2.0.1"
# 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 -it --rm \
-v "${source_dir}/celo/chaindata:/old-db" \
-v "${destination_dir}/geth/chaindata:/new-db" \
"${cel2_migration_tool_image}" \
"${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"
# For mainnet we set the L1_BEACON_RPC_FLAG to be able to dynamically find the l1 starting block tag
if [ "$network" = "mainnet" ]; then
L1_BEACON_RPC_FLAG="--l1-beacon-rpc=$OP_NODE__L1_BEACON"
fi
# Get MIGRATION_BLOCK_NUMBER.
. "./envs/${network}/migration-config/migration.env"
# Gather required migration files
migration_config_dir="./envs/${network}/migration-config"
mkdir -p "$migration_config_dir"
if ! (
networkid=${network}
if [ ${network} = "mainnet" ]; then
networkid="celo"
fi
cd "$migration_config_dir"
wget -O config.json "https://storage.googleapis.com/cel2-rollup-files/${networkid}/config.json"
wget -O deployment-l1.json "https://storage.googleapis.com/cel2-rollup-files/${networkid}/deployment-l1.json"
wget -O l2-allocs.json "http://storage.googleapis.com/cel2-rollup-files/${networkid}/l2-allocs.json"
); then
printf "\033[0;31mFailed to download migration config: one or more downloads failed. You may need to wait until the migration config has been published.\033[0m\n"
exit 1
fi
# Write the migration tool's rollup-config and genesis outputs to the (gitignored)
# migration-config dir. The node loads its chain config from the superchain-registry,
# so these files are not used at runtime.
docker run -it --rm \
-v "${source_dir}/celo/chaindata:/old-db" \
-v "${destination_dir}/geth/chaindata:/new-db" \
-v "${migration_config_dir}:/migration-config" \
"${cel2_migration_tool_image}" \
"${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 /migration-config/rollup.json \
--outfile.genesis /migration-config/genesis.json \
--migration-block-number="$MIGRATION_BLOCK_NUMBER" "$L1_BEACON_RPC_FLAG"
# Put a blank line before the summary
echo ""
# The migrated datadir is validated at node startup: op-geth refuses to start if the
# migrated genesis does not match the superchain-registry config for the network.
printf "\033[0;32mMigration successful\033[0m\n"